src/HOL/Library/Periodic_Fun.thy
author haftmann
Wed Jul 18 20:51:21 2018 +0200 (11 months ago)
changeset 68658 16cc1161ad7f
parent 68406 6beb45f6cf67
child 69593 3dda49e08b9d
permissions -rw-r--r--
tuned equation
hoelzl@62055
     1
(*  Title:    HOL/Library/Periodic_Fun.thy
hoelzl@62055
     2
    Author:   Manuel Eberl, TU M√ľnchen
eberlm@62049
     3
*)
hoelzl@62055
     4
hoelzl@62055
     5
section \<open>Periodic Functions\<close>
hoelzl@62055
     6
eberlm@62049
     7
theory Periodic_Fun
eberlm@62049
     8
imports Complex_Main
eberlm@62049
     9
begin
eberlm@62049
    10
eberlm@62049
    11
text \<open>
hoelzl@62055
    12
  A locale for periodic functions. The idea is that one proves $f(x + p) = f(x)$
hoelzl@62055
    13
  for some period $p$ and gets derived results like $f(x - p) = f(x)$ and $f(x + 2p) = f(x)$
hoelzl@62055
    14
  for free.
hoelzl@62055
    15
eberlm@62049
    16
  @{term g} and @{term gm} are ``plus/minus k periods'' functions. 
eberlm@62049
    17
  @{term g1} and @{term gn1} are ``plus/minus one period'' functions.
eberlm@62049
    18
  This is useful e.g. if the period is one; the lemmas one gets are then 
eberlm@62049
    19
  @{term "f (x + 1) = f x"} instead of @{term "f (x + 1 * 1) = f x"} etc.
eberlm@62049
    20
\<close>
eberlm@62049
    21
locale periodic_fun = 
eberlm@62049
    22
  fixes f :: "('a :: {ring_1}) \<Rightarrow> 'b" and g gm :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" and g1 gn1 :: "'a \<Rightarrow> 'a"
eberlm@62049
    23
  assumes plus_1: "f (g1 x) = f x"
eberlm@62049
    24
  assumes periodic_arg_plus_0: "g x 0 = x"
eberlm@62049
    25
  assumes periodic_arg_plus_distrib: "g x (of_int (m + n)) = g (g x (of_int n)) (of_int m)"
eberlm@62049
    26
  assumes plus_1_eq: "g x 1 = g1 x" and minus_1_eq: "g x (-1) = gn1 x" 
eberlm@62049
    27
          and minus_eq: "g x (-y) = gm x y"
eberlm@62049
    28
begin
eberlm@62049
    29
eberlm@62049
    30
lemma plus_of_nat: "f (g x (of_nat n)) = f x"
eberlm@62049
    31
  by (induction n) (insert periodic_arg_plus_distrib[of _ 1 "int n" for n], 
eberlm@62049
    32
                    simp_all add: plus_1 periodic_arg_plus_0 plus_1_eq)
eberlm@62049
    33
eberlm@62049
    34
lemma minus_of_nat: "f (gm x (of_nat n)) = f x"
eberlm@62049
    35
proof -
eberlm@62049
    36
  have "f (g x (- of_nat n)) = f (g (g x (- of_nat n)) (of_nat n))"
eberlm@62049
    37
    by (rule plus_of_nat[symmetric])
eberlm@62049
    38
  also have "\<dots> = f (g (g x (of_int (- of_nat n))) (of_int (of_nat n)))" by simp
eberlm@62049
    39
  also have "\<dots> = f x" 
eberlm@62049
    40
    by (subst periodic_arg_plus_distrib [symmetric]) (simp add: periodic_arg_plus_0)
eberlm@62049
    41
  finally show ?thesis by (simp add: minus_eq)
eberlm@62049
    42
qed
eberlm@62049
    43
eberlm@62049
    44
lemma plus_of_int: "f (g x (of_int n)) = f x"
eberlm@62049
    45
  by (induction n) (simp_all add: plus_of_nat minus_of_nat minus_eq del: of_nat_Suc)
eberlm@62049
    46
eberlm@62049
    47
lemma minus_of_int: "f (gm x (of_int n)) = f x"
eberlm@62049
    48
  using plus_of_int[of x "of_int (-n)"] by (simp add: minus_eq)
eberlm@62049
    49
eberlm@62049
    50
lemma plus_numeral: "f (g x (numeral n)) = f x"
eberlm@62049
    51
  by (subst of_nat_numeral[symmetric], subst plus_of_nat) (rule refl)
eberlm@62049
    52
eberlm@62049
    53
lemma minus_numeral: "f (gm x (numeral n)) = f x"
eberlm@62049
    54
  by (subst of_nat_numeral[symmetric], subst minus_of_nat) (rule refl)
eberlm@62049
    55
eberlm@62049
    56
lemma minus_1: "f (gn1 x) = f x"
nipkow@68406
    57
  using minus_of_nat[of x 1] by (simp flip: minus_1_eq minus_eq)
eberlm@62049
    58
eberlm@62049
    59
lemmas periodic_simps = plus_of_nat minus_of_nat plus_of_int minus_of_int 
eberlm@62049
    60
                        plus_numeral minus_numeral plus_1 minus_1
eberlm@62049
    61
eberlm@62049
    62
end
eberlm@62049
    63
eberlm@62049
    64
eberlm@62049
    65
text \<open>
eberlm@62049
    66
  Specialised case of the @{term periodic_fun} locale for periods that are not 1.
eberlm@62049
    67
  Gives lemmas @{term "f (x - period) = f x"} etc.
eberlm@62049
    68
\<close>
eberlm@62049
    69
locale periodic_fun_simple = 
eberlm@62049
    70
  fixes f :: "('a :: {ring_1}) \<Rightarrow> 'b" and period :: 'a
eberlm@62049
    71
  assumes plus_period: "f (x + period) = f x"
eberlm@62049
    72
begin
eberlm@62049
    73
sublocale periodic_fun f "\<lambda>z x. z + x * period" "\<lambda>z x. z - x * period" 
eberlm@62049
    74
  "\<lambda>z. z + period" "\<lambda>z. z - period"
eberlm@62049
    75
  by standard (simp_all add: ring_distribs plus_period)
eberlm@62049
    76
end
eberlm@62049
    77
eberlm@62049
    78
eberlm@62049
    79
text \<open>
eberlm@62049
    80
  Specialised case of the @{term periodic_fun} locale for period 1.
eberlm@62049
    81
  Gives lemmas @{term "f (x - 1) = f x"} etc.
eberlm@62049
    82
\<close>
eberlm@62049
    83
locale periodic_fun_simple' = 
eberlm@62049
    84
  fixes f :: "('a :: {ring_1}) \<Rightarrow> 'b"
eberlm@62049
    85
  assumes plus_period: "f (x + 1) = f x"
eberlm@62049
    86
begin
eberlm@62049
    87
sublocale periodic_fun f "\<lambda>z x. z + x" "\<lambda>z x. z - x" "\<lambda>z. z + 1" "\<lambda>z. z - 1"
eberlm@62049
    88
  by standard (simp_all add: ring_distribs plus_period)
eberlm@62049
    89
eberlm@62049
    90
lemma of_nat: "f (of_nat n) = f 0" using plus_of_nat[of 0 n] by simp
eberlm@62049
    91
lemma uminus_of_nat: "f (-of_nat n) = f 0" using minus_of_nat[of 0 n] by simp
eberlm@62049
    92
lemma of_int: "f (of_int n) = f 0" using plus_of_int[of 0 n] by simp
eberlm@62049
    93
lemma uminus_of_int: "f (-of_int n) = f 0" using minus_of_int[of 0 n] by simp
eberlm@62049
    94
lemma of_numeral: "f (numeral n) = f 0" using plus_numeral[of 0 n] by simp
eberlm@62049
    95
lemma of_neg_numeral: "f (-numeral n) = f 0" using minus_numeral[of 0 n] by simp
eberlm@62049
    96
lemma of_1: "f 1 = f 0" using plus_of_nat[of 0 1] by simp
eberlm@62049
    97
lemma of_neg_1: "f (-1) = f 0" using minus_of_nat[of 0 1] by simp
eberlm@62049
    98
eberlm@62049
    99
lemmas periodic_simps' = 
eberlm@62049
   100
  of_nat uminus_of_nat of_int uminus_of_int of_numeral of_neg_numeral of_1 of_neg_1
eberlm@62049
   101
eberlm@62049
   102
end
eberlm@62049
   103
eberlm@62049
   104
lemma sin_plus_pi: "sin ((z :: 'a :: {real_normed_field,banach}) + of_real pi) = - sin z"
eberlm@62049
   105
  by (simp add: sin_add)
eberlm@62049
   106
  
eberlm@62049
   107
lemma cos_plus_pi: "cos ((z :: 'a :: {real_normed_field,banach}) + of_real pi) = - cos z"
eberlm@62049
   108
  by (simp add: cos_add)
eberlm@62049
   109
eberlm@62049
   110
interpretation sin: periodic_fun_simple sin "2 * of_real pi :: 'a :: {real_normed_field,banach}"
eberlm@62049
   111
proof
eberlm@62049
   112
  fix z :: 'a
eberlm@62049
   113
  have "sin (z + 2 * of_real pi) = sin (z + of_real pi + of_real pi)" by (simp add: ac_simps)
eberlm@62049
   114
  also have "\<dots> = sin z" by (simp only: sin_plus_pi) simp
eberlm@62049
   115
  finally show "sin (z + 2 * of_real pi) = sin z" .
eberlm@62049
   116
qed
eberlm@62049
   117
eberlm@62049
   118
interpretation cos: periodic_fun_simple cos "2 * of_real pi :: 'a :: {real_normed_field,banach}"
eberlm@62049
   119
proof
eberlm@62049
   120
  fix z :: 'a
eberlm@62049
   121
  have "cos (z + 2 * of_real pi) = cos (z + of_real pi + of_real pi)" by (simp add: ac_simps)
eberlm@62049
   122
  also have "\<dots> = cos z" by (simp only: cos_plus_pi) simp
eberlm@62049
   123
  finally show "cos (z + 2 * of_real pi) = cos z" .
eberlm@62049
   124
qed
eberlm@62049
   125
eberlm@62049
   126
interpretation tan: periodic_fun_simple tan "2 * of_real pi :: 'a :: {real_normed_field,banach}"
eberlm@62049
   127
  by standard (simp only: tan_def [abs_def] sin.plus_1 cos.plus_1)
eberlm@62049
   128
eberlm@62049
   129
interpretation cot: periodic_fun_simple cot "2 * of_real pi :: 'a :: {real_normed_field,banach}"
eberlm@62049
   130
  by standard (simp only: cot_def [abs_def] sin.plus_1 cos.plus_1)
eberlm@62049
   131
  
nipkow@62390
   132
end