I'm not seeing a clean method to redefine builtin functions like Cross, Dot, etc. in such a way they only are only applied to expressions that are using some marker-like Head value. Reduced example, let's say I'm using Foo[..]
as a head to represents some pair of expression. The pair of expressions inside a Foo might be involved so making explicit patterns doesn't go very far. Basically I'm looking to do something like this non-working example:
Foo /: Cross[v_, v_] := 0;
update 1
Trivial example is symbolically reducing quaternions over reals. One rule for the product looks like:
realQuat /:
NonCommutativeMultiply[realQuat[L_, l_], realQuat[R_, r_]] :=
realQuat[Cross[L,R] + l R + r L, r l - Dot[L,R]]
So with a pair written as a (bi)vector scalar pair without Cross reduction:
t0 = realQuat[A,a];
t1 = realQuat[A,b];
t0**t1
gives:
realQuat[a A + A b + AxA, a b - A.A]
instead of the Cross
term dropping out like this:
realQuat[a A + A b, a b - A.A]
(this is a strawman example)
attempt using TensorReduce
Starting from the suggesting of using TensorReduce, I tossed together two containers to mark symbols as either elements of R3 or R, basic funcs to add to both and a reduction function. Much cleaner than my previous attempts.
realQuatB = Alternates[]; (* for marking R3 symbols *)
realQuatS = Alternates[]; (* for marking R symbols *)
realQuatDefB[x_] := If[!MemberQ[realQuatB,x],AppendTo[realQuatB,x];];
realQuatDefS[x_] := If[!MemberQ[realQuatS,x],AppendTo[realQuatS,x];];
SetAttributes[realQuatDefB, {Listable}];
SetAttributes[realQuatDefS, {Listable}];
realQuat /: rqReduce[realQuat[Q_,q_]] := realQuat[
TensorReduce[Q, Assumptions->Element[realQuatB,Vectors[3,Reals]] &&
Element[realQuatS,Reals]],
TensorReduce[q, Assumptions->Element[realQuatB,Vectors[3,Reals]] &&
Element[realQuatS,Reals]]];
UpValues
. What do you expect as the output? Please give a concrete example, complete with example input, actual output (you have both) and desired output (you don't have this). $\endgroup$TensorReduce[Cross[A, A], Assumptions -> A \[Element] Vectors[n]]
$\endgroup$