src/Pure/Proof/proofchecker.ML
author berghofe
Wed Nov 27 17:25:04 2002 +0100 (2002-11-27)
changeset 13733 8ea7388f66d4
parent 13670 c71b905a852a
child 14981 e73f8140af78
permissions -rw-r--r--
- tuned beta_eta_convert
- returned theorem is now in beta-eta normal form
berghofe@11522
     1
(*  Title:      Pure/Proof/proofchecker.ML
berghofe@11522
     2
    ID:         $Id$
wenzelm@11539
     3
    Author:     Stefan Berghofer, TU Muenchen
wenzelm@11539
     4
    License:    GPL (GNU GENERAL PUBLIC LICENSE)
berghofe@11522
     5
berghofe@11522
     6
Simple proof checker based only on the core inference rules
berghofe@11522
     7
of Isabelle/Pure.
berghofe@11522
     8
*)
berghofe@11522
     9
berghofe@11522
    10
signature PROOF_CHECKER =
berghofe@11522
    11
sig
berghofe@11522
    12
  val thm_of_proof : theory -> Proofterm.proof -> thm
berghofe@11522
    13
end;
berghofe@11522
    14
berghofe@11612
    15
structure ProofChecker : PROOF_CHECKER =
berghofe@11522
    16
struct
berghofe@11522
    17
berghofe@11522
    18
open Proofterm;
berghofe@11522
    19
berghofe@11522
    20
(***** construct a theorem out of a proof term *****)
berghofe@11522
    21
berghofe@11522
    22
fun lookup_thm thy =
berghofe@11522
    23
  let val tab = foldr Symtab.update
berghofe@11522
    24
    (flat (map thms_of (thy :: Theory.ancestors_of thy)), Symtab.empty)
berghofe@11522
    25
  in
berghofe@11522
    26
    (fn s => case Symtab.lookup (tab, s) of
berghofe@11522
    27
       None => error ("Unknown theorem " ^ quote s)
berghofe@11522
    28
     | Some thm => thm)
berghofe@11522
    29
  end;
berghofe@11522
    30
berghofe@13733
    31
val beta_eta_convert =
berghofe@13733
    32
  MetaSimplifier.fconv_rule MetaSimplifier.beta_eta_conversion;
berghofe@11522
    33
berghofe@11522
    34
fun thm_of_proof thy prf =
berghofe@11522
    35
  let
berghofe@11522
    36
    val names = add_prf_names ([], prf);
berghofe@11522
    37
    val sg = sign_of thy;
berghofe@11522
    38
    val lookup = lookup_thm thy;
berghofe@11522
    39
berghofe@13670
    40
    fun thm_of_atom thm Ts =
berghofe@13670
    41
      let
berghofe@13670
    42
        val tvars = term_tvars (prop_of thm);
berghofe@13670
    43
        val (thm', fmap) = Thm.varifyT' [] thm;
berghofe@13670
    44
        val ctye = map fst tvars @ map snd fmap ~~ map (Thm.ctyp_of sg) Ts
berghofe@13670
    45
      in
berghofe@13670
    46
        Thm.instantiate (ctye, []) (forall_intr_vars (forall_intr_frees thm'))
berghofe@13670
    47
      end;
berghofe@13670
    48
berghofe@11522
    49
    fun thm_of _ _ (PThm ((name, _), _, prop', Some Ts)) =
berghofe@11522
    50
          let
berghofe@13670
    51
            val thm = Thm.implies_intr_hyps (lookup name);
berghofe@11522
    52
            val {prop, ...} = rep_thm thm;
berghofe@13733
    53
            val _ = if prop aconv prop' then () else
berghofe@12238
    54
              error ("Duplicate use of theorem name " ^ quote name ^ "\n" ^
berghofe@12238
    55
                Sign.string_of_term sg prop ^ "\n\n" ^
berghofe@12238
    56
                Sign.string_of_term sg prop');
berghofe@13670
    57
          in thm_of_atom thm Ts end
berghofe@11522
    58
berghofe@11522
    59
      | thm_of _ _ (PAxm (name, _, Some Ts)) =
berghofe@13670
    60
          thm_of_atom (get_axiom thy name) Ts
berghofe@11522
    61
berghofe@11522
    62
      | thm_of _ Hs (PBound i) = nth_elem (i, Hs)
berghofe@11522
    63
berghofe@11522
    64
      | thm_of vs Hs (Abst (s, Some T, prf)) =
berghofe@11522
    65
          let
berghofe@11522
    66
            val x = variant (names @ map fst vs) s;
berghofe@11522
    67
            val thm = thm_of ((x, T) :: vs) Hs prf
berghofe@11522
    68
          in
berghofe@11522
    69
            Thm.forall_intr (Thm.cterm_of sg (Free (x, T))) thm
berghofe@11522
    70
          end
berghofe@11522
    71
berghofe@11612
    72
      | thm_of vs Hs (prf % Some t) =
berghofe@11522
    73
          let
berghofe@11522
    74
            val thm = thm_of vs Hs prf
berghofe@11522
    75
            val ct = Thm.cterm_of sg (Term.subst_bounds (map Free vs, t))
berghofe@11522
    76
          in Thm.forall_elim ct thm end
berghofe@11522
    77
berghofe@11522
    78
      | thm_of vs Hs (AbsP (s, Some t, prf)) =
berghofe@11522
    79
          let
berghofe@11522
    80
            val ct = Thm.cterm_of sg (Term.subst_bounds (map Free vs, t));
berghofe@11522
    81
            val thm = thm_of vs (Thm.assume ct :: Hs) prf
berghofe@11522
    82
          in
berghofe@11522
    83
            Thm.implies_intr ct thm
berghofe@11522
    84
          end
berghofe@11522
    85
berghofe@11612
    86
      | thm_of vs Hs (prf %% prf') =
berghofe@11522
    87
          let 
berghofe@11522
    88
            val thm = beta_eta_convert (thm_of vs Hs prf);
berghofe@11522
    89
            val thm' = beta_eta_convert (thm_of vs Hs prf')
berghofe@11522
    90
          in
berghofe@11522
    91
            Thm.implies_elim thm thm'
berghofe@11522
    92
          end
berghofe@11522
    93
berghofe@11522
    94
      | thm_of _ _ (Hyp t) = Thm.assume (Thm.cterm_of sg t)
berghofe@11522
    95
berghofe@11522
    96
      | thm_of _ _ _ = error "thm_of_proof: partial proof term";
berghofe@11522
    97
berghofe@13733
    98
  in beta_eta_convert (thm_of [] [] prf) end;
berghofe@11522
    99
berghofe@11522
   100
end;