:: Uniqueness of factoring an integer and multiplicative group $Z/pZ^{*}$
:: by Hiroyuki Okazaki and Yasunari Shidama
::
:: Copyright (c) 2008-2018 Association of Mizar Users

Lm1: for x, y being object
for X being set
for z being object st z <> x holds
((X --> 0) +* (x,y)) . z = 0

proof end;

theorem Th1: :: INT_7:1
for x being object
for X being set
for p being ManySortedSet of X st support p = {x} holds
p = (X --> 0) +* (x,(p . x))
proof end;

theorem Th2: :: INT_7:2
for X being set
for p, q, r being real-valued ManySortedSet of X st () /\ () = {} & () \/ () = support r & p | () = r | () & q | () = r | () holds
p + q = r
proof end;

theorem Th3: :: INT_7:3
for X being set
for p, q being ManySortedSet of X st p | () = q | () holds
p = q
proof end;

theorem Th4: :: INT_7:4
for X being set
for p, q being bag of X st support p = {} & support q = {} holds
p = q
proof end;

Lm2: for p, q being bag of SetPrimes st support p c= support q & p | () = q | () holds
ex r being bag of SetPrimes st
( support r = () \ () & support p misses support r & r | () = q | () & p + r = q )

proof end;

Lm3: for p being bag of SetPrimes
for X being set st X c= support p holds
ex q, r being bag of SetPrimes st
( support q = () \ X & support r = X & support q misses support r & q | () = p | () & r | () = p | () & q + r = p )

proof end;

definition
let p be bag of SetPrimes ;
attr p is prime-factorization-like means :: INT_7:def 1
for x being Prime st x in support p holds
ex n being Nat st
( 0 < n & p . x = x |^ n );
end;

:: deftheorem defines prime-factorization-like INT_7:def 1 :
for p being bag of SetPrimes holds
( p is prime-factorization-like iff for x being Prime st x in support p holds
ex n being Nat st
( 0 < n & p . x = x |^ n ) );

registration
let n be non zero Nat;
coherence
proof end;
end;

theorem Th5: :: INT_7:5
for p, q being Prime
for n, m being Nat st p divides m * (q |^ n) & p <> q holds
p divides m
proof end;

Lm4: for a being Prime
for b being bag of SetPrimes st b is prime-factorization-like & a in support b holds
( a divides Product b & ex n being Nat st a |^ n divides Product b )

proof end;

Lm5: for p being FinSequence of NAT
for x being Element of NAT
for b being bag of SetPrimes st b is prime-factorization-like & p ^ <*x*> = b * (canFS ()) holds
ex p1 being FinSequence of NAT ex q being Prime ex n being Element of NAT ex b1 being bag of SetPrimes st
( 0 < n & b1 is prime-factorization-like & q in support b & support b1 = () \ {q} & x = q |^ n & len p1 = len p & Product p = Product p1 & p1 = b1 * (canFS (support b1)) )

proof end;

Lm6: for i being Element of NAT
for f being FinSequence of NAT
for b being bag of SetPrimes
for a being Prime st len f = i & b is prime-factorization-like & Product b <> 1 & a divides Product b & Product b = Product f & f = b * (canFS ()) holds
a in support b

proof end;

theorem Th6: :: INT_7:6
for f being FinSequence of NAT
for b being bag of SetPrimes
for a being Prime st b is prime-factorization-like & Product b <> 1 & a divides Product b & Product b = Product f & f = b * (canFS ()) holds
a in support b
proof end;

Lm7: for a being Prime
for b being bag of SetPrimes st b is prime-factorization-like & a divides Product b holds
a in support b

proof end;

theorem Th7: :: INT_7:7
for p, q being bag of SetPrimes st support p c= support q & p | () = q | () holds
Product p divides Product q
proof end;

theorem :: INT_7:8
for p being bag of SetPrimes
for x being Prime st p is prime-factorization-like holds
( x divides Product p iff x in support p ) by ;

theorem Th9: :: INT_7:9
for n, m, k being non zero Nat st k = n lcm m holds
support (ppf k) = (support (ppf n)) \/ (support (ppf m))
proof end;

theorem Th10: :: INT_7:10
for X being set
for b1, b2 being bag of X holds support (min (b1,b2)) = (support b1) /\ (support b2)
proof end;

theorem :: INT_7:11
for n, m, k being non zero Nat st k = n gcd m holds
support (ppf k) = (support (ppf n)) /\ (support (ppf m))
proof end;

theorem Th12: :: INT_7:12
for p, q being bag of SetPrimes st p is prime-factorization-like & q is prime-factorization-like & support p misses support q holds
Product p, Product q are_coprime
proof end;

Lm8: for q being Prime
for g being Element of NAT st g <> 0 holds
ex p1 being bag of SetPrimes st
( p1 = () +* (q,g) & support p1 = {q} & Product p1 = g )

proof end;

Lm9: for p being bag of SetPrimes
for x being Prime st p is prime-factorization-like & x in support p & p . x = x holds
ex p1, r1 being bag of SetPrimes st
( p1 is prime-factorization-like & support r1 = {x} & Product r1 = x & support p1 = () \ {x} & p1 | (support p1) = p | (support p1) & Product p = (Product p1) * x )

proof end;

Lm10: for p being bag of SetPrimes
for x being Prime st p is prime-factorization-like & x in support p & p . x <> x holds
ex p1, r1 being bag of SetPrimes st
( p1 is prime-factorization-like & support r1 = {x} & Product r1 = x & support p1 = support p & p1 | ((support p1) \ {x}) = p | ((support p1) \ {x}) & p . x = (p1 . x) * x & Product p = (Product p1) * x )

proof end;

theorem Th13: :: INT_7:13
for p being bag of SetPrimes st p is prime-factorization-like holds
Product p <> 0
proof end;

theorem Th14: :: INT_7:14
for p being bag of SetPrimes st p is prime-factorization-like holds
( Product p = 1 iff support p = {} )
proof end;

Lm11: for n being Element of NAT
for p, q being bag of SetPrimes st p is prime-factorization-like & q is prime-factorization-like & Product p <= 2 |^ n & Product p = Product q holds
p = q

proof end;

:: Fundamental Theorem of Arithmetic (uniqueness)
theorem Th15: :: INT_7:15
for p, q being bag of SetPrimes st p is prime-factorization-like & q is prime-factorization-like & Product p = Product q holds
p = q
proof end;

theorem :: INT_7:16
for p being bag of SetPrimes
for n being non zero Nat st p is prime-factorization-like & n = Product p holds
ppf n = p
proof end;

theorem Th17: :: INT_7:17
for n, m being Element of NAT st 1 <= n & 1 <= m holds
ex m0, n0 being Element of NAT st
( n lcm m = n0 * m0 & n0 gcd m0 = 1 & n0 divides n & m0 divides m & n0 <> 0 & m0 <> 0 )
proof end;

definition
let n be Nat;
assume A1: 1 < n ;
func Segm0 n -> non empty finite Subset of NAT equals :Def2: :: INT_7:def 2
(Segm n) \ ;
correctness
coherence
(Segm n) \ is non empty finite Subset of NAT
;
proof end;
end;

:: deftheorem Def2 defines Segm0 INT_7:def 2 :
for n being Nat st 1 < n holds
Segm0 n = (Segm n) \ ;

theorem Th18: :: INT_7:18
for n being Nat st 1 < n holds
card () = n - 1
proof end;

definition
let n be Prime;
func multint0 n -> BinOp of () equals :: INT_7:def 3
() || ();
coherence
() || () is BinOp of ()
proof end;
end;

:: deftheorem defines multint0 INT_7:def 3 :
for n being Prime holds multint0 n = () || ();

Lm12: for p being Prime
for a, b being Element of multMagma(# (),() #)
for x, y being Element of () st a = x & y = b holds
x * y = a * b

proof end;

theorem Th19: :: INT_7:19
for p being Prime holds
( multMagma(# (),() #) is associative & multMagma(# (),() #) is commutative & multMagma(# (),() #) is Group-like )
proof end;

definition
let p be Prime;
func Z/Z* p -> commutative Group equals :: INT_7:def 4
multMagma(# (),() #);
correctness
coherence
multMagma(# (),() #) is commutative Group
;
by Th19;
end;

:: deftheorem defines Z/Z* INT_7:def 4 :
for p being Prime holds Z/Z* p = multMagma(# (),() #);

theorem :: INT_7:20
for p being Prime
for x, y being Element of (Z/Z* p)
for x1, y1 being Element of () st x = x1 & y = y1 holds
x * y = x1 * y1 by Lm12;

theorem Th21: :: INT_7:21
for p being Prime holds
( 1_ (Z/Z* p) = 1 & 1_ (Z/Z* p) = 1. () )
proof end;

theorem :: INT_7:22
for p being Prime
for x being Element of (Z/Z* p)
for x1 being Element of () st x = x1 holds
x " = x1 "
proof end;

registration
let p be Prime;
coherence
Z/Z* p is finite
;
end;

theorem :: INT_7:23
for p being Prime holds card (Z/Z* p) = p - 1 by ;

theorem :: INT_7:24
for G being Group
for a being Element of G
for i being Integer st not a is being_of_order_0 holds
ex n, k being Element of NAT st
( a |^ i = a |^ n & n = (k * (ord a)) + i )
proof end;

theorem Th25: :: INT_7:25
for G being commutative Group
for a, b being Element of G
for n, m being Nat st G is finite & ord a = n & ord b = m & n gcd m = 1 holds
ord (a * b) = n * m
proof end;

Lm13: for L being Field
for n being Element of NAT
for f being non-zero Polynomial of L st deg f = n holds
ex m being Element of NAT st
( m = card () & m <= n )

proof end;

theorem Th26: :: INT_7:26
for L being non empty ZeroStr
for p being Polynomial of L st 0 <= deg p holds
p is non-zero
proof end;

theorem Th27: :: INT_7:27
for L being Field
for f being Polynomial of L st 0 <= deg f holds
( Roots f is finite set & ex m, n being Element of NAT st
( n = deg f & m = card () & m <= n ) )
proof end;

theorem Th28: :: INT_7:28
for p being Prime
for z being Element of (Z/Z* p)
for y being Element of () st z = y holds
for n being Element of NAT holds (power (Z/Z* p)) . (z,n) = (power ()) . (y,n)
proof end;

Lm14: for p being Prime
for L being Field
for n being Nat st 0 < n & L = INT.Ring p holds
ex f being Polynomial of L st
( deg f = n & ( for x being Element of L
for xz being Element of (Z/Z* p)
for xn being Element of () st x = xz & xn = xz |^ n holds
eval (f,x) = xn - (1_ ()) ) )

proof end;

theorem Th29: :: INT_7:29
for p being Prime
for a, b being Element of (Z/Z* p)
for n being Nat st 0 < n & ord a = n & b |^ n = 1 holds
b is Element of (gr {a})
proof end;

theorem Th30: :: INT_7:30
for G being Group
for z being Element of G
for d, l being Element of NAT st G is finite & ord z = d * l holds
ord (z |^ d) = l
proof end;

theorem :: INT_7:31
for p being Prime holds Z/Z* p is cyclic Group
proof end;