:: BINARI_2 semantic presentation
Lemma1:
for b1 being Nat
for b2, b3 being Tuple of b1,BOOLEAN holds
( len b2 = b1 & len b3 = b1 & ( for b4 being Nat holds
( b4 in Seg b1 implies b2 /. b4 = b3 /. b4 ) ) implies b2 = b3 )
definition
let c
1 be
Nat;
func Bin1 c
1 -> Tuple of a
1,
BOOLEAN means :
Def1:
:: BINARI_2:def 1
for b
1 being
Nat holds
( b
1 in Seg a
1 implies a
2 /. b
1 = IFEQ b
1,1,
TRUE ,
FALSE );
existence
ex b1 being Tuple of c1,BOOLEAN st
for b2 being Nat holds
( b2 in Seg c1 implies b1 /. b2 = IFEQ b2,1,TRUE ,FALSE )
proof
deffunc H
1(
set )
-> Element of
BOOLEAN =
IFEQ a
1,1,
TRUE ,
FALSE ;
consider c
2 being
FinSequence of
BOOLEAN such that E2:
len c
2 = c
1
and E3:
for b
1 being
Nat holds
( b
1 in Seg c
1 implies c
2 . b
1 = H
1(b
1) )
from FINSEQ_2:sch 1();
reconsider c
3 = c
2 as
Tuple of c
1,
BOOLEAN by E2, FINSEQ_2:110;
take
c
3
;
let c
4 be
Nat;
assume E4:
c
4 in Seg c
1
;
then
c
4 in dom c
3
by E2, FINSEQ_1:def 3;
hence c
3 /. c
4 =
c
3 . c
4
by FINSEQ_4:def 4
.=
IFEQ c
4,1,
TRUE ,
FALSE
by E3, E4
;
end;
uniqueness
for b1, b2 being Tuple of c1,BOOLEAN holds
( ( for b3 being Nat holds
( b3 in Seg c1 implies b1 /. b3 = IFEQ b3,1,TRUE ,FALSE ) ) & ( for b3 being Nat holds
( b3 in Seg c1 implies b2 /. b3 = IFEQ b3,1,TRUE ,FALSE ) ) implies b1 = b2 )
end;
:: deftheorem Def1 defines Bin1 BINARI_2:def 1 :
:: deftheorem Def2 defines Neg2 BINARI_2:def 2 :
:: deftheorem Def3 defines Intval BINARI_2:def 3 :
:: deftheorem Def4 defines Int_add_ovfl BINARI_2:def 4 :
:: deftheorem Def5 defines Int_add_udfl BINARI_2:def 5 :
theorem Th1: :: BINARI_2:1
canceled;
theorem Th2: :: BINARI_2:2
canceled;
theorem Th3: :: BINARI_2:3
proof
let c
1 be
Tuple of 2,
BOOLEAN ;
assume E4:
c
1 = <*FALSE *> ^ <*FALSE *>
;
consider c
2, c
3 being
Nat such that E5:
Binary c
1 = <*c2,c3*>
by FINSEQ_2:120;
c
1 = <*FALSE ,FALSE *>
by E4, FINSEQ_1:def 9;
then E6:
( c
1 /. 1
= FALSE & c
1 /. 2
= FALSE )
by FINSEQ_4:26;
E7:
1
in Seg 1
by FINSEQ_1:5;
Seg 1
c= Seg 2
by FINSEQ_1:7;
then E8:
(Binary c1) /. 1 =
IFEQ (c1 /. 1),
FALSE ,0,
(2 to_power (1 -' 1))
by E7, BINARITH:def 6
.=
0
by E6, CQC_LANG:def 1
;
E9:
(Binary c1) /. 1
= c
2
by E5, FINSEQ_4:26;
2
in Seg 2
by FINSEQ_1:5;
then E10:
(Binary c1) /. 2 =
IFEQ (c1 /. 2),
FALSE ,0,
(2 to_power (2 -' 1))
by BINARITH:def 6
.=
0
by E6, CQC_LANG:def 1
;
(Binary c1) /. 2
= c
3
by E5, FINSEQ_4:26;
then Absval c
1 =
addnat $$ <*0,0*>
by E5, E8, E9, E10, BINARITH:def 7
.=
addnat $$ (<*0*> ^ <*0*>)
by FINSEQ_1:def 9
.=
addnat . (addnat $$ <*0*>),
(addnat $$ <*0*>)
by FINSOP_1:6
.=
addnat . 0,
(addnat $$ <*0*>)
by FINSOP_1:12
.=
addnat . 0,0
by FINSOP_1:12
.=
0
+ 0
by BINOP_2:def 23
.=
0
;
hence
Intval c
1 = 0
by E6, Def3;
end;
theorem Th4: :: BINARI_2:4
proof
let c
1 be
Tuple of 2,
BOOLEAN ;
assume E5:
c
1 = <*TRUE *> ^ <*FALSE *>
;
consider c
2, c
3 being
Nat such that E6:
Binary c
1 = <*c2,c3*>
by FINSEQ_2:120;
c
1 = <*TRUE ,FALSE *>
by E5, FINSEQ_1:def 9;
then E7:
( c
1 /. 1
= TRUE & c
1 /. 2
= FALSE )
by FINSEQ_4:26;
E8:
1
in Seg 1
by FINSEQ_1:5;
Seg 1
c= Seg 2
by FINSEQ_1:7;
then E9:
(Binary c1) /. 1 =
IFEQ (c1 /. 1),
FALSE ,0,
(2 to_power (1 -' 1))
by E8, BINARITH:def 6
.=
2
to_power (1 -' 1)
by E7, CQC_LANG:def 1
;
1
- 1
= 0
;
then
1
-' 1
= 0
by BINARITH:def 3;
then E10:
(Binary c1) /. 1
= 1
by E9, POWER:29;
E11:
(Binary c1) /. 1
= c
2
by E6, FINSEQ_4:26;
2
in Seg 2
by FINSEQ_1:5;
then E12:
(Binary c1) /. 2 =
IFEQ (c1 /. 2),
FALSE ,0,
(2 to_power (2 -' 1))
by BINARITH:def 6
.=
0
by E7, CQC_LANG:def 1
;
(Binary c1) /. 2
= c
3
by E6, FINSEQ_4:26;
then Absval c
1 =
addnat $$ <*1,0*>
by E6, E10, E11, E12, BINARITH:def 7
.=
addnat $$ (<*1*> ^ <*0*>)
by FINSEQ_1:def 9
.=
addnat . (addnat $$ <*1*>),
(addnat $$ <*0*>)
by FINSOP_1:6
.=
addnat . 1,
(addnat $$ <*0*>)
by FINSOP_1:12
.=
addnat . 1,0
by FINSOP_1:12
.=
1
+ 0
by BINOP_2:def 23
.=
1
;
hence
Intval c
1 = 1
by E7, Def3;
end;
theorem Th5: :: BINARI_2:5
proof
let c
1 be
Tuple of 2,
BOOLEAN ;
assume E5:
c
1 = <*FALSE *> ^ <*TRUE *>
;
consider c
2, c
3 being
Nat such that E6:
Binary c
1 = <*c2,c3*>
by FINSEQ_2:120;
c
1 = <*FALSE ,TRUE *>
by E5, FINSEQ_1:def 9;
then E7:
( c
1 /. 1
= FALSE & c
1 /. 2
= TRUE )
by FINSEQ_4:26;
then E8:
Intval c
1 =
(Absval c1) - (2 to_power (1 + 1))
by Def3
.=
(Absval c1) - ((2 to_power 1) * (2 to_power 1))
by POWER:32
.=
(Absval c1) - (2 * (2 to_power 1))
by POWER:30
.=
(Absval c1) - (2 * 2)
by POWER:30
.=
(Absval c1) - 4
;
E9:
1
in Seg 1
by FINSEQ_1:5;
Seg 1
c= Seg 2
by FINSEQ_1:7;
then E10:
(Binary c1) /. 1 =
IFEQ (c1 /. 1),
FALSE ,0,
(2 to_power (1 -' 1))
by E9, BINARITH:def 6
.=
0
by E7, CQC_LANG:def 1
;
E11:
(Binary c1) /. 1
= c
2
by E6, FINSEQ_4:26;
2
in Seg 2
by FINSEQ_1:5;
then E12:
(Binary c1) /. 2 =
IFEQ (c1 /. 2),
FALSE ,0,
(2 to_power (2 -' 1))
by BINARITH:def 6
.=
2
to_power (2 -' 1)
by E7, CQC_LANG:def 1
;
2
- 1
= 1
;
then
2
-' 1
= 1
by BINARITH:def 3;
then E13:
(Binary c1) /. 2
= 2
by E12, POWER:30;
(Binary c1) /. 2
= c
3
by E6, FINSEQ_4:26;
then Absval c
1 =
addnat $$ <*0,2*>
by E6, E10, E11, E13, BINARITH:def 7
.=
addnat $$ (<*0*> ^ <*2*>)
by FINSEQ_1:def 9
.=
addnat . (addnat $$ <*0*>),
(addnat $$ <*2*>)
by FINSOP_1:6
.=
addnat . 0,
(addnat $$ <*2*>)
by FINSOP_1:12
.=
addnat . 0,2
by FINSOP_1:12
.=
0
+ 2
by BINOP_2:def 23
.=
2
;
hence
Intval c
1 = - 2
by E8;
end;
theorem Th6: :: BINARI_2:6
proof
let c
1 be
Tuple of 2,
BOOLEAN ;
assume E5:
c
1 = <*TRUE *> ^ <*TRUE *>
;
consider c
2, c
3 being
Nat such that E6:
Binary c
1 = <*c2,c3*>
by FINSEQ_2:120;
c
1 = <*TRUE ,TRUE *>
by E5, FINSEQ_1:def 9;
then E7:
( c
1 /. 1
<> FALSE & c
1 /. 2
<> FALSE )
by FINSEQ_4:26;
then E8:
Intval c
1 =
(Absval c1) - (2 to_power (1 + 1))
by Def3
.=
(Absval c1) - ((2 to_power 1) * (2 to_power 1))
by POWER:32
.=
(Absval c1) - (2 * (2 to_power 1))
by POWER:30
.=
(Absval c1) - (2 * 2)
by POWER:30
.=
(Absval c1) - 4
;
E9:
1
in Seg 1
by FINSEQ_1:5;
Seg 1
c= Seg 2
by FINSEQ_1:7;
then E10:
(Binary c1) /. 1 =
IFEQ (c1 /. 1),
FALSE ,0,
(2 to_power (1 -' 1))
by E9, BINARITH:def 6
.=
2
to_power (1 -' 1)
by E7, CQC_LANG:def 1
;
1
- 1
= 0
;
then
1
-' 1
= 0
by BINARITH:def 3;
then E11:
(Binary c1) /. 1
= 1
by E10, POWER:29;
E12:
(Binary c1) /. 1
= c
2
by E6, FINSEQ_4:26;
2
in Seg 2
by FINSEQ_1:5;
then E13:
(Binary c1) /. 2 =
IFEQ (c1 /. 2),
FALSE ,0,
(2 to_power (2 -' 1))
by BINARITH:def 6
.=
2
to_power (2 -' 1)
by E7, CQC_LANG:def 1
;
2
- 1
= 1
;
then
2
-' 1
= 1
by BINARITH:def 3;
then E14:
(Binary c1) /. 2
= 2
by E13, POWER:30;
(Binary c1) /. 2
= c
3
by E6, FINSEQ_4:26;
then Absval c
1 =
addnat $$ <*1,2*>
by E6, E11, E12, E14, BINARITH:def 7
.=
addnat $$ (<*1*> ^ <*2*>)
by FINSEQ_1:def 9
.=
addnat . (addnat $$ <*1*>),
(addnat $$ <*2*>)
by FINSOP_1:6
.=
addnat . 1,
(addnat $$ <*2*>)
by FINSOP_1:12
.=
addnat . 1,2
by FINSOP_1:12
.=
1
+ 2
by BINOP_2:def 23
.=
3
;
hence
Intval c
1 = - 1
by E8;
end;
theorem Th7: :: BINARI_2:7
theorem Th8: :: BINARI_2:8
theorem Th9: :: BINARI_2:9
theorem Th10: :: BINARI_2:10
theorem Th11: :: BINARI_2:11
theorem Th12: :: BINARI_2:12
proof
let c
1 be non
empty Nat;
let c
2 be
Tuple of c
1,
BOOLEAN ;
let c
3 be
Element of
BOOLEAN ;
per cases
( c3 = FALSE or c3 = TRUE )
by MARGREL1:39;
suppose E11:
c
3 = FALSE
;
then
(c2 ^ <*c3*>) /. (c1 + 1) = FALSE
by BINARITH:3;
then E12:
Intval (c2 ^ <*c3*>) =
Absval (c2 ^ <*c3*>)
by Def3
.=
(Absval c2) + (IFEQ c3,FALSE ,0,(2 to_power c1))
by BINARITH:46
.=
(Absval c2) + 0
by E11, CQC_LANG:def 1
.=
Absval c
2
;
(Absval c2) - (IFEQ c3,FALSE ,0,(2 to_power c1)) =
(Absval c2) - 0
by E11, CQC_LANG:def 1
.=
Absval c
2
;
hence
Intval (c2 ^ <*c3*>) = (Absval c2) - (IFEQ c3,FALSE ,0,(2 to_power c1))
by E12;
end;
end;
end;
theorem Th13: :: BINARI_2:13
for b
1 being non
empty Natfor b
2, b
3 being
Tuple of b
1,
BOOLEAN for b
4, b
5 being
Element of
BOOLEAN holds
((Intval ((b2 ^ <*b4*>) + (b3 ^ <*b5*>))) + (IFEQ (Int_add_ovfl (b2 ^ <*b4*>),(b3 ^ <*b5*>)),FALSE ,0,(2 to_power (b1 + 1)))) - (IFEQ (Int_add_udfl (b2 ^ <*b4*>),(b3 ^ <*b5*>)),FALSE ,0,(2 to_power (b1 + 1))) = (Intval (b2 ^ <*b4*>)) + (Intval (b3 ^ <*b5*>))
proof
let c
1 be non
empty Nat;
let c
2, c
3 be
Tuple of c
1,
BOOLEAN ;
let c
4, c
5 be
Element of
BOOLEAN ;
set c
6 =
FALSE ;
set c
7 =
TRUE ;
E12:
Absval (c2 + c3) = ((Absval c2) + (Absval c3)) - (IFEQ (add_ovfl c2,c3),FALSE ,0,(2 to_power c1))
proof
set c
8 =
Absval (c2 + c3);
set c
9 =
IFEQ (add_ovfl c2,c3),
FALSE ,0,
(2 to_power c1);
((Absval (c2 + c3)) + (IFEQ (add_ovfl c2,c3),FALSE ,0,(2 to_power c1))) - (IFEQ (add_ovfl c2,c3),FALSE ,0,(2 to_power c1)) = Absval (c2 + c3)
;
hence
Absval (c2 + c3) = ((Absval c2) + (Absval c3)) - (IFEQ (add_ovfl c2,c3),FALSE ,0,(2 to_power c1))
by BINARITH:47;
end;
E13:
Intval ((c2 ^ <*c4*>) + (c3 ^ <*c5*>)) =
Intval ((c2 + c3) ^ <*((c4 'xor' c5) 'xor' (add_ovfl c2,c3))*>)
by BINARITH:45
.=
((