# logic_python2sympy
| | |
| --- | --- |
| PyPI: | <https://pypi.org/project/logic-python2sympy/> |
| Source: | <https://github.com/duntytelessia/logic_python2sympy/> |
| License: | MIT |
`Sympy` has the advantage of using `Python` syntax in its own expressions, but with some exceptions :
logical expressions in `Sympy` differ a bit from their `Python` counterparts (`a and b` is written `a & b` in `Sympy`).
Thus, this module provides functions that can convert a logical expression written in `Python` syntax, into a `Sympy` expression.
## Usage
```python
>>> import logic_python2sympy as p2s
>>> code = "((0 < x <= 10) or not y"
>>> print(p2s.convert(code))
Or(And(0 < x, x <= 10), Not(y))
>> print(p2s.get_expression(code))
~y | ((0 < x) & (x <= 10))
```
### convert
```python
convert(expr: str) -> str
```
Transform a `Python` logical expression into `Sympy` syntax. \
expr: valid logical expression, i.e. expr must be valid `Python` syntax, and must be a combintion of the following `ast` nodes: `BoolOp, BinOp, UnaryOp, Compare, Call, Constant, Name` \
raises: `NotImplentedError`, when the expression contains operators that are not supported in `Sympy`
### get_expression
```python
get_expression(expr: str) -> Any
```
Transform a `Python` logical expression into a `Sympy` expression. \
expr: valid logical expression, i.e. expr must be valid `Python` syntax,
and must be a combintion of the following `ast` nodes:
`BoolOp, BinOp, UnaryOp, Compare, Call, Constant, Name`
raises: `NotImplentedError`, when the expression contains operators that are not supported in `Sympy`
Raw data
{
"_id": null,
"home_page": "https://github.com/duntytelessia/logic_python2sympy/",
"name": "logic-python2sympy",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.12",
"maintainer_email": null,
"keywords": "logical expression, sympy",
"author": "Telessia",
"author_email": "dunty.telessia@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/b7/af/a68e30ac33cd25493016479980e0d0a60431c164e9be1e2a001074806114/logic_python2sympy-0.1.3.tar.gz",
"platform": null,
"description": "# logic_python2sympy\n\n| | |\n| --- | --- |\n| PyPI: | <https://pypi.org/project/logic-python2sympy/> |\n| Source: | <https://github.com/duntytelessia/logic_python2sympy/> |\n| License: | MIT |\n\n`Sympy` has the advantage of using `Python` syntax in its own expressions, but with some exceptions :\nlogical expressions in `Sympy` differ a bit from their `Python` counterparts (`a and b` is written `a & b` in `Sympy`).\nThus, this module provides functions that can convert a logical expression written in `Python` syntax, into a `Sympy` expression.\n\n## Usage\n\n```python\n>>> import logic_python2sympy as p2s\n>>> code = \"((0 < x <= 10) or not y\"\n>>> print(p2s.convert(code))\nOr(And(0 < x, x <= 10), Not(y))\n>> print(p2s.get_expression(code))\n~y | ((0 < x) & (x <= 10))\n```\n\n### convert\n\n```python\nconvert(expr: str) -> str\n```\n\nTransform a `Python` logical expression into `Sympy` syntax. \\\nexpr: valid logical expression, i.e. expr must be valid `Python` syntax, and must be a combintion of the following `ast` nodes: `BoolOp, BinOp, UnaryOp, Compare, Call, Constant, Name` \\\nraises: `NotImplentedError`, when the expression contains operators that are not supported in `Sympy`\n\n### get_expression\n\n```python\nget_expression(expr: str) -> Any\n```\n\nTransform a `Python` logical expression into a `Sympy` expression. \\\nexpr: valid logical expression, i.e. expr must be valid `Python` syntax,\nand must be a combintion of the following `ast` nodes:\n`BoolOp, BinOp, UnaryOp, Compare, Call, Constant, Name`\nraises: `NotImplentedError`, when the expression contains operators that are not supported in `Sympy`\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "convert a logical expression written in `Python` syntax, into a `Sympy` expression",
"version": "0.1.3",
"project_urls": {
"Homepage": "https://github.com/duntytelessia/logic_python2sympy/",
"Repository": "https://github.com/duntytelessia/logic_python2sympy/"
},
"split_keywords": [
"logical expression",
" sympy"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "bcfcb31b49035d063a688dc26d98a77fc7579e76d4924d90ddb7ea5edd8e6376",
"md5": "5cbad75aa8c2273042b82cfec244af05",
"sha256": "c720903bb2f5fbfd6712cc218c650caa61476e119864419c4b1cc3f8cb605bf0"
},
"downloads": -1,
"filename": "logic_python2sympy-0.1.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "5cbad75aa8c2273042b82cfec244af05",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.12",
"size": 4681,
"upload_time": "2024-07-31T13:49:12",
"upload_time_iso_8601": "2024-07-31T13:49:12.356976Z",
"url": "https://files.pythonhosted.org/packages/bc/fc/b31b49035d063a688dc26d98a77fc7579e76d4924d90ddb7ea5edd8e6376/logic_python2sympy-0.1.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "b7afa68e30ac33cd25493016479980e0d0a60431c164e9be1e2a001074806114",
"md5": "cd6a89335dce79ba3b153f9e72677e00",
"sha256": "7c4386f0ff62e2b44f67c3d33b8df7c8797a56e03775a6daef7cd02e669868f5"
},
"downloads": -1,
"filename": "logic_python2sympy-0.1.3.tar.gz",
"has_sig": false,
"md5_digest": "cd6a89335dce79ba3b153f9e72677e00",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.12",
"size": 3408,
"upload_time": "2024-07-31T13:49:13",
"upload_time_iso_8601": "2024-07-31T13:49:13.225707Z",
"url": "https://files.pythonhosted.org/packages/b7/af/a68e30ac33cd25493016479980e0d0a60431c164e9be1e2a001074806114/logic_python2sympy-0.1.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-07-31 13:49:13",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "duntytelessia",
"github_project": "logic_python2sympy",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "logic-python2sympy"
}