keep_weight
Keep terms with indicated weight
Keep only those terms for which a product has the indicated
weight. Weights are computed by making use of the Weight
property of symbols. This algorithm does the opposite
of drop_weight
.
As an example, consider the simple case in which we want to keep all
terms with 3 fields. This is done using
{A,B}::Weight(label=field);
ex:=A B B + A A A + A B + B;
keep_weight(_, $field=3$);
Attached property Weight to [A,B].
ABB+AAA+AB+B
ABB+AAA
However, you can also do more complicated things by assigning non-unit
weights to symbols, as in the example below,
{A,B}::Weight(label=field);
C::Weight(label=field, value=2);
ex:= A B B + A A A + A B + A C + B;
Attached property Weight to [A,B].
Attached property Weight to C.
ABB+AAA+AB+AC+B
keep_weight(_, $field=3$);
ABB+AAA+AC
Weights also apply to tensorial expressions. Consider e.g. a situation
in which we have a polynomial of the type
ex:=c^{a} + c^{a}_{b} x^{b} + c^{a}_{b c} x^{b} x^{c} + c^{a}_{b c d} x^{b} x^{c} x^{d};
ca+cabxb+cabcxbxc+cabcdxbxcxd
and we want to keep only the quadratic term. This can be done using
x^{a}::Weight(label=crd, value=1);
c^{#}::Weight(label=crd, value=0);
Attached property Weight to xa.
Attached property Weight to c#.
keep_weight(ex, $crd=2$);
cabcxbxc
Weights can be "inherited" by operators by using
the
WeightInherit
property. Here is an example using
partial derivatives,{\phi,\chi}::Weight(label=small, value=1);
\partial{#}::PartialDerivative;
\partial{#}::WeightInherit(label=all, type=multiplicative);
ex:=\phi \partial_{0}{\phi} + \partial_{0}{\lambda} + \lambda \partial_{3}{\chi};
keep_weight(_, $small=1$);
Attached property Weight to [ϕ,χ].
Attached property PartialDerivative to ∂#.
Attached property WeightInherit to ∂#.
ϕ∂0ϕ+∂0λ+λ∂3χ
λ∂3χ
If you want to use weights for dimension counting, in which operators
can also carry a dimension themselves (e.g. derivatives), then use the
self
attribute,reset();
{\phi,\chi}::Weight(label=length, value=1);
x::Coordinate;
\partial{#}::PartialDerivative;
\partial{#}::WeightInherit(label=length, type=multiplicative, self=-1);
ex:=\phi \partial_{x}{\phi} + \phi\chi + \partial_{x}{ \phi \chi**2 };
Attached property Weight to [ϕ,χ].
Attached property Coordinate to x.
Attached property PartialDerivative to ∂#.
Attached property WeightInherit to ∂#.
ϕ∂xϕ+ϕχ+∂x(ϕχ2)
keep_weight(_, $length=1$);
ϕ∂xϕ