reserve x,y for object, X for set;

theorem Th17:
  for n,m be Element of NAT st 1<=n & 1 <=m holds ex m0,n0 be
Element of NAT st n lcm m =n0*m0 & n0 gcd m0 = 1 & n0 divides n & m0 divides m
  & n0 <> 0 & m0 <> 0
proof
  let n1,m1 be Element of NAT;
  assume that
A1: 1<=n1 and
A2: 1 <=m1;
  reconsider n=n1,m=m1 as non zero Nat by A1,A2;
  set nm1 = n1 lcm m1;
  reconsider nm=nm1 as non zero Nat by A1,A2,INT_2:4;
  set N1={p where p is Element of NAT: p in (support (ppf n)) & (pfexp nm).p =
  (pfexp n). p };
  set N2= (support (ppf nm)) \ N1;
A3: N1 c= support ppf n
  proof
    let x be object;
    assume x in N1;
    then
    ex p be Element of NAT st x=p & p in (support (ppf n)) & (pfexp nm).p
    = (pfexp n). p;
    hence thesis;
  end;
A4: for x be set st x in N2 holds (pfexp nm).x = (pfexp m).x
  proof
    let x be set;
A5: (pfexp n).x > (pfexp m).x implies max(pfexp n,pfexp m).x = (pfexp n).
    x by NAT_3:def 4;
    assume x in N2;
    then
A6: not x in N1 by XBOOLE_0:def 5;
A7: support ppf n = support pfexp n by NAT_3:def 9;
A8: not (pfexp n).x > (pfexp m).x
    proof
      assume
A9:   (pfexp n).x > (pfexp m).x;
      then
A10:  (pfexp nm).x = (pfexp n). x by A5,NAT_3:54;
A11:  x in support (pfexp n) by A9,PRE_POLY:def 7;
      then x in SetPrimes;
      hence contradiction by A6,A7,A10,A11;
    end;
    (pfexp n).x <= (pfexp m).x implies max(pfexp n,pfexp m).x = (pfexp m)
    . x by NAT_3:def 4;
    hence thesis by A8,NAT_3:54;
  end;
A12: Product (ppf m)=m by NAT_3:61;
A13: support ppf nm = support ppf n \/ support ppf m by Th9;
  then
A14: support ppf n c= support ppf nm by XBOOLE_1:7;
  then consider ppm,ppn be bag of SetPrimes such that
A15: (support ppm) = (support (ppf nm)) \ N1 and
A16: (support ppn) = N1 and
A17: (support ppm) misses (support ppn) and
A18: ppm | (support ppm) =(ppf nm) | (support ppm) and
A19: ppn | (support ppn) =(ppf nm) | (support ppn) and
A20: ppm+ppn = (ppf nm) by A3,Lm3,XBOOLE_1:1;
  reconsider n0=Product ppn, m0=Product ppm as Element of NAT;
A21: Product (ppf n)=n by NAT_3:61;
A22: N2 c= support ppf m
  proof
    let x be object;
A23: (pfexp n).x <= (pfexp m).x implies max(pfexp n,pfexp m).x = (pfexp m)
    . x by NAT_3:def 4;
A24: (pfexp n).x > (pfexp m).x implies max(pfexp n,pfexp m).x = (pfexp n).
    x by NAT_3:def 4;
    assume
A25: x in N2;
    then
A26: x in SetPrimes;
A27: x in (support (ppf nm)) by A25,XBOOLE_0:def 5;
    then x in support pfexp nm by NAT_3:def 9;
    then
A28: (pfexp nm).x = (pfexp m). x implies (pfexp m).x <> 0 by PRE_POLY:def 7;
    not x in N1 by A25,XBOOLE_0:def 5;
    then
A29: not x in (support (ppf n)) or (pfexp nm).x <> (pfexp n). x by A26;
    support ppf m = support pfexp m by NAT_3:def 9;
    hence thesis by A13,A27,A29,A23,A24,A28,NAT_3:54,PRE_POLY:def 7
,XBOOLE_0:def 3;
  end;
  N1 \/ N2 = support ppf nm by A14,A3,XBOOLE_1:1,45;
  then
A30: N2 c= support ppf nm by XBOOLE_1:7;
A31: now
    let x2 be set;
    assume
A32: x2 in N2;
    then reconsider x=x2 as Prime by NEWTON:def 6;
    x2 in support ppf m by A22,A32;
    then
A33: x2 in support pfexp m by NAT_3:def 9;
    x2 in (support (ppf nm)) by A30,A32;
    then x2 in (support pfexp nm) by NAT_3:def 9;
    hence (ppf nm).x2 = x |^ (x |-count nm) by NAT_3:def 9
      .= x |^ ((pfexp nm).x) by NAT_3:def 8
      .= x |^ ((pfexp m).x) by A4,A32
      .= x |^ (x |-count m) by NAT_3:def 8
      .= (ppf m).x2 by A33,NAT_3:def 9;
  end;
  dom (ppf nm)= SetPrimes by PARTFUN1:def 2
    .= dom (ppf m) by PARTFUN1:def 2;
  then ppm|N2 = (ppf m) | N2 by A15,A18,A31,FUNCT_1:96;
  then
A34: m0 divides m by A22,A12,A15,Th7;
A35: n0*m0 = Product (ppf nm) by A17,A20,NAT_3:19
    .=nm by NAT_3:61;
  then
A36: m0 <> 0;
  now
    let x being Prime;
    assume
A37: x in support ppm;
    then x in (support (ppf nm)) by A15,XBOOLE_0:def 5;
    then
A38: x in (support pfexp nm) by NAT_3:def 9;
    then
A39: (ppf nm) .x = x |^ (x |-count nm) by NAT_3:def 9;
    (pfexp nm).x <> 0 by A38,NAT_3:36,38;
    then
A40: 0 < (x |-count nm) by NAT_3:def 8;
    ppm.x =(ppm | (support ppm)).x by A37,FUNCT_1:49
      .= (ppf nm).x by A18,A37,FUNCT_1:49;
    hence ex m be Nat st 0 < m & (ppm).x = x |^m by A39,A40;
  end;
  then
A41: ppm is prime-factorization-like;
A42: N1 c= support ppf nm by A14,A3;
  now
    let x being Prime;
    assume
A43: x in support (ppn);
    then x in (support (ppf nm)) by A42,A16;
    then
A44: x in (support pfexp nm) by NAT_3:def 9;
    then
A45: (ppf nm) .x = x |^ (x |-count nm) by NAT_3:def 9;
    (pfexp nm).x <> 0 by A44,NAT_3:36,38;
    then
A46: 0 < (x |-count nm) by NAT_3:def 8;
    ppn.x =(ppn | (support ppn)).x by A43,FUNCT_1:49
      .= (ppf nm).x by A19,A43,FUNCT_1:49;
    hence ex n be Nat st 0 < n & (ppn).x = x |^n by A45,A46;
  end;
  then ppn is prime-factorization-like;
  then n0,m0 are_coprime by A17,A41,Th12;
  then
A47: n0 gcd m0 = 1 by INT_2:def 3;
A48: for x be set st x in N1 holds (pfexp nm).x = (pfexp n). x
  proof
    let x be set;
    assume x in N1;
    then
    ex p be Element of NAT st x=p & p in (support (ppf n)) & (pfexp nm).p
    = (pfexp n). p;
    hence thesis;
  end;
A49: now
    let x1 be set;
    assume
A50: x1 in N1;
    then
A51: x1 in (support (ppf nm)) by A42;
    then reconsider x=x1 as Prime by NEWTON:def 6;
    x1 in support ppf n by A3,A50;
    then
A52: x1 in support pfexp n by NAT_3:def 9;
    x1 in (support pfexp nm) by A51,NAT_3:def 9;
    hence (ppf nm).x1= x |^ (x |-count nm) by NAT_3:def 9
      .= x |^ ((pfexp nm).x) by NAT_3:def 8
      .= x |^ ((pfexp n).x) by A48,A50
      .= x |^ (x |-count n) by NAT_3:def 8
      .= (ppf n).x1 by A52,NAT_3:def 9;
  end;
  dom (ppf nm)= SetPrimes by PARTFUN1:def 2
    .= dom (ppf n) by PARTFUN1:def 2;
  then
A53: ppn|N1=(ppf n) |N1 by A16,A19,A49,FUNCT_1:96;
  n0 <> 0 by A35;
  hence thesis by A3,A21,A16,A53,A35,A34,A36,A47,Th7;
end;
