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