<commit_before>/-
Copyright (c) 2022 OpenAI. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author(s): <NAME>

Simple "squeezing" finishing.
-/
import util.io
import data.list.basic
import util.tactic

meta def try_finish_tactics : list (tactic unit × string) := [
  (`[trivial], "trivial"),
  (`[refl], "refl"),
  (`[exact dec_trivia], "exact dec_trivial"),
  (`[assumption], "assumption"),
  (`[simp], "simp"),    
  (`[dsimp], "dsimp"),    
  (`[norm_num], "norm_num"),    
  (`[ring], "ring"),
  (`[simp [*]], "simp [*]"),    
  (`[linarith], "linarith")
]
  
meta def try_finish (ts : tactic_state) (timeout : nat := 1000) : io (option (string × tactic_state)) := do
  try_finish_tactics.mfirst $ λ ⟨tac, tacString⟩, do {
    io.run_tac ts $ do {
      gs1 ← tactic.get_goals,
      tactic.try_for_time timeout $ tactic.try_for 200000 (tactic.solve1 tac),
      ts2 ← get,
      pure (tacString, ts2)
    }
  }<commit_msg>fix: try_finish should be robust to failures<commit_after>/-
Copyright (c) 2022 OpenAI. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author(s): <NAME>

Simple "squeezing" finishing.
-/
import util.io
import data.list.basic
import util.tactic

meta def try_finish_tactics : list (tactic unit × string) := [
  (`[trivial], "trivial"),
  (`[refl], "refl"),
  (`[exact dec_trivia], "exact dec_trivial"),
  (`[assumption], "assumption"),
  (`[simp], "simp"),
  (`[dsimp], "dsimp"),
  (`[norm_num], "norm_num"),
  (`[ring], "ring"),
  (`[simp [*]], "simp [*]"),
  (`[linarith], "linarith")
]

meta def try_finish (ts : tactic_state) (timeout : nat := 1000) : io (option (string × tactic_state)) :=
  (try_finish_tactics.mfirst $ λ ⟨tac, tacString⟩, io.run_tac ts $ do {
    gs1 ← tactic.get_goals,
    tactic.try_for_time timeout $ tactic.try_for 200000 (tactic.solve1 tac),
    ts2 ← get,
    pure (tacString, ts2)
  }) <|> pure none

{'fraction_non_alphanumeric': 0.17816683831101957, 'fraction_numerical': 0.02059732234809475, 'mean_word_length': 3.918987341772152, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5254783', 'n_tokens_mistral': 808, 'n_tokens_neox': 733, 'n_words': 200}