math-exercises 2.2.40 → 2.2.42
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/lib/exercises/exercise.d.ts +42 -36
- package/lib/exercises/exercise.d.ts.map +1 -1
- package/lib/exercises/math/calcul/fractions/fractionsSum.d.ts +4 -1
- package/lib/exercises/math/calcul/fractions/fractionsSum.d.ts.map +1 -1
- package/lib/exercises/math/calcul/fractions/fractionsSum.js +23 -4
- package/lib/exercises/math/calcul/rounding/rounding.d.ts.map +1 -1
- package/lib/exercises/math/calculLitteral/distributivity/firstIdentity.d.ts.map +1 -1
- package/lib/exercises/math/calculLitteral/distributivity/firstIdentity.js +3 -0
- package/lib/exercises/math/derivation/derivative/sqrtCompositionDerivation.d.ts.map +1 -1
- package/lib/exercises/math/derivation/derivative/sqrtCompositionDerivation.js +0 -1
- package/lib/exercises/math/functions/logarithm/log10Simplifying.d.ts.map +1 -1
- package/lib/exercises/math/functions/logarithm/logPowerEquation.d.ts.map +1 -1
- package/lib/exercises/math/percent/evolutionRateFromValues.d.ts.map +1 -1
- package/lib/exercises/math/percent/evolutionRateFromValues.js +2 -2
- package/lib/exercises/math/percent/evolutionToCM.d.ts.map +1 -1
- package/lib/exercises/math/percent/evolutionToCM.js +3 -1
- package/lib/exercises/math/powers/powersDivision.d.ts.map +1 -1
- package/lib/exercises/math/powers/powersPower.d.ts.map +1 -1
- package/lib/exercises/math/powers/powersProduct.d.ts.map +1 -1
- package/lib/exercises/math/sequences/arithmetic/arithmeticReasonUsage.d.ts.map +1 -1
- package/lib/exercises/math/sequences/arithmetic/arithmeticReasonUsage.js +1 -0
- package/lib/exercises/math/sequences/arithmetic/recognizeReasonFromFirstTerms.d.ts.map +1 -1
- package/lib/exercises/math/sequences/arithmetic/recognizeReasonFromFirstTerms.js +3 -1
- package/lib/exercises/math/trigonometry/arcLength.js +1 -1
- package/lib/exercises/math/trigonometry/mainAngleMeasure.d.ts.map +1 -1
- package/lib/exercises/math/trigonometry/mainAngleMeasure.js +22 -9
- package/lib/exercises/utils/getDistinctQuestions.d.ts +1 -1
- package/lib/exercises/utils/getDistinctQuestions.d.ts.map +1 -1
- package/lib/index.d.ts +512 -510
- package/lib/index.d.ts.map +1 -1
- package/lib/math/sets/intervals/intervals.js +1 -1
- package/lib/math/systems/system.d.ts.map +1 -1
- package/lib/math/systems/system.js +29 -7
- package/lib/playground.d.ts.map +1 -1
- package/lib/playground.js +7 -1
- package/lib/server.js +9 -2
- package/lib/tree/nodes/operators/addNode.d.ts.map +1 -1
- package/lib/tree/nodes/operators/addNode.js +41 -0
- package/lib/tree/nodes/operators/fractionNode.d.ts.map +1 -1
- package/lib/tree/nodes/operators/fractionNode.js +19 -7
- package/lib/tree/parsers/latexParser.d.ts.map +1 -1
- package/lib/tree/parsers/latexParser.js +8 -1
- package/lib/tree/parsers/numberParser.js +1 -1
- package/lib/tree/parsers/rationalParser.d.ts +1 -0
- package/lib/tree/parsers/rationalParser.d.ts.map +1 -0
- package/lib/tree/parsers/rationalParser.js +9 -0
- package/package.json +1 -1
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,yBAAyB,CAAC;AAEjC,QAAA,MAAM,aAAa
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,yBAAyB,CAAC;AAEjC,QAAA,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SAA+B,CAAC;AACnD,QAAA,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SAA6B,CAAC;AAE/C,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -98,7 +98,7 @@ class Interval {
|
|
|
98
98
|
: interval.rightBracket;
|
|
99
99
|
let unionLeftBracket = this.min < interval.min
|
|
100
100
|
? this.leftBracket
|
|
101
|
-
: this.
|
|
101
|
+
: this.min === interval.min
|
|
102
102
|
? this.leftBracket === "[" || interval.leftBracket === "["
|
|
103
103
|
? "["
|
|
104
104
|
: "]"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"system.d.ts","sourceRoot":"","sources":["../../../src/math/systems/system.ts"],"names":[],"mappings":"AASA,8BAAsB,iBAAiB;IACrC,MAAM,CAAC,MAAM;IAeb,MAAM,CAAC,UAAU;CAiBlB;AACD,qBAAa,MAAM;IACjB,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC;gBAEP,MAAM,EAAE,MAAM,EAAE,EAAE;IAG9B,KAAK;;;;
|
|
1
|
+
{"version":3,"file":"system.d.ts","sourceRoot":"","sources":["../../../src/math/systems/system.ts"],"names":[],"mappings":"AASA,8BAAsB,iBAAiB;IACrC,MAAM,CAAC,MAAM;IAeb,MAAM,CAAC,UAAU;CAiBlB;AACD,qBAAa,MAAM;IACjB,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC;gBAEP,MAAM,EAAE,MAAM,EAAE,EAAE;IAG9B,KAAK;;;;IA4CL,KAAK;CAcN"}
|
|
@@ -45,14 +45,36 @@ class System {
|
|
|
45
45
|
solve() {
|
|
46
46
|
if (this.coeffs.length !== 2)
|
|
47
47
|
throw Error("General system resolution not implemented yet");
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
(this.coeffs[1][1] * this.coeffs[0][0]) / this.coeffs[0][1])
|
|
48
|
+
const [a, b, c] = this.coeffs[0];
|
|
49
|
+
const [d, e, f] = this.coeffs[1];
|
|
50
|
+
if (!b || d * b === e * a)
|
|
52
51
|
throw Error("No solution");
|
|
53
|
-
const x = new fractionNode_1.FractionNode(
|
|
54
|
-
|
|
55
|
-
const
|
|
52
|
+
const x = new fractionNode_1.FractionNode((b * f - e * c).toTree(), (d * b - e * a).toTree()).simplify();
|
|
53
|
+
const y = new fractionNode_1.FractionNode(new substractNode_1.SubstractNode(c.toTree(), new multiplyNode_1.MultiplyNode(a.toTree(), x)), b.toTree()).simplify();
|
|
54
|
+
// const x = new FractionNode(
|
|
55
|
+
// new SubstractNode(
|
|
56
|
+
// this.coeffs[1][2].toTree(),
|
|
57
|
+
// new FractionNode(
|
|
58
|
+
// (this.coeffs[1][1] * this.coeffs[0][2]).toTree(),
|
|
59
|
+
// this.coeffs[0][1].toTree(),
|
|
60
|
+
// ).simplify(),
|
|
61
|
+
// ).simplify(),
|
|
62
|
+
// new SubstractNode(
|
|
63
|
+
// this.coeffs[1][0].toTree(),
|
|
64
|
+
// new FractionNode(
|
|
65
|
+
// (this.coeffs[1][1] * this.coeffs[0][0]).toTree(),
|
|
66
|
+
// this.coeffs[0][1].toTree(),
|
|
67
|
+
// ).simplify(),
|
|
68
|
+
// ).simplify(),
|
|
69
|
+
// ).simplify();
|
|
70
|
+
// //y = c-ax/b
|
|
71
|
+
// const y = new FractionNode(
|
|
72
|
+
// new SubstractNode(
|
|
73
|
+
// this.coeffs[0][2].toTree(),
|
|
74
|
+
// new MultiplyNode(this.coeffs[0][0].toTree(), x).simplify(),
|
|
75
|
+
// ).simplify(),
|
|
76
|
+
// this.coeffs[0][1].toTree(),
|
|
77
|
+
// ).simplify();
|
|
56
78
|
return {
|
|
57
79
|
x,
|
|
58
80
|
y,
|
package/lib/playground.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"playground.d.ts","sourceRoot":"","sources":["../src/playground.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"playground.d.ts","sourceRoot":"","sources":["../src/playground.ts"],"names":[],"mappings":"AAkCA,eAAO,MAAM,UAAU,YAMtB,CAAC"}
|
package/lib/playground.js
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.playground = void 0;
|
|
4
|
-
const playground = () => {
|
|
4
|
+
const playground = () => {
|
|
5
|
+
// const frac = new AddNode(
|
|
6
|
+
// (3).toTree(),
|
|
7
|
+
// new OppositeNode(new FractionNode((1).toTree(), (2).toTree())),
|
|
8
|
+
// ).simplify();
|
|
9
|
+
// console.log(frac.toTex());
|
|
10
|
+
};
|
|
5
11
|
exports.playground = playground;
|
package/lib/server.js
CHANGED
|
@@ -58,11 +58,14 @@ const runServer = () => {
|
|
|
58
58
|
});
|
|
59
59
|
app.get("/exo", (req, res) => {
|
|
60
60
|
const exoId = req.query.exoId;
|
|
61
|
+
const options = req.query.options
|
|
62
|
+
? JSON.parse(req.query.options)
|
|
63
|
+
: undefined;
|
|
61
64
|
const exoIndex = allExercises.findIndex((exo) => exo.id == exoId);
|
|
62
65
|
const exo = allExercises[exoIndex];
|
|
63
66
|
if (!exo)
|
|
64
67
|
res.send("Exo not found");
|
|
65
|
-
const questions = exo?.generator(10);
|
|
68
|
+
const questions = exo?.generator(10, options);
|
|
66
69
|
res.json({
|
|
67
70
|
exercise: exo,
|
|
68
71
|
questions,
|
|
@@ -97,6 +100,10 @@ const runServer = () => {
|
|
|
97
100
|
});
|
|
98
101
|
app.post("/vea", jsonParser, (req, res) => {
|
|
99
102
|
const exoId = req.query.exoId;
|
|
103
|
+
const options = req.query.options
|
|
104
|
+
? JSON.parse(req.query.options)
|
|
105
|
+
: undefined;
|
|
106
|
+
console.log("vea opts", options);
|
|
100
107
|
const { ans, veaProps } = req.body;
|
|
101
108
|
const exoIndex = allExercises.findIndex((exo) => exo.id == exoId);
|
|
102
109
|
const exo = allExercises[exoIndex];
|
|
@@ -108,7 +115,7 @@ const runServer = () => {
|
|
|
108
115
|
res.send("No VEA implemented");
|
|
109
116
|
return;
|
|
110
117
|
}
|
|
111
|
-
const result = exo.isAnswerValid(ans, veaProps) ?? false;
|
|
118
|
+
const result = exo.isAnswerValid(ans, veaProps, options) ?? false;
|
|
112
119
|
res.json({
|
|
113
120
|
result,
|
|
114
121
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addNode.d.ts","sourceRoot":"","sources":["../../../../src/tree/nodes/operators/addNode.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS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AS,CAAC,CAAC,EAAE,IAAI,GAAG,CAAC,IAAI,OAAO,CAE/C;AAED,qBAAa,OAAQ,YAAW,uBAAuB;IACrD,EAAE,EAAE,WAAW,CAAC;IAChB,SAAS,EAAE,aAAa,CAAC;IACzB,UAAU,EAAE,aAAa,CAAC;IAC1B,IAAI,EAAE,QAAQ,CAAC;IACf,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,SAAS,EAAE,OAAO,CAAC;gBAEjB,SAAS,EAAE,aAAa,EACxB,UAAU,EAAE,aAAa,EACzB,IAAI,CAAC,EAAE,WAAW;IASpB,OAAO,aAGL;IAEF,YAAY,IAAI,MAAM;IAItB,iBAAiB,CAAC,IAAI,CAAC,EAAE,WAAW,GAAG,aAAa,EAAE;IAoCtD,SAAS,IAAI,MAAM,EAAE;IAIrB,cAAc,CAAC,IAAI,CAAC,EAAE,WAAW,GAAG,MAAM,EAAE;IAK5C,KAAK,CAAC,OAAO,CAAC,EAAE,YAAY,GAAG,MAAM;IAerC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAMrC,QAAQ,CAAC,IAAI,CAAC,EAAE,eAAe,GAAG,aAAa;IAgP/C,aAAa;;;;;;;;;IAOb,MAAM,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO;CAUrC"}
|
|
@@ -131,18 +131,59 @@ class AddNode {
|
|
|
131
131
|
const f = b.rightChild;
|
|
132
132
|
return new fractionNode_1.FractionNode(new AddNode(new multiplyNode_1.MultiplyNode(c, f), new multiplyNode_1.MultiplyNode(e, d)), new multiplyNode_1.MultiplyNode(d, f)).simplify(opts);
|
|
133
133
|
}
|
|
134
|
+
if ((0, oppositeNode_1.isOppositeNode)(a) && (0, fractionNode_1.isFractionNode)(a.child) && (0, fractionNode_1.isFractionNode)(b)) {
|
|
135
|
+
//-(c/d) + e/f = -cf+ed / df
|
|
136
|
+
const c = a.child.leftChild;
|
|
137
|
+
const d = a.child.rightChild;
|
|
138
|
+
const e = b.leftChild;
|
|
139
|
+
const f = b.rightChild;
|
|
140
|
+
return new fractionNode_1.FractionNode(new AddNode(new multiplyNode_1.MultiplyNode(new oppositeNode_1.OppositeNode(c), f), new multiplyNode_1.MultiplyNode(e, d)), new multiplyNode_1.MultiplyNode(d, f)).simplify(opts);
|
|
141
|
+
}
|
|
142
|
+
if ((0, oppositeNode_1.isOppositeNode)(b) && (0, fractionNode_1.isFractionNode)(b.child) && (0, fractionNode_1.isFractionNode)(a)) {
|
|
143
|
+
//(c/d) + (-e/f) = cf-ed / df
|
|
144
|
+
const c = a.leftChild;
|
|
145
|
+
const d = a.rightChild;
|
|
146
|
+
const e = b.child.leftChild;
|
|
147
|
+
const f = b.child.rightChild;
|
|
148
|
+
return new fractionNode_1.FractionNode(new AddNode(new multiplyNode_1.MultiplyNode(c, f), new multiplyNode_1.MultiplyNode(new oppositeNode_1.OppositeNode(e), d)), new multiplyNode_1.MultiplyNode(d, f)).simplify(opts);
|
|
149
|
+
}
|
|
150
|
+
if ((0, oppositeNode_1.isOppositeNode)(b) &&
|
|
151
|
+
(0, fractionNode_1.isFractionNode)(b.child) &&
|
|
152
|
+
(0, oppositeNode_1.isOppositeNode)(a) &&
|
|
153
|
+
(0, fractionNode_1.isFractionNode)(a.child)) {
|
|
154
|
+
//-(c/d) + (-e/f) = -cf-ed / df
|
|
155
|
+
const c = a.child.leftChild;
|
|
156
|
+
const d = a.child.rightChild;
|
|
157
|
+
const e = b.child.leftChild;
|
|
158
|
+
const f = b.child.rightChild;
|
|
159
|
+
return new fractionNode_1.FractionNode(new AddNode(new multiplyNode_1.MultiplyNode(new oppositeNode_1.OppositeNode(c), f), new multiplyNode_1.MultiplyNode(new oppositeNode_1.OppositeNode(e), d)), new multiplyNode_1.MultiplyNode(d, f)).simplify(opts);
|
|
160
|
+
}
|
|
134
161
|
if ((0, fractionNode_1.isFractionNode)(a)) {
|
|
135
162
|
//c/d + b
|
|
136
163
|
const c = a.leftChild;
|
|
137
164
|
const d = a.rightChild;
|
|
138
165
|
return new fractionNode_1.FractionNode(new AddNode(c, new multiplyNode_1.MultiplyNode(d, b)), d).simplify(opts);
|
|
139
166
|
}
|
|
167
|
+
if ((0, oppositeNode_1.isOppositeNode)(a) && (0, fractionNode_1.isFractionNode)(a.child)) {
|
|
168
|
+
//-(c/d) + b = (-c+bd)/d
|
|
169
|
+
const c = a.child.leftChild;
|
|
170
|
+
const d = a.child.rightChild;
|
|
171
|
+
return new fractionNode_1.FractionNode(new AddNode(new oppositeNode_1.OppositeNode(c), new multiplyNode_1.MultiplyNode(d, b)), d).simplify(opts);
|
|
172
|
+
}
|
|
140
173
|
if ((0, fractionNode_1.isFractionNode)(b) && !opts?.forceDistributeFractions) {
|
|
141
174
|
//a+c/d
|
|
142
175
|
const c = b.leftChild;
|
|
143
176
|
const d = b.rightChild;
|
|
144
177
|
return new fractionNode_1.FractionNode(new AddNode(c, new multiplyNode_1.MultiplyNode(d, a)), d).simplify(opts);
|
|
145
178
|
}
|
|
179
|
+
if ((0, oppositeNode_1.isOppositeNode)(b) &&
|
|
180
|
+
(0, fractionNode_1.isFractionNode)(b.child) &&
|
|
181
|
+
!opts?.forceDistributeFractions) {
|
|
182
|
+
//a+-(c/d) = (da-c)/d
|
|
183
|
+
const c = b.child.leftChild;
|
|
184
|
+
const d = b.child.rightChild;
|
|
185
|
+
return new fractionNode_1.FractionNode(new AddNode(new oppositeNode_1.OppositeNode(c), new multiplyNode_1.MultiplyNode(d, a)), d).simplify(opts);
|
|
186
|
+
}
|
|
146
187
|
if ((0, numberNode_1.isNumberNode)(a) && (0, numberNode_1.isNumberNode)(b)) {
|
|
147
188
|
return new numberNode_1.NumberNode(a.value + b.value);
|
|
148
189
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fractionNode.d.ts","sourceRoot":"","sources":["../../../../src/tree/nodes/operators/fractionNode.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,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C,IAAI,YAAY,CAEzD;AACD,qBAAa,YAAa,YAAW,YAAY;IAC/C,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB;;;OAGG;IACH,EAAE,EAAE,WAAW,CAAC;IAChB,SAAS,EAAE,aAAa,CAAC;IACzB,UAAU,EAAE,aAAa,CAAC;IAC1B,IAAI,EAAE,QAAQ,CAAC;IACf,SAAS,EAAE,OAAO,CAAC;gBAEjB,SAAS,EAAE,aAAa,EACxB,UAAU,EAAE,aAAa,EACzB,IAAI,CAAC,EAAE,WAAW;IAUpB,YAAY,IAAI,MAAM;IAItB,aAAa;;;;;;;;;IAQb,UAAU;IAGV,iBAAiB,CAAC,IAAI,CAAC,EAAE,WAAW;IA+BpC,cAAc,CAAC,IAAI,CAAC,EAAE,WAAW,GAAG,MAAM,EAAE;IAI5C,KAAK,IAAI,MAAM;IAcf,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAMrC,QAAQ,CAAC,IAAI,CAAC,EAAE,eAAe,GAAG,aAAa;IA2J/C,MAAM,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO;CAOrC"}
|
|
@@ -107,6 +107,10 @@ class FractionNode {
|
|
|
107
107
|
oppositesCount++;
|
|
108
108
|
recursiveNums(node.child);
|
|
109
109
|
}
|
|
110
|
+
else if ((0, numberNode_1.isNumberNode)(node) && node.value < 0) {
|
|
111
|
+
oppositesCount++;
|
|
112
|
+
externalsNums.push(new numberNode_1.NumberNode(Math.abs(node.value)));
|
|
113
|
+
}
|
|
110
114
|
else {
|
|
111
115
|
externalsNums.push(node);
|
|
112
116
|
}
|
|
@@ -118,7 +122,11 @@ class FractionNode {
|
|
|
118
122
|
}
|
|
119
123
|
else if ((0, oppositeNode_1.isOppositeNode)(node)) {
|
|
120
124
|
oppositesCount++;
|
|
121
|
-
|
|
125
|
+
recursiveDenums(node.child);
|
|
126
|
+
}
|
|
127
|
+
else if ((0, numberNode_1.isNumberNode)(node) && node.value < 0) {
|
|
128
|
+
oppositesCount++;
|
|
129
|
+
externalsDenums.push(new numberNode_1.NumberNode(Math.abs(node.value)));
|
|
122
130
|
}
|
|
123
131
|
else {
|
|
124
132
|
externalsDenums.push(node);
|
|
@@ -126,9 +134,10 @@ class FractionNode {
|
|
|
126
134
|
};
|
|
127
135
|
recursiveNums(copy.leftChild);
|
|
128
136
|
recursiveDenums(copy.rightChild);
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
137
|
+
const shouldAddOppositeNode = oppositesCount % 2 === 1;
|
|
138
|
+
// if (oppositesCount % 2 === 1) {
|
|
139
|
+
// externalsNums.unshift(new NumberNode(-1));
|
|
140
|
+
// }
|
|
132
141
|
const simplifyExternalNodes = (num, denum) => {
|
|
133
142
|
if ((0, numberNode_1.isNumberNode)(num) && (0, numberNode_1.isNumberNode)(denum)) {
|
|
134
143
|
// console.log("num nb, denum nb", num.toTex(), denum.toTex());
|
|
@@ -193,17 +202,20 @@ class FractionNode {
|
|
|
193
202
|
? externalsNums[0]
|
|
194
203
|
: (0, operatorComposition_1.operatorComposition)(multiplyNode_1.MultiplyNode, externalsNums).simplify(opts);
|
|
195
204
|
if (externalsDenums.length === 0) {
|
|
196
|
-
return nums;
|
|
205
|
+
return shouldAddOppositeNode ? new oppositeNode_1.OppositeNode(nums).simplify() : nums;
|
|
197
206
|
}
|
|
198
207
|
const denums = externalsDenums.length === 1
|
|
199
208
|
? externalsDenums[0]
|
|
200
209
|
: (0, operatorComposition_1.operatorComposition)(multiplyNode_1.MultiplyNode, externalsDenums);
|
|
201
210
|
if (opts?.forceDistributeFractions) {
|
|
202
211
|
if ((0, addNode_1.isAddNode)(nums)) {
|
|
203
|
-
|
|
212
|
+
const res = new addNode_1.AddNode(new FractionNode(nums.leftChild, denums).simplify(opts), new FractionNode(nums.rightChild, denums).simplify(opts));
|
|
213
|
+
return shouldAddOppositeNode ? new oppositeNode_1.OppositeNode(res) : res;
|
|
204
214
|
}
|
|
205
215
|
}
|
|
206
|
-
return
|
|
216
|
+
return shouldAddOppositeNode
|
|
217
|
+
? new oppositeNode_1.OppositeNode(new FractionNode(nums, denums))
|
|
218
|
+
: new FractionNode(nums, denums);
|
|
207
219
|
}
|
|
208
220
|
equals(node) {
|
|
209
221
|
return (isFractionNode(node) &&
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"latexParser.d.ts","sourceRoot":"","sources":["../../../src/tree/parsers/latexParser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"latexParser.d.ts","sourceRoot":"","sources":["../../../src/tree/parsers/latexParser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AA8CvD,eAAO,MAAM,QAAQ,UAAW,MAAM,aA4BrC,CAAC;AAEF,eAAO,MAAM,UAAU,UAAW,MAAM,kBAavC,CAAC"}
|
|
@@ -4,13 +4,14 @@ exports.parseLatex = exports.tokenize = void 0;
|
|
|
4
4
|
const oppositeNode_1 = require("../nodes/functions/oppositeNode");
|
|
5
5
|
const sqrtNode_1 = require("../nodes/functions/sqrtNode");
|
|
6
6
|
const numberNode_1 = require("../nodes/numbers/numberNode");
|
|
7
|
+
const piNode_1 = require("../nodes/numbers/piNode");
|
|
7
8
|
const addNode_1 = require("../nodes/operators/addNode");
|
|
8
9
|
const fractionNode_1 = require("../nodes/operators/fractionNode");
|
|
9
10
|
const multiplyNode_1 = require("../nodes/operators/multiplyNode");
|
|
10
11
|
const powerNode_1 = require("../nodes/operators/powerNode");
|
|
11
12
|
const substractNode_1 = require("../nodes/operators/substractNode");
|
|
12
13
|
const variableNode_1 = require("../nodes/variables/variableNode");
|
|
13
|
-
//
|
|
14
|
+
//cmds that needs a child, like \exp{3}
|
|
14
15
|
const functions = [
|
|
15
16
|
"\\exp",
|
|
16
17
|
"\\sqrt",
|
|
@@ -21,6 +22,8 @@ const functions = [
|
|
|
21
22
|
"\\frac",
|
|
22
23
|
];
|
|
23
24
|
const operators = ["+", "-", "\\div", "\\times", "^"];
|
|
25
|
+
//cmds childless, like \\pi
|
|
26
|
+
const symbols = [{ tex: "\\pi", node: piNode_1.PiNode }];
|
|
24
27
|
const isDyck = (tokens) => {
|
|
25
28
|
const brackets = tokens.filter((el) => el === "(" || el === ")");
|
|
26
29
|
while (brackets.length) {
|
|
@@ -138,6 +141,10 @@ const buildTreeForSameDepthTokens = (tokens) => {
|
|
|
138
141
|
}
|
|
139
142
|
else if (token[0].match(/[a-z]/i))
|
|
140
143
|
tempTokens[i] = new variableNode_1.VariableNode(token);
|
|
144
|
+
else if (symbols.some((el) => el.tex === token)) {
|
|
145
|
+
const obj = symbols.find((el) => el.tex === token);
|
|
146
|
+
tempTokens[i] = obj.node;
|
|
147
|
+
}
|
|
141
148
|
//! les fonctions qui attendent un child ne sont pas encore parsées
|
|
142
149
|
else if (functions.includes(token)) {
|
|
143
150
|
tempTokens[i] = token;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.numberParser = void 0;
|
|
4
|
-
//
|
|
4
|
+
//returns false if ans is NaN (even in french form) and returns the frenchified form otherwise
|
|
5
5
|
const numberParser = (ans) => {
|
|
6
6
|
const nb = ans.unfrenchify();
|
|
7
7
|
if (isNaN(nb))
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=rationalParser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rationalParser.d.ts","sourceRoot":"","sources":["../../../src/tree/parsers/rationalParser.ts"],"names":[],"mappings":""}
|