Opened 6 years ago

Closed 6 years ago

#22706 closed enhancement (fixed)

Add more conversions from giac

Reported by: Marcelo Forets Owned by:
Priority: major Milestone: sage-8.0
Component: interfaces Keywords: giac, special functions
Cc: Paul Masson, ​frederichan Merged in:
Authors: Paul Masson, Marcelo Forets Reviewers: Frédéric Chapoton
Report Upstream: N/A Work issues:
Branch: 350316f (Commits, GitHub, GitLab) Commit: 350316fe0bc69cb8c1fdebbd3363d3437661f28f
Dependencies: #22422 Stopgaps:

Status badges

Description (last modified by Marcelo Forets)

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:

  • sage.libs.pynac.pynac.register_symbol can be used to register new symbols in the symbols_table, as in register_symbol(heaviside,{'giac':'Heaviside'}).
  • for BuiltIn functions which exist in giac with a different name, it is sufficient to update the conversions dictionary for the corresponding __init__ method.

Change History (36)

comment:1 Changed 6 years ago by Marcelo Forets

Description: modified (diff)

comment:2 Changed 6 years ago by Marcelo Forets

Description: modified (diff)

comment:3 Changed 6 years ago by Marcelo Forets

Description: modified (diff)

comment:4 Changed 6 years ago by Marcelo Forets

Description: modified (diff)

comment:5 Changed 6 years ago by Han Frederic

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([[16-16*i,-16+16*i,-400+528*i,144+240*i],[1,0,-30,-40,5]]))/512

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))

comment:6 Changed 6 years ago by Marcelo Forets

Cc: Paul Masson ​frederichan added

comment:7 Changed 6 years ago by Marcelo Forets

Dependencies: #22422

comment:8 Changed 6 years ago by Paul Masson

Branch: u/paulmasson/22706

comment:9 Changed 6 years ago by Paul Masson

Authors: Paul Masson
Commit: 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:

0e337efAdd Giac conversions and cleanup
ffba36aAdd Giac conversions and cleanup
e1a63edAdd Giac conversions and cleanup
3a3d079Add Giac conversion
bdc2807Add Giac conversions and cleanup

comment:10 Changed 6 years ago by Paul Masson

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 6 years ago by Ralf Stephan

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([[16-16*i,-16+16*i,-400+528*i,144+240*i],[1,0,-30,-40,5]]))/512

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))

This appears to be #22024.

comment:12 in reply to:  9 Changed 6 years ago by Marcelo Forets

Replying to paulmasson:

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.

true and they agree if just 1 argument is passed.

also:

  • should Giac's abs be mapped so abs_symbolic? notice that asking for abs_symbolic??, there is already some:
"""GinacFunction.__init__(self, "abs", latex_name=r"\mathrm{abs}",
                               conversions=dict(sympy='Abs'))
  • same for binomial, arg, ceil, conjugage (and conj), factorial, frac, imag (and imag_part), real (and real_part).

comment:13 in reply to:  10 Changed 6 years ago by Marcelo Forets

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(x-2)*sin(x), x, 0, 4)    # unevaluated??
integrate(dirac_delta(x-2)*sin(x), x, 0, 4)
sage: integrate(dirac_delta(x-2)*sin(x), x, 0, 4, algorithm='sympy')    # ok
sin(2)

comment:14 Changed 6 years ago by Marcelo Forets

after this one is done, we could go for "Add giac interface to integrate". what do you think?

comment:15 Changed 6 years ago by Marcelo Forets

Branch: u/paulmasson/22706u/mforets/22706

comment:16 Changed 6 years ago by Marcelo Forets

Authors: Paul MassonPaul Masson, Marcelo Forets
Commit: bdc2807934ce570c7a29547f3ff3fdff5a387beb9143bd2c7f60e364f3864e862d0cf8d563bc6a60

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:

9143bd2add more /functions conversions

comment:17 Changed 6 years ago by Marcelo Forets

we may want to ensure a symbolic integral wrapper, for instance with (cf. #22138):

sage: n = var('n')
sage: integral(x^n*sin(x), x, algorithm='giac')
...
NotImplementedError: Unable to parse Giac output: integrate(x^n*sin(x),x)

but in other cases it already returns unevaluted:

sage: integrate(log(1+x)/x, x, 0, 1, algorithm='giac')
integrate(ln(x + 1)/x, x, 0, 1)
Version 0, edited 6 years ago by Marcelo Forets (next)

comment:18 Changed 6 years ago by Frédéric 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.

comment:19 in reply to:  18 Changed 6 years ago by Marcelo Forets

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 6 years ago by Marcelo Forets

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.0587863771115636e-12)

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 6 years ago by Marcelo Forets

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.21644966006352e-14*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 Changed 6 years ago by Frédéric Chapoton

branch looks good to me and bot is green, but is this in "needs review" state ?

comment:23 Changed 6 years ago by git

Commit: 9143bd2c7f60e364f3864e862d0cf8d563bc6a606e5e3e2af7f55105b5b85b5940dcbe916c3a35d9

Branch pushed to git repo; I updated commit sha1. New commits:

4b9bfdaMerge branch 'develop' into t/mforets/22706
6e5e3e2incomplete gamma conversions

comment:24 in reply to:  22 Changed 6 years ago by Marcelo Forets

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 6 years ago by Frédéric Chapoton

branch does not apply

comment:26 Changed 6 years ago by git

Commit: 6e5e3e2af7f55105b5b85b5940dcbe916c3a35d971bc33610a526043a93ff68f45964ed5b4b93660

Branch pushed to git repo; I updated commit sha1. New commits:

666c2f3resolve merge conflicts with v.8.0.beta8
71bc336add error functions conversions

comment:27 Changed 6 years ago by git

Commit: 71bc33610a526043a93ff68f45964ed5b4b93660b2f426184bbd24ddc9b8d710ed937ff7b24eef0c

Branch pushed to git repo; I updated commit sha1. New commits:

b2f4261fix missing ) in giac erfc

comment:28 Changed 6 years ago by git

Commit: b2f426184bbd24ddc9b8d710ed937ff7b24eef0c6592c6197fbdb40307c6bad3e01e97116af448a3

Branch pushed to git repo; I updated commit sha1. New commits:

6592c61register swap psi

comment:29 Changed 6 years ago by Marcelo Forets

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 Changed 6 years ago by Ralf Stephan

It works if you give a giac conversion in the psi2 init as well.

comment:31 Changed 6 years ago by git

Commit: 6592c6197fbdb40307c6bad3e01e97116af448a3350316fe0bc69cb8c1fdebbd3363d3437661f28f

Branch pushed to git repo; I updated commit sha1. New commits:

350316fadd Psi conversion in psi2

comment:32 Changed 6 years ago by Marcelo Forets

Status: newneeds_review

comment:33 in reply to:  30 Changed 6 years ago by Marcelo Forets

Replying to rws:

It works if you give a giac conversion in the psi2 init as well.

It does!! Thanks.

comment:34 Changed 6 years ago by Frédéric Chapoton

Reviewers: Frédéric Chapoton
Status: needs_reviewpositive_review

ok, let it be

comment:35 in reply to:  34 Changed 6 years ago by Marcelo Forets

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 6 years ago by Volker Braun

Branch: u/mforets/22706350316fe0bc69cb8c1fdebbd3363d3437661f28f
Resolution: fixed
Status: positive_reviewclosed
Note: See TracTickets for help on using tickets.