UNPKG

mathsteps-experimental-fork

Version:

Step by step math solutions. Experimental Fork

65 lines (60 loc) 2.75 kB
'use strict'; Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); const calculateNumericalValue = require('./rules/calculateNumericalValue.js'); const cancelTerms = require('./rules/cancelTerms.js'); const collectLikeTerms = require('./rules/collectLikeTerms.js'); const commonFunctions$1 = require('./rules/commonFunctions.js'); const commonFunctionsLogXY = require('./rules/commonFunctionsLogXY.js'); const commonRules = require('./rules/commonRules.js'); const convertDecimalToFraction = require('./rules/convertDecimalToFraction.js'); const distribute = require('./rules/distribute.js'); const multiplyShortFormulas = require('./rules/multiplyShortFormulas.js'); const sqrtFromConstant = require('./rules/sqrtFromConstant.js'); const sqrtFromPow = require('./rules/sqrtFromPow.js'); const { commonFunctions, commonFunctionsPooledTogether } = commonFunctions$1.default; const POOLED_TOGETHER_POOL_OF_RULES = { // Convert 3.14 to 314/100 etc. in non-numerical mode. convertDecimalToFraction, // Apply logarithm rules before arithmetic to avoid huge intermediate // values like log10(10^23) => log10(100000000000000000000000) // We want log10(10^23) => 23 instead. commonFunctionsLogXY: commonFunctionsLogXY, // Basic simplifications that we always try first e.g. (...)^0 => 1 commonRules: commonRules.commonRulesPooledTogether, // x*a/x gives a cancelTerms, // 3x + 2x gives 5x etc. collectLikeTerms, // common function simplification e.g. sin(0) gives 0 commonFunctions: commonFunctionsPooledTogether, // (a + b + c + ...) * x gives ac ax + bx + cx + ... etc. distribute, // sqrt(x^2) gives x or |x| (depends on domain) sqrtFromPow, // sqrt(n) - calculate if possible. sqrtFromConstant, // (a + b)^2 gives a^2 + 2ab + b^2 etc. multiplyShortFormulas, // Numerical result e.g. 1.414 instead of sqrt(2). calculateNumericalValue }; const rulesArray = [ { id: "convertDecimalToFraction", fn: convertDecimalToFraction }, { id: "commonFunctionsLogXY", fn: commonFunctionsLogXY }, ...commonRules.commonRules, { id: "cancelTerms", fn: cancelTerms }, { id: "collectLikeTerms", fn: collectLikeTerms }, ...commonFunctions, // { id: 'commonFunctions', fn: require('./rules/commonFunctions') }, { id: "distribute", fn: distribute }, { id: "sqrtFromPow", fn: sqrtFromPow }, { id: "sqrtFromConstant", fn: sqrtFromConstant }, { id: "multiplyShortFormulas", fn: multiplyShortFormulas }, { id: "calculateNumericalValue", fn: calculateNumericalValue } ]; const POOL_OF_RULES = rulesArray.reduce((acc, rule) => { acc[rule.id] = rule.fn; return acc; }, {}); exports.POOLED_TOGETHER_POOL_OF_RULES = POOLED_TOGETHER_POOL_OF_RULES; exports.POOL_OF_RULES = POOL_OF_RULES;