src/HOLCF/Tools/Domain/domain_axioms.ML
author huffman
Tue, 02 Mar 2010 17:21:10 -0800
changeset 35525 fa231b86cb1e
parent 35517 0e2ef13796a4
child 35529 089e438b925b
permissions -rw-r--r--
proper names for types cfun, sprod, ssum
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
32126
a5042f260440 obey captialized directory names convention
haftmann
parents: 31738
diff changeset
     1
(*  Title:      HOLCF/Tools/Domain/domain_axioms.ML
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
     2
    Author:     David von Oheimb
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
     3
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
     4
Syntax generator for domain command.
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
     5
*)
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
     6
30919
dcf8a7a66bd1 make domain package ML interface more consistent with datatype package; use binding instead of bstring
huffman
parents: 30912
diff changeset
     7
signature DOMAIN_AXIOMS =
dcf8a7a66bd1 make domain package ML interface more consistent with datatype package; use binding instead of bstring
huffman
parents: 30912
diff changeset
     8
sig
33801
e8535acd302c copy_of_dtyp uses map table from theory data
huffman
parents: 33798
diff changeset
     9
  val copy_of_dtyp :
e8535acd302c copy_of_dtyp uses map table from theory data
huffman
parents: 33798
diff changeset
    10
      string Symtab.table -> (int -> term) -> Datatype.dtyp -> term
31232
689aa7da48cc define copy functions using combinators; add checking for failed proofs of induction rules
huffman
parents: 31227
diff changeset
    11
31288
67dff9c5b2bd remove hard tabs, fix indentation
huffman
parents: 31232
diff changeset
    12
  val calc_axioms :
35497
979706bd5c16 re-enable bisim code, now in domain_theorems.ML
huffman
parents: 35495
diff changeset
    13
      Domain_Library.eq list -> int -> Domain_Library.eq ->
35515
d631dc53ede0 move definition of finiteness predicate into domain_take_proofs.ML
huffman
parents: 35514
diff changeset
    14
      string * (string * term) list
31227
0aa6afd229d3 indentation; export Domain_Axioms.calc_axioms
huffman
parents: 31023
diff changeset
    15
31288
67dff9c5b2bd remove hard tabs, fix indentation
huffman
parents: 31232
diff changeset
    16
  val add_axioms :
35494
45c9a8278faf domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents: 35486
diff changeset
    17
      ((string * typ list) *
45c9a8278faf domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents: 35486
diff changeset
    18
       (binding * (bool * binding option * typ) list * mixfix) list) list ->
35497
979706bd5c16 re-enable bisim code, now in domain_theorems.ML
huffman
parents: 35495
diff changeset
    19
      Domain_Library.eq list -> theory -> theory
30919
dcf8a7a66bd1 make domain package ML interface more consistent with datatype package; use binding instead of bstring
huffman
parents: 30912
diff changeset
    20
end;
dcf8a7a66bd1 make domain package ML interface more consistent with datatype package; use binding instead of bstring
huffman
parents: 30912
diff changeset
    21
dcf8a7a66bd1 make domain package ML interface more consistent with datatype package; use binding instead of bstring
huffman
parents: 30912
diff changeset
    22
33245
65232054ffd0 eliminated some old folds;
wenzelm
parents: 32952
diff changeset
    23
structure Domain_Axioms : DOMAIN_AXIOMS =
30919
dcf8a7a66bd1 make domain package ML interface more consistent with datatype package; use binding instead of bstring
huffman
parents: 30912
diff changeset
    24
struct
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
    25
31227
0aa6afd229d3 indentation; export Domain_Axioms.calc_axioms
huffman
parents: 31023
diff changeset
    26
open Domain_Library;
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
    27
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
    28
infixr 0 ===>;infixr 0 ==>;infix 0 == ; 
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
    29
infix 1 ===; infix 1 ~= ; infix 1 <<; infix 1 ~<<;
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
    30
infix 9 `   ; infix 9 `% ; infix 9 `%%; infixr 9 oo;
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
    31
31232
689aa7da48cc define copy functions using combinators; add checking for failed proofs of induction rules
huffman
parents: 31227
diff changeset
    32
(* FIXME: use theory data for this *)
689aa7da48cc define copy functions using combinators; add checking for failed proofs of induction rules
huffman
parents: 31227
diff changeset
    33
val copy_tab : string Symtab.table =
35525
fa231b86cb1e proper names for types cfun, sprod, ssum
huffman
parents: 35517
diff changeset
    34
    Symtab.make [(@{type_name cfun}, @{const_name "cfun_map"}),
fa231b86cb1e proper names for types cfun, sprod, ssum
huffman
parents: 35517
diff changeset
    35
                 (@{type_name ssum}, @{const_name "ssum_map"}),
fa231b86cb1e proper names for types cfun, sprod, ssum
huffman
parents: 35517
diff changeset
    36
                 (@{type_name sprod}, @{const_name "sprod_map"}),
33504
b4210cc3ac97 map functions for various types, with ep_pair/deflation/finite_deflation lemmas
huffman
parents: 33396
diff changeset
    37
                 (@{type_name "*"}, @{const_name "cprod_map"}),
b4210cc3ac97 map functions for various types, with ep_pair/deflation/finite_deflation lemmas
huffman
parents: 33396
diff changeset
    38
                 (@{type_name "u"}, @{const_name "u_map"})];
31232
689aa7da48cc define copy functions using combinators; add checking for failed proofs of induction rules
huffman
parents: 31227
diff changeset
    39
33801
e8535acd302c copy_of_dtyp uses map table from theory data
huffman
parents: 33798
diff changeset
    40
fun copy_of_dtyp tab r dt =
33971
9c7fa7f76950 modernized structure Datatype_Aux
haftmann
parents: 33809
diff changeset
    41
    if Datatype_Aux.is_rec_type dt then copy tab r dt else ID
9c7fa7f76950 modernized structure Datatype_Aux
haftmann
parents: 33809
diff changeset
    42
and copy tab r (Datatype_Aux.DtRec i) = r i
9c7fa7f76950 modernized structure Datatype_Aux
haftmann
parents: 33809
diff changeset
    43
  | copy tab r (Datatype_Aux.DtTFree a) = ID
9c7fa7f76950 modernized structure Datatype_Aux
haftmann
parents: 33809
diff changeset
    44
  | copy tab r (Datatype_Aux.DtType (c, ds)) =
33801
e8535acd302c copy_of_dtyp uses map table from theory data
huffman
parents: 33798
diff changeset
    45
    case Symtab.lookup tab c of
e8535acd302c copy_of_dtyp uses map table from theory data
huffman
parents: 33798
diff changeset
    46
      SOME f => list_ccomb (%%:f, map (copy_of_dtyp tab r) ds)
31288
67dff9c5b2bd remove hard tabs, fix indentation
huffman
parents: 31232
diff changeset
    47
    | NONE => (warning ("copy_of_dtyp: unknown type constructor " ^ c); ID);
31232
689aa7da48cc define copy functions using combinators; add checking for failed proofs of induction rules
huffman
parents: 31227
diff changeset
    48
31227
0aa6afd229d3 indentation; export Domain_Axioms.calc_axioms
huffman
parents: 31023
diff changeset
    49
fun calc_axioms
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33504
diff changeset
    50
    (eqs : eq list)
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33504
diff changeset
    51
    (n : int)
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33504
diff changeset
    52
    (eqn as ((dname,_),cons) : eq)
35515
d631dc53ede0 move definition of finiteness predicate into domain_take_proofs.ML
huffman
parents: 35514
diff changeset
    53
    : string * (string * term) list =
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33504
diff changeset
    54
  let
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33504
diff changeset
    55
    val dc_abs = %%:(dname^"_abs");
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33504
diff changeset
    56
    val dc_rep = %%:(dname^"_rep");
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33504
diff changeset
    57
    val x_name'= "x";
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33504
diff changeset
    58
    val x_name = idx_name eqs x_name' (n+1);
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33504
diff changeset
    59
    val dnam = Long_Name.base_name dname;
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33504
diff changeset
    60
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33504
diff changeset
    61
    val abs_iso_ax = ("abs_iso", mk_trp(dc_rep`(dc_abs`%x_name') === %:x_name'));
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33504
diff changeset
    62
    val rep_iso_ax = ("rep_iso", mk_trp(dc_abs`(dc_rep`%x_name') === %:x_name'));
35515
d631dc53ede0 move definition of finiteness predicate into domain_take_proofs.ML
huffman
parents: 35514
diff changeset
    63
  in
35517
0e2ef13796a4 add_axioms no longer needs a definitional mode
huffman
parents: 35515
diff changeset
    64
    (dnam, [abs_iso_ax, rep_iso_ax])
0e2ef13796a4 add_axioms no longer needs a definitional mode
huffman
parents: 35515
diff changeset
    65
  end;
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
    66
30483
0c398040969c added legacy type inference (from fixrec_package.ML);
wenzelm
parents: 30364
diff changeset
    67
0c398040969c added legacy type inference (from fixrec_package.ML);
wenzelm
parents: 30364
diff changeset
    68
(* legacy type inference *)
0c398040969c added legacy type inference (from fixrec_package.ML);
wenzelm
parents: 30364
diff changeset
    69
0c398040969c added legacy type inference (from fixrec_package.ML);
wenzelm
parents: 30364
diff changeset
    70
fun legacy_infer_term thy t =
31227
0aa6afd229d3 indentation; export Domain_Axioms.calc_axioms
huffman
parents: 31023
diff changeset
    71
    singleton (Syntax.check_terms (ProofContext.init thy)) (Sign.intern_term thy t);
30483
0c398040969c added legacy type inference (from fixrec_package.ML);
wenzelm
parents: 30364
diff changeset
    72
0c398040969c added legacy type inference (from fixrec_package.ML);
wenzelm
parents: 30364
diff changeset
    73
fun legacy_infer_prop thy t = legacy_infer_term thy (TypeInfer.constrain propT t);
0c398040969c added legacy type inference (from fixrec_package.ML);
wenzelm
parents: 30364
diff changeset
    74
0c398040969c added legacy type inference (from fixrec_package.ML);
wenzelm
parents: 30364
diff changeset
    75
fun infer_props thy = map (apsnd (legacy_infer_prop thy));
0c398040969c added legacy type inference (from fixrec_package.ML);
wenzelm
parents: 30364
diff changeset
    76
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
    77
29585
c23295521af5 binding replaces bstring
haftmann
parents: 28965
diff changeset
    78
fun add_axioms_i x = snd o PureThy.add_axioms (map (Thm.no_attributes o apfst Binding.name) x);
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
    79
fun add_axioms_infer axms thy = add_axioms_i (infer_props thy axms) thy;
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
    80
35517
0e2ef13796a4 add_axioms no longer needs a definitional mode
huffman
parents: 35515
diff changeset
    81
fun add_axioms eqs' (eqs : eq list) thy' =
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33504
diff changeset
    82
  let
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33504
diff changeset
    83
    val dnames = map (fst o fst) eqs;
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33504
diff changeset
    84
    val x_name = idx_name dnames "x"; 
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
    85
35515
d631dc53ede0 move definition of finiteness predicate into domain_take_proofs.ML
huffman
parents: 35514
diff changeset
    86
    fun add_one (dnam, axs) =
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33504
diff changeset
    87
        Sign.add_path dnam
33245
65232054ffd0 eliminated some old folds;
wenzelm
parents: 32952
diff changeset
    88
          #> add_axioms_infer axs
65232054ffd0 eliminated some old folds;
wenzelm
parents: 32952
diff changeset
    89
          #> Sign.parent_path;
31227
0aa6afd229d3 indentation; export Domain_Axioms.calc_axioms
huffman
parents: 31023
diff changeset
    90
35517
0e2ef13796a4 add_axioms no longer needs a definitional mode
huffman
parents: 35515
diff changeset
    91
    val axs = mapn (calc_axioms eqs) 0 eqs;
35494
45c9a8278faf domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents: 35486
diff changeset
    92
    val thy = thy' |> fold add_one axs;
33801
e8535acd302c copy_of_dtyp uses map table from theory data
huffman
parents: 33798
diff changeset
    93
35494
45c9a8278faf domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents: 35486
diff changeset
    94
    fun get_iso_info ((dname, tyvars), cons') =
45c9a8278faf domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents: 35486
diff changeset
    95
      let
45c9a8278faf domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents: 35486
diff changeset
    96
        fun opt_lazy (lazy,_,t) = if lazy then mk_uT t else t
45c9a8278faf domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents: 35486
diff changeset
    97
        fun prod     (_,args,_) =
45c9a8278faf domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents: 35486
diff changeset
    98
            case args of [] => oneT
45c9a8278faf domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents: 35486
diff changeset
    99
                       | _ => foldr1 mk_sprodT (map opt_lazy args);
45c9a8278faf domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents: 35486
diff changeset
   100
        val ax_abs_iso = PureThy.get_thm thy (dname ^ ".abs_iso");
45c9a8278faf domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents: 35486
diff changeset
   101
        val ax_rep_iso = PureThy.get_thm thy (dname ^ ".rep_iso");
45c9a8278faf domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents: 35486
diff changeset
   102
        val lhsT = Type(dname,tyvars);
45c9a8278faf domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents: 35486
diff changeset
   103
        val rhsT = foldr1 mk_ssumT (map prod cons');
45c9a8278faf domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents: 35486
diff changeset
   104
        val rep_const = Const(dname^"_rep", lhsT ->> rhsT);
45c9a8278faf domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents: 35486
diff changeset
   105
        val abs_const = Const(dname^"_abs", rhsT ->> lhsT);
45c9a8278faf domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents: 35486
diff changeset
   106
      in
45c9a8278faf domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents: 35486
diff changeset
   107
        {
45c9a8278faf domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents: 35486
diff changeset
   108
          absT = lhsT,
45c9a8278faf domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents: 35486
diff changeset
   109
          repT = rhsT,
45c9a8278faf domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents: 35486
diff changeset
   110
          abs_const = abs_const,
45c9a8278faf domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents: 35486
diff changeset
   111
          rep_const = rep_const,
45c9a8278faf domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents: 35486
diff changeset
   112
          abs_inverse = ax_abs_iso,
45c9a8278faf domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents: 35486
diff changeset
   113
          rep_inverse = ax_rep_iso
45c9a8278faf domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents: 35486
diff changeset
   114
        }
45c9a8278faf domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents: 35486
diff changeset
   115
      end;
45c9a8278faf domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents: 35486
diff changeset
   116
    val dom_binds = map (Binding.name o Long_Name.base_name) dnames;
35517
0e2ef13796a4 add_axioms no longer needs a definitional mode
huffman
parents: 35515
diff changeset
   117
    val (take_info, thy) =
0e2ef13796a4 add_axioms no longer needs a definitional mode
huffman
parents: 35515
diff changeset
   118
        Domain_Take_Proofs.define_take_functions
0e2ef13796a4 add_axioms no longer needs a definitional mode
huffman
parents: 35515
diff changeset
   119
          (dom_binds ~~ map get_iso_info eqs') thy;
35494
45c9a8278faf domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents: 35486
diff changeset
   120
45c9a8278faf domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents: 35486
diff changeset
   121
    (* declare lub_take axioms *)
45c9a8278faf domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents: 35486
diff changeset
   122
    local
45c9a8278faf domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents: 35486
diff changeset
   123
      fun ax_lub_take dname =
45c9a8278faf domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents: 35486
diff changeset
   124
        let
45c9a8278faf domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents: 35486
diff changeset
   125
          val dnam : string = Long_Name.base_name dname;
45c9a8278faf domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents: 35486
diff changeset
   126
          val take_const = %%:(dname^"_take");
45c9a8278faf domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents: 35486
diff changeset
   127
          val lub = %%: @{const_name lub};
45c9a8278faf domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents: 35486
diff changeset
   128
          val image = %%: @{const_name image};
35499
6acef0aea07d UNIV is not a logical constant
huffman
parents: 35497
diff changeset
   129
          val UNIV = @{term "UNIV :: nat set"};
35494
45c9a8278faf domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents: 35486
diff changeset
   130
          val lhs = lub $ (image $ take_const $ UNIV);
45c9a8278faf domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents: 35486
diff changeset
   131
          val ax = mk_trp (lhs === ID);
45c9a8278faf domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents: 35486
diff changeset
   132
        in
35515
d631dc53ede0 move definition of finiteness predicate into domain_take_proofs.ML
huffman
parents: 35514
diff changeset
   133
          add_one (dnam, [("lub_take", ax)])
35494
45c9a8278faf domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents: 35486
diff changeset
   134
        end
45c9a8278faf domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents: 35486
diff changeset
   135
    in
35517
0e2ef13796a4 add_axioms no longer needs a definitional mode
huffman
parents: 35515
diff changeset
   136
      val thy = fold ax_lub_take dnames thy
35494
45c9a8278faf domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents: 35486
diff changeset
   137
    end;
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33504
diff changeset
   138
  in
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33504
diff changeset
   139
    thy
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33504
diff changeset
   140
  end; (* let (add_axioms) *)
31227
0aa6afd229d3 indentation; export Domain_Axioms.calc_axioms
huffman
parents: 31023
diff changeset
   141
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   142
end; (* struct *)