reserve D for non empty set,
  f for FinSequence of D,
  p, p1, p2, p3, q for Element of D,
  i, j, k, l, n for Nat;

theorem Th21:
  Swap(f, i, j) = Swap(f, j, i)
proof
  per cases;
  suppose
A1: 1 <= i & i <= len f & 1 <= j & j <= len f;
    set FJ = Replace(f,j,f/.i);
    set FI = Replace(f,i,f/.j);
A2: for k be Nat st 1 <= k & k <= len Swap(f,i,j) holds Swap(f,i,j).k =
    Swap(f,j,i).k
    proof
A3:   len Swap(f,i,j) = len f by Th18
        .= len FJ by FUNCT_7:97;
A4:   len Swap(f,i,j) = len f by Th18
        .= len FI by FUNCT_7:97;
      let k be Nat;
      assume that
A5:   1 <= k and
A6:   k <= len Swap(f,i,j);
A7:   k <= len f by A6,Th18;
      now
        per cases;
        suppose
A8:       i = k;
          now
            per cases;
            suppose
A9:           j = k;
              then Swap(f,i,k).k = Replace(FI,k,f/.i).k by A1,Def2
                .= f/.i by A5,A6,A4,Lm2
                .= Replace(FJ,k,f/.i).k by A5,A6,A3,Lm2
                .= Swap(f,k,i).k by A1,A8,A9,Def2;
              hence thesis by A9;
            end;
            suppose
A10:          j <> k;
              Swap(f,i,j).k = Replace(FI,j,f/.i).k by A1,Def2
                .= Replace(f,k,f/.j).k by A8,A10,FUNCT_7:32
                .= f/.j by A5,A7,Lm2
                .= Replace(FJ,k,f/.j).k by A5,A6,A3,Lm2;
              hence thesis by A1,A8,Def2;
            end;
          end;
          hence thesis;
        end;
        suppose
A11:      i <> k;
          now
            per cases;
            suppose
A12:          j = k;
              then Swap(f,i,j).k = Replace(FI,k,f/.i).k by A1,Def2
                .= f/.i by A5,A6,A4,Lm2
                .= FJ.k by A5,A7,A12,Lm2
                .= Replace(FJ,i,f/.j).k by A11,FUNCT_7:32;
              hence thesis by A1,Def2;
            end;
            suppose
A13:          j <> k;
              Swap(f,i,j).k = Replace(FI,j,f/.i).k by A1,Def2
                .= FI.k by A13,FUNCT_7:32
                .= f.k by A11,FUNCT_7:32
                .= Replace(f,j,f/.i).k by A13,FUNCT_7:32
                .= Replace(FJ,i,f/.j).k by A11,FUNCT_7:32;
              hence thesis by A1,Def2;
            end;
          end;
          hence thesis;
        end;
      end;
      hence thesis;
    end;
    len Swap(f,i,j) = len f by Th18
      .= len Swap(f,j,i) by Th18;
    hence thesis by A2;
  end;
  suppose
A14: not (1 <= i & i <= len f & 1 <= j & j <= len f);
    then Swap(f, i, j) = f by Def2;
    hence thesis by A14,Def2;
  end;
end;
