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[2] 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.
$Assumptions
? It is of course the first answer that comes to mind. $\endgroup$TransformationFunctions
option forSimplify
? $\endgroup$simplify
function that callsSimplify
with the appropriateTransformationFunctions
. $\endgroup$