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
});
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.
| Setting | Default | Effect |
|---|---|---|
ALLOW_IMPLICIT_MULTIPLICATION | true | Reads 2x, x(9) and (a+b)(c+d) as multiplication. Set it to false to require *. |
USE_SINGLE_LETTER_VARIABLES | false | Reads each letter as its own variable, so ab is a*b. Function names still work: sin(ab) is sin(a*b). |
INDEX_BASE | 0 | Where vector and matrix indexes start: 0 or 1. |
SUBSTITUTE | true | Replaces assigned variables with their values. With false, after a:5, a+1 stays 1+a. |
Evaluation and output
| Setting | Default | Effect |
|---|---|---|
EVALUATE | false | Gives decimal results right away: sqrt(2)+pi becomes 4.5558062159628882873 instead of staying exact. For one expression, call .evaluate() instead. |
PRECISION | 20 | Significant digits for decimal results, including pi and e. Nerdamer works at this precision or higher. |
SORT_TERMS | false | Writes 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_SUBS | false | Allows rational multipliers in substitutions. |
USE_NATIVE_DEFINT | false | Computes 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.
| Setting | Default | Effect |
|---|---|---|
MAX_LOOP_ITERATIONS | 1000000 | Passes a Scripting loop may make. Stops a loop that never ends. |
MAX_PRODUCT_AND_SUMMATION_ITERATION | 20000 | Terms sum and product work through one by one. Beyond it, the call comes back unevaluated. |
MAX_FACTORIAL_INPUT | 25000 | Largest exact input for factorial and gamma: 30000! is an error. |
MAX_DFACT_INPUT | 45000 | Largest exact input for the double factorial. |
MAX_FIB_INPUT | 450000 | Largest index for fib. |
MAX_NUMBER_DIGITS | 100000 | Most digits an exact number may have. |
MAX_RADICAL_FACTOR_STEPS | 5000 | Effort 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'.
| Language | Code |
|---|---|
| English | eng (default) |
| Spanish | spa |
| French | fra |
| German | deu |
| Portuguese | por |
| Italian | ita |
| Dutch | nld |
--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.
