# Abstract vector algebra with scalars

I am interested in expanding a vector expression in terms of the scalar parameter, but it doesn't give the expected result

$Assumptions = (ϵ) ∈ Reals;$Assumptions = (r | k) ∈ Vectors[3, Reals];

A[r_] := Module[{M},
$Assumptions = r ∈ Vectors[3, Reals]; M = r + k*ϵ // Simplify; Return[M] ]; q[r_] := Module[{M},$Assumptions = r ∈ Vectors[3, Reals];
M = ϵ*(r\[Cross]A[r]) + ϵ*r // Simplify;
Return[M]
];

q[r]

Coefficient[Expand[TensorReduce[q[r]], ϵ], ϵ, 1]

Coefficient[Expand[TensorReduce[q[r]], ϵ], ϵ, 2]


Edit:

Output of the first Coefficient is

    r + r\[Cross](r + k ϵ)


and should be

   r+ r\[Cross]r (* same as just r *)


and output of the second Coefficient is

   0


and should be

  r\[Cross]k

• "doesn't give the expected result" - what is the expected result? – Jason B. Aug 28 '18 at 13:36
• You really don't need to use Module for these functions, you could rewrite them as A[r_] := Assuming[r ∈ Vectors[3, Reals], r + k*ϵ // Simplify ]; q[r_] := Assuming[r ∈ Vectors[3, Reals], ϵ*(r\[Cross]A[r]) + ϵ*r // Simplify ]; – Jason B. Aug 28 '18 at 13:39
• same problem with this. The expected result is r for the first Coefficient and r x k for the second one. – Thela Hun Ginjeet Aug 28 '18 at 13:54
• I can't really help on that, just trying to help formulate the question better. It doesn't really have anything to do with the Module, so the title of the question should be changed. Next, you should edit the question to show what output you do get and what output you expect. – Jason B. Aug 28 '18 at 14:02
• You need to use $Assumptions = ϵ∈Reals && (r|k)∈Vectors[3,Reals] at the top, and remove the redefinitions of $Assumptions in your code. – Carl Woll Aug 28 '18 at 14:27

When you set the value of $Assumptions, the old value of $Assumptions is lost. Instead, use Assuming:

WolframLanguageData["Assuming","PlaintextUsage"]


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. In your case you need to use Assuming when you call TensorReduce. So: $Assumptions = ϵ∈Reals && (r|k)∈Vectors[3, Reals];

A[r_] := r + k ϵ

q[r_] := ϵ (r \[Cross] A[r]) + ϵ r

expanded = Assuming[rp ∈ Vectors[3, Reals], Expand @ TensorReduce[q[rp]]]

Coefficient[expanded, ϵ, 1]

Coefficient[expanded, ϵ, 2]


rp ϵ - ϵ^2 k \[Cross] rp

rp

-k \[Cross] rp