Skip to content
pubscout

math_expressions

3.2.0, released 4 months ago by leonhardt.co.nz

Parse and evaluate mathematical expressions in real, vector, and interval contexts.

WASM-ready
$ flutter pub add math_expressions
Source repository

What it does

A library for parsing strings into mathematical expressions, evaluating them with context models, simplifying them, and computing derivatives. It supports real numbers, vectors, and basic interval arithmetic.

AI-written summary of version 3.2.0, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You need to evaluate mathematical formulas entered as strings at runtime.
  • You need expression simplification or symbolic differentiation.
  • You need interval arithmetic support.

Skip it when

  • You need to parse complex numbers.
  • You need to work with N-dimensional vectors where N is greater than four.

Strengths

  • Supports real numbers, vectors, and interval arithmetic.
  • Provides expression parsing, simplification, and differentiation.
  • Extensible through custom function definitions in code.

Weaknesses

  • Parser only works for real numbers out of the box.
  • Does not support complex numbers.
  • Some evaluations in vector and interval space (especially functions) are not working yet.

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
2
ExpressionParser p = GrammarParser();
Expression exp = p.parse("(x^2 + cos(y)) / 3");
var context = ContextModel()
  ..bindVariableName('x', Number(2.0))
  ..bindVariableName('y', Number(math.pi));
var evaluator = RealEvaluator(context);
num eval = evaluator.evaluate(exp);

Alternatives

Packages that do the same job and could replace math_expressions.

  • fixed

    Fixed decimal numbers with a fixed scale, stored as BigInts, supporting math, formatting and parsing.

  • phone_numbers_parser

    Dart library for parsing, validating, and formatting international phone numbers.

  • advance_math

    A Dart library for mathematical programming, complex numbers, algebra, statistics, and geometry.

  • rsa_id_number

    Validates, parses, and generates South African ID numbers.

Works with

Packages commonly used together with math_expressions: ones it builds on, ones built on it, and its own family.