:: Euler's Function
:: by Yoshinori Fujisawa and Yasushi Fuwa
::
:: Received December 10, 1997
:: Copyright (c) 1997-2021 Association of Mizar Users


Lm1: for k being Nat
for j being Integer st k <> 0 & [\(j / k)/] + 1 >= j / k holds
k >= j - ([\(j / k)/] * k)

proof end;

Lm2: not 1 is prime
by INT_2:def 4;

theorem Th1: :: EULER_1:1
for n being Nat holds
( n,n are_coprime iff n = 1 )
proof end;

theorem Th2: :: EULER_1:2
for k, n being Nat st k <> 0 & k < n & n is prime holds
k,n are_coprime
proof end;

theorem Th3: :: EULER_1:3
for k, n being Nat holds
( n is prime & k in { kk where kk is Element of NAT : ( n,kk are_coprime & kk >= 1 & kk <= n ) } iff ( n is prime & k in Segm n & not k in {0} ) )
proof end;

theorem Th4: :: EULER_1:4
for A being finite set
for x being set st x in A holds
card (A \ {x}) = (card A) - (card {x}) by CARD_2:44, ZFMISC_1:31;

:: !!! ???
theorem Th5: :: EULER_1:5
for a, b being Nat st a gcd b = 1 holds
for c being Nat holds (a * c) gcd (b * c) = c
proof end;

theorem Th6: :: EULER_1:6
for a, b, c being Nat st a <> 0 & c <> 0 & (a * c) gcd (b * c) = c holds
a,b are_coprime
proof end;

theorem Th7: :: EULER_1:7
for a, b being Nat st a gcd b = 1 holds
(a + b) gcd b = 1
proof end;

theorem Th8: :: EULER_1:8
for a, b, c being Nat holds (a + (b * c)) gcd b = a gcd b
proof end;

theorem Th9: :: EULER_1:9
for m, n being Nat st m,n are_coprime holds
ex k being Nat st
( ex i0, j0 being Integer st
( k = (i0 * m) + (j0 * n) & k > 0 ) & ( for l being Nat st ex i, j being Integer st
( l = (i * m) + (j * n) & l > 0 ) holds
k <= l ) )
proof end;

theorem Th10: :: EULER_1:10
for m, n being Nat st m,n are_coprime holds
for k being Nat ex i, j being Integer st (i * m) + (j * n) = k
proof end;

theorem Th11: :: EULER_1:11
for A being set
for B being non empty set
for f being Function of A,B st f is bijective holds
card A = card B
proof end;

theorem Th12: :: EULER_1:12
for i, k, n being Integer holds (i + (k * n)) mod n = i mod n
proof end;

theorem Th13: :: EULER_1:13
for a, b, c being Nat st c divides a * b & a,c are_coprime holds
c divides b
proof end;

theorem Th14: :: EULER_1:14
for a, b, c being Nat st a <> 0 & c <> 0 & a,c are_coprime & b,c are_coprime holds
a * b,c are_coprime
proof end;

theorem Th15: :: EULER_1:15
for i, x, y being Integer st x <> 0 & i >= 0 holds
(i * x) gcd (i * y) = i * (x gcd y)
proof end;

theorem Th16: :: EULER_1:16
for a, b being Nat
for x being Integer st a <> 0 holds
(a + (x * b)) gcd b = a gcd b
proof end;

definition
let n be Nat;
func Euler n -> Element of NAT equals :: EULER_1:def 1
card { k where k is Element of NAT : ( n,k are_coprime & k >= 1 & k <= n ) } ;
coherence
card { k where k is Element of NAT : ( n,k are_coprime & k >= 1 & k <= n ) } is Element of NAT
proof end;
end;

:: deftheorem defines Euler EULER_1:def 1 :
for n being Nat holds Euler n = card { k where k is Element of NAT : ( n,k are_coprime & k >= 1 & k <= n ) } ;

set X = { k where k is Element of NAT : ( 1,k are_coprime & k >= 1 & k <= 1 ) } ;

for x being object holds
( x in { k where k is Element of NAT : ( 1,k are_coprime & k >= 1 & k <= 1 ) } iff x = 1 )

proof end;

then Lm3: card {1} = Euler 1
by TARSKI:def 1;

theorem :: EULER_1:17
Euler 1 = 1 by Lm3, CARD_1:30;

set X = { k where k is Element of NAT : ( 2,k are_coprime & k >= 1 & k <= 2 ) } ;

for x being object holds
( x in { k where k is Element of NAT : ( 2,k are_coprime & k >= 1 & k <= 2 ) } iff x = 1 )

proof end;

then Lm4: card {1} = Euler 2
by TARSKI:def 1;

theorem :: EULER_1:18
Euler 2 = 1 by Lm4, CARD_1:30;

theorem Th19: :: EULER_1:19
for n being Nat st n > 1 holds
Euler n <= n - 1
proof end;

theorem :: EULER_1:20
for n being Nat st n is prime holds
Euler n = n - 1
proof end;

theorem :: EULER_1:21
for m, n being Nat st m > 1 & n > 1 & m,n are_coprime holds
Euler (m * n) = (Euler m) * (Euler n)
proof end;