Python Symbolic Expression 3
A Python module for symbolic calculations
Usage
Optimize expression
>>> import symexpress3
>>> objExpress = symexpress3.SymFormulaParser( '(x+1) * (x+2)' )
>>> objExpress.optimizeExtended()
>>> print( objExpress )
x^2 + x * 3 + 2
Supported operators
+ - * / ( ) ^ ^^
^ gives root values by fractions
^^ gives principal root values by fractions
>>> import symexpress3
>>> objExpress = symexpress3.SymFormulaParser( '(4)^(1/2)' )
>>> objExpress.optimizeExtended()
>>> print( objExpress )
[ (-2) | 2 ]
>>> objExpress = symexpress3.SymFormulaParser( '(4)^^(1/2)' )
>>> objExpress.optimizeExtended()
>>> print( objExpress )
2
Numeric values
Only integers are supported. For fractions use /
>>> import symexpress3
>>> objExpress = symexpress3.SymFormulaParser( '7/10 + 3/11' )
>>> objExpress.optimizeExtended()
>>> print( objExpress )
(107/110)
Get the real value
If there is more the one value, it gives an array back
>>> import symexpress3
>>> objExpress = symexpress3.SymFormulaParser( '7/10 + 3/11' )
>>> objExpress.optimizeExtended()
>>> print( objExpress.getValue() )
0.9727272727272728
>>> objExpress = symexpress3.SymFormulaParser( '(4)^(1/2)' )
>>> objExpress.optimizeExtended()
>>> print( objExpress.getValue() )
[-2, 2]
Get all defined functions
Get a dictionary of all the defined functions. Key is the functions syntax, value is the description
>>> import symexpress3
>>> print( symexpress3.GetAllFunctions() )
Get all defined optimize actions
Get a dictionary of all the optimize actions. Key is the optimize action, value is the description
>>> import symexpress3
>>> print( symexpress3.GetAllOptimizeActions() )
Get all fixed variables
Get a dictionary of all the fixed variables. Key is the variable name, value is the description
>>> import symexpress3
>>> print( symexpress3.GetFixedVariables() )
Predefined optimization methods
The optimizeNormal method use the multiply, onlyOneRoot, i, power and add optimize actions The power action do not optimize roots. onlyOneRoot get radicals in it lowest form.
>>> import symexpress3
>>> objExpress = symexpress3.SymFormulaParser( '5 * 2^2 + i * i + (4)^(1/2)' )
>>> objExpress.optimizeNormal()
>>> print( objExpress )
19 + 4^(1/2)
The optimizeExtended method use the optimizeNormal method and the following optimize actions: rootToPrincipalRoot, powerArrays,arrayPower, functionToValues, negRootToI, functionToValues, unnestingRadicals, functionToValues, radicalDenominatorToCounter, rootIToSinCos, functionToValues, rootOfImagNumToCosISin, functionToValues, nestedRadicals, imaginairDenominator, sinTwoCosTwo, cosXplusYtoSinCos, sinXplusYtoSinCos, splitDenominator and expandArrays
>>> import symexpress3
>>> objExpress = symexpress3.SymFormulaParser( '5 * 2^2 + i * i + (4)^(1/2)' )
>>> objExpress.optimizeExtended()
>>> print( objExpress )
19 + [ (-2) | 2 ]
>>> print( objExpress.getValue() )
[17, 21]
Optimize expression
Use the optimize method for optimization
Remove unnecessary () and optimize the internal structure
>>> import symexpress3
>>> objExpress = symexpress3.SymFormulaParser( '((2) + (3))' )
>>> objExpress.optimize( None )
>>> print( objExpress )
2 + 3
Use of the optimize actions. Use after SymFormulaParser and each optimize() an optimize( None ) Most of the time use optimizeNormal() instead of optimize( None )
>>> import symexpress3
>>> objExpress = symexpress3.SymFormulaParser( 'cos( pi/4 )' )
>>> objExpress.optimize( None )
>>> objExpress.optimize( 'functionToValues' )
>>> objExpress.optimize( None )
>>> print( objExpress )
2^^(1/2) * (1/2)
Output formats
MathMl output
>>> import symexpress3
>>> objExpress = symexpress3.SymFormulaParser( 'cos( pi/4 )' )
>>> objExpress.optimize( None )
>>> print( objExpress.mathMl() )
Html output with expression in MathMl and string format. It create the symexpress3_demo.html file in the current directory.
>>> import symexpress3
>>> objExpress = symexpress3.SymFormulaParser( 'cos( pi/4 )' )
>>> objExpress.optimize( None )
>>> objOutput = symexpress3.SymToHtml( "symexpress3_demo.html", "SymExpress 3 demo" )
>>> objOutput.writeSymExpress( objExpress )
>>> objOutput.writeLine( str( objExpress ))
>>> objOutput.closeFile()
Calculate value with variables
Define a dictionary for the variables. The key is the variable name and de value is a number.
>>> import symexpress3
>>> objExpress = symexpress3.SymFormulaParser( '(x+1) (y+2)' )
>>> dictVar = {}
>>> dictVar[ 'x' ] = 0.33333
>>> dictVar[ 'y' ] = 3
>>> valueExpression = objExpress.getValue( dictVar )
>>> print( valueExpression )
6.66665
Command line
python -m symexpress3
- Help: python -m symexpress3 -h
- Direct optimize: python -m symexpress3 "cos( pi / 4 )^^(1/3)"
MathMl colors
| Color | Description |
|---|---|
| Black | Normal |
| Green | Principal root |
| Red | Incorrect number of parameters |
| Blue | Display function like numberToPrimeFactors |
| Orange | Display function with incorrect number of parameters |
Notes
- By big numbers set mpmatch precision accordingly (mpmath.mp.dps)
- Graphical user interface: https://github.com/SWVandenEnden/websym3
Metadata
Release files for symexpress3 0.0.19
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| symexpress3-0.0.19.tar.gz | 145.9 kB | Without provenance | Details for symexpress3-0.0.19.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| symexpress3-0.0.19-py3-none-any.whl | Python 3 | none | any | Details for symexpress3-0.0.19-py3-none-any.whl |
Total release size: 396.8 kB
Release files / symexpress3-0.0.19.tar.gz
| Download URL | symexpress3-0.0.19.tar.gz |
|---|---|
| Size | 145.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1493ae0cc1a023ecf6c6f0b0465f6828166b47badd4f983832db625f4d578161
|
|
BLAKE2b-256 checksum How to use checksums |
a0f7d8926c1c452f5662ca63b70e5b312adad349f7577bd0155e174412bde9c8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.5
|
Release files / symexpress3-0.0.19-py3-none-any.whl
| Download URL | symexpress3-0.0.19-py3-none-any.whl |
|---|---|
| Size | 250.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d742da243e6c7386d441acfa225491cb221cf65b0e5caa483d03f8959598f003
|
|
BLAKE2b-256 checksum How to use checksums |
0158bddbb100ffacafc889b9ba6eb866d43a095aa946d0436f0f0347d01026db
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.5
|
Security for symexpress3 0.0.19
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.