plusminus


Nameplusminus JSON
Version 0.7.0 PyPI version JSON
download
home_pagehttps://github.com/pyparsing/plusminus
Summary+/- plusminus is a module that builds on the pyparsing infixNotation helper method to build easy-to-code and
upload_time2022-12-19 04:15:33
maintainer
docs_urlNone
authorPaul McGuire
requires_python>=3.6
license
keywords python infix notation arithmetic safe eval
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # plusminus

The **plusminus** package provides a ready-to-run arithmetic parser and evaluator, 
based on [`pyparsing`](https://pyparsing-docs.readthedocs.io/en/latest/index.html)'s 
[`infix_notation`](https://pyparsing-docs.readthedocs.io/en/latest/pyparsing.html#pyparsing.infixNotation) 
helper method.

Strings containing 6-function arithmetic expressions can be parsed and evaluated using the 
[`ArithmeticParser`](https://github.com/pyparsing/plusminus/blob/master/doc/arithmetic_parser.md#the-core-basicarithmeticparser):

```python
from plusminus import BaseArithmeticParser

parser = BaseArithmeticParser()
print(parser.evaluate("2+3/10"))
```

The parser can also return an Abstract Syntax Tree of `ArithNode` objects:

```python
parsed_elements = parser.parse("2+3/10")
```

Arithmetic expressions are evaluated following standard rules for operator precedence, allowing for use of parentheses to override:

    ()
    |x|
    ∩ & ∪ | - ^ ∆ (set operations)
    **
    -
    * / // × ÷ mod
    + -
    < > <= >= == != ≠ ≤ ≥
    in ∈ ∉ (element in/not in set)
    not
    and ∧
    or ∨
    ? : (ternary)

Functions can be called:

    abs    ceil   max
    round  floor  str
    trunc  min    bool


The `BaseArithmeticParser` also supports assignment of variables:

    r = 5
    area = π × r²


This last expression could be assigned using  `@=` formula assignment:

    area @= π × r²


As `r` is updated, evaluating `area` will be reevaluated using the new value.


An `ArithmeticParser` class is also defined, with more extensive operators, 
including:

    !     - factorial  
    °     - degree-radian conversion
    √ ⁿ√  - square root and n'th root (2-9)
    ⁻¹  ⁰  ¹  ²  ³ - common exponents as superscripts

and additional pre-defined functions:

    sin    asin  rad    gcd
    cos    acos  deg    lcm
    tan    atan  ln     rnd
    sgn    sinh  log    randint
    gamma  cosh  log2
    hypot  tanh  log10

This parser class can be used in applications using algebra or trigonometry
expressions.

Custom expressions can be defined using a simple
[`API`](https://github.com/pyparsing/plusminus/blob/master/doc/developer_api.md).
Example parsers are included for other specialized applications
and domains:

- dice rolling (`"3d6 + d20"`)
- time delta expressions (`"today() + 2d + 12h"`)
- retail and business expressions (`"20% off of 19.99"`)
- combinatoric expressions (`"6C2"` or `"5P3"` )
 

These parsers can be incorporated into other
applications to support the safe evaluation of user-defined domain-specific
expressions.



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/pyparsing/plusminus",
    "name": "plusminus",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "python infix notation arithmetic safe eval",
    "author": "Paul McGuire",
    "author_email": "ptmcg@austin.rr.com",
    "download_url": "https://files.pythonhosted.org/packages/61/d3/f9a96cd35a04ccdc9dea30d766ac66cb7ff9f66eff722f977a786bf2a1e6/plusminus-0.7.0.tar.gz",
    "platform": null,
    "description": "# plusminus\n\nThe **plusminus** package provides a ready-to-run arithmetic parser and evaluator, \nbased on [`pyparsing`](https://pyparsing-docs.readthedocs.io/en/latest/index.html)'s \n[`infix_notation`](https://pyparsing-docs.readthedocs.io/en/latest/pyparsing.html#pyparsing.infixNotation) \nhelper method.\n\nStrings containing 6-function arithmetic expressions can be parsed and evaluated using the \n[`ArithmeticParser`](https://github.com/pyparsing/plusminus/blob/master/doc/arithmetic_parser.md#the-core-basicarithmeticparser):\n\n```python\nfrom plusminus import BaseArithmeticParser\n\nparser = BaseArithmeticParser()\nprint(parser.evaluate(\"2+3/10\"))\n```\n\nThe parser can also return an Abstract Syntax Tree of `ArithNode` objects:\n\n```python\nparsed_elements = parser.parse(\"2+3/10\")\n```\n\nArithmetic expressions are evaluated following standard rules for operator precedence, allowing for use of parentheses to override:\n\n    ()\n    |x|\n    \u2229 & \u222a | - ^ \u2206 (set operations)\n    **\n    -\n    * / // \u00d7 \u00f7 mod\n    + -\n    < > <= >= == != \u2260 \u2264 \u2265\n    in \u2208 \u2209 (element in/not in set)\n    not\n    and \u2227\n    or \u2228\n    ? : (ternary)\n\nFunctions can be called:\n\n    abs    ceil   max\n    round  floor  str\n    trunc  min    bool\n\n\nThe `BaseArithmeticParser` also supports assignment of variables:\n\n    r = 5\n    area = \u03c0 \u00d7 r\u00b2\n\n\nThis last expression could be assigned using  `@=` formula assignment:\n\n    area @= \u03c0 \u00d7 r\u00b2\n\n\nAs `r` is updated, evaluating `area` will be reevaluated using the new value.\n\n\nAn `ArithmeticParser` class is also defined, with more extensive operators, \nincluding:\n\n    !     - factorial  \n    \u00b0     - degree-radian conversion\n    \u221a \u207f\u221a  - square root and n'th root (2-9)\n    \u207b\u00b9  \u2070  \u00b9  \u00b2  \u00b3 - common exponents as superscripts\n\nand additional pre-defined functions:\n\n    sin    asin  rad    gcd\n    cos    acos  deg    lcm\n    tan    atan  ln     rnd\n    sgn    sinh  log    randint\n    gamma  cosh  log2\n    hypot  tanh  log10\n\nThis parser class can be used in applications using algebra or trigonometry\nexpressions.\n\nCustom expressions can be defined using a simple\n[`API`](https://github.com/pyparsing/plusminus/blob/master/doc/developer_api.md).\nExample parsers are included for other specialized applications\nand domains:\n\n- dice rolling (`\"3d6 + d20\"`)\n- time delta expressions (`\"today() + 2d + 12h\"`)\n- retail and business expressions (`\"20% off of 19.99\"`)\n- combinatoric expressions (`\"6C2\"` or `\"5P3\"` )\n \n\nThese parsers can be incorporated into other\napplications to support the safe evaluation of user-defined domain-specific\nexpressions.\n\n\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "+/- plusminus is a module that builds on the pyparsing infixNotation helper method to build easy-to-code and",
    "version": "0.7.0",
    "split_keywords": [
        "python",
        "infix",
        "notation",
        "arithmetic",
        "safe",
        "eval"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "bb3fe61c9d73b447ce961e7f1a6efa2a",
                "sha256": "2889d75b99c1d29a79bce8f92f49c4c19f0fa4715d96d12238123a1f10751f30"
            },
            "downloads": -1,
            "filename": "plusminus-0.7.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "bb3fe61c9d73b447ce961e7f1a6efa2a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 36292,
            "upload_time": "2022-12-19T04:15:31",
            "upload_time_iso_8601": "2022-12-19T04:15:31.518007Z",
            "url": "https://files.pythonhosted.org/packages/62/85/39b699c97f609d27b372658a26d57e9f361dc463926bcf594ef23d2bfa49/plusminus-0.7.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "574398fe331f5ccce2dd68d80b812cb9",
                "sha256": "9e769188b6784b6fae3c8e1266940d8d2bc5b733c28fe0e07825d9e5219fcecd"
            },
            "downloads": -1,
            "filename": "plusminus-0.7.0.tar.gz",
            "has_sig": false,
            "md5_digest": "574398fe331f5ccce2dd68d80b812cb9",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 38608,
            "upload_time": "2022-12-19T04:15:33",
            "upload_time_iso_8601": "2022-12-19T04:15:33.148964Z",
            "url": "https://files.pythonhosted.org/packages/61/d3/f9a96cd35a04ccdc9dea30d766ac66cb7ff9f66eff722f977a786bf2a1e6/plusminus-0.7.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-12-19 04:15:33",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "pyparsing",
    "github_project": "plusminus",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "plusminus"
}
        
Elapsed time: 0.02004s