Skip to content

Commit 7f3937f

Browse files
authored
Merge pull request #49 from pie-framework/feat/PD-302
feat(PD-302): add log and sqrt rules
2 parents 0516253 + b8773af commit 7f3937f

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

src/conversion/ast-to-mathjs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ export class AstToMathJs {
167167
this.convert(operands[1]),
168168
]);
169169

170-
const f = new m.SymbolNode(operands[0]);
170+
const f = operands[0]
171171
const args = operands[1];
172172
let f_args;
173173

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
export default {
2+
mode: "symbolic",
3+
tests: [
4+
{
5+
target: "\\log(x*y)",
6+
eq: [
7+
"\\log(x)+\\log(y)",
8+
"\\log_{10}(x)+\\log_{10}(y)",
9+
"\\log_{10}(x*y)",
10+
],
11+
ne: ["\\log_{10}(x)", "\\log(a*b)"],
12+
},
13+
{
14+
target: "\\log(x/y)",
15+
eq: [
16+
"\\log(x)-\\log(y)",
17+
"\\log_{10}(x)-\\log_{10}(y)",
18+
"\\log_{10}(x/y)",
19+
],
20+
ne: ["\\log_{10}(x)", "\\log(a/b)"],
21+
},
22+
{
23+
target: "\\log(x^y)",
24+
eq: ["y\\log(x)", "y\\log_{10}(x)", "\\log_{10}(x^y)"],
25+
},
26+
{
27+
target: "\\sqrt(-1)",
28+
eq: ["i"],
29+
},
30+
],
31+
};

src/symbolic/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const { simplify: ms, rationalize } = mathjs;
1717
const SIMPLIFY_RULES = [
1818
{ l: "n1^(1/n2)", r: "nthRoot(n1, n2)" },
1919
{ l: "sqrt(n1)", r: "nthRoot(n1, 2)" },
20+
{ l: "nthRoot(-1, 2)", r: "i" },
2021
{ l: "(v1-v2)/n", r: "v1/n-v2/n" },
2122
{ l: "(v1-n)/n", r: "v1/n-1" },
2223
{ l: "n/n1-c1", r: "(n-c1*n1)/n1" },
@@ -33,6 +34,11 @@ const SIMPLIFY_RULES = [
3334
{ l: "n1/(-n2)", r: "-(n1/n2)" },
3435
{ l: "sin(n*pi)", r: "0" },
3536

37+
// logarithm rules
38+
{ l: "log(n1*n2, n3)", r: "log(n1, n3)+log(n2,n3)" },
39+
{ l: "log(n1/n2, n3)", r: "log(n1, n3)-log(n2,n3)" },
40+
{ l: "log(n1^n2, n3)", r: "n2*log(n1,n3)" },
41+
3642
// trigonometry: defining relations for tangent, cotangent, secant, and cosecant in terms of sine and cosine
3743
{ l: "sin(n)/cos(n)", r: "tan(n)" },
3844
{ l: "csc(n)", r: "1/sin(n)" },
@@ -167,7 +173,6 @@ export const isMathEqual = (a: any, b: any) => {
167173
let bs: MathNode;
168174

169175
// apply sort if we are not in a relationalNode
170-
171176
as = a.conditionals ? normalize(a) : sort(normalize(a));
172177

173178
bs = b.conditionals ? normalize(b) : sort(normalize(b));

0 commit comments

Comments
 (0)