# Replacements/Substitutions in Mathematica

I am a new user of Mathematica and have some questions about the simplifications of calculated expressions. I am unable to attach an image of the session, but my Mathematica commands are:

Element[{x,y,z},Reals]
Element[{x0,y0,z0},Reals]
rhatV={x-x0,y-y0,z-z0}
rhat=Norm[rhatV]


In the expression for rhat, I am unable to get rid of the Abs functions, despite the Reals declarations.

phi=1/rhat
D[phi,x]


In the evaluated derivative is there a way to have x-x0 in the numerator recognized as rhatV[] and the denominator as rhat^3, such that it can be used in additional operations?

• Look up Assuming[]... – J. M. is away Nov 21 '12 at 15:59
• Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2)Read the FAQs! 3) When you see good Q&A, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. ALSO, remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign – chris Nov 21 '12 at 18:56
• The documentation included with Mathematica includes two tutorials you should read: Using Assumptions and Simplifying with Assumptions. – m_goldberg Nov 21 '12 at 22:31

The formulation of the assumptions are one problem, and the fact that you're not using them is another:

$Assumptions = {Element[{x, y, z}, Reals], Element[{x0, y0, z0}, Reals] }; rhatV = {x - x0, y - y0, z - z0}; rhat = Simplify[Norm[rhatV]]; phi = 1/rhat; D[phi, x] $-\frac{x-\text{x0}}{\left((x-\text{x0})^2+(y-\text{y0 })^2+(z-\text{z0})^2\right)^{3/2}}$Here I put the assumptions in a special variable $Assumptions, assuming (no pun intended) that you'll want to re-use them in further calculations. But to use them in the first place, you have to add Simplify or another command that specifically utilizes the Assumptions option.

• Thanks, I thought that the declaration of the variables as Reals would be automatically incorporated in subsequent calculations, but I understand from your response that it should be formulated as Assumptions and have calculations specifically invoke the Assumptions. I hope there is a way to have substitutions made so that the numerator is recognized as the first element of the vector rhatV and the denominator as rhat^3. – user1031565 Nov 21 '12 at 17:01
• @user1031565 For the last part of the question, you may be better off using spherical coordinates. – Jens Nov 21 '12 at 19:23

Mathematica is a term rewriting system, variables need not to be declared as in compiled languages. For a general view I recommend reading this post by Leonid Shifrin. In general, symbolic variables are processed as complex if not assumed otherwise. To specify assumptions there are a few ways :

• $Assumptions are recommended when you want to use global assumptions. • for local assumptions there is Assuming[ assum, expr] where expr can be a compound expression (see CompoundExpression, a shorthand - ;) : Assuming[ assum, expr] evaluates expr with assum appended to$Assumptions, so that assum
is included in the default assumptions used by functions such as Refine, Simplify, and
Integrate


Many functions as Simplify, Refine, and Integrate have options Assumptions that specifies default assumptions to be made about symbolic quantities.

Here are a few examples how to specify desired assumptions and compute a given expression :

D[ Simplify[ 1/ Norm @ rhatV, {x, y, z}  ∈ Reals && {x0, y0, z0}  ∈ Reals], x]


and

D[ Simplify[ 1/EuclideanDistance[{x, y, z}, {x0, y0, z0}],
{x, y, z}  ∈ Reals && {x0, y0, z0}  ∈ Reals], x]


and

Assuming[ {x, y, z}  ∈ Reals && {x0, y0, z0}  ∈ Reals, D[ 1/Simplify @ Norm @ rhatV, x] ]
`

all these expressions return : • Thanks to you and @Jens for clearing up my confusion on declarations. – user1031565 Nov 21 '12 at 17:05