text
stringlengths 0
89.3k
|
---|
induction ys with |
nil |
simp zip Listtake Listdrop |
cons y ys ih match xs with |
simp zip Listtake |
Listdrop Listlength |
cons x xs |
5unfold zip |
unfold Listtake at ih |
unfold Listdrop at ih |
simp Listlength |
rw ih |
The following is a correct proof of prop_84 generated by GPT4 There are several unnecessary |
definitions passed to the calls to the simplifier the simp tactic However in both the correct and |
incorrect proofs GPT4 demonstrates the main ideas of the proof induct on ys pair off the first |
elements of xsandys then apply the inductive hypothesis to what remains |
induction ys generalizing xs with |
nil simp zip Listtake Listdrop |
cons y ys ih |
cases xs with |
nil simp zip Listtake Listdrop |
cons x xs |
simp Listcons_append zip Listtake |
Listdrop Listlength |
rw ih |
342 Nonstandard Insertion Increments Length |
Although the zip concatenation property is not part of Mathlib one can argue that because the |
property involves a utility function defined in Mathlib with its own associated properties and proofs |
it is not altogether surprising that GPT4 was able to infer a proof of a novel property of a redefinition |
of the function We therefore present a property of a function ins not included in Mathlib that inserts |
an element into a list before the first element it is less than Proving this property requires the ability |
to reason about previously unseen code |
def ins Nat List Nat List Nat |
n n |
n xxs if n x then n x xs else x ins n xs |
The following is an incorrect proof of prop_15 by GPT4 Interestingly GPT4s main failing in this |
case is syntactic the proof can be manually corrected by using the correct by_cases tactic in place |
of byCases unrecognized by Lean 4 and manual removal of the following case matching the in |
statements at which point the proof is completed at the rw ih step |
induction xs with |
nil |
simp ins Listlength Natsucc |
cons y ys ih |
simp ins |
byCases h x y |
inl h_lt |
simp h_lt Listlength Natsucc |
inr h_geq |
simp h_geq |
rw ih |
simp Natsucc_assoc |
As one might expect from the nearly correct proof above GPT4 also produces a correct proof This |
proof is remarkable for its simplicity Unlike the previous correct proof there is little wasted space a |
feature often sought after by human proof experts GPT4 demonstrates understanding of how to work |
with the ins function via the split_ifs tactic and the usage of the inductive hypothesis only in the |
second branch where it is necessary |
induction xs with |
nil simp ins |
cons y ys ih |
simp ins |
split_ifs with h |
simp |
simp ih |
6343 Sorting Properties |
The Lean source code of miniCodeProps contains implementations of 9 sorting algorithms with |
associated properties to prove for each algorithm We display several of the functions and lemmas |
associated with one of our two heapsort implementations each uses a different strategy for merging |
heaps The toList function contains an example of a termination lemma the line beginning with |
have _h references a lemma that is used by Lean to prove that the recursion in toList terminates a |
property required by default for recursive functions in Lean Several of the functions and lemmas |
referenced are omitted from the code for brevity |
def toHeap List Nat MyHeap |
xs hmerging xsmap fun x MyHeapnode MyHeapnil x MyHeapnil |
lemma numElem_merge_branches_lt p q MyHeap x Nat numElem hmerge p q |
numElem MyHeapnode p x q by |
rw merge_elems _ _ |
have h numElem MyHeapnode p x q 1 numElem p numElem q rfl |
rw h |
linarith |
def toList MyHeap List Nat |
MyHeapnil |
MyHeapnode p x q |
have _h numElem_merge_branches_lt p q x |
x toList hmerge p q |
termination_by hp numElem hp |
def hsort List Nat List Nat |
xs toList toHeap xs |
theorem prop_HSortSorts xs List Nat ordered hsort xs True by sorry |
theorem prop_HSortCount x Nat xs List Nat count x hsort xs count x xs |
by sorry |
theorem prop_HSortPermutes xs List Nat isPermutation hsort xs xs True |
by sorry |
theorem prop_HSortIsSort xs List Nat hsort xs isort xs by sorry |
The properties above express the following intuitive properties heapsort orders list elements pre |
serves the list size returns a permutation of the original list and returns the same result as insertion |
sort These properties are repeated for each sorting algorithm However given the complexity |
of the sorting functions involved we expect that proving such properties will be very difficult |
miniCodeProps also includes termination lemmas such as numElem_merge_branches_lt with the |
humanproduced proof removed An example of an incorrect proof of one of the sorting properties |
produced by GPT4 can be found in Appendix A |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.