src/HOL/Prolog/Test.ML
author wenzelm
Wed Sep 07 21:07:09 2005 +0200 (2005-09-07)
changeset 17311 5b1d47d920ce
parent 14981 e73f8140af78
permissions -rw-r--r--
converted to Isar theory format;
oheimb@13208
     1
(*  Title:    HOL/Prolog/Test.ML
oheimb@13208
     2
    ID:       $Id$
oheimb@13208
     3
    Author:   David von Oheimb (based on a lecture on Lambda Prolog by Nadathur)
oheimb@13208
     4
*)
oheimb@13208
     5
oheimb@9015
     6
val prog_Test = prog_HOHH@[append, reverse, mappred, mapfun, age, eq, bag_appl];
wenzelm@12486
     7
fun pgoal s = (case Goal s of _ => by (prolog_tac prog_Test));
oheimb@9015
     8
val p = ptac prog_Test 1;
oheimb@9015
     9
oheimb@9015
    10
pgoal "append ?x ?y [a,b,c,d]";
oheimb@9015
    11
back();
oheimb@9015
    12
back();
oheimb@9015
    13
back();
oheimb@9015
    14
back();
oheimb@9015
    15
oheimb@9015
    16
pgoal "append [a,b] y ?L";
oheimb@9015
    17
pgoal "!y. append [a,b] y (?L y)";
oheimb@9015
    18
oheimb@9015
    19
pgoal "reverse [] ?L";
oheimb@9015
    20
oheimb@9015
    21
pgoal "reverse [23] ?L";
oheimb@9015
    22
pgoal "reverse [23,24,?x] ?L";
oheimb@9015
    23
pgoal "reverse ?L [23,24,?x]";
oheimb@9015
    24
oheimb@9015
    25
pgoal "mappred age ?x [23,24]";
oheimb@9015
    26
back();
oheimb@9015
    27
oheimb@9015
    28
pgoal "mappred (%x y. ? z. age z y) ?x [23,24]";
oheimb@9015
    29
oheimb@9015
    30
pgoal "mappred ?P [bob,sue] [24,23]";
oheimb@9015
    31
oheimb@9015
    32
pgoal "mapfun f [bob,bob,sue] [?x,?y,?z]";
oheimb@9015
    33
oheimb@9015
    34
pgoal "mapfun (%x. h x 25) [bob,sue] ?L";
oheimb@9015
    35
oheimb@9015
    36
pgoal "mapfun ?F [24,25] [h bob 24,h bob 25]";
oheimb@9015
    37
oheimb@9015
    38
pgoal "mapfun ?F [24] [h 24 24]";
oheimb@9015
    39
back();
oheimb@9015
    40
back();
oheimb@9015
    41
back();
oheimb@9015
    42
oheimb@9015
    43
oheimb@9015
    44
(*
wenzelm@17311
    45
goal (the_context ()) "f a = ?g a a & ?g = x";
wenzelm@12486
    46
by (rtac conjI 1);
wenzelm@12486
    47
by (rtac refl 1);
oheimb@9015
    48
back();
oheimb@9015
    49
back();
oheimb@9015
    50
*)
oheimb@9015
    51
oheimb@9015
    52
pgoal "True";
oheimb@9015
    53
oheimb@9015
    54
pgoal "age ?x 24 & age ?y 23";
oheimb@9015
    55
back();
oheimb@9015
    56
oheimb@9015
    57
pgoal "age ?x 24 | age ?x 23";
oheimb@9015
    58
back();
oheimb@9015
    59
back();
oheimb@9015
    60
oheimb@9015
    61
pgoal "? x y. age x y";
oheimb@9015
    62
oheimb@9015
    63
pgoal "!x y. append [] x x";
oheimb@9015
    64
oheimb@9015
    65
pgoal "age sue 24 .. age bob 23 => age ?x ?y";
oheimb@9015
    66
back();
oheimb@9015
    67
back();
oheimb@9015
    68
back();
oheimb@9015
    69
back();
oheimb@9015
    70
oheimb@9015
    71
(*set trace_DEPTH_FIRST;*)
oheimb@9015
    72
pgoal "age bob 25 :- age bob 24 => age bob 25";
oheimb@9015
    73
(*reset trace_DEPTH_FIRST;*)
oheimb@9015
    74
oheimb@9015
    75
pgoal "(!x. age x 25 :- age x 23) => age ?x 25 & age ?y 25";
oheimb@9015
    76
back();
oheimb@9015
    77
back();
oheimb@9015
    78
back();
oheimb@9015
    79
oheimb@9015
    80
pgoal "!x. ? y. eq x y";
oheimb@9015
    81
oheimb@9015
    82
pgoal "? P. P & eq P ?x";
oheimb@9015
    83
(*
oheimb@9015
    84
back();
oheimb@9015
    85
back();
oheimb@9015
    86
back();
oheimb@9015
    87
back();
oheimb@9015
    88
back();
oheimb@9015
    89
back();
oheimb@9015
    90
back();
oheimb@9015
    91
back();
oheimb@9015
    92
*)
oheimb@9015
    93
oheimb@9015
    94
pgoal "? P. eq P (True & True) & P";
oheimb@9015
    95
oheimb@9015
    96
pgoal "? P. eq P op | & P k True";
oheimb@9015
    97
oheimb@9015
    98
pgoal "? P. eq P (Q => True) & P";
oheimb@9015
    99
oheimb@9015
   100
(* P flexible: *)
oheimb@9015
   101
pgoal "(!P k l. P k l :- eq P Q) => Q a b";
oheimb@9015
   102
(*
oheimb@9015
   103
loops:
oheimb@9015
   104
pgoal "(!P k l. P k l :- eq P (%x y. x | y)) => a | b";
oheimb@9015
   105
*)
oheimb@9015
   106
oheimb@9015
   107
(* implication and disjunction in atom: *)
wenzelm@17311
   108
goal (the_context ()) "? Q. (!p q. R(q :- p) => R(Q p q)) & Q (t | s) (s | t)";
wenzelm@12486
   109
by (fast_tac HOL_cs 1);
oheimb@9015
   110
oheimb@9015
   111
(* disjunction in atom: *)
wenzelm@17311
   112
goal (the_context ()) "(!P. g P :- (P => b | a)) => g(a | b)";
wenzelm@12486
   113
by (step_tac HOL_cs 1);
wenzelm@12486
   114
by (step_tac HOL_cs 1);
wenzelm@12486
   115
by (step_tac HOL_cs 1);
wenzelm@12486
   116
by (fast_tac HOL_cs 2);
wenzelm@12486
   117
by (fast_tac HOL_cs 1);
oheimb@9015
   118
(*
oheimb@9015
   119
hangs:
wenzelm@17311
   120
goal (the_context ()) "(!P. g P :- (P => b | a)) => g(a | b)";
wenzelm@12486
   121
by (fast_tac HOL_cs 1);
oheimb@9015
   122
*)
oheimb@9015
   123
oheimb@9015
   124
pgoal "!Emp Stk.(\
oheimb@9015
   125
\                       empty    (Emp::'b) .. \
oheimb@9015
   126
\         (!(X::nat) S. add    X (S::'b)         (Stk X S)) .. \
oheimb@9015
   127
\         (!(X::nat) S. remove X ((Stk X S)::'b) S))\
oheimb@9015
   128
\ => bag_appl 23 24 ?X ?Y";
oheimb@9015
   129
oheimb@9015
   130
pgoal "!Qu. ( \
oheimb@9015
   131
\          (!L.            empty    (Qu L L)) .. \
oheimb@9015
   132
\          (!(X::nat) L K. add    X (Qu L (X#K)) (Qu L K)) ..\
oheimb@9015
   133
\          (!(X::nat) L K. remove X (Qu (X#L) K) (Qu L K)))\
oheimb@9015
   134
\ => bag_appl 23 24 ?X ?Y";
oheimb@9015
   135
oheimb@9015
   136
pgoal "D & (!y. E) :- (!x. True & True) :- True => D";
oheimb@9015
   137
oheimb@9015
   138
pgoal "P x .. P y => P ?X";
oheimb@9015
   139
back();
oheimb@9015
   140
(*
oheimb@9015
   141
back();
oheimb@9015
   142
-> problem with DEPTH_SOLVE:
oheimb@9015
   143
Exception- THM ("dest_state", 1, ["P x & P y --> P y"]) raised
oheimb@9015
   144
Exception raised at run-time
wenzelm@17311
   145
*)