:: BINARITH semantic presentation

definition
let c1 be Nat;
let c2 be non empty set ;
mode Tuple of a1,a2 is Element of a1 -tuples_on a2;
end;

Lemma1: for b1, b2 being Nat holds addnat . b1,b2 = b1 + b2
by BINOP_2:def 23;

theorem Th1: :: BINARITH:1
canceled;

theorem Th2: :: BINARITH:2
for b1, b2 being Nat
for b3 being non empty set
for b4 being Element of b3
for b5 being Tuple of b2,b3 st b1 in Seg b2 holds
(b5 ^ <*b4*>) /. b1 = b5 /. b1
proof end;

theorem Th3: :: BINARITH:3
for b1 being Nat
for b2 being non empty set
for b3 being Element of b2
for b4 being Tuple of b1,b2 holds (b4 ^ <*b3*>) /. (b1 + 1) = b3
proof end;

theorem Th4: :: BINARITH:4
canceled;

theorem Th5: :: BINARITH:5
for b1, b2 being Nat st b1 in Seg b2 holds
not b1 is empty by CARD_1:51, FINSEQ_1:3;

definition
let c1, c2 be boolean set ;
func c1 'or' c2 -> set equals :: BINARITH:def 1
'not' (('not' a1) '&' ('not' a2));
correctness
coherence
'not' (('not' c1) '&' ('not' c2)) is set
;
;
commutativity
for b1 being set
for b2, b3 being boolean set st b1 = 'not' (('not' b2) '&' ('not' b3)) holds
b1 = 'not' (('not' b3) '&' ('not' b2))
;
end;

:: deftheorem Def1 defines 'or' BINARITH:def 1 :
for b1, b2 being boolean set holds b1 'or' b2 = 'not' (('not' b1) '&' ('not' b2));

definition
let c1, c2 be boolean set ;
func c1 'xor' c2 -> set equals :: BINARITH:def 2
(('not' a1) '&' a2) 'or' (a1 '&' ('not' a2));
correctness
coherence
(('not' c1) '&' c2) 'or' (c1 '&' ('not' c2)) is set
;
;
commutativity
for b1 being set
for b2, b3 being boolean set st b1 = (('not' b2) '&' b3) 'or' (b2 '&' ('not' b3)) holds
b1 = (('not' b3) '&' b2) 'or' (b3 '&' ('not' b2))
;
end;

:: deftheorem Def2 defines 'xor' BINARITH:def 2 :
for b1, b2 being boolean set holds b1 'xor' b2 = (('not' b1) '&' b2) 'or' (b1 '&' ('not' b2));

registration
let c1, c2 be boolean set ;
cluster a1 'or' a2 -> boolean ;
correctness
coherence
c1 'or' c2 is boolean
;
;
end;

registration
let c1, c2 be boolean set ;
cluster a1 'xor' a2 -> boolean ;
correctness
coherence
c1 'xor' c2 is boolean
;
;
end;

definition
let c1, c2 be Element of BOOLEAN ;
redefine func 'or' as c1 'or' c2 -> Element of BOOLEAN ;
correctness
coherence
c1 'or' c2 is Element of BOOLEAN
;
by MARGREL1:def 15;
redefine func 'xor' as c1 'xor' c2 -> Element of BOOLEAN ;
correctness
coherence
c1 'xor' c2 is Element of BOOLEAN
;
by MARGREL1:def 15;
end;

theorem Th6: :: BINARITH:6
canceled;

theorem Th7: :: BINARITH:7
for b1 being boolean set holds b1 'or' FALSE = b1
proof end;

theorem Th8: :: BINARITH:8
canceled;

theorem Th9: :: BINARITH:9
for b1, b2 being boolean set holds 'not' (b1 '&' b2) = ('not' b1) 'or' ('not' b2)
proof end;

theorem Th10: :: BINARITH:10
for b1, b2 being boolean set holds 'not' (b1 'or' b2) = ('not' b1) '&' ('not' b2) by MARGREL1:40;

theorem Th11: :: BINARITH:11
canceled;

theorem Th12: :: BINARITH:12
for b1, b2 being boolean set holds b1 '&' b2 = 'not' (('not' b1) 'or' ('not' b2))
proof end;

theorem Th13: :: BINARITH:13
for b1 being boolean set holds TRUE 'xor' b1 = 'not' b1
proof end;

theorem Th14: :: BINARITH:14
for b1 being boolean set holds FALSE 'xor' b1 = b1
proof end;

theorem Th15: :: BINARITH:15
for b1 being boolean set holds b1 'xor' b1 = FALSE
proof end;

theorem Th16: :: BINARITH:16
for b1 being boolean set holds b1 '&' b1 = b1
proof end;

theorem Th17: :: BINARITH:17
for b1 being boolean set holds b1 'xor' ('not' b1) = TRUE
proof end;

theorem Th18: :: BINARITH:18
for b1 being boolean set holds b1 'or' ('not' b1) = TRUE by MARGREL1:47;

theorem Th19: :: BINARITH:19
for b1 being boolean set holds b1 'or' TRUE = TRUE
proof end;

theorem Th20: :: BINARITH:20
for b1, b2, b3 being boolean set holds (b1 'or' b2) 'or' b3 = b1 'or' (b2 'or' b3)
proof end;

theorem Th21: :: BINARITH:21
for b1 being boolean set holds b1 'or' b1 = b1
proof end;

theorem Th22: :: BINARITH:22
for b1, b2, b3 being boolean set holds b1 '&' (b2 'or' b3) = (b1 '&' b2) 'or' (b1 '&' b3)
proof end;

theorem Th23: :: BINARITH:23
for b1, b2, b3 being boolean set holds b1 'or' (b2 '&' b3) = (b1 'or' b2) '&' (b1 'or' b3)
proof end;

theorem Th24: :: BINARITH:24
for b1, b2 being boolean set holds b1 'or' (b1 '&' b2) = b1
proof end;

theorem Th25: :: BINARITH:25
for b1, b2 being boolean set holds b1 '&' (b1 'or' b2) = b1
proof end;

theorem Th26: :: BINARITH:26
for b1, b2 being boolean set holds b1 'or' (('not' b1) '&' b2) = b1 'or' b2
proof end;

theorem Th27: :: BINARITH:27
for b1, b2 being boolean set holds b1 '&' (('not' b1) 'or' b2) = b1 '&' b2
proof end;

theorem Th28: :: BINARITH:28
canceled;

theorem Th29: :: BINARITH:29
canceled;

theorem Th30: :: BINARITH:30
canceled;

theorem Th31: :: BINARITH:31
canceled;

theorem Th32: :: BINARITH:32
canceled;

theorem Th33: :: BINARITH:33
TRUE 'xor' FALSE = TRUE
proof end;

theorem Th34: :: BINARITH:34
for b1, b2, b3 being boolean set holds (b1 'xor' b2) 'xor' b3 = b1 'xor' (b2 'xor' b3)
proof end;

theorem Th35: :: BINARITH:35
for b1, b2 being boolean set holds b1 'xor' (('not' b1) '&' b2) = b1 'or' b2
proof end;

theorem Th36: :: BINARITH:36
for b1, b2 being boolean set holds b1 'or' (b1 'xor' b2) = b1 'or' b2
proof end;

theorem Th37: :: BINARITH:37
for b1, b2 being boolean set holds b1 'or' (('not' b1) 'xor' b2) = b1 'or' ('not' b2)
proof end;

theorem Th38: :: BINARITH:38
for b1, b2, b3 being boolean set holds b1 '&' (b2 'xor' b3) = (b1 '&' b2) 'xor' (b1 '&' b3)
proof end;

definition
let c1, c2 be natural number ;
func c1 -' c2 -> Nat equals :Def3: :: BINARITH:def 3
a1 - a2 if a1 - a2 >= 0
otherwise 0;
coherence
( ( c1 - c2 >= 0 implies c1 - c2 is Nat ) & ( not c1 - c2 >= 0 implies 0 is Nat ) )
by INT_1:16;
correctness
consistency
for b1 being Nat holds verum
;
;
end;

:: deftheorem Def3 defines -' BINARITH:def 3 :
for b1, b2 being natural number holds
( ( b1 - b2 >= 0 implies b1 -' b2 = b1 - b2 ) & ( not b1 - b2 >= 0 implies b1 -' b2 = 0 ) );

theorem Th39: :: BINARITH:39
for b1, b2 being natural number holds (b1 + b2) -' b2 = b1
proof end;

definition
let c1 be Nat;
let c2 be Tuple of c1,BOOLEAN ;
func 'not' c2 -> Tuple of a1,BOOLEAN means :: BINARITH:def 4
for b1 being Nat st b1 in Seg a1 holds
a3 /. b1 = 'not' (a2 /. b1);
existence
ex b1 being Tuple of c1,BOOLEAN st
for b2 being Nat st b2 in Seg c1 holds
b1 /. b2 = 'not' (c2 /. b2)
proof end;
uniqueness
for b1, b2 being Tuple of c1,BOOLEAN st ( for b3 being Nat st b3 in Seg c1 holds
b1 /. b3 = 'not' (c2 /. b3) ) & ( for b3 being Nat st b3 in Seg c1 holds
b2 /. b3 = 'not' (c2 /. b3) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def4 defines 'not' BINARITH:def 4 :
for b1 being Nat
for b2, b3 being Tuple of b1,BOOLEAN holds
( b3 = 'not' b2 iff for b4 being Nat st b4 in Seg b1 holds
b3 /. b4 = 'not' (b2 /. b4) );

definition
let c1 be non empty Nat;
let c2, c3 be Tuple of c1,BOOLEAN ;
func carry c2,c3 -> Tuple of a1,BOOLEAN means :Def5: :: BINARITH:def 5
( a4 /. 1 = FALSE & ( for b1 being Nat st 1 <= b1 & b1 < a1 holds
a4 /. (b1 + 1) = (((a2 /. b1) '&' (a3 /. b1)) 'or' ((a2 /. b1) '&' (a4 /. b1))) 'or' ((a3 /. b1) '&' (a4 /. b1)) ) );
existence
ex b1 being Tuple of c1,BOOLEAN st
( b1 /. 1 = FALSE & ( for b2 being Nat st 1 <= b2 & b2 < c1 holds
b1 /. (b2 + 1) = (((c2 /. b2) '&' (c3 /. b2)) 'or' ((c2 /. b2) '&' (b1 /. b2))) 'or' ((c3 /. b2) '&' (b1 /. b2)) ) )
proof end;
uniqueness
for b1, b2 being Tuple of c1,BOOLEAN st b1 /. 1 = FALSE & ( for b3 being Nat st 1 <= b3 & b3 < c1 holds
b1 /. (b3 + 1) = (((c2 /. b3) '&' (c3 /. b3)) 'or' ((c2 /. b3) '&' (b1 /. b3))) 'or' ((c3 /. b3) '&' (b1 /. b3)) ) & b2 /. 1 = FALSE & ( for b3 being Nat st 1 <= b3 & b3 < c1 holds
b2 /. (b3 + 1) = (((c2 /. b3) '&' (c3 /. b3)) 'or' ((c2 /. b3) '&' (b2 /. b3))) 'or' ((c3 /. b3) '&' (b2 /. b3)) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def5 defines carry BINARITH:def 5 :
for b1 being non empty Nat
for b2, b3, b4 being Tuple of b1,BOOLEAN holds
( b4 = carry b2,b3 iff ( b4 /. 1 = FALSE & ( for b5 being Nat st 1 <= b5 & b5 < b1 holds
b4 /. (b5 + 1) = (((b2 /. b5) '&' (b3 /. b5)) 'or' ((b2 /. b5) '&' (b4 /. b5))) 'or' ((b3 /. b5) '&' (b4 /. b5)) ) ) );

definition
let c1 be Nat;
let c2 be Tuple of c1,BOOLEAN ;
func Binary c2 -> Tuple of a1,NAT means :Def6: :: BINARITH:def 6
for b1 being Nat st b1 in Seg a1 holds
a3 /. b1 = IFEQ (a2 /. b1),FALSE ,0,(2 to_power (b1 -' 1));
existence
ex b1 being Tuple of c1,NAT st
for b2 being Nat st b2 in Seg c1 holds
b1 /. b2 = IFEQ (c2 /. b2),FALSE ,0,(2 to_power (b2 -' 1))
proof end;
uniqueness
for b1, b2 being Tuple of c1,NAT st ( for b3 being Nat st b3 in Seg c1 holds
b1 /. b3 = IFEQ (c2 /. b3),FALSE ,0,(2 to_power (b3 -' 1)) ) & ( for b3 being Nat st b3 in Seg c1 holds
b2 /. b3 = IFEQ (c2 /. b3),FALSE ,0,(2 to_power (b3 -' 1)) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def6 defines Binary BINARITH:def 6 :
for b1 being Nat
for b2 being Tuple of b1,BOOLEAN
for b3 being Tuple of b1,NAT holds
( b3 = Binary b2 iff for b4 being Nat st b4 in Seg b1 holds
b3 /. b4 = IFEQ (b2 /. b4),FALSE ,0,(2 to_power (b4 -' 1)) );

definition
let c1 be Nat;
let c2 be Tuple of c1,BOOLEAN ;
func Absval c2 -> Nat equals :: BINARITH:def 7
addnat $$ (Binary a2);
correctness
coherence
addnat $$ (Binary c2) is Nat
;
;
end;

:: deftheorem Def7 defines Absval BINARITH:def 7 :
for b1 being Nat
for b2 being Tuple of b1,BOOLEAN holds Absval b2 = addnat $$ (Binary b2);

definition
let c1 be non empty Nat;
let c2, c3 be Tuple of c1,BOOLEAN ;
func c2 + c3 -> Tuple of a1,BOOLEAN means :Def8: :: BINARITH:def 8
for b1 being Nat st b1 in Seg a1 holds
a4 /. b1 = ((a2 /. b1) 'xor' (a3 /. b1)) 'xor' ((carry a2,a3) /. b1);
existence
ex b1 being Tuple of c1,BOOLEAN st
for b2 being Nat st b2 in Seg c1 holds
b1 /. b2 = ((c2 /. b2) 'xor' (c3 /. b2)) 'xor' ((carry c2,c3) /. b2)
proof end;
uniqueness
for b1, b2 being Tuple of c1,BOOLEAN st ( for b3 being Nat st b3 in Seg c1 holds
b1 /. b3 = ((c2 /. b3) 'xor' (c3 /. b3)) 'xor' ((carry c2,c3) /. b3) ) & ( for b3 being Nat st b3 in Seg c1 holds
b2 /. b3 = ((c2 /. b3) 'xor' (c3 /. b3)) 'xor' ((carry c2,c3) /. b3) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def8 defines + BINARITH:def 8 :
for b1 being non empty Nat
for b2, b3, b4 being Tuple of b1,BOOLEAN holds
( b4 = b2 + b3 iff for b5 being Nat st b5 in Seg b1 holds
b4 /. b5 = ((b2 /. b5) 'xor' (b3 /. b5)) 'xor' ((carry b2,b3) /. b5) );

definition
let c1 be non empty Nat;
let c2, c3 be Tuple of c1,BOOLEAN ;
func add_ovfl c2,c3 -> Element of BOOLEAN equals :: BINARITH:def 9
(((a2 /. a1) '&' (a3 /. a1)) 'or' ((a2 /. a1) '&' ((carry a2,a3) /. a1))) 'or' ((a3 /. a1) '&' ((carry a2,a3) /. a1));
correctness
coherence
(((c2 /. c1) '&' (c3 /. c1)) 'or' ((c2 /. c1) '&' ((carry c2,c3) /. c1))) 'or' ((c3 /. c1) '&' ((carry c2,c3) /. c1)) is Element of BOOLEAN
;
;
end;

:: deftheorem Def9 defines add_ovfl BINARITH:def 9 :
for b1 being non empty Nat
for b2, b3 being Tuple of b1,BOOLEAN holds add_ovfl b2,b3 = (((b2 /. b1) '&' (b3 /. b1)) 'or' ((b2 /. b1) '&' ((carry b2,b3) /. b1))) 'or' ((b3 /. b1) '&' ((carry b2,b3) /. b1));

scheme :: BINARITH:sch 1
s1{ P1[ Nat] } :
for b1 being non empty Nat holds P1[b1]
provided
E25: P1[1] and
E26: for b1 being non empty Nat st P1[b1] holds
P1[b1 + 1]
proof end;

definition
let c1 be non empty Nat;
let c2, c3 be Tuple of c1,BOOLEAN ;
pred c2,c3 are_summable means :Def10: :: BINARITH:def 10
add_ovfl a2,a3 = FALSE ;
end;

:: deftheorem Def10 defines are_summable BINARITH:def 10 :
for b1 being non empty Nat
for b2, b3 being Tuple of b1,BOOLEAN holds
( b2,b3 are_summable iff add_ovfl b2,b3 = FALSE );

theorem Th40: :: BINARITH:40
for b1 being Tuple of 1,BOOLEAN holds
( b1 = <*FALSE *> or b1 = <*TRUE *> )
proof end;

theorem Th41: :: BINARITH:41
for b1 being Tuple of 1,BOOLEAN st b1 = <*FALSE *> holds
Absval b1 = 0
proof end;

theorem Th42: :: BINARITH:42
for b1 being Tuple of 1,BOOLEAN st b1 = <*TRUE *> holds
Absval b1 = 1
proof end;

definition
let c1 be non empty Nat;
let c2 be Nat;
let c3 be non empty set ;
let c4 be Tuple of c1,c3;
let c5 be Tuple of c2,c3;
redefine func ^ as c4 ^ c5 -> Tuple of (a1 + a2),a3;
coherence
c4 ^ c5 is Tuple of (c1 + c2),c3
by FINSEQ_2:127;
end;

definition
let c1 be non empty set ;
let c2 be Element of c1;
redefine func <* as <*c2*> -> Tuple of 1,a1;
coherence
<*c2*> is Tuple of 1,c1
by FINSEQ_2:118;
end;

theorem Th43: :: BINARITH:43
for b1 being non empty Nat
for b2, b3 being Tuple of b1,BOOLEAN
for b4, b5 being Element of BOOLEAN
for b6 being Nat st b6 in Seg b1 holds
(carry (b2 ^ <*b4*>),(b3 ^ <*b5*>)) /. b6 = (carry b2,b3) /. b6
proof end;

theorem Th44: :: BINARITH:44
for b1 being non empty Nat
for b2, b3 being Tuple of b1,BOOLEAN
for b4, b5 being Element of BOOLEAN holds add_ovfl b2,b3 = (carry (b2 ^ <*b4*>),(b3 ^ <*b5*>)) /. (b1 + 1)
proof end;

theorem Th45: :: BINARITH:45
for b1 being non empty Nat
for b2, b3 being Tuple of b1,BOOLEAN
for b4, b5 being Element of BOOLEAN holds (b2 ^ <*b4*>) + (b3 ^ <*b5*>) = (b2 + b3) ^ <*((b4 'xor' b5) 'xor' (add_ovfl b2,b3))*>
proof end;

theorem Th46: :: BINARITH:46
for b1 being non empty Nat
for b2 being Tuple of b1,BOOLEAN
for b3 being Element of BOOLEAN holds Absval (b2 ^ <*b3*>) = (Absval b2) + (IFEQ b3,FALSE ,0,(2 to_power b1))
proof end;

theorem Th47: :: BINARITH:47
for b1 being non empty Nat
for b2, b3 being Tuple of b1,BOOLEAN holds (Absval (b2 + b3)) + (IFEQ (add_ovfl b2,b3),FALSE ,0,(2 to_power b1)) = (Absval b2) + (Absval b3)
proof end;

theorem Th48: :: BINARITH:48
for b1 being non empty Nat
for b2, b3 being Tuple of b1,BOOLEAN st b2,b3 are_summable holds
Absval (b2 + b3) = (Absval b2) + (Absval b3)
proof end;

theorem Th49: :: BINARITH:49
for b1, b2, b3 being natural number st b1 <= b2 & b1 <= b3 & b2 -' b1 = b3 -' b1 holds
b2 = b3
proof end;

theorem Th50: :: BINARITH:50
for b1, b2 being natural number st b1 <= b2 holds
b2 -' b1 = b2 - b1
proof end;

theorem Th51: :: BINARITH:51
for b1 being natural number holds b1 -' b1 = 0
proof end;

theorem Th52: :: BINARITH:52
for b1, b2 being natural number holds b1 -' b2 <= b1
proof end;

theorem Th53: :: BINARITH:53
for b1, b2 being natural number st b1 >= b2 holds
(b1 -' b2) + b2 = b1
proof end;