0 | module Data.Prim.Int32
2 | import public Control.WellFounded
3 | import public Data.DPair
4 | import public Data.Prim.Ord
5 | import public Algebra.Solver.Ring
6 | import Syntax.PreorderReasoning
10 | unsafeRefl : a === b
11 | unsafeRefl = believe_me (Refl {x = a})
19 | data (<) : (m,n : Int32) -> Type where
20 | LT : {0 m,n : Int32} -> (0 prf : (m < n) === True) -> m < n
26 | 0 mkLT : (0 prf : (m < n) === True) -> m < n
33 | 0 runLT : m < n -> (m < n) === True
34 | runLT (LT prf) = prf
39 | strictLT : (0 p : m < n) -> Lazy c -> c
40 | strictLT (LT prf) x = x
48 | 0 (>) : (m,n : Int32) -> Type
53 | 0 (<=) : (m,n : Int32) -> Type
54 | m <= n = Either (m < n) (m === n)
58 | 0 (>=) : (m,n : Int32) -> Type
63 | 0 (/=) : (m,n : Int32) -> Type
64 | m /= n = Either (m < n) (m > n)
70 | 0 ltNotEQ : m < n -> Not (m === n)
71 | ltNotEQ x = strictLT x $
assert_total (idris_crash "IMPOSSIBLE: LT and EQ")
73 | 0 ltNotGT : m < n -> Not (n < m)
74 | ltNotGT x = strictLT x $
assert_total (idris_crash "IMPOSSIBLE: LT and GT")
76 | 0 eqNotLT : m === n -> Not (m < n)
77 | eqNotLT = flip ltNotEQ
80 | comp : (m,n : Int32) -> Trichotomy (<) m n
81 | comp m n = case prim__lt_Int32 m n of
82 | 0 => case prim__eq_Int32 m n of
83 | 0 => GT (ltNotGT $
LT unsafeRefl) (ltNotEQ $
LT unsafeRefl) (LT unsafeRefl)
84 | x => EQ (eqNotLT unsafeRefl) (unsafeRefl) (eqNotLT unsafeRefl)
85 | x => LT (LT unsafeRefl) (ltNotEQ $
LT unsafeRefl) (ltNotGT $
LT unsafeRefl)
88 | Total Int32 (<) where
90 | transLT p q = strictLT p $
strictLT q $
LT unsafeRefl
99 | MinInt32 = -
0x80000000
104 | MaxInt32 = 0x7fffffff
108 | 0 GTE_MinInt32 : (m : Int32) -> m >= MinInt32
109 | GTE_MinInt32 m = case comp MinInt32 m of
110 | LT x f g => %search
111 | EQ f x g => %search
114 | idris_crash "IMPOSSIBLE: Int32 smaller than \{show MinInt32}"
118 | 0 Not_LT_MinInt32 : m < MinInt32 -> Void
119 | Not_LT_MinInt32 = GTE_not_LT (GTE_MinInt32 m)
123 | 0 LTE_MaxInt32 : (m : Int32) -> m <= MaxInt32
124 | LTE_MaxInt32 m = case comp m MaxInt32 of
125 | LT x f g => %search
126 | EQ f x g => %search
129 | idris_crash "IMPOSSIBLE: Int32 greater than \{show MaxInt32}"
133 | 0 Not_GT_MaxInt32 : m > MaxInt32 -> Void
134 | Not_GT_MaxInt32 = LTE_not_GT (LTE_MaxInt32 m)
139 | accessLT : (m : Int32) -> Accessible (<) m
140 | accessLT m = Access $
\n,lt => accessLT (assert_smaller m n)
144 | WellFounded Int32 (<) where
145 | wellFounded = accessLT
150 | accessGT : (m : Int32) -> Accessible (>) m
151 | accessGT m = Access $
\n,gt => accessGT (assert_smaller m n)
155 | [GT] WellFounded Int32 (>) where
156 | wellFounded = accessGT
164 | sdiv : (n,d : Int32) -> (0 prf : d /= 0) => Int32
165 | sdiv n d = n `div` d
169 | smod : (n,d : Int32) -> (0 prf : d /= 0) => Int32
170 | smod n d = n `mod` d