UNPKG

mathsteps-experimental-fork

Version:

Step by step math solutions. Experimental Fork

60 lines (57 loc) 2.55 kB
import calculateNumericalValue from './rules/calculateNumericalValue.js'; import cancelTerms from './rules/cancelTerms.js'; import collectLikeTerms from './rules/collectLikeTerms.js'; import commonFunctions$0 from './rules/commonFunctions.js'; import commonFunctionsLogXY from './rules/commonFunctionsLogXY.js'; import { commonRules, commonRulesPooledTogether } from './rules/commonRules.js'; import convertDecimalToFraction from './rules/convertDecimalToFraction.js'; import distribute from './rules/distribute.js'; import multiplyShortFormulas from './rules/multiplyShortFormulas.js'; import sqrtFromConstant from './rules/sqrtFromConstant.js'; import sqrtFromPow from './rules/sqrtFromPow.js'; const { commonFunctions, commonFunctionsPooledTogether } = commonFunctions$0; 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: 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, { 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; }, {}); export { POOLED_TOGETHER_POOL_OF_RULES, POOL_OF_RULES };