src/HOL/ex/mesontest2.ML
changeset 14220 4dc132902672
parent 14183 466a2a69e7e8
child 15285 ce83b7e74a91
equal deleted inserted replaced
14219:9fdea25f9ebb 14220:4dc132902672
     1 (*  Title:      HOL/ex/mesontest2
     1 (*  Title:      HOL/ex/mesontest2
     2     ID:         $Id$
     2     ID:         $Id$
     3     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     3     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     4     Copyright   2000  University of Cambridge
     4     Copyright   2000  University of Cambridge
     5 
     5 
     6 MORE and MUCH HARDER test data for the MESON proof procedure
     6 Test data for the MESON proof procedure
       
     7    (Excludes the equality problems 51, 52, 56, 58)
       
     8 
       
     9 NOTE: most of the old file "mesontest.ML" has been converted to Isar and moved
       
    10 to Classical.thy
       
    11 
       
    12 Use the "mesonlog" shell script to process logs.
       
    13 
       
    14 show_hyps := false;
       
    15 
       
    16 proofs := 0;
       
    17 by (rtac ccontr 1);
       
    18 val [prem] = gethyps 1;
       
    19 val nnf = make_nnf prem;
       
    20 val xsko = skolemize nnf;
       
    21 by (cut_facts_tac [xsko] 1 THEN REPEAT (etac exE 1));
       
    22 val [_,sko] = gethyps 1;
       
    23 val clauses = make_clauses [sko];       
       
    24 val horns = make_horns clauses;
       
    25 val goes = gocls clauses;
       
    26 
       
    27 Goal "False";
       
    28 by (resolve_tac goes 1);
       
    29 proofs := 2;
       
    30 
       
    31 by (prolog_step_tac horns 1);
       
    32 by (iter_deepen_prolog_tac horns);
       
    33 by (depth_prolog_tac horns);
       
    34 by (best_prolog_tac size_of_subgoals horns);
       
    35 *)
       
    36 
       
    37 writeln"File HOL/ex/meson-test.";
       
    38 
       
    39 context Main.thy;
       
    40 
       
    41 (*Deep unifications can be required, esp. during transformation to clauses*)
       
    42 val orig_trace_bound = !Unify.trace_bound
       
    43 and orig_search_bound = !Unify.search_bound;
       
    44 Unify.trace_bound := 20;
       
    45 Unify.search_bound := 40;
       
    46 
       
    47 (**** Interactive examples ****)
       
    48 
       
    49 (*Generate nice names for Skolem functions*)
       
    50 Logic.auto_rename := true; Logic.set_rename_prefix "a";
       
    51 
       
    52 
       
    53 writeln"Problem 25";
       
    54 Goal "(\\<exists>x. P x) &  \
       
    55 \     (\\<forall>x. L x --> ~ (M x & R x)) &  \
       
    56 \     (\\<forall>x. P x --> (M x & L x)) &   \
       
    57 \     ((\\<forall>x. P x --> Q x) | (\\<exists>x. P x & R x))  \
       
    58 \   --> (\\<exists>x. Q x & P x)";
       
    59 by (rtac ccontr 1);
       
    60 val [prem25] = gethyps 1;
       
    61 val nnf25 = make_nnf prem25;
       
    62 val xsko25 = skolemize nnf25;
       
    63 by (cut_facts_tac [xsko25] 1 THEN REPEAT (etac exE 1));
       
    64 val [_,sko25] = gethyps 1;
       
    65 val clauses25 = make_clauses [sko25];   (*7 clauses*)
       
    66 val horns25 = make_horns clauses25;     (*16 Horn clauses*)
       
    67 val go25::_ = gocls clauses25;
       
    68 
       
    69 Goal "False";
       
    70 by (rtac go25 1);
       
    71 by (depth_prolog_tac horns25);
       
    72 
       
    73 
       
    74 writeln"Problem 26";
       
    75 Goal "((\\<exists>x. p x) = (\\<exists>x. q x)) &     \
       
    76 \     (\\<forall>x. \\<forall>y. p x & q y --> (r x = s y)) \
       
    77 \ --> ((\\<forall>x. p x --> r x) = (\\<forall>x. q x --> s x))";
       
    78 by (rtac ccontr 1);
       
    79 val [prem26] = gethyps 1;
       
    80 val nnf26 = make_nnf prem26;
       
    81 val xsko26 = skolemize nnf26;
       
    82 by (cut_facts_tac [xsko26] 1 THEN REPEAT (etac exE 1));
       
    83 val [_,sko26] = gethyps 1;
       
    84 val clauses26 = make_clauses [sko26];                   (*9 clauses*)
       
    85 val horns26 = make_horns clauses26;                     (*24 Horn clauses*)
       
    86 val go26::_ = gocls clauses26;
       
    87 
       
    88 Goal "False";
       
    89 by (rtac go26 1);
       
    90 by (depth_prolog_tac horns26);  (*1.4 secs*)
       
    91 (*Proof is of length 107!!*)
       
    92 
       
    93 
       
    94 writeln"Problem 43  NOW PROVED AUTOMATICALLY!!";  (*16 Horn clauses*)
       
    95 Goal "(\\<forall>x. \\<forall>y. q x y = (\\<forall>z. p z x = (p z y::bool)))  \
       
    96 \     --> (\\<forall>x. (\\<forall>y. q x y = (q y x::bool)))";
       
    97 by (rtac ccontr 1);
       
    98 val [prem43] = gethyps 1;
       
    99 val nnf43 = make_nnf prem43;
       
   100 val xsko43 = skolemize nnf43;
       
   101 by (cut_facts_tac [xsko43] 1 THEN REPEAT (etac exE 1));
       
   102 val [_,sko43] = gethyps 1;
       
   103 val clauses43 = make_clauses [sko43];   (*6*)
       
   104 val horns43 = make_horns clauses43;     (*16*)
       
   105 val go43::_ = gocls clauses43;
       
   106 
       
   107 Goal "False";
       
   108 by (rtac go43 1);
       
   109 by (best_prolog_tac size_of_subgoals horns43);   (*1.6 secs*)
       
   110 
       
   111 (* 
       
   112 #1  (q x xa ==> ~ q x xa) ==> q xa x
       
   113 #2  (q xa x ==> ~ q xa x) ==> q x xa
       
   114 #3  (~ q x xa ==> q x xa) ==> ~ q xa x
       
   115 #4  (~ q xa x ==> q xa x) ==> ~ q x xa
       
   116 #5  [| ~ q ?U ?V ==> q ?U ?V; ~ p ?W ?U ==> p ?W ?U |] ==> p ?W ?V
       
   117 #6  [| ~ p ?W ?U ==> p ?W ?U; p ?W ?V ==> ~ p ?W ?V |] ==> ~ q ?U ?V
       
   118 #7  [| p ?W ?V ==> ~ p ?W ?V; ~ q ?U ?V ==> q ?U ?V |] ==> ~ p ?W ?U
       
   119 #8  [| ~ q ?U ?V ==> q ?U ?V; ~ p ?W ?V ==> p ?W ?V |] ==> p ?W ?U
       
   120 #9  [| ~ p ?W ?V ==> p ?W ?V; p ?W ?U ==> ~ p ?W ?U |] ==> ~ q ?U ?V
       
   121 #10 [| p ?W ?U ==> ~ p ?W ?U; ~ q ?U ?V ==> q ?U ?V |] ==> ~ p ?W ?V
       
   122 #11 [| p (xb ?U ?V) ?U ==> ~ p (xb ?U ?V) ?U;
       
   123        p (xb ?U ?V) ?V ==> ~ p (xb ?U ?V) ?V |] ==> q ?U ?V
       
   124 #12 [| p (xb ?U ?V) ?V ==> ~ p (xb ?U ?V) ?V; q ?U ?V ==> ~ q ?U ?V |] ==>
       
   125     p (xb ?U ?V) ?U
       
   126 #13 [| q ?U ?V ==> ~ q ?U ?V; p (xb ?U ?V) ?U ==> ~ p (xb ?U ?V) ?U |] ==>
       
   127     p (xb ?U ?V) ?V
       
   128 #14 [| ~ p (xb ?U ?V) ?U ==> p (xb ?U ?V) ?U;
       
   129        ~ p (xb ?U ?V) ?V ==> p (xb ?U ?V) ?V |] ==> q ?U ?V
       
   130 #15 [| ~ p (xb ?U ?V) ?V ==> p (xb ?U ?V) ?V; q ?U ?V ==> ~ q ?U ?V |] ==>
       
   131     ~ p (xb ?U ?V) ?U
       
   132 #16 [| q ?U ?V ==> ~ q ?U ?V; ~ p (xb ?U ?V) ?U ==> p (xb ?U ?V) ?U |] ==>
       
   133     ~ p (xb ?U ?V) ?V
       
   134 
       
   135 And here is the proof! (Unkn is the start state after use of goal clause)
       
   136 [Unkn, Res ([Thm "#14"], false, 1), Res ([Thm "#5"], false, 1),
       
   137    Res ([Thm "#1"], false, 1), Asm 1, Res ([Thm "#13"], false, 1), Asm 2,
       
   138    Asm 1, Res ([Thm "#13"], false, 1), Asm 1, Res ([Thm "#10"], false, 1),
       
   139    Res ([Thm "#16"], false, 1), Asm 2, Asm 1, Res ([Thm "#1"], false, 1),
       
   140    Asm 1, Res ([Thm "#14"], false, 1), Res ([Thm "#5"], false, 1),
       
   141    Res ([Thm "#2"], false, 1), Asm 1, Res ([Thm "#13"], false, 1), Asm 2,
       
   142    Asm 1, Res ([Thm "#8"], false, 1), Res ([Thm "#2"], false, 1), Asm 1,
       
   143    Res ([Thm "#12"], false, 1), Asm 2, Asm 1] : lderiv list
       
   144 *)
       
   145 
       
   146 
       
   147 (*Restore variable name preservation*)
       
   148 Logic.auto_rename := false; 
       
   149 
       
   150 
       
   151 (** Charles Morgan's problems **)
       
   152 
       
   153 val axa = "\\<forall>x y.   T(i x(i y x))";
       
   154 val axb = "\\<forall>x y z. T(i(i x(i y z))(i(i x y)(i x z)))";
       
   155 val axc = "\\<forall>x y.   T(i(i(n x)(n y))(i y x))";
       
   156 val axd = "\\<forall>x y.   T(i x y) & T x --> T y";
       
   157 
       
   158 fun axjoin ([],   q) = q
       
   159   | axjoin (p::ps, q) = "(" ^ p ^ ") --> (" ^ axjoin(ps,q) ^ ")";
       
   160 
       
   161 Goal (axjoin([axa,axb,axd], "\\<forall>x. T(i x x)"));
       
   162 by (meson_tac 1);  
       
   163 result();
       
   164 
       
   165 writeln"Problem 66";  
       
   166 Goal (axjoin([axa,axb,axc,axd], "\\<forall>x. T(i x(n(n x)))"));
       
   167 by (meson_tac 1);  
       
   168 result();
       
   169 (*SLOW: 37s on a 1.8MHz machine
       
   170      208346 inferences so far.  Searching to depth 23 *)
       
   171 
       
   172 writeln"Problem 67";  
       
   173 Goal (axjoin([axa,axb,axc,axd], "\\<forall>x. T(i(n(n x)) x)"));
       
   174 by (meson_tac 1);  
       
   175 result();
       
   176 (*10s on a 1.8MHz machine
       
   177   51061 inferences so far.  Searching to depth 21 *)
       
   178 
       
   179 
       
   180 (*MORE and MUCH HARDER test data for the MESON proof procedure
     7 
   181 
     8 Courtesy John Harrison 
   182 Courtesy John Harrison 
     9 
   183 
    10 WARNING: there are many potential conflicts between variables used below
   184 WARNING: there are many potential conflicts between variables used below
    11 and constants declared in HOL!
   185 and constants declared in HOL!
   179 \  (\\<forall>X Y. equal(X::'a,Y) --> equal(INVERSE(X),INVERSE(Y))) &       \
   353 \  (\\<forall>X Y. equal(X::'a,Y) --> equal(INVERSE(X),INVERSE(Y))) &       \
   180 \  (~product(x::'a,x,x)) --> False",
   354 \  (~product(x::'a,x,x)) --> False",
   181   meson_tac 1);
   355   meson_tac 1);
   182 
   356 
   183 (*51194 inferences so far.  Searching to depth 13. 204.6 secs
   357 (*51194 inferences so far.  Searching to depth 13. 204.6 secs
   184   Strange\\<forall> The previous problem also has 51194 inferences at depth 13.  They
   358   Strange! The previous problem also has 51194 inferences at depth 13.  They
   185    must be very similar!*)
   359    must be very similar!*)
   186 val BOO004_1 = prove_hard
   360 val BOO004_1 = prove_hard
   187  ("(\\<forall>X. equal(X::'a,X)) &  \
   361  ("(\\<forall>X. equal(X::'a,X)) &  \
   188 \  (\\<forall>Y X. equal(X::'a,Y) --> equal(Y::'a,X)) & \
   362 \  (\\<forall>Y X. equal(X::'a,Y) --> equal(Y::'a,X)) & \
   189 \  (\\<forall>Y X Z. equal(X::'a,Y) & equal(Y::'a,Z) --> equal(X::'a,Z)) &  \
   363 \  (\\<forall>Y X Z. equal(X::'a,Y) & equal(Y::'a,Z) --> equal(X::'a,Z)) &  \
  2946 \  (difference(b::'a,a,bDa)) &      \
  3120 \  (difference(b::'a,a,bDa)) &      \
  2947 \  (difference(b::'a,d,bDd)) &      \
  3121 \  (difference(b::'a,d,bDd)) &      \
  2948 \  (~subset(bDa::'a,bDd)) --> False",
  3122 \  (~subset(bDa::'a,bDd)) --> False",
  2949   meson_tac 1);
  3123   meson_tac 1);
  2950 
  3124 
  2951 (*34726 inferences so far.  Searching to depth 6.  2420 secs: 40 mins\\<forall> BIG*)
  3125 (*34726 inferences so far.  Searching to depth 6.  2420 secs: 40 mins! BIG*)
  2952 val SET025_4 = prove_hard
  3126 val SET025_4 = prove_hard
  2953  ("(\\<forall>X. equal(X::'a,X)) &  \
  3127  ("(\\<forall>X. equal(X::'a,X)) &  \
  2954 \  (\\<forall>Y X. equal(X::'a,Y) --> equal(Y::'a,X)) & \
  3128 \  (\\<forall>Y X. equal(X::'a,Y) --> equal(Y::'a,X)) & \
  2955 \  (\\<forall>Y X Z. equal(X::'a,Y) & equal(Y::'a,Z) --> equal(X::'a,Z)) &  \
  3129 \  (\\<forall>Y X Z. equal(X::'a,Y) & equal(Y::'a,Z) --> equal(X::'a,Z)) &  \
  2956 \  (\\<forall>Y X. member(X::'a,Y) --> little_set(X)) &     \
  3130 \  (\\<forall>Y X. member(X::'a,Y) --> little_set(X)) &     \