src/HOL/Tools/Predicate_Compile/pred_compile_pred.ML
author wenzelm
Mon, 26 Oct 2009 20:42:08 +0100
changeset 33213 1b550123f133
parent 33150 75eddea4abef
permissions -rw-r--r--
forget old some old option stuff from NJ -- superceded by material in Pure/General/basics.ML;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
32668
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
     1
(* Author: Lukas Bulwahn, TU Muenchen
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
     2
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
     3
Preprocessing definitions of predicates to introduction rules
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
     4
*)
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
     5
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
     6
signature PREDICATE_COMPILE_PRED =
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
     7
sig
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
     8
  (* preprocesses an equation to a set of intro rules; defines new constants *)
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
     9
  (*
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    10
  val preprocess_pred_equation : thm -> theory -> thm list * theory
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    11
  *)
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    12
  val preprocess : string -> theory -> (thm list list * theory) 
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    13
  (* output is the term list of clauses of an unknown predicate *)
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    14
  val preprocess_term : term -> theory -> (term list * theory)
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    15
  
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    16
  (*val rewrite : thm -> thm*)
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    17
  
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    18
end;
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    19
(* : PREDICATE_COMPILE_PREPROC_PRED *)
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    20
structure Predicate_Compile_Pred =
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    21
struct
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    22
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    23
open Predicate_Compile_Aux
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    24
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    25
fun is_compound ((Const ("Not", _)) $ t) =
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    26
    error "is_compound: Negation should not occur; preprocessing is defect"
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    27
  | is_compound ((Const ("Ex", _)) $ _) = true
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    28
  | is_compound ((Const (@{const_name "op |"}, _)) $ _ $ _) = true
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    29
  | is_compound ((Const ("op &", _)) $ _ $ _) =
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    30
    error "is_compound: Conjunction should not occur; preprocessing is defect"
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    31
  | is_compound _ = false
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    32
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    33
fun flatten constname atom (defs, thy) =
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    34
  if is_compound atom then
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    35
    let
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    36
      val constname = Name.variant (map (Long_Name.base_name o fst) defs)
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    37
        ((Long_Name.base_name constname) ^ "_aux")
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    38
      val full_constname = Sign.full_bname thy constname
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    39
      val (params, args) = List.partition (is_predT o fastype_of)
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    40
        (map Free (Term.add_frees atom []))
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    41
      val constT = map fastype_of (params @ args) ---> HOLogic.boolT
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    42
      val lhs = list_comb (Const (full_constname, constT), params @ args)
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    43
      val def = Logic.mk_equals (lhs, atom)
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    44
      val ([definition], thy') = thy
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    45
        |> Sign.add_consts_i [(Binding.name constname, constT, NoSyn)]
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    46
        |> PureThy.add_defs false [((Binding.name (constname ^ "_def"), def), [])]
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    47
    in
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    48
      (lhs, ((full_constname, [definition]) :: defs, thy'))
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    49
    end
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    50
  else
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    51
    (atom, (defs, thy))
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    52
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    53
fun flatten_intros constname intros thy =
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    54
  let
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    55
    val ctxt = ProofContext.init thy
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    56
    val ((_, intros), ctxt') = Variable.import true intros ctxt
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    57
    val (intros', (local_defs, thy')) = (fold_map o fold_map_atoms)
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    58
      (flatten constname) (map prop_of intros) ([], thy)
32970
fbd2bb2489a8 operations of structure Skip_Proof (formerly SkipProof) no longer require quick_and_dirty mode;
wenzelm
parents: 32966
diff changeset
    59
    val tac = fn _ => Skip_Proof.cheat_tac thy'
32668
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    60
    val intros'' = map (fn t => Goal.prove ctxt' [] [] t tac) intros'
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    61
      |> Variable.export ctxt' ctxt
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    62
  in
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    63
    (intros'', (local_defs, thy'))
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    64
  end
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    65
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    66
(* TODO: same function occurs in inductive package *)
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    67
fun select_disj 1 1 = []
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    68
  | select_disj _ 1 = [rtac @{thm disjI1}]
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    69
  | select_disj n i = (rtac @{thm disjI2})::(select_disj (n - 1) (i - 1));
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    70
32672
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32669
diff changeset
    71
fun introrulify thy ths = 
32668
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    72
  let
32672
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32669
diff changeset
    73
    val ctxt = ProofContext.init thy
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32669
diff changeset
    74
    val ((_, ths'), ctxt') = Variable.import true ths ctxt
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32669
diff changeset
    75
    fun introrulify' th =
32668
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    76
      let
32672
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32669
diff changeset
    77
        val (lhs, rhs) = Logic.dest_equals (prop_of th)
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32669
diff changeset
    78
        val frees = Term.add_free_names rhs []
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32669
diff changeset
    79
        val disjuncts = HOLogic.dest_disj rhs
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32669
diff changeset
    80
        val nctxt = Name.make_context frees
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32669
diff changeset
    81
        fun mk_introrule t =
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32669
diff changeset
    82
          let
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32669
diff changeset
    83
            val ((ps, t'), nctxt') = focus_ex t nctxt
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32669
diff changeset
    84
            val prems = map HOLogic.mk_Trueprop (HOLogic.dest_conj t')
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32669
diff changeset
    85
          in
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32669
diff changeset
    86
            (ps, Logic.list_implies (prems, HOLogic.mk_Trueprop lhs))
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32669
diff changeset
    87
          end
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32669
diff changeset
    88
        val x = ((cterm_of thy) o the_single o snd o strip_comb o HOLogic.dest_Trueprop o fst o
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32669
diff changeset
    89
          Logic.dest_implies o prop_of) @{thm exI}
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32669
diff changeset
    90
        fun prove_introrule (index, (ps, introrule)) =
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32669
diff changeset
    91
          let
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32669
diff changeset
    92
            val tac = Simplifier.simp_tac (HOL_basic_ss addsimps [th]) 1
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32669
diff changeset
    93
              THEN EVERY1 (select_disj (length disjuncts) (index + 1)) 
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32669
diff changeset
    94
              THEN (EVERY (map (fn y =>
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32669
diff changeset
    95
                rtac (Drule.cterm_instantiate [(x, cterm_of thy (Free y))] @{thm exI}) 1) ps))
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32669
diff changeset
    96
              THEN REPEAT_DETERM (rtac @{thm conjI} 1 THEN atac 1)
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32669
diff changeset
    97
              THEN TRY (atac 1)
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32669
diff changeset
    98
          in
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32669
diff changeset
    99
            Goal.prove ctxt' (map fst ps) [] introrule (fn {...} => tac)
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32669
diff changeset
   100
          end
32668
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
   101
      in
32672
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32669
diff changeset
   102
        map_index prove_introrule (map mk_introrule disjuncts)
32668
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
   103
      end
32672
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32669
diff changeset
   104
  in maps introrulify' ths' |> Variable.export ctxt' ctxt end
32668
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
   105
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
   106
val rewrite =
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
   107
  Simplifier.simplify (HOL_basic_ss addsimps [@{thm Ball_def}, @{thm Bex_def}])
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
   108
  #> Simplifier.simplify (HOL_basic_ss addsimps [@{thm all_not_ex}]) 
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
   109
  #> Conv.fconv_rule nnf_conv 
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
   110
  #> Simplifier.simplify (HOL_basic_ss addsimps [@{thm ex_disj_distrib}])
32672
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32669
diff changeset
   111
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32669
diff changeset
   112
val rewrite_intros =
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32669
diff changeset
   113
  Simplifier.simplify (HOL_basic_ss addsimps @{thms HOL.simp_thms(9)})
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32669
diff changeset
   114
32668
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
   115
fun preprocess (constname, specs) thy =
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
   116
  let
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
   117
    val ctxt = ProofContext.init thy
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
   118
      val intros =
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
   119
      if forall is_pred_equation specs then 
32672
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32669
diff changeset
   120
        introrulify thy (map rewrite specs)
32668
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
   121
      else if forall (is_intro constname) specs then
32672
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32669
diff changeset
   122
        map rewrite_intros specs
32668
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
   123
      else
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
   124
        error ("unexpected specification for constant " ^ quote constname ^ ":\n"
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
   125
          ^ commas (map (quote o Display.string_of_thm_global thy) specs))
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
   126
    val (intros', (local_defs, thy')) = flatten_intros constname intros thy
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
   127
    val (intross, thy'') = fold_map preprocess local_defs thy'
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
   128
  in
33146
bf852ef586f2 now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents: 33138
diff changeset
   129
    ((constname, intros') :: flat intross,thy'')
32668
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
   130
  end;
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
   131
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
   132
fun preprocess_term t thy = error "preprocess_pred_term: to implement" 
33121
9b10dc5da0e0 added to process higher-order arguments by adding new constants
bulwahn
parents: 32672
diff changeset
   133
9b10dc5da0e0 added to process higher-order arguments by adding new constants
bulwahn
parents: 32672
diff changeset
   134
fun is_Abs (Abs _) = true
9b10dc5da0e0 added to process higher-order arguments by adding new constants
bulwahn
parents: 32672
diff changeset
   135
  | is_Abs _       = false
9b10dc5da0e0 added to process higher-order arguments by adding new constants
bulwahn
parents: 32672
diff changeset
   136
9b10dc5da0e0 added to process higher-order arguments by adding new constants
bulwahn
parents: 32672
diff changeset
   137
fun flat_higher_order_arguments (intross, thy) =
9b10dc5da0e0 added to process higher-order arguments by adding new constants
bulwahn
parents: 32672
diff changeset
   138
  let
9b10dc5da0e0 added to process higher-order arguments by adding new constants
bulwahn
parents: 32672
diff changeset
   139
    fun process constname atom (new_defs, thy) =
9b10dc5da0e0 added to process higher-order arguments by adding new constants
bulwahn
parents: 32672
diff changeset
   140
      let
9b10dc5da0e0 added to process higher-order arguments by adding new constants
bulwahn
parents: 32672
diff changeset
   141
        val (pred, args) = strip_comb atom
9b10dc5da0e0 added to process higher-order arguments by adding new constants
bulwahn
parents: 32672
diff changeset
   142
        val abs_args = filter is_Abs args
9b10dc5da0e0 added to process higher-order arguments by adding new constants
bulwahn
parents: 32672
diff changeset
   143
        fun replace_abs_arg (abs_arg as Abs _ ) (new_defs, thy) =
9b10dc5da0e0 added to process higher-order arguments by adding new constants
bulwahn
parents: 32672
diff changeset
   144
          let
9b10dc5da0e0 added to process higher-order arguments by adding new constants
bulwahn
parents: 32672
diff changeset
   145
            val _ = tracing ("Introduce new constant for " ^
9b10dc5da0e0 added to process higher-order arguments by adding new constants
bulwahn
parents: 32672
diff changeset
   146
              Syntax.string_of_term_global thy abs_arg)
9b10dc5da0e0 added to process higher-order arguments by adding new constants
bulwahn
parents: 32672
diff changeset
   147
            val vars = map Var (Term.add_vars abs_arg [])
9b10dc5da0e0 added to process higher-order arguments by adding new constants
bulwahn
parents: 32672
diff changeset
   148
            val abs_arg' = Logic.unvarify abs_arg
9b10dc5da0e0 added to process higher-order arguments by adding new constants
bulwahn
parents: 32672
diff changeset
   149
            val frees = map Free (Term.add_frees abs_arg' [])
33138
e2e23987c59a reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents: 33128
diff changeset
   150
            val constname = Name.variant (map (Long_Name.base_name o fst) new_defs)
33121
9b10dc5da0e0 added to process higher-order arguments by adding new constants
bulwahn
parents: 32672
diff changeset
   151
              ((Long_Name.base_name constname) ^ "_hoaux")
9b10dc5da0e0 added to process higher-order arguments by adding new constants
bulwahn
parents: 32672
diff changeset
   152
            val full_constname = Sign.full_bname thy constname
9b10dc5da0e0 added to process higher-order arguments by adding new constants
bulwahn
parents: 32672
diff changeset
   153
            val constT = map fastype_of frees ---> (fastype_of abs_arg')
9b10dc5da0e0 added to process higher-order arguments by adding new constants
bulwahn
parents: 32672
diff changeset
   154
            val const = Const (full_constname, constT)
9b10dc5da0e0 added to process higher-order arguments by adding new constants
bulwahn
parents: 32672
diff changeset
   155
            val lhs = list_comb (const, frees)
9b10dc5da0e0 added to process higher-order arguments by adding new constants
bulwahn
parents: 32672
diff changeset
   156
            val def = Logic.mk_equals (lhs, abs_arg')
9b10dc5da0e0 added to process higher-order arguments by adding new constants
bulwahn
parents: 32672
diff changeset
   157
            val _ = tracing (Syntax.string_of_term_global thy def)
9b10dc5da0e0 added to process higher-order arguments by adding new constants
bulwahn
parents: 32672
diff changeset
   158
            val ([definition], thy') = thy
9b10dc5da0e0 added to process higher-order arguments by adding new constants
bulwahn
parents: 32672
diff changeset
   159
              |> Sign.add_consts_i [(Binding.name constname, constT, NoSyn)]
9b10dc5da0e0 added to process higher-order arguments by adding new constants
bulwahn
parents: 32672
diff changeset
   160
              |> PureThy.add_defs false [((Binding.name (constname ^ "_def"), def), [])]
9b10dc5da0e0 added to process higher-order arguments by adding new constants
bulwahn
parents: 32672
diff changeset
   161
          in
9b10dc5da0e0 added to process higher-order arguments by adding new constants
bulwahn
parents: 32672
diff changeset
   162
            (list_comb (Logic.varify const, vars), ((full_constname, [definition])::new_defs, thy'))
9b10dc5da0e0 added to process higher-order arguments by adding new constants
bulwahn
parents: 32672
diff changeset
   163
          end
9b10dc5da0e0 added to process higher-order arguments by adding new constants
bulwahn
parents: 32672
diff changeset
   164
        | replace_abs_arg arg (new_defs, thy) = (arg, (new_defs, thy))
33146
bf852ef586f2 now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents: 33138
diff changeset
   165
        val (args', (new_defs', thy')) = fold_map replace_abs_arg args (new_defs, thy)
33121
9b10dc5da0e0 added to process higher-order arguments by adding new constants
bulwahn
parents: 32672
diff changeset
   166
      in
9b10dc5da0e0 added to process higher-order arguments by adding new constants
bulwahn
parents: 32672
diff changeset
   167
        (list_comb (pred, args'), (new_defs', thy'))
9b10dc5da0e0 added to process higher-order arguments by adding new constants
bulwahn
parents: 32672
diff changeset
   168
      end
9b10dc5da0e0 added to process higher-order arguments by adding new constants
bulwahn
parents: 32672
diff changeset
   169
    fun flat_intro intro (new_defs, thy) =
9b10dc5da0e0 added to process higher-order arguments by adding new constants
bulwahn
parents: 32672
diff changeset
   170
      let
33128
1f990689349f further cleaning up
bulwahn
parents: 33123
diff changeset
   171
        val constname = fst (dest_Const (fst (strip_comb
1f990689349f further cleaning up
bulwahn
parents: 33123
diff changeset
   172
          (HOLogic.dest_Trueprop (Logic.strip_imp_concl (prop_of intro))))))
33121
9b10dc5da0e0 added to process higher-order arguments by adding new constants
bulwahn
parents: 32672
diff changeset
   173
        val (intro_ts, (new_defs, thy)) = fold_map_atoms (process constname) (prop_of intro) (new_defs, thy)
33150
75eddea4abef further changes due to the previous merge in the predicate compiler
bulwahn
parents: 33149
diff changeset
   174
        val th = Skip_Proof.make_thm thy intro_ts
33121
9b10dc5da0e0 added to process higher-order arguments by adding new constants
bulwahn
parents: 32672
diff changeset
   175
      in
9b10dc5da0e0 added to process higher-order arguments by adding new constants
bulwahn
parents: 32672
diff changeset
   176
        (th, (new_defs, thy))
9b10dc5da0e0 added to process higher-order arguments by adding new constants
bulwahn
parents: 32672
diff changeset
   177
      end
33146
bf852ef586f2 now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents: 33138
diff changeset
   178
    fun fold_map_spec f [] s = ([], s)
bf852ef586f2 now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents: 33138
diff changeset
   179
      | fold_map_spec f ((c, ths) :: specs) s =
bf852ef586f2 now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents: 33138
diff changeset
   180
        let
bf852ef586f2 now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents: 33138
diff changeset
   181
          val (ths', s') = f ths s
bf852ef586f2 now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents: 33138
diff changeset
   182
          val (specs', s'') = fold_map_spec f specs s'
bf852ef586f2 now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents: 33138
diff changeset
   183
        in ((c, ths') :: specs', s'') end
bf852ef586f2 now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents: 33138
diff changeset
   184
    val (intross', (new_defs, thy')) = fold_map_spec (fold_map flat_intro) intross ([], thy)
33121
9b10dc5da0e0 added to process higher-order arguments by adding new constants
bulwahn
parents: 32672
diff changeset
   185
  in
9b10dc5da0e0 added to process higher-order arguments by adding new constants
bulwahn
parents: 32672
diff changeset
   186
    (intross', (new_defs, thy'))
9b10dc5da0e0 added to process higher-order arguments by adding new constants
bulwahn
parents: 32672
diff changeset
   187
  end
9b10dc5da0e0 added to process higher-order arguments by adding new constants
bulwahn
parents: 32672
diff changeset
   188
32668
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
   189
end;