How to use the simplify function from mathjs

Find comprehensive JavaScript mathjs.simplify code examples handpicked from public code repositorys.

41
42
43
44
45
46
47
48
49
    parsedMath = math.parse(parsedMath)
  } catch (e) {
    return latex
  }

  console.log('solve result', math.simplify(parsedMath, variables).toTex())

  return math.simplify(parsedMath, variables).toTex()
}
fork icon12
star icon32
watch icon3

+ 3 other calls in file

37
38
39
40
41
42
43
44
45
46
47
// const d = mathjs.parse('foo(1 + 4) * 3');
// console.log('c:', mo(c));
// console.log('d:', mo(d));
// console.log('>>>>>>>>>>>>> c === d?', c.equals(d));


// const cr = mathjs.simplify(c);
// const dr = mathjs.simplify(d);
// // const dr = r(d);
// // console.log('cr:', mo(cr));
// // console.log('dr:', mo(dr));
fork icon3
star icon4
watch icon0

+ 5 other calls in file

26
27
28
29
30
31
32
33
34
35
case "rat":
    try { done = math.rationalize(args.slice(1).join(" ")).toString(); } catch(err) {done = "Rationalization Error"; NorthClient.storage.error(err);}
    break;
case "simplify":
case "sim":
    try { done = math.simplify(args.slice(1).join(" ")).toString(); } catch(err) {done = "Simplification Error"; NorthClient.storage.error(err);}
    break;
case "help":
    return await this.help(message);
default:
fork icon1
star icon1
watch icon0

+ 3 other calls in file

161
162
163
164
165
166
167
168
169
170
var s = ind[1];
s = replaceAll(s, "x0", "x") // for human readers now
s = replaceAll(s, ".*", "*");
const node = math.parse(s);
console.log("latex", node.toTex());
console.log("simplified", math.simplify(s).toString())
   }


truncation_selection() {
fork icon1
star icon0
watch icon0

+ 2 other calls in file

54
55
56
57
58
59
60
61
62
63
var simplify = 'simplify';
var checksimplify = args.indexOf(simplify);

if(checksimplify > -1) {
    args = args.substring((checksimplify+simplify.length));
    result = math.simplify(args).toString();
}

var rationalize = 'rationalize';
var checkrationalize = args.indexOf(rationalize);
fork icon0
star icon1
watch icon0

211
212
213
214
215
216
217
218
219
220
    let af = aArr[2].replaceAll(aVar, "x");

    gf = gf.replaceAll(/([a-z]+)([x0-9])/g, "$1($2)"); // so you can't type "sinx" which mathjs doesn't know how to deal with
    af = af.replaceAll(/([a-z]+)([x0-9])/g, "$1($2)");

    return simplify(parse(gf)).equals(simplify(parse(af)));

} else {
    try {
        return simplify(parse(g)).evaluate() == simplify(parse(a)).evaluate();
fork icon0
star icon0
watch icon0

+ 7 other calls in file

60
61
62
63
64
65
66
67
68
69
iteracion = 0;
xn = xInicial;
f = parse(funcion);
const simplified = simplify(f);
fPrima = parse(derivarFuncion(funcion));
const simplifiedPrima = simplify(fPrima);
bandera = true;
while (bandera) {
  iteracion = iteracion + 1;
  resultadoF = simplified.evaluate({ x: xn });
fork icon0
star icon0
watch icon0

+ 2 other calls in file

1
2
3
4
5
6
7
8
9
10
11
12




module.exports = function(req, res) {
	var q = req.body.q;
	try{
		var rs = simplify(q);
	}catch(e){
		rs="No result";
	}
	//var rs = rationalize(q);
fork icon0
star icon0
watch icon0

129
130
131
132
133
134
135
136
137
138
} finally {
	db.close();
}
//console.log("1: " + req.params.answer);
//console.log("2: " + outputjson.correctAnswer);
var urlanswer = math.simplify(String(req.params.answer)).toString();
var dbanswer = math.simplify(String(outputjson.correctAnswer)).toString();
if(urlanswer.localeCompare(dbanswer)==0) {
	outputjson.correct = 10;
} else {
fork icon0
star icon0
watch icon0