I wonder if Swift's type system is powerful enough to be (mis)used in order to implement for example the 2D projective geometric algebra R*(2,0,1) (with e02 = 0 and e12 = e22 = 1) so that there are types
Scalar
-
E0
,E1
,E2
-
E01
,E02
,E12
-
E012
(These could be typealiases for some recursive generic type constructs.)
and that eg the product of
- an
E0
and anE0
is of typeScalar
(e0*e0 = 0
) - an
E1
and anE1
is of typeScalar
(e1*e1 = 1
) - an
E2
and anE2
is of typeScalar
(e2*e2 = 1
) - an
E0
and anE2
is of typeE02
(e0*e2 = e02
) - an
E1
and anE0
is of typeE01
(e1*e0 = -e0*e1 = -e01
) - an
E2
,E0
and anE1
is of typeE012
(e2*e0*e1 = -e0*e2*e1 = e0*e1*e2 = e012
) - an
E2
and anE02
is of typeE0
(e2*e02 = e2*e0*e2 = -e2*e2*e0 = -(1)*e0 = -e0
)
That is, is it possible to encode the rules of the algebra at the type level, without resorting to hard coding everything / code generation?
I guess it might be intentionally impossible in Swift / require the type system to be Turing complete or something?