Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove conformance to AlgebraicField on Quaternion #229

Merged

Conversation

markuswntr
Copy link
Contributor

@markuswntr markuswntr commented Apr 27, 2022

As of now, Quaternion conforms to the AlgebraicField protocol defined in RealModule. 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 of AlgebraicField on Quaternion, but contradicts the mathematical definition – and the definition in the AlgebraicField documentation noting that:

... a field is a commutative group under its addition, the non-zero elements of the field form a commutative group under its multiplication, and the distributive law holds.

I would like to propose to remove the conformance to AlgebraicField and replace it with SignedNumeric, but to keep the implementation of the division operators and reciprocoal, as these are well defined for quaternions.

Replace the (incorrect) conformance on AlgebraicField with a conformance to SignedNumeric
@markuswntr markuswntr changed the title Remove conformance to AlgebraicField on quaternions Remove conformance to AlgebraicField on Quaternion Apr 27, 2022
@markuswntr
Copy link
Contributor Author

markuswntr commented Apr 27, 2022

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 #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.

@markuswntr markuswntr marked this pull request as ready for review June 21, 2022 06:20
@stephentyrone stephentyrone merged commit bab8d4e into apple:Quaternions Nov 30, 2023
@markuswntr markuswntr deleted the quaternion/division-algebra branch March 13, 2024 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants