src/Pure/morphism.ML
author wenzelm
Mon, 19 Aug 2013 20:37:36 +0200
changeset 53087 5a1dcda7967c
parent 45289 25e9e7f527b4
child 54740 91f54d386680
permissions -rw-r--r--
tuned signature;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
21476
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/morphism.ML
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
     3
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
     4
Abstract morphisms on formal entities.
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
     5
*)
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
     6
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
     7
infix 1 $>
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
     8
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
     9
signature BASIC_MORPHISM =
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    10
sig
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    11
  type morphism
24031
e94e541346d7 type Morphism.declaration;
wenzelm
parents: 22670
diff changeset
    12
  type declaration = morphism -> Context.generic -> Context.generic
21476
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    13
  val $> : morphism * morphism -> morphism
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    14
end
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    15
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    16
signature MORPHISM =
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    17
sig
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    18
  include BASIC_MORPHISM
45289
25e9e7f527b4 slightly more explicit/syntactic modelling of morphisms;
wenzelm
parents: 37216
diff changeset
    19
  type 'a funs = ('a -> 'a) list
29581
b3b33e0298eb binding is alias for Binding.T
haftmann
parents: 28965
diff changeset
    20
  val binding: morphism -> binding -> binding
21476
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    21
  val typ: morphism -> typ -> typ
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    22
  val term: morphism -> term -> term
21521
095f4963beed simultaneous fact morphism;
wenzelm
parents: 21492
diff changeset
    23
  val fact: morphism -> thm list -> thm list
21476
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    24
  val thm: morphism -> thm -> thm
22235
6eac7f7c3294 added cterm interface;
wenzelm
parents: 21521
diff changeset
    25
  val cterm: morphism -> cterm -> cterm
21476
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    26
  val morphism:
45289
25e9e7f527b4 slightly more explicit/syntactic modelling of morphisms;
wenzelm
parents: 37216
diff changeset
    27
   {binding: binding funs,
25e9e7f527b4 slightly more explicit/syntactic modelling of morphisms;
wenzelm
parents: 37216
diff changeset
    28
    typ: typ funs,
25e9e7f527b4 slightly more explicit/syntactic modelling of morphisms;
wenzelm
parents: 37216
diff changeset
    29
    term: term funs,
25e9e7f527b4 slightly more explicit/syntactic modelling of morphisms;
wenzelm
parents: 37216
diff changeset
    30
    fact: thm list funs} -> morphism
29581
b3b33e0298eb binding is alias for Binding.T
haftmann
parents: 28965
diff changeset
    31
  val binding_morphism: (binding -> binding) -> morphism
21492
c73faa8e98aa added name/var/typ/term/thm_morphism;
wenzelm
parents: 21476
diff changeset
    32
  val typ_morphism: (typ -> typ) -> morphism
c73faa8e98aa added name/var/typ/term/thm_morphism;
wenzelm
parents: 21476
diff changeset
    33
  val term_morphism: (term -> term) -> morphism
21521
095f4963beed simultaneous fact morphism;
wenzelm
parents: 21492
diff changeset
    34
  val fact_morphism: (thm list -> thm list) -> morphism
21492
c73faa8e98aa added name/var/typ/term/thm_morphism;
wenzelm
parents: 21476
diff changeset
    35
  val thm_morphism: (thm -> thm) -> morphism
53087
5a1dcda7967c tuned signature;
wenzelm
parents: 45289
diff changeset
    36
  val transfer_morphism: theory -> morphism
21476
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    37
  val identity: morphism
22571
3f00e937d1c9 renamed comp to compose (avoid clash with Alice keywords);
wenzelm
parents: 22235
diff changeset
    38
  val compose: morphism -> morphism -> morphism
22670
c803b2696ada added Morphism.transform/form (generic non-sense);
wenzelm
parents: 22571
diff changeset
    39
  val transform: morphism -> (morphism -> 'a) -> morphism -> 'a
c803b2696ada added Morphism.transform/form (generic non-sense);
wenzelm
parents: 22571
diff changeset
    40
  val form: (morphism -> 'a) -> 'a
21476
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    41
end;
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    42
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    43
structure Morphism: MORPHISM =
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    44
struct
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    45
45289
25e9e7f527b4 slightly more explicit/syntactic modelling of morphisms;
wenzelm
parents: 37216
diff changeset
    46
type 'a funs = ('a -> 'a) list;
25e9e7f527b4 slightly more explicit/syntactic modelling of morphisms;
wenzelm
parents: 37216
diff changeset
    47
fun apply fs = fold_rev (fn f => fn x => f x) fs;
25e9e7f527b4 slightly more explicit/syntactic modelling of morphisms;
wenzelm
parents: 37216
diff changeset
    48
21476
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    49
datatype morphism = Morphism of
45289
25e9e7f527b4 slightly more explicit/syntactic modelling of morphisms;
wenzelm
parents: 37216
diff changeset
    50
 {binding: binding funs,
25e9e7f527b4 slightly more explicit/syntactic modelling of morphisms;
wenzelm
parents: 37216
diff changeset
    51
  typ: typ funs,
25e9e7f527b4 slightly more explicit/syntactic modelling of morphisms;
wenzelm
parents: 37216
diff changeset
    52
  term: term funs,
25e9e7f527b4 slightly more explicit/syntactic modelling of morphisms;
wenzelm
parents: 37216
diff changeset
    53
  fact: thm list funs};
21476
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    54
24031
e94e541346d7 type Morphism.declaration;
wenzelm
parents: 22670
diff changeset
    55
type declaration = morphism -> Context.generic -> Context.generic;
e94e541346d7 type Morphism.declaration;
wenzelm
parents: 22670
diff changeset
    56
45289
25e9e7f527b4 slightly more explicit/syntactic modelling of morphisms;
wenzelm
parents: 37216
diff changeset
    57
fun binding (Morphism {binding, ...}) = apply binding;
25e9e7f527b4 slightly more explicit/syntactic modelling of morphisms;
wenzelm
parents: 37216
diff changeset
    58
fun typ (Morphism {typ, ...}) = apply typ;
25e9e7f527b4 slightly more explicit/syntactic modelling of morphisms;
wenzelm
parents: 37216
diff changeset
    59
fun term (Morphism {term, ...}) = apply term;
25e9e7f527b4 slightly more explicit/syntactic modelling of morphisms;
wenzelm
parents: 37216
diff changeset
    60
fun fact (Morphism {fact, ...}) = apply fact;
21521
095f4963beed simultaneous fact morphism;
wenzelm
parents: 21492
diff changeset
    61
val thm = singleton o fact;
22235
6eac7f7c3294 added cterm interface;
wenzelm
parents: 21521
diff changeset
    62
val cterm = Drule.cterm_rule o thm;
21476
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    63
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    64
val morphism = Morphism;
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    65
45289
25e9e7f527b4 slightly more explicit/syntactic modelling of morphisms;
wenzelm
parents: 37216
diff changeset
    66
fun binding_morphism binding = morphism {binding = [binding], typ = [], term = [], fact = []};
25e9e7f527b4 slightly more explicit/syntactic modelling of morphisms;
wenzelm
parents: 37216
diff changeset
    67
fun typ_morphism typ = morphism {binding = [], typ = [typ], term = [], fact = []};
25e9e7f527b4 slightly more explicit/syntactic modelling of morphisms;
wenzelm
parents: 37216
diff changeset
    68
fun term_morphism term = morphism {binding = [], typ = [], term = [term], fact = []};
25e9e7f527b4 slightly more explicit/syntactic modelling of morphisms;
wenzelm
parents: 37216
diff changeset
    69
fun fact_morphism fact = morphism {binding = [], typ = [], term = [], fact = [fact]};
25e9e7f527b4 slightly more explicit/syntactic modelling of morphisms;
wenzelm
parents: 37216
diff changeset
    70
fun thm_morphism thm = morphism {binding = [], typ = [], term = [], fact = [map thm]};
53087
5a1dcda7967c tuned signature;
wenzelm
parents: 45289
diff changeset
    71
val transfer_morphism = thm_morphism o Thm.transfer;
21492
c73faa8e98aa added name/var/typ/term/thm_morphism;
wenzelm
parents: 21476
diff changeset
    72
45289
25e9e7f527b4 slightly more explicit/syntactic modelling of morphisms;
wenzelm
parents: 37216
diff changeset
    73
val identity = morphism {binding = [], typ = [], term = [], fact = []};
21492
c73faa8e98aa added name/var/typ/term/thm_morphism;
wenzelm
parents: 21476
diff changeset
    74
22571
3f00e937d1c9 renamed comp to compose (avoid clash with Alice keywords);
wenzelm
parents: 22235
diff changeset
    75
fun compose
29605
f2924219125e eliminated obsolete var morphism;
wenzelm
parents: 29581
diff changeset
    76
    (Morphism {binding = binding1, typ = typ1, term = term1, fact = fact1})
f2924219125e eliminated obsolete var morphism;
wenzelm
parents: 29581
diff changeset
    77
    (Morphism {binding = binding2, typ = typ2, term = term2, fact = fact2}) =
45289
25e9e7f527b4 slightly more explicit/syntactic modelling of morphisms;
wenzelm
parents: 37216
diff changeset
    78
  morphism {binding = binding1 @ binding2, typ = typ1 @ typ2,
25e9e7f527b4 slightly more explicit/syntactic modelling of morphisms;
wenzelm
parents: 37216
diff changeset
    79
    term = term1 @ term2, fact = fact1 @ fact2};
21476
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    80
22571
3f00e937d1c9 renamed comp to compose (avoid clash with Alice keywords);
wenzelm
parents: 22235
diff changeset
    81
fun phi1 $> phi2 = compose phi2 phi1;
21476
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    82
22670
c803b2696ada added Morphism.transform/form (generic non-sense);
wenzelm
parents: 22571
diff changeset
    83
fun transform phi f = fn psi => f (phi $> psi);
c803b2696ada added Morphism.transform/form (generic non-sense);
wenzelm
parents: 22571
diff changeset
    84
fun form f = f identity;
c803b2696ada added Morphism.transform/form (generic non-sense);
wenzelm
parents: 22571
diff changeset
    85
21476
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    86
end;
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    87
37216
3165bc303f66 modernized some structure names, keeping a few legacy aliases;
wenzelm
parents: 29605
diff changeset
    88
structure Basic_Morphism: BASIC_MORPHISM = Morphism;
3165bc303f66 modernized some structure names, keeping a few legacy aliases;
wenzelm
parents: 29605
diff changeset
    89
open Basic_Morphism;