Skip to content
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

Adding pytests for from_sympy / to_sympy. #828

Merged
merged 6 commits into from
May 27, 2023
Merged

Adding pytests for from_sympy / to_sympy. #828

merged 6 commits into from
May 27, 2023

Conversation

mmatera
Copy link
Contributor

@mmatera mmatera commented Mar 28, 2023

This PR adds some basic tests to check the consistency in the behavior of from_sympy. When I was writing the tests, I found some issues in the behavior of these functions, and also some failures in the modularity. So, this PR

  • moves mathics_to_sympy and sympy_to_mathics dicts from mathics.builtin to mathics.core.convert.sympy. This allows for avoiding some local imports.
  • to_numeric_sympy_args was moved from mathics.core.convert.expression to mathics.core.convert.sympy, which again helps to reduce local imports.
  • moves the implementation of Expression.to_sympy and Symbol.to_sympy to mathics.core.convert.sympy.
  • Constant expressions like MATHICS_*INFINITY and numbers MATHICS_COMPLEX_I were included in mathics.core.expression to avoid local duplication.
  • Improves the implementation of Symbol.to_sympy by using a dictionary to translate some predefined symbols in SymPy, like pi, E, GoldenRatio or I.
  • adds pytests for from_sympy and to_sympy.

In the code, it is also a proposal for a rewriting of from_sympy using dictionaries, which could help to get a clearer code.

mmatera added 2 commits March 28, 2023 16:46
…builtin` to `mathics.core.convert.sympy`.

* move the implementation of `Expression.to_sympy` and `Symbol.to_sympy` to `mathics.core.convert.sympy`.
* adding pytests for `from_sympy` and `to_sympy`.
@rocky
Copy link
Member

rocky commented Mar 28, 2023

At first glance, looks like a welcome improvement. Would like to try this out and go over in detail later.



# These are constant expressions used in several places.
# TODO: See if the is a better place to declare them.
Copy link
Member

@rocky rocky Mar 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no reason this can't be put in its own separate module as was done between the symbols and systemsymbols module .

More smaller focused modules is better than one larger sprawling module

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, any suggestions for the name of such a module?

Copy link
Member

@rocky rocky Mar 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These all seem to be symbolic constants.

So mathics.core.symbolic_constants.

Copy link
Member

@rocky rocky Mar 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At one time I had thought that we might set elements_properties, but that is not needed - once set on the first use will no longer need to get set again.

(And computing the properties for any of these is very quick.)

We might consider if it is worth it to turn this create an ExpressionConstant class which has a special and simple evaluate method (and other custom and simple methods like that).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, maybe I can make a separate PR with these objects and module, and then reformulate over it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was solved in #831

@mmatera mmatera mentioned this pull request Mar 31, 2023
mmatera added a commit that referenced this pull request Apr 6, 2023
This comes from #828. Here a new module is added to contain the
expression constants of the form `DirectedInfinity[...]`.
@mmatera mmatera marked this pull request as ready for review May 24, 2023 19:30
@rocky
Copy link
Member

rocky commented May 27, 2023

LGTM

@mmatera mmatera merged commit 4d0bcb9 into master May 27, 2023
@mmatera mmatera deleted the from_to_sympy branch May 27, 2023 12:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants