Skip to main content

plusminus

The plusminus package provides a ready-to-run arithmetic parser and evaluator, based on pyparsing's infix_notation helper method.

Strings containing 6-function arithmetic expressions can be parsed and evaluated using the ArithmeticParser:

from plusminus import BaseArithmeticParser

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

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

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. 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.

Metadata

Release files for plusminus 0.8.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for plusminus 0.8.1
File Size Uploaded Provenance Actions
plusminus-0.8.1.tar.gz 36.3 kB Without provenance Details for plusminus-0.8.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for plusminus 0.8.1
File Interpreter ABI Platform Actions
plusminus-0.8.1-py3-none-any.whl Python 3 none any Details for plusminus-0.8.1-py3-none-any.whl

Total release size: 64.6 kB

Release files / plusminus-0.8.1.tar.gz

Download URL plusminus-0.8.1.tar.gz
Size 36.3 kB
Tags Source
SHA-256 checksum
How to use checksums
7252664da7dffb1b405787e5bebc6a32702f48d6551a81c857a1c9ead9319ddd
BLAKE2b-256 checksum
How to use checksums
909d0a5c73502ce3b1091970b87c6b23f05dde59edf4e54bab83a51c7cf4d9a0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.2

Release files / plusminus-0.8.1-py3-none-any.whl

Download URL plusminus-0.8.1-py3-none-any.whl
Size 28.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9131e6232a996f63afe0f47a0f516e257709f4e8115911695638b958f941ffa9
BLAKE2b-256 checksum
How to use checksums
11cb0e59c6a68f2709906e845e7b462a42bb3f386e70e015d38a238d0ae94c2d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.2

Security for plusminus 0.8.1

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page