Skip to content

Commit

Permalink
Use hooks to IPython display formatter and sys.displayhook to simplif…
Browse files Browse the repository at this point in the history
…y control of human readable output. (#20)

* algwsym.config.output control simplified using sys.displayhook and IPython.display_formatters.

* Fixing tests

* Output tests fixed

* Doc tests fixed

* Doc tests fixed

* Readme updates

* added `solve_to_list` output flag to recover pre-0.11.0 behavior.

* `solve_to_list=True` now makes multivariable solutions within a list of solutions a `list` instead of a `FiniteSet`.

* docs and final dev for 0.11.0

* bump to v0.11.0
  • Loading branch information
gutow authored Jun 6, 2023
1 parent 07adc5a commit 3217e25
Show file tree
Hide file tree
Showing 14 changed files with 7,026 additions and 21,216 deletions.
806 changes: 398 additions & 408 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 @@ -13,6 +13,8 @@
* 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), ...)`.
* [MathLive](https://cortexjs.io/mathlive/) on another web page as possible
input engine.

## Constructing the Documentation

Expand Down
57 changes: 38 additions & 19 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,26 +61,35 @@ but require more knowledge of command syntax, plus they cannot easily be
installed in a generic python environment.

## 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
$\frac{a}{b} = \frac{c}{d}$. To also see the code representation (what can
be copied and pasted for
$\frac{a}{b} = \frac{c}{d}$ or $e^{\frac{-x^2}{\sigma^2}}$. To also see the
code representation (what can be copied and pasted for
additional computation) set `algwsym_config.output.show_code = True`.
This will print the code version (e.g. `Equation(a,b/c)`) of the equation as
well. This code version can be accessed directly by calling `repr()` on the
equation.

* **In interactive text environments (ipython and command line)** the
representation (code version) is returned by default. Calling `print()`
or `str()` on an equation will return the human readable version with an
equals sign. To have the human readable version returned by default set
`algwsym_config.output.human_text = True`. If combined with
`algwsym_config.output.show_code = True`, both code and human readable
versions will be shown.
This will print the code version (e.g. `Equation(a,b/c)`) of equations
and sympy expression in addition to the human readable version. This code
version can be accessed directly by calling `repr()` on the
equation or expression.

* **In interactive text environments (IPython and command line)** The human
readable string version of Sympy expressions are returned (for `Equations` a
= b rather than Equation(a,b)). This is equivalent to Calling `print()`
or `str()` on an expression.
* To have the code version (can be copied and pasted as a
Python statement) returned, set `algwsym_config.output.human_text = False`.
* Setting both `algwsym_config.output.human_text = True`
and `algwsym_config.output.show_code = True`, will return both the
code and human readable versions.

* **The equation label** can be turned off by setting
`algwsym_config.output.label = False`.

* By default **solutions output by `solve()`** are returned as a SymPy
`FiniteSet()` to force typesetting of the included solutions. To get Python
lists instead you can override this for the whole session by setting
`algwsym_config.output.solve_to_list = True`. For a one-off, simply
wrap the output of a solve in `list()` (e.g. `list(solve(...))`).

## Setup/Installation

1. Use pip to install in your python environment:
Expand All @@ -107,10 +116,20 @@ github](https://github.com/gutow/Algebra_with_Sympy/issues).

## Change Log

* 0.11.0dev
* Added ability to hide human friendly output from solve with
`algwsym_config.output.show_solve_output=False`. Tests of this
functionality also added.
* 0.11.0dev (June 5, 2023)
* Formatting of `FiniteSets` overridden so that the contents always
pretty-print. This removes the necessity of special flags to get
pretty output from `solve`.
* Sympy `solve()` now works reliably with equations and outputs
pretty-printed solutions.
* Added option `algwsym_config.output.solve_to_list = True` which causes
`solve()` to return solutions sets as Python lists. Using this option
prevents pretty-printing of the solutions produced by `solve()`.
* `algwsym_config.output.show_code` and
`algwsym_config.output.human_text` now work for all sympy objects, not
just `Equation` objects. This works
in terminal, IPython terminal and Jupyter. This is achieved by hooking
into the python `display_hook` and IPython `display_formatter`.
* Added jupyter to requirements.txt so that virtual environment builds
will include jupyter.
* The way `__version__` was handled could break pip install. Changed to
Expand Down Expand Up @@ -165,4 +184,4 @@ This program is free software: you can redistribute it and/or modify
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

Copyright - Jonathan Gutow 2021, 2022
Copyright - Algebra with Sympy Contributors 2021, 2022, 2023
4 changes: 2 additions & 2 deletions algebra_with_sympy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

# Set the output formatting defaults
algwsym_config.output.show_code = False
algwsym_config.output.human_text = False
algwsym_config.output.human_text = True
algwsym_config.output.label = True
algwsym_config.output.show_solve_output = True
algwsym_config.output.solve_to_list = False

# Set version number for internal access
algwsym_version = 'unknown'
Expand Down
Loading

0 comments on commit 3217e25

Please sign in to comment.