Opened 2 years ago

Closed 2 years ago

#22998 closed enhancement (fixed)

Unable to parse hypergeometric result from mathematica_free

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

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 2 years ago by mforets

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 2 years ago by mforets (previous) (diff)

comment:2 Changed 2 years ago by mforets

  • Branch set to u/mforets/22998
  • Commit set to 83c1dfc948b2b70bbba60b9db5e48bf9b633461e
  • Status changed from new to needs_review

New commits:

624f0e3error func mathematica conversion
83c1dfcuse mathematica symbols table

comment:3 Changed 2 years ago by git

  • Commit changed from 83c1dfc948b2b70bbba60b9db5e48bf9b633461e to ccc99a13ab67806d2d0f1fb7265bbf1cd1d76fff

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

017571badd 2 mathematica conversions
ccc99a1tweak import as

comment:4 Changed 2 years ago by git

  • Commit changed from ccc99a13ab67806d2d0f1fb7265bbf1cd1d76fff to 686f1cafe5918cad19db0afb6c9c8ae9a40ac4c8

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

686f1cafix extra space in message

comment:5 follow-up: Changed 2 years ago by mforets

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 2 years ago by rws

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 2 years ago by mforets

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

comment:8 Changed 2 years ago by rws

  • Reviewers set to Ralf Stephan
  • Status changed from needs_review to positive_review

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

comment:9 Changed 2 years ago by mforets

  • Authors set to Marcelo Forets

Thanks :)

comment:10 Changed 2 years ago by mforets

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 2 years ago by vbraun

  • Status changed from positive_review to needs_work

merge conflict

comment:12 Changed 2 years ago by rws

  • Branch changed from u/mforets/22998 to u/rws/22998

comment:13 Changed 2 years ago by rws

  • Commit changed from 686f1cafe5918cad19db0afb6c9c8ae9a40ac4c8 to 49bb25e9beb56bf1bb3669a2c406f99be1d3ff4b
  • Status changed from needs_work to positive_review

New commits:

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

comment:14 Changed 2 years ago by vbraun

  • Branch changed from u/rws/22998 to 49bb25e9beb56bf1bb3669a2c406f99be1d3ff4b
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.