-
Notifications
You must be signed in to change notification settings - Fork 9
HumanEval8 #206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
shaazib-tanvir
wants to merge
1
commit into
leanprover:master
Choose a base branch
from
shaazib-tanvir:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
HumanEval8 #206
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,71 @@ | ||||||||||||||||||||||||||||||||||||||
| def sum_product : Unit := | ||||||||||||||||||||||||||||||||||||||
| () | ||||||||||||||||||||||||||||||||||||||
| import Std.Tactic.Do | ||||||||||||||||||||||||||||||||||||||
| open Std.Do | ||||||||||||||||||||||||||||||||||||||
| set_option mvcgen.warning false | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| def List.product (xs : List Int) : Int := | ||||||||||||||||||||||||||||||||||||||
| match xs with | ||||||||||||||||||||||||||||||||||||||
| | [] => 1 | ||||||||||||||||||||||||||||||||||||||
| | x :: xs' => x * (product xs') | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| def sumProduct (xs : List Int) : Int × Int := (List.sum xs, List.product xs) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| def sumProductDo (xs : List Int) : Int × Int := Id.run do | ||||||||||||||||||||||||||||||||||||||
| let mut sum := 0 | ||||||||||||||||||||||||||||||||||||||
| let mut product := 1 | ||||||||||||||||||||||||||||||||||||||
| for x in xs do | ||||||||||||||||||||||||||||||||||||||
| sum := sum + x | ||||||||||||||||||||||||||||||||||||||
| product := product * x | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| return (sum, product) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| theorem List.sum_append (xs : List Int) (ys : List Int) | ||||||||||||||||||||||||||||||||||||||
| : sum (xs ++ ys) = sum xs + sum ys := by | ||||||||||||||||||||||||||||||||||||||
| induction xs with | ||||||||||||||||||||||||||||||||||||||
| | nil => | ||||||||||||||||||||||||||||||||||||||
| change sum ys = 0 + sum ys | ||||||||||||||||||||||||||||||||||||||
| omega | ||||||||||||||||||||||||||||||||||||||
| | cons x xs hi => | ||||||||||||||||||||||||||||||||||||||
| change x + sum (xs ++ ys) = x + sum xs + sum ys | ||||||||||||||||||||||||||||||||||||||
| rw [hi] | ||||||||||||||||||||||||||||||||||||||
| omega | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| theorem List.product_append (xs : List Int) (ys : List Int) | ||||||||||||||||||||||||||||||||||||||
| : product (xs ++ ys) = product xs * product ys := by | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+32
to
+33
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly:
Suggested change
|
||||||||||||||||||||||||||||||||||||||
| induction xs with | ||||||||||||||||||||||||||||||||||||||
| | nil => | ||||||||||||||||||||||||||||||||||||||
| change product ys = 1 * product ys | ||||||||||||||||||||||||||||||||||||||
| omega | ||||||||||||||||||||||||||||||||||||||
| | cons x xs hi => | ||||||||||||||||||||||||||||||||||||||
| change x * product (xs ++ ys) = x * product xs * product ys | ||||||||||||||||||||||||||||||||||||||
| rw [hi] | ||||||||||||||||||||||||||||||||||||||
| simp only [Int.mul_assoc] | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| theorem sumProductDo_correct (xs : List Int) : sumProductDo xs = sumProduct xs := by | ||||||||||||||||||||||||||||||||||||||
| generalize h : sumProductDo xs = ys | ||||||||||||||||||||||||||||||||||||||
| apply Id.of_wp_run_eq h | ||||||||||||||||||||||||||||||||||||||
| mvcgen | ||||||||||||||||||||||||||||||||||||||
| invariants | ||||||||||||||||||||||||||||||||||||||
| · ⇓ ⟨ cur, result ⟩ => | ||||||||||||||||||||||||||||||||||||||
| ⌜ result.snd = List.sum cur.prefix ∧ result.fst = List.product cur.prefix ⌝ | ||||||||||||||||||||||||||||||||||||||
| case vc1.step pref x suff h' result hi => | ||||||||||||||||||||||||||||||||||||||
| obtain ⟨ hi₀, hi₁⟩ := hi | ||||||||||||||||||||||||||||||||||||||
| constructor | ||||||||||||||||||||||||||||||||||||||
| rw [hi₀, List.sum_append] | ||||||||||||||||||||||||||||||||||||||
| change List.sum pref + x = List.sum pref + (x + 0) | ||||||||||||||||||||||||||||||||||||||
| omega | ||||||||||||||||||||||||||||||||||||||
| rw [hi₁, List.product_append] | ||||||||||||||||||||||||||||||||||||||
| change List.product pref * x = List.product pref * (x * 1) | ||||||||||||||||||||||||||||||||||||||
| rw [Int.mul_one] | ||||||||||||||||||||||||||||||||||||||
| case vc3.a.post.success result h' => | ||||||||||||||||||||||||||||||||||||||
| obtain ⟨ left, right ⟩ := h' | ||||||||||||||||||||||||||||||||||||||
| rw [left, right] | ||||||||||||||||||||||||||||||||||||||
| rfl | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+50
to
+62
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you want, you could also use grind, which saves you some of the annoying manual
Suggested change
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| example : sumProductDo [] = (0, 1) := by rfl | ||||||||||||||||||||||||||||||||||||||
| example : sumProductDo [1, 1, 1] = (3, 1) := by rfl | ||||||||||||||||||||||||||||||||||||||
| example : sumProductDo [100, 0] = (100, 0) := by rfl | ||||||||||||||||||||||||||||||||||||||
| example : sumProductDo [3, 5, 7] = (3 + 5 + 7, 3 * 5 * 7) := by rfl | ||||||||||||||||||||||||||||||||||||||
| example : sumProductDo [10] = (10, 10) := by rfl | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| /-! | ||||||||||||||||||||||||||||||||||||||
| ## Prompt | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -48,4 +114,4 @@ def check(candidate): | |||||||||||||||||||||||||||||||||||||
| assert candidate([3, 5, 7]) == (3 + 5 + 7, 3 * 5 * 7) | ||||||||||||||||||||||||||||||||||||||
| assert candidate([10]) == (10, 10) | ||||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||||
| -/ | ||||||||||||||||||||||||||||||||||||||
| -/ | ||||||||||||||||||||||||||||||||||||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just a very minor remark, but in this repository we usually put the colon at the end of the line: