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

Add Abstract Algebra Interface Hierarchy proposal #5810

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

expipiplus1
Copy link
Collaborator

closes #4681

@expipiplus1 expipiplus1 added the pr: non-breaking PRs without breaking changes label Dec 9, 2024
Copy link
Collaborator

@csyonghe csyonghe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While adopting concepts from abstract algebra gives us flexibility and comprehensiveness, it is not necessarily the most accessible way to approach game and system developers who may not have good knowledge of abstract algebra. I recommend we rename the same interfaces to something more descriptive: IAddable, IMultiplicable, ISubtractable. We don't need to have CommutativeGroup for now.

Another big problem with the approach right now is there is no distinction on scalar types and composite types. How do I write a generic function constrained on builtin scalar types only? This is necessary to expose intrinsics or defining derived functions based on the intrinsics. We sometimes need to define generic functions on all integer scalar types, and sometimes need to define generic functions on all floating point scalar, vector or matrix types. How can we express that?

```slang
// Semigroup represents types with an associative addition operation
// Examples: Non-empty arrays (concatenation), Colors (blending)
interface Semigroup
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All interfaces should be named with I prefix in Slang's core module naming convention.

};

// Semiring adds multiplication with identity to Monoid
// Examples: Matrices, Quaternions
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Matrices and quaternions are full rings, aren't they? Of course that means they're also semirings but it's more interesting to list examples here that are not full rings. I guess the non-negative integers would be an example. (?)

// Examples: Vectors under addition, Matrices under addition
interface Group : Monoid
{
T operator-(); // Additive inverse
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the group is "additive" meaning the group operation is written + and inverse is written -, that always also implies that the group is commutative. This is sometimes called an "additive group".

Group in the most general sense usually uses some kind of operator that looks more like * (or when written, just concatenation: a*b = ab).

Should we call this AdditiveGroup and subclass it from a more general group interface that just has some interface (maybe *) for a more generic group operation? The more general Group would then also need an interface to get the inverse of an element.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...so there could be AdditiveGroup that adds an identity element called 'zero' with 'operator-' for inverse, and a MultiplicativeGroup adding an identity element called 'one' with 'reciprocal' for inverse.

Both could inherit from the more general Group that just has 'identity' and 'inverse'

// Examples: Vectors under addition, Matrices under addition
interface Group : Monoid
{
T operator-(); // Additive inverse
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...so there could be AdditiveGroup that adds an identity element called 'zero' with 'operator-' for inverse, and a MultiplicativeGroup adding an identity element called 'one' with 'reciprocal' for inverse.

Both could inherit from the more general Group that just has 'identity' and 'inverse'


// Monoid adds an identity element to Semigroup
// Examples: float3(0), identity matrix, zero quaternion
interface Monoid : Semigroup
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we deal with the fact that integers can be a monoid in two (probably more?) ways?
E.g. "Integers under addition" is a monoid, and "integers under multiplication" is another.

When you use the Monoid interface on an int, how can you specify in which way the int is a monoid (multiplication or addition, or some other operation)?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there are similar examples for most algebraic structures, but it's easier to come up with examples for the more generic ones.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr: non-breaking PRs without breaking changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Need further development of built-in interfaces
3 participants