src/FOL/ex/IffOracle.thy
author haftmann
Tue, 22 Jan 2008 11:37:28 +0100
changeset 25940 6942f3c5dec8
parent 23153 3cc4a80c4d30
child 25946 8ceff6c1f2a8
permissions -rw-r--r--
avoid 'it' in ML expressions
     1 (*  Title:      FOL/ex/IffOracle.thy
     2     ID:         $Id$
     3     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     4     Copyright   1996  University of Cambridge
     5 *)
     6 
     7 header {* Example of Declaring an Oracle *}
     8 
     9 theory IffOracle
    10 imports FOL
    11 begin
    12 
    13 subsection {* Oracle declaration *}
    14 
    15 text {*
    16   This oracle makes tautologies of the form @{text "P <-> P <-> P <-> P"}.
    17   The length is specified by an integer, which is checked to be even
    18   and positive.
    19 *}
    20 
    21 oracle iff_oracle (int) = {*
    22   let
    23     fun mk_iff 1 = Var (("P", 0), @{typ o})
    24       | mk_iff n = FOLogic.iff $ Var (("P", 0), @{typ o}) $ mk_iff (n - 1);
    25   in
    26     fn thy => fn n =>
    27       if n > 0 andalso n mod 2 = 0
    28       then FOLogic.mk_Trueprop (mk_iff n)
    29       else raise Fail ("iff_oracle: " ^ string_of_int n)
    30   end
    31 *}
    32 
    33 
    34 subsection {* Oracle as low-level rule *}
    35 
    36 ML {* iff_oracle @{theory} 2 *}
    37 ML {* iff_oracle @{theory} 10 *}
    38 
    39 text {* These oracle calls had better fail. *}
    40 
    41 ML {*
    42   (iff_oracle @{theory} 5; error "?")
    43     handle Fail _ => warning "Oracle failed, as expected"
    44 *}
    45 
    46 ML {*
    47   (iff_oracle @{theory} 1; error "?")
    48     handle Fail _ => warning "Oracle failed, as expected"
    49 *}
    50 
    51 
    52 subsection {* Oracle as proof method *}
    53 
    54 method_setup iff = {*
    55   Method.simple_args Args.nat (fn n => fn ctxt =>
    56     Method.SIMPLE_METHOD
    57       (HEADGOAL (Tactic.rtac (iff_oracle (ProofContext.theory_of ctxt) n))
    58         handle Fail _ => no_tac))
    59 *} "iff oracle"
    60 
    61 
    62 lemma "A <-> A"
    63   by (iff 2)
    64 
    65 lemma "A <-> A <-> A <-> A <-> A <-> A <-> A <-> A <-> A <-> A"
    66   by (iff 10)
    67 
    68 lemma "A <-> A <-> A <-> A <-> A"
    69   apply (iff 5)?
    70   oops
    71 
    72 lemma A
    73   apply (iff 1)?
    74   oops
    75 
    76 end