Skip to content

Commit

Permalink
v0.12.0.dev0 for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
gutow committed Jul 12, 2023
1 parent b88ec74 commit 2322f59
Show file tree
Hide file tree
Showing 13 changed files with 16,721 additions and 3,971 deletions.
916 changes: 565 additions & 351 deletions Demonstration of equation class.ipynb

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Development Notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
* Test for _binary_op NotImplemented error (not sure how to get there).
* examine these more carefully (top priority: real_root, cbrt, Ynm_c).
* To consider
* Include [Sympy Plot Backends](https://sympy-plot-backends.readthedocs.io/en/latest/)
in the default setup.
* Change `Equation` constructor to accept `Equality`, `Set`, `List` or
`lhs, rhs`, rather than just `lhs, rhs`.
* Extend `.subs` to accept `.subs(a=2*c, b = sin(q), ...)`.
Expand Down
28 changes: 27 additions & 1 deletion ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
This tool defines relations that all high school and college students would
recognize as mathematical equations.
They consist of a left hand side (lhs) and a right hand side (rhs) connected by
the relation operator "=".
the relation operator "=". In addition, it sets some convenient defaults and
provides some useful controls of output formatting that may be useful even if
you do not use the `Equation` class (see [Conveniences for
SymPy](#convenience-tools-and-defaults-for-interactive-use-of-sympy)).

This tool applies operations to both sides of the equation simultaneously, just
as students are taught to do when
Expand Down Expand Up @@ -60,6 +63,24 @@ and [Maxima](http://maxima.sourceforge.net/) have similar capabilities,
but require more knowledge of command syntax, plus they cannot easily be
installed in a generic python environment.

## Convenience Tools and Defaults for Interactive Use of SymPy

Even if you do not use the `Equation` class, there are some convenience
tools and defaults that will probably make interactive use of SymPy in
Jupyter/IPython environments easier:

* By default all numbers without decimal points are interpreted as integers.
One implication of this is that base ten fractions are exact (e.g. 2/3 ->
2/3 not 0.6666...). This can be turned off with `unset_integers_as_exact()`
and on with `set_integers_as_exact()`. When on the flag
`algwsym_config.numerics.integers_as_exact = True`.
* Results of `solve()` are wrapped in `FiniteSet()` to force pretty-printing
of all of a solution set. See [Controlling the Format of Interactive
Outputs](#controlling-the-format-of-interactive-outputs).
* It is possible to set the default display to show both the pretty-printed
result and the code version simultaneously. See [Controlling the Format of Interactive
Outputs](#controlling-the-format-of-interactive-outputs).

## Controlling the Format of Interactive Outputs
* These controls impact all Sympy objects and the `Equation` class.
* **In graphical environments (Jupyter)** you will get rendered Latex such as
Expand Down Expand Up @@ -116,6 +137,11 @@ github](https://github.com/gutow/Algebra_with_Sympy/issues).

## Change Log

* 0.12.0 (July X, 2023)
* Now defaults to interpreting numbers without decimal points as integers.
This can be turned off with `unset_integers_as_exact()` and on with
`set_integers_as_exact()`. When on the flag
`algwsym_config.numerics.integers_as_exact = True`.
* 0.11.0 (June 5, 2023)
* Formatting of `FiniteSets` overridden so that the contents always
pretty-print. This removes the necessity of special flags to get
Expand Down
9 changes: 6 additions & 3 deletions algebra_with_sympy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
.. include:: ../Development Notes.md
"""
__docformat__ = "numpy"

from algebra_with_sympy.algebraic_equation import *

# Set config value for numerics before adjusting with the preparser
algwsym_config.numerics.integers_as_exact = False # adjusted in preparser.
# Set up numerics behaviors
from IPython import get_ipython
if get_ipython():
get_ipython().input_transformers_post.append(integers_as_exact)
algwsym_config.numerics.integers_as_exact = True

from algebra_with_sympy.preparser import *

# Set the output formatting defaults
Expand Down
26 changes: 15 additions & 11 deletions algebra_with_sympy/algebraic_equation.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import functools
from sympy import *


class algwsym_config():

def __init__(self):
Expand Down Expand Up @@ -209,29 +208,33 @@ def __command_line_printing__(expr, *arg):

# Numerics controls
def set_integers_as_exact():
"""This operation uses `sympy.interactive.session,int_to_Integer` which
"""This operation uses `sympy.interactive.session.int_to_Integer`, which
causes any number input without a decimal to be interpreted as a sympy
integer to pre-parse input cells. It also sets the flag
integer, to pre-parse input cells. It also sets the flag
`algwsym_config.numerics.integers_as_exact = True` This is the default
mode of algebra_with_sympy. To turn this off call
`unset_integers_as_exact()`.
"""
from IPython import get_ipython
if get_ipython():
get_ipython().input_transformers_post.append(integers_as_exact)
algwsym_config.numerics.integers_as_exact = True
algwsym_config = get_ipython().user_ns.get("algwsym_config", False)
if algwsym_config:
algwsym_config.numerics.integers_as_exact = True
else:
raise ValueError("The algwsym_config object does not exist.")
return

def unset_integers_as_exact():
"""This operation disables forcing of numbers input without
decimals being interpreted as sympy integers. Numbers input without a
decimal may be interpreted as floating point if they are part of an
expression that undergoes python evaluation (e.g. 2/3 -> 0.6666...). It
also sets the flag `algwsym_config.numerics.integers_as_exact = False`
also sets the flag `algwsym_config.numerics.integers_as_exact = False`.
Call `set_integers_as_exact()` to avoid this conversion of rational
fractions and related expressions to floating point. Algebra_with_sympy
starts with `set_integers_as_exact()` enabled (
`algwsym_config.numerics.integers_as_exact = True`)
`algwsym_config.numerics.integers_as_exact = True`).
"""
from IPython import get_ipython
if get_ipython():
Expand All @@ -241,12 +244,13 @@ def unset_integers_as_exact():
for k in pre:
if "integers_as_exact" in k.__name__:
pre.remove(k)
algwsym_config.numerics.integers_as_exact = False
return
algwsym_config = get_ipython().user_ns.get("algwsym_config", False)
if algwsym_config:
algwsym_config.numerics.integers_as_exact = False
else:
raise ValueError("The algwsym_config object does not exist.")

# Set up numerics behaviors
if ip:
set_integers_as_exact()
return

class Equation(Basic, EvalfMixin):
"""
Expand Down
6 changes: 3 additions & 3 deletions algebra_with_sympy/preparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ def algebra_with_sympy_preparser(lines):
def integers_as_exact(lines):
"""This preparser uses `sympy.interactive.session.int_to_Integer` to
convert numbers without decimal points into sympy integers so that math
on them will be exact rather than defaulting to floating point. This
on them will be exact rather than defaulting to floating point. **This
should not be called directly by the user. It is plugged into the
IPython preparsing sequence when the feature is requested. The default for
IPython preparsing sequence when the feature is requested.** The default for
Algebra_with_sympy is to use this preparser. This can be turned on and
off with:
off using the Algebra_with_sympy functions:
* `set_integers_as_exact()`
* `unset_integers_as_exact()`
"""
Expand Down
Loading

0 comments on commit 2322f59

Please sign in to comment.