semantic-math-processor-client
Version:
Semantic Math Processor Client is a plugin for SemanticMathEditor, which allows making math calculation using Math Processor - our REST wrapper around Sympy CAS
214 lines (213 loc) • 10.8 kB
TypeScript
/**
* @hidden
* @packageDocumentation
*/
import { SympyToken } from "./sympy-parser";
import { SemanticErrorDescription, MathNode, MathNodeVisitor, MathVariable } from "semantic-math-editor";
import { PreparedSympyCall, EquivResponse, PlotInterval, Plot2dParams, SympyError, Plot3dParams, HttpClient } from "./model";
/**
* A client for [MathProcessor](https://github.com/softaria/math-processor) - simple REST service around [sympy](https://sympy.org)
* @category API
*/
export declare class SympyClient {
/**
* @hidden
*/
private readonly client;
/**
*
* @param serverAddress - http(s) address of the [MathProcessor](https://github.com/softaria/math-processor) to call
* @param http - No need to pass it when use from browser.
* if use not from broswer you need to implement HttpClient interface
* For example, consider using AxiousBasedHttpClient from /test/sympy-rest-client.ts
*/
constructor(serverAddress: string, http?: HttpClient);
/**
* Converts MathTree from the [SemanticMatEditor](https://github.com/softaria/semantic-math-editor) to {@link PreparedSympyCall}
* Alternatively returns SemanticMathEditor's {SemanticErrorDescription} (if converting is not possible)
* The SemanticErrorDescription object can be used to decorate problematic node in the SemanticMathEditor
* @param node
*/
prepareCompute(node: MathNode): PreparedSympyCall | SemanticErrorDescription;
/**
* The returned expression is equivavlent to entered one (but not equal in genearl case)
* The goal of this method is to ensure sympy understands the expression
* It is designed for use with tests. Note: **MathNode** class belongs to the [SemanticMatEditor](https://github.com/softaria/semantic-math-editor)
* @returns the expression passed as an argument as sympy has understood it
* @param sympyExpression - the result of one of {@link prepareCompute} methods
* @param log - if true, writes debug info to the console
* @throws {@link SympyError}
* @throws {@link UnsupportedSympyConstruction}
*/
mirror(sympyExpression: PreparedSympyCall, log?: boolean): Promise<MathNode>;
/**
* Checks if two passed expressions are equivalent
* Look at {@link Equiv} and {@link Simpler} for details.
* @param exp1 - the result of {@link prepareCompute}
* @param exp2 - the result of {@link prepareCompute}
* @returns an information if the expressions are eqivalent and which one is simpler
* @throws {@link SympyError}
* @throws {@link UnsupportedSympyConstruction}
*/
checkEquivalence(exp1: PreparedSympyCall, exp2: PreparedSympyCall): Promise<EquivResponse>;
/**
* @returns the result of sympy [.doit()](https://docs.sympy.org/latest/modules/core.html#sympy.core.basic.Basic.doit) method on the provided expression.
* @param sympyExpression - the result of one of {@link prepareCompute}
* @throws {@link SympyError}
* @throws {@link UnsupportedSympyConstruction}
*/
compute(sympyExpression: PreparedSympyCall): Promise<MathNode>;
/**
* @returns the result of sympy [simplify](https://docs.sympy.org/latest/modules/core.html#module-sympy.core.sympify) function on the provided expression.
* @param sympyExpression - the result of one of {@link prepareCompute}
* @param log - if true, writes debug info to the console
* @throws {@link SympyError}
* @throws {@link UnsupportedSympyConstruction}
*/
simplify(sympyExpression: PreparedSympyCall, log?: boolean): Promise<MathNode>;
/**
* Get the LaTex representation of Sympy expression.
* Note: The latex is generated by Sympy and in most cases this latex can't be pasted to the SemanticMathEditor.
* It only can be shown using KaTex or some other Latex renderer.
* @returns the LaTex representation of the given parameter.
* @param sympyExpression - the result of one of {@link prepareCompute}
* @throws {@link SympyError}
* @throws {@link UnsupportedSympyConstruction}
*/
latex(sympyExpression: PreparedSympyCall): Promise<string>;
/**
* Generates source for image with 2d plot.
* @param sympyExpressions - One or more expressions to plot. Each is the result of one of {@link prepareCompute}
* @param svg - if the result must be in SVG (if not, PNG is used)
* @param interval - optional interval where we need the plot
* @param params - additional plot parameters
* @returns URL to be added to image tag.
*/
plot2dSrc(sympyExpressions: PreparedSympyCall[], svg: boolean, interval?: PlotInterval, params?: Plot2dParams): string;
/**
* Generates source for image with 2d parametric plot.
* @param expressionPairs - one or more pair of expressions to generate the parametric plot.
* @param svg - if the result must be in SVG (if not, PNG is used)
* @param interval - optional interval where we need the plot
* @param params - additional plot parameters
* @returns URL to be added to image tag.
*/
plot2dParametricSrc(expressionPairs: {
x: PreparedSympyCall;
y: PreparedSympyCall;
}[], svg: boolean, interval?: PlotInterval, params?: Plot2dParams): string;
/**
* Generates source for image with 3d plot.
* @param sympyExpressions - one or more expressions to plot
* @param svg - if the result must be in SVG (if not, PNG is used)
* @param intervals - optional intervals for both dimensions of the 3d plot
* @param params - additional plot parameters
* @returns URL to be added to image tag.
*/
plot3dSrc(sympyExpressions: PreparedSympyCall[], svg: boolean, intervals?: {
i1: PlotInterval;
i2: PlotInterval;
}, params?: Plot3dParams): string;
/**
* Creates interval objects for plot generation methods
* @param v - a variable. Please look at [SemanticMathEditor](https://github.com/softaria/semantic-math-editor) for MathVariable meaning.
* @param start - a min value
* @param end - a max value
* @returns {@link PlotInterval} object, suitable for passing to plotting methods.
*/
preparePlotInterval(v: MathVariable, start?: number, end?: number): PlotInterval;
/**
* Generates source for image with 3d parametric plot.
* @param expressions - one or more triplet of the expressions. Each with its own iterval.
* @param svg - if the result must be in SVG (if not, PNG is used)
* @param params - additional plot parameters
* @returns URL to be added to image tag.
*/
plot3dParametricLineSrc(expressions: {
x: PreparedSympyCall;
y: PreparedSympyCall;
z: PreparedSympyCall;
interval: PlotInterval;
}[], svg: boolean, params?: Plot3dParams): string;
/**
* Generates source for image with 3d parametric plot.
* @param expressions - one or more triplet of the expressions. Each with its own pair of the itervals.
* @param svg - if the result must be in SVG (if not, PNG is used)
* @param params - additional plot parameters
* @returns URL to be added to image tag.
*/
plot3dParametricSurfaceSrc(expressions: {
x: PreparedSympyCall;
y: PreparedSympyCall;
z: PreparedSympyCall;
r_u: PlotInterval;
r_v: PlotInterval;
}[], svg: boolean, params?: Plot3dParams): string;
/**
* Generates an image with 2d plot.
* @param sympyExpressions - One or more expressions to plot. Each is the result of one of {@link prepareCompute}
* @param svg - if the result must be in SVG (if not, PNG is used)
* @param onError - callback to call in case of error
* @param interval - optional interval where we need the plot
* @param params - additional plot parameters
* @returns image element.
*/
plot2d(sympyExpressions: PreparedSympyCall[], svg: boolean, onError?: (err: SympyError) => void, interval?: PlotInterval, params?: Plot2dParams): HTMLImageElement;
/**
* Generates source for image with 3d plot.
* @param sympyExpressions - one or more expressions to plot
* @param svg - if the result must be in SVG (if not, PNG is used)
* @param onError - callback to call in case of error
* @param intervals - optional intervals for both dimensions of the 3d plot
* @param params - additional plot parameters
* @returns image element.
*/
plot3d(sympyExpressions: PreparedSympyCall[], svg: boolean, onError?: (err: SympyError) => void, intervals?: {
i1: PlotInterval;
i2: PlotInterval;
}, params?: Plot3dParams): HTMLImageElement;
/**
* Generates image with 2d parametric plot.
* @param expressionPairs - one or more pair of expressions to generate the parametric plot.
* @param svg - if the result must be in SVG (if not, PNG is used)
* @param onError - callback to call in case of error
* @param interval - optional interval where we need the plot
* @param params - additional plot parameters
* @returns image element
*/
plot2d_parametric(expressionPairs: {
x: PreparedSympyCall;
y: PreparedSympyCall;
}[], svg: boolean, onError?: (err: SympyError) => void, interval?: PlotInterval, params?: Plot2dParams): HTMLImageElement;
/**
* Generates image with 3d parametric plot.
* @param expressions - one or more triplet of the expressions. Each with its own iterval.
* @param svg - if the result must be in SVG (if not, PNG is used)
* @param params - additional plot parameters
* @param onError - callback to call in case of error
* @returns image element.
*/
plot3d_parametric_line(expressions: {
x: PreparedSympyCall;
y: PreparedSympyCall;
z: PreparedSympyCall;
interval: PlotInterval;
}[], svg: boolean, onError?: (err: SympyError) => void, params?: Plot3dParams): HTMLImageElement;
/**
* Generates image with 3d parametric plot.
* @param expressions - one or more triplet of the expressions. Each with its own pair of the itervals.
* @param svg - if the result must be in SVG (if not, PNG is used)
* @param params - additional plot parameters
* @param onError - callback to call in case of error
* @returns image lement.
*/
plot3d_parametric_surface(expressions: {
x: PreparedSympyCall;
y: PreparedSympyCall;
z: PreparedSympyCall;
r_u: PlotInterval;
r_v: PlotInterval;
}[], svg: boolean, onError?: (err: SympyError) => void, params?: Plot3dParams): HTMLImageElement;
private replaceAll;
protected prepare(node: MathNode, operation: MathNodeVisitor<SympyToken>): PreparedSympyCall | SemanticErrorDescription;
}