I want to define my own little 'Inner Product' function satisfying properties of linearity and commutativity, and I'd like to use the "$\langle$" and "$\rangle$" symbols to output my results. For this I am using AngleBracket
which has no built-in meaning.
I was able to use SetAttributes[AngleBracket,Orderless]
to give my inner product the property of commutativity. $\langle v,w\rangle=\langle w,v\rangle$.
Then I am able to inconsistently get the AngleBracket to distribute over addition using for example Distribute[AngleBracket[u+v,w]]
But I am at a loss to impose the conditions $\langle a v, w\rangle=a\langle v,w \rangle$ where $a$ satisfies NumericQ[a]==True
, and especially $\langle 0,v\rangle = 0$.
How can do this? Do I need to write my own 'myInnerProductSimplify' function?
Answer
From your question it can be deduced that you're interested only in the Euclidean scalar product for real vector spaces, so I'll make that assumption.
In version 9, I think the cleanest way to do the symbolic manipulations you're after is to use the new capabilities of TensorReduce
. The special case of a null vector does require care because the product of the scalar $0$ with a vector is evaluated by Mathematica to yield $0$ which should then be interpreted as the null vector. This causes no problems if we define AngleBracket
to yield zero for such $0$ arguments. So the following works if we make a decision at the outset what symbols we will assume to represent vectors - here I add that to the global variable $Assumptions
:
AngleBracket[0, y_] := 0
AngleBracket[x_, 0] := 0
AngleBracket[x_, y_] := Dot[x, y]
Clear[dim];
$Assumptions =
a ∈ Vectors[dim, Reals] && b ∈ Vectors[dim, Reals];
Now some tests:
AngleBracket[3 a, b] == 3 AngleBracket[a, b] // TensorReduce
(* ==> True *)
Assuming[x ∈ Reals,
TensorReduce[AngleBracket[x a, b] == x AngleBracket[a, b]]]
(* ==> True *)
Assuming[x ∈ Reals,
TensorReduce[AngleBracket[a, x b] == x AngleBracket[a, b]]]
(* ==> True *)
So to do the simplifications in the above equations, one wraps them in TensorReduce
. The scalar x
is introduced through an additional assumption which I could have added to $Assumptions
, too.
The use of AngleBracket
instead of purely the built-in Dot
is still useful here because it allows me to handle the special case involving the null vector. For that I personally prefer to use BraKet
, by the way, because it only requires a single escape sequence to get the template for both factors of the scalar product.
Comments
Post a Comment