0 | module Data.Prim.Int16
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 : Int16) -> Type where
20 | LT : {0 m,n : Int16} -> (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 : Int16) -> Type
53 | 0 (<=) : (m,n : Int16) -> Type
54 | m <= n = Either (m < n) (m === n)
58 | 0 (>=) : (m,n : Int16) -> Type
63 | 0 (/=) : (m,n : Int16) -> 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 : Int16) -> Trichotomy (<) m n
81 | comp m n = case prim__lt_Int16 m n of
82 | 0 => case prim__eq_Int16 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 Int16 (<) where
90 | transLT p q = strictLT p $
strictLT q $
LT unsafeRefl
108 | 0 GTE_MinInt16 : (m : Int16) -> m >= MinInt16
109 | GTE_MinInt16 m = case comp MinInt16 m of
110 | LT x f g => %search
111 | EQ f x g => %search
114 | idris_crash "IMPOSSIBLE: Int16 smaller than \{show MinInt16}"
118 | 0 Not_LT_MinInt16 : m < MinInt16 -> Void
119 | Not_LT_MinInt16 = GTE_not_LT (GTE_MinInt16 m)
123 | 0 LTE_MaxInt16 : (m : Int16) -> m <= MaxInt16
124 | LTE_MaxInt16 m = case comp m MaxInt16 of
125 | LT x f g => %search
126 | EQ f x g => %search
129 | idris_crash "IMPOSSIBLE: Int16 greater than \{show MaxInt16}"
133 | 0 Not_GT_MaxInt16 : m > MaxInt16 -> Void
134 | Not_GT_MaxInt16 = LTE_not_GT (LTE_MaxInt16 m)
139 | accessLT : (m : Int16) -> Accessible (<) m
140 | accessLT m = Access $
\n,lt => accessLT (assert_smaller m n)
144 | WellFounded Int16 (<) where
145 | wellFounded = accessLT
150 | accessGT : (m : Int16) -> Accessible (>) m
151 | accessGT m = Access $
\n,gt => accessGT (assert_smaller m n)
155 | [GT] WellFounded Int16 (>) where
156 | wellFounded = accessGT
164 | sdiv : (n,d : Int16) -> (0 prf : d /= 0) => Int16
165 | sdiv n d = n `div` d
169 | smod : (n,d : Int16) -> (0 prf : d /= 0) => Int16
170 | smod n d = n `mod` d