Opened 23 months ago
Closed 21 months ago
#22706 closed enhancement (fixed)
Add more conversions from giac
Reported by:  mforets  Owned by:  

Priority:  major  Milestone:  sage8.0 
Component:  interfaces  Keywords:  giac, special functions 
Cc:  paulmasson, frederichan  Merged in:  
Authors:  Paul Masson, Marcelo Forets  Reviewers:  Frédéric Chapoton 
Report Upstream:  N/A  Work issues:  
Branch:  350316f (Commits)  Commit:  350316fe0bc69cb8c1fdebbd3363d3437661f28f 
Dependencies:  #22422  Stopgaps: 
Description (last modified by )
A "conversion" is a dictionary entry which maps object names in an interface (e.g. Maxima, Mathematica, Giac, ...) to corresponding objects with a different name in Sage.
Some conversions relevant to the Giac interface are missing:
 Derivatives of Dirac delta, as in
Dirac(t, 1)
.  Special function names at
/functions/orthogonal_polys.py
.
See also:
 In the file:
local/share/giac/doc/aide_cas
, lines starting by # are keywords followed by synonyms, next lines are for small doc and see also. Full doc can be found in: Symbolic algebra and Mathematics with Xcas
sage.libs.pynac.pynac.register_symbol
can be used to register new symbols in thesymbols_table
, as inregister_symbol(heaviside,{'giac':'Heaviside'})
.
 for
BuiltIn
functions which exist in giac with a different name, it is sufficient to update theconversions
dictionary for the corresponding__init__
method.
Change History (36)
comment:1 Changed 23 months ago by
 Description modified (diff)
comment:2 Changed 23 months ago by
 Description modified (diff)
comment:3 Changed 23 months ago by
 Description modified (diff)
comment:4 Changed 23 months ago by
 Description modified (diff)
comment:5 followup: ↓ 11 Changed 23 months ago by
comment:6 Changed 23 months ago by
 Cc paulmasson frederichan added
comment:7 Changed 23 months ago by
 Dependencies set to #22422
comment:8 Changed 23 months ago by
 Branch set to u/paulmasson/22706
comment:9 followup: ↓ 12 Changed 23 months ago by
 Commit set to bdc2807934ce570c7a29547f3ff3fdff5a387beb
I went through the files in sage/functions
to add as many conversions for special functions as possible, but could only find ten that were different from Sage.
The Giac exponential integrals Ei
, Si
and Ci
have existing Sage aliases, so there shouldn't be a problem with those.
The orthogonal polynomials hermite
and laguerre
have the same names in Giac and Sage. Same for erf
and a pending erfc
, as well as binomial
and factorial
.
The Giac function Psi
has is a different name from Sage psi
, but the order of the arguments is reversed so I didn't add it now.
New commits:
0e337ef  Add Giac conversions and cleanup

ffba36a  Add Giac conversions and cleanup

e1a63ed  Add Giac conversions and cleanup

3a3d079  Add Giac conversion

bdc2807  Add Giac conversions and cleanup

comment:10 followup: ↓ 13 Changed 23 months ago by
Considering the derivatives of delta functions, I think we'll have to do a string replacement using a regular expression similar to how Maxima conversions are handled starting here. Perhaps that should be a separate ticket after #22422 is merged.
The conversions I've entered are not dependent on #22422 and can be merged at any time. If either of you can identify additional functions that can be added easily with this ticket, let me know.
comment:11 in reply to: ↑ 5 Changed 23 months ago by
Replying to frederichan:
This one doesn't look easy. Any idea to deal with rootof?
sage: giac.simplify((exp(2*i*pi/3)+exp(2*i*pi/15))^3) ((768*i)*(1)^(2/15)*sqrt(3)768*(1)^(2/15)+768*i*(1)^(4/15)*sqrt(3)768*(1)^(4/15)+rootof([[1616*i,16+16*i,400+528*i,144+240*i],[1,0,30,40,5]]))/512do we need to chose a name for the variable in the extention field? (if yes then how? (or what would be a good name))
This appears to be #22024.
comment:12 in reply to: ↑ 9 Changed 23 months ago by
Replying to paulmasson:
The Giac function
Psi
has is a different name from Sagepsi
, but the order of the arguments is reversed so I didn't add it now.
true and they agree if just 1 argument is passed.
also:
 should Giac's
abs
be mapped soabs_symbolic
? notice that asking forabs_symbolic??
, there is already some:
"""GinacFunction.__init__(self, "abs", latex_name=r"\mathrm{abs}", conversions=dict(sympy='Abs'))
 same for
binomial
,arg
,ceil
,conjugage
(andconj
),factorial
,frac
,imag
(andimag_part
),real
(andreal_part
).
comment:13 in reply to: ↑ 10 Changed 23 months ago by
Replying to paulmasson:
Considering the derivatives of delta functions, I think we'll have to do a string replacement using a regular expression similar to how Maxima conversions are handled starting here. Perhaps that should be a separate ticket after #22422 is merged.
+1. moreover, it should also fix integration:
sage: integrate(dirac_delta(x2)*sin(x), x, 0, 4) # unevaluated?? integrate(dirac_delta(x2)*sin(x), x, 0, 4) sage: integrate(dirac_delta(x2)*sin(x), x, 0, 4, algorithm='sympy') # ok sin(2)
comment:14 Changed 22 months ago by
after this one is done, we could go for "Add giac interface to integrate". what do you think?
comment:15 Changed 22 months ago by
 Branch changed from u/paulmasson/22706 to u/mforets/22706
comment:16 Changed 22 months ago by
 Commit changed from bdc2807934ce570c7a29547f3ff3fdff5a387beb to 9143bd2c7f60e364f3864e862d0cf8d563bc6a60
hi, i've added some simple conversions.
remaining:
 rootof
 psi function
 derivative of delta function.
for the last item is not clear to me if it is required to write a _derivative_
method for FunctionDiracDelta
, or to write a new a class FunctionDiracDeltaDerivative
, or if it's about passing a dictionary element with some preprocessing (some arguments) so that say Dirac(x, 2)
(giac) changes to diff(dirac_delta(x), x, x)
in sage and conversely.
New commits:
9143bd2  add more /functions conversions

comment:17 Changed 22 months ago by
see #22891 for "add giac interface to integrate"
comment:18 followup: ↓ 19 Changed 21 months ago by
something related:
sage: integrate(exp(x^3), (x, 1, 2), algorithm='giac') 1/3*igamma(1/3, 1)  1/3*igamma(1/3, 8)
where igamma
is giac's name for the incomplete gamma function.
comment:19 in reply to: ↑ 18 Changed 21 months ago by
Replying to chapoton:
something related:
sage: integrate(exp(x^3), (x, 1, 2), algorithm='giac') 1/3*igamma(1/3, 1)  1/3*igamma(1/3, 8)where
igamma
is giac's name for the incomplete gamma function.
interesting. it seems that giac's igamma
corresponds to gamma_inc_lower
in Sage (lower incomplete Gamma). moreover, giac's ugamma
corresponds to gamma_inc
in Sage (upper incomplete Gamma). i'll add these conversions asap.
comment:20 Changed 21 months ago by
in this case there is also a difference in their numerical evaluations:
actual value of the integral:
sage: numerical_integral(exp(x^3), 1, 2) (275.51098376331174, 3.0587863771115636e12)
giac:
sage: giac('1/3*igamma(1./3, 1)  1/3*igamma(1./3, 8)') 275.510983763 sage: giac('igamma(1./3, 1)') 4.02571325393 sage: giac('igamma(1./3, 8)') 830.558664544 sage: giac('igamma(1./3, 1)') 2.42253354642 sage: giac('igamma(1./3, 8)') 2.67886054288
sage:
sage: 1/3*gamma_inc_lower(1./3, 1)  1/3*gamma_inc_lower(1./3, 8) 137.755491881656  238.599510960670*I sage: gamma_inc_lower(1./3, 1) # values don't match. imag part => t^(2/3) ? 2.01285662696613 + 3.48636994625705*I sage: gamma_inc_lower(1./3, 8) # values don't match 415.279332271934 + 719.284902828267*I sage: gamma_inc_lower(1./3, 1) # values match 2.42253354641901 sage: gamma_inc_lower(1./3, 8) # values match 2.67886054288163
comment:21 Changed 21 months ago by
however,
sage: integrate(exp(x^3), x, 1, 2, algorithm='maxima') # OK 1/3*(1)^(2/3)*gamma(1/3, 1) + 1/3*(1)^(2/3)*gamma(1/3, 8) sage: _.n() 275.510983763312  7.21644966006352e14*I sage: giac('integrate(exp(x^3), x, 1, 2)') # OK 1/3*igamma(1/3,1)1/3*igamma(1/3,8)
what's going on? is there a problem on the numerical eval of gamma_inc_lower
or the conversion is not accurate?
comment:22 followup: ↓ 24 Changed 21 months ago by
branch looks good to me and bot is green, but is this in "needs review" state ?
comment:23 Changed 21 months ago by
 Commit changed from 9143bd2c7f60e364f3864e862d0cf8d563bc6a60 to 6e5e3e2af7f55105b5b85b5940dcbe916c3a35d9
comment:24 in reply to: ↑ 22 Changed 21 months ago by
Replying to chapoton:
branch looks good to me and bot is green, but is this in "needs review" state ?
Thanks for the feedback  not yet but close! I'd like to handle the psi
function conversion. Have to figure out how to reverse the arguments in the function call. I haven't seen examples of that sort..
For the other tasks discussed in this thread, i've separated them into smaller chunks, see giac interface wiki section.
comment:25 Changed 21 months ago by
branch does not apply
comment:26 Changed 21 months ago by
 Commit changed from 6e5e3e2af7f55105b5b85b5940dcbe916c3a35d9 to 71bc33610a526043a93ff68f45964ed5b4b93660
comment:27 Changed 21 months ago by
 Commit changed from 71bc33610a526043a93ff68f45964ed5b4b93660 to b2f426184bbd24ddc9b8d710ed937ff7b24eef0c
Branch pushed to git repo; I updated commit sha1. New commits:
b2f4261  fix missing ) in giac erfc

comment:28 Changed 21 months ago by
 Commit changed from b2f426184bbd24ddc9b8d710ed937ff7b24eef0c to 6592c6197fbdb40307c6bad3e01e97116af448a3
Branch pushed to git repo; I updated commit sha1. New commits:
6592c61  register swap psi

comment:29 Changed 21 months ago by
partial progress: with the last commit one has
sage: giac('Psi(x,1)')._sage_() psi(1, x)
as desired. however the other way round doesn't work get swapped:
sage: psi(1, x)._giac_() psi(1, x) # Psi(x, 1) is expected
comment:30 followup: ↓ 33 Changed 21 months ago by
It works if you give a giac conversion in the psi2 init as well.
comment:31 Changed 21 months ago by
 Commit changed from 6592c6197fbdb40307c6bad3e01e97116af448a3 to 350316fe0bc69cb8c1fdebbd3363d3437661f28f
Branch pushed to git repo; I updated commit sha1. New commits:
350316f  add Psi conversion in psi2

comment:32 Changed 21 months ago by
 Status changed from new to needs_review
comment:33 in reply to: ↑ 30 Changed 21 months ago by
comment:34 followup: ↓ 35 Changed 21 months ago by
 Reviewers set to Frédéric Chapoton
 Status changed from needs_review to positive_review
ok, let it be
comment:35 in reply to: ↑ 34 Changed 21 months ago by
Replying to chapoton:
ok, let it be
great, thanks for the review and to all participants of this ticket!
w.r.t giac symbolics tickets i think i'll go on with #23016...
comment:36 Changed 21 months ago by
 Branch changed from u/mforets/22706 to 350316fe0bc69cb8c1fdebbd3363d3437661f28f
 Resolution set to fixed
 Status changed from positive_review to closed
This one doesn't look easy. Any idea to deal with rootof?
do we need to chose a name for the variable in the extention field? (if yes then how? (or what would be a good name))