Skip to content

Refine ​

Simplify exprexpr using condcond (or, with no condcond, whatever is already assumed) as a fact — the same fact-driven simplification Assuming scopes for a whole subcomputation, but applied once. Provided by @enumeratio/analytic.

✓ checked against that system · ! checked, with disagreements (hover a chip)Wolfram LanguageRefine!
Refine(expr, cond)simplify exprexpr under condcond (a single condition, a List, or an And), then forget it.
Refine(expr)simplify exprexpr under whatever is already assumed (e.g. inside an enclosing Assuming).
Typed signatures
TypePackageApplies
(expression, expression?) -> expressionanalyticalways

Domain: Analytic

Details
  • Delegates entirely to compute-engine's own simplify() under a scoped assumption (see Assuming for the scoping mechanism) — this covers exactly the sign/domain reasoning simplify() already does: x2→x\sqrt{x^2} \to x under x>0x>0 (and →−x\to -x under x<0x<0), ∣x∣→x|x| \to x, ln⁡(ex)→x\ln(e^x) \to x, sign⁡(x)→1\operatorname{sign}(x) \to 1.
  • A condition that simplify() has no rule for is left alone, same as Wolfram's Refine declines a fact it can't use — this is not a general decision procedure for arbitrary predicates.

Examples

Basic #

x2→x\sqrt{x^2} \to x under x>0x > 0

live ↗
InRefine(x2,x>0)\mathrm{Refine}(\sqrt{x^2}, x\gt0)Outxx

x2→−x\sqrt{x^2} \to -x under x<0x < 0

live ↗
InRefine(x2,x<0)\mathrm{Refine}(\sqrt{x^2}, x\lt0)Out−x-x

∣x∣→x|x| \to x under x>0x > 0

live ↗
InRefine(∣x∣,x>0)\mathrm{Refine}(\vert x\vert, x\gt0)Outxx

sign⁡(x)→1\operatorname{sign}(x) \to 1 under x>0x > 0

live ↗
InRefine(sgn(x),x>0)\mathrm{Refine}(\mathrm{sgn}(x), x\gt0)Out11

ln⁡(ex)→x\ln(e^x) \to x once xx is known real

live ↗
InRefine(ln⁡(ex),x∈R)\mathrm{Refine}(\ln(e^{x}), x∈ℝ)Outxx

For real xx, x2=∣x∣\sqrt{x^2}=|x|

live ↗
InRefine(x2,x∈R)\mathrm{Refine}(\sqrt{x^2}, x∈ℝ)Out∣x∣\vert x\vert
live ↗
InAssuming(x≥0∧y<0,if IsTrue(Refine(x−y>0)) then Refine(x2y2) else 0)\mathrm{Assuming}(x≥0∧y\lt0, \text{if }\mathrm{IsTrue}(\mathrm{Refine}(x-y\gt0))\text{ then }\mathrm{Refine}(\sqrt{x^2y^2})\text{ else }0)Out−(xy)-(xy)
Scope #

With x≥0x\ge0 the cube root of the cube is xx

live ↗
InRefine(x33,x≥0)\mathrm{Refine}(\sqrt[3]{x^3}, x≥0)Outxx

This assumption does not make (ab)c(a^b)^c collapse, so it stays

live ↗
InRefine((ab)c,−1<b<1)\mathrm{Refine}((a^{b})^{c}, -1\lt b\lt1)Out(ab)c(a^{b})^{c}

Assumptions on positivity do not merge the powers here

live ↗
InRefine(apbp,a>0∧b>0)\mathrm{Refine}(a^{p}b^{p}, a\gt0∧b\gt0)Outapbpa^{p}b^{p}

A negative argument gives no simplification of the log

live ↗
InRefine(ln⁡(x),x<0)\mathrm{Refine}(\ln(x), x\lt0)Outln⁡(x)\ln(x)

For ∣p∣<1|p|<1, ln⁡xp\ln x^p becomes pln⁡xp\ln x

live ↗
InRefine(ln⁡(xp),−1<p<1)\mathrm{Refine}(\ln(x^{p}), -1\lt p\lt1)Outpln⁡(x)p\ln(x)

Assumptions on sums are not used to rewrite this equation

live ↗
InRefine(a2−b2+1=0,a+b=0)\mathrm{Refine}(a^2-b^2+1=0, a+b=0)Outa2−b2+1=0a^2-b^2+1=0

An unrelated inequality is not used

live ↗
InRefine((x−1)2+(y−2)2<32,x2+y2≤1)\mathrm{Refine}((x-1)^2+(y-2)^2\lt\frac{3}{2}, x^2+y^2≤1)Out(x−1)2+(y−2)2<32(x-1)^2+(y-2)^2\lt\frac{3}{2}

A ceiling is left alone given a range for xx

live ↗
InRefine(⌈x⌉,Inequality(2,Less,x,LessEqual,3))\mathrm{Refine}(\lceil x\rceil, \mathrm{Inequality}(2, \mathrm{Less}, x, \mathrm{LessEqual}, 3))Out⌈x⌉\lceil x\rceil

Conditions on residues do not change the fractional part

live ↗
InRefine(FractionalPart(a),a<0∧a mod 1=13)\mathrm{Refine}(\mathrm{FractionalPart}(a), a\lt0∧a\bmod1=\frac{1}{3})OutFractionalPart(a)\mathrm{FractionalPart}(a)

The assumption x>0x>0 makes x2=x\sqrt{x^2}=x

live ↗
InAssuming(x>0,Refine(x2))\mathrm{Assuming}(x\gt0, \mathrm{Refine}(\sqrt{x^2}))Outxx

Integers make the sine of kπk\pi vanish

live ↗
InRefine(sin⁡(kπ),k∈Z)\mathrm{Refine}(\sin(kπ), k∈ℤ)Out00

The cosine shift is not simplified for integer kk, only reordered

live ↗
InRefine(cos⁡(x+kπ),k∈Z)\mathrm{Refine}(\cos(x+kπ), k∈ℤ)Outcos⁡(πk+x)\cos(πk+x)

Positivity assumptions leave this real-valued test unchanged

live ↗
InRefine(2x+xpxΓ(x+2)∈R,x>0∧p>0)\mathrm{Refine}(\frac{2x+x^{p}}{xΓ(x+2)}∈ℝ, x\gt0∧p\gt0)Out2x+xpxΓ(x+2)∈R\frac{2x+x^{p}}{xΓ(x+2)}∈ℝ

A product of integers is not reduced further

live ↗
InRefine(2k3⌊x⌋k∈Z,k∈Z∧k>0∧x∈R)\mathrm{Refine}(2k^3\lfloor x\rfloor^{k}∈ℤ, k∈ℤ∧k\gt0∧x∈ℝ)Out2k3⌊x⌋k∈Z2k^3\lfloor x\rfloor^{k}∈ℤ

Floor of integer-affine expression stays

live ↗
InRefine(⌊2a+1⌋,a∈Z)\mathrm{Refine}(\lfloor2a+1\rfloor, a∈ℤ)Out⌊2a+1⌋\lfloor2a+1\rfloor

Divisibility assumptions do not simplify the mod

live ↗
InRefine(a mod 4,a+34∈Z)\mathrm{Refine}(a\bmod4, \frac{a+3}{4}∈ℤ)Outa mod 4a\bmod4

With no assumption, x2=∣x∣\sqrt{x^2}=|x|

live ↗
InRefine(x2)\mathrm{Refine}(\sqrt{x^2})Out∣x∣\vert x\vert

Together with y<0y<0, x2y2=−xy\sqrt{x^2y^2}=-xy

live ↗
InAssuming(x>0,Refine(x2y2,y<0))\mathrm{Assuming}(x\gt0, \mathrm{Refine}(\sqrt{x^2y^2}, y\lt0))Out−(xy)-(xy)

The range of Re x\mathrm{Re}\,x does not rewrite arctan⁡tan⁡x\arctan\tan x

live ↗
InRefine(arctan⁡(tan⁡(x)),−π2<Re(x)<π2)\mathrm{Refine}(\arctan(\tan(x)), -\frac{π}{2}\lt\mathrm{Re}(x)\lt\frac{π}{2})Outarctan⁡(tan⁡(x))\arctan(\tan(x))
live ↗
InRefine(arctan⁡(tan⁡(x)),−π2<ℜ(x)<π2)\mathrm{Refine}(\arctan(\tan(x)), -\frac{π}{2}\lt\Re(x)\lt\frac{π}{2})Outarctan⁡(tan⁡(x))\arctan(\tan(x))
Properties #

With x>0x>0 real yy, ln⁡xy=yln⁡x\ln x^y = y\ln x

live ↗
InRefine(ln⁡(xy),x>0∧y∈R)\mathrm{Refine}(\ln(x^{y}), x\gt0∧y∈ℝ)Outyln⁡(x)y\ln(x)

A sum x+y≥0x+y\ge0 lets the perfect square root become ∣x+y∣|x+y|

live ↗
InRefine(x2+2xy+y2,x+y≥0)\mathrm{Refine}(\sqrt{x^2+2xy+y^2}, x+y≥0)Out∣x+y∣\vert x+y\vert
Possible issues #

x2>0x^2 > 0 is left alone with no assumption — it fails exactly at x=0x=0

live ↗
InRefine(x2>0)\mathrm{Refine}(x^2\gt0)Out0<x20\lt x^2

The assumption does not decide membership, so this stays

live ↗
InRefine(x∈R,x2<1)\mathrm{Refine}(x∈ℝ, x^2\lt1)Outx∈Rx∈ℝ
live ↗
InRefine(−1<x<1,x2<1)\mathrm{Refine}(-1\lt x\lt1, x^2\lt1)Out−1<x-1\lt x
About
Examples32
Checked againstWolfram Language 17 agree15 differ
CrosswalkWolfram Language