Py Expression Eval

screenshot of Py Expression Eval

Overview

The Python Mathematical Expression Evaluator is a library that allows users to parse, evaluate, and simplify mathematical expressions in Python. It is based on the js-expression-eval library by Matthew Crumley and has been ported to Python with modifications by @cansadadeserfeliz. The library provides functionalities to work with mathematical expressions, including evaluating expressions with variables, substituting variables, simplifying expressions, and converting expressions to strings.

Features

  • Parser Class: Contains methods to parse, evaluate, and simplify mathematical expressions.
  • Expression Object: Created using the parse method of the Parser class.
  • evaluate(): Takes a dictionary with variables as a parameter and returns the value of the expression.
  • substitute(): Replaces specified variables with a new expression.
  • variables(): Returns a list of variables for the expression.
  • simplify(): Simplifies the expression.
  • toString(): Converts the expression to a string.

Summary

The Python Mathematical Expression Evaluator is a useful library for working with mathematical expressions in Python. With functionalities like parsing, evaluation, simplification, and substitution of variables, it provides a convenient way to handle mathematical expressions in Python scripts or applications. The library aims to maintain similarity with its JavaScript counterpart for ease of use and integration into backend systems.