Closed markuswntr closed 9 months ago
Its worth noting, that we could add another protocol (a DivisionRing
, or similar in naming) that extends SignedNumeric
by division operators and reciprocal
– effectively, what is now defined as an AlgebraicField
– and then refine AlgebraicField
on top of the new division algebra protocol by guaranteeing commutativity. Quaternions would then conform to DivisionRing
while Real and Complex numbers would conform to AlgebraicField
.
I don't think a DivisionRing
protocol is of much use right now, but I am happy to draft an example an to bring this question over to e.g. the Swift Forums, if you feel it is worth it.
Edit: I just found the discussion on AlgebraicField
in https://github.com/apple/swift-numerics/pull/91 where this trade-off has been discussed with attention to all aspects. Based on the explicit design decision and comments, I think removing the conformance without a replacement (other than SignedNumeric
) is the right thing to do for now.
As of now,
Quaternion
conforms to theAlgebraicField
protocol defined inRealModule
. However quaternions are a non-commutative, associative algebra over the real numbers and thus, this is incorrect. Their structure is similiar to a field, but given that their multiplication is non-commutative they form a division algebra (division ring). This has no implications on the implementation ofAlgebraicField
onQuaternion
, but contradicts the mathematical definition – and the definition in theAlgebraicField
documentation noting that:I would like to propose to remove the conformance to
AlgebraicField
and replace it withSignedNumeric
, but to keep the implementation of the division operators andreciprocoal
, as these are well defined for quaternions.