FM This page is to illustrate some of the proposals made in the expanding the expansion prefix page. Please refer to this page to know what this subject is about. This changes could be done in TCL 10.0, since TCL 9.0 is already out.
Here I use some prefixes as they could be configured :
Then, we can write :
# matrix determinant
proc {double}determinant {typed_args}{
{matrix[3x3]}M
} {=}{
{{double}*}(a, b, c, d, e, f, g, h, i) = {{*}*}$M;
$a*$e*$i + $b*$f*$g + $c*$d*$h \
- ($g*$e*$c + $i*$d*$b + $h*$f*$a)
}
# vectorial product
proc {vec[3]}v_prod {typed_args}{
{vec[3]}A
{vec[3]}D
} {=}{
{{double}*}(a,b,c) = {*}$A;
{{double}*}(d,e,f) = {*}$D;
($b*$f-$e*$c, $c*$d-$f*$a, $a*$e-$d*$b)
}
# dot product
proc {double}dot_product {typed_args}{
{vec[3]}A
{vec[3]}B
} {=}{
{{double}*}(a1, a2, a3) = {*}$A;
{{double}*}(b1, b2, b3) = {*}$B;
$a1*$b1 + $a2*$b2 + $a3*$b3
}
# tensorial product
proc {matrix[3x3]}tensorial_product {typed_args}{
{vec[3]}A
{vec[3]}B
} {=}{
{{double}*}(a1, a2, a3) = {*}$A;
{{double}*}(b1, b2, b3) = {*}$B;
(($a1*$b1, $a1*$b2, $a1*$b3),
($a2*$b1, $a2*$b2, $a2*$b3),
($a3*$b1, $a3*$b2, $a3*$b3))
}
# Lie product
proc {matrix[3x3]}lie_product {typed_args}{
{vec[3]}A
{vec[3]}B
} {=}{
{{double}*}(a1, a2, a3) = {*}$A;
{{double}*}(b1, b2, b3) = {*}$B;
(( 0 , $b1*$a2 - $a1*$b2, $b1*$a3 - $a1*$b3),
($a1*$b2 - $b1*$a2, 0 , $b2*$a3 - $a2*$b3),
($a1*$b3 - $b1*$a2, $a2*$b3 - $b2*$a3, 0 ))
}
Is that not a lot more clear an synthetic that all what we can write currently ?