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