reserve n,m,k for Nat,
  x,y for set,
  r for Real;
reserve C,D for non empty finite set,
  a for FinSequence of bool D;

theorem Th16:
  for F be PartFunc of D,REAL, A be RearrangmentGen of C st F is
  total & card C = card D holds Rland(F,A), FinS(F,D) are_fiberwise_equipotent
proof
  let F be PartFunc of D,REAL, B be RearrangmentGen of C;
  set fd = FinS(F,D), p = Rland(F,B), mf = MIM(fd), h = CHI(B,C);
  dom p is finite;
  then reconsider p as finite PartFunc of C,REAL by FINSET_1:10;
A1: len h = len B & len mf = len fd by RFINSEQ:def 2,RFUNCT_3:def 6;
A2: dom fd = Seg len fd & dom B = Seg len B by FINSEQ_1:def 3;
  assume
A3: F is total & card C = card D;
  then
A4: len mf = len h by Th11;
A5: dom p = C by A3,Th12;
A6: rng p = rng fd by A3,Th15;
  now
    let x be object;
    now
      per cases;
      case
A7:     not x in rng fd;
        then fd"{x}={} by Lm1;
        hence card (fd"{x}) = card(p"{x}) by A6,A7,Lm1;
      end;
      case
A8:     x in rng fd;
        defpred P[Nat] means $1 in dom fd & fd.$1 = x;
A9:     for n be Nat st P[n] holds n<=len fd by FINSEQ_3:25;
A10:    ex n be Nat st P[n] by A8,FINSEQ_2:10;
        consider ma be Nat such that
A11:    P[ma] & for n being Nat st P[n] holds n<=ma from NAT_1:sch 6(
        A9,A10 );
A12:    ex n be Nat st P[n] by A8,FINSEQ_2:10;
        consider mi be Nat such that
A13:    P[mi] & for n be Nat st P[n] holds mi<=n from NAT_1:sch 5(A12
        );
        reconsider r=x as Real by A13;
A14:    1<=mi by A13,FINSEQ_3:25;
        then max(0,mi-1)=mi-1 by FINSEQ_2:4;
        then reconsider m1 = mi -1 as Element of NAT by FINSEQ_2:5;
A15:    m1+1=mi;
A16:    ma<=len fd by A11,FINSEQ_3:25;
A17:    Seg ma \ Seg m1 = fd"{x}
        proof
          thus Seg ma \ Seg m1 c= fd"{x}
          proof
            let y be object;
            assume
A18:        y in Seg ma \ Seg m1;
            then reconsider l=y as Element of NAT;
            reconsider o=fd.l as Real;
A19:        y in Seg ma by A18,XBOOLE_0:def 5;
            then
A20:        1<=l by FINSEQ_1:1;
A21:        l<=ma by A19,FINSEQ_1:1;
            then l<=len fd by A16,XXREAL_0:2;
            then
A22:        l in dom fd by A20,FINSEQ_3:25;
            not y in Seg m1 by A18,XBOOLE_0:def 5;
            then l<1 or m1<l by FINSEQ_1:1;
            then mi<l+1 by A19,FINSEQ_1:1,XREAL_1:19;
            then
A23:        mi<=l by NAT_1:13;
            now
              per cases;
              case
                l=ma;
                then o in {x} by A11,TARSKI:def 1;
                hence thesis by A22,FUNCT_1:def 7;
              end;
              case
                l<>ma;
                then l<ma by A21,XXREAL_0:1;
                then
A24:            o>=r by A11,A22,RFINSEQ:19;
                now
                  per cases;
                  case
                    l=mi;
                    then o in {x} by A13,TARSKI:def 1;
                    hence thesis by A22,FUNCT_1:def 7;
                  end;
                  case
                    l<>mi;
                    then mi<l by A23,XXREAL_0:1;
                    then r>=o by A13,A22,RFINSEQ:19;
                    then r=o by A24,XXREAL_0:1;
                    then o in {x} by TARSKI:def 1;
                    hence thesis by A22,FUNCT_1:def 7;
                  end;
                end;
                hence thesis;
              end;
            end;
            hence thesis;
          end;
          let y be object;
          assume
A25:      y in fd"{x};
          then
A26:      y in dom fd by FUNCT_1:def 7;
          reconsider l=y as Element of NAT by A25;
A27:      1<=l by A26,FINSEQ_3:25;
          fd.y in {x} by A25,FUNCT_1:def 7;
          then
A28:      fd.l=x by TARSKI:def 1;
          then mi<=l by A13,A26;
          then mi<l+1 by NAT_1:13;
          then m1<l or l<1 by XREAL_1:19;
          then
A29:      not l in Seg m1 by FINSEQ_1:1;
          l<=ma by A11,A26,A28;
          then l in Seg ma by A27,FINSEQ_1:1;
          hence thesis by A29,XBOOLE_0:def 5;
        end;
A30:    1<=ma by A11,FINSEQ_3:25;
A31:    mi<=ma by A13,A11;
        m1<=mi by XREAL_1:43;
        then
A32:    m1<=ma by A31,XXREAL_0:2;
        then Seg m1 c= Seg ma by FINSEQ_1:5;
        then
A33:    card(fd"{x}) = card(Seg ma) - card(Seg m1) by A17,CARD_2:44
          .= ma - card(Seg m1) by FINSEQ_1:57
          .= ma - m1 by FINSEQ_1:57;
A34:    mi<=len fd by A13,FINSEQ_3:25;
        then 1<=len fd by A14,XXREAL_0:2;
        then
A35:    1 in dom fd by FINSEQ_3:25;
        now
          per cases;
          case
A36:        mi=1;
            B.ma = p"{x}
            proof
              thus B.ma c= p"{x}
              proof
                defpred P[Nat] means $1 in dom B & $1<=ma implies
                for c be Element of C st c in B.$1 holds c in p"{x};
                let y be object;
                assume
A37:            y in B.ma;
                B.ma c= C by A4,A1,A2,A11,Lm5;
                then reconsider cy = y as Element of C by A37;
A38:            for n st P[n] holds P[n+1]
                proof
                  let n;
                  assume
A39:              P[n];
                  assume that
A40:              n+1 in dom B and
A41:              n+1<=ma;
A42:              n+1<=len B by A40,FINSEQ_3:25;
                  then
A43:              n<=len B -1 by XREAL_1:19;
A44:              n<len B by A42,NAT_1:13;
                  let c be Element of C;
                  assume
A45:              c in B.(n+1);
A46:              n<=len B by A42,NAT_1:13;
                  now
                    per cases;
                    case
                      n=0;
                      then p.c = x by A3,A13,A36,A45,Th14;
                      then p.c in {x} by TARSKI:def 1;
                      hence thesis by A5,FUNCT_1:def 7;
                    end;
                    case
A47:                  n<>0;
                      then
A48:                  0+1<n+1 by XREAL_1:6;
A49:                  0+1<=n by A47,NAT_1:13;
                      then B.n c= B.(n+1) by A43,Def2;
                      then
A50:                  B.(n+1) = B.(n+1) \/ B.n by XBOOLE_1:12
                        .= (B.(n+1) \ B.n) \/ B.n by XBOOLE_1:39;
                      now
                        per cases by A45,A50,XBOOLE_0:def 3;
                        case
                          c in B.(n+1) \ B.n;
                          then
A51:                      p.c = fd.(n+1) by A3,A44,A49,Th14;
                          now
                            per cases;
                            case
                              n+1=ma;
                              then p.c in {x} by A11,A51,TARSKI:def 1;
                              hence thesis by A5,FUNCT_1:def 7;
                            end;
                            case
                              n+1<>ma;
                              then n+1<ma by A41,XXREAL_0:1;
                              then
A52:                          p.c>=r by A4,A1,A2,A11,A40,A51,RFINSEQ:19;
                              r>=p.c by A4,A1,A2,A13,A36,A40,A48,A51,RFINSEQ:19
;
                              then r=p.c by A52,XXREAL_0:1;
                              then p.c in {x} by TARSKI:def 1;
                              hence thesis by A5,FUNCT_1:def 7;
                            end;
                          end;
                          hence thesis;
                        end;
                        case
                          c in B.n;
                          hence thesis by A39,A41,A46,A49,FINSEQ_3:25,NAT_1:13;
                        end;
                      end;
                      hence thesis;
                    end;
                  end;
                  hence thesis;
                end;
A53:            P[ 0 ] by FINSEQ_3:25;
A54:            for n holds P[n] from NAT_1:sch 2(A53,A38);
                ma in dom B by A4,A1,A11,FINSEQ_3:29;
                then cy in p"{x} by A37,A54;
                hence thesis;
              end;
              let y be object;
              assume
A55:          y in p"{x};
              then reconsider cy = y as Element of C;
              p.cy in {x} by A55,FUNCT_1:def 7;
              then
A56:          p.cy = x by TARSKI:def 1;
              defpred Q[Nat] means $1 in dom B & ma<$1 & cy in B.$1;
              assume
A57:          not y in B.ma;
A58:          ex n be Nat st Q[n]
              proof
                take n=len B;
                len B <> 0 by Th4;
                then 0+1<=len B by NAT_1:13;
                hence n in dom B by FINSEQ_3:25;
A59:            B.n= C by Th3;
                now
                  assume n <= ma;
                  then ma=len B by A4,A1,A16,XXREAL_0:1;
                  then cy in B.ma by A59;
                  hence contradiction by A57;
                end;
                hence thesis by A59;
              end;
              consider mm be Nat such that
A60:          Q[mm] & for n be Nat st Q[n] holds mm<=n from NAT_1:
              sch 5(A58);
              1<=mm by A60,FINSEQ_3:25;
              then max(0,mm-1)=mm-1 by FINSEQ_2:4;
              then reconsider 1m = mm - 1 as Element of NAT by FINSEQ_2:5;
              ma+1<=mm by A60,NAT_1:13;
              then
A61:          ma<=1m by XREAL_1:19;
              then
A62:          1<=1m by A30,XXREAL_0:2;
A63:          mm in dom fd by A4,A1,A60,FINSEQ_3:29;
A64:          mm<=len B by A60,FINSEQ_3:25;
A65:          mm<mm+1 by NAT_1:13;
              then 1m<mm by XREAL_1:19;
              then
A66:          1m<len B by A64,XXREAL_0:2;
              1m<=mm by A65,XREAL_1:19;
              then 1m<=len B by A64,XXREAL_0:2;
              then
A67:          1m in dom B by A62,FINSEQ_3:25;
              now
                per cases;
                case
                  ma=1m;
                  then cy in B.(1m+1) \ B.(1m) by A57,A60,XBOOLE_0:def 5;
                  then p.cy = fd.mm by A3,A62,A66,Th14;
                  hence contradiction by A11,A56,A60,A63;
                end;
                case
                  ma <> 1m;
                  then
A68:              ma < 1m by A61,XXREAL_0:1;
                  now
                    assume cy in B.(1m);
                    then mm<=1m by A60,A67,A68;
                    then mm - 1m <=0 by XREAL_1:47;
                    hence contradiction;
                  end;
                  then cy in B.(1m+1) \ B.(1m) by A60,XBOOLE_0:def 5;
                  then p.cy = fd.mm by A3,A62,A66,Th14;
                  hence contradiction by A11,A56,A60,A63;
                end;
              end;
              hence contradiction;
            end;
            hence card(p"{x}) = card(fd"{x}) by A4,A1,A30,A16,A33,A36,Def1;
          end;
          case
A69:        mi<>1;
            then 1<mi by A14,XXREAL_0:1;
            then
A70:        1<=m1 by A15,NAT_1:13;
A71:        m1<=len fd by A34,A15,NAT_1:13;
            then
A72:        m1 in dom B by A4,A1,A70,FINSEQ_3:25;
            then
A73:        B.m1 c= B.ma by A4,A1,A2,A11,A32,Th2;
            B.ma c= C by A4,A1,A2,A11,Lm5;
            then reconsider Bma = B.ma, Bm1 = B.m1 as finite set by A73;
            B.ma \ B.m1 = p"{x}
            proof
              thus B.ma \ B.m1 c= p"{x}
              proof
                defpred P[Nat] means $1 in dom B & mi<=$1 & $1<=ma
implies for c be Element of C st c in B.$1 \ B.m1 holds c in p"{x};
                let y be object;
A74:            B.ma c= C by A4,A1,A2,A11,Lm5;
A75:            for n st P[n] holds P[n+1]
                proof
                  let n;
                  assume
A76:              P[n];
                  assume that
A77:              n+1 in dom B and
A78:              mi<=n+1 and
A79:              n+1<=ma;
                  let c be Element of C;
                  n+1<=len B by A77,FINSEQ_3:25;
                  then
A80:              n<len B by NAT_1:13;
                  assume
A81:              c in B.(n+1) \ B.m1;
                  now
                    per cases;
                    case
A82:                  n+1=mi;
                      then p.c = fd.(n+1) by A3,A70,A80,A81,Th14;
                      then p.c in {x} by A13,A82,TARSKI:def 1;
                      hence thesis by A5,FUNCT_1:def 7;
                    end;
                    case
                      mi <> n+1;
                      then
A83:                  mi<n+1 by A78,XXREAL_0:1;
                      then mi<=n by NAT_1:13;
                      then
A84:                  1<=n by A14,XXREAL_0:2;
                      n<=ma by A79,NAT_1:13;
                      then
A85:                  n<=len B by A4,A1,A16,XXREAL_0:2;
                      then n<=n+1 & n in dom B by A84,FINSEQ_3:25,NAT_1:11;
                      then B.n c= B.(n+1) by A77,Th2;
                      then
A86:                  B.(n+1) \ B.m1 = (B.(n+1) \/ B .n) \ B.m1 by XBOOLE_1:12
                        .= ((B.(n+1) \B.n) \/ B.n) \ B.m1 by XBOOLE_1:39
                        .= (B.(n+1) \ B.n)\ B.m1 \/ (B.n \ B.m1) by XBOOLE_1:42
;
                      now
                        per cases by A81,A86,XBOOLE_0:def 3;
                        case
                          c in (B.(n+1) \ B.n) \ B.m1;
                          then c in B.(n+1) \ B.n by XBOOLE_0:def 5;
                          then
A87:                      p.c = fd.(n+1) by A3,A80,A84,Th14;
                          now
                            per cases;
                            case
                              n+1=ma;
                              then p.c in {x} by A11,A87,TARSKI:def 1;
                              hence thesis by A5,FUNCT_1:def 7;
                            end;
                            case
                              n+1<>ma;
                              then n+1<ma by A79,XXREAL_0:1;
                              then
A88:                          p.c>=r by A4,A1,A2,A11,A77,A87,RFINSEQ:19;
                              r>=p.c by A4,A1,A2,A13,A77,A83,A87,RFINSEQ:19;
                              then r=p.c by A88,XXREAL_0:1;
                              then p.c in {x} by TARSKI:def 1;
                              hence thesis by A5,FUNCT_1:def 7;
                            end;
                          end;
                          hence thesis;
                        end;
                        case
                          c in B.n \ B.m1;
                          hence thesis by A76,A79,A83,A84,A85,FINSEQ_3:25
,NAT_1:13;
                        end;
                      end;
                      hence thesis;
                    end;
                  end;
                  hence thesis;
                end;
A89:            P[ 0 ];
A90:            for n holds P[n] from NAT_1:sch 2(A89,A75);
                assume
A91:            y in B.ma \ B.m1;
                then y in B.ma;
                then reconsider cy = y as Element of C by A74;
                ma in dom B by A4,A1,A11,FINSEQ_3:29;
                then cy in p"{x} by A31,A91,A90;
                hence thesis;
              end;
              let y be object;
              assume
A92:          y in p"{x};
              then reconsider cy = y as Element of C;
              p.cy in {x} by A92,FUNCT_1:def 7;
              then
A93:          p.cy = x by TARSKI:def 1;
              assume
A94:          not y in B.ma \ B.m1;
              now
                per cases by A94,XBOOLE_0:def 5;
                case
A95:              not y in B.ma;
                  defpred Q[Nat] means $1 in dom B & ma<$1 & cy in B.$1;
A96:              ex n be Nat st Q[n]
                  proof
                    take n=len B;
                    len B <> 0 by Th4;
                    then 0+1<=len B by NAT_1:13;
                    hence n in dom B by FINSEQ_3:25;
A97:                B.n= C by Th3;
                    now
                      assume n <= ma;
                      then ma=len B by A4,A1,A16,XXREAL_0:1;
                      then cy in B.ma by A97;
                      hence contradiction by A95;
                    end;
                    hence thesis by A97;
                  end;
                  consider mm be Nat such that
A98:              Q [mm] & for n be Nat st Q[n] holds mm<=n from
                  NAT_1:sch 5(A96);
                  1<=mm by A98,FINSEQ_3:25;
                  then max(0,mm-1)=mm-1 by FINSEQ_2:4;
                  then reconsider 1m = mm - 1 as Element of NAT by FINSEQ_2:5;
                  ma+1<=mm by A98,NAT_1:13;
                  then
A99:              ma<=1m by XREAL_1:19;
                  then
A100:             1<=1m by A30,XXREAL_0:2;
A101:             mm in dom fd by A4,A1,A98,FINSEQ_3:29;
A102:             mm<=len B by A98,FINSEQ_3:25;
A103:             mm<mm+1 by NAT_1:13;
                  then 1m<mm by XREAL_1:19;
                  then
A104:             1m<len B by A102,XXREAL_0:2;
                  1m<=mm by A103,XREAL_1:19;
                  then 1m<=len B by A102,XXREAL_0:2;
                  then
A105:             1m in dom B by A100,FINSEQ_3:25;
                  now
                    per cases;
                    case
                      ma=1m;
                      then cy in B.(1m+1) \ B.(1m) by A95,A98,XBOOLE_0:def 5;
                      then p.cy = fd.mm by A3,A100,A104,Th14;
                      hence contradiction by A11,A93,A98,A101;
                    end;
                    case
                      ma <> 1m;
                      then
A106:                 ma < 1m by A99,XXREAL_0:1;
                      now
                        assume cy in B.(1m);
                        then mm<=1m by A98,A105,A106;
                        then mm - 1m <=0 by XREAL_1:47;
                        hence contradiction;
                      end;
                      then cy in B.(1m+1) \ B.(1m) by A98,XBOOLE_0:def 5;
                      then p.cy = fd.mm by A3,A100,A104,Th14;
                      hence contradiction by A11,A93,A98,A101;
                    end;
                  end;
                  hence contradiction;
                end;
                case
A107:             y in B.m1;
                  defpred Q[Nat] means $1 in dom B & $1<=m1 & cy in B.$1;
A108:             ex n be Nat st Q[n] by A72,A107;
                  consider mm be Nat such that
A109:             Q [mm] & for n be Nat st Q[n] holds mm<=n from
                  NAT_1:sch 5(A108);
A110:             1<=mm by A109,FINSEQ_3:25;
                  then max(0,mm-1)=mm-1 by FINSEQ_2:4;
                  then reconsider 1m=mm-1 as Element of NAT by FINSEQ_2:5;
A111:             mm<=len B by A109,FINSEQ_3:25;
A112:             mm in dom fd by A4,A1,A109,FINSEQ_3:29;
                  now
                    per cases;
                    case
                      mm=1;
                      then p.cy = fd.1 by A3,A109,Th14;
                      then mi<=1 by A13,A35,A93;
                      hence contradiction by A14,A69,XXREAL_0:1;
                    end;
                    case
                      mm<>1;
                      then 1<mm by A110,XXREAL_0:1;
                      then 1+1<=mm by NAT_1:13;
                      then
A113:                 1<=1m by XREAL_1:19;
A114:                 mm<mm+1 by NAT_1:13;
                      then
A115:                 1m<=mm by XREAL_1:19;
                      then 1m<=len B by A111,XXREAL_0:2;
                      then
A116:                 1m in dom B by A113,FINSEQ_3:25;
A117:                 1m<mm by A114,XREAL_1:19;
                      then
A118:                 1m<len B by A111,XXREAL_0:2;
                      1m<=m1 by A109,A115,XXREAL_0:2;
                      then not cy in B.1m by A109,A117,A116;
                      then cy in B.(1m+1) \ B.1m by A109,XBOOLE_0:def 5;
                      then p.cy = fd.(1m+1) by A3,A113,A118,Th14;
                      then mi<=mm by A13,A93,A112;
                      then m1+1<=m1 by A109,XXREAL_0:2;
                      then 1<=m1-m1 by XREAL_1:19;
                      then 1<=0;
                      hence contradiction;
                    end;
                  end;
                  hence contradiction;
                end;
              end;
              hence contradiction;
            end;
            hence card(p"{x}) = card(Bma) - card(Bm1) by A73,CARD_2:44
              .= ma - card(Bm1) by A4,A1,A30,A16,Def1
              .= card (fd"{x}) by A4,A1,A33,A70,A71,Def1;
          end;
        end;
        hence card (fd"{x}) = card(p"{x});
      end;
    end;
    hence card Coim(fd,x) = card Coim(p,x);
  end;
  hence thesis by CLASSES1:def 10;
end;
