src/HOL/Eisbach/Examples.thy
changeset 61909 d5ead6bfa1ff
parent 60285 b4f1a0a701ae
child 61912 ad710de5c576
equal deleted inserted replaced
61908:a759f69db1f6 61909:d5ead6bfa1ff
    39      print_term Q,
    39      print_term Q,
    40      print_term x,
    40      print_term x,
    41      print_fact U\<close>)
    41      print_fact U\<close>)
    42 
    42 
    43 lemma "\<And>x. P x \<and> Q x \<Longrightarrow> A x \<and> B x \<Longrightarrow> R x y \<Longrightarrow> True"
    43 lemma "\<And>x. P x \<and> Q x \<Longrightarrow> A x \<and> B x \<Longrightarrow> R x y \<Longrightarrow> True"
    44   apply match_test  -- \<open>Valid match, but not quite what we were expecting..\<close>
    44   apply match_test  \<comment> \<open>Valid match, but not quite what we were expecting..\<close>
    45   back  -- \<open>Can backtrack over matches, exploring all bindings\<close>
    45   back  \<comment> \<open>Can backtrack over matches, exploring all bindings\<close>
    46   back
    46   back
    47   back
    47   back
    48   back
    48   back
    49   back
    49   back
    50   back  -- \<open>Found the other conjunction\<close>
    50   back  \<comment> \<open>Found the other conjunction\<close>
    51   back
    51   back
    52   back
    52   back
    53   back
    53   back
    54   oops
    54   oops
    55 
    55 
    56 text \<open>Use matching to avoid "improper" methods\<close>
    56 text \<open>Use matching to avoid "improper" methods\<close>
    57 
    57 
    58 lemma focus_test:
    58 lemma focus_test:
    59   shows "\<And>x. \<forall>x. P x \<Longrightarrow> P x"
    59   shows "\<And>x. \<forall>x. P x \<Longrightarrow> P x"
    60   apply (my_spec "x :: 'a", assumption)?  -- \<open>Wrong x\<close>
    60   apply (my_spec "x :: 'a", assumption)?  \<comment> \<open>Wrong x\<close>
    61   apply (match conclusion in "P x" for x \<Rightarrow> \<open>my_spec x, assumption\<close>)
    61   apply (match conclusion in "P x" for x \<Rightarrow> \<open>my_spec x, assumption\<close>)
    62   done
    62   done
    63 
    63 
    64 
    64 
    65 text \<open>Matches are exclusive. Backtracking will not occur past a match\<close>
    65 text \<open>Matches are exclusive. Backtracking will not occur past a match\<close>
   100     \<open>insert spec[where x=x, OF U],
   100     \<open>insert spec[where x=x, OF U],
   101      print_term P,
   101      print_term P,
   102      print_term Q\<close>)
   102      print_term Q\<close>)
   103 
   103 
   104 lemma "\<forall>x. P x \<longrightarrow> Q x \<Longrightarrow> Q x \<Longrightarrow> Q x"
   104 lemma "\<forall>x. P x \<longrightarrow> Q x \<Longrightarrow> Q x \<Longrightarrow> Q x"
   105   apply my_spec_guess2?  -- \<open>Fails. Note that both "P"s must match\<close>
   105   apply my_spec_guess2?  \<comment> \<open>Fails. Note that both "P"s must match\<close>
   106   oops
   106   oops
   107 
   107 
   108 lemma "\<forall>x. P x \<longrightarrow> Q x \<Longrightarrow> P x \<Longrightarrow> Q x"
   108 lemma "\<forall>x. P x \<longrightarrow> Q x \<Longrightarrow> P x \<Longrightarrow> Q x"
   109   apply my_spec_guess2
   109   apply my_spec_guess2
   110   apply (erule mp)
   110   apply (erule mp)
   139 
   139 
   140 
   140 
   141 subsection \<open>Solves combinator\<close>
   141 subsection \<open>Solves combinator\<close>
   142 
   142 
   143 lemma "A \<Longrightarrow> B \<Longrightarrow> A \<and> B"
   143 lemma "A \<Longrightarrow> B \<Longrightarrow> A \<and> B"
   144   apply (solves \<open>rule conjI\<close>)?  -- \<open>Doesn't solve the goal!\<close>
   144   apply (solves \<open>rule conjI\<close>)?  \<comment> \<open>Doesn't solve the goal!\<close>
   145   apply (solves \<open>rule conjI, assumption, assumption\<close>)
   145   apply (solves \<open>rule conjI, assumption, assumption\<close>)
   146   done
   146   done
   147 
   147 
   148 
   148 
   149 subsection \<open>Demo\<close>
   149 subsection \<open>Demo\<close>
   182   apply guess_all
   182   apply guess_all
   183   apply prop_solver
   183   apply prop_solver
   184   done
   184   done
   185 
   185 
   186 lemma "(\<forall>x. P x \<longrightarrow> Q x) \<Longrightarrow>  P z \<Longrightarrow> P y \<Longrightarrow> Q y"
   186 lemma "(\<forall>x. P x \<longrightarrow> Q x) \<Longrightarrow>  P z \<Longrightarrow> P y \<Longrightarrow> Q y"
   187   apply (solves \<open>guess_all, prop_solver\<close>)  -- \<open>Try it without solve\<close>
   187   apply (solves \<open>guess_all, prop_solver\<close>)  \<comment> \<open>Try it without solve\<close>
   188   done
   188   done
   189 
   189 
   190 method guess_ex =
   190 method guess_ex =
   191   (match conclusion in
   191   (match conclusion in
   192     "\<exists>x. P (x :: 'a)" for P \<Rightarrow>
   192     "\<exists>x. P (x :: 'a)" for P \<Rightarrow>