Add Abstract Algebra Interface Hierarchy proposal - #5810
Conversation
csyonghe
left a comment
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
...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 |
There was a problem hiding this comment.
...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 |
There was a problem hiding this comment.
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)?
There was a problem hiding this comment.
I think there are similar examples for most algebraic structures, but it's easier to come up with examples for the more generic ones.
|
Closing in favor of shader-slang/spec#7 |
closes #4681