(* * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230) * * SPDX-License-Identifier: BSD-2-Clause *) (* Basic tests for the @{inline_tactic} and @{inline_method} antiquotations. *) theory TacticAntiquotation_Test imports Lib.TacticAntiquotation begin text \Simple tests.\ text \Example proof.\ lemma fixes fib :: "nat \ nat" shows "\ fib 0 = 0; fib (Suc 0) = Suc 0; \n. fib (Suc (Suc n)) = fib n + fib (Suc n) \ \ fib n < 2^n" apply (induct n rule: less_induct) apply (rename_tac n, case_tac n) apply fastforce apply (rename_tac n, case_tac n) apply (clarsimp simp only:, simp) apply (clarsimp simp add: mult_2) apply (rule add_less_le_mono) apply (metis trans_less_add2 lessI less_trans) apply (fastforce simp only: mult_2[symmetric] power_Suc[symmetric] intro: less_imp_le) done text \Let's uglify this proof\\ (* Test that we can save a tactic and call it in another context. * (For this to work, the antiquoter has to dynamically parse and eval * the method text each time the tactic is run) *) ML \ val stored_tactic = @{inline_tactic "rename_tac n, case_tac n"}; val stored_method = @{inline_method "rule add_less_le_mono"}; \ lemma fixes fib :: "nat \ nat" shows "\ fib 0 = 0; fib (Suc 0) = Suc 0; \n. fib (Suc (Suc n)) = fib n + fib (Suc n) \ \ fib n < 2^n" apply (tactic \@{inline_tactic "induct n rule: less_induct"}\) apply (tactic \stored_tactic\) apply (tactic \@{inline_tactic fastforce}\) apply (tactic \stored_tactic\) apply (tactic \@{inline_tactic "clarsimp simp only:"} THEN @{inline_tactic "simp"}\) apply (tactic \NO_CONTEXT_TACTIC @{context} (@{inline_method "clarsimp simp add: mult_2"} [])\) apply (tactic \NO_CONTEXT_TACTIC @{context} (stored_method [])\) apply (tactic \@{inline_tactic "metis trans_less_add2 lessI less_trans"}\) apply (tactic \@{inline_tactic "fastforce simp only: mult_2[symmetric] power_Suc[symmetric] intro: less_imp_le"}\) done end