Socket
Socket
Sign inDemoInstall

2d-algebra

Package Overview
Dependencies
0
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.2.0 to 2.0.0

lib/format/index.d.ts

6

lib/Expression.d.ts
import { ExpressionStack } from "./ExpressionStack";
import { INode, Term, Identifier } from "./node/index";
import { Identifier, INode, Term } from "./node/index";
export declare type Assignments = Map<Identifier, number>;
export declare type Substitutions = Map<Identifier, Expression>;
export declare class Expression {

@@ -18,5 +19,6 @@ readonly a: INode;

push(b: Term): ExpressionStack<Expression>;
toString(indent?: string): string;
toString(indent?: string, inline?: boolean): string;
derivative(withRespectTo: Identifier): Expression;
eval(assign: Assignments): number;
apply(subs: Substitutions): Expression;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Expression = void 0;
const ExpressionStack_1 = require("./ExpressionStack");
const InlineFormat_1 = require("./format/InlineFormat");
const TreeFormat_1 = require("./format/TreeFormat");
const index_1 = require("./node/index");

@@ -10,12 +13,12 @@ class Expression {

plus(b) {
return new Expression(index_1.add(this.a, index_1.toNode(b)));
return new Expression((0, index_1.add)(this.a, (0, index_1.toNode)(b)));
}
minus(b) {
return new Expression(index_1.sub(this.a, index_1.toNode(b)));
return new Expression((0, index_1.sub)(this.a, (0, index_1.toNode)(b)));
}
times(b) {
return new Expression(index_1.mult(this.a, index_1.toNode(b)));
return new Expression((0, index_1.mult)(this.a, (0, index_1.toNode)(b)));
}
dividedBy(b) {
return new Expression(index_1.div(this.a, index_1.toNode(b)));
return new Expression((0, index_1.div)(this.a, (0, index_1.toNode)(b)));
}

@@ -26,21 +29,21 @@ squared() {

toThe(n) {
return new Expression(index_1.pow(this.a, n));
return new Expression((0, index_1.pow)(this.a, n));
}
sin() {
return new Expression(index_1.sin(this.a));
return new Expression((0, index_1.sin)(this.a));
}
cos() {
return new Expression(index_1.cos(this.a));
return new Expression((0, index_1.cos)(this.a));
}
tan() {
return new Expression(index_1.tan(this.a));
return new Expression((0, index_1.tan)(this.a));
}
eq(b) {
return new Expression(index_1.eq(this.a, index_1.toNode(b)));
return new Expression((0, index_1.eq)(this.a, (0, index_1.toNode)(b)));
}
push(b) {
return new ExpressionStack_1.ExpressionStack(this, index_1.toNode(b));
return new ExpressionStack_1.ExpressionStack(this, (0, index_1.toNode)(b));
}
toString(indent = "") {
return this.a.toString(indent);
toString(indent = "", inline = true) {
return this.a.toString(indent, inline ? new InlineFormat_1.InlineFormat() : new TreeFormat_1.TreeFormat());
}

@@ -53,4 +56,7 @@ derivative(withRespectTo) {

}
apply(subs) {
return new Expression(this.a.apply(subs));
}
}
exports.Expression = Expression;
//# sourceMappingURL=Expression.js.map
import { Expression } from "./Expression";
import { INode, Identifier } from "./node/index";
import { Identifier, INode } from "./node/index";
declare type Term = number | Identifier | Expression;

@@ -4,0 +4,0 @@ export declare class ExpressionStack<N extends ExpressionStack<any> | Expression> {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ExpressionStack = void 0;
const Expression_1 = require("./Expression");

@@ -7,3 +8,3 @@ const index_1 = require("./node/index");

if (c !== undefined) {
return new ExpressionStack(parent, op(b, index_1.toNode(c)));
return new ExpressionStack(parent, op(b, (0, index_1.toNode)(c)));
}

@@ -47,12 +48,12 @@ if (parent instanceof ExpressionStack) {

sin() {
return new ExpressionStack(this.parent, index_1.sin(this.b));
return new ExpressionStack(this.parent, (0, index_1.sin)(this.b));
}
cos() {
return new ExpressionStack(this.parent, index_1.cos(this.b));
return new ExpressionStack(this.parent, (0, index_1.cos)(this.b));
}
tan() {
return new ExpressionStack(this.parent, index_1.tan(this.b));
return new ExpressionStack(this.parent, (0, index_1.tan)(this.b));
}
push(b) {
return new ExpressionStack(this, index_1.toNode(b));
return new ExpressionStack(this, (0, index_1.toNode)(b));
}

@@ -59,0 +60,0 @@ }

"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -9,7 +16,7 @@ const Expression_1 = require("./Expression");

function expression(a) {
return new Expression_1.Expression(node_1.toNode(a));
return new Expression_1.Expression((0, node_1.toNode)(a));
}
exports.default = expression;
__export(require("./Expression"));
__export(require("./ExpressionStack"));
__exportStar(require("./Expression"), exports);
__exportStar(require("./ExpressionStack"), exports);
//# sourceMappingURL=index.js.map

@@ -1,3 +0,4 @@

import { Assignments } from "../Expression";
import { INode, Identifier } from "./index";
import { Assignments, Substitutions } from "../Expression";
import { InlineFormat } from "../format/InlineFormat";
import { Identifier, INode } from "./index";
export declare class Add implements INode {

@@ -7,8 +8,11 @@ readonly a: INode;

constructor(a: INode, b: INode);
op(): string;
eval(assign: Assignments): number;
apply(subs: Substitutions): INode;
derivative(withRespectTo: Identifier): INode;
degree(): Map<INode, number> | undefined;
degree(): Array<[INode, number]> | undefined;
coefficient(): [number, INode];
exponent(): [number, INode];
toString(indent?: string): string;
toString(indent?: string, fmt?: InlineFormat): string;
equals(that: INode): boolean;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Add = void 0;
const InlineFormat_1 = require("../format/InlineFormat");
const index_1 = require("./index");

@@ -9,9 +11,15 @@ class Add {

}
op() {
return "+";
}
eval(assign) {
return this.a.eval(assign) + this.b.eval(assign);
}
apply(subs) {
return (0, index_1.add)(this.a.apply(subs), this.b.apply(subs));
}
derivative(withRespectTo) {
const da = this.a.derivative(withRespectTo);
const db = this.b.derivative(withRespectTo);
return index_1.add(da, db);
return (0, index_1.add)(da, db);
}

@@ -27,9 +35,14 @@ degree() {

}
toString(indent = "") {
return "+" +
"\n" + indent + "├ " + this.a.toString(indent + "│ ") +
"\n" + indent + "└ " + this.b.toString(indent + " ");
toString(indent = "", fmt = new InlineFormat_1.InlineFormat()) {
return fmt.binary(indent, this.op(), this.a, this.b);
}
equals(that) {
if (this === that)
return true;
if (!(that instanceof Add))
return false;
return this.a.equals(that.a) && this.b.equals(that.b);
}
}
exports.Add = Add;
//# sourceMappingURL=Add.js.map

@@ -1,12 +0,16 @@

import { Assignments } from "../Expression";
import { INode, Identifier } from "./index";
import { Assignments, Substitutions } from "../Expression";
import { InlineFormat } from "../format/InlineFormat";
import { Identifier, INode } from "./index";
export declare class Constant implements INode {
readonly n: number;
constructor(n: number);
op(): string;
eval(assign: Assignments): number;
apply(subs: Substitutions): INode;
derivative(withRespectTo: Identifier): INode;
degree(): Map<INode, number>;
degree(): Array<[INode, number]>;
coefficient(): [number, INode];
exponent(): [number, INode];
toString(indent?: string): string;
toString(indent?: string, fmt?: InlineFormat): string;
equals(that: INode): boolean;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Constant = void 0;
const InlineFormat_1 = require("../format/InlineFormat");
const index_1 = require("./index");

@@ -8,13 +10,19 @@ class Constant {

}
op() {
return undefined;
}
eval(assign) {
return this.n;
}
apply(subs) {
return this;
}
derivative(withRespectTo) {
return index_1.value(0);
return (0, index_1.value)(0);
}
degree() {
return new Map([[index_1.degreeSum, 0]]);
return [[index_1.degreeSum, 0]];
}
coefficient() {
return [this.n, index_1.value(1)];
return [this.n, (0, index_1.value)(1)];
}

@@ -24,7 +32,14 @@ exponent() {

}
toString(indent = "") {
toString(indent = "", fmt = new InlineFormat_1.InlineFormat()) {
return this.n.toString();
}
equals(that) {
if (this === that)
return true;
if (!(that instanceof Constant))
return false;
return this.n === that.n;
}
}
exports.Constant = Constant;
//# sourceMappingURL=Constant.js.map

@@ -1,12 +0,16 @@

import { Assignments } from "../Expression";
import { INode, Identifier } from "./index";
import { Assignments, Substitutions } from "../Expression";
import { InlineFormat } from "../format/InlineFormat";
import { Identifier, INode } from "./index";
export declare class Cosine implements INode {
readonly a: INode;
constructor(a: INode);
op(): string;
eval(assign: Assignments): number;
apply(subs: Substitutions): INode;
derivative(withRespectTo: Identifier): INode;
degree(): Map<INode, number>;
degree(): Array<[INode, number]>;
coefficient(): [number, INode];
exponent(): [number, INode];
toString(indent?: string): string;
toString(indent?: string, fmt?: InlineFormat): string;
equals(that: INode): boolean;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Cosine = void 0;
const InlineFormat_1 = require("../format/InlineFormat");
const index_1 = require("./index");

@@ -8,10 +10,16 @@ class Cosine {

}
op() {
return undefined;
}
eval(assign) {
return Math.cos(this.a.eval(assign));
}
apply(subs) {
return (0, index_1.cos)(this.a.apply(subs));
}
derivative(withRespectTo) {
return index_1.mult(index_1.value(-1), index_1.mult(index_1.sin(this.a), this.a.derivative(withRespectTo)));
return (0, index_1.mult)((0, index_1.value)(-1), (0, index_1.mult)((0, index_1.sin)(this.a), this.a.derivative(withRespectTo)));
}
degree() {
return new Map([[this, 1], [index_1.degreeSum, 1]]);
return [[this, 1], [index_1.degreeSum, 1]];
}

@@ -24,8 +32,14 @@ coefficient() {

}
toString(indent = "") {
return "cosine" +
"\n" + indent + "└ " + this.a.toString(indent + " ");
toString(indent = "", fmt = new InlineFormat_1.InlineFormat()) {
return fmt.func(indent, "cos", this.a);
}
equals(that) {
if (this === that)
return true;
if (!(that instanceof Cosine))
return false;
return this.a.equals(that.a);
}
}
exports.Cosine = Cosine;
//# sourceMappingURL=Cosine.js.map

@@ -1,2 +0,3 @@

import { Assignments, Expression } from "../Expression";
import { Assignments, Expression, Substitutions } from "../Expression";
import { Format } from "../format";
import { Constant } from "./Constant";

@@ -9,8 +10,11 @@ import { Cosine } from "./Cosine";

export interface INode {
op(): string;
eval(assign: Assignments): number;
apply(subs: Substitutions): INode;
derivative(withRespectTo: Identifier): INode;
degree(): Map<INode, number> | undefined;
degree(): Array<[INode, number]> | undefined;
coefficient(): [number, INode];
exponent(): [number, INode];
toString(indent?: string): string;
toString(indent?: string, fmt?: Format): string;
equals(that: INode): boolean;
}

@@ -22,3 +26,2 @@ export declare function toNode(x: Term): INode;

export declare function sub(a: INode, b: INode): INode;
export declare const degreeSum: Constant;
export declare function mult(a: INode, b: INode): INode;

@@ -31,2 +34,3 @@ export declare function pow(a: INode, b: number): INode;

export declare function eq(a: INode, b: INode): INode;
export declare const degreeSum: Constant;
/**

@@ -33,0 +37,0 @@ * Compare the degree (power of exponents) for each variable in the product

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.degreeComparator = exports.degreeSum = exports.eq = exports.tan = exports.cos = exports.sin = exports.div = exports.pow = exports.mult = exports.sub = exports.add = exports.value = exports.variable = exports.toNode = void 0;
const Expression_1 = require("../Expression");

@@ -92,4 +93,2 @@ const Add_1 = require("./Add");

const negOne = new Constant_1.Constant(-1);
// marker used in computing the sort order of terms.
exports.degreeSum = new Constant_1.Constant(NaN);
function mult(a, b) {

@@ -151,7 +150,21 @@ // distribute 2*(x+y) => 2x+2y

}
if (a instanceof Multiply_1.Multiply) {
return mult(pow(a.a, b), pow(a.b, b));
}
// unroll (x + y)^N => (x + y) * (x + y)....
// unroll (x * y)^N => (x * y) * (x * y)....
// so that the distribution rule can be applied
if (Number.isInteger(b) && (a instanceof Add_1.Add || a instanceof Multiply_1.Multiply)) {
return mult(a, pow(a, b - 1));
if (Number.isInteger(b) && a instanceof Add_1.Add) {
const mag = Math.abs(b);
let base = one;
for (let i = 0; i < mag; i++) {
base = mult(base, a);
}
if (b < 0) {
a = base;
b = -1;
}
else {
return base;
}
}

@@ -161,6 +174,6 @@ if (a instanceof Constant_1.Constant) {

}
if (a instanceof Power_1.Pow) {
return pow(a.a, a.b + b);
if (a instanceof Power_1.Power) {
return pow(a.a, Math.pow(a.b, b));
}
return new Power_1.Pow(a, b);
return new Power_1.Power(a, b);
}

@@ -207,2 +220,4 @@ exports.pow = pow;

exports.eq = eq;
// marker used in computing the sort order of terms.
exports.degreeSum = new Constant_1.Constant(NaN);
/**

@@ -222,4 +237,4 @@ * Compare the degree (power of exponents) for each variable in the product

}
const aTotal = aDegrees.get(exports.degreeSum);
const bTotal = bDegrees.get(exports.degreeSum);
const aTotal = aDegrees.find(([aExp, aDegree]) => aExp.equals(exports.degreeSum))[1];
const bTotal = bDegrees.find(([bExp, bDegree]) => bExp.equals(exports.degreeSum))[1];
// Math.abs allow x and 1/x to sort to the same place to be canceled out

@@ -229,10 +244,21 @@ if (Math.abs(aTotal) !== Math.abs(bTotal)) {

}
for (const v of Array.from([...aDegrees.keys(), ...bDegrees.keys()]).sort()) {
const aDegree = aDegrees.get(v) || 0;
const bDegree = bDegrees.get(v) || 0;
// Math.abs allow x and 1/x to sort to the same place to be canceled out
if (Math.abs(aDegree) !== Math.abs(bDegree)) {
return aDegree - bDegree;
// create a set of expresions the hard way.
const exps = aDegrees.map(([aExp, aDegree]) => aExp);
bDegrees.forEach(([bExp, bDegree]) => {
if (exps.findIndex((exp) => exp.equals(bExp)) === -1) {
exps.push(bExp);
}
});
exps.sort((a, b) => a.toString().localeCompare(b.toString()));
for (const exp of exps) {
const aExpDegree = aDegrees.find(([aExp, aDegree]) => exp.equals(aExp));
const bExpDegree = bDegrees.find(([bExp, bDegree]) => exp.equals(bExp));
if (aExpDegree === undefined)
return 0 - 1;
if (bExpDegree === undefined)
return 1 - 0;
if (Math.abs(aExpDegree[1]) !== Math.abs(bExpDegree[1]))
return aExpDegree[1] - bExpDegree[1];
}
;
return 0;

@@ -239,0 +265,0 @@ }

@@ -1,3 +0,4 @@

import { Assignments } from "../Expression";
import { INode, Identifier } from "./index";
import { Assignments, Substitutions } from "../Expression";
import { InlineFormat } from "../format/InlineFormat";
import { Identifier, INode } from "./index";
export declare class Multiply implements INode {

@@ -7,8 +8,11 @@ readonly a: INode;

constructor(a: INode, b: INode);
op(): string;
eval(assign: Assignments): number;
apply(subs: Substitutions): INode;
derivative(withRespectTo: Identifier): INode;
degree(): Map<INode, number> | undefined;
degree(): Array<[INode, number]> | undefined;
coefficient(): [number, INode];
exponent(): [number, INode];
toString(indent?: string): string;
toString(indent?: string, fmt?: InlineFormat): string;
equals(that: INode): boolean;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Multiply = void 0;
const InlineFormat_1 = require("../format/InlineFormat");
const Constant_1 = require("./Constant");

@@ -10,5 +12,11 @@ const index_1 = require("./index");

}
op() {
return "*";
}
eval(assign) {
return this.a.eval(assign) * this.b.eval(assign);
}
apply(subs) {
return (0, index_1.mult)(this.a.apply(subs), this.b.apply(subs));
}
derivative(withRespectTo) {

@@ -18,3 +26,3 @@ // apply the power rule a*b... => a'*b + a*b'

const db = this.b.derivative(withRespectTo);
return index_1.add(index_1.mult(da, this.b), index_1.mult(this.a, db));
return (0, index_1.add)((0, index_1.mult)(da, this.b), (0, index_1.mult)(this.a, db));
}

@@ -27,5 +35,11 @@ degree() {

}
const degrees = new Map(aDegrees);
bDegrees.forEach((bDegree, bExp) => {
return degrees.set(bExp, (aDegrees.get(bExp) || 0) + bDegree);
const degrees = [...aDegrees];
bDegrees.forEach(([bExp, bDegree]) => {
const index = degrees.findIndex(([exp, degree]) => exp.equals(bExp));
if (index === -1) {
degrees.push([bExp, bDegree]);
}
else {
degrees[index][1] + bDegree;
}
});

@@ -43,9 +57,14 @@ return degrees;

}
toString(indent = "") {
return "*" +
"\n" + indent + "├ " + this.a.toString(indent + "│ ") +
"\n" + indent + "└ " + this.b.toString(indent + " ");
toString(indent = "", fmt = new InlineFormat_1.InlineFormat()) {
return fmt.binary(indent, this.op(), this.a, this.b);
}
equals(that) {
if (this === that)
return true;
if (!(that instanceof Multiply))
return false;
return this.a.equals(that.a) && this.b.equals(that.b);
}
}
exports.Multiply = Multiply;
//# sourceMappingURL=Multiply.js.map

@@ -1,13 +0,17 @@

import { Assignments } from "../Expression";
import { INode, Identifier } from "./index";
export declare class Pow implements INode {
import { Assignments, Substitutions } from "../Expression";
import { InlineFormat } from "../format/InlineFormat";
import { Identifier, INode } from "./index";
export declare class Power implements INode {
readonly a: INode;
readonly b: number;
constructor(a: INode, b: number);
op(): string;
eval(assign: Assignments): number;
apply(subs: Substitutions): INode;
derivative(withRespectTo: Identifier): INode;
degree(): Map<INode, number> | undefined;
degree(): Array<[INode, number]> | undefined;
coefficient(): [number, INode];
exponent(): [number, INode];
toString(indent?: string): string;
toString(indent?: string, fmt?: InlineFormat): string;
equals(that: INode): boolean;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Power = void 0;
const InlineFormat_1 = require("../format/InlineFormat");
const index_1 = require("./index");
class Pow {
class Power {
constructor(a, b) {

@@ -9,9 +11,15 @@ this.a = a;

}
op() {
return "^";
}
eval(assign) {
return Math.pow(this.a.eval(assign), this.b);
}
apply(subs) {
return (0, index_1.pow)(this.a.apply(subs), this.b);
}
derivative(withRespectTo) {
const da = this.a.derivative(withRespectTo);
const x = index_1.pow(this.a, this.b - 1);
const out = index_1.mult(index_1.mult(index_1.value(this.b), x), da);
const x = (0, index_1.pow)(this.a, this.b - 1);
const out = (0, index_1.mult)((0, index_1.mult)((0, index_1.value)(this.b), x), da);
return out;

@@ -24,4 +32,3 @@ }

}
degrees.forEach((degree, exp) => degrees.set(exp, degree * this.b));
return degrees;
return degrees.map(([exp, degree]) => [exp, degree * this.b]);
}

@@ -34,9 +41,14 @@ coefficient() {

}
toString(indent = "") {
return "^" +
"\n" + indent + "├ " + this.a.toString(indent + "│ ") +
"\n" + indent + "└ " + this.b;
toString(indent = "", fmt = new InlineFormat_1.InlineFormat()) {
return fmt.binary(indent, this.op(), this.a, (0, index_1.value)(this.b));
}
equals(that) {
if (this === that)
return true;
if (!(that instanceof Power))
return false;
return this.a.equals(that.a) && this.b === that.b;
}
}
exports.Pow = Pow;
exports.Power = Power;
//# sourceMappingURL=Power.js.map

@@ -1,12 +0,16 @@

import { Assignments } from "../Expression";
import { INode, Identifier } from "./index";
import { Assignments, Substitutions } from "../Expression";
import { InlineFormat } from "../format/InlineFormat";
import { Identifier, INode } from "./index";
export declare class Sine implements INode {
readonly a: INode;
constructor(a: INode);
op(): string;
eval(assign: Assignments): number;
apply(subs: Substitutions): INode;
derivative(withRespectTo: Identifier): INode;
degree(): Map<INode, number>;
degree(): Array<[INode, number]>;
coefficient(): [number, INode];
exponent(): [number, INode];
toString(indent?: string): string;
toString(indent?: string, fmt?: InlineFormat): string;
equals(that: INode): boolean;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Sine = void 0;
const InlineFormat_1 = require("../format/InlineFormat");
const index_1 = require("./index");

@@ -8,10 +10,16 @@ class Sine {

}
op() {
return undefined;
}
eval(assign) {
return Math.sin(this.a.eval(assign));
}
apply(subs) {
return (0, index_1.sin)(this.a.apply(subs));
}
derivative(withRespectTo) {
return index_1.mult(index_1.cos(this.a), this.a.derivative(withRespectTo));
return (0, index_1.mult)((0, index_1.cos)(this.a), this.a.derivative(withRespectTo));
}
degree() {
return new Map([[this, 1], [index_1.degreeSum, 1]]);
return [[this, 1], [index_1.degreeSum, 1]];
}

@@ -24,8 +32,14 @@ coefficient() {

}
toString(indent = "") {
return " sine" +
"\n" + indent + " └" + this.a.toString(indent + " ");
toString(indent = "", fmt = new InlineFormat_1.InlineFormat()) {
return fmt.func(indent, "sin", this.a);
}
equals(that) {
if (this === that)
return true;
if (!(that instanceof Sine))
return false;
return this.a.equals(that.a);
}
}
exports.Sine = Sine;
//# sourceMappingURL=Sine.js.map

@@ -1,3 +0,4 @@

import { Assignments } from "../Expression";
import { INode, Identifier } from "./index";
import { Assignments, Substitutions } from "../Expression";
import { InlineFormat } from "../format/InlineFormat";
import { Identifier, INode } from "./index";
export declare class Variable implements INode {

@@ -8,8 +9,11 @@ readonly a: Identifier;

constructor(a: Identifier);
op(): string;
eval(assign: Assignments): number;
apply(subs: Substitutions): INode;
derivative(withRespectTo: Identifier): INode;
degree(): Map<INode, number>;
degree(): Array<[INode, number]>;
coefficient(): [number, INode];
exponent(): [number, INode];
toString(): string;
toString(indent?: string, fmt?: InlineFormat): string;
equals(that: INode): boolean;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Variable = void 0;
const InlineFormat_1 = require("../format/InlineFormat");
const index_1 = require("./index");

@@ -7,4 +9,10 @@ class Variable {

this.a = a;
this.description = this.a.description || ("x" + Variable.idSequence++);
if (typeof a === 'symbol')
this.description = this.a.description || ("x" + Variable.idSequence++);
else
this.description = a;
}
op() {
return undefined;
}
eval(assign) {

@@ -17,7 +25,14 @@ const r = assign.get(this.a);

}
apply(subs) {
const r = subs.get(this.a);
if (r !== undefined) {
return r.a;
}
return this;
}
derivative(withRespectTo) {
return (withRespectTo === this.a) ? index_1.value(1) : index_1.value(0);
return (withRespectTo === this.a) ? (0, index_1.value)(1) : (0, index_1.value)(0);
}
degree() {
return new Map([[this, 1], [index_1.degreeSum, 1]]);
return [[this, 1], [index_1.degreeSum, 1]];
}

@@ -30,5 +45,12 @@ coefficient() {

}
toString() {
toString(indent = "", fmt = new InlineFormat_1.InlineFormat()) {
return this.description;
}
equals(that) {
if (this === that)
return true;
if (!(that instanceof Variable))
return false;
return this.a === that.a && this.description === that.description;
}
}

@@ -35,0 +57,0 @@ exports.Variable = Variable;

{
"name": "2d-algebra",
"version": "1.2.0",
"version": "2.0.0",
"description": "Library for building expressions and computing derivatives",

@@ -12,3 +12,3 @@ "repository": "github:abersnaze/2d-algebra",

"scripts": {
"test": "mocha --require ts-node/register 'test/**/*.ts'",
"test": "nyc mocha --require ts-node/register 'test/**/*.ts'",
"watch": "yarn test -w",

@@ -27,9 +27,9 @@ "compile": "tsc"

"@types/chai": "^4.2.13",
"@types/mocha": "^8.0.3",
"@types/mocha": "^9.0.0",
"chai": "^4.2.0",
"mocha": "^8.1.3",
"ts-node": "^9.0.0",
"mocha": "^9",
"nyc": "^15.1.0",
"ts-node": "^10.4.0",
"typescript": "^4.0.3"
},
"dependencies": {}
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc