reserve i1 for Element of INT;
reserve j1,j2,j3 for Integer;
reserve p,s,k,n for Nat;
reserve x,y,xp,yp for set;
reserve G for Group;
reserve a,b for Element of G;
reserve F for FinSequence of G;
reserve I for FinSequence of INT;

theorem Th5:
  b in gr {a} iff ex j1 st b=a|^j1
proof
A1: (ex j1 st b=a|^j1) implies b in gr {a}
  proof
    given j1 such that
A2: b =a|^j1;
    consider n being Nat such that
A3: j1 = n or j1 = -n by INT_1:2;
    per cases by A3;
    suppose
A4:   j1=n;
      ex F,I st len F = len I & rng F c= {a} & Product(F |^ I) = b
      proof
        take F =(n |-> a);
A5:     len F = n by CARD_1:def 7
          .= len(n |->@ 1) by CARD_1:def 7;
        Product(F|^(n |->@ 1)) = Product(F|^(len F |->@ 1)) by CARD_1:def 7
          .=Product(n |-> a) by GROUP_4:25
          .=b by A2,A4,GROUP_4:12;
        hence thesis by A5,FUNCOP_1:13;
      end;
      hence thesis by GROUP_4:28;
    end;
    suppose
      j1 = -n;
      then
A6:   b"=a|^(-(-n)) by A2,GROUP_1:36
        .= a|^n;
      ex F,I st len F = len I & rng F c= {a} & Product(F |^ I) = b"
      proof
        take F =(n |-> a);
A7:     len F = n by CARD_1:def 7
          .= len(n |->@ 1) by CARD_1:def 7;
        Product(F|^(n |->@ 1)) = Product(F|^(len F |->@ 1)) by CARD_1:def 7
          .=Product(n |-> a) by GROUP_4:25
          .= b" by A6,GROUP_4:12;
        hence thesis by A7,FUNCOP_1:13;
      end;
      then b" in gr {a} by GROUP_4:28;
      then b"" in gr {a} by GROUP_2:51;
      hence thesis;
    end;
  end;
  b in gr {a} implies ex j1 st b=a|^j1
  proof
    assume b in gr {a};
    then consider F,I such that
A8: len F = len I and
A9: rng F c= {a} and
A10: Product(F |^ I ) = b by GROUP_4:28;
    take Sum I;
A11: for p be Nat st p in dom F holds F.p = ((len F)|-> a).p
    proof
      let p be Nat;
A12:  dom F = Seg len F by FINSEQ_1:def 3;
      assume
A13:  p in dom F;
      then F.p in rng F by FUNCT_1:def 3;
      then F.p = a by A9,TARSKI:def 1
        .= ((len F)|-> a).p by A12,A13,FUNCOP_1:7;
      hence thesis;
    end;
    dom ((len F) |-> a) = Seg len F by FUNCOP_1:13
      .= dom F by FINSEQ_1:def 3;
    then b= Product(((len I) |-> a)|^I) by A8,A10,A11,FINSEQ_1:13
      .= a|^Sum I by Th4;
    hence thesis;
  end;
  hence thesis by A1;
end;
