src/HOL/Record.thy
author paulson
Mon, 12 Jan 2004 16:51:45 +0100
changeset 14353 79f9fbef9106
parent 14080 9a50427d7165
child 14700 2f885b7e5ba7
permissions -rw-r--r--
Added lemmas to Ring_and_Field with slightly modified simplification rules Deleted some little-used integer theorems, replacing them by the generic ones in Ring_and_Field Consolidated integer powers
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4870
cc36acb5b114 Extensible records with structural subtyping in HOL. See
wenzelm
parents:
diff changeset
     1
(*  Title:      HOL/Record.thy
cc36acb5b114 Extensible records with structural subtyping in HOL. See
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
cc36acb5b114 Extensible records with structural subtyping in HOL. See
wenzelm
parents:
diff changeset
     3
    Author:     Wolfgang Naraschewski and Markus Wenzel, TU Muenchen
cc36acb5b114 Extensible records with structural subtyping in HOL. See
wenzelm
parents:
diff changeset
     4
*)
cc36acb5b114 Extensible records with structural subtyping in HOL. See
wenzelm
parents:
diff changeset
     5
11821
ad32c92435db abstract product types;
wenzelm
parents: 11489
diff changeset
     6
header {* Extensible records with structural subtyping *}
ad32c92435db abstract product types;
wenzelm
parents: 11489
diff changeset
     7
11826
2203c7f9ec40 proper setup for abstract product types;
wenzelm
parents: 11821
diff changeset
     8
theory Record = Product_Type
11821
ad32c92435db abstract product types;
wenzelm
parents: 11489
diff changeset
     9
files ("Tools/record_package.ML"):
4870
cc36acb5b114 Extensible records with structural subtyping in HOL. See
wenzelm
parents:
diff changeset
    10
cc36acb5b114 Extensible records with structural subtyping in HOL. See
wenzelm
parents:
diff changeset
    11
11821
ad32c92435db abstract product types;
wenzelm
parents: 11489
diff changeset
    12
subsection {* Abstract product types *}
ad32c92435db abstract product types;
wenzelm
parents: 11489
diff changeset
    13
13412
666137b488a4 predicate defs via locales;
wenzelm
parents: 11956
diff changeset
    14
locale product_type =
666137b488a4 predicate defs via locales;
wenzelm
parents: 11956
diff changeset
    15
  fixes Rep and Abs and pair and dest1 and dest2
666137b488a4 predicate defs via locales;
wenzelm
parents: 11956
diff changeset
    16
  assumes "typedef": "type_definition Rep Abs UNIV"
666137b488a4 predicate defs via locales;
wenzelm
parents: 11956
diff changeset
    17
    and pair: "pair == (\<lambda>a b. Abs (a, b))"
666137b488a4 predicate defs via locales;
wenzelm
parents: 11956
diff changeset
    18
    and dest1: "dest1 == (\<lambda>p. fst (Rep p))"
666137b488a4 predicate defs via locales;
wenzelm
parents: 11956
diff changeset
    19
    and dest2: "dest2 == (\<lambda>p. snd (Rep p))"
11821
ad32c92435db abstract product types;
wenzelm
parents: 11489
diff changeset
    20
13412
666137b488a4 predicate defs via locales;
wenzelm
parents: 11956
diff changeset
    21
lemma (in product_type)
666137b488a4 predicate defs via locales;
wenzelm
parents: 11956
diff changeset
    22
    "inject": "(pair x y = pair x' y') = (x = x' \<and> y = y')"
666137b488a4 predicate defs via locales;
wenzelm
parents: 11956
diff changeset
    23
  by (simp add: pair type_definition.Abs_inject [OF "typedef"])
11821
ad32c92435db abstract product types;
wenzelm
parents: 11489
diff changeset
    24
13412
666137b488a4 predicate defs via locales;
wenzelm
parents: 11956
diff changeset
    25
lemma (in product_type) conv1: "dest1 (pair x y) = x"
666137b488a4 predicate defs via locales;
wenzelm
parents: 11956
diff changeset
    26
  by (simp add: pair dest1 type_definition.Abs_inverse [OF "typedef"])
11826
2203c7f9ec40 proper setup for abstract product types;
wenzelm
parents: 11821
diff changeset
    27
13412
666137b488a4 predicate defs via locales;
wenzelm
parents: 11956
diff changeset
    28
lemma (in product_type) conv2: "dest2 (pair x y) = y"
666137b488a4 predicate defs via locales;
wenzelm
parents: 11956
diff changeset
    29
  by (simp add: pair dest2 type_definition.Abs_inverse [OF "typedef"])
11821
ad32c92435db abstract product types;
wenzelm
parents: 11489
diff changeset
    30
13412
666137b488a4 predicate defs via locales;
wenzelm
parents: 11956
diff changeset
    31
lemma (in product_type) induct [induct type]:
666137b488a4 predicate defs via locales;
wenzelm
parents: 11956
diff changeset
    32
  assumes hyp: "!!x y. P (pair x y)"
666137b488a4 predicate defs via locales;
wenzelm
parents: 11956
diff changeset
    33
  shows "P p"
666137b488a4 predicate defs via locales;
wenzelm
parents: 11956
diff changeset
    34
proof (rule type_definition.Abs_induct [OF "typedef"])
666137b488a4 predicate defs via locales;
wenzelm
parents: 11956
diff changeset
    35
  fix q show "P (Abs q)"
666137b488a4 predicate defs via locales;
wenzelm
parents: 11956
diff changeset
    36
  proof (induct q)
666137b488a4 predicate defs via locales;
wenzelm
parents: 11956
diff changeset
    37
    fix x y have "P (pair x y)" by (rule hyp)
666137b488a4 predicate defs via locales;
wenzelm
parents: 11956
diff changeset
    38
    also have "pair x y = Abs (x, y)" by (simp only: pair)
666137b488a4 predicate defs via locales;
wenzelm
parents: 11956
diff changeset
    39
    finally show "P (Abs (x, y))" .
11821
ad32c92435db abstract product types;
wenzelm
parents: 11489
diff changeset
    40
  qed
ad32c92435db abstract product types;
wenzelm
parents: 11489
diff changeset
    41
qed
ad32c92435db abstract product types;
wenzelm
parents: 11489
diff changeset
    42
13412
666137b488a4 predicate defs via locales;
wenzelm
parents: 11956
diff changeset
    43
lemma (in product_type) cases [cases type]:
666137b488a4 predicate defs via locales;
wenzelm
parents: 11956
diff changeset
    44
    "(!!x y. p = pair x y ==> C) ==> C"
666137b488a4 predicate defs via locales;
wenzelm
parents: 11956
diff changeset
    45
  by (induct p) (auto simp add: "inject")
11826
2203c7f9ec40 proper setup for abstract product types;
wenzelm
parents: 11821
diff changeset
    46
13412
666137b488a4 predicate defs via locales;
wenzelm
parents: 11956
diff changeset
    47
lemma (in product_type) surjective_pairing:
666137b488a4 predicate defs via locales;
wenzelm
parents: 11956
diff changeset
    48
    "p = pair (dest1 p) (dest2 p)"
666137b488a4 predicate defs via locales;
wenzelm
parents: 11956
diff changeset
    49
  by (induct p) (simp only: conv1 conv2)
11826
2203c7f9ec40 proper setup for abstract product types;
wenzelm
parents: 11821
diff changeset
    50
13412
666137b488a4 predicate defs via locales;
wenzelm
parents: 11956
diff changeset
    51
lemma (in product_type) split_paired_all:
666137b488a4 predicate defs via locales;
wenzelm
parents: 11956
diff changeset
    52
  "(!!x. PROP P x) == (!!a b. PROP P (pair a b))"
11826
2203c7f9ec40 proper setup for abstract product types;
wenzelm
parents: 11821
diff changeset
    53
proof
2203c7f9ec40 proper setup for abstract product types;
wenzelm
parents: 11821
diff changeset
    54
  fix a b
2203c7f9ec40 proper setup for abstract product types;
wenzelm
parents: 11821
diff changeset
    55
  assume "!!x. PROP P x"
2203c7f9ec40 proper setup for abstract product types;
wenzelm
parents: 11821
diff changeset
    56
  thus "PROP P (pair a b)" .
2203c7f9ec40 proper setup for abstract product types;
wenzelm
parents: 11821
diff changeset
    57
next
2203c7f9ec40 proper setup for abstract product types;
wenzelm
parents: 11821
diff changeset
    58
  fix x
2203c7f9ec40 proper setup for abstract product types;
wenzelm
parents: 11821
diff changeset
    59
  assume "!!a b. PROP P (pair a b)"
2203c7f9ec40 proper setup for abstract product types;
wenzelm
parents: 11821
diff changeset
    60
  hence "PROP P (pair (dest1 x) (dest2 x))" .
13412
666137b488a4 predicate defs via locales;
wenzelm
parents: 11956
diff changeset
    61
  thus "PROP P x" by (simp only: surjective_pairing [symmetric])
11826
2203c7f9ec40 proper setup for abstract product types;
wenzelm
parents: 11821
diff changeset
    62
qed
2203c7f9ec40 proper setup for abstract product types;
wenzelm
parents: 11821
diff changeset
    63
14080
9a50427d7165 Added split_paired_All rule for splitting variables bound by
berghofe
parents: 13421
diff changeset
    64
lemma (in product_type) split_paired_All:
9a50427d7165 Added split_paired_All rule for splitting variables bound by
berghofe
parents: 13421
diff changeset
    65
  "(ALL x. P x) = (ALL a b. P (pair a b))"
9a50427d7165 Added split_paired_All rule for splitting variables bound by
berghofe
parents: 13421
diff changeset
    66
proof
9a50427d7165 Added split_paired_All rule for splitting variables bound by
berghofe
parents: 13421
diff changeset
    67
  fix a b
9a50427d7165 Added split_paired_All rule for splitting variables bound by
berghofe
parents: 13421
diff changeset
    68
  assume "ALL x. P x"
9a50427d7165 Added split_paired_All rule for splitting variables bound by
berghofe
parents: 13421
diff changeset
    69
  thus "ALL a b. P (pair a b)" by rules
9a50427d7165 Added split_paired_All rule for splitting variables bound by
berghofe
parents: 13421
diff changeset
    70
next
9a50427d7165 Added split_paired_All rule for splitting variables bound by
berghofe
parents: 13421
diff changeset
    71
  assume P: "ALL a b. P (pair a b)"
9a50427d7165 Added split_paired_All rule for splitting variables bound by
berghofe
parents: 13421
diff changeset
    72
  show "ALL x. P x"
9a50427d7165 Added split_paired_All rule for splitting variables bound by
berghofe
parents: 13421
diff changeset
    73
  proof
9a50427d7165 Added split_paired_All rule for splitting variables bound by
berghofe
parents: 13421
diff changeset
    74
    fix x
9a50427d7165 Added split_paired_All rule for splitting variables bound by
berghofe
parents: 13421
diff changeset
    75
    from P have "P (pair (dest1 x) (dest2 x))" by rules
9a50427d7165 Added split_paired_All rule for splitting variables bound by
berghofe
parents: 13421
diff changeset
    76
    thus "P x" by (simp only: surjective_pairing [symmetric])
9a50427d7165 Added split_paired_All rule for splitting variables bound by
berghofe
parents: 13421
diff changeset
    77
  qed
9a50427d7165 Added split_paired_All rule for splitting variables bound by
berghofe
parents: 13421
diff changeset
    78
qed
9a50427d7165 Added split_paired_All rule for splitting variables bound by
berghofe
parents: 13421
diff changeset
    79
11821
ad32c92435db abstract product types;
wenzelm
parents: 11489
diff changeset
    80
11833
wenzelm
parents: 11826
diff changeset
    81
subsection {* Concrete record syntax *}
4870
cc36acb5b114 Extensible records with structural subtyping in HOL. See
wenzelm
parents:
diff changeset
    82
cc36acb5b114 Extensible records with structural subtyping in HOL. See
wenzelm
parents:
diff changeset
    83
nonterminals
5198
b1adae4f8b90 added type and update syntax;
wenzelm
parents: 5032
diff changeset
    84
  ident field_type field_types field fields update updates
4870
cc36acb5b114 Extensible records with structural subtyping in HOL. See
wenzelm
parents:
diff changeset
    85
cc36acb5b114 Extensible records with structural subtyping in HOL. See
wenzelm
parents:
diff changeset
    86
syntax
11821
ad32c92435db abstract product types;
wenzelm
parents: 11489
diff changeset
    87
  "_constify"           :: "id => ident"                        ("_")
ad32c92435db abstract product types;
wenzelm
parents: 11489
diff changeset
    88
  "_constify"           :: "longid => ident"                    ("_")
5198
b1adae4f8b90 added type and update syntax;
wenzelm
parents: 5032
diff changeset
    89
11821
ad32c92435db abstract product types;
wenzelm
parents: 11489
diff changeset
    90
  "_field_type"         :: "[ident, type] => field_type"        ("(2_ ::/ _)")
ad32c92435db abstract product types;
wenzelm
parents: 11489
diff changeset
    91
  ""                    :: "field_type => field_types"          ("_")
ad32c92435db abstract product types;
wenzelm
parents: 11489
diff changeset
    92
  "_field_types"        :: "[field_type, field_types] => field_types"    ("_,/ _")
ad32c92435db abstract product types;
wenzelm
parents: 11489
diff changeset
    93
  "_record_type"        :: "field_types => type"                ("(3'(| _ |'))")
10093
44584c2b512b more symbolic syntax (currently "input");
wenzelm
parents: 9729
diff changeset
    94
  "_record_type_scheme" :: "[field_types, type] => type"        ("(3'(| _,/ (2... ::/ _) |'))")
5198
b1adae4f8b90 added type and update syntax;
wenzelm
parents: 5032
diff changeset
    95
11821
ad32c92435db abstract product types;
wenzelm
parents: 11489
diff changeset
    96
  "_field"              :: "[ident, 'a] => field"               ("(2_ =/ _)")
ad32c92435db abstract product types;
wenzelm
parents: 11489
diff changeset
    97
  ""                    :: "field => fields"                    ("_")
ad32c92435db abstract product types;
wenzelm
parents: 11489
diff changeset
    98
  "_fields"             :: "[field, fields] => fields"          ("_,/ _")
ad32c92435db abstract product types;
wenzelm
parents: 11489
diff changeset
    99
  "_record"             :: "fields => 'a"                       ("(3'(| _ |'))")
10093
44584c2b512b more symbolic syntax (currently "input");
wenzelm
parents: 9729
diff changeset
   100
  "_record_scheme"      :: "[fields, 'a] => 'a"                 ("(3'(| _,/ (2... =/ _) |'))")
5198
b1adae4f8b90 added type and update syntax;
wenzelm
parents: 5032
diff changeset
   101
10641
d1533f63c738 added "_update_name" and parse_translation;
wenzelm
parents: 10331
diff changeset
   102
  "_update_name"        :: idt
11821
ad32c92435db abstract product types;
wenzelm
parents: 11489
diff changeset
   103
  "_update"             :: "[ident, 'a] => update"              ("(2_ :=/ _)")
ad32c92435db abstract product types;
wenzelm
parents: 11489
diff changeset
   104
  ""                    :: "update => updates"                  ("_")
ad32c92435db abstract product types;
wenzelm
parents: 11489
diff changeset
   105
  "_updates"            :: "[update, updates] => updates"       ("_,/ _")
10093
44584c2b512b more symbolic syntax (currently "input");
wenzelm
parents: 9729
diff changeset
   106
  "_record_update"      :: "['a, updates] => 'b"                ("_/(3'(| _ |'))" [900,0] 900)
4870
cc36acb5b114 Extensible records with structural subtyping in HOL. See
wenzelm
parents:
diff changeset
   107
10331
7411e4659d4a more "xsymbols" syntax;
wenzelm
parents: 10309
diff changeset
   108
syntax (xsymbols)
11821
ad32c92435db abstract product types;
wenzelm
parents: 11489
diff changeset
   109
  "_record_type"        :: "field_types => type"                ("(3\<lparr>_\<rparr>)")
10093
44584c2b512b more symbolic syntax (currently "input");
wenzelm
parents: 9729
diff changeset
   110
  "_record_type_scheme" :: "[field_types, type] => type"        ("(3\<lparr>_,/ (2\<dots> ::/ _)\<rparr>)")
44584c2b512b more symbolic syntax (currently "input");
wenzelm
parents: 9729
diff changeset
   111
  "_record"             :: "fields => 'a"                               ("(3\<lparr>_\<rparr>)")
44584c2b512b more symbolic syntax (currently "input");
wenzelm
parents: 9729
diff changeset
   112
  "_record_scheme"      :: "[fields, 'a] => 'a"                 ("(3\<lparr>_,/ (2\<dots> =/ _)\<rparr>)")
44584c2b512b more symbolic syntax (currently "input");
wenzelm
parents: 9729
diff changeset
   113
  "_record_update"      :: "['a, updates] => 'b"                ("_/(3\<lparr>_\<rparr>)" [900,0] 900)
9729
40cfc3dd27da \<dots> syntax;
wenzelm
parents: 7357
diff changeset
   114
11833
wenzelm
parents: 11826
diff changeset
   115
wenzelm
parents: 11826
diff changeset
   116
subsection {* Package setup *}
wenzelm
parents: 11826
diff changeset
   117
wenzelm
parents: 11826
diff changeset
   118
use "Tools/record_package.ML"
wenzelm
parents: 11826
diff changeset
   119
setup RecordPackage.setup
10641
d1533f63c738 added "_update_name" and parse_translation;
wenzelm
parents: 10331
diff changeset
   120
4870
cc36acb5b114 Extensible records with structural subtyping in HOL. See
wenzelm
parents:
diff changeset
   121
end