plusminus


Nameplusminus JSON
Version 0.8.1 PyPI version JSON
download
home_pageNone
Summary+/- plusminus is a module that builds on the pyparsing infixNotation helper method to build easy-to-code and easy-to-use parsers for parsing and evaluating infix arithmetic expressions. plusminus's ArithmeticParser class includes separate parse and evaluate methods, handling operator precedence, override with parentheses, presence or absence of whitespace, built-in functions, and pre-defined and user-defined variables, functions, and operators.
upload_time2024-08-03 15:20:48
maintainerNone
docs_urlNone
authorNone
requires_python>=3.7
licenseNone
keywords
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": null,
    "name": "plusminus",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": null,
    "author": null,
    "author_email": "Paul McGuire <ptmcg+pm@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/90/9d/0a5c73502ce3b1091970b87c6b23f05dde59edf4e54bab83a51c7cf4d9a0/plusminus-0.8.1.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",
    "bugtrack_url": null,
    "license": null,
    "summary": "+/- plusminus is a module that builds on the pyparsing infixNotation helper method to build easy-to-code and easy-to-use parsers for parsing and evaluating infix arithmetic expressions. plusminus's ArithmeticParser class includes separate parse and evaluate methods, handling operator precedence, override with parentheses, presence or absence of whitespace, built-in functions, and pre-defined and user-defined variables, functions, and operators.",
    "version": "0.8.1",
    "project_urls": {
        "Documentation": "https://github.com/pyparsing/plusminus/tree/master/doc",
        "Homepage": "https://github.com/pyparsing/plusminus",
        "Issues": "https://github.com/pyparsing/plusminus/issues"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "11cb0e59c6a68f2709906e845e7b462a42bb3f386e70e015d38a238d0ae94c2d",
                "md5": "c8483e69e5ff9ac8c4282df00799cc10",
                "sha256": "9131e6232a996f63afe0f47a0f516e257709f4e8115911695638b958f941ffa9"
            },
            "downloads": -1,
            "filename": "plusminus-0.8.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c8483e69e5ff9ac8c4282df00799cc10",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 28289,
            "upload_time": "2024-08-03T15:20:47",
            "upload_time_iso_8601": "2024-08-03T15:20:47.235960Z",
            "url": "https://files.pythonhosted.org/packages/11/cb/0e59c6a68f2709906e845e7b462a42bb3f386e70e015d38a238d0ae94c2d/plusminus-0.8.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "909d0a5c73502ce3b1091970b87c6b23f05dde59edf4e54bab83a51c7cf4d9a0",
                "md5": "693df639b2b80b4e618550ef9f712729",
                "sha256": "7252664da7dffb1b405787e5bebc6a32702f48d6551a81c857a1c9ead9319ddd"
            },
            "downloads": -1,
            "filename": "plusminus-0.8.1.tar.gz",
            "has_sig": false,
            "md5_digest": "693df639b2b80b4e618550ef9f712729",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 36308,
            "upload_time": "2024-08-03T15:20:48",
            "upload_time_iso_8601": "2024-08-03T15:20:48.681709Z",
            "url": "https://files.pythonhosted.org/packages/90/9d/0a5c73502ce3b1091970b87c6b23f05dde59edf4e54bab83a51c7cf4d9a0/plusminus-0.8.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-03 15:20:48",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "pyparsing",
    "github_project": "plusminus",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "tox": true,
    "lcname": "plusminus"
}
        
Elapsed time: 0.28441s