Algebraic expression parser and evaluator in Nim
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
examples
LICENSE
README.md
algebra.nim
algebra.nimble

README.md

Algebra Parser & Evaluator

Example

import algebra

echo evaluate(expr"1.5+1.5")
#=> 3.0

echo evaluate(expr"a/ln(b)", {"a": 5.5, "b": 2.2})
#=> 6.975646720399666

echo evaluate(expr"sin(a)", "a", [0.0, 1.0, 2.0, 3.0, 4.0, 4.5])
#=> @[0.0, 0.8414709848078965, 0.9092974268256817, 0.1411200080598672, -0.7568024953079282, -0.977530117665097]

Parsing Details

  • After a function name (e.g. sin, cos, ln, etc.), a left parenthesis (() must always immediately follow.
  • The expr procedure returns the tokens after the Shunting-Yard algorithm is applied.