@cortex-js/compute-engine 0.32.1 → 0.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/compute-engine.esm.js +39456 -28560
- package/dist/compute-engine.min.esm.js +80 -59
- package/dist/compute-engine.min.umd.js +80 -59
- package/dist/compute-engine.umd.js +39464 -28585
- package/dist/math-json.esm.js +2 -2
- package/dist/math-json.min.esm.js +2 -130
- package/dist/math-json.min.umd.js +2 -2
- package/dist/math-json.umd.js +2 -2
- package/dist/types/common/ansi-codes.d.ts +1 -1
- package/dist/types/common/configuration-change.d.ts +1 -1
- package/dist/types/common/fuzzy-string-match.d.ts +1 -1
- package/dist/types/common/grapheme-splitter.d.ts +1 -1
- package/dist/types/common/interruptible.d.ts +1 -1
- package/dist/types/common/one-of.d.ts +2 -1
- package/dist/types/common/signals.d.ts +1 -1
- package/dist/types/common/type/ast-nodes.d.ts +1 -1
- package/dist/types/common/type/boxed-type.d.ts +1 -1
- package/dist/types/common/type/lexer.d.ts +1 -1
- package/dist/types/common/type/parse.d.ts +1 -1
- package/dist/types/common/type/parser.d.ts +1 -1
- package/dist/types/common/type/primitive.d.ts +1 -1
- package/dist/types/common/type/reduce.d.ts +12 -0
- package/dist/types/common/type/serialize.d.ts +1 -1
- package/dist/types/common/type/subtype.d.ts +1 -1
- package/dist/types/common/type/type-builder.d.ts +1 -1
- package/dist/types/common/type/types.d.ts +1 -1
- package/dist/types/common/type/utils.d.ts +1 -1
- package/dist/types/common/utils.d.ts +1 -1
- package/dist/types/compute-engine/assume.d.ts +37 -1
- package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +6 -3
- package/dist/types/compute-engine/boxed-expression/apply.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/arithmetic-add.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/arithmetic-mul-div.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/arithmetic-power.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/ascii-math.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/box.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +6 -2
- package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-operator-definition.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +5 -1
- package/dist/types/compute-engine/boxed-expression/boxed-tensor.d.ts +2 -1
- package/dist/types/compute-engine/boxed-expression/boxed-value-definition.d.ts +5 -1
- package/dist/types/compute-engine/boxed-expression/cache.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/canonical-utils.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/canonical.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/compare.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/expand.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/factor.d.ts +47 -1
- package/dist/types/compute-engine/boxed-expression/flatten.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/hold.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/match.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/negate.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/numerics.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/order.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/polynomials.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/product.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/rules.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/serialize.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/sgn.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/simplify.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/solve-linear-system.d.ts +60 -0
- package/dist/types/compute-engine/boxed-expression/solve.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/terms.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/trigonometry.d.ts +1 -2
- package/dist/types/compute-engine/boxed-expression/utils.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/validate.d.ts +1 -1
- package/dist/types/compute-engine/collection-utils.d.ts +1 -1
- package/dist/types/compute-engine/compilation/base-compiler.d.ts +1 -1
- package/dist/types/compute-engine/compilation/glsl-target.d.ts +63 -0
- package/dist/types/compute-engine/compilation/javascript-target.d.ts +1 -1
- package/dist/types/compute-engine/compilation/types.d.ts +58 -1
- package/dist/types/compute-engine/cost-function.d.ts +1 -1
- package/dist/types/compute-engine/function-utils.d.ts +1 -1
- package/dist/types/compute-engine/global-types.d.ts +381 -10
- package/dist/types/compute-engine/index.d.ts +186 -3
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-complex.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-linear-algebra.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-relational-operators.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-statistics.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +10 -1
- package/dist/types/compute-engine/latex-syntax/parse-symbol.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/parse.d.ts +21 -1
- package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/serializer.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/types.d.ts +33 -3
- package/dist/types/compute-engine/latex-syntax/utils.d.ts +1 -1
- package/dist/types/compute-engine/library/arithmetic.d.ts +1 -1
- package/dist/types/compute-engine/library/calculus.d.ts +1 -1
- package/dist/types/compute-engine/library/collections.d.ts +1 -1
- package/dist/types/compute-engine/library/combinatorics.d.ts +1 -1
- package/dist/types/compute-engine/library/complex.d.ts +1 -1
- package/dist/types/compute-engine/library/control-structures.d.ts +1 -1
- package/dist/types/compute-engine/library/core.d.ts +1 -1
- package/dist/types/compute-engine/library/invisible-operator.d.ts +1 -1
- package/dist/types/compute-engine/library/library.d.ts +1 -1
- package/dist/types/compute-engine/library/linear-algebra.d.ts +1 -1
- package/dist/types/compute-engine/library/logic-analysis.d.ts +189 -4
- package/dist/types/compute-engine/library/logic-utils.d.ts +1 -5
- package/dist/types/compute-engine/library/logic.d.ts +1 -1
- package/dist/types/compute-engine/library/number-theory.d.ts +1 -1
- package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
- package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
- package/dist/types/compute-engine/library/relational-operator.d.ts +1 -1
- package/dist/types/compute-engine/library/sets.d.ts +1 -1
- package/dist/types/compute-engine/library/statistics.d.ts +1 -1
- package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
- package/dist/types/compute-engine/library/utils.d.ts +60 -2
- package/dist/types/compute-engine/numeric-value/big-numeric-value.d.ts +1 -1
- package/dist/types/compute-engine/numeric-value/exact-numeric-value.d.ts +1 -1
- package/dist/types/compute-engine/numeric-value/machine-numeric-value.d.ts +1 -1
- package/dist/types/compute-engine/numeric-value/types.d.ts +1 -1
- package/dist/types/compute-engine/numerics/bigint.d.ts +1 -1
- package/dist/types/compute-engine/numerics/expression.d.ts +1 -1
- package/dist/types/compute-engine/numerics/interval.d.ts +1 -1
- package/dist/types/compute-engine/numerics/monte-carlo.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric.d.ts +2 -2
- package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
- package/dist/types/compute-engine/numerics/rationals.d.ts +1 -1
- package/dist/types/compute-engine/numerics/richardson.d.ts +1 -1
- package/dist/types/compute-engine/numerics/special-functions.d.ts +1 -1
- package/dist/types/compute-engine/numerics/statistics.d.ts +1 -1
- package/dist/types/compute-engine/numerics/strings.d.ts +1 -1
- package/dist/types/compute-engine/numerics/types.d.ts +2 -1
- package/dist/types/compute-engine/oeis.d.ts +85 -0
- package/dist/types/compute-engine/sequence.d.ts +120 -0
- package/dist/types/compute-engine/symbolic/antiderivative.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/derivative.d.ts +17 -2
- package/dist/types/compute-engine/symbolic/distribute.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/fu-cost.d.ts +33 -0
- package/dist/types/compute-engine/symbolic/fu-transforms.d.ts +130 -0
- package/dist/types/compute-engine/symbolic/fu.d.ts +48 -0
- package/dist/types/compute-engine/symbolic/simplify-abs.d.ts +12 -0
- package/dist/types/compute-engine/symbolic/simplify-divide.d.ts +15 -0
- package/dist/types/compute-engine/symbolic/simplify-hyperbolic.d.ts +2 -0
- package/dist/types/compute-engine/symbolic/simplify-infinity.d.ts +14 -0
- package/dist/types/compute-engine/symbolic/simplify-log.d.ts +15 -0
- package/dist/types/compute-engine/symbolic/simplify-power.d.ts +15 -0
- package/dist/types/compute-engine/symbolic/simplify-product.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/simplify-rules.d.ts +1 -11
- package/dist/types/compute-engine/symbolic/simplify-sum.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/simplify-trig.d.ts +2 -0
- package/dist/types/compute-engine/tensor/tensor-fields.d.ts +1 -1
- package/dist/types/compute-engine/tensor/tensors.d.ts +3 -3
- package/dist/types/compute-engine/types.d.ts +1 -1
- package/dist/types/compute-engine.d.ts +5 -1
- package/dist/types/math-json/symbols.d.ts +1 -1
- package/dist/types/math-json/types.d.ts +1 -1
- package/dist/types/math-json/utils.d.ts +1 -1
- package/dist/types/math-json.d.ts +2 -2
- package/package.json +2 -2
|
@@ -1,19 +1,26 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.34.0 */
|
|
2
2
|
import { Decimal } from 'decimal.js';
|
|
3
3
|
import { Type, TypeResolver, TypeString } from '../common/type/types';
|
|
4
4
|
import { BoxedType } from '../common/type/boxed-type';
|
|
5
5
|
import type { OneOf } from '../common/one-of';
|
|
6
6
|
import { ConfigurationChangeListener } from '../common/configuration-change';
|
|
7
7
|
import type { Expression, MathJsonSymbol, MathJsonNumberObject } from '../math-json/types';
|
|
8
|
-
import type { ValueDefinition, OperatorDefinition, AngularUnit, AssignValue, AssumeResult, BoxedExpression, BoxedRule, BoxedRuleSet, BoxedSubstitution, CanonicalOptions, SymbolDefinitions, Metadata, Rule, Scope, EvalContext, SemiBoxedExpression, ComputeEngine as IComputeEngine, BoxedDefinition, SymbolDefinition } from './global-types';
|
|
8
|
+
import type { ValueDefinition, OperatorDefinition, AngularUnit, AssignValue, AssumeResult, BoxedExpression, BoxedRule, BoxedRuleSet, BoxedSubstitution, CanonicalOptions, SymbolDefinitions, Metadata, Rule, Scope, EvalContext, SemiBoxedExpression, ComputeEngine as IComputeEngine, BoxedDefinition, SymbolDefinition, SequenceDefinition, SequenceStatus, SequenceInfo, OEISSequenceInfo, OEISOptions } from './global-types';
|
|
9
9
|
import type { LatexDictionaryEntry, LatexString, LibraryCategory, ParseLatexOptions } from './latex-syntax/types';
|
|
10
10
|
import { type IndexedLatexDictionary } from './latex-syntax/dictionary/definitions';
|
|
11
11
|
import type { BigNum, Rational } from './numerics/types';
|
|
12
12
|
import { ExactNumericValueData, NumericValue, NumericValueData } from './numeric-value/types';
|
|
13
13
|
import { validatePattern } from './boxed-expression/boxed-patterns';
|
|
14
|
+
import { factor, factorPerfectSquare, factorDifferenceOfSquares, factorQuadratic, factorPolynomial } from './boxed-expression/factor';
|
|
14
15
|
import './boxed-expression/serialize';
|
|
15
16
|
export * from './global-types';
|
|
16
17
|
export { validatePattern };
|
|
18
|
+
export { factor, factorPerfectSquare, factorDifferenceOfSquares, factorQuadratic, factorPolynomial, };
|
|
19
|
+
export type { CompileTarget, CompiledOperators, CompiledFunctions, CompilationOptions, CompiledExecutable, LanguageTarget, TargetSource, CompiledFunction, } from './compilation/types';
|
|
20
|
+
export { JavaScriptTarget } from './compilation/javascript-target';
|
|
21
|
+
export { GLSLTarget } from './compilation/glsl-target';
|
|
22
|
+
export { BaseCompiler } from './compilation/base-compiler';
|
|
23
|
+
import type { LanguageTarget } from './compilation/types';
|
|
17
24
|
/**
|
|
18
25
|
*
|
|
19
26
|
* To use the Compute Engine, create a `ComputeEngine` instance:
|
|
@@ -101,6 +108,8 @@ export declare class ComputeEngine implements IComputeEngine {
|
|
|
101
108
|
private _configurationChangeTracker;
|
|
102
109
|
/** @internal */
|
|
103
110
|
private _cost?;
|
|
111
|
+
/** @internal Registry of compilation targets */
|
|
112
|
+
private _compilationTargets;
|
|
104
113
|
/** @internal */
|
|
105
114
|
private _commonSymbols;
|
|
106
115
|
/** @internal */
|
|
@@ -240,6 +249,43 @@ export declare class ComputeEngine implements IComputeEngine {
|
|
|
240
249
|
_reset(): void;
|
|
241
250
|
/** @internal */
|
|
242
251
|
listenToConfigurationChange(tracker: ConfigurationChangeListener): () => void;
|
|
252
|
+
/**
|
|
253
|
+
* Register a custom compilation target.
|
|
254
|
+
*
|
|
255
|
+
* This allows you to compile mathematical expressions to different target
|
|
256
|
+
* languages beyond the built-in JavaScript and GLSL targets.
|
|
257
|
+
*
|
|
258
|
+
* @param name - The name of the target (e.g., 'python', 'wgsl', 'matlab')
|
|
259
|
+
* @param target - The LanguageTarget implementation
|
|
260
|
+
*
|
|
261
|
+
* @example
|
|
262
|
+
* ```typescript
|
|
263
|
+
* import { ComputeEngine, GLSLTarget } from '@cortex-js/compute-engine';
|
|
264
|
+
*
|
|
265
|
+
* const ce = new ComputeEngine();
|
|
266
|
+
*
|
|
267
|
+
* // Register a custom target
|
|
268
|
+
* class PythonTarget implements LanguageTarget {
|
|
269
|
+
* // Implementation...
|
|
270
|
+
* }
|
|
271
|
+
*
|
|
272
|
+
* ce.registerCompilationTarget('python', new PythonTarget());
|
|
273
|
+
*
|
|
274
|
+
* // Use the custom target
|
|
275
|
+
* const expr = ce.parse('x^2 + y^2');
|
|
276
|
+
* const code = expr.compile({ to: 'python' });
|
|
277
|
+
* ```
|
|
278
|
+
*/
|
|
279
|
+
registerCompilationTarget(name: string, target: LanguageTarget): void;
|
|
280
|
+
/**
|
|
281
|
+
* Get a registered compilation target by name.
|
|
282
|
+
*
|
|
283
|
+
* @param name - The name of the target (e.g., 'javascript', 'glsl')
|
|
284
|
+
* @returns The LanguageTarget implementation, or undefined if not found
|
|
285
|
+
*
|
|
286
|
+
* @internal
|
|
287
|
+
*/
|
|
288
|
+
_getCompilationTarget(name: string): LanguageTarget | undefined;
|
|
243
289
|
get precision(): number;
|
|
244
290
|
/** The precision, or number of significant digits, of numeric
|
|
245
291
|
* calculations.
|
|
@@ -298,6 +344,35 @@ export declare class ComputeEngine implements IComputeEngine {
|
|
|
298
344
|
get recursionLimit(): number;
|
|
299
345
|
set recursionLimit(t: number);
|
|
300
346
|
private _recursionLimit;
|
|
347
|
+
/**
|
|
348
|
+
* Flag to prevent infinite recursion in the verify/ask/equality checking cycle.
|
|
349
|
+
*
|
|
350
|
+
* **The Problem:**
|
|
351
|
+
* When verifying equality predicates, a recursion loop can occur:
|
|
352
|
+
* 1. `verify(Equal(x, 0))` evaluates the expression
|
|
353
|
+
* 2. `Equal.evaluate()` calls `eq(x, 0)` to check equality
|
|
354
|
+
* 3. `eq()` calls `ask(['NotEqual', x, 0])` to check assumptions
|
|
355
|
+
* 4. `ask()` calls `verify(NotEqual(x, 0))` as a fallback
|
|
356
|
+
* 5. `verify()` evaluates, calling `eq()` again → infinite loop
|
|
357
|
+
*
|
|
358
|
+
* **The Solution:**
|
|
359
|
+
* - Set `_isVerifying = true` when entering `verify()`
|
|
360
|
+
* - `ask()` skips the `verify()` fallback when `_isVerifying` is true
|
|
361
|
+
* - `Equal/NotEqual` evaluate handlers check this flag to preserve 3-valued
|
|
362
|
+
* logic in verification mode while still returning False/True in normal mode
|
|
363
|
+
*
|
|
364
|
+
* @see verify() in index.ts
|
|
365
|
+
* @see ask() in index.ts
|
|
366
|
+
* @see eq() in compare.ts
|
|
367
|
+
* @see Equal/NotEqual operators in relational-operator.ts
|
|
368
|
+
*/
|
|
369
|
+
private _isVerifying;
|
|
370
|
+
/**
|
|
371
|
+
* @internal
|
|
372
|
+
* Indicates whether we're currently inside a verify() call.
|
|
373
|
+
* Used to prevent recursion and to enable 3-valued logic in verification mode.
|
|
374
|
+
*/
|
|
375
|
+
get isVerifying(): boolean;
|
|
301
376
|
get tolerance(): number;
|
|
302
377
|
/**
|
|
303
378
|
* Values smaller than the tolerance are considered to be zero for the
|
|
@@ -473,6 +548,13 @@ export declare class ComputeEngine implements IComputeEngine {
|
|
|
473
548
|
* @internal
|
|
474
549
|
*/
|
|
475
550
|
_setSymbolValue(id: MathJsonSymbol, value: BoxedExpression | boolean | number | undefined): void;
|
|
551
|
+
/**
|
|
552
|
+
* Set a value directly in the current context's values map.
|
|
553
|
+
* This is used for assumptions so that the value is scoped to the current
|
|
554
|
+
* evaluation context and is automatically removed when the scope is popped.
|
|
555
|
+
* @internal
|
|
556
|
+
*/
|
|
557
|
+
_setCurrentContextValue(id: MathJsonSymbol, value: BoxedExpression | boolean | number | undefined): void;
|
|
476
558
|
/**
|
|
477
559
|
* Declare a symbol in the current lexical scope: specify their type and
|
|
478
560
|
* other attributes, including optionally a value.
|
|
@@ -491,6 +573,107 @@ export declare class ComputeEngine implements IComputeEngine {
|
|
|
491
573
|
declare(symbols: {
|
|
492
574
|
[id: string]: Type | TypeString | Partial<SymbolDefinition>;
|
|
493
575
|
}): IComputeEngine;
|
|
576
|
+
/**
|
|
577
|
+
* Declare a sequence with a recurrence relation.
|
|
578
|
+
*
|
|
579
|
+
* @example
|
|
580
|
+
* ```typescript
|
|
581
|
+
* // Fibonacci sequence
|
|
582
|
+
* ce.declareSequence('F', {
|
|
583
|
+
* base: { 0: 0, 1: 1 },
|
|
584
|
+
* recurrence: 'F_{n-1} + F_{n-2}',
|
|
585
|
+
* });
|
|
586
|
+
* ce.parse('F_{10}').evaluate(); // → 55
|
|
587
|
+
* ```
|
|
588
|
+
*/
|
|
589
|
+
declareSequence(name: string, def: SequenceDefinition): IComputeEngine;
|
|
590
|
+
/**
|
|
591
|
+
* Get the status of a sequence definition.
|
|
592
|
+
*
|
|
593
|
+
* @example
|
|
594
|
+
* ```typescript
|
|
595
|
+
* ce.parse('F_0 := 0').evaluate();
|
|
596
|
+
* ce.getSequenceStatus('F');
|
|
597
|
+
* // → { status: 'pending', hasBase: true, hasRecurrence: false, baseIndices: [0] }
|
|
598
|
+
* ```
|
|
599
|
+
*/
|
|
600
|
+
getSequenceStatus(name: string): SequenceStatus;
|
|
601
|
+
/**
|
|
602
|
+
* Get information about a defined sequence.
|
|
603
|
+
* Returns `undefined` if the symbol is not a sequence.
|
|
604
|
+
*/
|
|
605
|
+
getSequence(name: string): SequenceInfo | undefined;
|
|
606
|
+
/**
|
|
607
|
+
* List all defined sequences.
|
|
608
|
+
*/
|
|
609
|
+
listSequences(): string[];
|
|
610
|
+
/**
|
|
611
|
+
* Check if a symbol is a defined sequence.
|
|
612
|
+
*/
|
|
613
|
+
isSequence(name: string): boolean;
|
|
614
|
+
/**
|
|
615
|
+
* Clear the memoization cache for a sequence.
|
|
616
|
+
* If no name is provided, clears caches for all sequences.
|
|
617
|
+
*/
|
|
618
|
+
clearSequenceCache(name?: string): void;
|
|
619
|
+
/**
|
|
620
|
+
* Get the memoization cache for a sequence.
|
|
621
|
+
* Returns a Map of index → value, or `undefined` if not a sequence or memoization is disabled.
|
|
622
|
+
*
|
|
623
|
+
* For single-index sequences, keys are numbers.
|
|
624
|
+
* For multi-index sequences, keys are comma-separated strings (e.g., '5,2').
|
|
625
|
+
*/
|
|
626
|
+
getSequenceCache(name: string): Map<number | string, BoxedExpression> | undefined;
|
|
627
|
+
/**
|
|
628
|
+
* Generate a list of sequence terms from start to end (inclusive).
|
|
629
|
+
*
|
|
630
|
+
* @param name - The sequence name
|
|
631
|
+
* @param start - Starting index (inclusive)
|
|
632
|
+
* @param end - Ending index (inclusive)
|
|
633
|
+
* @param step - Step size (default: 1)
|
|
634
|
+
* @returns Array of BoxedExpressions, or undefined if not a sequence
|
|
635
|
+
*
|
|
636
|
+
* @example
|
|
637
|
+
* ```typescript
|
|
638
|
+
* ce.declareSequence('F', { base: { 0: 0, 1: 1 }, recurrence: 'F_{n-1} + F_{n-2}' });
|
|
639
|
+
* ce.getSequenceTerms('F', 0, 10);
|
|
640
|
+
* // → [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
|
|
641
|
+
* ```
|
|
642
|
+
*/
|
|
643
|
+
getSequenceTerms(name: string, start: number, end: number, step?: number): BoxedExpression[] | undefined;
|
|
644
|
+
/**
|
|
645
|
+
* Look up sequences in OEIS by their terms.
|
|
646
|
+
*
|
|
647
|
+
* @param terms - Array of sequence terms to search for
|
|
648
|
+
* @param options - Optional configuration (timeout, maxResults)
|
|
649
|
+
* @returns Promise resolving to array of matching sequences
|
|
650
|
+
*
|
|
651
|
+
* @example
|
|
652
|
+
* ```typescript
|
|
653
|
+
* const results = await ce.lookupOEIS([0, 1, 1, 2, 3, 5, 8, 13]);
|
|
654
|
+
* // → [{ id: 'A000045', name: 'Fibonacci numbers', ... }]
|
|
655
|
+
* ```
|
|
656
|
+
*/
|
|
657
|
+
lookupOEIS(terms: (number | BoxedExpression)[], options?: OEISOptions): Promise<OEISSequenceInfo[]>;
|
|
658
|
+
/**
|
|
659
|
+
* Check if a defined sequence matches an OEIS sequence.
|
|
660
|
+
*
|
|
661
|
+
* @param name - Name of the defined sequence
|
|
662
|
+
* @param count - Number of terms to check (default: 10)
|
|
663
|
+
* @param options - Optional configuration
|
|
664
|
+
* @returns Promise with match results including OEIS matches and generated terms
|
|
665
|
+
*
|
|
666
|
+
* @example
|
|
667
|
+
* ```typescript
|
|
668
|
+
* ce.declareSequence('F', { base: { 0: 0, 1: 1 }, recurrence: 'F_{n-1} + F_{n-2}' });
|
|
669
|
+
* const result = await ce.checkSequenceOEIS('F', 10);
|
|
670
|
+
* // → { matches: [{ id: 'A000045', name: 'Fibonacci numbers', ... }], terms: [0, 1, 1, ...] }
|
|
671
|
+
* ```
|
|
672
|
+
*/
|
|
673
|
+
checkSequenceOEIS(name: string, count?: number, options?: OEISOptions): Promise<{
|
|
674
|
+
matches: OEISSequenceInfo[];
|
|
675
|
+
terms: number[];
|
|
676
|
+
}>;
|
|
494
677
|
/**
|
|
495
678
|
* Return an evaluation context in which the symbol is defined.
|
|
496
679
|
*/
|
|
@@ -632,7 +815,7 @@ export declare class ComputeEngine implements IComputeEngine {
|
|
|
632
815
|
* Answer a query based on the current assumptions.
|
|
633
816
|
*
|
|
634
817
|
*/
|
|
635
|
-
verify(
|
|
818
|
+
verify(query: BoxedExpression): boolean | undefined;
|
|
636
819
|
/**
|
|
637
820
|
* Add an assumption.
|
|
638
821
|
*
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.34.0 */
|
|
2
2
|
export declare const DEFINITIONS_ALGEBRA: LatexDictionary;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.34.0 */
|
|
2
2
|
export declare const DEFINITIONS_ARITHMETIC: LatexDictionary;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.34.0 */
|
|
2
2
|
export declare const DEFINITIONS_CALCULUS: LatexDictionary;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.34.0 */
|
|
2
2
|
export declare const DEFINITIONS_COMPLEX: LatexDictionary;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.34.0 */
|
|
2
2
|
export declare const DEFINITIONS_LINEAR_ALGEBRA: LatexDictionary;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.34.0 */
|
|
2
2
|
export declare const DEFINITIONS_LOGIC: LatexDictionary;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.34.0 */
|
|
2
2
|
export declare const DEFINITIONS_OTHERS: LatexDictionary;
|
package/dist/types/compute-engine/latex-syntax/dictionary/definitions-relational-operators.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.34.0 */
|
|
2
2
|
export declare const DEFINITIONS_INEQUALITIES: LatexDictionaryEntry[];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.34.0 */
|
|
2
2
|
export declare const DEFINITIONS_SETS: LatexDictionary;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.34.0 */
|
|
2
2
|
export declare const DEFINITIONS_STATISTICS: LatexDictionary;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.34.0 */
|
|
2
2
|
export declare const DEFINITIONS_TRIGONOMETRY: LatexDictionary;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.34.0 */
|
|
2
2
|
import { Delimiter, EnvironmentParseHandler, ExpressionParseHandler, InfixParseHandler, LatexDictionary, LatexDictionaryEntry, LatexString, LatexToken, LibraryCategory, MatchfixParseHandler, PostfixParseHandler, Precedence, SerializeHandler } from '../types';
|
|
3
3
|
export type CommonEntry = {
|
|
4
4
|
/** Note: a name is required if a serialize handler is provided */
|
|
@@ -75,11 +75,20 @@ export type IndexedEnvironmentEntry = CommonEntry & {
|
|
|
75
75
|
};
|
|
76
76
|
/** @internal */
|
|
77
77
|
export declare function isIndexedEnvironmentEntry(entry: IndexedLatexDictionaryEntry): entry is IndexedEnvironmentEntry;
|
|
78
|
+
/** @internal */
|
|
78
79
|
export type IndexedLatexDictionaryEntry = IndexedExpressionEntry | IndexedFunctionEntry | IndexedSymbolEntry | IndexedMatchfixEntry | IndexedInfixEntry | IndexedPrefixEntry | IndexedPostfixEntry | IndexedEnvironmentEntry;
|
|
80
|
+
/** @internal */
|
|
79
81
|
export type IndexedLatexDictionary = {
|
|
80
82
|
ids: Map<string, IndexedLatexDictionaryEntry>;
|
|
81
83
|
lookahead: number;
|
|
82
84
|
defs: IndexedLatexDictionaryEntry[];
|
|
85
|
+
matchfixByOpen: Map<string, IndexedMatchfixEntry[]>;
|
|
86
|
+
infixByTrigger: Map<string, IndexedInfixEntry[]>;
|
|
87
|
+
prefixByTrigger: Map<string, IndexedPrefixEntry[]>;
|
|
88
|
+
postfixByTrigger: Map<string, IndexedPostfixEntry[]>;
|
|
89
|
+
functionByTrigger: Map<string, IndexedFunctionEntry[]>;
|
|
90
|
+
symbolByTrigger: Map<string, IndexedSymbolEntry[]>;
|
|
91
|
+
expressionByTrigger: Map<string, IndexedExpressionEntry[]>;
|
|
83
92
|
};
|
|
84
93
|
export declare function indexLatexDictionary(dic: Readonly<Partial<LatexDictionaryEntry>[]>, onError: (sig: WarningSignal) => void): IndexedLatexDictionary;
|
|
85
94
|
export declare const DEFAULT_LATEX_DICTIONARY: {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.34.0 */
|
|
2
2
|
import { ParseLatexOptions, LatexToken, Terminator, Parser, SymbolTable } from './types';
|
|
3
3
|
import type { IndexedLatexDictionary, IndexedLatexDictionaryEntry, IndexedInfixEntry, IndexedPostfixEntry, IndexedPrefixEntry, IndexedSymbolEntry, IndexedExpressionEntry, IndexedFunctionEntry } from './dictionary/definitions';
|
|
4
4
|
import { BoxedType } from '../../common/type/boxed-type';
|
|
@@ -69,6 +69,7 @@ export declare class _Parser implements Parser {
|
|
|
69
69
|
private _peekCounter;
|
|
70
70
|
constructor(tokens: LatexToken[], dictionary: IndexedLatexDictionary, options: Readonly<ParseLatexOptions>);
|
|
71
71
|
getSymbolType(id: MathJsonSymbol): BoxedType;
|
|
72
|
+
hasSubscriptEvaluate(id: MathJsonSymbol): boolean;
|
|
72
73
|
get peek(): LatexToken;
|
|
73
74
|
nextToken(): LatexToken;
|
|
74
75
|
get atEnd(): boolean;
|
|
@@ -88,6 +89,18 @@ export declare class _Parser implements Parser {
|
|
|
88
89
|
removeBoundary(): void;
|
|
89
90
|
matchBoundary(): boolean;
|
|
90
91
|
boundaryError(msg: string | [string, ...Expression[]]): Expression;
|
|
92
|
+
/**
|
|
93
|
+
* Performance optimization: determines if we can skip expensive re-parsing
|
|
94
|
+
* for matchfix boundary mismatches.
|
|
95
|
+
*
|
|
96
|
+
* We skip re-parsing only for specific non-ambiguous cases where we know
|
|
97
|
+
* the boundary mismatch is due to trying interval notation on regular parens.
|
|
98
|
+
* For example, trying (] on input () - we can safely skip without re-parsing.
|
|
99
|
+
*
|
|
100
|
+
* All other cases (including |, [, and other delimiters) require re-parsing
|
|
101
|
+
* to handle nested delimiters correctly.
|
|
102
|
+
*/
|
|
103
|
+
private canSkipMatchfixReparsing;
|
|
91
104
|
latex(start: number, end?: number): string;
|
|
92
105
|
private latexAhead;
|
|
93
106
|
/**
|
|
@@ -235,6 +248,13 @@ export declare class _Parser implements Parser {
|
|
|
235
248
|
*/
|
|
236
249
|
private parseFunction;
|
|
237
250
|
parseSymbol(until?: Readonly<Terminator>): Expression | null;
|
|
251
|
+
/**
|
|
252
|
+
* In non-strict mode, try to parse a bare function name followed by parentheses.
|
|
253
|
+
* This allows syntax like `sin(x)` instead of requiring `\sin(x)`.
|
|
254
|
+
*
|
|
255
|
+
* Returns the parsed function call or null if not a bare function.
|
|
256
|
+
*/
|
|
257
|
+
private tryParseBareFunction;
|
|
238
258
|
/**
|
|
239
259
|
* Parse a sequence superfix/subfix operator, e.g. `^{*}`
|
|
240
260
|
*
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.34.0 */
|
|
2
2
|
import type { Expression, MathJsonSymbol } from '../../math-json/types';
|
|
3
3
|
import { BoxedType, TypeString } from '../types';
|
|
4
4
|
import type { IndexedLatexDictionary, IndexedLatexDictionaryEntry } from './dictionary/definitions';
|
|
@@ -365,7 +365,7 @@ export type FunctionEntry = BaseEntry & Trigger & {
|
|
|
365
365
|
* A dictionary entry is a record that maps a LaTeX token or string of tokens
|
|
366
366
|
* ( a trigger) to a MathJSON expression or to a parsing handler.
|
|
367
367
|
*
|
|
368
|
-
* Set the
|
|
368
|
+
* Set the `ComputeEngine.latexDictionary` property to an array of
|
|
369
369
|
* dictionary entries to define custom LaTeX parsing and serialization.
|
|
370
370
|
*
|
|
371
371
|
* @category Latex Parsing and Serialization
|
|
@@ -480,6 +480,16 @@ export type NumberSerializationFormat = NumberFormat & {
|
|
|
480
480
|
* @category Latex Parsing and Serialization
|
|
481
481
|
*/
|
|
482
482
|
export type ParseLatexOptions = NumberFormat & {
|
|
483
|
+
/**
|
|
484
|
+
* Controls the strictness of LaTeX parsing:
|
|
485
|
+
*
|
|
486
|
+
* - `true`: Strict LaTeX syntax required (e.g., `\sin{x}`, `x^{n+1}`)
|
|
487
|
+
* - `false`: Accept relaxed Math-ASCII/Typst-like syntax in addition to
|
|
488
|
+
* LaTeX (e.g., `sin(x)`, `x^(n+1)`)
|
|
489
|
+
*
|
|
490
|
+
* **Default**: `true`
|
|
491
|
+
*/
|
|
492
|
+
strict: boolean;
|
|
483
493
|
/**
|
|
484
494
|
* If true, ignore space characters in math mode.
|
|
485
495
|
*
|
|
@@ -513,6 +523,13 @@ export type ParseLatexOptions = NumberFormat & {
|
|
|
513
523
|
*
|
|
514
524
|
*/
|
|
515
525
|
getSymbolType: (symbol: MathJsonSymbol) => BoxedType;
|
|
526
|
+
/**
|
|
527
|
+
* This handler is invoked when the parser needs to determine if a symbol
|
|
528
|
+
* has a custom subscript evaluation handler. If true, subscripts on this
|
|
529
|
+
* symbol will be kept as `Subscript` expressions rather than being absorbed
|
|
530
|
+
* into a compound symbol name.
|
|
531
|
+
*/
|
|
532
|
+
hasSubscriptEvaluate?: (symbol: MathJsonSymbol) => boolean;
|
|
516
533
|
/** This handler is invoked when the parser encounters an unexpected token.
|
|
517
534
|
*
|
|
518
535
|
* The `lhs` argument is the left-hand side of the token, if any.
|
|
@@ -563,6 +580,15 @@ export type ParseLatexOptions = NumberFormat & {
|
|
|
563
580
|
* // parses as: ∀x. (P(x) → Q(x))
|
|
564
581
|
*/
|
|
565
582
|
quantifierScope: 'tight' | 'loose';
|
|
583
|
+
/**
|
|
584
|
+
* The variable used for time derivatives in Newton notation
|
|
585
|
+
* (`\dot{x}`, `\ddot{x}`, etc.).
|
|
586
|
+
*
|
|
587
|
+
* When parsing `\dot{x}`, it will be interpreted as `["D", "x", timeDerivativeVariable]`.
|
|
588
|
+
*
|
|
589
|
+
* **Default:** `"t"`
|
|
590
|
+
*/
|
|
591
|
+
timeDerivativeVariable: string;
|
|
566
592
|
};
|
|
567
593
|
/**
|
|
568
594
|
*
|
|
@@ -578,8 +604,12 @@ export type ParseLatexOptions = NumberFormat & {
|
|
|
578
604
|
* @category Latex Parsing and Serialization
|
|
579
605
|
*/
|
|
580
606
|
export interface Parser {
|
|
581
|
-
readonly options:
|
|
607
|
+
readonly options: Readonly<ParseLatexOptions>;
|
|
582
608
|
getSymbolType(id: MathJsonSymbol): BoxedType;
|
|
609
|
+
/**
|
|
610
|
+
* Check if a symbol has a custom subscript evaluation handler.
|
|
611
|
+
*/
|
|
612
|
+
hasSubscriptEvaluate(id: MathJsonSymbol): boolean;
|
|
583
613
|
pushSymbolTable(): void;
|
|
584
614
|
popSymbolTable(): void;
|
|
585
615
|
addSymbol(id: MathJsonSymbol, type: BoxedType | TypeString): void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.34.0 */
|
|
2
2
|
export type CanonicalArithmeticOperators = 'Add' | 'Negate' | 'Multiply' | 'Divide' | 'Power' | 'Sqrt' | 'Root' | 'Ln';
|
|
3
3
|
export declare const ARITHMETIC_LIBRARY: SymbolDefinitions[];
|
|
4
4
|
export declare function isPrime(expr: BoxedExpression): boolean | undefined;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.34.0 */
|
|
2
2
|
export declare const CALCULUS_LIBRARY: SymbolDefinitions[];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.34.0 */
|
|
2
2
|
export declare const COMBINATORICS_LIBRARY: SymbolDefinitions[];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.34.0 */
|
|
2
2
|
export declare const COMPLEX_LIBRARY: SymbolDefinitions[];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.34.0 */
|
|
2
2
|
export declare const CONTROL_STRUCTURES_LIBRARY: SymbolDefinitions[];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.34.0 */
|
|
2
2
|
export declare const CORE_LIBRARY: SymbolDefinitions[];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.34.0 */
|
|
2
2
|
export declare const LINEAR_ALGEBRA_LIBRARY: SymbolDefinitions[];
|