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