Using Assumptions

The Wolfram Language normally makes as few assumptions as possible about the objects you ask it to manipulate. This means that the results it gives are as general as possible. But sometimes these results are considerably more complicated than they would be if more assumptions were made.

Doing operations with assumptions.

(RefLink[Simplify, paclet:ref/Simplify]) by default does essentially nothing with this expression:

Simplify[1/Sqrt[x]-Sqrt[1/x]]

The reason is that its value is quite different for different choices of x:

%/.x->{-3,-2,-1,1,2,3}

With the assumption x>0, (RefLink[Simplify, paclet:ref/Simplify]) can immediately reduce the expression to 0:

Simplify[1/Sqrt[x]-Sqrt[1/x],x>0]

Without making assumptions about x and y, nothing can be done:

FunctionExpand[Log[x y]]

If x and y are both assumed positive, the log can be expanded:

FunctionExpand[Log[x y],x>0&&y>0]

By applying (RefLink[Simplify, paclet:ref/Simplify]) and (RefLink[FullSimplify, paclet:ref/FullSimplify]) with appropriate assumptions to equations and inequalities, you can in effect establish a vast range of theorems.

Without making assumptions about x, the truth or falsity of this equation cannot be determined:

Simplify[Abs[x]==x]

Now (RefLink[Simplify, paclet:ref/Simplify]) can prove that the equation is true:

Simplify[Abs[x]==x,x>0]

This establishes the standard result that the arithmetic mean is larger than the geometric one:

Simplify[(x+y)/2>=Sqrt[x y],x>=0&&y>=0]

This proves that erf(x) lies in the range (0,1) for all positive arguments:

FullSimplify[0<Erf[x]<1,x>0]

(RefLink[Simplify, paclet:ref/Simplify]) and (RefLink[FullSimplify, paclet:ref/FullSimplify]) always try to find the simplest forms of expressions. Sometimes, however, you may just want the Wolfram Language to follow its ordinary evaluation process, but with certain assumptions made. You can do this using (RefLink[Refine, paclet:ref/Refine]). The way it works is that (RefLink[Refine, paclet:ref/Refine])[expr,assum] performs the same transformations as the Wolfram Language would perform automatically if the variables in expr were replaced by numerical expressions satisfying the assumptions assum.

There is no simpler form that (RefLink[Simplify, paclet:ref/Simplify]) can find:

Simplify[Log[x],x<0]

(RefLink[Refine, paclet:ref/Refine]) just evaluates (RefLink[Log, paclet:ref/Log])[x] as it would for any explicit negative number x:

Refine[Log[x],x<0]

An important class of assumptions is those which assert that some object is an element of a particular domain. You can set up such assumptions using x∈dom, where the ∈ character can be entered as el or ∖[(RefLink[Element, paclet:ref/Element])].

Asserting that objects are elements of domains.

This confirms that π is an element of the domain of real numbers:

Pi ∈ Reals

These numbers are all elements of the domain of algebraic numbers:

{1,Sqrt[2],3+Sqrt[5]} ∈ Algebraics

The Wolfram Language knows that π is not an algebraic number:

Pi ∈ Algebraics

Current mathematics has not established whether e+π is an algebraic number or not:

E+Pi ∈ Algebraics

This represents the assertion that the symbol x is an element of the domain of real numbers:

x ∈ Reals

Domains supported by the Wolfram Language.

If n is assumed to be an integer, sin(nπ) is zero:

Simplify[Sin[n Pi],n ∈ Integers]

This establishes the theorem cosh(x)≥1 if x is assumed to be a real number:

Simplify[Cosh[x]>=1,x ∈ Reals]

If you say that a variable satisfies an inequality, the Wolfram Language will automatically assume that it is real:

Simplify[x ∈ Reals,x>0]

By using (RefLink[Simplify, paclet:ref/Simplify]), (RefLink[FullSimplify, paclet:ref/FullSimplify]), and (RefLink[FunctionExpand, paclet:ref/FunctionExpand]) with assumptions, you can access many of the Wolfram Language's vast collection of mathematical facts.

This uses the periodicity of the tangent function:

Simplify[Tan[x+Pi k],k ∈ Integers]

The assumption k/2 ∈ (RefLink[Integers, paclet:ref/Integers]) implies that k must be even:

Simplify[Tan[x+Pi k/2],k/2 ∈ Integers]

The Wolfram Language knows that log(x)<exp(x) for positive x:

Simplify[Log[x]<Exp[x],x>0]

(RefLink[FullSimplify, paclet:ref/FullSimplify]) accesses knowledge about special functions:

FullSimplify[Im[BesselJ[0,x]],x ∈ Reals]

The Wolfram Language knows about discrete mathematics and number theory as well as continuous mathematics.

This uses Wilson's theorem to simplify the result:

FunctionExpand[Mod[(p-1)!,p],p ∈ Primes]

This uses the multiplicative property of the Euler phi function:

FunctionExpand[EulerPhi[m n],{m,n} ∈ Integers&&GCD[m,n]==1]

In something like (RefLink[Simplify, paclet:ref/Simplify])[expr,assum] or (RefLink[Refine, paclet:ref/Refine])[expr,assum], you explicitly give the assumptions you want to use. But sometimes you may want to specify one set of assumptions to use in a whole collection of operations. You can do this by using (RefLink[Assuming, paclet:ref/Assuming]).

Specifying assumptions with larger scopes.

This tells (RefLink[Simplify, paclet:ref/Simplify]) to use the default assumption x>0:

Assuming[x>0,Simplify[Sqrt[x^2]]]

This combines the two assumptions given:

Assuming[x>0,Assuming[x ∈ Integers,Refine[Floor[Sqrt[x^2]]]]]

Functions like (RefLink[Simplify, paclet:ref/Simplify]) and (RefLink[Refine, paclet:ref/Refine]) take the option (RefLink[Assumptions, paclet:ref/Assumptions]), which specifies what default assumptions they should use. By default, the setting for this option is (RefLink[Assumptions, paclet:ref/Assumptions]):>(RefLink[$Assumptions, paclet:ref/$Assumptions]). The way (RefLink[Assuming, paclet:ref/Assuming]) then works is to assign a local value to (RefLink[$Assumptions, paclet:ref/$Assumptions]), much as in (RefLink[Block, paclet:ref/Block]).

In addition to (RefLink[Simplify, paclet:ref/Simplify]) and (RefLink[Refine, paclet:ref/Refine]), a number of other functions take (RefLink[Assumptions, paclet:ref/Assumptions]) options, and thus can have assumptions specified for them by (RefLink[Assuming, paclet:ref/Assuming]). Examples are (RefLink[FunctionExpand, paclet:ref/FunctionExpand]), (RefLink[Integrate, paclet:ref/Integrate]), (RefLink[Limit, paclet:ref/Limit]), (RefLink[Series, paclet:ref/Series]), and (RefLink[LaplaceTransform, paclet:ref/LaplaceTransform]).

The assumption is automatically used in (RefLink[Integrate, paclet:ref/Integrate]):

Assuming[n>0,1+Integrate[x^n,{x,0,1}]^2]