Skip to content

Commit 0868a24

Browse files
Merge branch 'main' of github.com:IUDataStructuresCourse/course-web-page-spring-2025
2 parents 9e62729 + 42ddb7f commit 0868a24

14 files changed

+1074
-337
lines changed

ListSearch.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Lab: List Search
22

33
Prove the following theorem about the variant of linear `search` that
4-
you implemented in lab last week.
4+
you implemented in lab.
55

66
```
77
theorem search_correct: all y: Nat. all xs: List<Nat>.

QuickReverse.md

+5
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,8 @@ proof
1111
end
1212
```
1313

14+
The file you submit to the autograder must be named `QuickRevCorrect.pf`
15+
and it should include the above theorem and the definition of `quick_rev`
16+
and any helper functions that you created to use in `quick_rev`.
17+
Your `QuickRevCorrect.pf` should only import files from the Deduce
18+
`lib` directory.

index.md

+10-9
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,17 @@ Jan. 23 or 24 | |
9797
Jan. 28 | [Programming in Deduce with Linked Lists](./lectures/deduce-programming.md) | [Programming in Deduce](https://jsiek.github.io/deduce/pages/deduce-programming.html) | Project FloodIt! due | [code](https://autograder.luddy.indiana.edu/web/project/1509)
9898
Jan. 30 | [Writing Proofs in Deduce](./lectures/deduce-intro-proof.md) | [Proofs in Deduce](https://jsiek.github.io/deduce/pages/deduce-proofs.html)
9999
Jan. 30 or 31 | | | [Lab: Linked Lists in Deduce](./LabDeduceProg) | [code](https://autograder.luddy.indiana.edu/web/project/1614)
100-
Feb. 4 | [Proof by Induction](./lectures/InductionOnLists.md) | | Lab Linked Lists in Deduce due
101-
Feb. 6 | [Discovering and Generalizing Lemmas](./lectures/RevRev.md) | | [Proof Exercises](./ProofExercises.md) | [submit](https://autograder.luddy.indiana.edu/web/project/1623)
102-
Feb. 6 or 7 | | | [Lab: List Search](./ListSearch.md)
103-
Feb. 11 | Insertion Sort | Ch.7 Sec. 2 | | Lab List Search due
104-
Feb. 13 | Merge Sort, Quick Sort | Ch.7 Sec. 6,7 | [Proof: Quick Reverse Correct](./QuickReverse.md)
105-
Feb. 13 or 14 | | | [Lab: Insertion Sort](./LabInsertionSort.md)
106-
Feb. 18 | [Binary Trees](./lectures/binary-trees.md) | Ch. 4 Sec. 1-2 | Lab Insertion Sort due
100+
Feb. 4 | [Writing Proofs and Induction](./lectures/deduce-more-proof.md) | | Lab Linked Lists in Deduce due
101+
Feb. 6 | [Logical And, Or, Not, and Sets](./lectures/LogicAndSets.md) | | |
102+
Feb. 6 or 7 | | | [Lab: Proof Exercises](./ProofExercises.md)
103+
Feb. 11 | [Discovering and Generalizing Lemmas](./lectures/RevRev.md) | | Lab Proof Exercises due | [submit](https://autograder.luddy.indiana.edu/web/project/1623)
104+
Feb. 13 | [Insertion Sort, Merge Sort, Quick Sort](./lectures/sorting.md) | Ch.7 Sec. 2,6,7 |
105+
Feb. 13 or 14 | | | [Lab: Quick Reverse Correct](./QuickReverse.md)
106+
Feb. 14 | | |
107+
Feb. 18 | [Binary Trees](./lectures/binary-trees.md) | Ch. 4 Sec. 1-2 | [Lab: Quick Reverse Correct](./QuickReverse.md) due | [submit](https://autograder.luddy.indiana.edu/web/project/1632)
107108
Feb. 20 | [Binary Search Trees](./lectures/binary-search-trees.md) | Ch. 4 Sec. 3
108-
Feb. 20 or 21 | | | [Lab: Binary Tree Search](./LabBinarySearchTree.md)
109-
Feb. 25 | [Balanced Search Trees (AVL)](./lectures/balanced-search-trees.md) | Ch. 4 Sec. 4 | Lab Binary Tree Search due
109+
Feb. 20 or 21 | | | [Lab: List Search](./ListSearch.md)
110+
Feb. 25 | [Balanced Search Trees (AVL)](./lectures/balanced-search-trees.md) | Ch. 4 Sec. 4 | Lab List Search due
110111
Feb. 27 | [More AVL](./lectures/more-avl-trees.md)
111112
Feb. 27 or 28 | | | Lab: work on [Project 2: Segment Intersection](./SegmentIntersection.md) | [code](https://autograder.luddy.indiana.edu/web/project/1530), [test](https://autograder.luddy.indiana.edu/web/project/1529)
112113
March 4 | [Recipes for Time Analysis and Testing](./lectures/analysis-and-testing-recipes.md)

lectures/Feb11.pf

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import Nat
2+
import List
3+
4+
5+
lemma reverse_helper: <U> all x:U, ls:List<U>, xs:List<U>.
6+
reverse(ls ++ xs) = reverse(xs) ++ reverse(ls)
7+
proof
8+
arbitrary U:type
9+
arbitrary x:U
10+
induction List<U>
11+
case [] {
12+
arbitrary xs:List<U>
13+
suffices reverse(xs) = reverse(xs) ++ [] by evaluate
14+
rewrite append_empty<U>
15+
}
16+
case node(y, ls') assume IH {
17+
arbitrary xs:List<U>
18+
equations
19+
reverse(node(y, ls') ++ xs)
20+
= reverse(node(y, ls' ++ xs)) by definition operator++
21+
... = reverse(ls' ++ xs) ++ [y] by definition reverse
22+
... = (reverse(xs) ++ reverse(ls')) ++ [y] by rewrite IH
23+
... = reverse(xs) ++ (reverse(ls') ++ [y]) by rewrite append_assoc<U>
24+
... = reverse(xs) ++ #reverse(node(y, ls'))# by definition reverse
25+
}
26+
end
27+
28+
theorem reverse_reverse: all U :type. all ls :List<U>.
29+
reverse(reverse(ls)) = ls
30+
proof
31+
arbitrary U:type
32+
induction List<U>
33+
case [] {
34+
definition reverse
35+
}
36+
case node(x, ls') assume IH: reverse(reverse(ls')) = ls' {
37+
suffices reverse(reverse(ls') ++ [x]) = node(x, ls') by evaluate
38+
equations
39+
reverse(reverse(ls') ++ [x])
40+
= reverse([x]) ++ reverse(reverse(ls')) by reverse_helper<U>
41+
... = reverse([x]) ++ ls' by rewrite IH
42+
... = node(x, ls') by evaluate
43+
}
44+
end

lectures/Feb4.pf

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import Nat
2+
import List
3+
import Pair
4+
import Jan28
5+
import Jan30
6+
7+
theorem len_42: 1 = len(Node(42, Empty)) and len(Node(25, Empty)) = 1
8+
proof
9+
rewrite len_one
10+
/*have eq1: len(Node(42, Empty)) = 1 by len_one[42]
11+
have eq3: len(Node(25, Empty)) = 1 by len_one[25]
12+
rewrite eq1 | eq3 //suffices len(Node(25, Empty)) = 1 by rewrite eq1
13+
*/
14+
//symmetric len_one[42]
15+
//have eq: len(Node(42, Empty)) = 1 by len_one[42]
16+
//rewrite eq
17+
// goal: 1 = len(Node(42, Empty))
18+
// rewrite: 1 = 1
19+
// true
20+
end
21+
22+
theorem algebra_example: all x:Nat. (1 + x) * x = x * x + x
23+
proof
24+
arbitrary x:Nat
25+
equations
26+
(1 + x) * x
27+
= 1 * x + x * x by dist_mult_add_right[1,x,x]
28+
... = x + x * x by rewrite one_mult[x]
29+
... = x * x + x by add_commute[x,x*x]
30+
end
31+
32+
theorem modus_ponens_example: all x:Nat. max(x, 1 + x) = 1 + x
33+
proof
34+
arbitrary x:Nat
35+
have lt: x ≤ 1 + x by less_equal_add_left
36+
apply max_equal_greater_right[x, 1+x] to lt
37+
end
38+
39+
theorem assume_example: all xs:NatList. if len(xs) = 0 then xs = Empty
40+
proof
41+
arbitrary xs:NatList
42+
assume lenz: len(xs) = 0
43+
// Goal: xs = Empty
44+
switch xs {
45+
case Empty {
46+
. // Goal: Empty = Empty
47+
}
48+
case Node(x, xs2) assume eq {
49+
have eq2: len(Node(x,xs2)) = 0 by rewrite eq in lenz
50+
have eq3: 1 + len(xs2) = 0 by definition len in eq2
51+
have eq4: suc(0 + len(xs2)) = 0 by definition operator+ in eq3
52+
conclude false by eq4
53+
}
54+
}
55+
end
56+
57+
theorem list_append_empty: <U> all xs :List<U>.
58+
xs ++ [] = xs
59+
proof
60+
arbitrary U:type
61+
induction List<U>
62+
case empty {
63+
definition operator++
64+
}
65+
case node(T1, L2) assume IH: L2 ++ [] = L2 {
66+
suffices node(T1, L2 ++ @[]<U>) = node(T1, L2)
67+
by definition operator++
68+
rewrite IH
69+
}
70+
end

lectures/Feb6.pf

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
import Nat
2+
import List
3+
import Base
4+
5+
define isEven : fn Nat -> bool = fun n { some m:Nat. n = 2 * m }
6+
define isOdd : fn Nat -> bool = fun n { some m:Nat. n = suc (2 * m) }
7+
8+
theorem addition_of_evens_example:
9+
all x:Nat, y:Nat.
10+
if isEven(x) and isEven(y) then isEven(x + y)
11+
proof
12+
arbitrary x:Nat, y:Nat
13+
assume even_xy: isEven(x) and isEven(y)
14+
suffices some m:Nat. x + y = 2 * m
15+
by definition {isEven}
16+
have ex: some m:Nat. x = 2 * m by definition isEven in even_xy
17+
have ey: some m:Nat. y = 2 * m by definition isEven in even_xy
18+
obtain a where x_2a: x = 2*a from ex
19+
obtain b where y_2b: y = 2*b from ey
20+
choose (a + b)
21+
suffices 2 * a + 2 * b = 2 * (a + b) by rewrite x_2a | y_2b
22+
rewrite dist_mult_add
23+
end
24+
25+
26+
27+
theorem exercise_demorgan: all A:bool, B:bool.
28+
if (not A) or (not B) then not (A and B)
29+
proof
30+
arbitrary A:bool, B:bool
31+
assume premise: (not A) or (not B)
32+
cases premise
33+
case nA: not A {
34+
//rewrite (apply eq_false to nA)
35+
assume ab: A and B
36+
have: A by ab
37+
conclude false by apply nA to recall A
38+
}
39+
case nB: not B {
40+
assume ab: A and B
41+
conclude false by apply nB to ab
42+
}
43+
end
44+
45+
46+
47+
/*
48+
theorem add_to_zero_is_zero: all n:Nat, m:Nat.
49+
if n + m = 0
50+
then n = 0 and m = 0
51+
proof
52+
arbitrary n:Nat, m:Nat
53+
switch n {
54+
case 0 {
55+
assume premise: 0 + m = 0
56+
have f1: 0 + 0 = 0 by definition operator+
57+
have f2: m = 0 by definition operator+ in premise
58+
f1, f2
59+
}
60+
case suc(n') {
61+
assume premise: suc(n') + m = 0
62+
sorry
63+
}
64+
}
65+
66+
end
67+
68+
theorem example: all T:type, xs:List<T>, ys:List<T>.
69+
if length(xs ++ ys) = 0
70+
then length(xs) = 0
71+
proof
72+
arbitrary T:type, xs:List<T>, ys:List<T>
73+
assume premise: length(xs ++ ys) = 0
74+
have f1: length(xs) + length(ys) = 0
75+
by rewrite length_append<T>[xs,ys] in premise
76+
apply add_to_zero_is_zero[length(xs), length(ys)] to f1
77+
end
78+
*/
79+
80+
theorem intro_dichotomy: all x:Nat, y:Nat. x ≤ y or y < x
81+
proof
82+
arbitrary x:Nat, y:Nat
83+
have tri: x < y or x = y or y < x by trichotomy[x][y]
84+
cases tri
85+
case: x < y {
86+
have: x ≤ y by apply less_implies_less_equal[x][y] to recall x < y
87+
conclude x ≤ y or y < x by recall x ≤ y
88+
}
89+
case: x = y {
90+
have: x ≤ y by
91+
suffices y ≤ y by rewrite (recall x = y)
92+
less_equal_refl[y]
93+
conclude x ≤ y or y < x by recall x ≤ y
94+
}
95+
case: y < x {
96+
conclude x ≤ y or y < x by recall y < x
97+
}
98+
end
99+
100+
theorem prove_not_example: not (0 = 1)
101+
proof
102+
assume z1: 0 = 1
103+
conclude false by recall 0 = 1
104+
end
105+
106+
theorem use_not_example: all P:bool. if P and not P then false
107+
proof
108+
arbitrary P:bool
109+
assume premise: P and not P
110+
have np: not P by premise
111+
have p: P by premise
112+
conclude false by apply np to p
113+
end
114+
115+

0 commit comments

Comments
 (0)