on master help sign in
Tidy up accessibility proofs in views
commit34080981e284ee89c16fedf1d8f6c7c817fbb914 authorEdwin Brady <ecb10@st-andrews.ac.uk> dateSun 10 Apr 2016, 17:13 (11 years ago) parentd7b7e25
3 files changed+17−15
libs/base/Data/List/Views.idr+1−2 libs/base/Data/Nat/Views.idr+1−5 libs/prelude/Prelude/WellFounded.idr+15−8
libs/base/Data/List/Views.idr+1−2
@@ -70,8 +70,7 @@ splitRecFix xs srec with (split xs)
7070||| Covering function for the `SplitRec` view
7171export total
7272splitRec : (xs : List a) -> SplitRec xs
73−splitRec [] = SplitRecNil
74−splitRec (x :: xs) = accInd splitRecFix (x :: xs) (smallerAcc (x :: x :: xs) lteRefl)
73+splitRec xs = accInd splitRecFix xs (smallerAcc xs)
7574
7675||| View for traversing a list backwards
7776public export
libs/base/Data/Nat/Views.idr+1−5
@@ -1,9 +1,5 @@
11module Data.Nat.Views
22
3−ltAcc : (m : Nat) -> LT n m -> Accessible LT n
4−ltAcc Z x = absurd x
5−ltAcc (S k) (LTESucc x) = Access (\val, p => ltAcc k (lteTransitive p x))
6−
73public export
84data Half : Nat -> Type where
95 HalfOdd : Half (S (n + n))
@@ -34,5 +30,5 @@ halfRecFix (S k) hrec with (half k)
3430
3531export
3632halfRec : (n : Nat) -> HalfRec n
37−halfRec n = accInd halfRecFix n (ltAcc (S n) (LTESucc lteRefl))
33+halfRec n = accInd halfRecFix n (ltAccessible n)
3834
libs/prelude/Prelude/WellFounded.idr+15−8
@@ -88,18 +88,25 @@ wfInd {rel} step x = accInd step x (wellFounded {rel} x)
8888-- Some basic useful relations
8989
9090||| LT is a well-founded relation on numbers
91−ltAccessible : (m : Nat) -> LT n m -> Accessible LT n
92−ltAccessible Z x = absurd x
93−ltAccessible (S k) (LTESucc x)
94− = Access (\val, p => ltAccessible k (lteTransitive p x))
91+ltAccessible : (n : Nat) -> Accessible LT n
92+ltAccessible n = Access (\v, prf => ltAccessible' {n'=v} n prf)
93+ where
94+ ltAccessible' : (m : Nat) -> LT n' m -> Accessible LT n'
95+ ltAccessible' Z x = absurd x
96+ ltAccessible' (S k) (LTESucc x)
97+ = Access (\val, p => ltAccessible' k (lteTransitive p x))
9598
9699-- First list is smaller than the second
97100smaller : List a -> List a -> Type
98101smaller xs ys = LT (length xs) (length ys)
99102
100103||| `smaller` is a well-founded relation on lists
101−smallerAcc : (ys : List a) -> smaller xs ys -> Accessible smaller xs
102−smallerAcc [] x = absurd x
103−smallerAcc (y :: ys) (LTESucc x)
104− = Access (\val, p => smallerAcc ys (lteTransitive p x))
104+smallerAcc : (xs : List a) -> Accessible WellFounded.smaller xs
105+smallerAcc xs = Access (\v, prf => smallerAcc' {xs'=v} xs prf)
106+ where
107+ smallerAcc' : (ys : List a) -> smaller xs' ys -> Accessible smaller xs'
108+ smallerAcc' [] x = absurd x
109+ smallerAcc' (y :: ys) (LTESucc x)
110+ = Access (\val, p => smallerAcc' ys (lteTransitive p x))
111+
105112