UNPKG

mathsteps-experimental-fork

Version:

Step by step math solutions. Experimental Fork

41 lines (35 loc) 1.22 kB
'use strict'; Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); const index = require('../../node/index.js'); const index$1 = require('../../simplifyExpression/index.js'); const NODE_TRUE = index.default.Creator.symbol('true'); const NODE_FALSE = index.default.Creator.symbol('false'); const C_EQ_C = { id: 'C_EQ_C', pattern: 'C=C', solveFunction: (equation) => { // Simplify both side before step. equation.simplifyLeft(); equation.simplifyRight(); // Fetch LR nodes. const leftNode = equation.left.node; const rightNode = equation.right.node; // Try to calculate L-R difference. const diffNode = index$1.default.newApi(index.default.Creator.operator('-', [leftNode, rightNode])); if (index.default.Type.isConstant(diffNode)) { // L - R gives a constant number. // We can check equality directly. if (index.default.Type.isZero(diffNode)) { // L - R = 0 // Solution is true. equation.applySolution([NODE_TRUE]); } else { // L - R != 0 // Solution is false. equation.applySolution([NODE_FALSE]); } } }, }; exports.C_EQ_C = C_EQ_C;