
theorem ReplacePositive:
  for f be positive heterogeneous non empty real-valued FinSequence
    for i,j be Nat st
    i in dom f & j in dom f & i <> j & f.i > Mean f holds
    Replace (f,i,j,Mean f,f.i + f.j - Mean f) is positive
  proof
    let f be positive heterogeneous non empty real-valued FinSequence;
    let i,j be Nat such that
A1: i in dom f & j in dom f & i <> j & f.i > Mean f;
    set a = Mean f;
    set b = f.i + f.j - Mean f;
h2: Mean f - Mean f < f.i - Mean f by A1,XREAL_1:14;
    f.j > 0 by A1,PosDef; then
    f.i - Mean f + f.j > 0 by h2; then
    reconsider b as positive Real;
    set g = Replace (f,i,j,a,b);
    for n being Nat st n in dom g holds g.n > 0
    proof
      let n be Nat;
      assume n in dom g; then
A2:   n in dom f by DinoDom;
      per cases;
      suppose n = i;
        hence thesis by ReplaceValue3,A1;
      end;
      suppose n = j;
        hence thesis by ReplaceValue2,A1;
      end;
      suppose n <> i & n <> j; then
        g.n = f.n by A2,ReplaceValue,A1;
        hence thesis by PosDef,A2;
      end;
    end;
    hence thesis;
  end;
