forked from jonsterling/agda-calf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sequential.agda
69 lines (46 loc) · 2.27 KB
/
Sequential.agda
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
{-# OPTIONS --prop --rewriting #-}
module Examples.Sorting.Sequential where
open import Examples.Sorting.Sequential.Comparable
open import Calf costMonoid
open import Calf.Types.Nat
open import Calf.Types.List
open import Relation.Binary.PropositionalEquality as Eq using (_≡_)
open import Data.Product using (_,_)
test/forward = 1 ∷ 2 ∷ 3 ∷ 4 ∷ 5 ∷ 6 ∷ 7 ∷ 8 ∷ 9 ∷ 10 ∷ 11 ∷ 12 ∷ 13 ∷ 14 ∷ 15 ∷ 16 ∷ []
test/backward = 16 ∷ 15 ∷ 14 ∷ 13 ∷ 12 ∷ 11 ∷ 10 ∷ 9 ∷ 8 ∷ 7 ∷ 6 ∷ 5 ∷ 4 ∷ 3 ∷ 2 ∷ 1 ∷ []
test/shuffled = 4 ∷ 8 ∷ 12 ∷ 16 ∷ 13 ∷ 3 ∷ 5 ∷ 14 ∷ 9 ∷ 6 ∷ 7 ∷ 10 ∷ 11 ∷ 1 ∷ 2 ∷ 15 ∷ []
module Ex/InsertionSort where
import Examples.Sorting.Sequential.InsertionSort NatComparable as Sort
list' = list nat
ex/insert : cmp (F list')
ex/insert = Sort.insert 3 (1 ∷ 2 ∷ 4 ∷ [])
ex/sort : cmp (F list')
ex/sort = Sort.sort (1 ∷ 5 ∷ 3 ∷ 1 ∷ 2 ∷ [])
ex/sort/forward : cmp (F list')
ex/sort/forward = Sort.sort test/forward -- cost: 15
ex/sort/backward : cmp (F list')
ex/sort/backward = Sort.sort test/backward -- cost: 120
ex/sort/shuffled : cmp (F list')
ex/sort/shuffled = Sort.sort test/shuffled -- cost: 76
module Ex/MergeSort where
import Examples.Sorting.Sequential.MergeSort NatComparable as Sort
list' = list nat
ex/split : cmp (F Sort.pair)
ex/split = Sort.split (6 ∷ 2 ∷ 8 ∷ 3 ∷ 1 ∷ 8 ∷ 5 ∷ [])
ex/merge : cmp (F list')
ex/merge = Sort.merge (2 ∷ 3 ∷ 6 ∷ 8 ∷ [] , 1 ∷ 5 ∷ 8 ∷ [])
ex/sort : cmp (F list')
ex/sort = Sort.sort (1 ∷ 5 ∷ 3 ∷ 1 ∷ 2 ∷ [])
ex/sort/forward : cmp (F list')
ex/sort/forward = Sort.sort test/forward -- cost: 32
ex/sort/backward : cmp (F list')
ex/sort/backward = Sort.sort test/backward -- cost: 32
ex/sort/shuffled : cmp (F list')
ex/sort/shuffled = Sort.sort test/shuffled -- cost: 47
module SortEquivalence (M : Comparable) where
open Comparable M
open import Examples.Sorting.Sequential.Core M
import Examples.Sorting.Sequential.InsertionSort M as ISort
import Examples.Sorting.Sequential.MergeSort M as MSort
isort≡msort : ◯ (ISort.sort ≡ MSort.sort)
isort≡msort = IsSort⇒≡ ISort.sort ISort.sort/correct MSort.sort MSort.sort/correct