Nominal-General/nominal_eqvt.ML
author Christian Urban <urbanc@in.tum.de>
Sat, 15 May 2010 22:06:06 +0100
changeset 2140 8beda0b4e35a
parent 2117 b3a5bda07007
child 2168 ce0255ffaeb4
permissions -rw-r--r--
tuned paper
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1833
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
(*  Title:      nominal_eqvt.ML
1835
636de31888a6 tuned and removed dead code
Christian Urban <urbanc@in.tum.de>
parents: 1833
diff changeset
     2
    Author:     Stefan Berghofer (original code)
1833
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
    Author:     Christian Urban
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
    Automatic proofs for equivariance of inductive predicates.
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
*)
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
signature NOMINAL_EQVT =
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
sig
1835
636de31888a6 tuned and removed dead code
Christian Urban <urbanc@in.tum.de>
parents: 1833
diff changeset
    10
  val eqvt_rel_tac: Proof.context -> string list -> term -> thm -> thm list -> int -> tactic
1948
Christian Urban <urbanc@in.tum.de>
parents: 1866
diff changeset
    11
  val eqvt_rel_single_case_tac: Proof.context -> string list -> term -> thm -> int -> tactic
2107
5686d83db1f9 ingnored parameters in equivariance; added a proper interface to be called from ML
Christian Urban <urbanc@in.tum.de>
parents: 2081
diff changeset
    12
  
2110
872187804ff5 better ML-interface (returning only a list of theorems and a context)
Christian Urban <urbanc@in.tum.de>
parents: 2107
diff changeset
    13
  val equivariance: term list -> thm -> thm list -> Proof.context -> thm list * local_theory
2107
5686d83db1f9 ingnored parameters in equivariance; added a proper interface to be called from ML
Christian Urban <urbanc@in.tum.de>
parents: 2081
diff changeset
    14
  val equivariance_cmd: string -> Proof.context -> local_theory
1833
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
end
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
structure Nominal_Eqvt : NOMINAL_EQVT =
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
struct
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
open Nominal_Permeq;
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
open Nominal_ThmDecls;
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
val atomize_conv = 
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
  MetaSimplifier.rewrite_cterm (true, false, false) (K (K NONE))
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
    (HOL_basic_ss addsimps @{thms induct_atomize});
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
val atomize_intr = Conv.fconv_rule (Conv.prems_conv ~1 atomize_conv);
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
fun atomize_induct ctxt = Conv.fconv_rule (Conv.prems_conv ~1
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
  (Conv.params_conv ~1 (K (Conv.prems_conv ~1 atomize_conv)) ctxt));
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
1835
636de31888a6 tuned and removed dead code
Christian Urban <urbanc@in.tum.de>
parents: 1833
diff changeset
    30
636de31888a6 tuned and removed dead code
Christian Urban <urbanc@in.tum.de>
parents: 1833
diff changeset
    31
(** 
1948
Christian Urban <urbanc@in.tum.de>
parents: 1866
diff changeset
    32
 given the theorem F[t]; proves the theorem F[f t] 
Christian Urban <urbanc@in.tum.de>
parents: 1866
diff changeset
    33
1835
636de31888a6 tuned and removed dead code
Christian Urban <urbanc@in.tum.de>
parents: 1833
diff changeset
    34
  - F needs to be monotone
1948
Christian Urban <urbanc@in.tum.de>
parents: 1866
diff changeset
    35
  - f returns either SOME for a term it fires on 
1835
636de31888a6 tuned and removed dead code
Christian Urban <urbanc@in.tum.de>
parents: 1833
diff changeset
    36
    and NONE elsewhere 
636de31888a6 tuned and removed dead code
Christian Urban <urbanc@in.tum.de>
parents: 1833
diff changeset
    37
**)
1833
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
fun map_term f t = 
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
  (case f t of
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
     NONE => map_term' f t 
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
   | x => x)
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
and map_term' f (t $ u) = 
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
    (case (map_term f t, map_term f u) of
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
        (NONE, NONE) => NONE
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
      | (SOME t'', NONE) => SOME (t'' $ u)
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
      | (NONE, SOME u'') => SOME (t $ u'')
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
      | (SOME t'', SOME u'') => SOME (t'' $ u''))
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
  | map_term' f (Abs (s, T, t)) = 
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
      (case map_term f t of
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
        NONE => NONE
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
      | SOME t'' => SOME (Abs (s, T, t'')))
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
  | map_term' _ _  = NONE;
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
fun map_thm_tac ctxt tac thm =
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
let
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
  val monos = Inductive.get_monos ctxt
2081
9e7cf0a996d3 fixed the problem with alpha containing splits
Christian Urban <urbanc@in.tum.de>
parents: 2069
diff changeset
    57
  val simps = HOL_basic_ss addsimps @{thms split_def}
1833
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
in
2081
9e7cf0a996d3 fixed the problem with alpha containing splits
Christian Urban <urbanc@in.tum.de>
parents: 2069
diff changeset
    59
  EVERY [cut_facts_tac [thm] 1, etac rev_mp 1, 
9e7cf0a996d3 fixed the problem with alpha containing splits
Christian Urban <urbanc@in.tum.de>
parents: 2069
diff changeset
    60
    REPEAT_DETERM (FIRSTGOAL (simp_tac simps THEN' resolve_tac monos)),
1833
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
    REPEAT_DETERM (rtac impI 1 THEN (atac 1 ORELSE tac))]
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
end
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
fun map_thm ctxt f tac thm =
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
let
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
  val opt_goal_trm = map_term f (prop_of thm)
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
in
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
  case opt_goal_trm of
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
    NONE => thm
1835
636de31888a6 tuned and removed dead code
Christian Urban <urbanc@in.tum.de>
parents: 1833
diff changeset
    70
  | SOME goal =>
636de31888a6 tuned and removed dead code
Christian Urban <urbanc@in.tum.de>
parents: 1833
diff changeset
    71
     Goal.prove ctxt [] [] goal (fn _ => map_thm_tac ctxt tac thm) 
1833
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
end
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
1835
636de31888a6 tuned and removed dead code
Christian Urban <urbanc@in.tum.de>
parents: 1833
diff changeset
    74
(*
636de31888a6 tuned and removed dead code
Christian Urban <urbanc@in.tum.de>
parents: 1833
diff changeset
    75
 inductive premises can be of the form
636de31888a6 tuned and removed dead code
Christian Urban <urbanc@in.tum.de>
parents: 1833
diff changeset
    76
 R ... /\ P ...; split_conj picks out
636de31888a6 tuned and removed dead code
Christian Urban <urbanc@in.tum.de>
parents: 1833
diff changeset
    77
 the part P ...
636de31888a6 tuned and removed dead code
Christian Urban <urbanc@in.tum.de>
parents: 1833
diff changeset
    78
*)
1833
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
fun transform_prem ctxt names thm =
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
let
2064
2725853f43b9 solved the problem with equivariance by first eta-normalising the goal
Christian Urban <urbanc@in.tum.de>
parents: 1948
diff changeset
    81
  fun split_conj names (Const ("op &", _) $ f1 $ f2) = 
2725853f43b9 solved the problem with equivariance by first eta-normalising the goal
Christian Urban <urbanc@in.tum.de>
parents: 1948
diff changeset
    82
      (case head_of f1 of
2069
2b6ba4d4e19a Fixes for new isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2064
diff changeset
    83
         Const (name, _) => if member (op =) names name then SOME f2 else NONE
1833
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
       | _ => NONE)
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
  | split_conj _ _ = NONE;
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
in
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
  map_thm ctxt (split_conj names) (etac conjunct2 1) thm
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
end
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
1835
636de31888a6 tuned and removed dead code
Christian Urban <urbanc@in.tum.de>
parents: 1833
diff changeset
    90
636de31888a6 tuned and removed dead code
Christian Urban <urbanc@in.tum.de>
parents: 1833
diff changeset
    91
(** equivariance tactics **)
636de31888a6 tuned and removed dead code
Christian Urban <urbanc@in.tum.de>
parents: 1833
diff changeset
    92
1866
6d4e4bf9bce6 automatic proofs for equivariance of alphas
Christian Urban <urbanc@in.tum.de>
parents: 1861
diff changeset
    93
val perm_boolE = @{thm permute_boolE}
6d4e4bf9bce6 automatic proofs for equivariance of alphas
Christian Urban <urbanc@in.tum.de>
parents: 1861
diff changeset
    94
val perm_cancel = @{thms permute_minus_cancel(2)}
6d4e4bf9bce6 automatic proofs for equivariance of alphas
Christian Urban <urbanc@in.tum.de>
parents: 1861
diff changeset
    95
1948
Christian Urban <urbanc@in.tum.de>
parents: 1866
diff changeset
    96
fun eqvt_rel_single_case_tac ctxt pred_names pi intro  = 
1833
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
let
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
  val thy = ProofContext.theory_of ctxt
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
  val cpi = Thm.cterm_of thy (mk_minus pi)
1866
6d4e4bf9bce6 automatic proofs for equivariance of alphas
Christian Urban <urbanc@in.tum.de>
parents: 1861
diff changeset
   100
  val pi_intro_rule = Drule.instantiate' [] [SOME cpi] perm_boolE
2081
9e7cf0a996d3 fixed the problem with alpha containing splits
Christian Urban <urbanc@in.tum.de>
parents: 2069
diff changeset
   101
  val simps1 = HOL_basic_ss addsimps @{thms permute_fun_def minus_minus split_paired_all}
9e7cf0a996d3 fixed the problem with alpha containing splits
Christian Urban <urbanc@in.tum.de>
parents: 2069
diff changeset
   102
  val simps2 = HOL_basic_ss addsimps @{thms permute_bool_def}
1833
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
in
2081
9e7cf0a996d3 fixed the problem with alpha containing splits
Christian Urban <urbanc@in.tum.de>
parents: 2069
diff changeset
   104
  eqvt_strict_tac ctxt [] pred_names THEN'
1866
6d4e4bf9bce6 automatic proofs for equivariance of alphas
Christian Urban <urbanc@in.tum.de>
parents: 1861
diff changeset
   105
  SUBPROOF (fn {prems, context as ctxt, ...} =>
1833
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
    let
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
      val prems' = map (transform_prem ctxt pred_names) prems
1866
6d4e4bf9bce6 automatic proofs for equivariance of alphas
Christian Urban <urbanc@in.tum.de>
parents: 1861
diff changeset
   108
      val tac1 = resolve_tac prems'
6d4e4bf9bce6 automatic proofs for equivariance of alphas
Christian Urban <urbanc@in.tum.de>
parents: 1861
diff changeset
   109
      val tac2 = EVERY' [ rtac pi_intro_rule, 
6d4e4bf9bce6 automatic proofs for equivariance of alphas
Christian Urban <urbanc@in.tum.de>
parents: 1861
diff changeset
   110
            eqvt_strict_tac ctxt perm_cancel pred_names, resolve_tac prems' ]
6d4e4bf9bce6 automatic proofs for equivariance of alphas
Christian Urban <urbanc@in.tum.de>
parents: 1861
diff changeset
   111
      val tac3 = EVERY' [ rtac pi_intro_rule, 
2081
9e7cf0a996d3 fixed the problem with alpha containing splits
Christian Urban <urbanc@in.tum.de>
parents: 2069
diff changeset
   112
            eqvt_strict_tac ctxt perm_cancel pred_names, simp_tac simps1, 
9e7cf0a996d3 fixed the problem with alpha containing splits
Christian Urban <urbanc@in.tum.de>
parents: 2069
diff changeset
   113
            simp_tac simps2, resolve_tac prems']
1833
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
    in
1866
6d4e4bf9bce6 automatic proofs for equivariance of alphas
Christian Urban <urbanc@in.tum.de>
parents: 1861
diff changeset
   115
      (rtac intro THEN_ALL_NEW FIRST' [tac1, tac2, tac3]) 1 
1833
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
    end) ctxt
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
end
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
1835
636de31888a6 tuned and removed dead code
Christian Urban <urbanc@in.tum.de>
parents: 1833
diff changeset
   119
fun eqvt_rel_tac ctxt pred_names pi induct intros =
636de31888a6 tuned and removed dead code
Christian Urban <urbanc@in.tum.de>
parents: 1833
diff changeset
   120
let
1948
Christian Urban <urbanc@in.tum.de>
parents: 1866
diff changeset
   121
  val cases = map (eqvt_rel_single_case_tac ctxt pred_names pi) intros
1835
636de31888a6 tuned and removed dead code
Christian Urban <urbanc@in.tum.de>
parents: 1833
diff changeset
   122
in
636de31888a6 tuned and removed dead code
Christian Urban <urbanc@in.tum.de>
parents: 1833
diff changeset
   123
  EVERY' (rtac induct :: cases)
636de31888a6 tuned and removed dead code
Christian Urban <urbanc@in.tum.de>
parents: 1833
diff changeset
   124
end
1833
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   125
1835
636de31888a6 tuned and removed dead code
Christian Urban <urbanc@in.tum.de>
parents: 1833
diff changeset
   126
636de31888a6 tuned and removed dead code
Christian Urban <urbanc@in.tum.de>
parents: 1833
diff changeset
   127
(** equivariance procedure *)
636de31888a6 tuned and removed dead code
Christian Urban <urbanc@in.tum.de>
parents: 1833
diff changeset
   128
636de31888a6 tuned and removed dead code
Christian Urban <urbanc@in.tum.de>
parents: 1833
diff changeset
   129
(* sets up goal and makes sure parameters
636de31888a6 tuned and removed dead code
Christian Urban <urbanc@in.tum.de>
parents: 1833
diff changeset
   130
   are untouched PROBLEM: this violates the 
636de31888a6 tuned and removed dead code
Christian Urban <urbanc@in.tum.de>
parents: 1833
diff changeset
   131
   form of eqvt lemmas *)
2107
5686d83db1f9 ingnored parameters in equivariance; added a proper interface to be called from ML
Christian Urban <urbanc@in.tum.de>
parents: 2081
diff changeset
   132
fun prepare_goal pi pred =
1833
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   133
let
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   134
  val (c, xs) = strip_comb pred;
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   135
in
2107
5686d83db1f9 ingnored parameters in equivariance; added a proper interface to be called from ML
Christian Urban <urbanc@in.tum.de>
parents: 2081
diff changeset
   136
  HOLogic.mk_imp (pred, list_comb (c, map (mk_perm pi) xs))
1833
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   137
end
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   138
1835
636de31888a6 tuned and removed dead code
Christian Urban <urbanc@in.tum.de>
parents: 1833
diff changeset
   139
(* stores thm under name.eqvt and adds [eqvt]-attribute *)
1833
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   140
fun note_named_thm (name, thm) ctxt = 
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   141
let
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   142
  val thm_name = Binding.qualified_name 
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   143
    (Long_Name.qualify (Long_Name.base_name name) "eqvt")
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   144
  val attr = Attrib.internal (K eqvt_add)
2110
872187804ff5 better ML-interface (returning only a list of theorems and a context)
Christian Urban <urbanc@in.tum.de>
parents: 2107
diff changeset
   145
  val ((_, [thm']), ctxt') =  Local_Theory.note ((thm_name, [attr]), [thm]) ctxt
1833
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   146
in
2110
872187804ff5 better ML-interface (returning only a list of theorems and a context)
Christian Urban <urbanc@in.tum.de>
parents: 2107
diff changeset
   147
  (thm', ctxt')
1833
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   148
end
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   149
2107
5686d83db1f9 ingnored parameters in equivariance; added a proper interface to be called from ML
Christian Urban <urbanc@in.tum.de>
parents: 2081
diff changeset
   150
fun equivariance pred_trms raw_induct intrs ctxt = 
1833
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   151
let
2117
b3a5bda07007 added a test whether some of the constants already equivariant (then the procedure has to fail).
Christian Urban <urbanc@in.tum.de>
parents: 2110
diff changeset
   152
  val is_already_eqvt = 
b3a5bda07007 added a test whether some of the constants already equivariant (then the procedure has to fail).
Christian Urban <urbanc@in.tum.de>
parents: 2110
diff changeset
   153
    filter (is_eqvt ctxt) pred_trms
b3a5bda07007 added a test whether some of the constants already equivariant (then the procedure has to fail).
Christian Urban <urbanc@in.tum.de>
parents: 2110
diff changeset
   154
    |> map (Syntax.string_of_term ctxt)
b3a5bda07007 added a test whether some of the constants already equivariant (then the procedure has to fail).
Christian Urban <urbanc@in.tum.de>
parents: 2110
diff changeset
   155
  val _ = if null is_already_eqvt then ()
b3a5bda07007 added a test whether some of the constants already equivariant (then the procedure has to fail).
Christian Urban <urbanc@in.tum.de>
parents: 2110
diff changeset
   156
    else error ("Already equivariant: " ^ commas is_already_eqvt)
b3a5bda07007 added a test whether some of the constants already equivariant (then the procedure has to fail).
Christian Urban <urbanc@in.tum.de>
parents: 2110
diff changeset
   157
2107
5686d83db1f9 ingnored parameters in equivariance; added a proper interface to be called from ML
Christian Urban <urbanc@in.tum.de>
parents: 2081
diff changeset
   158
  val pred_names = map (fst o dest_Const) pred_trms
5686d83db1f9 ingnored parameters in equivariance; added a proper interface to be called from ML
Christian Urban <urbanc@in.tum.de>
parents: 2081
diff changeset
   159
  val raw_induct' = atomize_induct ctxt raw_induct
5686d83db1f9 ingnored parameters in equivariance; added a proper interface to be called from ML
Christian Urban <urbanc@in.tum.de>
parents: 2081
diff changeset
   160
  val intrs' = map atomize_intr intrs
1948
Christian Urban <urbanc@in.tum.de>
parents: 1866
diff changeset
   161
  val (([raw_concl], [raw_pi]), ctxt') = 
Christian Urban <urbanc@in.tum.de>
parents: 1866
diff changeset
   162
    ctxt 
2107
5686d83db1f9 ingnored parameters in equivariance; added a proper interface to be called from ML
Christian Urban <urbanc@in.tum.de>
parents: 2081
diff changeset
   163
    |> Variable.import_terms false [concl_of raw_induct'] 
1948
Christian Urban <urbanc@in.tum.de>
parents: 1866
diff changeset
   164
    ||>> Variable.variant_fixes ["p"]
1833
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   165
  val pi = Free (raw_pi, @{typ perm})
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   166
  val preds = map (fst o HOLogic.dest_imp)
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   167
    (HOLogic.dest_conj (HOLogic.dest_Trueprop raw_concl));
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   168
  val goal = HOLogic.mk_Trueprop 
2107
5686d83db1f9 ingnored parameters in equivariance; added a proper interface to be called from ML
Christian Urban <urbanc@in.tum.de>
parents: 2081
diff changeset
   169
    (foldr1 HOLogic.mk_conj (map (prepare_goal pi) preds))
1835
636de31888a6 tuned and removed dead code
Christian Urban <urbanc@in.tum.de>
parents: 1833
diff changeset
   170
  val thms = Datatype_Aux.split_conj_thm (Goal.prove ctxt' [] [] goal 
2107
5686d83db1f9 ingnored parameters in equivariance; added a proper interface to be called from ML
Christian Urban <urbanc@in.tum.de>
parents: 2081
diff changeset
   171
    (fn {context,...} => eqvt_rel_tac context pred_names pi raw_induct' intrs' 1)
1835
636de31888a6 tuned and removed dead code
Christian Urban <urbanc@in.tum.de>
parents: 1833
diff changeset
   172
    |> singleton (ProofContext.export ctxt' ctxt))
636de31888a6 tuned and removed dead code
Christian Urban <urbanc@in.tum.de>
parents: 1833
diff changeset
   173
  val thms' = map (fn th => zero_var_indexes (th RS mp)) thms
1833
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   174
in
2107
5686d83db1f9 ingnored parameters in equivariance; added a proper interface to be called from ML
Christian Urban <urbanc@in.tum.de>
parents: 2081
diff changeset
   175
  ctxt |> fold_map note_named_thm (pred_names ~~ thms')   
1833
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   176
end
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   177
2107
5686d83db1f9 ingnored parameters in equivariance; added a proper interface to be called from ML
Christian Urban <urbanc@in.tum.de>
parents: 2081
diff changeset
   178
fun equivariance_cmd pred_name ctxt =
5686d83db1f9 ingnored parameters in equivariance; added a proper interface to be called from ML
Christian Urban <urbanc@in.tum.de>
parents: 2081
diff changeset
   179
let
5686d83db1f9 ingnored parameters in equivariance; added a proper interface to be called from ML
Christian Urban <urbanc@in.tum.de>
parents: 2081
diff changeset
   180
  val thy = ProofContext.theory_of ctxt
5686d83db1f9 ingnored parameters in equivariance; added a proper interface to be called from ML
Christian Urban <urbanc@in.tum.de>
parents: 2081
diff changeset
   181
  val (_, {preds, raw_induct, intrs, ...}) =
5686d83db1f9 ingnored parameters in equivariance; added a proper interface to be called from ML
Christian Urban <urbanc@in.tum.de>
parents: 2081
diff changeset
   182
    Inductive.the_inductive ctxt (Sign.intern_const thy pred_name)
5686d83db1f9 ingnored parameters in equivariance; added a proper interface to be called from ML
Christian Urban <urbanc@in.tum.de>
parents: 2081
diff changeset
   183
in
5686d83db1f9 ingnored parameters in equivariance; added a proper interface to be called from ML
Christian Urban <urbanc@in.tum.de>
parents: 2081
diff changeset
   184
  equivariance preds raw_induct intrs ctxt |> snd
5686d83db1f9 ingnored parameters in equivariance; added a proper interface to be called from ML
Christian Urban <urbanc@in.tum.de>
parents: 2081
diff changeset
   185
end
1833
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   186
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   187
local structure P = OuterParse and K = OuterKeyword in
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   188
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   189
val _ =
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   190
  OuterSyntax.local_theory "equivariance"
1948
Christian Urban <urbanc@in.tum.de>
parents: 1866
diff changeset
   191
    "Proves equivariance for inductive predicate involving nominal datatypes." 
2107
5686d83db1f9 ingnored parameters in equivariance; added a proper interface to be called from ML
Christian Urban <urbanc@in.tum.de>
parents: 2081
diff changeset
   192
      K.thy_decl (P.xname >> equivariance_cmd);
1833
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   193
end;
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   194
2069
2b6ba4d4e19a Fixes for new isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2064
diff changeset
   195
end (* structure *)