symexpress3


Namesymexpress3 JSON
Version 0.0.11 PyPI version JSON
download
home_pageNone
SummaryA Python module for symbolic calculations
upload_time2024-12-05 18:12:09
maintainerNone
docs_urlNone
authorGien van den Enden
requires_python>=3.11
licenseGNU General Public License v3 or later (GPLv3+)
keywords calculator math symbolic
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Python Symbolic Expression 3

A Python module for symbolic calculations

## Usage

### Optimize expression
```py
>>> import symexpress3
>>> objExpress = symexpress3.SymFormulaParser( '(x+1) * (x+2)' )
>>> objExpress.optimizeExtended()
>>> print( objExpress )
x^2 + x * 3 + 2
```

### Supported operators
\+   \-   \*   \/   \(   \)   \^   \^\^
<br>
^ gives root values by fractions
^^ gives principal root values by fractions
```py
>>> 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 /
```py
>>> 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
```py
>>> 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
```py
>>> 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
```py
>>> 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
```py
>>> 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.
```py
>>> 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*
```py
>>> 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
```py
>>> 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(<action>)* an *optimize( None )*
Most of the time use *optimizeNormal()* instead of *optimize( None )*
```py
>>> 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
```py
>>> 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.
```py
>>> 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.
```py
>>> 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)"

### Graphical user interface
https://github.com/SWVandenEnden/websym3

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "symexpress3",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.11",
    "maintainer_email": "Gien van den Enden <swvandenenden@gmail.com>",
    "keywords": "calculator, math, symbolic",
    "author": "Gien van den Enden",
    "author_email": "swvandenenden@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/74/64/f87e53b451a011484ef58222a81017684e48e32c60c37ec00ad125171c21/symexpress3-0.0.11.tar.gz",
    "platform": null,
    "description": "# Python Symbolic Expression 3\n\nA Python module for symbolic calculations\n\n## Usage\n\n### Optimize expression\n```py\n>>> import symexpress3\n>>> objExpress = symexpress3.SymFormulaParser( '(x+1) * (x+2)' )\n>>> objExpress.optimizeExtended()\n>>> print( objExpress )\nx^2 + x * 3 + 2\n```\n\n### Supported operators\n\\+&nbsp;&nbsp; \\-&nbsp;&nbsp; \\*&nbsp;&nbsp; \\/&nbsp;&nbsp; \\(&nbsp;&nbsp; \\)&nbsp;&nbsp; \\^&nbsp;&nbsp; \\^\\^\n<br>\n^ gives root values by fractions\n^^ gives principal root values by fractions\n```py\n>>> import symexpress3\n>>> objExpress = symexpress3.SymFormulaParser( '(4)^(1/2)' )\n>>> objExpress.optimizeExtended()\n>>> print( objExpress )\n[ (-2) | 2 ]\n>>> objExpress = symexpress3.SymFormulaParser( '(4)^^(1/2)' )\n>>> objExpress.optimizeExtended()\n>>> print( objExpress )\n2\n```\n### Numeric values\nOnly integers are supported. For fractions use /\n```py\n>>> import symexpress3\n>>> objExpress = symexpress3.SymFormulaParser( '7/10 + 3/11' )\n>>> objExpress.optimizeExtended()\n>>> print( objExpress )\n(107/110)\n```\n\n### Get the real value\nIf there is more the one value, it gives an array back\n```py\n>>> import symexpress3\n>>> objExpress = symexpress3.SymFormulaParser( '7/10 + 3/11' )\n>>> objExpress.optimizeExtended()\n>>> print( objExpress.getValue() )\n0.9727272727272728\n>>> objExpress = symexpress3.SymFormulaParser( '(4)^(1/2)' )\n>>> objExpress.optimizeExtended()\n>>> print( objExpress.getValue() )\n[-2, 2]\n```\n\n### Get all defined functions\nGet a dictionary of all the defined functions. Key is the functions syntax, value is the description\n```py\n>>> import symexpress3\n>>> print( symexpress3.GetAllFunctions() )\n```\n\n### Get all defined optimize actions\nGet a dictionary of all the optimize actions. Key is the optimize action, value is the description\n```py\n>>> import symexpress3\n>>> print( symexpress3.GetAllOptimizeActions() )\n```\n\n### Get all fixed variables\nGet a dictionary of all the fixed variables. Key is the variable name, value is the description\n```py\n>>> import symexpress3\n>>> print( symexpress3.GetFixedVariables() )\n```\n\n### Predefined optimization methods\nThe *optimizeNormal* method use the *multiply*, *onlyOneRoot*, *i*, *power* and *add* optimize actions\nThe *power* action do not optimize roots. *onlyOneRoot* get radicals in it lowest form.\n```py\n>>> import symexpress3\n>>> objExpress = symexpress3.SymFormulaParser( '5 * 2^2 + i * i + (4)^(1/2)' )\n>>> objExpress.optimizeNormal()\n>>> print( objExpress )\n19 + 4^(1/2)\n```\nThe *optimizeExtended* method use the *optimizeNormal* method and the following optimize actions:\n*rootToPrincipalRoot*, *powerArrays*,*arrayPower*, *functionToValues*, *negRootToI*,\n*functionToValues*, *unnestingRadicals*, *functionToValues*, *radicalDenominatorToCounter*,\n*rootIToSinCos*, *functionToValues*, *rootOfImagNumToCosISin*, *functionToValues*,\n*nestedRadicals*, *imaginairDenominator*, *sinTwoCosTwo*, *cosXplusYtoSinCos*,\n*sinXplusYtoSinCos*, *splitDenominator* and *expandArrays*\n```py\n>>> import symexpress3\n>>> objExpress = symexpress3.SymFormulaParser( '5 * 2^2 + i * i + (4)^(1/2)' )\n>>> objExpress.optimizeExtended()\n>>> print( objExpress )\n19 + [ (-2) | 2 ]\n>>> print( objExpress.getValue() )\n[17, 21]\n```\n\n### Optimize expression\nUse the *optimize* method for optimization\n\nRemove unnecessary () and optimize the internal structure\n```py\n>>> import symexpress3\n>>> objExpress = symexpress3.SymFormulaParser( '((2) + (3))' )\n>>> objExpress.optimize( None )\n>>> print( objExpress )\n2 + 3\n```\nUse of the optimize actions.\nUse after *SymFormulaParser* and each *optimize(<action>)* an *optimize( None )*\nMost of the time use *optimizeNormal()* instead of *optimize( None )*\n```py\n>>> import symexpress3\n>>> objExpress = symexpress3.SymFormulaParser( 'cos( pi/4 )' )\n>>> objExpress.optimize( None )\n>>> objExpress.optimize( 'functionToValues' )\n>>> objExpress.optimize( None )\n>>> print( objExpress )\n2^^(1/2) * (1/2)\n```\n\n### Output formats\nMathMl output\n```py\n>>> import symexpress3\n>>> objExpress = symexpress3.SymFormulaParser( 'cos( pi/4 )' )\n>>> objExpress.optimize( None )\n>>> print( objExpress.mathMl() )\n```\nHtml output with expression in MathMl and string format.\nIt create the symexpress3_demo.html file in the current directory.\n```py\n>>> import symexpress3\n>>> objExpress = symexpress3.SymFormulaParser( 'cos( pi/4 )' )\n>>> objExpress.optimize( None )\n>>> objOutput = symexpress3.SymToHtml( \"symexpress3_demo.html\", \"SymExpress 3 demo\" )\n>>> objOutput.writeSymExpress( objExpress )\n>>> objOutput.writeLine( str( objExpress ))\n>>> objOutput.closeFile()\n```\n\n### Calculate value with variables\nDefine a dictionary for the variables. The key is the variable name and de value is a number.\n```py\n>>> import symexpress3\n>>> objExpress = symexpress3.SymFormulaParser( '(x+1) (y+2)' )\n>>> dictVar = {}\n>>> dictVar[ 'x' ] = 0.33333\n>>> dictVar[ 'y' ] = 3\n>>> valueExpression = objExpress.getValue( dictVar )\n>>> print( valueExpression )\n6.66665\n```\n\n### Command line\npython -m symexpress3\n\n- *Help*: python -m symexpress3  -h\n- *Direct optimize*: python -m symexpress3 \"cos( pi / 4 )^^(1/3)\"\n\n### Graphical user interface\nhttps://github.com/SWVandenEnden/websym3\n",
    "bugtrack_url": null,
    "license": "GNU General Public License v3 or later (GPLv3+)",
    "summary": "A Python module for symbolic calculations",
    "version": "0.0.11",
    "project_urls": {
        "Source Code": "https://github.com/SWVandenEnden/symexpress3"
    },
    "split_keywords": [
        "calculator",
        " math",
        " symbolic"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "06c2b0a267eb3bc61eba9e205a15401b4c82d1f065d1e2cd1517f7900a09fb97",
                "md5": "d46e903e2ef41e6cc186524bafe1f378",
                "sha256": "f85539297314948dd9edea6e95103a67451c634526f456de584ccf1ae9af8c4f"
            },
            "downloads": -1,
            "filename": "symexpress3-0.0.11-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d46e903e2ef41e6cc186524bafe1f378",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 174659,
            "upload_time": "2024-12-05T18:12:08",
            "upload_time_iso_8601": "2024-12-05T18:12:08.397321Z",
            "url": "https://files.pythonhosted.org/packages/06/c2/b0a267eb3bc61eba9e205a15401b4c82d1f065d1e2cd1517f7900a09fb97/symexpress3-0.0.11-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7464f87e53b451a011484ef58222a81017684e48e32c60c37ec00ad125171c21",
                "md5": "b1d89cddf6ed9c8de375d9d3350305e7",
                "sha256": "64543521ce13efb39fe50442922d7ba44f1aefc654cd649133b3263cfbc55aaf"
            },
            "downloads": -1,
            "filename": "symexpress3-0.0.11.tar.gz",
            "has_sig": false,
            "md5_digest": "b1d89cddf6ed9c8de375d9d3350305e7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 101694,
            "upload_time": "2024-12-05T18:12:09",
            "upload_time_iso_8601": "2024-12-05T18:12:09.968664Z",
            "url": "https://files.pythonhosted.org/packages/74/64/f87e53b451a011484ef58222a81017684e48e32c60c37ec00ad125171c21/symexpress3-0.0.11.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-05 18:12:09",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "SWVandenEnden",
    "github_project": "symexpress3",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "symexpress3"
}
        
Elapsed time: 0.41803s