src/HOL/Nat_Transfer.thy
author nipkow
Mon, 17 Oct 2016 17:33:07 +0200
changeset 64272 f76b6dda2e56
parent 64267 b9a1486e79be
child 66795 420d0080545f
permissions -rw-r--r--
setprod -> prod
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
32554
4ccd84fb19d3 early bootstrap of generic transfer procedure
haftmann
parents: 32264
diff changeset
     1
(* Authors: Jeremy Avigad and Amine Chaieb *)
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
     2
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 58889
diff changeset
     3
section \<open>Generic transfer machinery;  specific transfer from nats to ints and back.\<close>
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
     4
32558
e6e1fc2e73cb obey underscore naming convention
haftmann
parents: 32554
diff changeset
     5
theory Nat_Transfer
47255
30a1692557b0 removed Nat_Numeral.thy, moving all theorems elsewhere
huffman
parents: 42870
diff changeset
     6
imports Int
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
     7
begin
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
     8
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 58889
diff changeset
     9
subsection \<open>Generic transfer machinery\<close>
33318
ddd97d9dfbfb moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents: 32558
diff changeset
    10
35821
ee34f03a7d26 meaningful transfer certificate
haftmann
parents: 35683
diff changeset
    11
definition transfer_morphism:: "('b \<Rightarrow> 'a) \<Rightarrow> ('b \<Rightarrow> bool) \<Rightarrow> bool"
42870
36abaf4cce1f clarified vacuous nature of predicate "transfer_morphism" -- equivalent to previous definiton
krauss
parents: 39302
diff changeset
    12
  where "transfer_morphism f A \<longleftrightarrow> True"
35644
d20cf282342e transfer: avoid camel case
haftmann
parents: 35551
diff changeset
    13
42870
36abaf4cce1f clarified vacuous nature of predicate "transfer_morphism" -- equivalent to previous definiton
krauss
parents: 39302
diff changeset
    14
lemma transfer_morphismI[intro]: "transfer_morphism f A"
36abaf4cce1f clarified vacuous nature of predicate "transfer_morphism" -- equivalent to previous definiton
krauss
parents: 39302
diff changeset
    15
  by (simp add: transfer_morphism_def)
33318
ddd97d9dfbfb moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents: 32558
diff changeset
    16
48891
c0eafbd55de3 prefer ML_file over old uses;
wenzelm
parents: 47324
diff changeset
    17
ML_file "Tools/legacy_transfer.ML"
33318
ddd97d9dfbfb moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents: 32558
diff changeset
    18
ddd97d9dfbfb moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents: 32558
diff changeset
    19
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 58889
diff changeset
    20
subsection \<open>Set up transfer from nat to int\<close>
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
    21
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 58889
diff changeset
    22
text \<open>set up transfer direction\<close>
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
    23
42870
36abaf4cce1f clarified vacuous nature of predicate "transfer_morphism" -- equivalent to previous definiton
krauss
parents: 39302
diff changeset
    24
lemma transfer_morphism_nat_int: "transfer_morphism nat (op <= (0::int))" ..
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
    25
35683
70ace653fe77 misc tuning
haftmann
parents: 35644
diff changeset
    26
declare transfer_morphism_nat_int [transfer add
70ace653fe77 misc tuning
haftmann
parents: 35644
diff changeset
    27
  mode: manual
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
    28
  return: nat_0_le
35683
70ace653fe77 misc tuning
haftmann
parents: 35644
diff changeset
    29
  labels: nat_int
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
    30
]
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
    31
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 58889
diff changeset
    32
text \<open>basic functions and relations\<close>
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
    33
35683
70ace653fe77 misc tuning
haftmann
parents: 35644
diff changeset
    34
lemma transfer_nat_int_numerals [transfer key: transfer_morphism_nat_int]:
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
    35
    "(0::nat) = nat 0"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
    36
    "(1::nat) = nat 1"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
    37
    "(2::nat) = nat 2"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
    38
    "(3::nat) = nat 3"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
    39
  by auto
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
    40
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
    41
definition
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
    42
  tsub :: "int \<Rightarrow> int \<Rightarrow> int"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
    43
where
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
    44
  "tsub x y = (if x >= y then x - y else 0)"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
    45
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
    46
lemma tsub_eq: "x >= y \<Longrightarrow> tsub x y = x - y"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
    47
  by (simp add: tsub_def)
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
    48
35683
70ace653fe77 misc tuning
haftmann
parents: 35644
diff changeset
    49
lemma transfer_nat_int_functions [transfer key: transfer_morphism_nat_int]:
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
    50
    "(x::int) >= 0 \<Longrightarrow> y >= 0 \<Longrightarrow> (nat x) + (nat y) = nat (x + y)"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
    51
    "(x::int) >= 0 \<Longrightarrow> y >= 0 \<Longrightarrow> (nat x) * (nat y) = nat (x * y)"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
    52
    "(x::int) >= 0 \<Longrightarrow> y >= 0 \<Longrightarrow> (nat x) - (nat y) = nat (tsub x y)"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
    53
    "(x::int) >= 0 \<Longrightarrow> (nat x)^n = nat (x^n)"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
    54
  by (auto simp add: eq_nat_nat_iff nat_mult_distrib
33318
ddd97d9dfbfb moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents: 32558
diff changeset
    55
      nat_power_eq tsub_def)
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
    56
35683
70ace653fe77 misc tuning
haftmann
parents: 35644
diff changeset
    57
lemma transfer_nat_int_function_closures [transfer key: transfer_morphism_nat_int]:
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
    58
    "(x::int) >= 0 \<Longrightarrow> y >= 0 \<Longrightarrow> x + y >= 0"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
    59
    "(x::int) >= 0 \<Longrightarrow> y >= 0 \<Longrightarrow> x * y >= 0"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
    60
    "(x::int) >= 0 \<Longrightarrow> y >= 0 \<Longrightarrow> tsub x y >= 0"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
    61
    "(x::int) >= 0 \<Longrightarrow> x^n >= 0"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
    62
    "(0::int) >= 0"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
    63
    "(1::int) >= 0"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
    64
    "(2::int) >= 0"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
    65
    "(3::int) >= 0"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
    66
    "int z >= 0"
33340
a165b97f3658 moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents: 33318
diff changeset
    67
  by (auto simp add: zero_le_mult_iff tsub_def)
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
    68
35683
70ace653fe77 misc tuning
haftmann
parents: 35644
diff changeset
    69
lemma transfer_nat_int_relations [transfer key: transfer_morphism_nat_int]:
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
    70
    "x >= 0 \<Longrightarrow> y >= 0 \<Longrightarrow>
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
    71
      (nat (x::int) = nat y) = (x = y)"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
    72
    "x >= 0 \<Longrightarrow> y >= 0 \<Longrightarrow>
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
    73
      (nat (x::int) < nat y) = (x < y)"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
    74
    "x >= 0 \<Longrightarrow> y >= 0 \<Longrightarrow>
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
    75
      (nat (x::int) <= nat y) = (x <= y)"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
    76
    "x >= 0 \<Longrightarrow> y >= 0 \<Longrightarrow>
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
    77
      (nat (x::int) dvd nat y) = (x dvd y)"
32558
e6e1fc2e73cb obey underscore naming convention
haftmann
parents: 32554
diff changeset
    78
  by (auto simp add: zdvd_int)
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
    79
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
    80
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 58889
diff changeset
    81
text \<open>first-order quantifiers\<close>
33318
ddd97d9dfbfb moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents: 32558
diff changeset
    82
ddd97d9dfbfb moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents: 32558
diff changeset
    83
lemma all_nat: "(\<forall>x. P x) \<longleftrightarrow> (\<forall>x\<ge>0. P (nat x))"
63648
f9f3006a5579 "split add" -> "split"
nipkow
parents: 62348
diff changeset
    84
  by (simp split: split_nat)
33318
ddd97d9dfbfb moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents: 32558
diff changeset
    85
ddd97d9dfbfb moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents: 32558
diff changeset
    86
lemma ex_nat: "(\<exists>x. P x) \<longleftrightarrow> (\<exists>x. 0 \<le> x \<and> P (nat x))"
ddd97d9dfbfb moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents: 32558
diff changeset
    87
proof
ddd97d9dfbfb moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents: 32558
diff changeset
    88
  assume "\<exists>x. P x"
ddd97d9dfbfb moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents: 32558
diff changeset
    89
  then obtain x where "P x" ..
ddd97d9dfbfb moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents: 32558
diff changeset
    90
  then have "int x \<ge> 0 \<and> P (nat (int x))" by simp
ddd97d9dfbfb moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents: 32558
diff changeset
    91
  then show "\<exists>x\<ge>0. P (nat x)" ..
ddd97d9dfbfb moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents: 32558
diff changeset
    92
next
ddd97d9dfbfb moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents: 32558
diff changeset
    93
  assume "\<exists>x\<ge>0. P (nat x)"
ddd97d9dfbfb moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents: 32558
diff changeset
    94
  then show "\<exists>x. P x" by auto
ddd97d9dfbfb moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents: 32558
diff changeset
    95
qed
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
    96
35683
70ace653fe77 misc tuning
haftmann
parents: 35644
diff changeset
    97
lemma transfer_nat_int_quantifiers [transfer key: transfer_morphism_nat_int]:
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
    98
    "(ALL (x::nat). P x) = (ALL (x::int). x >= 0 \<longrightarrow> P (nat x))"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
    99
    "(EX (x::nat). P x) = (EX (x::int). x >= 0 & P (nat x))"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   100
  by (rule all_nat, rule ex_nat)
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   101
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   102
(* should we restrict these? *)
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   103
lemma all_cong: "(\<And>x. Q x \<Longrightarrow> P x = P' x) \<Longrightarrow>
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   104
    (ALL x. Q x \<longrightarrow> P x) = (ALL x. Q x \<longrightarrow> P' x)"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   105
  by auto
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   106
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   107
lemma ex_cong: "(\<And>x. Q x \<Longrightarrow> P x = P' x) \<Longrightarrow>
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   108
    (EX x. Q x \<and> P x) = (EX x. Q x \<and> P' x)"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   109
  by auto
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   110
35644
d20cf282342e transfer: avoid camel case
haftmann
parents: 35551
diff changeset
   111
declare transfer_morphism_nat_int [transfer add
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   112
  cong: all_cong ex_cong]
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   113
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   114
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 58889
diff changeset
   115
text \<open>if\<close>
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   116
35683
70ace653fe77 misc tuning
haftmann
parents: 35644
diff changeset
   117
lemma nat_if_cong [transfer key: transfer_morphism_nat_int]:
70ace653fe77 misc tuning
haftmann
parents: 35644
diff changeset
   118
  "(if P then (nat x) else (nat y)) = nat (if P then x else y)"
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   119
  by auto
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   120
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   121
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 58889
diff changeset
   122
text \<open>operations with sets\<close>
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   123
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   124
definition
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   125
  nat_set :: "int set \<Rightarrow> bool"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   126
where
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   127
  "nat_set S = (ALL x:S. x >= 0)"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   128
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   129
lemma transfer_nat_int_set_functions:
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   130
    "card A = card (int ` A)"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   131
    "{} = nat ` ({}::int set)"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   132
    "A Un B = nat ` (int ` A Un int ` B)"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   133
    "A Int B = nat ` (int ` A Int int ` B)"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   134
    "{x. P x} = nat ` {x. x >= 0 & P(nat x)}"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   135
  apply (rule card_image [symmetric])
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   136
  apply (auto simp add: inj_on_def image_def)
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   137
  apply (rule_tac x = "int x" in bexI)
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   138
  apply auto
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   139
  apply (rule_tac x = "int x" in bexI)
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   140
  apply auto
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   141
  apply (rule_tac x = "int x" in bexI)
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   142
  apply auto
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   143
  apply (rule_tac x = "int x" in exI)
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   144
  apply auto
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   145
done
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   146
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   147
lemma transfer_nat_int_set_function_closures:
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   148
    "nat_set {}"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   149
    "nat_set A \<Longrightarrow> nat_set B \<Longrightarrow> nat_set (A Un B)"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   150
    "nat_set A \<Longrightarrow> nat_set B \<Longrightarrow> nat_set (A Int B)"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   151
    "nat_set {x. x >= 0 & P x}"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   152
    "nat_set (int ` C)"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   153
    "nat_set A \<Longrightarrow> x : A \<Longrightarrow> x >= 0" (* does it hurt to turn this on? *)
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   154
  unfolding nat_set_def apply auto
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   155
done
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   156
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   157
lemma transfer_nat_int_set_relations:
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   158
    "(finite A) = (finite (int ` A))"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   159
    "(x : A) = (int x : int ` A)"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   160
    "(A = B) = (int ` A = int ` B)"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   161
    "(A < B) = (int ` A < int ` B)"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   162
    "(A <= B) = (int ` A <= int ` B)"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   163
  apply (rule iffI)
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   164
  apply (erule finite_imageI)
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   165
  apply (erule finite_imageD)
39302
d7728f65b353 renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
nipkow
parents: 39198
diff changeset
   166
  apply (auto simp add: image_def set_eq_iff inj_on_def)
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   167
  apply (drule_tac x = "int x" in spec, auto)
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   168
  apply (drule_tac x = "int x" in spec, auto)
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   169
  apply (drule_tac x = "int x" in spec, auto)
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   170
done
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   171
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   172
lemma transfer_nat_int_set_return_embed: "nat_set A \<Longrightarrow>
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   173
    (int ` nat ` A = A)"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   174
  by (auto simp add: nat_set_def image_def)
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   175
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   176
lemma transfer_nat_int_set_cong: "(!!x. x >= 0 \<Longrightarrow> P x = P' x) \<Longrightarrow>
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   177
    {(x::int). x >= 0 & P x} = {x. x >= 0 & P' x}"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   178
  by auto
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   179
35644
d20cf282342e transfer: avoid camel case
haftmann
parents: 35551
diff changeset
   180
declare transfer_morphism_nat_int [transfer add
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   181
  return: transfer_nat_int_set_functions
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   182
    transfer_nat_int_set_function_closures
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   183
    transfer_nat_int_set_relations
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   184
    transfer_nat_int_set_return_embed
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   185
  cong: transfer_nat_int_set_cong
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   186
]
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   187
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   188
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
   189
text \<open>sum and prod\<close>
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   190
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   191
(* this handles the case where the *domain* of f is nat *)
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   192
lemma transfer_nat_int_sum_prod:
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63648
diff changeset
   193
    "sum f A = sum (%x. f (nat x)) (int ` A)"
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
   194
    "prod f A = prod (%x. f (nat x)) (int ` A)"
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63648
diff changeset
   195
  apply (subst sum.reindex)
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   196
  apply (unfold inj_on_def, auto)
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
   197
  apply (subst prod.reindex)
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   198
  apply (unfold inj_on_def o_def, auto)
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   199
done
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   200
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   201
(* this handles the case where the *range* of f is nat *)
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   202
lemma transfer_nat_int_sum_prod2:
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63648
diff changeset
   203
    "sum f A = nat(sum (%x. int (f x)) A)"
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
   204
    "prod f A = nat(prod (%x. int (f x)) A)"
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63648
diff changeset
   205
  apply (simp only: int_sum [symmetric] nat_int)
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
   206
  apply (simp only: int_prod [symmetric] nat_int)
61649
268d88ec9087 Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
paulson <lp15@cam.ac.uk>
parents: 60758
diff changeset
   207
  done
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   208
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   209
lemma transfer_nat_int_sum_prod_closure:
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63648
diff changeset
   210
    "nat_set A \<Longrightarrow> (!!x. x >= 0 \<Longrightarrow> f x >= (0::int)) \<Longrightarrow> sum f A >= 0"
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
   211
    "nat_set A \<Longrightarrow> (!!x. x >= 0 \<Longrightarrow> f x >= (0::int)) \<Longrightarrow> prod f A >= 0"
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   212
  unfolding nat_set_def
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63648
diff changeset
   213
  apply (rule sum_nonneg)
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   214
  apply auto
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
   215
  apply (rule prod_nonneg)
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   216
  apply auto
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   217
done
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   218
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   219
(* this version doesn't work, even with nat_set A \<Longrightarrow>
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   220
      x : A \<Longrightarrow> x >= 0 turned on. Why not?
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   221
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   222
  also: what does =simp=> do?
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   223
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   224
lemma transfer_nat_int_sum_prod_closure:
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63648
diff changeset
   225
    "(!!x. x : A  ==> f x >= (0::int)) \<Longrightarrow> sum f A >= 0"
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
   226
    "(!!x. x : A  ==> f x >= (0::int)) \<Longrightarrow> prod f A >= 0"
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   227
  unfolding nat_set_def simp_implies_def
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63648
diff changeset
   228
  apply (rule sum_nonneg)
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   229
  apply auto
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
   230
  apply (rule prod_nonneg)
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   231
  apply auto
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   232
done
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   233
*)
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   234
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   235
(* Making A = B in this lemma doesn't work. Why not?
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
   236
   Also, why aren't sum.cong and prod.cong enough,
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   237
   with the previously mentioned rule turned on? *)
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   238
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   239
lemma transfer_nat_int_sum_prod_cong:
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   240
    "A = B \<Longrightarrow> nat_set B \<Longrightarrow> (!!x. x >= 0 \<Longrightarrow> f x = g x) \<Longrightarrow>
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63648
diff changeset
   241
      sum f A = sum g B"
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   242
    "A = B \<Longrightarrow> nat_set B \<Longrightarrow> (!!x. x >= 0 \<Longrightarrow> f x = g x) \<Longrightarrow>
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
   243
      prod f A = prod g B"
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   244
  unfolding nat_set_def
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63648
diff changeset
   245
  apply (subst sum.cong, assumption)
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   246
  apply auto [2]
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
   247
  apply (subst prod.cong, assumption, auto)
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   248
done
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   249
35644
d20cf282342e transfer: avoid camel case
haftmann
parents: 35551
diff changeset
   250
declare transfer_morphism_nat_int [transfer add
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   251
  return: transfer_nat_int_sum_prod transfer_nat_int_sum_prod2
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   252
    transfer_nat_int_sum_prod_closure
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   253
  cong: transfer_nat_int_sum_prod_cong]
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   254
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   255
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 58889
diff changeset
   256
subsection \<open>Set up transfer from int to nat\<close>
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   257
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 58889
diff changeset
   258
text \<open>set up transfer direction\<close>
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   259
42870
36abaf4cce1f clarified vacuous nature of predicate "transfer_morphism" -- equivalent to previous definiton
krauss
parents: 39302
diff changeset
   260
lemma transfer_morphism_int_nat: "transfer_morphism int (\<lambda>n. True)" ..
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   261
35644
d20cf282342e transfer: avoid camel case
haftmann
parents: 35551
diff changeset
   262
declare transfer_morphism_int_nat [transfer add
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   263
  mode: manual
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   264
  return: nat_int
35683
70ace653fe77 misc tuning
haftmann
parents: 35644
diff changeset
   265
  labels: int_nat
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   266
]
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   267
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   268
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 58889
diff changeset
   269
text \<open>basic functions and relations\<close>
33318
ddd97d9dfbfb moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents: 32558
diff changeset
   270
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   271
definition
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   272
  is_nat :: "int \<Rightarrow> bool"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   273
where
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   274
  "is_nat x = (x >= 0)"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   275
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   276
lemma transfer_int_nat_numerals:
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   277
    "0 = int 0"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   278
    "1 = int 1"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   279
    "2 = int 2"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   280
    "3 = int 3"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   281
  by auto
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   282
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   283
lemma transfer_int_nat_functions:
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   284
    "(int x) + (int y) = int (x + y)"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   285
    "(int x) * (int y) = int (x * y)"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   286
    "tsub (int x) (int y) = int (x - y)"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   287
    "(int x)^n = int (x^n)"
62348
9a5f43dac883 dropped various legacy fact bindings
haftmann
parents: 61649
diff changeset
   288
  by (auto simp add: of_nat_mult tsub_def of_nat_power)
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   289
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   290
lemma transfer_int_nat_function_closures:
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   291
    "is_nat x \<Longrightarrow> is_nat y \<Longrightarrow> is_nat (x + y)"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   292
    "is_nat x \<Longrightarrow> is_nat y \<Longrightarrow> is_nat (x * y)"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   293
    "is_nat x \<Longrightarrow> is_nat y \<Longrightarrow> is_nat (tsub x y)"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   294
    "is_nat x \<Longrightarrow> is_nat (x^n)"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   295
    "is_nat 0"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   296
    "is_nat 1"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   297
    "is_nat 2"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   298
    "is_nat 3"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   299
    "is_nat (int z)"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   300
  by (simp_all only: is_nat_def transfer_nat_int_function_closures)
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   301
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   302
lemma transfer_int_nat_relations:
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   303
    "(int x = int y) = (x = y)"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   304
    "(int x < int y) = (x < y)"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   305
    "(int x <= int y) = (x <= y)"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   306
    "(int x dvd int y) = (x dvd y)"
33318
ddd97d9dfbfb moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents: 32558
diff changeset
   307
  by (auto simp add: zdvd_int)
32121
a7bc3141e599 UNIV_code now named UNIV_apply
haftmann
parents: 31708
diff changeset
   308
35644
d20cf282342e transfer: avoid camel case
haftmann
parents: 35551
diff changeset
   309
declare transfer_morphism_int_nat [transfer add return:
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   310
  transfer_int_nat_numerals
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   311
  transfer_int_nat_functions
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   312
  transfer_int_nat_function_closures
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   313
  transfer_int_nat_relations
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   314
]
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   315
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   316
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 58889
diff changeset
   317
text \<open>first-order quantifiers\<close>
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   318
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   319
lemma transfer_int_nat_quantifiers:
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   320
    "(ALL (x::int) >= 0. P x) = (ALL (x::nat). P (int x))"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   321
    "(EX (x::int) >= 0. P x) = (EX (x::nat). P (int x))"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   322
  apply (subst all_nat)
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   323
  apply auto [1]
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   324
  apply (subst ex_nat)
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   325
  apply auto
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   326
done
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   327
35644
d20cf282342e transfer: avoid camel case
haftmann
parents: 35551
diff changeset
   328
declare transfer_morphism_int_nat [transfer add
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   329
  return: transfer_int_nat_quantifiers]
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   330
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   331
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 58889
diff changeset
   332
text \<open>if\<close>
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   333
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   334
lemma int_if_cong: "(if P then (int x) else (int y)) =
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   335
    int (if P then x else y)"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   336
  by auto
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   337
35644
d20cf282342e transfer: avoid camel case
haftmann
parents: 35551
diff changeset
   338
declare transfer_morphism_int_nat [transfer add return: int_if_cong]
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   339
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   340
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   341
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 58889
diff changeset
   342
text \<open>operations with sets\<close>
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   343
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   344
lemma transfer_int_nat_set_functions:
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   345
    "nat_set A \<Longrightarrow> card A = card (nat ` A)"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   346
    "{} = int ` ({}::nat set)"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   347
    "nat_set A \<Longrightarrow> nat_set B \<Longrightarrow> A Un B = int ` (nat ` A Un nat ` B)"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   348
    "nat_set A \<Longrightarrow> nat_set B \<Longrightarrow> A Int B = int ` (nat ` A Int nat ` B)"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   349
    "{x. x >= 0 & P x} = int ` {x. P(int x)}"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   350
       (* need all variants of these! *)
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   351
  by (simp_all only: is_nat_def transfer_nat_int_set_functions
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   352
          transfer_nat_int_set_function_closures
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   353
          transfer_nat_int_set_return_embed nat_0_le
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   354
          cong: transfer_nat_int_set_cong)
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   355
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   356
lemma transfer_int_nat_set_function_closures:
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   357
    "nat_set {}"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   358
    "nat_set A \<Longrightarrow> nat_set B \<Longrightarrow> nat_set (A Un B)"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   359
    "nat_set A \<Longrightarrow> nat_set B \<Longrightarrow> nat_set (A Int B)"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   360
    "nat_set {x. x >= 0 & P x}"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   361
    "nat_set (int ` C)"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   362
    "nat_set A \<Longrightarrow> x : A \<Longrightarrow> is_nat x"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   363
  by (simp_all only: transfer_nat_int_set_function_closures is_nat_def)
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   364
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   365
lemma transfer_int_nat_set_relations:
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   366
    "nat_set A \<Longrightarrow> finite A = finite (nat ` A)"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   367
    "is_nat x \<Longrightarrow> nat_set A \<Longrightarrow> (x : A) = (nat x : nat ` A)"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   368
    "nat_set A \<Longrightarrow> nat_set B \<Longrightarrow> (A = B) = (nat ` A = nat ` B)"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   369
    "nat_set A \<Longrightarrow> nat_set B \<Longrightarrow> (A < B) = (nat ` A < nat ` B)"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   370
    "nat_set A \<Longrightarrow> nat_set B \<Longrightarrow> (A <= B) = (nat ` A <= nat ` B)"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   371
  by (simp_all only: is_nat_def transfer_nat_int_set_relations
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   372
    transfer_nat_int_set_return_embed nat_0_le)
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   373
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   374
lemma transfer_int_nat_set_return_embed: "nat ` int ` A = A"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   375
  by (simp only: transfer_nat_int_set_relations
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   376
    transfer_nat_int_set_function_closures
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   377
    transfer_nat_int_set_return_embed nat_0_le)
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   378
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   379
lemma transfer_int_nat_set_cong: "(!!x. P x = P' x) \<Longrightarrow>
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   380
    {(x::nat). P x} = {x. P' x}"
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   381
  by auto
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   382
35644
d20cf282342e transfer: avoid camel case
haftmann
parents: 35551
diff changeset
   383
declare transfer_morphism_int_nat [transfer add
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   384
  return: transfer_int_nat_set_functions
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   385
    transfer_int_nat_set_function_closures
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   386
    transfer_int_nat_set_relations
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   387
    transfer_int_nat_set_return_embed
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   388
  cong: transfer_int_nat_set_cong
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   389
]
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   390
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   391
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
   392
text \<open>sum and prod\<close>
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   393
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   394
(* this handles the case where the *domain* of f is int *)
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   395
lemma transfer_int_nat_sum_prod:
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63648
diff changeset
   396
    "nat_set A \<Longrightarrow> sum f A = sum (%x. f (int x)) (nat ` A)"
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
   397
    "nat_set A \<Longrightarrow> prod f A = prod (%x. f (int x)) (nat ` A)"
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63648
diff changeset
   398
  apply (subst sum.reindex)
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   399
  apply (unfold inj_on_def nat_set_def, auto simp add: eq_nat_nat_iff)
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
   400
  apply (subst prod.reindex)
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   401
  apply (unfold inj_on_def nat_set_def o_def, auto simp add: eq_nat_nat_iff
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
   402
            cong: prod.cong)
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   403
done
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   404
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   405
(* this handles the case where the *range* of f is int *)
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   406
lemma transfer_int_nat_sum_prod2:
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63648
diff changeset
   407
    "(!!x. x:A \<Longrightarrow> is_nat (f x)) \<Longrightarrow> sum f A = int(sum (%x. nat (f x)) A)"
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   408
    "(!!x. x:A \<Longrightarrow> is_nat (f x)) \<Longrightarrow>
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
   409
      prod f A = int(prod (%x. nat (f x)) A)"
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   410
  unfolding is_nat_def
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63648
diff changeset
   411
  by (subst int_sum) auto
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   412
35644
d20cf282342e transfer: avoid camel case
haftmann
parents: 35551
diff changeset
   413
declare transfer_morphism_int_nat [transfer add
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   414
  return: transfer_int_nat_sum_prod transfer_int_nat_sum_prod2
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
   415
  cong: sum.cong prod.cong]
31708
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   416
a3fce678c320 add NatTransfer.thy, needed for new GCD library
huffman
parents:
diff changeset
   417
end