# Attaching persistent assumptions to symbol definition

Is it possible to attach assumptions to a symbol? This relates to this question. Most of my work involves physical equations, i.e. there are basic assumptions on variables that will always hold true (in a physical sense).

My current example involves higher-order Laguerre Gaussian modes:

u[p_, m_, λ_, w_, R_, ψ_, ψ0_, r_, θ_] :=
Sqrt[(2 p!)/((1 + DiscreteDelta[0, m]) π (m + p)!)]
Exp[I (2 p + m + 1) (ψ - ψ0)]/w
((Sqrt r)/w)^m LaguerreL[p, m, (2 r^2)/w^2]
Exp[-I (2 π)/λ r^2/2 (1/R - I λ/(π w^2)) + I m θ]


For this example, consider $p=m=\psi=\psi 0=0$, which gives the electric field distribution for the basic Gaussian mode. I can get the mode intensity with (I'm sure there is a more concise way of writing the assumption):

Assuming[(And @@ (# > 0 && # ∈ Reals & /@ {λ, w, R, r, θ})) ~And~
(r > 0 && r ∈ Reals && -π < θ <= π && θ ∈ Reals),
Abs[u[0, 0, λ, w, R, 0, 0, r, θ]]^2 //Simplify]


$$\frac{e^{-\frac{2 r^2}{w^2}}}{\pi w^2}$$

Back to the question, how can I define a function that "simplifies" without explicitly listing the assumptions every time a I perform an algebraic operation on said function? Looking at the previously linked question, I can define a function

v[p_, m_, λ_, w_, R_, ψ_, ψ0_, r_, θ_] :=
Assuming[(And @@ (# > 0 && # ∈ Reals & /@ {λ, w, R, r, θ})) ~And~
(r > 0 && r ∈ Reals && -π < θ <= π && θ ∈ Reals),
u[p, m, λ, w, R, ψ, ψ0, r, θ]]


but the Simplify operation applies only to the definition, any operation such as

Abs[v[0, 0, λ, w, R, 0, 0, r, θ]]^2 // Simplify


$$\frac{e^{-2 \text{Re}\left[r^2 \left(\frac{1}{w^2}+\frac{i \pi }{R \lambda }\right)\right]}}{\pi \text{Abs}[w]^2}$$ does not simplify.

Defining functions using pattern conditions, i.e. f[a?Positive]:=... do not allow for algebraic manipulation, as f[a] will remain unevaluated.

I am hesitant to use $Assumptions. Whilst it would work in this specific example, I can see several problems where I'd like to use the same approach, but setting global assumptions would cause other issues. • Could you be more specific about your reservations regarding $Assumptions? It is of course the first answer that comes to mind. May 7, 2012 at 5:59
• It sets global assumptions. Another layer of things I set and then forget about.. :/ May 7, 2012 at 6:10
• Have you looked at and considered the use of the TransformationFunctions option for Simplify? May 7, 2012 at 6:15
• First time I heard about that option! It sort of does what I want, using a simplify function that calls Simplify with the appropriate TransformationFunctions. May 7, 2012 at 7:48
• Okay, I'll post that as an answer. Don't rush to accept it; that may discourage someone from posting a better one. May 7, 2012 at 7:50

A slightly more flexible approach is to use assumptions as an option for u[..]:

ClearAll[u, assuming, asmptns];
asmptns = And @@
Flatten@{(# > 0) & /@ {λ, w, R, r, θ}, (# ∈ Reals) & /@ {λ, w, R, r, θ}, -π < θ <= π};
Options[u] = {"assuming" -> asmptns};
u[p_, m_, λ_, w_, R_, ψ_, ψ0_, r_, θ_] :=
Sqrt[(2 p!)/((1 + DiscreteDelta[0, m]) π (m + p)!)]
Exp[I (2 p + m + 1) (ψ - ψ0)]/w ((Sqrt r)/w)^ m
LaguerreL[p, m, (2 r^2)/ w^2]
Exp[-I (2 π)/λ r^2/ 2 (1/R - I λ/(π w^2)) + I m θ];
Abs[u[0, 0, λ, w, R, 0, 0, r, θ]]^2 //
Simplify[#, OptionValue[u, "assuming"]] &


gives and, re-simplify with modified assumptions

SetOptions[u, "assuming" -> asmptns && (w == 2)];
Abs[u[0, 0, λ, w, R, 0, 0, r, θ]]^2 //
Simplify[#, OptionValue[u, "assuming"]] &


to get If you don't want to use \$Assumptions you may set the assumptions to a variable:

dom = And @@ (# > 0 &) /@ {λ, w, R, r} && -π < θ <= π
(* λ > 0 && w > 0 && R > 0 && r > 0 && -π < θ <= π *)


Then call (Full)Simplify with these assumptions:

Abs[v[0, 0, λ, w, R, 0, 0, r, θ]]^2 //  Simplify[#, dom] &


giving: 1/π

The TransformationFunctions option for Simplify and FullSimplify allows you to create custom simplification manipulations that can be used either in place of or in addition to the defaults. Combined with SetOptions this can allow special handling of certain expressions by Simplify and/or FullSimplify.

My proposal is elementary, and I am not answering your question in the form it has been asked. However, did you not think about custom assumptions or custom Simplify? For example, in your case let us fix the assumptions:

assume = (And @@ (# > 0 && # ∈ Reals & /@ {λ, w, R, r, θ})) ~ And ~
(r > 0 && r ∈ Reals && -π < θ <= π && θ ∈ Reals);


and make a custom Simplify:

mySimp[expr_] := Simplify[expr, assume];


u[p_, m_, λ_, w_, R_, ψ_, ψ0_, r_, θ_] :=
Sqrt[(2 p!)/((1 + DiscreteDelta[0, m]) π (m + p)!)]
Exp[I (2 p + m + 1) (ψ - ψ0)]/w
((Sqrt r)/w)^m LaguerreL[p, m, (2 r^2)/w^2]
Exp[-I (2 π)/λ r^2/2 (1/R - I λ/(π w^2)) + I m θ]


Let us simplify:

Abs[u[0, 0, λ, w, R, 0, 0, r, θ]]^2 // mySimp
(* =>  1/π  *)


This will work during the whole session. In a new session you need to only once execute a cell with this (and analogous) definition.

It seems me to be better than to attach the assumption to any variable. If I would attach a restriction to a variable, in 5 minutes I would need to use this variable outside of the just attached restriction :).