Expression syntax
Nerdamer Notation is the mathematical text accepted by nerdamer('...'). The parser turns that text into expressions, equations, vectors, matrices, sets, and other supported values.
nerdamer('...'). Programmatic parser access and runtime configuration are documented separately in the API reference and Settings and configuration.Expressions
2*x + 3
2x + 3
(x+1)(x-1)
sqrt(x^2+1)
sin(x)^2 + cos(x)^2
Operator precedence and associativity
The parser applies the usual arithmetic precedence rules. Parentheses can be used whenever the grouping should be explicit.
2+3*4 // 14
(2+3)*4 // 20
8/4/2 // 1
2^3^2 // 512
Multiplication and division associate from left to right. Exponentiation associates from right to left, so 2^3^2 means 2^(3^2).
Prefix signs and postfix operators also participate in precedence. For example, factorial binds to its operand before a leading minus:
-4!+1 // -23
(3!)! // 720
Implicit multiplication
Implicit multiplication is enabled by default. The parser can infer multiplication between adjacent values in common mathematical forms:
2x // 2*x
x(9) // 9*x
(a+b)(c+d) // (a+b)*(c+d)
2+4(9+1) // 42
y^-2z // y^-2*z
A registered function name followed by parentheses is treated as a function call. An ordinary symbol followed by parentheses can instead represent multiplication, as in x(9).
Unary signs, percentage, and modulo
Repeated prefix + and - signs are parsed as unary operators. The percent sign has two forms: postfix percentage and infix modulo.
--1 // 1
5^-3 // 1/125
50% // 1/2
10%3 // 1
4%5 // 4
When % follows a value without a right operand, it means percentage. Between two operands it means modulo.
Numbers and whitespace
Integers, decimal input, and scientific notation are accepted. Leading and trailing whitespace around an expression is ignored.
42
3.14159
1.234e+1 // 12.34
12.3e-1 // 1.23
x + 1
Symbols and aliases
Variable names can contain more than one letter by default, so velocity and xy are each single symbols unless single-letter-variable mode is enabled.
Common mathematical aliases normalize to the library's built-in names:
π + pi // 2*pi ∞ + Inf // Inf
The names e, pi, i, _n, and all have built-in meanings and cannot be used as assignment targets in Nerdamer Scripting. e and pi are mathematical constants, i is the imaginary unit by default, _n is used for solver-generated indexed families, and all is used for non-finite solution results.
Known caveats
i is the imaginary unit by default
An assignment such as i:0 throws because the active imaginary-unit symbol is reserved. If an application needs i as an ordinary variable, move the imaginary unit to another unused symbol through the parser API:
import nerdamer from 'nerdamer';
import { Parser } from 'nerdamer/parser';
Parser.setImaginary('_'); // Free up i
console.log(nerdamer('i:x; i*i').text()); // x^2
_ is the reserved imaginary-unit symbol. Complex-number operations parsed afterward will treat _ as the imaginary unit. Choose a replacement symbol that the application will not otherwise use. The change is shared runtime state.Multiple statements need semicolons
Newlines, tabs, and carriage returns are parser whitespace, not statement separators. When one call contains multiple root statements, separate them with ; even when each statement appears on its own line.
f(x):=x^2+1;
f(12)
Assignments persist until they are removed
Nerdamer Scripting assignments are stored as parser-known values and are substituted into later parses while substitution is enabled. Use unassign(name) to remove one scripting assignment, nerdamer.clearVars() to clear all stored variables from application code, or let(...) when the binding should be local.
nerdamer('x:4');
nerdamer('x^2').text(); // 16
nerdamer('unassign(x)');
nerdamer('x^2').text(); // x^2
Parsing is symbolic unless evaluation is requested
Ordinary parsing preserves exact symbolic values when possible. For example, nerdamer('sqrt(2)') stays symbolic rather than immediately becoming a decimal approximation. Call .evaluate() when numerical evaluation is wanted.
const exact = nerdamer('sqrt(2)');
const numeric = exact.evaluate();
Parser configuration is shared
Settings, registered constants and operators, numeric precision, and the imaginary-unit symbol are shared runtime state. Parser.create() creates another parser object with its own known-value table, but it does not create an isolated parser configuration. Changes made through APIs such as Parser.setImaginary(...) affect subsequent parsing elsewhere in the same runtime.
Equations
x = y + 2
x^2 - 4 = 0
Equations are structured parser values rather than ordinary expressions. Functions that accept equations say so in their reference pages.
Collections and linear algebra
[a, b, c]
{a, b, c}
matrix([1,2],[3,4])
dot([a,b],[x,y])
Square brackets create vectors. Curly braces create sets unless their contents use dictionary key/value syntax. Matrix construction and linear-algebra operations are available through their notation functions.
Indexing
Vector and matrix element access uses bracket notation. Public indices are zero-based by default; INDEX_BASE can switch the notation to one-based indexing.
v: [a,b,c];
v[0]
The assignment above is Nerdamer Scripting, so statements are separated with a semicolon. See Nerdamer Scripting for assignments, blocks, loops, and user-defined functions.
Functions
Functions such as factor, diff, solve, and matrix are part of Nerdamer Notation when they appear inside parsed input. Browse the function reference for the generated list.
Malformed input
The parser rejects incomplete or unbalanced notation rather than guessing what was intended. Examples such as the following are syntax errors:
cos(
(x+1))
/2
5+
Syntax-affecting settings
Three shared settings directly change how notation is interpreted:
nerdamer.set('ALLOW_IMPLICIT_MULTIPLICATION', false);
nerdamer.set('USE_SINGLE_LETTER_VARIABLES', true);
nerdamer.set('INDEX_BASE', 1);
ALLOW_IMPLICIT_MULTIPLICATION controls inferred multiplication. USE_SINGLE_LETTER_VARIABLES changes a name such as ab from one symbol to a*b. INDEX_BASE changes the public base used for vector and matrix indexing.
These settings are shared runtime state, not options local to a single expression. See Settings and configuration for defaults, temporary-setting patterns, precision, evaluation settings, iteration limits, and the complete currently active settings list.
