:: The Divisibility of Integers and Integer Relatively Primes
:: by Rafa{\l} Kwiatek and Grzegorz Zwara
::
:: Received July 10, 1990
:: Copyright (c) 1990-2021 Association of Mizar Users


definition
let a be Integer;
:: original: |.
redefine func |.a.| -> Element of NAT ;
coherence
|.a.| is Element of NAT
proof end;
end;

theorem Th1: :: INT_2:1
for a, b, c being Integer st a divides b & a divides b + c holds
a divides c
proof end;

theorem Th2: :: INT_2:2
for a, b, c being Integer st a divides b holds
a divides b * c
proof end;

theorem :: INT_2:3
for a being Integer holds
( 0 divides a iff a = 0 ) ;

Lm1: for a being Integer holds
( a divides - a & - a divides a )

proof end;

Lm2: for a, b, c being Integer st a divides b & b divides c holds
a divides c

proof end;

Lm3: for a, b being Integer holds
( a divides b iff a divides - b )

proof end;

Lm4: for a, b being Integer holds
( a divides b iff - a divides b )

proof end;

Lm5: for a being Integer holds
( a divides 0 & 1 divides a & - 1 divides a )

proof end;

Lm6: for a, b, c being Integer st a divides b & a divides c holds
a divides b mod c

proof end;

Lm7: for k, l being Nat holds
( k divides l iff ex t being Nat st l = k * t )

proof end;

Lm8: for i, j being Nat st i divides j & j divides i holds
i = j

proof end;

definition
let a, b be Integer;
func a lcm b -> Nat means :Def1: :: INT_2:def 1
( a divides it & b divides it & ( for m being Integer st a divides m & b divides m holds
it divides m ) );
existence
ex b1 being Nat st
( a divides b1 & b divides b1 & ( for m being Integer st a divides m & b divides m holds
b1 divides m ) )
proof end;
uniqueness
for b1, b2 being Nat st a divides b1 & b divides b1 & ( for m being Integer st a divides m & b divides m holds
b1 divides m ) & a divides b2 & b divides b2 & ( for m being Integer st a divides m & b divides m holds
b2 divides m ) holds
b1 = b2
proof end;
commutativity
for b1 being Nat
for a, b being Integer st a divides b1 & b divides b1 & ( for m being Integer st a divides m & b divides m holds
b1 divides m ) holds
( b divides b1 & a divides b1 & ( for m being Integer st b divides m & a divides m holds
b1 divides m ) )
;
end;

:: deftheorem Def1 defines lcm INT_2:def 1 :
for a, b being Integer
for b3 being Nat holds
( b3 = a lcm b iff ( a divides b3 & b divides b3 & ( for m being Integer st a divides m & b divides m holds
b3 divides m ) ) );

theorem Th4: :: INT_2:4
for a, b being Integer holds
( ( a = 0 or b = 0 ) iff a lcm b = 0 )
proof end;

Lm9: for i, j being Nat st 0 < j & i divides j holds
i <= j

proof end;

definition
let a, b be Integer;
func a gcd b -> Nat means :Def2: :: INT_2:def 2
( it divides a & it divides b & ( for m being Integer st m divides a & m divides b holds
m divides it ) );
existence
ex b1 being Nat st
( b1 divides a & b1 divides b & ( for m being Integer st m divides a & m divides b holds
m divides b1 ) )
proof end;
uniqueness
for b1, b2 being Nat st b1 divides a & b1 divides b & ( for m being Integer st m divides a & m divides b holds
m divides b1 ) & b2 divides a & b2 divides b & ( for m being Integer st m divides a & m divides b holds
m divides b2 ) holds
b1 = b2
proof end;
commutativity
for b1 being Nat
for a, b being Integer st b1 divides a & b1 divides b & ( for m being Integer st m divides a & m divides b holds
m divides b1 ) holds
( b1 divides b & b1 divides a & ( for m being Integer st m divides b & m divides a holds
m divides b1 ) )
;
end;

:: deftheorem Def2 defines gcd INT_2:def 2 :
for a, b being Integer
for b3 being Nat holds
( b3 = a gcd b iff ( b3 divides a & b3 divides b & ( for m being Integer st m divides a & m divides b holds
m divides b3 ) ) );

theorem Th5: :: INT_2:5
for a, b being Integer holds
( ( a = 0 & b = 0 ) iff a gcd b = 0 )
proof end;

theorem Th6: :: INT_2:6
for n being Nat holds
( - n is Element of NAT iff n = 0 )
proof end;

registration
let n be non zero Nat;
cluster - n -> non natural ;
coherence
not - n is natural
proof end;
end;

theorem :: INT_2:7
- 1 is not Element of NAT ;

theorem :: INT_2:8
for a being Integer holds
( a divides - a & - a divides a ) by Lm1;

theorem :: INT_2:9
for a, b, c being Integer st a divides b & b divides c holds
a divides c by Lm2;

theorem Th10: :: INT_2:10
for a, b being Integer holds
( ( a divides b implies a divides - b ) & ( a divides - b implies a divides b ) & ( a divides b implies - a divides b ) & ( - a divides b implies a divides b ) & ( a divides b implies - a divides - b ) & ( - a divides - b implies a divides b ) & ( a divides - b implies - a divides b ) & ( - a divides b implies a divides - b ) )
proof end;

theorem :: INT_2:11
for a, b being Integer st a divides b & b divides a & not a = b holds
a = - b
proof end;

theorem :: INT_2:12
for a being Integer holds
( a divides 0 & 1 divides a & - 1 divides a ) by Lm5;

theorem Th13: :: INT_2:13
for a being Integer holds
( ( not a divides 1 & not a divides - 1 ) or a = 1 or a = - 1 ) by INT_1:9, INT_1:10;

theorem :: INT_2:14
for a being Integer st ( a = 1 or a = - 1 ) holds
( a divides 1 & a divides - 1 ) by Lm5;

theorem :: INT_2:15
for a, b, c being Integer holds
( a,b are_congruent_mod c iff c divides a - b ) ;

theorem :: INT_2:16
for a, b being Integer holds
( a divides b iff |.a.| divides |.b.| )
proof end;

theorem :: INT_2:17
for a, b being Integer holds a lcm b is Element of NAT by ORDINAL1:def 12;

theorem :: INT_2:18
for a, b being Integer holds a divides a lcm b by Def1;

theorem :: INT_2:19
for a, b, c being Integer st a divides c & b divides c holds
a lcm b divides c by Def1;

theorem :: INT_2:20
for a, b being Integer holds a gcd b is Element of NAT by ORDINAL1:def 12;

theorem Th21: :: INT_2:21
for a, b being Integer holds a gcd b divides a by Def2;

theorem :: INT_2:22
for a, b, c being Integer st c divides a & c divides b holds
c divides a gcd b by Def2;

:: Relative Prime Numbers
definition
let a, b be Integer;
pred a,b are_coprime means :: INT_2:def 3
a gcd b = 1;
symmetry
for a, b being Integer st a gcd b = 1 holds
b gcd a = 1
;
end;

:: deftheorem defines are_coprime INT_2:def 3 :
for a, b being Integer holds
( a,b are_coprime iff a gcd b = 1 );

theorem :: INT_2:23
for a, b being Integer st ( a <> 0 or b <> 0 ) holds
ex a1, b1 being Integer st
( a = (a gcd b) * a1 & b = (a gcd b) * b1 & a1,b1 are_coprime )
proof end;

theorem Th24: :: INT_2:24
for a, b, c being Integer st a,b are_coprime holds
( (c * a) gcd (c * b) = |.c.| & (c * a) gcd (b * c) = |.c.| & (a * c) gcd (c * b) = |.c.| & (a * c) gcd (b * c) = |.c.| )
proof end;

theorem Th25: :: INT_2:25
for a, b, c being Integer st c divides a * b & a,c are_coprime holds
c divides b
proof end;

theorem :: INT_2:26
for a, b, c being Integer st a,c are_coprime & b,c are_coprime holds
a * b,c are_coprime
proof end;

definition
let p be integer Number ;
attr p is prime means :: INT_2:def 4
( p > 1 & ( for n being Nat holds
( not n divides p or n = 1 or n = p ) ) );
end;

:: deftheorem defines prime INT_2:def 4 :
for p being integer Number holds
( p is prime iff ( p > 1 & ( for n being Nat holds
( not n divides p or n = 1 or n = p ) ) ) );

registration
cluster integer prime -> natural integer for object ;
coherence
for b1 being integer Number st b1 is prime holds
b1 is natural
proof end;
end;

theorem Th27: :: INT_2:27
for a, b being Integer st 0 < b & a divides b holds
a <= b
proof end;

theorem Th28: :: INT_2:28
2 is prime
proof end;

theorem Th29: :: INT_2:29
not 4 is prime
proof end;

registration
cluster ext-real non negative epsilon-transitive epsilon-connected ordinal natural complex V38() integer dim-like V41() V46() prime for set ;
existence
ex b1 being Nat st b1 is prime
by Th28;
cluster ext-real non negative epsilon-transitive epsilon-connected ordinal natural non zero complex V38() integer dim-like V41() V46() non prime for set ;
existence
ex b1 being Nat st
( not b1 is zero & not b1 is prime )
by Th29;
end;

theorem :: INT_2:30
for p, q being Nat st p is prime & q is prime & not p,q are_coprime holds
p = q
proof end;

theorem :: INT_2:31
for l being Nat st l >= 2 holds
ex p being Element of NAT st
( p is prime & p divides l )
proof end;

:: from AMI_4, 2007.06.14, A.T.
theorem :: INT_2:32
for i, j being Integer st i >= 0 & j >= 0 holds
( |.i.| mod |.j.| = i mod j & |.i.| div |.j.| = i div j )
proof end;

:: old definitions, 2007.11.07, A.T
theorem :: INT_2:33
for a, b being Integer holds a lcm b = |.a.| lcm |.b.|
proof end;

theorem :: INT_2:34
for a, b being Integer holds a gcd b = |.a.| gcd |.b.|
proof end;