Simplified ready
 
How it was simplified

Input as understood

Rules applied

    Domain

      Other forms

      Expression Simplifier

      Robert Eisele

      Simplify formulas and inequalities in the browser: exact arithmetic, rewrite rules, a domain you can set, numerical verification, and output as plain text, LaTeX or JavaScript.

      Read the story

      The Expression Simplifier takes a formula, an equation or an inequality and returns the simplest equivalent form it can find, in plain text, LaTeX and JavaScript. It runs completely in your browser: nothing is sent to a server, and every result is checked numerically before it is shown. Unlike most online simplifiers you can tell it the domain of your variables. Knowing that \(b \ge 0\) or \(a > 0\) is often exactly what turns \(|b|\) into \(b\) or lets a factor move under a square root, and those are the simplifications you actually need when you clean up a formula for code.

      How to Use the Simplifier

      1. Type the expression. The result updates while you type. Press Enter to simplify immediately.
      2. Add the domain, one condition per line, for example x > 0, 0 <= y <= 10, x in [0, 1] or n integer. Without a domain every variable may be any real number.
      3. Copy the result as plain text, LaTeX or JavaScript. The badge tells you at how many sample points the result was compared with your input, and How it was simplified lists the rules that were used, the domain as it was understood and the expanded form.

      A few examples of what it does:

      Input Notation

      The parser accepts the usual mathematical notation as well as code, so you can paste an expression from a paper or from a JavaScript file.

      WhatYou can write
      Arithmetic+ - * /, ·, ×, ÷, implicit multiplication 2x, 3(x+1), x y
      Powers and rootsx^2, x**2, x², sqrt(x), √x, cbrt(x), pow(x, 3), hypot(a, b)
      Functionssin cos tan cot sec csc, asin acos atan (also arcsin …), sinh cosh tanh coth, asinh acosh atanh, exp log ln log10 log2, abs or |x|, sign floor ceil round min max
      Constantspi, π, e, E, Math.PI, Math.E
      Comparisons< <= > >= == = !=, ≤ ≥ ≠, chains such as 0 <= x < 1
      Conditions&& || !, and or not, ∧ ∨ ¬
      Numbers12, .25, 1.5e-3; decimals are converted to exact fractions

      log is the natural logarithm, as in JavaScript and most mathematics software. e always means Euler's number, so use another letter for a variable. Names of several letters such as xy or speed are single variables; write x y or x*y for a product. A name of several letters directly before a bracket must be a known function, so a typo such as sinn(x) is reported instead of silently becoming a product; a single letter before a bracket, as in a(b + c), is a multiplication. Every Math. prefix is ignored, which makes pasting code painless.

      Domains and Assumptions

      Many identities hold only on part of the real line. \(\sqrt{x^2} = |x|\) is always true, but \(\sqrt{x^2} = x\) needs \(x \ge 0\). The simplifier therefore never assumes a sign it cannot prove, and the domain field is how you supply the missing knowledge. Each line is one condition:

      Linear conditions in a single variable become an interval for that variable. With these intervals the simplifier evaluates every subexpression in interval arithmetic and decides signs: \(|u|\) becomes \(u\) if \(u\) is provably non-negative and \(-u\) if it is provably non-positive, a positive factor may move under a square root, an argument of min or max that can never win is dropped, and a common factor of known sign is divided out of an inequality (flipping it if the factor is negative). Integer variables enable periodicity: with n integer, \(\tan(x + n\pi) = \tan x\) and \(\sin(x + 2n\pi) = \sin x\). Conditions involving several variables, such as x < y, are not used for proofs, but they do restrict the points used for the numerical check.

      A typical case is a cost expression like

      \[bx + wy + \min\bigl(b(y - x) + |b|z,\; w(x - y) + |w|z\bigr)\]

      with weights \(b, w \ge 0\). With that domain the absolute values disappear and the common factors come out: \(bx + wy + \min\bigl(b(y - x + z),\, w(x - y + z)\bigr)\), which is shorter and cheaper to evaluate in a hot loop.

      How It Works

      Under the surface sits a small computer algebra system, written from scratch for this page. It works in four stages.

      1. Parsing

      A recursive-descent parser turns the text into a syntax tree with the usual precedence: conditions bind weakest, then comparisons, sums, products and implicit products, unary minus, and powers, which are right-associative, so \(a^{b^c} = a^{(b^c)}\) and \(-x^2 = -(x^2)\). Errors report the position so the editor can point at it.

      2. Canonical form

      The tree is rebuilt through constructors that normalize as they go, the same idea that classic computer algebra systems call automatic simplification:

      3. Rewriting and search

      Not every simplification makes a formula shorter at every step, so the canonical form is the starting point for a search. Rewrite rules propose alternative forms of each subexpression, bottom-up:

      Every candidate is scored by the number of operations of its displayed form, and the cheapest one wins. Every rule that is not an unconditional identity, including all rules that use the domain, is checked numerically before it may win, so a faulty rule application can waste time but cannot change the result.

      4. Presentation and verification

      The winner is then written the way people read formulas: common factors are pulled out of sums (\(by - bx + bz = b(y - x + z)\)), \(\sin u/\cos u\) is folded back into \(\tan u\), negative exponents become fractions, terms are ordered by degree, and a sum never starts with a minus sign if it can be avoided. Finally the result is compared with your original input at up to 64 random points of the domain. Points where the input is not defined are skipped, and so are points where the input itself is numerically unstable, for example \(\sin\) of a huge argument, so that rounding noise is not mistaken for an error.

      Equations and Inequalities

      A relation \(L \mathrel{\square} R\) is rewritten as \(P = L - R \mathrel{\square} 0\). \(P\) is expanded and divided by its content, so all coefficients become coprime integers: \(x/3 \le 1/2\) turns into \(2x \le 3\). Common factors with a known sign are divided out, and the inequality is flipped when the factor is negative. For display, terms with a positive coefficient go to the left side and the others to the right, and the side holding the alphabetically first variable is placed on the left: \(-b \le -a\) becomes \(a \le b\), and \(-k > 0\) becomes \(k < 0\).

      If both sides are provably non-negative and contain a root or an absolute value, squaring is an equivalence, which is why \(|x| = \sqrt{y}\) simplifies to \(x^2 = y\). Conditions joined with && are normalized individually, duplicates are removed, and bounds on the same expression are merged: x > 3 && x > 5 becomes x > 5.

      Output Formats

      Limits

      Frequently Asked Questions

      Is my input sent to a server?

      No. Parsing, simplification and verification all run in JavaScript in your browser. The page only puts the expression into the URL fragment so that you can bookmark or share it.

      Why does abs(x) not simplify to x?

      Because it is only true for \(x \ge 0\). Add x >= 0 to the domain and it does.

      Why is the result an equation in a different order than I expected?

      \(y = x^2\) and \(x^2 = y\) are the same equation. The simplifier puts the side with the alphabetically first variable on the left so that results are predictable.

      Can I trust the result?

      Every step is an algebraic identity, and the final result is additionally compared with your input at random points of the domain. The badge shows how many points were checked. If the check fails or the input is undefined on the sampled domain, the badge says so.

      How do I convert a formula to JavaScript?

      Enter it and switch the output to JavaScript. You get a single expression that uses Math functions and constants and can be pasted into code, already simplified.

      Does it work for Boolean logic?

      It combines comparisons with &&, || and !. For minimizing pure Boolean functions of variables use the Boolean expression simplifier.