src/FOL/ex/prolog.ML
changeset 0 a5a9c433f639
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/FOL/ex/prolog.ML	Thu Sep 16 12:20:38 1993 +0200
     1.3 @@ -0,0 +1,74 @@
     1.4 +(*  Title: 	FOL/ex/prolog.ML
     1.5 +    ID:         $Id$
     1.6 +    Author: 	Lawrence C Paulson, Cambridge University Computer Laboratory
     1.7 +    Copyright   1992  University of Cambridge
     1.8 +
     1.9 +For ex/prolog.thy.  First-Order Logic: PROLOG examples
    1.10 +*)
    1.11 +
    1.12 +open Prolog;
    1.13 +
    1.14 +goal Prolog.thy "app(a:b:c:Nil, d:e:Nil, ?x)";
    1.15 +by (resolve_tac [appNil,appCons] 1);
    1.16 +by (resolve_tac [appNil,appCons] 1);
    1.17 +by (resolve_tac [appNil,appCons] 1);
    1.18 +by (resolve_tac [appNil,appCons] 1);
    1.19 +prth (result());
    1.20 +
    1.21 +goal Prolog.thy "app(?x, c:d:Nil, a:b:c:d:Nil)";
    1.22 +by (REPEAT (resolve_tac [appNil,appCons] 1));
    1.23 +result();
    1.24 +
    1.25 +
    1.26 +goal Prolog.thy "app(?x, ?y, a:b:c:d:Nil)";
    1.27 +by (REPEAT (resolve_tac [appNil,appCons] 1));
    1.28 +back();
    1.29 +back();
    1.30 +back();
    1.31 +back();
    1.32 +result();
    1.33 +
    1.34 +
    1.35 +(*app([x1,...,xn], y, ?z) requires (n+1) inferences*)
    1.36 +(*rev([x1,...,xn], ?y) requires (n+1)(n+2)/2 inferences*)
    1.37 +
    1.38 +goal Prolog.thy "rev(a:b:c:d:Nil, ?x)";
    1.39 +val rules = [appNil,appCons,revNil,revCons];
    1.40 +by (REPEAT (resolve_tac rules 1));
    1.41 +result();
    1.42 +
    1.43 +goal Prolog.thy "rev(a:b:c:d:e:f:g:h:i:j:k:l:m:n:Nil, ?w)";
    1.44 +by (REPEAT (resolve_tac rules 1));
    1.45 +result();
    1.46 +
    1.47 +goal Prolog.thy "rev(?x, a:b:c:Nil)";
    1.48 +by (REPEAT (resolve_tac rules 1)); (*does not solve it directly!*)
    1.49 +back();
    1.50 +back();
    1.51 +
    1.52 +(*backtracking version*)
    1.53 +val prolog_tac = DEPTH_FIRST (has_fewer_prems 1) (resolve_tac rules 1);
    1.54 +
    1.55 +choplev 0;
    1.56 +by prolog_tac;
    1.57 +result();
    1.58 +
    1.59 +goal Prolog.thy "rev(a:?x:c:?y:Nil, d:?z:b:?u)";
    1.60 +by prolog_tac;
    1.61 +result();
    1.62 +
    1.63 +(*rev([a..p], ?w) requires 153 inferences *)
    1.64 +goal Prolog.thy "rev(a:b:c:d:e:f:g:h:i:j:k:l:m:n:o:p:Nil, ?w)";
    1.65 +by (DEPTH_SOLVE (resolve_tac ([refl,conjI]@rules) 1));
    1.66 +(*Poly/ML: 4 secs >> 38 lips*)
    1.67 +result();
    1.68 +
    1.69 +(*?x has 16, ?y has 32;  rev(?y,?w) requires 561 (rather large) inferences;
    1.70 +  total inferences = 2 + 1 + 17 + 561 = 581*)
    1.71 +goal Prolog.thy
    1.72 +    "a:b:c:d:e:f:g:h:i:j:k:l:m:n:o:p:Nil = ?x & app(?x,?x,?y) & rev(?y,?w)";
    1.73 +by (DEPTH_SOLVE (resolve_tac ([refl,conjI]@rules) 1));
    1.74 +(*Poly/ML: 29 secs >> 20 lips*)
    1.75 +result();
    1.76 +
    1.77 +writeln"Reached end of file.";