-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMagma.java
91 lines (87 loc) · 1.88 KB
/
Magma.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package com.github.vincentk.dedekind.algebra.structures;
import com.github.vincentk.dedekind.sets.Cardinality;
import com.github.vincentk.dedekind.sets.Element;
import com.github.vincentk.dedekind.sets.NonEmptySet;
import com.github.vincentk.dedekind.sets.binary.function.arithmetic.Addition;
import com.github.vincentk.dedekind.sets.binary.function.arithmetic.Multiplication;
import com.github.vincentk.dedekind.sets.binary.function.operation.BinaryOperation;
/**
* A set A with a binary operation (A, A) -> A.
*
* Notably, java prohibits implementing interfaces twice with different generic parameters.
* As a result, we need to distinguish statically between e.g. (M, +) and (M, *).
*
* @see https://en.wikipedia.org/wiki/Magma_(algebra)
*
* @param <T> implementation type
*/
public interface Magma<
E extends Magma.Oe<E>,
C extends Cardinality,
T extends Magma<E, C, T>>
extends
NonEmptySet<E, C, T>
{
interface Oe<E extends Oe<E>>
extends
Element<E>,
BinaryOperation<E, E>
{
}
/**
* Magma under addition (M, +).
*
* @param <T> the implementing type.
*/
interface P<
E extends P.Pe<E>,
C extends Cardinality,
T extends P<E, C, T>
>
extends
Magma<E, C, T>
{
/**
* Elements of the magma.
*
* @param <E>
*/
interface Pe<E extends Pe<E>>
extends
Oe<E>, Addition<E, E>
{
@Override
default E ap(E that) {
return plus(that);
}
}
}
/**
* Magma under multiplication (M, *).
*
* @param <T> the implementing type.
*/
interface M<
E extends M.Me<E>,
C extends Cardinality,
T extends M<E, C, T>
>
extends
Magma<E, C, T>
{
/**
* Elements of the magma.
*
* @param <E>
*/
interface Me<E extends Me<E>>
extends
Oe<E>, Multiplication<E, E>
{
@Override
default E ap(E that) {
return times(that);
}
}
}
}