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
- Type the expression. The result updates while you type. Press Enter to simplify immediately.
- Add the domain, one condition per line, for example
x > 0,0 <= y <= 10,x in [0, 1]orn integer. Without a domain every variable may be any real number. - 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:
- \(\dfrac{2^{x+2} + 2^x}{2^x} = 5\) and \(2^{2x} + 2^2 = 4^x + 4\)
- \(\dfrac{\sin x}{\tan x} = \cos x\), \(\dfrac{\cos x}{\sin x} = \dfrac{1}{\tan x}\) and \(\tan(x + 5\pi) = \tan x\)
- \(a\sqrt{x^2/a^2 - 1} = \sqrt{x^2 - a^2}\) for \(a > 0\)
- \(\log(x+2) - \log(x-2) = 2\operatorname{artanh}(2/x)\) and \(\dfrac{1 + \sqrt{e}}{\sqrt{e} - 1} = \coth\tfrac{1}{4}\)
- \(|x| = \sqrt{y} \iff x^2 = y\) and \(a + 3 > b + 6 \iff a > b + 3\)
- \(f > \tfrac{a}{4} + \tfrac{b}{4} + \tfrac{f}{2} \land f > \tfrac{a}{2} + \tfrac{b}{2} \iff a + b < 2f\)
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.
| What | You can write |
|---|---|
| Arithmetic | + - * /, ·, ×, ÷, implicit multiplication 2x, 3(x+1), x y |
| Powers and roots | x^2, x**2, x², sqrt(x), √x, cbrt(x), pow(x, 3), hypot(a, b) |
| Functions | sin 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 |
| Constants | pi, π, e, E, Math.PI, Math.E |
| Comparisons | < <= > >= == = !=, ≤ ≥ ≠, chains such as 0 <= x < 1 |
| Conditions | && || !, and or not, ∧ ∨ ¬ |
| Numbers | 12, .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:
- comparisons and chains:
a > 0,-1 < t < 1,2 <= x + 1 - intervals:
x in [0, 1],x ∈ (0, 10] - words:
x positive,y is negative,z nonnegative,n integer,n in Z,k natural
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:
- Exact arithmetic. Numbers are fractions of arbitrary-precision integers, so \(0.1 + 0.2\) is exactly \(3/10\) and \(2^{100}\) is exact. Roots of numbers are reduced: \(\sqrt{12} = 2\sqrt{3}\), \(8^{2/3} = 4\).
- Sums and products are flattened and sorted. Like terms are collected (\(x + (y - x) = y\)), equal bases are combined by adding exponents (\(3x^2 \cdot 2x^3 = 6x^5\)), numeric factors are distributed over a single sum, and powers of numbers split off integer exponents: \(2^{x+2} = 4 \cdot 2^x\), so \(2^{x+2} + 2^x = 5 \cdot 2^x\).
- Power rules respect signs. \((x^2)^{1/2}\) becomes \(|x|\), not \(x\); \((a^m)^n = a^{mn}\) is only used when \(n\) is an integer or \(a \ge 0\) is provable.
- Trigonometry. \(\tan\), \(\cot\), \(\sec\) and \(\csc\) are written with \(\sin\) and \(\cos\), so \(\sin x / \tan x\) cancels to \(\cos x\). Multiples of \(\pi\) in the argument are reduced (periodicity, half and quarter turns), even and odd symmetry is applied, \(\cos|x| = \cos x\), and exact values such as \(\sin\frac{\pi}{6} = \frac12\) and \(\cos\frac{\pi}{4} = \frac{\sqrt2}{2}\) are inserted.
- Exponentials and logarithms. \(\log e^x = x\), \(e^{\log x} = x\), \(e^{k\log x} = x^k\), and \(\log x^k = k \log x\) for integer \(k\) when \(x > 0\) is known.
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:
- expand products and integer powers, and factor univariate polynomials over their rational roots, so \(x^2 + 2x + 1 = (x + 1)^2\);
- combine fractions and cancel common polynomial factors, also with several variables: \(\dfrac{x^2 - y^2}{x - y} = x + y\);
- use \(\sin^2 + \cos^2 = 1\) in both directions;
- combine logarithms and recognize \(\log\frac{1+z}{1-z} = 2\operatorname{artanh} z\);
- turn exponentials into hyperbolic functions: \(\frac{e^x + e^{-x}}{2} = \cosh x\) and \(\frac{e^s + 1}{e^s - 1} = \coth\frac{s}{2}\);
- move non-negative factors under a square root: \(a\sqrt{u} = \sqrt{a^2 u}\) for \(a \ge 0\);
- normalize relations and merge conditions (next section).
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
- Plain is readable and can be pasted back into the input.
- LaTeX uses
\frac,\sqrt,\left| \right|,\operatorname{artanh}and so on, ready for a paper or a Markdown file with math support. - JavaScript is a valid expression using
Math.*, the**operator and===. Functions that JavaScript does not have are rewritten, for example \(\coth x\) as1 / Math.tanh(x), and a minus sign in front of a power is parenthesized because-x ** 2is a syntax error in JavaScript.
Limits
- Real numbers only. There is no imaginary unit; \(\sqrt{-4}\) and \(\log(-1)\) are reported as undefined.
- Equal where the input is defined. Like other computer algebra systems, the simplifier may remove a point where the input is undefined: \(\sin x/\tan x = \cos x\) also at \(x = 0\), where the left side has no value.
- Simplification, not solving. Equations are normalized but not solved, and there are no derivatives, integrals or limits.
- Heuristic search. The rules cover the common cases, and the search is bounded so that it stays fast. A shorter form can exist that the rules do not reach. Multivariate cancellation works when a factor written in the denominator divides the numerator; polynomial factoring finds rational roots of polynomials in one variable.
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.