Guides

Settings

Read a setting with nerdamer.get(name) and change it with nerdamer.set(name, value).

import nerdamer from 'nerdamer';

nerdamer.set('USE_SINGLE_LETTER_VARIABLES', true);
console.log(nerdamer('2ab').text()); // 2*a*b

Change several at once with an object:

nerdamer.set({
  ALLOW_IMPLICIT_MULTIPLICATION: false,
  INDEX_BASE: 1
});
Settings apply to your whole app, not to one expression. To change one for a single calculation, save the old value and put it back afterwards:
const previous = nerdamer.get('PRECISION');
try {
  nerdamer.set('PRECISION', 40);
  console.log(nerdamer('evaluate(pi)').text());
  // 3.141592653589793238462643383279502884197

} finally {
  nerdamer.set('PRECISION', previous);
}

Reading expressions

Writing expressions shows these in context.

SettingDefaultEffect
ALLOW_IMPLICIT_MULTIPLICATIONtrueReads 2x, x(9) and (a+b)(c+d) as multiplication. Set it to false to require *.
USE_SINGLE_LETTER_VARIABLESfalseReads each letter as its own variable, so ab is a*b. Function names still work: sin(ab) is sin(a*b).
INDEX_BASE0Where vector and matrix indexes start: 0 or 1.
SUBSTITUTEtrueReplaces assigned variables with their values. With false, after a:5, a+1 stays 1+a.

Evaluation and output

SettingDefaultEffect
EVALUATEfalseGives decimal results right away: sqrt(2)+pi becomes 4.5558062159628882873 instead of staying exact. For one expression, call .evaluate() instead.
PRECISION20Significant digits for decimal results, including pi and e. Nerdamer works at this precision or higher.
SORT_TERMSfalseWrites terms in conventional order, highest power first: x^2+x+1 instead of 1+x+x^2. For one result, use expression.text({ sort: true }); see Results & output.
TEX_PERIODIC_VAR'n'The letter TeX output uses for _n, "any integer" in periodic solutions: {_n*pi} is written \left\{n \cdot \pi\right\}. Text output keeps _n.
ALLOW_RAT_SUBSfalseAllows rational multipliers in substitutions.
USE_NATIVE_DEFINTfalseComputes numeric definite integrals with ordinary JavaScript numbers: faster, but only about 16 digits instead of PRECISION.

Limits

Limits stop a calculation that would take too long. Past a limit, sum and product return the call unevaluated; the others throw an error.

SettingDefaultEffect
MAX_LOOP_ITERATIONS1000000Passes a Scripting loop may make. Stops a loop that never ends.
MAX_PRODUCT_AND_SUMMATION_ITERATION20000Terms sum and product work through one by one. Beyond it, the call comes back unevaluated.
MAX_FACTORIAL_INPUT25000Largest exact input for factorial and gamma: 30000! is an error.
MAX_DFACT_INPUT45000Largest exact input for the double factorial.
MAX_FIB_INPUT450000Largest index for fib.
MAX_NUMBER_DIGITS100000Most digits an exact number may have.
MAX_RADICAL_FACTOR_STEPS5000Effort spent factoring an integer under a root. A factor that takes longer stays under the root.

Error messages in other languages

LANGUAGE chooses the language of error messages. The default is English, 'eng'.

LanguageCode
Englisheng (default)
Spanishspa
Frenchfra
Germandeu
Portuguesepor
Italianita
Dutchnld
The language must be in your build. The standard browser bundle has only English; choosing another language there keeps English messages. A bundle built with --env language=spa,fra has English, Spanish and French, and starts in Spanish. --env language=all includes every language. See Language-targeted builds.
import nerdamer from 'nerdamer';

const previousLanguage = nerdamer.get('LANGUAGE');
try {
  nerdamer.set('LANGUAGE', 'spa');
  nerdamer('0^0');
} catch (error) {
  console.log(error.message);   // ¡0^0 no está definido!

} finally {
  nerdamer.set('LANGUAGE', previousLanguage);
}

Only error messages change. Function names and Notation stay the same in every language.

In TypeScript, the Language type lists the codes:

import type { Language } from 'nerdamer/parser';

const language: Language = 'fra';
nerdamer.set('LANGUAGE', language);

From the parser API

If you use nerdamer/parser directly, Parser.get and Parser.set read and change the same settings. Precision has its own methods.

import { Parser } from 'nerdamer/parser';

Parser.set('INDEX_BASE', 1);
const base = Parser.get('INDEX_BASE');

Parser.setPrecision(40);
const precision = Parser.getPrecision();

Settings with no effect

USE_FRACTIONS, ALLOW_BIGINT, REWRITE_SQRT, IMMUTABLE_VALUE_SETS and INITIALIZE_RULES can be read and set, but nothing uses them. Changing them does nothing.