Skip to main content
added 15 characters in body
Source Link
Dr. belisarius
  • 116.2k
  • 13
  • 205
  • 456
a = Sum[x[r] ((Sum[x[i], {i, n}] - x[r])^2 - Sum[x[i]^2, {i, n}]), {r, n}];

Module[{t0, t1},
 rule = Sum[p__Sum[p1___ x[a_]^i_ x[a_]^i__  p2___, {a_, n}] :> pp1 p2 s[i];
 a /. x[k_] -> t0 x[k]^t1 
   /. Sum[a__, l_List] :> (Sum[#, l] & /@ Expand@a) 
   //. rule /.  t0 -> 1 /. t1 -> 1]
 
(*s[1]^3 - 3 s[1] s[2] + s[3]*)
a = Sum[x[r] ((Sum[x[i], {i, n}] - x[r])^2 - Sum[x[i]^2, {i, n}]), {r, n}];

Module[{t0, t1},
 rule = Sum[p__ x[a_]^i_, {a_, n}] :> p s[i];
 a /. x[k_] -> t0 x[k]^t1 
   /. Sum[a__, l_List] :> (Sum[#, l] & /@ Expand@a) 
   //. rule /.  t0 -> 1 /. t1 -> 1]
 
(*s[1]^3 - 3 s[1] s[2] + s[3]*)
a = Sum[x[r] ((Sum[x[i], {i, n}] - x[r])^2 - Sum[x[i]^2, {i, n}]), {r, n}];

Module[{t0, t1},
 rule = Sum[p1___  x[a_]^i__  p2___, {a_, n}] :> p1 p2 s[i];
 a /. x[k_] -> t0 x[k]^t1 
   /. Sum[a__, l_List] :> (Sum[#, l] & /@ Expand@a) 
   //. rule /.  t0 -> 1 /. t1 -> 1]
 
(*s[1]^3 - 3 s[1] s[2] + s[3]*)
added 4 characters in body
Source Link
Dr. belisarius
  • 116.2k
  • 13
  • 205
  • 456
a = Sum[x[r] ((Sum[x[i], {i, n}] - x[r])^2 - Sum[x[i]^2, {i, n}]), {r, n}];

Module[{t0, t1},
 rule = Sum[p__ x[a_]^i_, {a_, n}] :>  p Symbol["s" <> ToString[i /. t1 -> 1]];s[i];
 a /. x[k_] -> t0 x[k]^t1 
   /. Sum[a__, l_List] :> (Sum[#, l] & /@ Expand@a) 
   //. rule /.  t0 -> 1
] /. t1 -> 1]
 
(*s1^3*s[1]^3 - 3 s1s[1] s2s[2] + s3*s[3]*)
a = Sum[x[r] ((Sum[x[i], {i, n}] - x[r])^2 - Sum[x[i]^2, {i, n}]), {r, n}];

Module[{t0, t1},
 rule = Sum[p__ x[a_]^i_, {a_, n}] :>  p Symbol["s" <> ToString[i /. t1 -> 1]];
 a /. x[k_] -> t0 x[k]^t1 /.Sum[a__, l_List] :>(Sum[#, l] & /@ Expand@a) //. rule /. t0 -> 1
]

(*s1^3 - 3 s1 s2 + s3*)
a = Sum[x[r] ((Sum[x[i], {i, n}] - x[r])^2 - Sum[x[i]^2, {i, n}]), {r, n}];

Module[{t0, t1},
 rule = Sum[p__ x[a_]^i_, {a_, n}] :> p s[i];
 a /. x[k_] -> t0 x[k]^t1 
   /. Sum[a__, l_List] :> (Sum[#, l] & /@ Expand@a) 
   //. rule /.  t0 -> 1 /. t1 -> 1]
 
(*s[1]^3 - 3 s[1] s[2] + s[3]*)
deleted 84 characters in body
Source Link
Dr. belisarius
  • 116.2k
  • 13
  • 205
  • 456
Module[{t}, 
 rulTimesa = Sum[p__Sum[x[r] x[a_]^i_((Sum[x[i], {a_i, n}] :>- px[r])^2 Symbol["s"- <>Sum[x[i]^2, ToString[i{i, /.n}]), t{r, ->n}];

Module[{t0, 1]];t1},
 rulNakedrule = Sum[   Sum[p__ x[a_]^i_, {a_, n}] :>  p Symbol["s" <> ToString[i /. tt1 -> 1]];
 
 a = Sum[x[r] ((Sum[x[i], {i, n}] - x[r])^2 - Sum[x[i]^2, {i, n}]), {r, n}];
 a /. x[k_] -> x[k]^tt0 x[k]^t1 /.Sum[a__, l_List] :> (Sum[#, l] & /@ Expand@a) //.rulNaked rule /.rulTimes] t0 -> 1
]

(*s1^3 - 3 s1 s2 + s3*)
Module[{t}, 
 rulTimes = Sum[p__ x[a_]^i_, {a_, n}] :> p Symbol["s" <> ToString[i /. t -> 1]];
 rulNaked = Sum[    x[a_]^i_, {a_, n}] :>   Symbol["s" <> ToString[i /. t -> 1]];
 
 a = Sum[x[r] ((Sum[x[i], {i, n}] - x[r])^2 - Sum[x[i]^2, {i, n}]), {r, n}];
 a /. x[k_] -> x[k]^t /.Sum[a__, l_List] :> (Sum[#, l] & /@ Expand@a) /.rulNaked /.rulTimes]

(*s1^3 - 3 s1 s2 + s3*)
a = Sum[x[r] ((Sum[x[i], {i, n}] - x[r])^2 - Sum[x[i]^2, {i, n}]), {r, n}];

Module[{t0, t1},
 rule = Sum[p__ x[a_]^i_, {a_, n}] :>  p Symbol["s" <> ToString[i /. t1 -> 1]];
 a /. x[k_] -> t0 x[k]^t1 /.Sum[a__, l_List] :>(Sum[#, l] & /@ Expand@a) //. rule /. t0 -> 1
]

(*s1^3 - 3 s1 s2 + s3*)
deleted 190 characters in body
Source Link
Dr. belisarius
  • 116.2k
  • 13
  • 205
  • 456
Loading
Rollback to Revision 1
Source Link
Dr. belisarius
  • 116.2k
  • 13
  • 205
  • 456
Loading
deleted 170 characters in body
Source Link
Dr. belisarius
  • 116.2k
  • 13
  • 205
  • 456
Loading
Source Link
Dr. belisarius
  • 116.2k
  • 13
  • 205
  • 456
Loading