Skip to content

Commit 3060109

Browse files
committed
polish
1 parent b49e548 commit 3060109

File tree

2 files changed

+16
-231
lines changed

2 files changed

+16
-231
lines changed

CaseStudies/Velvet/VelvetExamples/Demo/InsertionSort.lean

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
-- Example 1: Velvet basics
33
----------------------------------------------------
44

5-
import Mathlib.Algebra.BigOperators.Intervals
6-
import Mathlib.Algebra.Ring.Int.Defs
7-
85
import CaseStudies.Velvet.Std
96
import CaseStudies.TestingUtil
107

@@ -34,6 +31,8 @@ prove_correct sqrt by
3431
loom_solve
3532
-- all_goals loom_smt [*]
3633

34+
-- #eval sqrt 10 |>.extract
35+
3736
end squareRoot
3837

3938
-- (2) Insertion sort
@@ -85,7 +84,7 @@ set_option loom.semantics.choice "demonic"
8584
method insertionSort
8685
(mut arr: Array Int) return (u: Unit)
8786
require 1 ≤ arr.size
88-
ensures forall i j, 0 ≤ i ∧ i j ∧ j < arr.size → arr[i]! arr[j]!
87+
ensures forall i j, 0 ≤ i ∧ i <= j ∧ j < arr.size → arr[i]! <= arr[j]!
8988
ensures arr.toMultiset = arr.toMultiset
9089
do
9190
let arr₀ := arr
@@ -96,7 +95,7 @@ method insertionSort
9695
invariant 1 ≤ n ∧ n ≤ arr.size
9796
invariant forall i j, 0 ≤ i ∧ i < j ∧ j <= n - 1 → arr[i]! ≤ arr[j]!
9897
invariant arr.toMultiset = arr₀.toMultiset
99-
-- decreasing size arr - n
98+
-- decreasing arr.size - n
10099
do
101100
let mut mind := n
102101
while mind ≠ 0
@@ -109,7 +108,7 @@ method insertionSort
109108
if arr[mind]! < arr[mind - 1]! then
110109
swap! arr[mind - 1]! arr[mind]!
111110
mind := mind - 1
112-
-- n := n + 1 -- try commenting this out for termination
111+
n := n + 1 -- try commenting this out for termination
113112
return
114113

115114
-- Let's test this stuff
@@ -127,17 +126,17 @@ derive_tester_for insertionSort
127126
-- (2.1) Doing simple testing
128127
-- See here where the postcondition is violated
129128

130-
-- run_elab do
131-
-- -- Generate random arrays
132-
-- let g : Plausible.Gen (_ × Bool) := do
133-
-- let arr ← Plausible.SampleableExt.interpSample (Array Int)
134-
-- let res := insertionSortTester arr
135-
-- pure (arr, res)
136-
-- for _ in [1: 500] do
137-
-- let res ← Plausible.Gen.run g 10
138-
-- unless res.2 do
139-
-- IO.println s!"postcondition violated for input {res.1}"
140-
-- break
129+
run_elab do
130+
-- Generate random arrays
131+
let g : Plausible.Gen (_ × Bool) := do
132+
let arr ← Plausible.SampleableExt.interpSample (Array Int)
133+
let res := insertionSortTester arr
134+
pure (arr, res)
135+
for _ in [1: 500] do
136+
let res ← Plausible.Gen.run g 10
137+
unless res.2 do
138+
IO.println s!"postcondition violated for input {res.1}"
139+
break
141140

142141
-- (2.2) This just works
143142

CaseStudies/Velvet/VelvetExamples/Demo/mbpp_33.lean

Lines changed: 0 additions & 214 deletions
This file was deleted.

0 commit comments

Comments
 (0)