Expression Evaluator

This page uses PEG.js to parse a Sketchpad expression string and convert it to both an equivalent javascript function and a MathML display of the expression. The page uses MathJax to display the expression.

The raw Sketchpad expression string should, except for object references, match the syntax displayed in the "calculate" dialog in Sketchpad. Object references are references to other sketchpad objects such as measurements, functions, or other calculations. These are designated the raw Sketchpad syntax with an '@' sign followed by a unique word composed of letters, digits, and underscores.

Function:

MFS:

MathML:

Raw HTML:

HTML:

Execution:

Result:

json:

Errors:

Description Expression Arguments Expect Value Function MFS MathML HTML isSimple unit
A constant5 5
A constant-5.25 -5.25
A reference@a {"a":{"uValue":4}}4
A variablex {"x":4}4
Special Constantpi 3.1416
Special Constantπ 3.1416
Special Constante 2.7183
parentheses(5) 5
Addition1+2 3
Subtraction1-2 -1
Unary minus-pi -3.1416
Unary minus-(1+2) -3
Multiplication1*2 2
Division1/2 0.5
Exponent1^2 1
Order of evaluation 2*10^-1/4 0.05
Order of evaluation 3*10^2/4 75
Order of evaluation 2*3/5 1.2
Order of evaluation 2/3*5 3.3333
Sinesin(180) 0
Cosinecos(0) 1
Tangenttan(0) 0
Square RootArcsin(0.5) 30
Square RootArccos(0) 90
Square RootArctan(1) 45
Absolute valueabs(-2) 2
Square Rootsqrt(4) 2
Natural logln(2) 0.6931
Log base 10log(10) 1
Signsgn(-2) -1
Roundround(2.1) 2
Truncatetrunc(2.1) 2
A constant length5 cm 5
A constant length 5 pixels 0.1763
A constant length5 in. 12.6999
A constant angle 5 radians 286.4789
A constant angle 5
An equation f(x) = x^2+2*x+3 {"x": 10}123
An equation y = x^2+2*x+3 {"x": 10}123
An equation g(y) = y^2+2*y+3 {"y": 10}123
An equation x = y^2+2*y+3 {"y": 10}123
An equation f(θ) = θ^2+2*θ+3 {"θ": 10}123
An equation r = θ^2+2*θ+3 {"θ": 10}123
An equation g(r) = r^2+2*r+3 {"r": 10}123
An equation θ = r^2+2*r+3 {"r": 10}123
An equation f(x) = @a*x^2+@b*x+@c {"x": 4, "a": {"uValue": 1}, "b": {"uValue": 2}, "c": {"uValue": 3}}27