0 | module Data.Prim.Bits16
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 : Bits16) -> Type where
20 | LT : {0 m,n : Bits16} -> (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 : Bits16) -> Type
53 | 0 (<=) : (m,n : Bits16) -> Type
54 | m <= n = Either (m < n) (m === n)
58 | 0 (>=) : (m,n : Bits16) -> Type
63 | 0 (/=) : (m,n : Bits16) -> 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 : Bits16) -> Trichotomy (<) m n
81 | comp m n = case prim__lt_Bits16 m n of
82 | 0 => case prim__eq_Bits16 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 Bits16 (<) where
90 | transLT p q = strictLT p $
strictLT q $
LT unsafeRefl
108 | 0 GTE_MinBits16 : (m : Bits16) -> m >= MinBits16
109 | GTE_MinBits16 m = case comp MinBits16 m of
110 | LT x f g => %search
111 | EQ f x g => %search
112 | GT f g x => assert_total $
idris_crash "IMPOSSIBLE: Bits16 smaller than 0"
116 | 0 Not_LT_MinBits16 : m < 0 -> Void
117 | Not_LT_MinBits16 = GTE_not_LT (GTE_MinBits16 m)
121 | 0 LTE_MaxBits16 : (m : Bits16) -> m <= MaxBits16
122 | LTE_MaxBits16 m = case comp m MaxBits16 of
123 | LT x f g => %search
124 | EQ f x g => %search
127 | idris_crash "IMPOSSIBLE: Bits16 greater than \{show MaxBits16}"
131 | 0 Not_GT_MaxBits16 : m > MaxBits16 -> Void
132 | Not_GT_MaxBits16 = LTE_not_GT (LTE_MaxBits16 m)
137 | accessLT : (m : Bits16) -> Accessible (<) m
138 | accessLT m = Access $
\n,lt => accessLT (assert_smaller m n)
142 | WellFounded Bits16 (<) where
143 | wellFounded = accessLT
148 | accessGT : (m : Bits16) -> Accessible (>) m
149 | accessGT m = Access $
\n,gt => accessGT (assert_smaller m n)
153 | [GT] WellFounded Bits16 (>) where
154 | wellFounded = accessGT
166 | sdiv : (n,d : Bits16) -> (0 prf : 0 < d) => Bits16
167 | sdiv n d = n `div` d
180 | -> {auto 0 dgt1 : 1 < d}
181 | -> {auto 0 ngt0 : 0 < n}
182 | -> Subset Bits16 (< n)
183 | rdiv n d = Element (n `div` d) (LT unsafeRefl)
194 | smod : (n,d : Bits16) -> (0 prf : 0 < d) => Bits16
195 | smod n d = n `mod` d
206 | rmod : (n,d : Bits16) -> (0 prf : 0 < d) => Subset Bits16 (< d)
207 | rmod n d = Element (n `mod` d) (LT unsafeRefl)