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