
theorem Th12:
  for p being Nat st p > 1 holds INT.Ring(p) is
  add-associative right_zeroed right_complementable Abelian commutative
  associative well-unital distributive almost_left_invertible non degenerated
  non empty doubleLoopStr iff p is Prime
proof
  let p be Nat;
  assume
A1: p > 1;
  then reconsider p as non zero Nat;
  reconsider P = INT.Ring(p) as Ring by A1,Th11;
  reconsider p as non zero Element of NAT by ORDINAL1:def 12;
A2: now
    assume
A3: INT.Ring(p) is add-associative right_zeroed right_complementable
Abelian commutative associative well-unital distributive almost_left_invertible
    non degenerated non empty doubleLoopStr;
    for n being Nat holds n divides p implies n = 1 or n = p
    proof
      let n be Nat;
      assume n divides p;
      then consider k being Nat such that
A4:   p = n * k by NAT_D:def 3;
A5:   n <= p
      proof
        assume
A6:     n > p;
        now
          per cases;
          case
            k = 0;
            hence thesis by A4;
          end;
          case
A7:         k <> 0;
            then k >= 1 + 0 by INT_1:7;
            then k * p >= 1 * p by XREAL_1:64;
            hence thesis by A4,A6,A7,XREAL_1:68;
          end;
        end;
        hence thesis;
      end;
A8:   k <= p
      proof
        assume
A9:     k > p;
        now
          per cases;
          case
            n = 0;
            hence thesis by A4;
          end;
          case
A10:        n <> 0;
            then n >= 1 + 0 by INT_1:7;
            then n * p >= 1 * p by XREAL_1:64;
            hence thesis by A4,A9,A10,XREAL_1:68;
          end;
        end;
        hence thesis;
      end;
      now
        per cases;
        case
          k = p;
          then 1 * p = p * n by A4;
          hence thesis by XCMPLX_1:5;
        end;
        case
          k <> p;
          then
A11:      k < p by A8,XXREAL_0:1;
          now
            per cases;
            case
              n = p;
              then 1 * p = k * p by A4;
              then k = 1 by XCMPLX_1:5;
              hence thesis by A4;
            end;
            case
              n <> p;
              then n < p by A5,XXREAL_0:1;
              then reconsider n2 = n as Element of Segm(p) by NAT_1:44;
              0 in Segm p by NAT_1:44;
              then
A12:            0 = 0.(INT.Ring p) by SUBSET_1:def 8;
              k <> 0 by A4;
              then
A13:          k <> 0.(INT.Ring(p)) by A12;
              reconsider k2 = k as Element of Segm(p) by A11,NAT_1:44;
              reconsider n9 = n2 as Element of INT.Ring(p);
              reconsider k9 = k2 as Element of INT.Ring(p);
              n <> 0 by A4;
              then
A14:          n <> 0.(INT.Ring(p)) by A12;
              n9 * k9 = (n2 * k2) mod p by Def10
                .= 0.(INT.Ring(p)) by A12,A4,INT_1:62;
              hence contradiction by A3,A14,A13,VECTSP_1:12;
            end;
          end;
          hence thesis;
        end;
      end;
      hence thesis;
    end;
    hence p is Prime by A1,INT_2:def 4;
  end;
  now
    assume
A15: p is Prime;
    for a being Element of P st a <> 0.P ex b be Element of P st b * a = 1.P
    proof
      reconsider e = 1 as Integer;
      let a be Element of P;
      reconsider a9 = a as Element of Segm(p);
      reconsider a9 as Element of NAT;
      reconsider a2 = a9 as Integer;
      1 * p = p;
      then
A16:  1 divides p by NAT_D:def 3;
      assume
A17:  a <> 0.P;
A18:  for m being Nat st m divides a9 & m divides p holds m divides 1
      proof
        let m be Nat;
        assume that
A19:    m divides a9 and
A20:    m divides p;
        consider k being Nat such that
A21:    a9 = m * k by A19,NAT_D:def 3;
        m <= a9
        proof
          assume
A22:      m > a9;
          now
            per cases;
            case
              k = 0;
              hence thesis by A17,A21,SUBSET_1:def 8;
            end;
            case
A23:          k <> 0;
              then k >= 1 + 0 by INT_1:7;
              then k * a9 >= 1 * a9 by XREAL_1:64;
              hence thesis by A21,A22,A23,XREAL_1:68;
            end;
          end;
          hence thesis;
        end;
        then m <> p by NAT_1:44;
        hence thesis by A15,A20,INT_2:def 4;
      end;
      1 * a9 = a9;
      then 1 divides a9 by NAT_D:def 3;
      then a9 gcd p = 1 by A16,A18,NAT_D:def 5;
      then consider s,t being Integer such that
A24:  1 = s * a9 + t * p by NAT_D:68;
      s mod p >= 0 by NAT_D:62;
      then
A25:  s mod p is Element of NAT by INT_1:3;
      s mod p < p by NAT_D:62;
      then reconsider b9 = s mod p as Element of Segm(p) by A25,NAT_1:44;
      reconsider b = b9 as Element of P;
      b * a = (a9 * b9) mod p by Def10
        .= ((a2 mod p) * ((s mod p) mod p)) mod p by NAT_D:67
        .= ((a2 mod p) * (s mod p)) mod p by NAT_D:65
        .= (a2 * s) mod p by NAT_D:67
        .= e mod p by A24,NAT_D:61
        .= e by A1,NAT_D:63
        .= 1.P by A1,Lm7;
      hence thesis;
    end;
    hence INT.Ring(p) is add-associative right_zeroed right_complementable
Abelian commutative associative well-unital distributive almost_left_invertible
    non degenerated non empty doubleLoopStr by A1,Th11,VECTSP_1:def 9;
  end;
  hence thesis by A2;
end;
