# Testing of component evaluation.
#

@reset.
\alpha::Integer(0..3).
obj:= C_{\alpha};
rul:= { C_{0} -> r**2,
        C_{1} -> f(r),
		  C_{2} -> r**(-2),
		  C_{3} -> r };
evl:= @eval![@(obj)]( @(rul) );
tst:= { C_{0} -> r**2, C_{1} -> f(r), C_{2} -> r**(-2), C_{3} -> r } - @(evl);
@collect_terms!(%);
@assert(tst);

@reset.
{\alpha,\beta}::Indices(values={0,1,2,3}).
obj:= C_{\alpha} C_{\alpha};
rul:= { C_{0} -> r**2,
        C_{1} -> f(r),
		  C_{2} -> r**(-2),
		  C_{3} -> r };
evl:= @eval![@(obj)]( @(rul) );
tst:= r**2 * r**2 + f(r) * f(r) + r**(-2) * r**(-2) + r * r - @(evl);
@collect_terms!(%);
@assert(tst);

# For documentation on the algorithm, see the 'components.tex' file in the
# 'docs' directory.

@reset.
{m,n,p}::Indices.
{m,n,p}::Integer(0..3).
A_{m} B_{m n} C_{n};
rule:= { A_{0} -> 3,
         A_{2} -> q,
         B_{0 1} -> a,
         B_{2 1} -> 2 a,
         C_{1} -> c,
         C_{2} -> d };
@indexmatch(%)( @(rule) );
# This should return a map
#    {m,n} -> {0,1}, {2,1}
# indicating for which index values there is a match.

@reset.
{\alpha,\beta}::Indices("vector", position=fixed).
{\alpha,\beta}::Integer(0..3).
g_{\alpha\beta}::Metric.
obj:= C_{\alpha} C^{\alpha};
@rewrite_indices!(%)( C_{\alpha} )( g^{\alpha\beta} );
rul:= { C_{0} -> r**2,
        C_{1} -> f(r),
		  C_{2} -> r**(-2),
		  C_{3} -> r,
        g^{0 0} -> -1,
        g^{1 1} -> 1,
        g^{2 2} -> 1,
        g^{3 3} -> 1 };
evl:= @eval![@(obj)]( @(rul) );
tst:= -r**2 * r**2 + f(r) * f(r) + r**(-2) * r**(-2) + r * r - @(evl);
@collect_terms!(%);
@assert(tst);



A_m (B_n C_n (D_k D_k + 1) + 3) P_m;


@reset.
{t, r, \phi, \theta}::Coordinate.
{m,n,p,q}::Indices(values={t,r,\phi,\theta}).
g_{m n}::Metric.

SSrule:= { g_{t t}          -> -f(r),
           g_{r r}          -> 1/f(r),
           g_{\theta\theta} -> r**2,
           g_{\phi\phi}     -> r**2 \sin(\theta)**2,
           g_{m n} -> 0 };

obj:= det(g_{m n});
@eval(%)( @(SSrule) );
@maxima(%);
tst:= - r**2 \sin(\theta)**2 - @(obj);
@collect_terms!(%);
@assert(tst);
