
theorem MOS8:
  for i be Integer holds
    (i|^2) mod 8 = 0 or (i|^2) mod 8 = 1 or (i|^2) mod 8 = 4
  proof
    let i be Integer;
    A1: i|^2 mod 8 = (i*i) mod 8 by NEWTON:81
    .= ((i mod 8)*(i mod 8)) mod 8 by NAT_D:67;
    i mod (7+1) = 0 or ... or i mod (7+1) = 7 by NUMBER03:11; then
    per cases;
    suppose
      i mod (7+1) = 0;
      hence thesis by A1;
    end;
    suppose
      i mod (7+1) = 1;
      hence thesis by A1;
    end;
    suppose
      i mod (7+1)= 2; then
      (i|^2) mod (7+1) = 4 mod (4 + 4) by A1
      .= 4;
      hence thesis;
    end;
    suppose
      i mod (7+1) = 3; then
      (i|^2) mod 8 = (1*8 + 1) mod 8 by A1
      .= 1 mod (1 + 7)
      .= 1;
      hence thesis;
    end;
    suppose
      i mod (7+1) = 4; then
      (i|^2) mod 8 = (2*8 + 0) mod 8 by A1
      .= 0;
      hence thesis;
    end;
    suppose
      i mod (7+1) = 5; then
      (i|^2) mod 8 = (3*8 + 1) mod 8 by A1
      .= 1 mod (1 + 7)
      .= 1;
      hence thesis;
    end;
    suppose
      i mod (7+1)= 6; then
      (i|^2) mod 8 = (4*8 + 4) mod 8 by A1
      .= 4 mod (4 + 4) by NAT_D:21
      .= 4;
      hence thesis;
    end;
    suppose
      i mod (7+1) = 7; then
      (i|^2) mod 8 = (6*8 + 1) mod 8 by A1
      .= 1 mod (1 + 7)
      .= 1;
      hence thesis;
    end;
  end;
