-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZ.java
137 lines (117 loc) · 2.55 KB
/
Z.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/**
*
*/
package com.github.vincentk.dedekind.algebra.numbers;
import com.github.vincentk.dedekind.algebra.structures.Ring;
import com.github.vincentk.dedekind.geometry.MetricSpace;
import com.github.vincentk.dedekind.geometry.NumberLine;
import com.github.vincentk.dedekind.sets.Cardinality;
import com.github.vincentk.dedekind.sets.Set;
import com.github.vincentk.dedekind.sets.ordered.ConvexSet;
/**
* The integer numbers.
*/
public interface Z<
// Element type:
E extends Z.Integer<E>,
// Implementation type:
T extends Z<E, T>
>
extends
NumberLine<E, Cardinality.Countable, T>
{
/**
* Elements ∈ {@link Z}.
*
* @param <E>
*/
interface Integer<E extends Integer<E>>
extends
// addition, multiplication:
Ring.Re<E>,
NumberLine.Number<E>,
// distances etc. are defined:
MetricSpace.MeG<E, E>
{
}
/**
* The subset of integers that can be
* represented in 64-bits (i.e. as java long values).
*/
interface Z64
extends
Z<Z64.Int64, Z64>,
ConvexSet.Closed<Z64.Int64, Z64, Cardinality.Countable, Z64>
{
public interface Int64
extends Integer<Int64>
{
public long intValue();
@Override
default Int64 plus(Int64 that) {
return integer(intValue() + that.intValue());
}
@Override
default Int64 times(Int64 that) {
return integer(intValue() * that.intValue());
}
@Override
default Int64 negate() {
return integer(-intValue());
}
@Override
default int compareTo(Int64 o) {
return Long.compare(intValue(), o.intValue());
}
@Override
default boolean eq(Int64 that) {
return intValue() == that.intValue();
}
@Override
default Int64 abs() {
return intValue() >= 0 ? this : this.neg();
}
}
record Impl (long intValue) implements Int64
{
}
static Int64 integer(long n) {
return new Impl(n);
}
public static final Int64
ZERO = integer(0),
ONE = integer(1),
TWO = integer(2),
THREE = integer(3),
MIN = integer(Long.MIN_VALUE),
MAX = integer(Long.MAX_VALUE);
@Override
default boolean isEmpty() {
return false;
}
@Override
default Set<Int64, ?> intersection(Set<Int64, ?> that) {
return that;
}
@Override
default Z64 union(Set<Int64, ?> that) {
return this;
}
@Override
default boolean sub(Set<Int64, ?> that) {
return this == that;
}
@Override
default boolean sup(Set<Int64, ?> that) {
return true;
}
@Override
default Int64 upperBound() {
return MAX;
}
@Override
default Int64 lowerBound() {
return MIN;
}
}
}