src/ZF/Tools/cartprod.ML
author wenzelm
Fri, 04 Jan 2019 23:22:53 +0100
changeset 69593 3dda49e08b9d
parent 60642 48dd1cefb4ae
child 74282 c2ee8d993d6a
permissions -rw-r--r--
isabelle update -u control_cartouches;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24584
01e83ffa6c54 fixed title
haftmann
parents: 22596
diff changeset
     1
(*  Title:      ZF/Tools/cartprod.ML
6049
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
     2
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
     3
    Copyright   1996  University of Cambridge
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
     4
35762
af3ff2ba4c54 removed old CVS Ids;
wenzelm
parents: 33957
diff changeset
     5
Signatures for inductive definitions.
6049
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
     6
35762
af3ff2ba4c54 removed old CVS Ids;
wenzelm
parents: 33957
diff changeset
     7
Syntactic operations for Cartesian Products.
6049
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
     8
*)
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
     9
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    10
signature FP =          (** Description of a fixed point operator **)
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    11
  sig
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    12
  val oper      : term                  (*fixed point operator*)
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    13
  val bnd_mono  : term                  (*monotonicity predicate*)
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    14
  val bnd_monoI : thm                   (*intro rule for bnd_mono*)
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    15
  val subs      : thm                   (*subset theorem for fp*)
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    16
  val Tarski    : thm                   (*Tarski's fixed point theorem*)
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    17
  val induct    : thm                   (*induction/coinduction rule*)
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    18
  end;
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    19
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    20
signature SU =                  (** Description of a disjoint sum **)
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    21
  sig
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    22
  val sum       : term                  (*disjoint sum operator*)
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    23
  val inl       : term                  (*left injection*)
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    24
  val inr       : term                  (*right injection*)
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    25
  val elim      : term                  (*case operator*)
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    26
  val case_inl  : thm                   (*inl equality rule for case*)
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    27
  val case_inr  : thm                   (*inr equality rule for case*)
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    28
  val inl_iff   : thm                   (*injectivity of inl, using <->*)
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    29
  val inr_iff   : thm                   (*injectivity of inr, using <->*)
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    30
  val distinct  : thm                   (*distinctness of inl, inr using <->*)
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    31
  val distinct' : thm                   (*distinctness of inr, inl using <->*)
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    32
  val free_SEs  : thm list              (*elim rules for SU, and pair_iff!*)
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    33
  end;
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    34
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    35
signature PR =                  (** Description of a Cartesian product **)
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    36
  sig
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    37
  val sigma     : term                  (*Cartesian product operator*)
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    38
  val pair      : term                  (*pairing operator*)
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    39
  val split_name : string               (*name of polymorphic split*)
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    40
  val pair_iff  : thm                   (*injectivity of pairing, using <->*)
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    41
  val split_eq  : thm                   (*equality rule for split*)
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    42
  val fsplitI   : thm                   (*intro rule for fsplit*)
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    43
  val fsplitD   : thm                   (*destruct rule for fsplit*)
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    44
  val fsplitE   : thm                   (*elim rule; apparently never used*)
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    45
  end;
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    46
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    47
signature CARTPROD =            (** Derived syntactic functions for produts **)
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    48
  sig
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    49
  val ap_split : typ -> typ -> term -> term
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    50
  val factors : typ -> typ list
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    51
  val mk_prod : typ * typ -> typ
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    52
  val mk_tuple : term -> typ -> term list -> term
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    53
  val pseudo_type : term -> typ
54742
7a86358a3c0b proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents: 43333
diff changeset
    54
  val remove_split : Proof.context -> thm -> thm
6049
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    55
  val split_const : typ -> term
54742
7a86358a3c0b proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents: 43333
diff changeset
    56
  val split_rule_var : Proof.context -> term * typ * thm -> thm
6049
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    57
  end;
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    58
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    59
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    60
functor CartProd_Fun (Pr: PR) : CARTPROD =
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    61
struct
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    62
15674
4a1d07bb53e2 reverted renaming of Some/None in comments and strings;
wenzelm
parents: 15570
diff changeset
    63
(* Some of these functions expect "pseudo-types" containing products,
6049
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    64
   as in HOL; the true ZF types would just be "i" *)
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    65
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    66
fun mk_prod (T1,T2) = Type("*", [T1,T2]);
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    67
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    68
(*Bogus product type underlying a (possibly nested) Sigma.  
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    69
  Lets us share HOL code*)
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    70
fun pseudo_type (t $ A $ Abs(_,_,B)) = 
26189
9808cca5c54d misc cleanup of embedded ML code;
wenzelm
parents: 24584
diff changeset
    71
      if t = Pr.sigma
9808cca5c54d misc cleanup of embedded ML code;
wenzelm
parents: 24584
diff changeset
    72
      then mk_prod(pseudo_type A, pseudo_type B)
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 60642
diff changeset
    73
      else \<^typ>\<open>i\<close>
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 60642
diff changeset
    74
  | pseudo_type _ = \<^typ>\<open>i\<close>;
6049
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    75
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    76
(*Maps the type T1*...*Tn to [T1,...,Tn], however nested*)
26189
9808cca5c54d misc cleanup of embedded ML code;
wenzelm
parents: 24584
diff changeset
    77
fun factors (Type("*", [T1, T2])) = factors T1 @ factors T2
9808cca5c54d misc cleanup of embedded ML code;
wenzelm
parents: 24584
diff changeset
    78
  | factors T                     = [T];
6049
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    79
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    80
(*Make a well-typed instance of "split"*)
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    81
fun split_const T = Const(Pr.split_name, 
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    82
                          [[Ind_Syntax.iT, Ind_Syntax.iT]--->T, 
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    83
                           Ind_Syntax.iT] ---> T);
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    84
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    85
(*In ap_split S T u, term u expects separate arguments for the factors of S,
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    86
  with result type T.  The call creates a new term expecting one argument
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    87
  of type S.*)
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    88
fun ap_split (Type("*", [T1,T2])) T3 u   = 
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    89
       split_const T3 $ 
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    90
       Abs("v", Ind_Syntax.iT, (*Not T1, as it involves pseudo-product types*)
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    91
           ap_split T2 T3
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    92
           ((ap_split T1 (factors T2 ---> T3) (incr_boundvars 1 u)) $ 
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    93
            Bound 0))
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    94
  | ap_split T T3 u = u;
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    95
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    96
(*Makes a nested tuple from a list, following the product type structure*)
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
    97
fun mk_tuple pair (Type("*", [T1,T2])) tms = 
33957
e9afca2118d4 normalized uncurry take/drop
haftmann
parents: 33955
diff changeset
    98
        pair $ mk_tuple pair T1 tms
e9afca2118d4 normalized uncurry take/drop
haftmann
parents: 33955
diff changeset
    99
             $ mk_tuple pair T2 (drop (length (factors T1)) tms)
6049
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
   100
  | mk_tuple pair T (t::_) = t;
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
   101
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
   102
(*Attempts to remove occurrences of split, and pair-valued parameters*)
54742
7a86358a3c0b proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents: 43333
diff changeset
   103
fun remove_split ctxt = rewrite_rule ctxt [Pr.split_eq];
6049
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
   104
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
   105
(*Uncurries any Var according to its "pseudo-product type" T1 in the rule*)
54742
7a86358a3c0b proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents: 43333
diff changeset
   106
fun split_rule_var ctxt (Var(v,_), Type("fun",[T1,T2]), rl) =
6049
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
   107
      let val T' = factors T1 ---> T2
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
   108
          val newt = ap_split T1 T2 (Var(v,T'))
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
   109
      in
59626
a6e977d8b070 clarified context;
wenzelm
parents: 59621
diff changeset
   110
        remove_split ctxt
a6e977d8b070 clarified context;
wenzelm
parents: 59621
diff changeset
   111
          (Drule.instantiate_normalize ([],
60642
48dd1cefb4ae simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
wenzelm
parents: 59626
diff changeset
   112
            [((v, Ind_Syntax.iT-->T2), Thm.cterm_of ctxt newt)]) rl)
6049
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
   113
      end
54742
7a86358a3c0b proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents: 43333
diff changeset
   114
  | split_rule_var _ (t,T,rl) = rl;
6049
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
   115
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
   116
end;
7fef0169ab5e moved from ZF to new subdirectory Tools
paulson
parents:
diff changeset
   117