-
-
Notifications
You must be signed in to change notification settings - Fork 528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Regression: Many mathematica doctests now fail #8495
Comments
comment:1
Before #3587, mathematica's output was sent to ExpectElement._sage_repr() in expect.py, which called repr() and tidied up the results (converting {} to [], stripping new line characters etc) then sage_eval() was called on the results. With this approach, mathematica functions that returned numbers, symbolic variables or arrays could be imported successfully into sage. The approach had the disadvantage that all symbolic variables had to be passed in manually as locals, and that functions couldn't be translated from mathematica to their equivalents in sage. #3587 instead calls str() on mathematica's results (which has the alarming option ascii_art = True), then replaces []s by (), changes everything to lower case and sends it to SR. This works for simple functions but fails for arrays and probably anything affected by ascii_art = True I'm not familiar with SR, but at a minimum MathematicaElement.sage() should be patched to call sage_repr() instead of str(). I don't know whether SR has all the functionality of sage_eval(), e.g. supporting arrays. |
comment:2
I've uploaded a patch that has a thorough rewrite of MathematicaElement.sage() to get the functionality from #3587 while keeping the functionality from before it (lists, complex numbers, numbers in scientific notation...). I still need to write some documentation for the top of the file (i.e. documentation that makes it into the reference manual) but before I do that and submit this for formal review I'd like wise comments about my approach, e.g. "The way you convert function names is really inefficient and problematic, do it this way...", or "You can efficiently get a list of all sage functions recognised by sage_eval() by ...". Also if someone could check the doctests on a 32-bit computer and let me know the result that they get instead of |
comment:3
I've updated the patch file so that it updates the Mathematica module documentation. This needs to be doctested on a 32-bit computer at some point. |
Author: flawrence |
Changed author from flawrence to Felix Lawrence |
Reviewer: Mike Hansen |
comment:5
There is dictionary in place from Mathematica to Sage.
This is constructed at runtime and is filled in by the |
comment:6
Replying to @sagetrac-flawrence:
On 32-bit Debian I get the same output. There is only one doctest failure:
But this is probably unrelated to this patch, since also without this patch applied I get
|
comment:7
Replying to @mwhansen:
Excellent! I've updated the patch so that it uses that dictionary. I also added the ability to pass a locals dictionary to The documentation for this function won't be very visible, since it starts with an underscore, so I was contemplating setting up a mathematica-specific .sage function that accepts a locals dictionary and has a copy of this documentation. In the end I didn't do this because I don't understand the consequences (or why there are separate Replying to @sagetrac-whuss:
Yes, I'm not sure it's related to the patch either. For the record I get the correct behaviour with the patch:
|
comment:9
This looks great! Many thanks for your work Felix. Here is my review:
This is definitely an improvement over what we have currently. I'd really like to see it included in the next release. |
Changed reviewer from Mike Hansen to Mike Hansen, Burcin Erocal |
comment:10
One more:
|
comment:11
Thanks for your suggestions Burcin. I implemented all of them, and made some significant further changes: Now we actually check whether each function exists, before we try to convert the entire expression. This allows us to check several variations of mma's function names, such as a downcased version, a down_cased version, and the original name. In order to do this I needed to add an option to sage.calculus.calculus._find_func() whereby it wouldn't automatically create a symbolic function if none were present in Sage. We now also try the same downcasing tricks for constants. In order to convert from CamelCase to camel_case I used code from stack overflow. I presume such code is public domain and doesn't require attribution in the docstring. I also realised that the documentation for |
Attachment: diff_with_previous_review.patch.gz What's changed since burcin's review |
comment:12
What patch(s) is supposed to be applied here? |
comment:17
Replying to @sagetrac-flawrence:
Sounds good to me. Can you open that ticket? :) |
comment:18
Replying to @sagetrac-flawrence:
Em, it is strange. I'm a bit tied up now, but will repeat later. I'm actually willing to give this a positive review, on the basis that it fixes a very large number of the problems, and no new bugs are introduced. But I'll run the tests later and see what can be done. Dave |
comment:19
Replying to @burcin:
Done: #10898 |
comment:20
Hi Dave, Have you had a chance to investigate what was happening on Solaris? Cheers, |
comment:21
Replying to @sagetrac-flawrence:
Can you clarify the exact commands you want tested with and without the patch? |
This comment has been minimized.
This comment has been minimized.
comment:22
ARGH! I upgraded to 4.6.2 (from 4.6.1), ran the tests and get the same errors as Dave. #9032 modified Sage's .n(), and added (in two files)
This means that Mathematica's I think that the way to fix this is by adjusting precedences so that on mathematica objects, mathematica functions take priority. I also think that fixing this is beyond the scope of this ticket (which was a rewrite of |
comment:23
Replying to @sagetrac-flawrence:
I'm glad I;m not going mad. Since the changes reduces the number of failures from 17 to 2, I believe this should be merged, so positive review. The remaining issues can be sorted out on #10968 |
Changed reviewer from Mike Hansen, Burcin Erocal to Mike Hansen, Burcin Erocal, David Kirkby |
comment:24
Problems while building the documentation:
|
Attachment: trac_8495-rewrite-sage.patch.gz |
comment:25
Attachment: trac_8495-rewrite-sage.2.patch.gz I made some minor formatting changes to the documentation to avoid the above problems. The documentation now builds without errors and looks OK on my machine. I forgot to tick the 'replace attachment' box; please disregard the older (non ".2.") patch. |
This comment has been minimized.
This comment has been minimized.
comment:26
Yes, the documentation builds ok for me. That was something I did not check before I must admit. Dave |
Merged: sage-4.7.alpha3 |
Since #3587, which implements a sage() method for mathematica elements, many mathematica doctests fail. E.g:
apply only attachment: trac_8495-rewrite-sage.2.patch
CC: @burcin @jasongrout
Component: interfaces
Author: Felix Lawrence
Reviewer: Mike Hansen, Burcin Erocal, David Kirkby
Merged: sage-4.7.alpha3
Issue created by migration from https://trac.sagemath.org/ticket/8495
The text was updated successfully, but these errors were encountered: