Datasets:

Languages:
English
Size:
n<1K
DOI:
Libraries:
License:
elohn commited on
Commit
8d5ba38
1 Parent(s): 8c67493

baselines working on Linux

Browse files
Files changed (3) hide show
  1. baseline.py +9 -8
  2. codeprops_bench_ps.jsonl +10 -10
  3. utils.py +28 -18
baseline.py CHANGED
@@ -29,11 +29,11 @@ def get_tactics_llmstep(goal, prev_file):
29
 
30
  # for benchmarking 'get_tactics' functions that suggest several next possible steps for a given
31
  # proofstate + optionally file context.
32
- def benchmark_nextstep(pwd, get_tactics, send_command, search_depth=3, repl_type='zsh'):
33
  lean_repl = make_lean_repl(repl_type=repl_type)
34
 
35
  # get the first command out of the way which has a weird "expect" behavior using icanon mode
36
- mathlib_out, mathlib_env = send_command(lean_repl, 'import Mathlib', env=None, first=True)
37
 
38
  num_proved = 0
39
  num_attempted = 0
@@ -41,7 +41,7 @@ def benchmark_nextstep(pwd, get_tactics, send_command, search_depth=3, repl_type
41
  print(prop_name)
42
  #time.sleep(5)
43
  num_attempted += 1
44
- #if num_attempted < 30:
45
  # continue
46
  successful_def = False
47
  while not successful_def:
@@ -58,7 +58,7 @@ def benchmark_nextstep(pwd, get_tactics, send_command, search_depth=3, repl_type
58
  successful_def = False
59
  lean_repl.close()
60
  lean_repl = make_lean_repl(repl_type=repl_type)
61
- mathlib_out, mathlib_env = send_command(lean_repl, 'import Mathlib', env=None, first=True)
62
  break
63
  all_lines.append(line)
64
 
@@ -77,8 +77,8 @@ def benchmark_nextstep(pwd, get_tactics, send_command, search_depth=3, repl_type
77
  print(f'search at level {search_lvl}')
78
  for (curr_goal, ps, tac_seq) in old_ps:
79
  next_tactics = get_tactics(curr_goal, prev_lines)
80
- for next_tactic, _scr in sorted(next_tactics, key=lambda p: -p[1])[:3]:
81
- print('\n'.join(tac_seq + [next_tactic]))
82
  outp, new_proofState = send_tactic(lean_repl, next_tactic, ps)
83
  if outp is None:
84
  continue # i.e. timeout/error on tactic sending
@@ -340,9 +340,10 @@ if __name__ == '__main__':
340
 
341
  #benchmark_nextstep(pwd, get_tactics_interactive, send_command, repl_type=repl_type) # get_tactics_interactive for testing
342
 
343
- pwd = parse_benchmark_input('codeprops_bench_lemmas.jsonl')
344
 
345
  if bench_type == 'nextstep':
346
  benchmark_nextstep(pwd, get_tactics_llmstep, send_command, repl_type=repl_type) # get_tactics_llmstep for benchmarking
347
  elif bench_type == 'fullproof':
348
- benchmark_full_proofgen(pwd, get_proof_gpt, send_command, repl_type=repl_type)
 
 
29
 
30
  # for benchmarking 'get_tactics' functions that suggest several next possible steps for a given
31
  # proofstate + optionally file context.
32
+ def benchmark_nextstep(pwd, get_tactics, send_command, search_depth=3, search_width=10, repl_type='zsh'):
33
  lean_repl = make_lean_repl(repl_type=repl_type)
34
 
35
  # get the first command out of the way which has a weird "expect" behavior using icanon mode
36
+ mathlib_out, mathlib_env = send_command(lean_repl, 'import Mathlib', env=None, first=True, timeout=30)
37
 
38
  num_proved = 0
39
  num_attempted = 0
 
41
  print(prop_name)
42
  #time.sleep(5)
43
  num_attempted += 1
44
+ #if num_attempted < 115:
45
  # continue
46
  successful_def = False
47
  while not successful_def:
 
58
  successful_def = False
59
  lean_repl.close()
60
  lean_repl = make_lean_repl(repl_type=repl_type)
61
+ mathlib_out, mathlib_env = send_command(lean_repl, 'import Mathlib', env=None, first=True, timeout=30)
62
  break
63
  all_lines.append(line)
64
 
 
77
  print(f'search at level {search_lvl}')
78
  for (curr_goal, ps, tac_seq) in old_ps:
79
  next_tactics = get_tactics(curr_goal, prev_lines)
80
+ for next_tactic, _scr in sorted(next_tactics, key=lambda p: -p[1])[:search_width]:
81
+ #print('\n'.join(tac_seq + [next_tactic]))
82
  outp, new_proofState = send_tactic(lean_repl, next_tactic, ps)
83
  if outp is None:
84
  continue # i.e. timeout/error on tactic sending
 
340
 
341
  #benchmark_nextstep(pwd, get_tactics_interactive, send_command, repl_type=repl_type) # get_tactics_interactive for testing
342
 
343
+ pwd = parse_benchmark_input('codeprops_bench_ps.jsonl')
344
 
345
  if bench_type == 'nextstep':
346
  benchmark_nextstep(pwd, get_tactics_llmstep, send_command, repl_type=repl_type) # get_tactics_llmstep for benchmarking
347
  elif bench_type == 'fullproof':
348
+ benchmark_full_proofgen(pwd, get_proof_gpt, send_command, repl_type=repl_type)
349
+
codeprops_bench_ps.jsonl CHANGED
@@ -115,10 +115,10 @@
115
  {"full_name": "prop_NMSortTDCount", "prop_defn": "theorem prop_NMSortTDCount (x: Nat) (xs: List Nat) : count x (nmsorttd xs) == count x xs:= by sorry", "prop_loc": "LeanSrc/LeanSrc/Sorts.lean:421", "score": 5, "deps": "import Mathlib\n\ndef count [DecidableEq \u03b1] : \u03b1 \u2192 List \u03b1 \u2192 Nat\n| _x, [] => 0\n| x, y::ys => if x == y then 1 + (count x ys) else count x ys\n\n\ndef lmerge : List Nat \u2192 List Nat \u2192 List Nat\n| [], ys => ys\n| xs, [] => xs\n| x::xs, y::ys => if x <= y then\n x::(lmerge xs (y::ys))\n else\n y::(lmerge (x::xs) ys)\n\n\ndef half : Nat \u2192 Nat\n| 0 => 0\n| 1 => 0\n| x + 2 => 1 + (half x)\n\n\nlemma half_lt: half x \u2264 x := by\n induction x using Nat.strong_induction_on with\n | h n ih =>\n cases n with\n | zero => unfold half; simp;\n | succ nm1 =>\n cases nm1 with\n | zero => unfold half; simp;\n | succ nm2 =>\n unfold half;\n have tmp := ih nm2 (by exact Nat.le.step Nat.le.refl);\n ring_nf;\n calc 1 + half nm2 \u2264 1 + nm2 := Nat.add_le_add (@Nat.le.refl 1) tmp\n _ \u2264 2 + nm2 := by simp\n\n\ndef nmsorttd : List Nat \u2192 List Nat\n| [] => []\n| [x] => [x]\n| x::y::xs =>\n let k:= half ((x::y::xs).length)\n have _h: half (Nat.succ (Nat.succ (List.length xs))) < Nat.succ (Nat.succ (List.length xs)) := by\n rw [Nat.succ_eq_add_one _];\n ring_nf;\n rw [Nat.add_comm];\n unfold half;\n ring_nf;\n calc 1 + half (xs.length) \u2264 1 + xs.length := by simp; exact half_lt;\n _ < 2 + xs.length := by simp;\n have _h': Nat.succ (Nat.succ (List.length xs)) - half (Nat.succ (Nat.succ (List.length xs))) <\n Nat.succ (Nat.succ (List.length xs)) := by\n suffices h': 0 < half (Nat.succ (Nat.succ (List.length xs)))\n case h';\n unfold half;simp;\n refine Nat.sub_lt ?h h'\n simp;\n lmerge (nmsorttd ((x::y::xs).take k)) (nmsorttd ((x::y::xs).drop k))\ntermination_by xs => xs.length\n", "proof_state": "x : \u2115\nxs : List \u2115\n\u22a2 (count x (nmsorttd xs) == count x xs) = true", "file_locs": [["LeanSrc/LeanSrc/Sorts.lean", 421]]}
116
  {"full_name": "prop_NMSortTDPermutes", "prop_defn": "theorem prop_NMSortTDPermutes (xs: List Nat) : isPermutation (nmsorttd xs) xs == true:= by sorry", "prop_loc": "LeanSrc/LeanSrc/Sorts.lean:422", "score": 5, "deps": "import Mathlib\n\ndef deleteFirst [DecidableEq \u03b1]: \u03b1 \u2192 List \u03b1 \u2192 List \u03b1\n | _, [] => []\n | n, x::xs => if n == x then xs else x::(deleteFirst n xs)\n\n\ndef isPermutation [DecidableEq \u03b1] : List \u03b1 \u2192 List \u03b1 \u2192 Bool\n| [], ys => (ys == [])\n| x::xs, ys => x \u2208 ys && (isPermutation xs (deleteFirst x ys))\n\n\ndef lmerge : List Nat \u2192 List Nat \u2192 List Nat\n| [], ys => ys\n| xs, [] => xs\n| x::xs, y::ys => if x <= y then\n x::(lmerge xs (y::ys))\n else\n y::(lmerge (x::xs) ys)\n\n\ndef half : Nat \u2192 Nat\n| 0 => 0\n| 1 => 0\n| x + 2 => 1 + (half x)\n\n\nlemma half_lt: half x \u2264 x := by\n induction x using Nat.strong_induction_on with\n | h n ih =>\n cases n with\n | zero => unfold half; simp;\n | succ nm1 =>\n cases nm1 with\n | zero => unfold half; simp;\n | succ nm2 =>\n unfold half;\n have tmp := ih nm2 (by exact Nat.le.step Nat.le.refl);\n ring_nf;\n calc 1 + half nm2 \u2264 1 + nm2 := Nat.add_le_add (@Nat.le.refl 1) tmp\n _ \u2264 2 + nm2 := by simp\n\n\ndef nmsorttd : List Nat \u2192 List Nat\n| [] => []\n| [x] => [x]\n| x::y::xs =>\n let k:= half ((x::y::xs).length)\n have _h: half (Nat.succ (Nat.succ (List.length xs))) < Nat.succ (Nat.succ (List.length xs)) := by\n rw [Nat.succ_eq_add_one _];\n ring_nf;\n rw [Nat.add_comm];\n unfold half;\n ring_nf;\n calc 1 + half (xs.length) \u2264 1 + xs.length := by simp; exact half_lt;\n _ < 2 + xs.length := by simp;\n have _h': Nat.succ (Nat.succ (List.length xs)) - half (Nat.succ (Nat.succ (List.length xs))) <\n Nat.succ (Nat.succ (List.length xs)) := by\n suffices h': 0 < half (Nat.succ (Nat.succ (List.length xs)))\n case h';\n unfold half;simp;\n refine Nat.sub_lt ?h h'\n simp;\n lmerge (nmsorttd ((x::y::xs).take k)) (nmsorttd ((x::y::xs).drop k))\ntermination_by xs => xs.length\n", "proof_state": "xs : List \u2115\n\u22a2 (isPermutation (nmsorttd xs) xs == true) = true", "file_locs": [["LeanSrc/LeanSrc/Sorts.lean", 422]]}
117
  {"full_name": "prop_NMSortTDIsSort", "prop_defn": "theorem prop_NMSortTDIsSort (xs: List Nat) : nmsorttd xs == isort xs:= by sorry", "prop_loc": "LeanSrc/LeanSrc/Sorts.lean:423", "score": 5, "deps": "import Mathlib\n\ndef insert' : Nat \u2192 List Nat \u2192 List Nat\n| x, [] => [x]\n| x, y::xs => if x <= y then x::y::xs else y::(insert x xs)\n\n\ndef isort: List Nat \u2192 List Nat\n| [] => []\n| x::xs => insert' x (isort xs)\n\n\ndef lmerge : List Nat \u2192 List Nat \u2192 List Nat\n| [], ys => ys\n| xs, [] => xs\n| x::xs, y::ys => if x <= y then\n x::(lmerge xs (y::ys))\n else\n y::(lmerge (x::xs) ys)\n\n\ndef half : Nat \u2192 Nat\n| 0 => 0\n| 1 => 0\n| x + 2 => 1 + (half x)\n\n\nlemma half_lt: half x \u2264 x := by\n induction x using Nat.strong_induction_on with\n | h n ih =>\n cases n with\n | zero => unfold half; simp;\n | succ nm1 =>\n cases nm1 with\n | zero => unfold half; simp;\n | succ nm2 =>\n unfold half;\n have tmp := ih nm2 (by exact Nat.le.step Nat.le.refl);\n ring_nf;\n calc 1 + half nm2 \u2264 1 + nm2 := Nat.add_le_add (@Nat.le.refl 1) tmp\n _ \u2264 2 + nm2 := by simp\n\n\ndef nmsorttd : List Nat \u2192 List Nat\n| [] => []\n| [x] => [x]\n| x::y::xs =>\n let k:= half ((x::y::xs).length)\n have _h: half (Nat.succ (Nat.succ (List.length xs))) < Nat.succ (Nat.succ (List.length xs)) := by\n rw [Nat.succ_eq_add_one _];\n ring_nf;\n rw [Nat.add_comm];\n unfold half;\n ring_nf;\n calc 1 + half (xs.length) \u2264 1 + xs.length := by simp; exact half_lt;\n _ < 2 + xs.length := by simp;\n have _h': Nat.succ (Nat.succ (List.length xs)) - half (Nat.succ (Nat.succ (List.length xs))) <\n Nat.succ (Nat.succ (List.length xs)) := by\n suffices h': 0 < half (Nat.succ (Nat.succ (List.length xs)))\n case h';\n unfold half;simp;\n refine Nat.sub_lt ?h h'\n simp;\n lmerge (nmsorttd ((x::y::xs).take k)) (nmsorttd ((x::y::xs).drop k))\ntermination_by xs => xs.length\n", "proof_state": "xs : List \u2115\n\u22a2 (nmsorttd xs == isort xs) = true", "file_locs": [["LeanSrc/LeanSrc/Sorts.lean", 423]]}
118
- {"full_name": "prop_BSortSorts", "prop_defn": "theorem prop_BSortSorts (xs: List Nat) : ordered (bsort xs) == true:= by sorry", "prop_loc": "LeanSrc/LeanSrc/Sorts.lean:530", "score": 5, "deps": "import Mathlib\n\ndef ordered : List Nat -> Bool\n| [] => True\n| [_x] => True\n| x::y::xs => x <= y && ordered (y::xs)\n\n\nmutual\n def evens : List Nat \u2192 List Nat\n | [] => []\n | x::xs => x::(odds xs)\n\n def odds : List Nat \u2192 List Nat\n | [] => []\n | _x::xs => evens xs\nend\n\n\nlemma len_evens_le : (evens xs).length \u2264 xs.length := by\n generalize hxsl: xs.length = xsl\n induction xsl using Nat.strong_induction_on generalizing xs with\n | h n ih =>\n cases xs with\n | nil => unfold evens; simp;\n | cons head1 tail1 =>\n unfold evens;\n cases tail1 with\n | nil => unfold odds; rw[\u2190 hxsl];\n | cons head2 tail2 =>\n unfold odds;\n rw [List.length_cons, List.length_cons] at hxsl;\n rw [\u2190 hxsl, List.length_cons, Nat.succ_eq_add_one _, Nat.succ_eq_add_one _];\n simp;\n have h': List.length tail2 < n := by rw [\u2190 hxsl, Nat.succ_eq_add_one _]; linarith;\n exact Nat.le.step (ih (List.length tail2) h' rfl);\n\n\nlemma len_odds_le : (odds xs).length \u2264 xs.length := by\n generalize hxsl: xs.length = xsl\n induction xsl using Nat.strong_induction_on generalizing xs with\n | h n ih =>\n cases xs with\n | nil => unfold odds; simp;\n | cons head1 tail1 =>\n unfold odds;\n cases tail1 with\n | nil => unfold evens; simp;\n | cons head2 tail2 =>\n unfold evens;\n rw [List.length_cons, List.length_cons] at hxsl;\n rw [\u2190 hxsl, List.length_cons, Nat.succ_eq_add_one _, Nat.succ_eq_add_one _];\n simp;\n have h': List.length tail2 < n := by rw [\u2190 hxsl, Nat.succ_eq_add_one _]; linarith;\n exact Nat.le.step (ih (List.length tail2) h' rfl);\n\n\ndef sort2 (a b: Nat): List Nat := if a \u2264 b then [a,b] else [b, a]\n\n\ndef pairs : List Nat \u2192 List Nat \u2192 List Nat\n| [], ys => ys\n| xs, [] => xs\n| x::xs, y::ys => (sort2 x y) ++ (pairs xs ys)\n\n\ndef stitch : List Nat \u2192 List Nat \u2192 List Nat\n| [], ys => ys\n| x::xs, ys => x::(pairs xs ys)\n\n\nlemma bmerge_term (a b: Nat) (as bs: List Nat) (hlen: \u00ac(List.length as == 0 && List.length bs == 0) = true): List.length (evens (a :: as)) + List.length (evens (b :: bs)) < Nat.succ (List.length as) + Nat.succ (List.length bs) := by\n unfold evens;\n simp at hlen;\n rw [List.length_cons, List.length_cons, Nat.succ_eq_add_one _, Nat.succ_eq_add_one _, Nat.succ_eq_add_one _, Nat.succ_eq_add_one _];\n ring_nf;\n cases as with\n | nil => cases bs with\n | nil => simp at hlen;\n | cons bhead btail => unfold odds; simp; linarith [@len_evens_le btail];\n | cons ahead atail =>\n rw [add_comm, add_comm (2 + List.length (ahead :: atail)) (List.length bs)]\n refine add_lt_add_of_le_of_lt (@len_odds_le bs) ?h; unfold odds; simp; linarith [@len_evens_le atail];\n\n\nlemma bmerge_term2 (x y: Nat) (xs ys: List Nat) : List.length (odds (x :: xs)) + List.length (odds (y :: ys)) < Nat.succ (List.length xs) + Nat.succ (List.length ys) := by\n unfold odds;\n exact add_lt_add_of_lt_of_lt (Nat.lt_succ_of_le (@len_evens_le xs)) (Nat.lt_succ_of_le (@len_evens_le ys))\n\n\ndef bmerge : List Nat \u2192 List Nat \u2192 List Nat\n| [], bs => bs -- I changed this from TIP. I don't believe this case is ever hit, though.\n| as, [] => as\n| x::xs, y::ys =>\n if hlen: xs.length == 0 && ys.length == 0 then sort2 x y else\n have _h := bmerge_term x y xs ys hlen;\n have _h2 := bmerge_term2 x y xs ys;\n stitch (bmerge (evens (x::xs)) (evens (y::ys))) (bmerge (odds (x::xs)) (odds (y::ys)))\ntermination_by xs ys => xs.length + ys.length\n\n\nlemma bsort_term1 (x y: Nat) (xs: List Nat): List.length (evens (x :: y :: xs)) < Nat.succ (Nat.succ (List.length xs)) := by\n unfold evens; unfold odds;\n rw [List.length_cons, Nat.succ_eq_add_one _, Nat.succ_eq_add_one _];\n simp;\n exact Nat.lt_succ_of_le (@len_evens_le xs);\n\n\nlemma bsort_term2 (x y: Nat) (xs: List Nat): List.length (odds (x :: y :: xs)) < Nat.succ (Nat.succ (List.length xs)) := by\n unfold odds; unfold evens;\n rw [List.length_cons, Nat.succ_eq_add_one _, Nat.succ_eq_add_one _];\n simp;\n exact Nat.lt_succ_of_le (@len_odds_le xs);\n\n\ndef bsort : List Nat \u2192 List Nat\n| [] => []\n| [x] => [x]\n| x::y::xs =>\n have _h := bsort_term1 x y xs\n have _h2 := bsort_term2 x y xs\n bmerge (bsort (evens (x::y::xs))) (bsort (odds (x::y::xs)))\ntermination_by xs => xs.length\n", "proof_state": "xs : List \u2115\n\u22a2 (ordered (bsort xs) == true) = true", "file_locs": [["LeanSrc/LeanSrc/Sorts.lean", 530]]}
119
- {"full_name": "prop_BSortCount", "prop_defn": "theorem prop_BSortCount (x: Nat) (xs: List Nat) : count x (bsort xs) == count x xs:= by sorry", "prop_loc": "LeanSrc/LeanSrc/Sorts.lean:531", "score": 5, "deps": "import Mathlib\n\ndef count [DecidableEq \u03b1] : \u03b1 \u2192 List \u03b1 \u2192 Nat\n| _x, [] => 0\n| x, y::ys => if x == y then 1 + (count x ys) else count x ys\n\n\nmutual\n def evens : List Nat \u2192 List Nat\n | [] => []\n | x::xs => x::(odds xs)\n\n def odds : List Nat \u2192 List Nat\n | [] => []\n | _x::xs => evens xs\nend\n\n\nlemma len_evens_le : (evens xs).length \u2264 xs.length := by\n generalize hxsl: xs.length = xsl\n induction xsl using Nat.strong_induction_on generalizing xs with\n | h n ih =>\n cases xs with\n | nil => unfold evens; simp;\n | cons head1 tail1 =>\n unfold evens;\n cases tail1 with\n | nil => unfold odds; rw[\u2190 hxsl];\n | cons head2 tail2 =>\n unfold odds;\n rw [List.length_cons, List.length_cons] at hxsl;\n rw [\u2190 hxsl, List.length_cons, Nat.succ_eq_add_one _, Nat.succ_eq_add_one _];\n simp;\n have h': List.length tail2 < n := by rw [\u2190 hxsl, Nat.succ_eq_add_one _]; linarith;\n exact Nat.le.step (ih (List.length tail2) h' rfl);\n\n\nlemma len_odds_le : (odds xs).length \u2264 xs.length := by\n generalize hxsl: xs.length = xsl\n induction xsl using Nat.strong_induction_on generalizing xs with\n | h n ih =>\n cases xs with\n | nil => unfold odds; simp;\n | cons head1 tail1 =>\n unfold odds;\n cases tail1 with\n | nil => unfold evens; simp;\n | cons head2 tail2 =>\n unfold evens;\n rw [List.length_cons, List.length_cons] at hxsl;\n rw [\u2190 hxsl, List.length_cons, Nat.succ_eq_add_one _, Nat.succ_eq_add_one _];\n simp;\n have h': List.length tail2 < n := by rw [\u2190 hxsl, Nat.succ_eq_add_one _]; linarith;\n exact Nat.le.step (ih (List.length tail2) h' rfl);\n\n\ndef sort2 (a b: Nat): List Nat := if a \u2264 b then [a,b] else [b, a]\n\n\ndef pairs : List Nat \u2192 List Nat \u2192 List Nat\n| [], ys => ys\n| xs, [] => xs\n| x::xs, y::ys => (sort2 x y) ++ (pairs xs ys)\n\n\ndef stitch : List Nat \u2192 List Nat \u2192 List Nat\n| [], ys => ys\n| x::xs, ys => x::(pairs xs ys)\n\n\nlemma bmerge_term (a b: Nat) (as bs: List Nat) (hlen: \u00ac(List.length as == 0 && List.length bs == 0) = true): List.length (evens (a :: as)) + List.length (evens (b :: bs)) < Nat.succ (List.length as) + Nat.succ (List.length bs) := by\n unfold evens;\n simp at hlen;\n rw [List.length_cons, List.length_cons, Nat.succ_eq_add_one _, Nat.succ_eq_add_one _, Nat.succ_eq_add_one _, Nat.succ_eq_add_one _];\n ring_nf;\n cases as with\n | nil => cases bs with\n | nil => simp at hlen;\n | cons bhead btail => unfold odds; simp; linarith [@len_evens_le btail];\n | cons ahead atail =>\n rw [add_comm, add_comm (2 + List.length (ahead :: atail)) (List.length bs)]\n refine add_lt_add_of_le_of_lt (@len_odds_le bs) ?h; unfold odds; simp; linarith [@len_evens_le atail];\n\n\nlemma bmerge_term2 (x y: Nat) (xs ys: List Nat) : List.length (odds (x :: xs)) + List.length (odds (y :: ys)) < Nat.succ (List.length xs) + Nat.succ (List.length ys) := by\n unfold odds;\n exact add_lt_add_of_lt_of_lt (Nat.lt_succ_of_le (@len_evens_le xs)) (Nat.lt_succ_of_le (@len_evens_le ys))\n\n\ndef bmerge : List Nat \u2192 List Nat \u2192 List Nat\n| [], bs => bs -- I changed this from TIP. I don't believe this case is ever hit, though.\n| as, [] => as\n| x::xs, y::ys =>\n if hlen: xs.length == 0 && ys.length == 0 then sort2 x y else\n have _h := bmerge_term x y xs ys hlen;\n have _h2 := bmerge_term2 x y xs ys;\n stitch (bmerge (evens (x::xs)) (evens (y::ys))) (bmerge (odds (x::xs)) (odds (y::ys)))\ntermination_by xs ys => xs.length + ys.length\n\n\nlemma bsort_term1 (x y: Nat) (xs: List Nat): List.length (evens (x :: y :: xs)) < Nat.succ (Nat.succ (List.length xs)) := by\n unfold evens; unfold odds;\n rw [List.length_cons, Nat.succ_eq_add_one _, Nat.succ_eq_add_one _];\n simp;\n exact Nat.lt_succ_of_le (@len_evens_le xs);\n\n\nlemma bsort_term2 (x y: Nat) (xs: List Nat): List.length (odds (x :: y :: xs)) < Nat.succ (Nat.succ (List.length xs)) := by\n unfold odds; unfold evens;\n rw [List.length_cons, Nat.succ_eq_add_one _, Nat.succ_eq_add_one _];\n simp;\n exact Nat.lt_succ_of_le (@len_odds_le xs);\n\n\ndef bsort : List Nat \u2192 List Nat\n| [] => []\n| [x] => [x]\n| x::y::xs =>\n have _h := bsort_term1 x y xs\n have _h2 := bsort_term2 x y xs\n bmerge (bsort (evens (x::y::xs))) (bsort (odds (x::y::xs)))\ntermination_by xs => xs.length\n", "proof_state": "x : \u2115\nxs : List \u2115\n\u22a2 (count x (bsort xs) == count x xs) = true", "file_locs": [["LeanSrc/LeanSrc/Sorts.lean", 531]]}
120
- {"full_name": "prop_BSortPermutes", "prop_defn": "theorem prop_BSortPermutes (xs: List Nat) : isPermutation (bsort xs) xs == true:= by sorry", "prop_loc": "LeanSrc/LeanSrc/Sorts.lean:532", "score": 5, "deps": "import Mathlib\n\ndef deleteFirst [DecidableEq \u03b1]: \u03b1 \u2192 List \u03b1 \u2192 List \u03b1\n | _, [] => []\n | n, x::xs => if n == x then xs else x::(deleteFirst n xs)\n\n\ndef isPermutation [DecidableEq \u03b1] : List \u03b1 \u2192 List \u03b1 \u2192 Bool\n| [], ys => (ys == [])\n| x::xs, ys => x \u2208 ys && (isPermutation xs (deleteFirst x ys))\n\n\nmutual\n def evens : List Nat \u2192 List Nat\n | [] => []\n | x::xs => x::(odds xs)\n\n def odds : List Nat \u2192 List Nat\n | [] => []\n | _x::xs => evens xs\nend\n\n\nlemma len_evens_le : (evens xs).length \u2264 xs.length := by\n generalize hxsl: xs.length = xsl\n induction xsl using Nat.strong_induction_on generalizing xs with\n | h n ih =>\n cases xs with\n | nil => unfold evens; simp;\n | cons head1 tail1 =>\n unfold evens;\n cases tail1 with\n | nil => unfold odds; rw[\u2190 hxsl];\n | cons head2 tail2 =>\n unfold odds;\n rw [List.length_cons, List.length_cons] at hxsl;\n rw [\u2190 hxsl, List.length_cons, Nat.succ_eq_add_one _, Nat.succ_eq_add_one _];\n simp;\n have h': List.length tail2 < n := by rw [\u2190 hxsl, Nat.succ_eq_add_one _]; linarith;\n exact Nat.le.step (ih (List.length tail2) h' rfl);\n\n\nlemma len_odds_le : (odds xs).length \u2264 xs.length := by\n generalize hxsl: xs.length = xsl\n induction xsl using Nat.strong_induction_on generalizing xs with\n | h n ih =>\n cases xs with\n | nil => unfold odds; simp;\n | cons head1 tail1 =>\n unfold odds;\n cases tail1 with\n | nil => unfold evens; simp;\n | cons head2 tail2 =>\n unfold evens;\n rw [List.length_cons, List.length_cons] at hxsl;\n rw [\u2190 hxsl, List.length_cons, Nat.succ_eq_add_one _, Nat.succ_eq_add_one _];\n simp;\n have h': List.length tail2 < n := by rw [\u2190 hxsl, Nat.succ_eq_add_one _]; linarith;\n exact Nat.le.step (ih (List.length tail2) h' rfl);\n\n\ndef sort2 (a b: Nat): List Nat := if a \u2264 b then [a,b] else [b, a]\n\n\ndef pairs : List Nat \u2192 List Nat \u2192 List Nat\n| [], ys => ys\n| xs, [] => xs\n| x::xs, y::ys => (sort2 x y) ++ (pairs xs ys)\n\n\ndef stitch : List Nat \u2192 List Nat \u2192 List Nat\n| [], ys => ys\n| x::xs, ys => x::(pairs xs ys)\n\n\nlemma bmerge_term (a b: Nat) (as bs: List Nat) (hlen: \u00ac(List.length as == 0 && List.length bs == 0) = true): List.length (evens (a :: as)) + List.length (evens (b :: bs)) < Nat.succ (List.length as) + Nat.succ (List.length bs) := by\n unfold evens;\n simp at hlen;\n rw [List.length_cons, List.length_cons, Nat.succ_eq_add_one _, Nat.succ_eq_add_one _, Nat.succ_eq_add_one _, Nat.succ_eq_add_one _];\n ring_nf;\n cases as with\n | nil => cases bs with\n | nil => simp at hlen;\n | cons bhead btail => unfold odds; simp; linarith [@len_evens_le btail];\n | cons ahead atail =>\n rw [add_comm, add_comm (2 + List.length (ahead :: atail)) (List.length bs)]\n refine add_lt_add_of_le_of_lt (@len_odds_le bs) ?h; unfold odds; simp; linarith [@len_evens_le atail];\n\n\nlemma bmerge_term2 (x y: Nat) (xs ys: List Nat) : List.length (odds (x :: xs)) + List.length (odds (y :: ys)) < Nat.succ (List.length xs) + Nat.succ (List.length ys) := by\n unfold odds;\n exact add_lt_add_of_lt_of_lt (Nat.lt_succ_of_le (@len_evens_le xs)) (Nat.lt_succ_of_le (@len_evens_le ys))\n\n\ndef bmerge : List Nat \u2192 List Nat \u2192 List Nat\n| [], bs => bs -- I changed this from TIP. I don't believe this case is ever hit, though.\n| as, [] => as\n| x::xs, y::ys =>\n if hlen: xs.length == 0 && ys.length == 0 then sort2 x y else\n have _h := bmerge_term x y xs ys hlen;\n have _h2 := bmerge_term2 x y xs ys;\n stitch (bmerge (evens (x::xs)) (evens (y::ys))) (bmerge (odds (x::xs)) (odds (y::ys)))\ntermination_by xs ys => xs.length + ys.length\n\n\nlemma bsort_term1 (x y: Nat) (xs: List Nat): List.length (evens (x :: y :: xs)) < Nat.succ (Nat.succ (List.length xs)) := by\n unfold evens; unfold odds;\n rw [List.length_cons, Nat.succ_eq_add_one _, Nat.succ_eq_add_one _];\n simp;\n exact Nat.lt_succ_of_le (@len_evens_le xs);\n\n\nlemma bsort_term2 (x y: Nat) (xs: List Nat): List.length (odds (x :: y :: xs)) < Nat.succ (Nat.succ (List.length xs)) := by\n unfold odds; unfold evens;\n rw [List.length_cons, Nat.succ_eq_add_one _, Nat.succ_eq_add_one _];\n simp;\n exact Nat.lt_succ_of_le (@len_odds_le xs);\n\n\ndef bsort : List Nat \u2192 List Nat\n| [] => []\n| [x] => [x]\n| x::y::xs =>\n have _h := bsort_term1 x y xs\n have _h2 := bsort_term2 x y xs\n bmerge (bsort (evens (x::y::xs))) (bsort (odds (x::y::xs)))\ntermination_by xs => xs.length\n", "proof_state": "xs : List \u2115\n\u22a2 (isPermutation (bsort xs) xs == true) = true", "file_locs": [["LeanSrc/LeanSrc/Sorts.lean", 532]]}
121
- {"full_name": "prop_BSortIsSort", "prop_defn": "theorem prop_BSortIsSort (xs: List Nat) : bsort xs == isort xs:= by sorry", "prop_loc": "LeanSrc/LeanSrc/Sorts.lean:533", "score": 5, "deps": "import Mathlib\n\ndef insert' : Nat \u2192 List Nat \u2192 List Nat\n| x, [] => [x]\n| x, y::xs => if x <= y then x::y::xs else y::(insert x xs)\n\n\ndef isort: List Nat \u2192 List Nat\n| [] => []\n| x::xs => insert' x (isort xs)\n\n\nmutual\n def evens : List Nat \u2192 List Nat\n | [] => []\n | x::xs => x::(odds xs)\n\n def odds : List Nat \u2192 List Nat\n | [] => []\n | _x::xs => evens xs\nend\n\n\nlemma len_evens_le : (evens xs).length \u2264 xs.length := by\n generalize hxsl: xs.length = xsl\n induction xsl using Nat.strong_induction_on generalizing xs with\n | h n ih =>\n cases xs with\n | nil => unfold evens; simp;\n | cons head1 tail1 =>\n unfold evens;\n cases tail1 with\n | nil => unfold odds; rw[\u2190 hxsl];\n | cons head2 tail2 =>\n unfold odds;\n rw [List.length_cons, List.length_cons] at hxsl;\n rw [\u2190 hxsl, List.length_cons, Nat.succ_eq_add_one _, Nat.succ_eq_add_one _];\n simp;\n have h': List.length tail2 < n := by rw [\u2190 hxsl, Nat.succ_eq_add_one _]; linarith;\n exact Nat.le.step (ih (List.length tail2) h' rfl);\n\n\nlemma len_odds_le : (odds xs).length \u2264 xs.length := by\n generalize hxsl: xs.length = xsl\n induction xsl using Nat.strong_induction_on generalizing xs with\n | h n ih =>\n cases xs with\n | nil => unfold odds; simp;\n | cons head1 tail1 =>\n unfold odds;\n cases tail1 with\n | nil => unfold evens; simp;\n | cons head2 tail2 =>\n unfold evens;\n rw [List.length_cons, List.length_cons] at hxsl;\n rw [\u2190 hxsl, List.length_cons, Nat.succ_eq_add_one _, Nat.succ_eq_add_one _];\n simp;\n have h': List.length tail2 < n := by rw [\u2190 hxsl, Nat.succ_eq_add_one _]; linarith;\n exact Nat.le.step (ih (List.length tail2) h' rfl);\n\n\ndef sort2 (a b: Nat): List Nat := if a \u2264 b then [a,b] else [b, a]\n\n\ndef pairs : List Nat \u2192 List Nat \u2192 List Nat\n| [], ys => ys\n| xs, [] => xs\n| x::xs, y::ys => (sort2 x y) ++ (pairs xs ys)\n\n\ndef stitch : List Nat \u2192 List Nat \u2192 List Nat\n| [], ys => ys\n| x::xs, ys => x::(pairs xs ys)\n\n\nlemma bmerge_term (a b: Nat) (as bs: List Nat) (hlen: \u00ac(List.length as == 0 && List.length bs == 0) = true): List.length (evens (a :: as)) + List.length (evens (b :: bs)) < Nat.succ (List.length as) + Nat.succ (List.length bs) := by\n unfold evens;\n simp at hlen;\n rw [List.length_cons, List.length_cons, Nat.succ_eq_add_one _, Nat.succ_eq_add_one _, Nat.succ_eq_add_one _, Nat.succ_eq_add_one _];\n ring_nf;\n cases as with\n | nil => cases bs with\n | nil => simp at hlen;\n | cons bhead btail => unfold odds; simp; linarith [@len_evens_le btail];\n | cons ahead atail =>\n rw [add_comm, add_comm (2 + List.length (ahead :: atail)) (List.length bs)]\n refine add_lt_add_of_le_of_lt (@len_odds_le bs) ?h; unfold odds; simp; linarith [@len_evens_le atail];\n\n\nlemma bmerge_term2 (x y: Nat) (xs ys: List Nat) : List.length (odds (x :: xs)) + List.length (odds (y :: ys)) < Nat.succ (List.length xs) + Nat.succ (List.length ys) := by\n unfold odds;\n exact add_lt_add_of_lt_of_lt (Nat.lt_succ_of_le (@len_evens_le xs)) (Nat.lt_succ_of_le (@len_evens_le ys))\n\n\ndef bmerge : List Nat \u2192 List Nat \u2192 List Nat\n| [], bs => bs -- I changed this from TIP. I don't believe this case is ever hit, though.\n| as, [] => as\n| x::xs, y::ys =>\n if hlen: xs.length == 0 && ys.length == 0 then sort2 x y else\n have _h := bmerge_term x y xs ys hlen;\n have _h2 := bmerge_term2 x y xs ys;\n stitch (bmerge (evens (x::xs)) (evens (y::ys))) (bmerge (odds (x::xs)) (odds (y::ys)))\ntermination_by xs ys => xs.length + ys.length\n\n\nlemma bsort_term1 (x y: Nat) (xs: List Nat): List.length (evens (x :: y :: xs)) < Nat.succ (Nat.succ (List.length xs)) := by\n unfold evens; unfold odds;\n rw [List.length_cons, Nat.succ_eq_add_one _, Nat.succ_eq_add_one _];\n simp;\n exact Nat.lt_succ_of_le (@len_evens_le xs);\n\n\nlemma bsort_term2 (x y: Nat) (xs: List Nat): List.length (odds (x :: y :: xs)) < Nat.succ (Nat.succ (List.length xs)) := by\n unfold odds; unfold evens;\n rw [List.length_cons, Nat.succ_eq_add_one _, Nat.succ_eq_add_one _];\n simp;\n exact Nat.lt_succ_of_le (@len_odds_le xs);\n\n\ndef bsort : List Nat \u2192 List Nat\n| [] => []\n| [x] => [x]\n| x::y::xs =>\n have _h := bsort_term1 x y xs\n have _h2 := bsort_term2 x y xs\n bmerge (bsort (evens (x::y::xs))) (bsort (odds (x::y::xs)))\ntermination_by xs => xs.length\n", "proof_state": "xs : List \u2115\n\u22a2 (bsort xs == isort xs) = true", "file_locs": [["LeanSrc/LeanSrc/Sorts.lean", 533]]}
122
  {"full_name": "prop_QSortSorts", "prop_defn": "theorem prop_QSortSorts (xs: List Nat) : ordered (qsort xs) == true:= by sorry", "prop_loc": "LeanSrc/LeanSrc/Sorts.lean:570", "score": 5, "deps": "import Mathlib\n\ndef ordered : List Nat -> Bool\n| [] => True\n| [_x] => True\n| x::y::xs => x <= y && ordered (y::xs)\n\n\ndef filter : List Nat \u2192 (Nat \u2192 Bool) \u2192 List Nat\n| [], _f => []\n| x::xs, f => if f x then x::(filter xs f) else (filter xs f)\n\n\nlemma filter_len_le {f: Nat \u2192 Bool} {xs: List Nat}: (filter xs f).length <= xs.length := by\n generalize hxsl: xs.length = xsl\n induction xsl generalizing xs with\n | zero => rw [List.length_eq_zero] at hxsl; rw [hxsl]; unfold filter; simp;\n | succ n ih =>\n cases xs with\n | nil => unfold filter; simp;\n | cons head tail =>\n rw [List.length_cons] at hxsl; simp at hxsl;\n unfold filter; split_ifs with h1;\n case pos;\n rw [List.length_cons];\n exact Nat.pred_le_iff.mp (ih hxsl)\n case neg;\n exact Nat.le.step (ih hxsl)\n\n\nlemma qsort_term (x:Nat) (xs: List Nat) : List.length (filter xs fun y => decide (y \u2264 x)) < Nat.succ (List.length xs) := by\n exact Nat.lt_succ_of_le (filter_len_le);\n\n\nlemma qsort_term2 (x:Nat) (xs: List Nat) : List.length (filter xs fun y => decide (y > x)) < Nat.succ (List.length xs) := by\n exact Nat.lt_succ_of_le (filter_len_le);\n\n\ndef qsort : List Nat \u2192 List Nat\n| [] => []\n| x::xs =>\n have _h:= qsort_term x xs\n have _h2:= qsort_term2 x xs\n (qsort (filter xs (fun y => y <= x))) ++ [x] ++ (qsort (filter xs (fun y => y > x)))\ntermination_by xs => xs.length\n", "proof_state": "xs : List \u2115\n\u22a2 (ordered (qsort xs) == true) = true", "file_locs": [["LeanSrc/LeanSrc/Sorts.lean", 570]]}
123
  {"full_name": "prop_QSortCount", "prop_defn": "theorem prop_QSortCount (x: Nat) (xs: List Nat) : count x (qsort xs) == count x xs:= by sorry", "prop_loc": "LeanSrc/LeanSrc/Sorts.lean:571", "score": 5, "deps": "import Mathlib\n\ndef count [DecidableEq \u03b1] : \u03b1 \u2192 List \u03b1 \u2192 Nat\n| _x, [] => 0\n| x, y::ys => if x == y then 1 + (count x ys) else count x ys\n\n\ndef filter : List Nat \u2192 (Nat \u2192 Bool) \u2192 List Nat\n| [], _f => []\n| x::xs, f => if f x then x::(filter xs f) else (filter xs f)\n\n\nlemma filter_len_le {f: Nat \u2192 Bool} {xs: List Nat}: (filter xs f).length <= xs.length := by\n generalize hxsl: xs.length = xsl\n induction xsl generalizing xs with\n | zero => rw [List.length_eq_zero] at hxsl; rw [hxsl]; unfold filter; simp;\n | succ n ih =>\n cases xs with\n | nil => unfold filter; simp;\n | cons head tail =>\n rw [List.length_cons] at hxsl; simp at hxsl;\n unfold filter; split_ifs with h1;\n case pos;\n rw [List.length_cons];\n exact Nat.pred_le_iff.mp (ih hxsl)\n case neg;\n exact Nat.le.step (ih hxsl)\n\n\nlemma qsort_term (x:Nat) (xs: List Nat) : List.length (filter xs fun y => decide (y \u2264 x)) < Nat.succ (List.length xs) := by\n exact Nat.lt_succ_of_le (filter_len_le);\n\n\nlemma qsort_term2 (x:Nat) (xs: List Nat) : List.length (filter xs fun y => decide (y > x)) < Nat.succ (List.length xs) := by\n exact Nat.lt_succ_of_le (filter_len_le);\n\n\ndef qsort : List Nat \u2192 List Nat\n| [] => []\n| x::xs =>\n have _h:= qsort_term x xs\n have _h2:= qsort_term2 x xs\n (qsort (filter xs (fun y => y <= x))) ++ [x] ++ (qsort (filter xs (fun y => y > x)))\ntermination_by xs => xs.length\n", "proof_state": "x : \u2115\nxs : List \u2115\n\u22a2 (count x (qsort xs) == count x xs) = true", "file_locs": [["LeanSrc/LeanSrc/Sorts.lean", 571]]}
124
  {"full_name": "prop_QSortPermutes", "prop_defn": "theorem prop_QSortPermutes (xs: List Nat) : isPermutation (qsort xs) xs == true:= by sorry", "prop_loc": "LeanSrc/LeanSrc/Sorts.lean:572", "score": 5, "deps": "import Mathlib\n\ndef deleteFirst [DecidableEq \u03b1]: \u03b1 \u2192 List \u03b1 \u2192 List \u03b1\n | _, [] => []\n | n, x::xs => if n == x then xs else x::(deleteFirst n xs)\n\n\ndef isPermutation [DecidableEq \u03b1] : List \u03b1 \u2192 List \u03b1 \u2192 Bool\n| [], ys => (ys == [])\n| x::xs, ys => x \u2208 ys && (isPermutation xs (deleteFirst x ys))\n\n\ndef filter : List Nat \u2192 (Nat \u2192 Bool) \u2192 List Nat\n| [], _f => []\n| x::xs, f => if f x then x::(filter xs f) else (filter xs f)\n\n\nlemma filter_len_le {f: Nat \u2192 Bool} {xs: List Nat}: (filter xs f).length <= xs.length := by\n generalize hxsl: xs.length = xsl\n induction xsl generalizing xs with\n | zero => rw [List.length_eq_zero] at hxsl; rw [hxsl]; unfold filter; simp;\n | succ n ih =>\n cases xs with\n | nil => unfold filter; simp;\n | cons head tail =>\n rw [List.length_cons] at hxsl; simp at hxsl;\n unfold filter; split_ifs with h1;\n case pos;\n rw [List.length_cons];\n exact Nat.pred_le_iff.mp (ih hxsl)\n case neg;\n exact Nat.le.step (ih hxsl)\n\n\nlemma qsort_term (x:Nat) (xs: List Nat) : List.length (filter xs fun y => decide (y \u2264 x)) < Nat.succ (List.length xs) := by\n exact Nat.lt_succ_of_le (filter_len_le);\n\n\nlemma qsort_term2 (x:Nat) (xs: List Nat) : List.length (filter xs fun y => decide (y > x)) < Nat.succ (List.length xs) := by\n exact Nat.lt_succ_of_le (filter_len_le);\n\n\ndef qsort : List Nat \u2192 List Nat\n| [] => []\n| x::xs =>\n have _h:= qsort_term x xs\n have _h2:= qsort_term2 x xs\n (qsort (filter xs (fun y => y <= x))) ++ [x] ++ (qsort (filter xs (fun y => y > x)))\ntermination_by xs => xs.length\n", "proof_state": "xs : List \u2115\n\u22a2 (isPermutation (qsort xs) xs == true) = true", "file_locs": [["LeanSrc/LeanSrc/Sorts.lean", 572]]}
@@ -154,12 +154,12 @@
154
  {"full_name": "len_pairwise", "prop_defn": "theorem len_pairwise (xs: List (List Nat)): 2 * (pairwise xs).length = (if (Odd xs.length) then xs.length + 1 else xs.length) := by sorry", "prop_loc": "LeanSrc/LeanSrc/Sorts.lean:241", "score": 5, "deps": "import Mathlib\n\ndef lmerge : List Nat \u2192 List Nat \u2192 List Nat\n| [], ys => ys\n| xs, [] => xs\n| x::xs, y::ys => if x <= y then\n x::(lmerge xs (y::ys))\n else\n y::(lmerge (x::xs) ys)\n\n\ndef pairwise : List (List Nat) \u2192 List (List Nat)\n| xs::ys::xss => lmerge xs ys :: pairwise xss\n| xss => xss\n", "proof_state": "xs : List (List \u2115)\n\u22a2 2 * (pairwise xs).length = if Odd xs.length then xs.length + 1 else xs.length", "file_locs": [["LeanSrc/LeanSrc/Sorts.lean", 286]]}
155
  {"full_name": "merge_term", "prop_defn": "theorem merge_term : (pairwise (xs::ys::xss)).length < (xs::ys::xss).length := by sorry", "prop_loc": "LeanSrc/LeanSrc/Sorts.lean:288", "score": 5, "deps": "import Mathlib\n\ndef lmerge : List Nat \u2192 List Nat \u2192 List Nat\n| [], ys => ys\n| xs, [] => xs\n| x::xs, y::ys => if x <= y then\n x::(lmerge xs (y::ys))\n else\n y::(lmerge (x::xs) ys)\n\n\ndef pairwise : List (List Nat) \u2192 List (List Nat)\n| xs::ys::xss => lmerge xs ys :: pairwise xss\n| xss => xss\n", "proof_state": "xs ys : List \u2115\nxss : List (List \u2115)\n\u22a2 (pairwise (xs :: ys :: xss)).length < (xs :: ys :: xss).length", "file_locs": [["LeanSrc/LeanSrc/Sorts.lean", 299]]}
156
  {"full_name": "half_lt", "prop_defn": "theorem half_lt: half x \u2264 x := by sorry", "prop_loc": "LeanSrc/LeanSrc/Sorts.lean:382", "score": 5, "deps": "import Mathlib\n\ndef half : Nat \u2192 Nat\n| 0 => 0\n| 1 => 0\n| x + 2 => 1 + (half x)\n", "proof_state": "x : \u2115\n\u22a2 half x \u2264 x", "file_locs": [["LeanSrc/LeanSrc/Sorts.lean", 395]]}
157
- {"full_name": "len_evens_le", "prop_defn": "theorem len_evens_le {xs: List Nat}: (evens xs).length \u2264 xs.length := by sorry", "prop_loc": "LeanSrc/LeanSrc/Sorts.lean:435", "score": 5, "deps": "import Mathlib\n\nmutual\n def evens : List Nat \u2192 List Nat\n | [] => []\n | x::xs => x::(odds xs)\n def odds : List Nat \u2192 List Nat\n | [] => []\n | _x::xs => evens xs\nend\n", "proof_state": "xs : List \u2115\n\u22a2 (evens xs).length \u2264 xs.length", "file_locs": [["LeanSrc/LeanSrc/Sorts.lean", 451]]}
158
- {"full_name": "len_odds_le", "prop_defn": "theorem len_odds_le {xs: List Nat}: (odds xs).length \u2264 xs.length := by sorry", "prop_loc": "LeanSrc/LeanSrc/Sorts.lean:453", "score": 5, "deps": "import Mathlib\n\nmutual\n def evens : List Nat \u2192 List Nat\n | [] => []\n | x::xs => x::(odds xs)\n def odds : List Nat \u2192 List Nat\n | [] => []\n | _x::xs => evens xs\nend\n", "proof_state": "xs : List \u2115\n\u22a2 (odds xs).length \u2264 xs.length", "file_locs": [["LeanSrc/LeanSrc/Sorts.lean", 469]]}
159
- {"full_name": "bmerge_term", "prop_defn": "theorem bmerge_term (a b: Nat) (as bs: List Nat) (hlen: \u00ac(List.length as == 0 && List.length bs == 0) = true): List.length (evens (a :: as)) + List.length (evens (b :: bs)) < Nat.succ (List.length as) + Nat.succ (List.length bs) := by sorry", "prop_loc": "LeanSrc/LeanSrc/Sorts.lean:482", "score": 5, "deps": "import Mathlib\n\nmutual\n def evens : List Nat \u2192 List Nat\n | [] => []\n | x::xs => x::(odds xs)\n def odds : List Nat \u2192 List Nat\n | [] => []\n | _x::xs => evens xs\nend\n", "proof_state": "a b : \u2115\nas bs : List \u2115\nhlen : \u00ac(as.length == 0 && bs.length == 0) = true\n\u22a2 (evens (a :: as)).length + (evens (b :: bs)).length < as.length.succ + bs.length.succ", "file_locs": [["LeanSrc/LeanSrc/Sorts.lean", 493]]}
160
- {"full_name": "bmerge_term2", "prop_defn": "theorem bmerge_term2 (x y: Nat) (xs ys: List Nat) : List.length (odds (x :: xs)) + List.length (odds (y :: ys)) < Nat.succ (List.length xs) + Nat.succ (List.length ys) := by sorry", "prop_loc": "LeanSrc/LeanSrc/Sorts.lean:495", "score": 5, "deps": "import Mathlib\n\nmutual\n def evens : List Nat \u2192 List Nat\n | [] => []\n | x::xs => x::(odds xs)\n def odds : List Nat \u2192 List Nat\n | [] => []\n | _x::xs => evens xs\nend\n", "proof_state": "x y : \u2115\nxs ys : List \u2115\n\u22a2 (odds (x :: xs)).length + (odds (y :: ys)).length < xs.length.succ + ys.length.succ", "file_locs": [["LeanSrc/LeanSrc/Sorts.lean", 497]]}
161
- {"full_name": "bsort_term1", "prop_defn": "theorem bsort_term1 (x y: Nat) (xs: List Nat): List.length (evens (x :: y :: xs)) < Nat.succ (Nat.succ (List.length xs)) := by sorry", "prop_loc": "LeanSrc/LeanSrc/Sorts.lean:509", "score": 5, "deps": "import Mathlib\n\nmutual\n def evens : List Nat \u2192 List Nat\n | [] => []\n | x::xs => x::(odds xs)\n def odds : List Nat \u2192 List Nat\n | [] => []\n | _x::xs => evens xs\nend\n", "proof_state": "x y : \u2115\nxs : List \u2115\n\u22a2 (evens (x :: y :: xs)).length < xs.length.succ.succ", "file_locs": [["LeanSrc/LeanSrc/Sorts.lean", 513]]}
162
- {"full_name": "bsort_term2", "prop_defn": "theorem bsort_term2 (x y: Nat) (xs: List Nat): List.length (odds (x :: y :: xs)) < Nat.succ (Nat.succ (List.length xs)) := by sorry", "prop_loc": "LeanSrc/LeanSrc/Sorts.lean:515", "score": 5, "deps": "import Mathlib\n\nmutual\n def evens : List Nat \u2192 List Nat\n | [] => []\n | x::xs => x::(odds xs)\n def odds : List Nat \u2192 List Nat\n | [] => []\n | _x::xs => evens xs\nend\n", "proof_state": "x y : \u2115\nxs : List \u2115\n\u22a2 (odds (x :: y :: xs)).length < xs.length.succ.succ", "file_locs": [["LeanSrc/LeanSrc/Sorts.lean", 519]]}
163
  {"full_name": "filter_len_le", "prop_defn": "theorem filter_len_le {f: Nat \u2192 Bool} {xs: List Nat}: (filter xs f).length <= xs.length := by sorry", "prop_loc": "LeanSrc/LeanSrc/Sorts.lean:539", "score": 5, "deps": "import Mathlib\n\ndef filter : List Nat \u2192 (Nat \u2192 Bool) \u2192 List Nat\n| [], _f => []\n| x::xs, f => if f x then x::(filter xs f) else (filter xs f)\n", "proof_state": "f : \u2115 \u2192 Bool\nxs : List \u2115\n\u22a2 (filter xs f).length \u2264 xs.length", "file_locs": [["LeanSrc/LeanSrc/Sorts.lean", 553]]}
164
  {"full_name": "qsort_term", "prop_defn": "theorem qsort_term (x:Nat) (xs: List Nat) : List.length (filter xs fun y => decide (y \u2264 x)) < Nat.succ (List.length xs) := by sorry", "prop_loc": "LeanSrc/LeanSrc/Sorts.lean:556", "score": 5, "deps": "import Mathlib\n\ndef filter : List Nat \u2192 (Nat \u2192 Bool) \u2192 List Nat\n| [], _f => []\n| x::xs, f => if f x then x::(filter xs f) else (filter xs f)\n", "proof_state": "x : \u2115\nxs : List \u2115\n\u22a2 (filter xs fun y => decide (y \u2264 x)).length < xs.length.succ", "file_locs": [["LeanSrc/LeanSrc/Sorts.lean", 557]]}
165
  {"full_name": "qsort_term2", "prop_defn": "theorem qsort_term2 (x:Nat) (xs: List Nat) : List.length (filter xs fun y => decide (y > x)) < Nat.succ (List.length xs) := by sorry", "prop_loc": "LeanSrc/LeanSrc/Sorts.lean:559", "score": 5, "deps": "import Mathlib\n\ndef filter : List Nat \u2192 (Nat \u2192 Bool) \u2192 List Nat\n| [], _f => []\n| x::xs, f => if f x then x::(filter xs f) else (filter xs f)\n", "proof_state": "x : \u2115\nxs : List \u2115\n\u22a2 (filter xs fun y => decide (y > x)).length < xs.length.succ", "file_locs": [["LeanSrc/LeanSrc/Sorts.lean", 560]]}
 
115
  {"full_name": "prop_NMSortTDCount", "prop_defn": "theorem prop_NMSortTDCount (x: Nat) (xs: List Nat) : count x (nmsorttd xs) == count x xs:= by sorry", "prop_loc": "LeanSrc/LeanSrc/Sorts.lean:421", "score": 5, "deps": "import Mathlib\n\ndef count [DecidableEq \u03b1] : \u03b1 \u2192 List \u03b1 \u2192 Nat\n| _x, [] => 0\n| x, y::ys => if x == y then 1 + (count x ys) else count x ys\n\n\ndef lmerge : List Nat \u2192 List Nat \u2192 List Nat\n| [], ys => ys\n| xs, [] => xs\n| x::xs, y::ys => if x <= y then\n x::(lmerge xs (y::ys))\n else\n y::(lmerge (x::xs) ys)\n\n\ndef half : Nat \u2192 Nat\n| 0 => 0\n| 1 => 0\n| x + 2 => 1 + (half x)\n\n\nlemma half_lt: half x \u2264 x := by\n induction x using Nat.strong_induction_on with\n | h n ih =>\n cases n with\n | zero => unfold half; simp;\n | succ nm1 =>\n cases nm1 with\n | zero => unfold half; simp;\n | succ nm2 =>\n unfold half;\n have tmp := ih nm2 (by exact Nat.le.step Nat.le.refl);\n ring_nf;\n calc 1 + half nm2 \u2264 1 + nm2 := Nat.add_le_add (@Nat.le.refl 1) tmp\n _ \u2264 2 + nm2 := by simp\n\n\ndef nmsorttd : List Nat \u2192 List Nat\n| [] => []\n| [x] => [x]\n| x::y::xs =>\n let k:= half ((x::y::xs).length)\n have _h: half (Nat.succ (Nat.succ (List.length xs))) < Nat.succ (Nat.succ (List.length xs)) := by\n rw [Nat.succ_eq_add_one _];\n ring_nf;\n rw [Nat.add_comm];\n unfold half;\n ring_nf;\n calc 1 + half (xs.length) \u2264 1 + xs.length := by simp; exact half_lt;\n _ < 2 + xs.length := by simp;\n have _h': Nat.succ (Nat.succ (List.length xs)) - half (Nat.succ (Nat.succ (List.length xs))) <\n Nat.succ (Nat.succ (List.length xs)) := by\n suffices h': 0 < half (Nat.succ (Nat.succ (List.length xs)))\n case h';\n unfold half;simp;\n refine Nat.sub_lt ?h h'\n simp;\n lmerge (nmsorttd ((x::y::xs).take k)) (nmsorttd ((x::y::xs).drop k))\ntermination_by xs => xs.length\n", "proof_state": "x : \u2115\nxs : List \u2115\n\u22a2 (count x (nmsorttd xs) == count x xs) = true", "file_locs": [["LeanSrc/LeanSrc/Sorts.lean", 421]]}
116
  {"full_name": "prop_NMSortTDPermutes", "prop_defn": "theorem prop_NMSortTDPermutes (xs: List Nat) : isPermutation (nmsorttd xs) xs == true:= by sorry", "prop_loc": "LeanSrc/LeanSrc/Sorts.lean:422", "score": 5, "deps": "import Mathlib\n\ndef deleteFirst [DecidableEq \u03b1]: \u03b1 \u2192 List \u03b1 \u2192 List \u03b1\n | _, [] => []\n | n, x::xs => if n == x then xs else x::(deleteFirst n xs)\n\n\ndef isPermutation [DecidableEq \u03b1] : List \u03b1 \u2192 List \u03b1 \u2192 Bool\n| [], ys => (ys == [])\n| x::xs, ys => x \u2208 ys && (isPermutation xs (deleteFirst x ys))\n\n\ndef lmerge : List Nat \u2192 List Nat \u2192 List Nat\n| [], ys => ys\n| xs, [] => xs\n| x::xs, y::ys => if x <= y then\n x::(lmerge xs (y::ys))\n else\n y::(lmerge (x::xs) ys)\n\n\ndef half : Nat \u2192 Nat\n| 0 => 0\n| 1 => 0\n| x + 2 => 1 + (half x)\n\n\nlemma half_lt: half x \u2264 x := by\n induction x using Nat.strong_induction_on with\n | h n ih =>\n cases n with\n | zero => unfold half; simp;\n | succ nm1 =>\n cases nm1 with\n | zero => unfold half; simp;\n | succ nm2 =>\n unfold half;\n have tmp := ih nm2 (by exact Nat.le.step Nat.le.refl);\n ring_nf;\n calc 1 + half nm2 \u2264 1 + nm2 := Nat.add_le_add (@Nat.le.refl 1) tmp\n _ \u2264 2 + nm2 := by simp\n\n\ndef nmsorttd : List Nat \u2192 List Nat\n| [] => []\n| [x] => [x]\n| x::y::xs =>\n let k:= half ((x::y::xs).length)\n have _h: half (Nat.succ (Nat.succ (List.length xs))) < Nat.succ (Nat.succ (List.length xs)) := by\n rw [Nat.succ_eq_add_one _];\n ring_nf;\n rw [Nat.add_comm];\n unfold half;\n ring_nf;\n calc 1 + half (xs.length) \u2264 1 + xs.length := by simp; exact half_lt;\n _ < 2 + xs.length := by simp;\n have _h': Nat.succ (Nat.succ (List.length xs)) - half (Nat.succ (Nat.succ (List.length xs))) <\n Nat.succ (Nat.succ (List.length xs)) := by\n suffices h': 0 < half (Nat.succ (Nat.succ (List.length xs)))\n case h';\n unfold half;simp;\n refine Nat.sub_lt ?h h'\n simp;\n lmerge (nmsorttd ((x::y::xs).take k)) (nmsorttd ((x::y::xs).drop k))\ntermination_by xs => xs.length\n", "proof_state": "xs : List \u2115\n\u22a2 (isPermutation (nmsorttd xs) xs == true) = true", "file_locs": [["LeanSrc/LeanSrc/Sorts.lean", 422]]}
117
  {"full_name": "prop_NMSortTDIsSort", "prop_defn": "theorem prop_NMSortTDIsSort (xs: List Nat) : nmsorttd xs == isort xs:= by sorry", "prop_loc": "LeanSrc/LeanSrc/Sorts.lean:423", "score": 5, "deps": "import Mathlib\n\ndef insert' : Nat \u2192 List Nat \u2192 List Nat\n| x, [] => [x]\n| x, y::xs => if x <= y then x::y::xs else y::(insert x xs)\n\n\ndef isort: List Nat \u2192 List Nat\n| [] => []\n| x::xs => insert' x (isort xs)\n\n\ndef lmerge : List Nat \u2192 List Nat \u2192 List Nat\n| [], ys => ys\n| xs, [] => xs\n| x::xs, y::ys => if x <= y then\n x::(lmerge xs (y::ys))\n else\n y::(lmerge (x::xs) ys)\n\n\ndef half : Nat \u2192 Nat\n| 0 => 0\n| 1 => 0\n| x + 2 => 1 + (half x)\n\n\nlemma half_lt: half x \u2264 x := by\n induction x using Nat.strong_induction_on with\n | h n ih =>\n cases n with\n | zero => unfold half; simp;\n | succ nm1 =>\n cases nm1 with\n | zero => unfold half; simp;\n | succ nm2 =>\n unfold half;\n have tmp := ih nm2 (by exact Nat.le.step Nat.le.refl);\n ring_nf;\n calc 1 + half nm2 \u2264 1 + nm2 := Nat.add_le_add (@Nat.le.refl 1) tmp\n _ \u2264 2 + nm2 := by simp\n\n\ndef nmsorttd : List Nat \u2192 List Nat\n| [] => []\n| [x] => [x]\n| x::y::xs =>\n let k:= half ((x::y::xs).length)\n have _h: half (Nat.succ (Nat.succ (List.length xs))) < Nat.succ (Nat.succ (List.length xs)) := by\n rw [Nat.succ_eq_add_one _];\n ring_nf;\n rw [Nat.add_comm];\n unfold half;\n ring_nf;\n calc 1 + half (xs.length) \u2264 1 + xs.length := by simp; exact half_lt;\n _ < 2 + xs.length := by simp;\n have _h': Nat.succ (Nat.succ (List.length xs)) - half (Nat.succ (Nat.succ (List.length xs))) <\n Nat.succ (Nat.succ (List.length xs)) := by\n suffices h': 0 < half (Nat.succ (Nat.succ (List.length xs)))\n case h';\n unfold half;simp;\n refine Nat.sub_lt ?h h'\n simp;\n lmerge (nmsorttd ((x::y::xs).take k)) (nmsorttd ((x::y::xs).drop k))\ntermination_by xs => xs.length\n", "proof_state": "xs : List \u2115\n\u22a2 (nmsorttd xs == isort xs) = true", "file_locs": [["LeanSrc/LeanSrc/Sorts.lean", 423]]}
118
+ {"full_name": "prop_BSortSorts", "prop_defn": "theorem prop_BSortSorts (xs: List Nat) : ordered (bsort xs) == true:= by sorry", "prop_loc": "LeanSrc/LeanSrc/Sorts.lean:530", "score": 5, "deps": "import Mathlib\n\ndef ordered : List Nat -> Bool\n| [] => True\n| [_x] => True\n| x::y::xs => x <= y && ordered (y::xs)\n\n\nmutual\n def evens : List Nat \u2192 List Nat\n | [] => []\n | x::xs => x::(odds xs)\n--\n def odds : List Nat \u2192 List Nat\n | [] => []\n | _x::xs => evens xs\nend\n\n\nlemma len_evens_le : (evens xs).length \u2264 xs.length := by\n generalize hxsl: xs.length = xsl\n induction xsl using Nat.strong_induction_on generalizing xs with\n | h n ih =>\n cases xs with\n | nil => unfold evens; simp;\n | cons head1 tail1 =>\n unfold evens;\n cases tail1 with\n | nil => unfold odds; rw[\u2190 hxsl];\n | cons head2 tail2 =>\n unfold odds;\n rw [List.length_cons, List.length_cons] at hxsl;\n rw [\u2190 hxsl, List.length_cons, Nat.succ_eq_add_one _, Nat.succ_eq_add_one _];\n simp;\n have h': List.length tail2 < n := by rw [\u2190 hxsl, Nat.succ_eq_add_one _]; linarith;\n exact Nat.le.step (ih (List.length tail2) h' rfl);\n\n\nlemma len_odds_le : (odds xs).length \u2264 xs.length := by\n generalize hxsl: xs.length = xsl\n induction xsl using Nat.strong_induction_on generalizing xs with\n | h n ih =>\n cases xs with\n | nil => unfold odds; simp;\n | cons head1 tail1 =>\n unfold odds;\n cases tail1 with\n | nil => unfold evens; simp;\n | cons head2 tail2 =>\n unfold evens;\n rw [List.length_cons, List.length_cons] at hxsl;\n rw [\u2190 hxsl, List.length_cons, Nat.succ_eq_add_one _, Nat.succ_eq_add_one _];\n simp;\n have h': List.length tail2 < n := by rw [\u2190 hxsl, Nat.succ_eq_add_one _]; linarith;\n exact Nat.le.step (ih (List.length tail2) h' rfl);\n\n\ndef sort2 (a b: Nat): List Nat := if a \u2264 b then [a,b] else [b, a]\n\n\ndef pairs : List Nat \u2192 List Nat \u2192 List Nat\n| [], ys => ys\n| xs, [] => xs\n| x::xs, y::ys => (sort2 x y) ++ (pairs xs ys)\n\n\ndef stitch : List Nat \u2192 List Nat \u2192 List Nat\n| [], ys => ys\n| x::xs, ys => x::(pairs xs ys)\n\n\nlemma bmerge_term (a b: Nat) (as bs: List Nat) (hlen: \u00ac(List.length as == 0 && List.length bs == 0) = true): List.length (evens (a :: as)) + List.length (evens (b :: bs)) < Nat.succ (List.length as) + Nat.succ (List.length bs) := by\n unfold evens;\n simp at hlen;\n rw [List.length_cons, List.length_cons, Nat.succ_eq_add_one _, Nat.succ_eq_add_one _, Nat.succ_eq_add_one _, Nat.succ_eq_add_one _];\n ring_nf;\n cases as with\n | nil => cases bs with\n | nil => simp at hlen;\n | cons bhead btail => unfold odds; simp; linarith [@len_evens_le btail];\n | cons ahead atail =>\n rw [add_comm, add_comm (2 + List.length (ahead :: atail)) (List.length bs)]\n refine add_lt_add_of_le_of_lt (@len_odds_le bs) ?h; unfold odds; simp; linarith [@len_evens_le atail];\n\n\nlemma bmerge_term2 (x y: Nat) (xs ys: List Nat) : List.length (odds (x :: xs)) + List.length (odds (y :: ys)) < Nat.succ (List.length xs) + Nat.succ (List.length ys) := by\n unfold odds;\n exact add_lt_add_of_lt_of_lt (Nat.lt_succ_of_le (@len_evens_le xs)) (Nat.lt_succ_of_le (@len_evens_le ys))\n\n\ndef bmerge : List Nat \u2192 List Nat \u2192 List Nat\n| [], bs => bs -- I changed this from TIP. I don't believe this case is ever hit, though.\n| as, [] => as\n| x::xs, y::ys =>\n if hlen: xs.length == 0 && ys.length == 0 then sort2 x y else\n have _h := bmerge_term x y xs ys hlen;\n have _h2 := bmerge_term2 x y xs ys;\n stitch (bmerge (evens (x::xs)) (evens (y::ys))) (bmerge (odds (x::xs)) (odds (y::ys)))\ntermination_by xs ys => xs.length + ys.length\n\n\nlemma bsort_term1 (x y: Nat) (xs: List Nat): List.length (evens (x :: y :: xs)) < Nat.succ (Nat.succ (List.length xs)) := by\n unfold evens; unfold odds;\n rw [List.length_cons, Nat.succ_eq_add_one _, Nat.succ_eq_add_one _];\n simp;\n exact Nat.lt_succ_of_le (@len_evens_le xs);\n\n\nlemma bsort_term2 (x y: Nat) (xs: List Nat): List.length (odds (x :: y :: xs)) < Nat.succ (Nat.succ (List.length xs)) := by\n unfold odds; unfold evens;\n rw [List.length_cons, Nat.succ_eq_add_one _, Nat.succ_eq_add_one _];\n simp;\n exact Nat.lt_succ_of_le (@len_odds_le xs);\n\n\ndef bsort : List Nat \u2192 List Nat\n| [] => []\n| [x] => [x]\n| x::y::xs =>\n have _h := bsort_term1 x y xs\n have _h2 := bsort_term2 x y xs\n bmerge (bsort (evens (x::y::xs))) (bsort (odds (x::y::xs)))\ntermination_by xs => xs.length\n", "proof_state": "xs : List \u2115\n\u22a2 (ordered (bsort xs) == true) = true", "file_locs": [["LeanSrc/LeanSrc/Sorts.lean", 530]]}
119
+ {"full_name": "prop_BSortCount", "prop_defn": "theorem prop_BSortCount (x: Nat) (xs: List Nat) : count x (bsort xs) == count x xs:= by sorry", "prop_loc": "LeanSrc/LeanSrc/Sorts.lean:531", "score": 5, "deps": "import Mathlib\n\ndef count [DecidableEq \u03b1] : \u03b1 \u2192 List \u03b1 \u2192 Nat\n| _x, [] => 0\n| x, y::ys => if x == y then 1 + (count x ys) else count x ys\n\n\nmutual\n def evens : List Nat \u2192 List Nat\n | [] => []\n | x::xs => x::(odds xs)\n--\n def odds : List Nat \u2192 List Nat\n | [] => []\n | _x::xs => evens xs\nend\n\n\nlemma len_evens_le : (evens xs).length \u2264 xs.length := by\n generalize hxsl: xs.length = xsl\n induction xsl using Nat.strong_induction_on generalizing xs with\n | h n ih =>\n cases xs with\n | nil => unfold evens; simp;\n | cons head1 tail1 =>\n unfold evens;\n cases tail1 with\n | nil => unfold odds; rw[\u2190 hxsl];\n | cons head2 tail2 =>\n unfold odds;\n rw [List.length_cons, List.length_cons] at hxsl;\n rw [\u2190 hxsl, List.length_cons, Nat.succ_eq_add_one _, Nat.succ_eq_add_one _];\n simp;\n have h': List.length tail2 < n := by rw [\u2190 hxsl, Nat.succ_eq_add_one _]; linarith;\n exact Nat.le.step (ih (List.length tail2) h' rfl);\n\n\nlemma len_odds_le : (odds xs).length \u2264 xs.length := by\n generalize hxsl: xs.length = xsl\n induction xsl using Nat.strong_induction_on generalizing xs with\n | h n ih =>\n cases xs with\n | nil => unfold odds; simp;\n | cons head1 tail1 =>\n unfold odds;\n cases tail1 with\n | nil => unfold evens; simp;\n | cons head2 tail2 =>\n unfold evens;\n rw [List.length_cons, List.length_cons] at hxsl;\n rw [\u2190 hxsl, List.length_cons, Nat.succ_eq_add_one _, Nat.succ_eq_add_one _];\n simp;\n have h': List.length tail2 < n := by rw [\u2190 hxsl, Nat.succ_eq_add_one _]; linarith;\n exact Nat.le.step (ih (List.length tail2) h' rfl);\n\n\ndef sort2 (a b: Nat): List Nat := if a \u2264 b then [a,b] else [b, a]\n\n\ndef pairs : List Nat \u2192 List Nat \u2192 List Nat\n| [], ys => ys\n| xs, [] => xs\n| x::xs, y::ys => (sort2 x y) ++ (pairs xs ys)\n\n\ndef stitch : List Nat \u2192 List Nat \u2192 List Nat\n| [], ys => ys\n| x::xs, ys => x::(pairs xs ys)\n\n\nlemma bmerge_term (a b: Nat) (as bs: List Nat) (hlen: \u00ac(List.length as == 0 && List.length bs == 0) = true): List.length (evens (a :: as)) + List.length (evens (b :: bs)) < Nat.succ (List.length as) + Nat.succ (List.length bs) := by\n unfold evens;\n simp at hlen;\n rw [List.length_cons, List.length_cons, Nat.succ_eq_add_one _, Nat.succ_eq_add_one _, Nat.succ_eq_add_one _, Nat.succ_eq_add_one _];\n ring_nf;\n cases as with\n | nil => cases bs with\n | nil => simp at hlen;\n | cons bhead btail => unfold odds; simp; linarith [@len_evens_le btail];\n | cons ahead atail =>\n rw [add_comm, add_comm (2 + List.length (ahead :: atail)) (List.length bs)]\n refine add_lt_add_of_le_of_lt (@len_odds_le bs) ?h; unfold odds; simp; linarith [@len_evens_le atail];\n\n\nlemma bmerge_term2 (x y: Nat) (xs ys: List Nat) : List.length (odds (x :: xs)) + List.length (odds (y :: ys)) < Nat.succ (List.length xs) + Nat.succ (List.length ys) := by\n unfold odds;\n exact add_lt_add_of_lt_of_lt (Nat.lt_succ_of_le (@len_evens_le xs)) (Nat.lt_succ_of_le (@len_evens_le ys))\n\n\ndef bmerge : List Nat \u2192 List Nat \u2192 List Nat\n| [], bs => bs -- I changed this from TIP. I don't believe this case is ever hit, though.\n| as, [] => as\n| x::xs, y::ys =>\n if hlen: xs.length == 0 && ys.length == 0 then sort2 x y else\n have _h := bmerge_term x y xs ys hlen;\n have _h2 := bmerge_term2 x y xs ys;\n stitch (bmerge (evens (x::xs)) (evens (y::ys))) (bmerge (odds (x::xs)) (odds (y::ys)))\ntermination_by xs ys => xs.length + ys.length\n\n\nlemma bsort_term1 (x y: Nat) (xs: List Nat): List.length (evens (x :: y :: xs)) < Nat.succ (Nat.succ (List.length xs)) := by\n unfold evens; unfold odds;\n rw [List.length_cons, Nat.succ_eq_add_one _, Nat.succ_eq_add_one _];\n simp;\n exact Nat.lt_succ_of_le (@len_evens_le xs);\n\n\nlemma bsort_term2 (x y: Nat) (xs: List Nat): List.length (odds (x :: y :: xs)) < Nat.succ (Nat.succ (List.length xs)) := by\n unfold odds; unfold evens;\n rw [List.length_cons, Nat.succ_eq_add_one _, Nat.succ_eq_add_one _];\n simp;\n exact Nat.lt_succ_of_le (@len_odds_le xs);\n\n\ndef bsort : List Nat \u2192 List Nat\n| [] => []\n| [x] => [x]\n| x::y::xs =>\n have _h := bsort_term1 x y xs\n have _h2 := bsort_term2 x y xs\n bmerge (bsort (evens (x::y::xs))) (bsort (odds (x::y::xs)))\ntermination_by xs => xs.length\n", "proof_state": "x : \u2115\nxs : List \u2115\n\u22a2 (count x (bsort xs) == count x xs) = true", "file_locs": [["LeanSrc/LeanSrc/Sorts.lean", 531]]}
120
+ {"full_name": "prop_BSortPermutes", "prop_defn": "theorem prop_BSortPermutes (xs: List Nat) : isPermutation (bsort xs) xs == true:= by sorry", "prop_loc": "LeanSrc/LeanSrc/Sorts.lean:532", "score": 5, "deps": "import Mathlib\n\ndef deleteFirst [DecidableEq \u03b1]: \u03b1 \u2192 List \u03b1 \u2192 List \u03b1\n | _, [] => []\n | n, x::xs => if n == x then xs else x::(deleteFirst n xs)\n\n\ndef isPermutation [DecidableEq \u03b1] : List \u03b1 \u2192 List \u03b1 \u2192 Bool\n| [], ys => (ys == [])\n| x::xs, ys => x \u2208 ys && (isPermutation xs (deleteFirst x ys))\n\n\nmutual\n def evens : List Nat \u2192 List Nat\n | [] => []\n | x::xs => x::(odds xs)\n--\n def odds : List Nat \u2192 List Nat\n | [] => []\n | _x::xs => evens xs\nend\n\n\nlemma len_evens_le : (evens xs).length \u2264 xs.length := by\n generalize hxsl: xs.length = xsl\n induction xsl using Nat.strong_induction_on generalizing xs with\n | h n ih =>\n cases xs with\n | nil => unfold evens; simp;\n | cons head1 tail1 =>\n unfold evens;\n cases tail1 with\n | nil => unfold odds; rw[\u2190 hxsl];\n | cons head2 tail2 =>\n unfold odds;\n rw [List.length_cons, List.length_cons] at hxsl;\n rw [\u2190 hxsl, List.length_cons, Nat.succ_eq_add_one _, Nat.succ_eq_add_one _];\n simp;\n have h': List.length tail2 < n := by rw [\u2190 hxsl, Nat.succ_eq_add_one _]; linarith;\n exact Nat.le.step (ih (List.length tail2) h' rfl);\n\n\nlemma len_odds_le : (odds xs).length \u2264 xs.length := by\n generalize hxsl: xs.length = xsl\n induction xsl using Nat.strong_induction_on generalizing xs with\n | h n ih =>\n cases xs with\n | nil => unfold odds; simp;\n | cons head1 tail1 =>\n unfold odds;\n cases tail1 with\n | nil => unfold evens; simp;\n | cons head2 tail2 =>\n unfold evens;\n rw [List.length_cons, List.length_cons] at hxsl;\n rw [\u2190 hxsl, List.length_cons, Nat.succ_eq_add_one _, Nat.succ_eq_add_one _];\n simp;\n have h': List.length tail2 < n := by rw [\u2190 hxsl, Nat.succ_eq_add_one _]; linarith;\n exact Nat.le.step (ih (List.length tail2) h' rfl);\n\n\ndef sort2 (a b: Nat): List Nat := if a \u2264 b then [a,b] else [b, a]\n\n\ndef pairs : List Nat \u2192 List Nat \u2192 List Nat\n| [], ys => ys\n| xs, [] => xs\n| x::xs, y::ys => (sort2 x y) ++ (pairs xs ys)\n\n\ndef stitch : List Nat \u2192 List Nat \u2192 List Nat\n| [], ys => ys\n| x::xs, ys => x::(pairs xs ys)\n\n\nlemma bmerge_term (a b: Nat) (as bs: List Nat) (hlen: \u00ac(List.length as == 0 && List.length bs == 0) = true): List.length (evens (a :: as)) + List.length (evens (b :: bs)) < Nat.succ (List.length as) + Nat.succ (List.length bs) := by\n unfold evens;\n simp at hlen;\n rw [List.length_cons, List.length_cons, Nat.succ_eq_add_one _, Nat.succ_eq_add_one _, Nat.succ_eq_add_one _, Nat.succ_eq_add_one _];\n ring_nf;\n cases as with\n | nil => cases bs with\n | nil => simp at hlen;\n | cons bhead btail => unfold odds; simp; linarith [@len_evens_le btail];\n | cons ahead atail =>\n rw [add_comm, add_comm (2 + List.length (ahead :: atail)) (List.length bs)]\n refine add_lt_add_of_le_of_lt (@len_odds_le bs) ?h; unfold odds; simp; linarith [@len_evens_le atail];\n\n\nlemma bmerge_term2 (x y: Nat) (xs ys: List Nat) : List.length (odds (x :: xs)) + List.length (odds (y :: ys)) < Nat.succ (List.length xs) + Nat.succ (List.length ys) := by\n unfold odds;\n exact add_lt_add_of_lt_of_lt (Nat.lt_succ_of_le (@len_evens_le xs)) (Nat.lt_succ_of_le (@len_evens_le ys))\n\n\ndef bmerge : List Nat \u2192 List Nat \u2192 List Nat\n| [], bs => bs -- I changed this from TIP. I don't believe this case is ever hit, though.\n| as, [] => as\n| x::xs, y::ys =>\n if hlen: xs.length == 0 && ys.length == 0 then sort2 x y else\n have _h := bmerge_term x y xs ys hlen;\n have _h2 := bmerge_term2 x y xs ys;\n stitch (bmerge (evens (x::xs)) (evens (y::ys))) (bmerge (odds (x::xs)) (odds (y::ys)))\ntermination_by xs ys => xs.length + ys.length\n\n\nlemma bsort_term1 (x y: Nat) (xs: List Nat): List.length (evens (x :: y :: xs)) < Nat.succ (Nat.succ (List.length xs)) := by\n unfold evens; unfold odds;\n rw [List.length_cons, Nat.succ_eq_add_one _, Nat.succ_eq_add_one _];\n simp;\n exact Nat.lt_succ_of_le (@len_evens_le xs);\n\n\nlemma bsort_term2 (x y: Nat) (xs: List Nat): List.length (odds (x :: y :: xs)) < Nat.succ (Nat.succ (List.length xs)) := by\n unfold odds; unfold evens;\n rw [List.length_cons, Nat.succ_eq_add_one _, Nat.succ_eq_add_one _];\n simp;\n exact Nat.lt_succ_of_le (@len_odds_le xs);\n\n\ndef bsort : List Nat \u2192 List Nat\n| [] => []\n| [x] => [x]\n| x::y::xs =>\n have _h := bsort_term1 x y xs\n have _h2 := bsort_term2 x y xs\n bmerge (bsort (evens (x::y::xs))) (bsort (odds (x::y::xs)))\ntermination_by xs => xs.length\n", "proof_state": "xs : List \u2115\n\u22a2 (isPermutation (bsort xs) xs == true) = true", "file_locs": [["LeanSrc/LeanSrc/Sorts.lean", 532]]}
121
+ {"full_name": "prop_BSortIsSort", "prop_defn": "theorem prop_BSortIsSort (xs: List Nat) : bsort xs == isort xs:= by sorry", "prop_loc": "LeanSrc/LeanSrc/Sorts.lean:533", "score": 5, "deps": "import Mathlib\n\ndef insert' : Nat \u2192 List Nat \u2192 List Nat\n| x, [] => [x]\n| x, y::xs => if x <= y then x::y::xs else y::(insert x xs)\n\n\ndef isort: List Nat \u2192 List Nat\n| [] => []\n| x::xs => insert' x (isort xs)\n\n\nmutual\n def evens : List Nat \u2192 List Nat\n | [] => []\n | x::xs => x::(odds xs)\n--\n def odds : List Nat \u2192 List Nat\n | [] => []\n | _x::xs => evens xs\nend\n\n\nlemma len_evens_le : (evens xs).length \u2264 xs.length := by\n generalize hxsl: xs.length = xsl\n induction xsl using Nat.strong_induction_on generalizing xs with\n | h n ih =>\n cases xs with\n | nil => unfold evens; simp;\n | cons head1 tail1 =>\n unfold evens;\n cases tail1 with\n | nil => unfold odds; rw[\u2190 hxsl];\n | cons head2 tail2 =>\n unfold odds;\n rw [List.length_cons, List.length_cons] at hxsl;\n rw [\u2190 hxsl, List.length_cons, Nat.succ_eq_add_one _, Nat.succ_eq_add_one _];\n simp;\n have h': List.length tail2 < n := by rw [\u2190 hxsl, Nat.succ_eq_add_one _]; linarith;\n exact Nat.le.step (ih (List.length tail2) h' rfl);\n\n\nlemma len_odds_le : (odds xs).length \u2264 xs.length := by\n generalize hxsl: xs.length = xsl\n induction xsl using Nat.strong_induction_on generalizing xs with\n | h n ih =>\n cases xs with\n | nil => unfold odds; simp;\n | cons head1 tail1 =>\n unfold odds;\n cases tail1 with\n | nil => unfold evens; simp;\n | cons head2 tail2 =>\n unfold evens;\n rw [List.length_cons, List.length_cons] at hxsl;\n rw [\u2190 hxsl, List.length_cons, Nat.succ_eq_add_one _, Nat.succ_eq_add_one _];\n simp;\n have h': List.length tail2 < n := by rw [\u2190 hxsl, Nat.succ_eq_add_one _]; linarith;\n exact Nat.le.step (ih (List.length tail2) h' rfl);\n\n\ndef sort2 (a b: Nat): List Nat := if a \u2264 b then [a,b] else [b, a]\n\n\ndef pairs : List Nat \u2192 List Nat \u2192 List Nat\n| [], ys => ys\n| xs, [] => xs\n| x::xs, y::ys => (sort2 x y) ++ (pairs xs ys)\n\n\ndef stitch : List Nat \u2192 List Nat \u2192 List Nat\n| [], ys => ys\n| x::xs, ys => x::(pairs xs ys)\n\n\nlemma bmerge_term (a b: Nat) (as bs: List Nat) (hlen: \u00ac(List.length as == 0 && List.length bs == 0) = true): List.length (evens (a :: as)) + List.length (evens (b :: bs)) < Nat.succ (List.length as) + Nat.succ (List.length bs) := by\n unfold evens;\n simp at hlen;\n rw [List.length_cons, List.length_cons, Nat.succ_eq_add_one _, Nat.succ_eq_add_one _, Nat.succ_eq_add_one _, Nat.succ_eq_add_one _];\n ring_nf;\n cases as with\n | nil => cases bs with\n | nil => simp at hlen;\n | cons bhead btail => unfold odds; simp; linarith [@len_evens_le btail];\n | cons ahead atail =>\n rw [add_comm, add_comm (2 + List.length (ahead :: atail)) (List.length bs)]\n refine add_lt_add_of_le_of_lt (@len_odds_le bs) ?h; unfold odds; simp; linarith [@len_evens_le atail];\n\n\nlemma bmerge_term2 (x y: Nat) (xs ys: List Nat) : List.length (odds (x :: xs)) + List.length (odds (y :: ys)) < Nat.succ (List.length xs) + Nat.succ (List.length ys) := by\n unfold odds;\n exact add_lt_add_of_lt_of_lt (Nat.lt_succ_of_le (@len_evens_le xs)) (Nat.lt_succ_of_le (@len_evens_le ys))\n\n\ndef bmerge : List Nat \u2192 List Nat \u2192 List Nat\n| [], bs => bs -- I changed this from TIP. I don't believe this case is ever hit, though.\n| as, [] => as\n| x::xs, y::ys =>\n if hlen: xs.length == 0 && ys.length == 0 then sort2 x y else\n have _h := bmerge_term x y xs ys hlen;\n have _h2 := bmerge_term2 x y xs ys;\n stitch (bmerge (evens (x::xs)) (evens (y::ys))) (bmerge (odds (x::xs)) (odds (y::ys)))\ntermination_by xs ys => xs.length + ys.length\n\n\nlemma bsort_term1 (x y: Nat) (xs: List Nat): List.length (evens (x :: y :: xs)) < Nat.succ (Nat.succ (List.length xs)) := by\n unfold evens; unfold odds;\n rw [List.length_cons, Nat.succ_eq_add_one _, Nat.succ_eq_add_one _];\n simp;\n exact Nat.lt_succ_of_le (@len_evens_le xs);\n\n\nlemma bsort_term2 (x y: Nat) (xs: List Nat): List.length (odds (x :: y :: xs)) < Nat.succ (Nat.succ (List.length xs)) := by\n unfold odds; unfold evens;\n rw [List.length_cons, Nat.succ_eq_add_one _, Nat.succ_eq_add_one _];\n simp;\n exact Nat.lt_succ_of_le (@len_odds_le xs);\n\n\ndef bsort : List Nat \u2192 List Nat\n| [] => []\n| [x] => [x]\n| x::y::xs =>\n have _h := bsort_term1 x y xs\n have _h2 := bsort_term2 x y xs\n bmerge (bsort (evens (x::y::xs))) (bsort (odds (x::y::xs)))\ntermination_by xs => xs.length\n", "proof_state": "xs : List \u2115\n\u22a2 (bsort xs == isort xs) = true", "file_locs": [["LeanSrc/LeanSrc/Sorts.lean", 533]]}
122
  {"full_name": "prop_QSortSorts", "prop_defn": "theorem prop_QSortSorts (xs: List Nat) : ordered (qsort xs) == true:= by sorry", "prop_loc": "LeanSrc/LeanSrc/Sorts.lean:570", "score": 5, "deps": "import Mathlib\n\ndef ordered : List Nat -> Bool\n| [] => True\n| [_x] => True\n| x::y::xs => x <= y && ordered (y::xs)\n\n\ndef filter : List Nat \u2192 (Nat \u2192 Bool) \u2192 List Nat\n| [], _f => []\n| x::xs, f => if f x then x::(filter xs f) else (filter xs f)\n\n\nlemma filter_len_le {f: Nat \u2192 Bool} {xs: List Nat}: (filter xs f).length <= xs.length := by\n generalize hxsl: xs.length = xsl\n induction xsl generalizing xs with\n | zero => rw [List.length_eq_zero] at hxsl; rw [hxsl]; unfold filter; simp;\n | succ n ih =>\n cases xs with\n | nil => unfold filter; simp;\n | cons head tail =>\n rw [List.length_cons] at hxsl; simp at hxsl;\n unfold filter; split_ifs with h1;\n case pos;\n rw [List.length_cons];\n exact Nat.pred_le_iff.mp (ih hxsl)\n case neg;\n exact Nat.le.step (ih hxsl)\n\n\nlemma qsort_term (x:Nat) (xs: List Nat) : List.length (filter xs fun y => decide (y \u2264 x)) < Nat.succ (List.length xs) := by\n exact Nat.lt_succ_of_le (filter_len_le);\n\n\nlemma qsort_term2 (x:Nat) (xs: List Nat) : List.length (filter xs fun y => decide (y > x)) < Nat.succ (List.length xs) := by\n exact Nat.lt_succ_of_le (filter_len_le);\n\n\ndef qsort : List Nat \u2192 List Nat\n| [] => []\n| x::xs =>\n have _h:= qsort_term x xs\n have _h2:= qsort_term2 x xs\n (qsort (filter xs (fun y => y <= x))) ++ [x] ++ (qsort (filter xs (fun y => y > x)))\ntermination_by xs => xs.length\n", "proof_state": "xs : List \u2115\n\u22a2 (ordered (qsort xs) == true) = true", "file_locs": [["LeanSrc/LeanSrc/Sorts.lean", 570]]}
123
  {"full_name": "prop_QSortCount", "prop_defn": "theorem prop_QSortCount (x: Nat) (xs: List Nat) : count x (qsort xs) == count x xs:= by sorry", "prop_loc": "LeanSrc/LeanSrc/Sorts.lean:571", "score": 5, "deps": "import Mathlib\n\ndef count [DecidableEq \u03b1] : \u03b1 \u2192 List \u03b1 \u2192 Nat\n| _x, [] => 0\n| x, y::ys => if x == y then 1 + (count x ys) else count x ys\n\n\ndef filter : List Nat \u2192 (Nat \u2192 Bool) \u2192 List Nat\n| [], _f => []\n| x::xs, f => if f x then x::(filter xs f) else (filter xs f)\n\n\nlemma filter_len_le {f: Nat \u2192 Bool} {xs: List Nat}: (filter xs f).length <= xs.length := by\n generalize hxsl: xs.length = xsl\n induction xsl generalizing xs with\n | zero => rw [List.length_eq_zero] at hxsl; rw [hxsl]; unfold filter; simp;\n | succ n ih =>\n cases xs with\n | nil => unfold filter; simp;\n | cons head tail =>\n rw [List.length_cons] at hxsl; simp at hxsl;\n unfold filter; split_ifs with h1;\n case pos;\n rw [List.length_cons];\n exact Nat.pred_le_iff.mp (ih hxsl)\n case neg;\n exact Nat.le.step (ih hxsl)\n\n\nlemma qsort_term (x:Nat) (xs: List Nat) : List.length (filter xs fun y => decide (y \u2264 x)) < Nat.succ (List.length xs) := by\n exact Nat.lt_succ_of_le (filter_len_le);\n\n\nlemma qsort_term2 (x:Nat) (xs: List Nat) : List.length (filter xs fun y => decide (y > x)) < Nat.succ (List.length xs) := by\n exact Nat.lt_succ_of_le (filter_len_le);\n\n\ndef qsort : List Nat \u2192 List Nat\n| [] => []\n| x::xs =>\n have _h:= qsort_term x xs\n have _h2:= qsort_term2 x xs\n (qsort (filter xs (fun y => y <= x))) ++ [x] ++ (qsort (filter xs (fun y => y > x)))\ntermination_by xs => xs.length\n", "proof_state": "x : \u2115\nxs : List \u2115\n\u22a2 (count x (qsort xs) == count x xs) = true", "file_locs": [["LeanSrc/LeanSrc/Sorts.lean", 571]]}
124
  {"full_name": "prop_QSortPermutes", "prop_defn": "theorem prop_QSortPermutes (xs: List Nat) : isPermutation (qsort xs) xs == true:= by sorry", "prop_loc": "LeanSrc/LeanSrc/Sorts.lean:572", "score": 5, "deps": "import Mathlib\n\ndef deleteFirst [DecidableEq \u03b1]: \u03b1 \u2192 List \u03b1 \u2192 List \u03b1\n | _, [] => []\n | n, x::xs => if n == x then xs else x::(deleteFirst n xs)\n\n\ndef isPermutation [DecidableEq \u03b1] : List \u03b1 \u2192 List \u03b1 \u2192 Bool\n| [], ys => (ys == [])\n| x::xs, ys => x \u2208 ys && (isPermutation xs (deleteFirst x ys))\n\n\ndef filter : List Nat \u2192 (Nat \u2192 Bool) \u2192 List Nat\n| [], _f => []\n| x::xs, f => if f x then x::(filter xs f) else (filter xs f)\n\n\nlemma filter_len_le {f: Nat \u2192 Bool} {xs: List Nat}: (filter xs f).length <= xs.length := by\n generalize hxsl: xs.length = xsl\n induction xsl generalizing xs with\n | zero => rw [List.length_eq_zero] at hxsl; rw [hxsl]; unfold filter; simp;\n | succ n ih =>\n cases xs with\n | nil => unfold filter; simp;\n | cons head tail =>\n rw [List.length_cons] at hxsl; simp at hxsl;\n unfold filter; split_ifs with h1;\n case pos;\n rw [List.length_cons];\n exact Nat.pred_le_iff.mp (ih hxsl)\n case neg;\n exact Nat.le.step (ih hxsl)\n\n\nlemma qsort_term (x:Nat) (xs: List Nat) : List.length (filter xs fun y => decide (y \u2264 x)) < Nat.succ (List.length xs) := by\n exact Nat.lt_succ_of_le (filter_len_le);\n\n\nlemma qsort_term2 (x:Nat) (xs: List Nat) : List.length (filter xs fun y => decide (y > x)) < Nat.succ (List.length xs) := by\n exact Nat.lt_succ_of_le (filter_len_le);\n\n\ndef qsort : List Nat \u2192 List Nat\n| [] => []\n| x::xs =>\n have _h:= qsort_term x xs\n have _h2:= qsort_term2 x xs\n (qsort (filter xs (fun y => y <= x))) ++ [x] ++ (qsort (filter xs (fun y => y > x)))\ntermination_by xs => xs.length\n", "proof_state": "xs : List \u2115\n\u22a2 (isPermutation (qsort xs) xs == true) = true", "file_locs": [["LeanSrc/LeanSrc/Sorts.lean", 572]]}
 
154
  {"full_name": "len_pairwise", "prop_defn": "theorem len_pairwise (xs: List (List Nat)): 2 * (pairwise xs).length = (if (Odd xs.length) then xs.length + 1 else xs.length) := by sorry", "prop_loc": "LeanSrc/LeanSrc/Sorts.lean:241", "score": 5, "deps": "import Mathlib\n\ndef lmerge : List Nat \u2192 List Nat \u2192 List Nat\n| [], ys => ys\n| xs, [] => xs\n| x::xs, y::ys => if x <= y then\n x::(lmerge xs (y::ys))\n else\n y::(lmerge (x::xs) ys)\n\n\ndef pairwise : List (List Nat) \u2192 List (List Nat)\n| xs::ys::xss => lmerge xs ys :: pairwise xss\n| xss => xss\n", "proof_state": "xs : List (List \u2115)\n\u22a2 2 * (pairwise xs).length = if Odd xs.length then xs.length + 1 else xs.length", "file_locs": [["LeanSrc/LeanSrc/Sorts.lean", 286]]}
155
  {"full_name": "merge_term", "prop_defn": "theorem merge_term : (pairwise (xs::ys::xss)).length < (xs::ys::xss).length := by sorry", "prop_loc": "LeanSrc/LeanSrc/Sorts.lean:288", "score": 5, "deps": "import Mathlib\n\ndef lmerge : List Nat \u2192 List Nat \u2192 List Nat\n| [], ys => ys\n| xs, [] => xs\n| x::xs, y::ys => if x <= y then\n x::(lmerge xs (y::ys))\n else\n y::(lmerge (x::xs) ys)\n\n\ndef pairwise : List (List Nat) \u2192 List (List Nat)\n| xs::ys::xss => lmerge xs ys :: pairwise xss\n| xss => xss\n", "proof_state": "xs ys : List \u2115\nxss : List (List \u2115)\n\u22a2 (pairwise (xs :: ys :: xss)).length < (xs :: ys :: xss).length", "file_locs": [["LeanSrc/LeanSrc/Sorts.lean", 299]]}
156
  {"full_name": "half_lt", "prop_defn": "theorem half_lt: half x \u2264 x := by sorry", "prop_loc": "LeanSrc/LeanSrc/Sorts.lean:382", "score": 5, "deps": "import Mathlib\n\ndef half : Nat \u2192 Nat\n| 0 => 0\n| 1 => 0\n| x + 2 => 1 + (half x)\n", "proof_state": "x : \u2115\n\u22a2 half x \u2264 x", "file_locs": [["LeanSrc/LeanSrc/Sorts.lean", 395]]}
157
+ {"full_name": "len_evens_le", "prop_defn": "theorem len_evens_le {xs: List Nat}: (evens xs).length \u2264 xs.length := by sorry", "prop_loc": "LeanSrc/LeanSrc/Sorts.lean:435", "score": 5, "deps": "import Mathlib\n\nmutual\n def evens : List Nat \u2192 List Nat\n | [] => []\n | x::xs => x::(odds xs)\n--\n def odds : List Nat \u2192 List Nat\n | [] => []\n | _x::xs => evens xs\nend\n", "proof_state": "xs : List \u2115\n\u22a2 (evens xs).length \u2264 xs.length", "file_locs": [["LeanSrc/LeanSrc/Sorts.lean", 451]]}
158
+ {"full_name": "len_odds_le", "prop_defn": "theorem len_odds_le {xs: List Nat}: (odds xs).length \u2264 xs.length := by sorry", "prop_loc": "LeanSrc/LeanSrc/Sorts.lean:453", "score": 5, "deps": "import Mathlib\n\nmutual\n def evens : List Nat \u2192 List Nat\n | [] => []\n | x::xs => x::(odds xs)\n--\n def odds : List Nat \u2192 List Nat\n | [] => []\n | _x::xs => evens xs\nend\n", "proof_state": "xs : List \u2115\n\u22a2 (odds xs).length \u2264 xs.length", "file_locs": [["LeanSrc/LeanSrc/Sorts.lean", 469]]}
159
+ {"full_name": "bmerge_term", "prop_defn": "theorem bmerge_term (a b: Nat) (as bs: List Nat) (hlen: \u00ac(List.length as == 0 && List.length bs == 0) = true): List.length (evens (a :: as)) + List.length (evens (b :: bs)) < Nat.succ (List.length as) + Nat.succ (List.length bs) := by sorry", "prop_loc": "LeanSrc/LeanSrc/Sorts.lean:482", "score": 5, "deps": "import Mathlib\n\nmutual\n def evens : List Nat \u2192 List Nat\n | [] => []\n | x::xs => x::(odds xs)\n--\n def odds : List Nat \u2192 List Nat\n | [] => []\n | _x::xs => evens xs\nend\n", "proof_state": "a b : \u2115\nas bs : List \u2115\nhlen : \u00ac(as.length == 0 && bs.length == 0) = true\n\u22a2 (evens (a :: as)).length + (evens (b :: bs)).length < as.length.succ + bs.length.succ", "file_locs": [["LeanSrc/LeanSrc/Sorts.lean", 493]]}
160
+ {"full_name": "bmerge_term2", "prop_defn": "theorem bmerge_term2 (x y: Nat) (xs ys: List Nat) : List.length (odds (x :: xs)) + List.length (odds (y :: ys)) < Nat.succ (List.length xs) + Nat.succ (List.length ys) := by sorry", "prop_loc": "LeanSrc/LeanSrc/Sorts.lean:495", "score": 5, "deps": "import Mathlib\n\nmutual\n def evens : List Nat \u2192 List Nat\n | [] => []\n | x::xs => x::(odds xs)\n--\n def odds : List Nat \u2192 List Nat\n | [] => []\n | _x::xs => evens xs\nend\n", "proof_state": "x y : \u2115\nxs ys : List \u2115\n\u22a2 (odds (x :: xs)).length + (odds (y :: ys)).length < xs.length.succ + ys.length.succ", "file_locs": [["LeanSrc/LeanSrc/Sorts.lean", 497]]}
161
+ {"full_name": "bsort_term1", "prop_defn": "theorem bsort_term1 (x y: Nat) (xs: List Nat): List.length (evens (x :: y :: xs)) < Nat.succ (Nat.succ (List.length xs)) := by sorry", "prop_loc": "LeanSrc/LeanSrc/Sorts.lean:509", "score": 5, "deps": "import Mathlib\n\nmutual\n def evens : List Nat \u2192 List Nat\n | [] => []\n | x::xs => x::(odds xs)\n--\n def odds : List Nat \u2192 List Nat\n | [] => []\n | _x::xs => evens xs\nend\n", "proof_state": "x y : \u2115\nxs : List \u2115\n\u22a2 (evens (x :: y :: xs)).length < xs.length.succ.succ", "file_locs": [["LeanSrc/LeanSrc/Sorts.lean", 513]]}
162
+ {"full_name": "bsort_term2", "prop_defn": "theorem bsort_term2 (x y: Nat) (xs: List Nat): List.length (odds (x :: y :: xs)) < Nat.succ (Nat.succ (List.length xs)) := by sorry", "prop_loc": "LeanSrc/LeanSrc/Sorts.lean:515", "score": 5, "deps": "import Mathlib\n\nmutual\n def evens : List Nat \u2192 List Nat\n | [] => []\n | x::xs => x::(odds xs)\n--\n def odds : List Nat \u2192 List Nat\n | [] => []\n | _x::xs => evens xs\nend\n", "proof_state": "x y : \u2115\nxs : List \u2115\n\u22a2 (odds (x :: y :: xs)).length < xs.length.succ.succ", "file_locs": [["LeanSrc/LeanSrc/Sorts.lean", 519]]}
163
  {"full_name": "filter_len_le", "prop_defn": "theorem filter_len_le {f: Nat \u2192 Bool} {xs: List Nat}: (filter xs f).length <= xs.length := by sorry", "prop_loc": "LeanSrc/LeanSrc/Sorts.lean:539", "score": 5, "deps": "import Mathlib\n\ndef filter : List Nat \u2192 (Nat \u2192 Bool) \u2192 List Nat\n| [], _f => []\n| x::xs, f => if f x then x::(filter xs f) else (filter xs f)\n", "proof_state": "f : \u2115 \u2192 Bool\nxs : List \u2115\n\u22a2 (filter xs f).length \u2264 xs.length", "file_locs": [["LeanSrc/LeanSrc/Sorts.lean", 553]]}
164
  {"full_name": "qsort_term", "prop_defn": "theorem qsort_term (x:Nat) (xs: List Nat) : List.length (filter xs fun y => decide (y \u2264 x)) < Nat.succ (List.length xs) := by sorry", "prop_loc": "LeanSrc/LeanSrc/Sorts.lean:556", "score": 5, "deps": "import Mathlib\n\ndef filter : List Nat \u2192 (Nat \u2192 Bool) \u2192 List Nat\n| [], _f => []\n| x::xs, f => if f x then x::(filter xs f) else (filter xs f)\n", "proof_state": "x : \u2115\nxs : List \u2115\n\u22a2 (filter xs fun y => decide (y \u2264 x)).length < xs.length.succ", "file_locs": [["LeanSrc/LeanSrc/Sorts.lean", 557]]}
165
  {"full_name": "qsort_term2", "prop_defn": "theorem qsort_term2 (x:Nat) (xs: List Nat) : List.length (filter xs fun y => decide (y > x)) < Nat.succ (List.length xs) := by sorry", "prop_loc": "LeanSrc/LeanSrc/Sorts.lean:559", "score": 5, "deps": "import Mathlib\n\ndef filter : List Nat \u2192 (Nat \u2192 Bool) \u2192 List Nat\n| [], _f => []\n| x::xs, f => if f x then x::(filter xs f) else (filter xs f)\n", "proof_state": "x : \u2115\nxs : List \u2115\n\u22a2 (filter xs fun y => decide (y > x)).length < xs.length.succ", "file_locs": [["LeanSrc/LeanSrc/Sorts.lean", 560]]}
utils.py CHANGED
@@ -2,8 +2,11 @@ import pexpect
2
  import json_stream
3
  import json
4
 
 
 
 
5
  LEAN_REPL_CMD = 'lake env ../repl/.lake/build/bin/repl'
6
- SHELL_CMD = '/bin/sh' #zsh doesn't play well with non-canonical input: https://github.com/samapriya/geeup/issues/41
7
  BASE_PATH = 'LeanSrc/LeanSrc'
8
 
9
  def make_lean_repl(repl_type='zsh'):
@@ -15,8 +18,9 @@ def make_lean_repl(repl_type='zsh'):
15
  lean_repl = pexpect.spawn(SHELL_CMD, cwd='LeanSrc', maxread=5000, timeout=20, echo=False)
16
  lean_repl.sendline('stty -icanon') # this is the magic that allows a bunch of chars to be sent
17
  lean_repl.sendline(LEAN_REPL_CMD)
18
- print(lean_repl.readline())
19
- print(lean_repl.readline())
 
20
  elif repl_type == 'zsh':
21
  lean_repl = pexpect.spawn(LEAN_REPL_CMD,cwd='LeanSrc', maxread=1025, timeout=5)
22
 
@@ -73,7 +77,7 @@ def load_mult_json(jsons):
73
 
74
  #ps_out = json.loads(output)
75
  assert ps_out is not None, 'parsing failed: ' + jsons.decode()
76
- print('parsed output:', ps_out)
77
  return ps_out
78
 
79
  def make_repl_command(def_str, env=None):
@@ -127,28 +131,34 @@ def send_command_zsh(repl, command, env=None, timeout=5, first=False):
127
 
128
 
129
  def send_command_icanon(repl, command, env=None, timeout=20, first=False):
130
- print('sending command:', command)
131
  rpl_comm = make_repl_command(command, env=env)
132
 
133
- repl.sendline(rpl_comm+'\n')
134
- if first:
135
- repl.expect_exact('~>')
136
- first = False
137
- else:
138
- try:
139
- repl.expect_exact('\r\n\r\n')
140
- except pexpect.exceptions.TIMEOUT as e:
141
- print('did not find newlines')
 
 
 
142
  try:
143
- _index = repl.expect('env": \d+\}', timeout=timeout)
144
  command_sent = True
145
  except pexpect.exceptions.TIMEOUT as e:
 
146
  print('did not find env in output')
147
  return None, None
148
 
149
  env_str = repl.match.group().decode()
150
  new_env = int(env_str.split(':')[1].strip()[:-1])
151
  output = repl.before + repl.match.group()
 
 
152
  return load_mult_json(output), new_env
153
 
154
  def make_repl_tactic(tac, proofState):
@@ -165,7 +175,7 @@ def send_tactic(repl, tactic, proofState):
165
 
166
  # the icanon mode sometimes sends a single dict with just one field: 'message'.
167
  # when we get that with a lean error, the tactic failed so we return None
168
- _index = repl.expect('(]})|(\"}\r\n\r\n)', timeout=10)
169
 
170
 
171
  #ps_str = repl.match.group().decode()
@@ -174,7 +184,7 @@ def send_tactic(repl, tactic, proofState):
174
  #if verbose:
175
  #print('js outp 2', output)
176
  ps_out = load_mult_json(output)
177
- print('ps out', ps_out)
178
  if 'proofState' not in ps_out:
179
  return None, None
180
  return ps_out, ps_out['proofState']
@@ -183,4 +193,4 @@ def send_tactic(repl, tactic, proofState):
183
  # return None, None
184
 
185
  def get_errs(outp):
186
- return [m for m in outp.get('messages', []) if m.get('severity', 'error') == 'error']
 
2
  import json_stream
3
  import json
4
 
5
+ MACOS = 'MacOS'
6
+ LINUX = 'Linux'
7
+ OS = LINUX #MACOS
8
  LEAN_REPL_CMD = 'lake env ../repl/.lake/build/bin/repl'
9
+ SHELL_CMD = '/bin/sh' if OS == MACOS else '/bin/bash' #zsh doesn't play well with non-canonical input: https://github.com/samapriya/geeup/issues/41
10
  BASE_PATH = 'LeanSrc/LeanSrc'
11
 
12
  def make_lean_repl(repl_type='zsh'):
 
18
  lean_repl = pexpect.spawn(SHELL_CMD, cwd='LeanSrc', maxread=5000, timeout=20, echo=False)
19
  lean_repl.sendline('stty -icanon') # this is the magic that allows a bunch of chars to be sent
20
  lean_repl.sendline(LEAN_REPL_CMD)
21
+ if OS == MACOS:
22
+ print(lean_repl.readline()) # my mac prints out some garbage when I run /bin/sh
23
+ print(lean_repl.readline())
24
  elif repl_type == 'zsh':
25
  lean_repl = pexpect.spawn(LEAN_REPL_CMD,cwd='LeanSrc', maxread=1025, timeout=5)
26
 
 
77
 
78
  #ps_out = json.loads(output)
79
  assert ps_out is not None, 'parsing failed: ' + jsons.decode()
80
+ #print('parsed output:', ps_out)
81
  return ps_out
82
 
83
  def make_repl_command(def_str, env=None):
 
131
 
132
 
133
  def send_command_icanon(repl, command, env=None, timeout=20, first=False):
134
+ #print('sending command:', command)
135
  rpl_comm = make_repl_command(command, env=env)
136
 
137
+ repl.sendline(rpl_comm + '\n')
138
+ if OS == MACOS:
139
+ if first:
140
+ repl.expect_exact('~>')
141
+ first = False
142
+ else:
143
+ try:
144
+ repl.expect_exact('\r\n\r\n')
145
+ except pexpect.exceptions.TIMEOUT as e:
146
+ print('did not find newlines')
147
+ elif OS == LINUX and first:
148
+ repl.expect_exact('\r{')
149
  try:
150
+ _index = repl.expect('env": \d+\}', timeout=60)
151
  command_sent = True
152
  except pexpect.exceptions.TIMEOUT as e:
153
+ raise(e)
154
  print('did not find env in output')
155
  return None, None
156
 
157
  env_str = repl.match.group().decode()
158
  new_env = int(env_str.split(':')[1].strip()[:-1])
159
  output = repl.before + repl.match.group()
160
+ if OS == LINUX and first:
161
+ output = '{'.encode() + output
162
  return load_mult_json(output), new_env
163
 
164
  def make_repl_tactic(tac, proofState):
 
175
 
176
  # the icanon mode sometimes sends a single dict with just one field: 'message'.
177
  # when we get that with a lean error, the tactic failed so we return None
178
+ _index = repl.expect('(]})|(\"}\r\n\r\n)', timeout=60)
179
 
180
 
181
  #ps_str = repl.match.group().decode()
 
184
  #if verbose:
185
  #print('js outp 2', output)
186
  ps_out = load_mult_json(output)
187
+ #print('ps out', ps_out)
188
  if 'proofState' not in ps_out:
189
  return None, None
190
  return ps_out, ps_out['proofState']
 
193
  # return None, None
194
 
195
  def get_errs(outp):
196
+ return [m for m in outp.get('messages', []) if m.get('severity', 'error') == 'error']