Opened 6 years ago

Closed 6 years ago

#22998 closed enhancement (fixed)

Unable to parse hypergeometric result from mathematica_free

Reported by: Marcelo Forets Owned by:
Priority: major Milestone: sage-8.0
Component: calculus Keywords: integrate, hypergeometric
Cc: Ralf Stephan, Karl-Dieter Crisman Merged in:
Authors: Marcelo Forets Reviewers: Ralf Stephan
Report Upstream: N/A Work issues:
Branch: 49bb25e (Commits, GitHub, GitLab) Commit: 49bb25e9beb56bf1bb3669a2c406f99be1d3ff4b
Dependencies: Stopgaps:

Status badges

Description

sage: integrate(e^(-x^2)*log(x), x, algorithm='mathematica_free')
Traceback (most recent call last):
...
ValueError: Unable to parse: -(x*HypergeometricPFQ[{1/2,1/2},{3/2,3/2},-x^2])+(Sqrt[Pi]*Erf[x]*Log[x])/2

Change History (14)

comment:1 Changed 6 years ago by Marcelo Forets

the result i was expecting is the sage object:

result = -(x*hypergeometric((1/2,1/2),(3/2,3/2),-x^2))+(sqrt(pi)*erf(x)*log(x))/2

maybe one can substitute the line in mma_free_integrator:

ans = SR(mexpr.lower().replace('[', '(').replace(']', ')'))

with the some of the code at the mathematica interface in _sage_ ?

(we don't need Mathematica to be installed!)

as you can see, there are two issues with the line above in this example. it transforms:

-(x*HypergeometricPFQ[{1/2,1/2},{3/2,3/2},-x^2])+(Sqrt[Pi]*Erf[x]*Log[x])/2

into

'-(x*hypergeometricpfq({1/2,1/2},{3/2,3/2},-x^2))+(sqrt(pi)*erf(x)*log(x))/2'

these are (i) curly braces, (ii) the special function is not transformed properly (no use of the conversions dictionary)

Last edited 6 years ago by Marcelo Forets (previous) (diff)

comment:2 Changed 6 years ago by Marcelo Forets

Branch: u/mforets/22998
Commit: 83c1dfc948b2b70bbba60b9db5e48bf9b633461e
Status: newneeds_review

New commits:

624f0e3error func mathematica conversion
83c1dfcuse mathematica symbols table

comment:3 Changed 6 years ago by git

Commit: 83c1dfc948b2b70bbba60b9db5e48bf9b633461eccc99a13ab67806d2d0f1fb7265bbf1cd1d76fff

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

017571badd 2 mathematica conversions
ccc99a1tweak import as

comment:4 Changed 6 years ago by git

Commit: ccc99a13ab67806d2d0f1fb7265bbf1cd1d76fff686f1cafe5918cad19db0afb6c9c8ae9a40ac4c8

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

686f1cafix extra space in message

comment:5 Changed 6 years ago by Marcelo Forets

notice that this change has an (arguably) adverse effect in test at lines 492-495 of symbolic/integration/integral.py.

indeed, instead of

sage: _ = var('x, y, z')
sage: f = sin(x^2) + y^z
sage: f.integrate(x, algorithm="mathematica_free")   # optional - internet
x*y^z + sqrt(1/2)*sqrt(pi)*fresnels(sqrt(2)*x/sqrt(pi))

one has:

sage: _ = var('x, y, z')
sage: f = sin(x^2) + y^z
sage: f.integrate(x, algorithm="mathematica_free")   # optional - internet
Traceback (most recent call last):
NotImplementedError: Don't know a Sage equivalent for Mathematica function 'FresnelS'.

the new issue is because Fresnel integrals are not implemented in Sage (right?) -- in other words, one cannot do much with the former result.

That said, Sage could return a more verbose message like:

"Don't know a Sage equivalent for Mathematica function '%s'.

Unable to parse: %s" % m.group() % mexpr

comment:6 in reply to:  5 Changed 6 years ago by Ralf Stephan

Replying to mforets:

the new issue is because Fresnel integrals are not implemented in Sage (right?)

Right. You can see all symbolic function tickets at https://trac.sagemath.org/wiki/symbolics/functions

comment:7 Changed 6 years ago by Marcelo Forets

thanks for pointing out that page. i've added an entry in Tickets to make for future reference.

comment:8 Changed 6 years ago by Ralf Stephan

Reviewers: Ralf Stephan
Status: needs_reviewpositive_review

Looks good, and tests in relevant directories pass. Please fill in the Authors field.

comment:9 Changed 6 years ago by Marcelo Forets

Authors: Marcelo Forets

Thanks :)

comment:10 Changed 6 years ago by Marcelo Forets

do you want me to update (in a new ticket) the doctest from comment:5? the patchbots, do they test with optional - internet?

comment:11 Changed 6 years ago by Volker Braun

Status: positive_reviewneeds_work

merge conflict

comment:12 Changed 6 years ago by Ralf Stephan

Branch: u/mforets/22998u/rws/22998

comment:13 Changed 6 years ago by Ralf Stephan

Commit: 686f1cafe5918cad19db0afb6c9c8ae9a40ac4c849bb25e9beb56bf1bb3669a2c406f99be1d3ff4b
Status: needs_workpositive_review

New commits:

49bb25eMerge branch 'develop' into t/22998/22998

comment:14 Changed 6 years ago by Volker Braun

Branch: u/rws/2299849bb25e9beb56bf1bb3669a2c406f99be1d3ff4b
Resolution: fixed
Status: positive_reviewclosed
Note: See TracTickets for help on using tickets.