Opened 6 years ago

Closed 6 years ago

# Unable to parse hypergeometric result from mathematica_free

Reported by: Owned by: Marcelo Forets major sage-8.0 calculus integrate, hypergeometric Ralf Stephan, Karl-Dieter Crisman Marcelo Forets Ralf Stephan N/A 49bb25e 49bb25e9beb56bf1bb3669a2c406f99be1d3ff4b

### 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
```

### 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 → 83c1dfc948b2b70bbba60b9db5e48bf9b633461e new → needs_review

New commits:

 ​624f0e3 `error func mathematica conversion` ​83c1dfc `use mathematica symbols table`

### comment:3 Changed 6 years ago by git

Commit: 83c1dfc948b2b70bbba60b9db5e48bf9b633461e → ccc99a13ab67806d2d0f1fb7265bbf1cd1d76fff

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

 ​017571b `add 2 mathematica conversions` ​ccc99a1 `tweak import as`

### comment:4 Changed 6 years ago by git

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

 ​686f1ca `fix extra space in message`

### comment:5 follow-up:  6 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`.

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

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 needs_review → positive_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_review → needs_work

merge conflict

### comment:12 Changed 6 years ago by Ralf Stephan

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

### comment:13 Changed 6 years ago by Ralf Stephan

Commit: 686f1cafe5918cad19db0afb6c9c8ae9a40ac4c8 → 49bb25e9beb56bf1bb3669a2c406f99be1d3ff4b needs_work → positive_review

New commits:

 ​49bb25e `Merge branch 'develop' into t/22998/22998`

### comment:14 Changed 6 years ago by Volker Braun

Branch: u/rws/22998 → 49bb25e9beb56bf1bb3669a2c406f99be1d3ff4b → fixed positive_review → closed
Note: See TracTickets for help on using tickets.