Article BINARI_4, MML version 4.99.1005

:: BINARI_4:th 1
theorem
for b1 being natural set
      st 0 < b1
   holds b1 + 1 <= b1 * 2;

:: BINARI_4:th 2
theorem
for b1 being natural set holds
   b1 <= 2 to_power b1;

:: BINARI_4:th 3
theorem
for b1 being Element of NAT holds
   (0* b1) + 0* b1 = 0* b1;

:: BINARI_4:th 4
theorem
for b1, b2, b3 being natural set
      st b1 <= b3 & b3 <= b2 & b1 <> b3
   holds b1 + 1 <= b3 & b3 <= b2;

:: BINARI_4:th 5
theorem
for b1 being non empty Element of NAT
for b2, b3 being Element of b1 -tuples_on BOOLEAN
      st b2 = 0* b1 & b3 = 0* b1
   holds carry(b2,b3) = 0* b1;

:: BINARI_4:th 6
theorem
for b1 being non empty Element of NAT
for b2, b3 being Element of b1 -tuples_on BOOLEAN
      st b2 = 0* b1 & b3 = 0* b1
   holds b2 + b3 = 0* b1;

:: BINARI_4:th 7
theorem
for b1 being non empty Element of NAT
for b2 being Element of b1 -tuples_on BOOLEAN
      st b2 = 0* b1
   holds Intval b2 = 0;

:: BINARI_4:th 8
theorem
for b1, b2, b3 being Element of NAT
      st b1 + b2 <= b3 - 1
   holds b1 < b3 & b2 < b3;

:: BINARI_4:th 9
theorem
for b1, b2, b3 being integer set
      st b1 <= b2 + b3 & b2 < 0 & b3 < 0
   holds b1 < b2 & b1 < b3;

:: BINARI_4:th 10
theorem
for b1 being non empty Element of NAT
for b2, b3 being Element of NAT
      st b2 + b3 <= (2 to_power b1) - 1
   holds add_ovfl(b1 -BinarySequence b2,b1 -BinarySequence b3) = FALSE;

:: BINARI_4:th 11
theorem
for b1 being non empty Element of NAT
for b2, b3 being Element of NAT
      st b2 + b3 <= (2 to_power b1) - 1
   holds Absval ((b1 -BinarySequence b2) + (b1 -BinarySequence b3)) = b2 + b3;

:: BINARI_4:th 12
theorem
for b1 being non empty Element of NAT
for b2 being Element of b1 -tuples_on BOOLEAN
      st b2 /. b1 = TRUE
   holds 2 to_power (b1 -' 1) <= Absval b2;

:: BINARI_4:th 13
theorem
for b1 being non empty Element of NAT
for b2, b3 being Element of NAT
      st b2 + b3 <= (2 to_power (b1 -' 1)) - 1
   holds (carry(b1 -BinarySequence b2,b1 -BinarySequence b3)) /. b1 = FALSE;

:: BINARI_4:th 14
theorem
for b1, b2 being Element of NAT
for b3 being non empty Element of NAT
      st b1 + b2 <= (2 to_power (b3 -' 1)) - 1
   holds Intval ((b3 -BinarySequence b1) + (b3 -BinarySequence b2)) = b1 + b2;

:: BINARI_4:th 15
theorem
for b1 being Element of 1 -tuples_on BOOLEAN
      st b1 = <*TRUE*>
   holds Intval b1 = - 1;

:: BINARI_4:th 16
theorem
for b1 being Element of 1 -tuples_on BOOLEAN
      st b1 = <*FALSE*>
   holds Intval b1 = 0;

:: BINARI_4:th 17
theorem
for b1 being boolean set holds
   TRUE 'or' b1 = TRUE;

:: BINARI_4:th 18
theorem
for b1 being non empty Element of NAT holds
   0 <= (2 to_power (b1 -' 1)) - 1 &
    - (2 to_power (b1 -' 1)) <= 0;

:: BINARI_4:th 19
theorem
for b1 being non empty Element of NAT
for b2, b3 being Element of b1 -tuples_on BOOLEAN
      st b2 = 0* b1 & b3 = 0* b1
   holds b2,b3 are_summable;

:: BINARI_4:th 20
theorem
for b1 being non empty Element of NAT
for b2 being integer set holds
   (b2 * b1) mod b1 = 0;

:: BINARI_4:funcnot 1 => BINARI_4:func 1
definition
  let a1, a2 be natural set;
  func MajP(A1,A2) -> Element of NAT means
    a2 <= 2 to_power it &
     a1 <= it &
     (for b1 being natural set
           st a2 <= 2 to_power b1 & a1 <= b1
        holds it <= b1);
end;

:: BINARI_4:def 1
theorem
for b1, b2 being natural set
for b3 being Element of NAT holds
      b3 = MajP(b1,b2)
   iff
      b2 <= 2 to_power b3 &
       b1 <= b3 &
       (for b4 being natural set
             st b2 <= 2 to_power b4 & b1 <= b4
          holds b3 <= b4);

:: BINARI_4:th 21
theorem
for b1, b2, b3 being Element of NAT
      st b2 <= b1
   holds MajP(b3,b2) <= MajP(b3,b1);

:: BINARI_4:th 22
theorem
for b1, b2, b3 being Element of NAT
      st b2 <= b1
   holds MajP(b2,b3) <= MajP(b1,b3);

:: BINARI_4:th 23
theorem
for b1 being Element of NAT
      st 1 <= b1
   holds MajP(b1,1) = b1;

:: BINARI_4:th 24
theorem
for b1, b2 being Element of NAT
      st b1 <= 2 to_power b2
   holds MajP(b2,b1) = b2;

:: BINARI_4:th 25
theorem
for b1, b2 being Element of NAT
      st 2 to_power b2 < b1
   holds b2 < MajP(b2,b1);

:: BINARI_4:funcnot 2 => BINARI_4:func 2
definition
  let a1 be Element of NAT;
  let a2 be integer set;
  func 2sComplement(A1,A2) -> Element of a1 -tuples_on BOOLEAN equals
    a1 -BinarySequence abs ((2 to_power MajP(a1,abs a2)) + a2)
    if a2 < 0
    otherwise a1 -BinarySequence abs a2;
end;

:: BINARI_4:def 2
theorem
for b1 being Element of NAT
for b2 being integer set holds
   (0 <= b2 or 2sComplement(b1,b2) = b1 -BinarySequence abs ((2 to_power MajP(b1,abs b2)) + b2)) &
    (0 <= b2 implies 2sComplement(b1,b2) = b1 -BinarySequence abs b2);

:: BINARI_4:th 26
theorem
for b1 being Element of NAT holds
   2sComplement(b1,0) = 0* b1;

:: BINARI_4:th 27
theorem
for b1 being non empty Element of NAT
for b2 being integer set
      st b2 <= (2 to_power (b1 -' 1)) - 1 &
         - (2 to_power (b1 -' 1)) <= b2
   holds Intval 2sComplement(b1,b2) = b2;

:: BINARI_4:th 28
theorem
for b1 being non empty Element of NAT
for b2, b3 being integer set
      st (0 <= b2 & 0 <= b3 or b2 < 0 & b3 < 0) &
         b2 mod (2 to_power b1) = b3 mod (2 to_power b1)
   holds 2sComplement(b1,b2) = 2sComplement(b1,b3);

:: BINARI_4:th 29
theorem
for b1 being non empty Element of NAT
for b2, b3 being integer set
      st (0 <= b2 & 0 <= b3 or b2 < 0 & b3 < 0) &
         b2,b3 are_congruent_mod 2 to_power b1
   holds 2sComplement(b1,b2) = 2sComplement(b1,b3);

:: BINARI_4:th 30
theorem
for b1 being non empty Element of NAT
for b2, b3 being Element of NAT
      st b2 mod (2 to_power b1) = b3 mod (2 to_power b1)
   holds b1 -BinarySequence b2 = b1 -BinarySequence b3;

:: BINARI_4:th 31
theorem
for b1 being non empty Element of NAT
for b2, b3 being Element of NAT
      st b2,b3 are_congruent_mod 2 to_power b1
   holds b1 -BinarySequence b2 = b1 -BinarySequence b3;

:: BINARI_4:th 32
theorem
for b1 being non empty Element of NAT
for b2 being integer set
for b3 being Element of NAT
      st 1 <= b3 & b3 <= b1
   holds (2sComplement(b1 + 1,b2)) /. b3 = (2sComplement(b1,b2)) /. b3;

:: BINARI_4:th 33
theorem
for b1 being Element of NAT
for b2 being integer set holds
   ex b3 being Element of BOOLEAN st
      2sComplement(b1 + 1,b2) = (2sComplement(b1,b2)) ^ <*b3*>;

:: BINARI_4:th 34
theorem
for b1, b2 being Element of NAT holds
ex b3 being Element of BOOLEAN st
   (b1 + 1) -BinarySequence b2 = (b1 -BinarySequence b2) ^ <*b3*>;

:: BINARI_4:th 35
theorem
for b1, b2 being integer set
for b3 being non empty Element of NAT
      st - (2 to_power b3) <= b1 + b2 & b1 < 0 & b2 < 0 & - (2 to_power (b3 -' 1)) <= b1 & - (2 to_power (b3 -' 1)) <= b2
   holds (carry(2sComplement(b3 + 1,b1),2sComplement(b3 + 1,b2))) /. (b3 + 1) = TRUE;

:: BINARI_4:th 36
theorem
for b1, b2 being integer set
for b3 being non empty Element of NAT
      st - (2 to_power (b3 -' 1)) <= b1 + b2 &
         b1 + b2 <= (2 to_power (b3 -' 1)) - 1 &
         0 <= b1 &
         0 <= b2
   holds Intval ((2sComplement(b3,b1)) + 2sComplement(b3,b2)) = b1 + b2;

:: BINARI_4:th 37
theorem
for b1, b2 being integer set
for b3 being non empty Element of NAT
      st - (2 to_power ((b3 + 1) -' 1)) <= b1 + b2 &
         b1 + b2 <= (2 to_power ((b3 + 1) -' 1)) - 1 &
         b1 < 0 &
         b2 < 0 &
         - (2 to_power (b3 -' 1)) <= b1 &
         - (2 to_power (b3 -' 1)) <= b2
   holds Intval ((2sComplement(b3 + 1,b1)) + 2sComplement(b3 + 1,b2)) = b1 + b2;

:: BINARI_4:th 38
theorem
for b1, b2 being integer set
for b3 being non empty Element of NAT
      st - (2 to_power (b3 -' 1)) <= b1 &
         b1 <= (2 to_power (b3 -' 1)) - 1 &
         - (2 to_power (b3 -' 1)) <= b2 &
         b2 <= (2 to_power (b3 -' 1)) - 1 &
         - (2 to_power (b3 -' 1)) <= b1 + b2 &
         b1 + b2 <= (2 to_power (b3 -' 1)) - 1 &
         (0 <= b1 & b2 < 0 or b1 < 0 & 0 <= b2)
   holds Intval ((2sComplement(b3,b1)) + 2sComplement(b3,b2)) = b1 + b2;