Nominal-General/nominal_atoms.ML
author Christian Urban <urbanc@in.tum.de>
Tue, 27 Apr 2010 22:21:16 +0200
changeset 1962 84a13d1e2511
parent 1774 c34347ec7ab3
child 2051 13da60487112
permissions -rw-r--r--
moved mk_atom into the library; that meant that concrete atom classes need to be in Nominal2_Base
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1079
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
(*  Title:      nominal_atoms/ML
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
    Authors:    Brian Huffman, Christian Urban
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
    Command for defining concrete atom types. 
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
    
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
    At the moment, only single-sorted atom types
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
    are supported. 
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
*)
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
signature ATOM_DECL =
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
sig
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
  val add_atom_decl: (binding * (binding option)) -> theory -> theory
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
end;
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
structure Atom_Decl :> ATOM_DECL =
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
struct
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
fun atom_decl_set (str : string) : term =
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
  let
1962
84a13d1e2511 moved mk_atom into the library; that meant that concrete atom classes need to be in Nominal2_Base
Christian Urban <urbanc@in.tum.de>
parents: 1774
diff changeset
    20
    val a = Free ("a", @{typ atom});
1079
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
    val s = Const (@{const_name "Sort"}, @{typ "string => atom_sort list => atom_sort"})
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
              $ HOLogic.mk_string str $ HOLogic.nil_const @{typ "atom_sort"};
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
  in
1962
84a13d1e2511 moved mk_atom into the library; that meant that concrete atom classes need to be in Nominal2_Base
Christian Urban <urbanc@in.tum.de>
parents: 1774
diff changeset
    24
    HOLogic.mk_Collect ("a", @{typ atom}, HOLogic.mk_eq (mk_sort_of a, s))
1079
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
  end
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
fun add_atom_decl (name : binding, arg : binding option) (thy : theory) =
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
  let
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
    val _ = Theory.requires thy "Nominal2_Atoms" "nominal logic";
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
    val str = Sign.full_name thy name;
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
    (* typedef *)
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
    val set = atom_decl_set str;
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
    val tac = rtac @{thm exists_eq_simple_sort} 1;
1689
8c0eef2b84e7 fixed a problem due to a change in type-def (needs new Isabelle)
Christian Urban <urbanc@in.tum.de>
parents: 1460
diff changeset
    35
    val ((full_tname, info  as ({Rep_name, Abs_name, ...}, {type_definition, ...})), thy) =
1460
0fd03936dedb merge and proof of support for non-recursive case
Christian Urban <urbanc@in.tum.de>
parents: 1451
diff changeset
    36
      Typedef.add_typedef_global false NONE (name, [], NoSyn) set NONE tac thy;
1079
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
    (* definition of atom and permute *)
1689
8c0eef2b84e7 fixed a problem due to a change in type-def (needs new Isabelle)
Christian Urban <urbanc@in.tum.de>
parents: 1460
diff changeset
    39
    val newT = #abs_type (fst info);
1962
84a13d1e2511 moved mk_atom into the library; that meant that concrete atom classes need to be in Nominal2_Base
Christian Urban <urbanc@in.tum.de>
parents: 1774
diff changeset
    40
    val RepC = Const (Rep_name, newT --> @{typ atom});
84a13d1e2511 moved mk_atom into the library; that meant that concrete atom classes need to be in Nominal2_Base
Christian Urban <urbanc@in.tum.de>
parents: 1774
diff changeset
    41
    val AbsC = Const (Abs_name, @{typ atom} --> newT);
1079
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
    val a = Free ("a", newT);
1962
84a13d1e2511 moved mk_atom into the library; that meant that concrete atom classes need to be in Nominal2_Base
Christian Urban <urbanc@in.tum.de>
parents: 1774
diff changeset
    43
    val p = Free ("p", @{typ perm});
1079
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
    val atom_eqn =
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
      HOLogic.mk_Trueprop (HOLogic.mk_eq (mk_atom a, RepC $ a));
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
    val permute_eqn =
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
      HOLogic.mk_Trueprop (HOLogic.mk_eq
1962
84a13d1e2511 moved mk_atom into the library; that meant that concrete atom classes need to be in Nominal2_Base
Christian Urban <urbanc@in.tum.de>
parents: 1774
diff changeset
    48
        (mk_perm p a, AbsC $ (mk_perm p (RepC $ a))));
1079
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
    val atom_def_name =
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
      Binding.prefix_name "atom_" (Binding.suffix_name "_def" name);
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
    val permute_def_name =
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
      Binding.prefix_name "permute_" (Binding.suffix_name "_def" name);
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
    (* at class instance *)
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
    val lthy =
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
      Theory_Target.instantiation ([full_tname], [], @{sort at}) thy;
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
    val ((_, (_, permute_ldef)), lthy) =
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
      Specification.definition (NONE, ((permute_def_name, []), permute_eqn)) lthy;
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
    val ((_, (_, atom_ldef)), lthy) =
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
      Specification.definition (NONE, ((atom_def_name, []), atom_eqn)) lthy;
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
    val ctxt_thy = ProofContext.init (ProofContext.theory_of lthy);
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
    val permute_def = singleton (ProofContext.export lthy ctxt_thy) permute_ldef;
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
    val atom_def = singleton (ProofContext.export lthy ctxt_thy) atom_ldef;
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
    val class_thm = @{thm at_class} OF [type_definition, atom_def, permute_def];
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
    val thy = lthy
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
      |> Class.prove_instantiation_instance (K (Tactic.rtac class_thm 1))
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
      |> Local_Theory.exit_global;
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
  in
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
    thy
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
  end;
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
(** outer syntax **)
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
local structure P = OuterParse and K = OuterKeyword in
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
val _ =
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
  OuterSyntax.command "atom_decl" "declaration of a concrete atom type" K.thy_decl
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
    ((P.binding -- Scan.option (Args.parens (P.binding))) >>
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
      (Toplevel.print oo (Toplevel.theory o add_atom_decl)));
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
end;
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
c70e7545b738 updated to latest Nominal2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
end;