kill(all)$

maxima: programming ,rerange codes ,txt =simplode(expr),version 1.0
peter.vlasschaert@gmail.com, 20/01/2020

load 'packages'
=============

load(lrats)$

How to use : 'simplode,eval_string '
============================

p1:s^2*τ1*τ2+s*τ2 + R1*C2*s +1+ a*s^3+b*s^2;

p2:rerange(s,pn):=block([px],
l1:[ev(pn,s=0)],
m1:hipow(pn,s)+1,
for i:2 thru m1 do(
px:ratcoef(pn,s^(i-1)),
 l1:endcons(px,l1))
 )$

p3:rerange(s,p1);

p4:l1;

p4a:reverse(l1);

p4b:hipow(p1,s);

l3:[];
 for i:1 thru m1 do(
 l3:endcons(p4[i]*s^(i-1),l3)
 );

l3;

l4:reverse(l3);

special command : ' simplode'
==========================
simplode : result  => string

low order to high order 's'
======================

p5:simplode(l3,"+");

high order to low order 's'
======================

p5a:simplode(l4,"+");

? We want order polynoom,'variable'
===============================
example : 's'

given :orderless : polynoom, 's'
============================

p6:p1;

code
====

p6a:lrerange(pn,s):=block([px,la,lb],
la:[ev(pn,s=0)],
m1:hipow(pn,s)+1,
for i:2 thru m1 do(
px:ratcoef(pn,s^(i-1)),
 la:endcons(px,la)), 
 lb:[],
 for i:1 thru m1 do(
 lb:endcons(la[i]*s^(i-1),lb)
 ),
 return(simplode(lb,"+"))
 )$

p6b:lrerange(p6,s);

optimized : code
=============

p7:lrerangep(pn,s,r):=block([px,la,lb],
la:[ev(pn,s=0)],
m1:hipow(pn,s)+1,
for i:2 thru m1 do(
px:ratcoef(pn,s^(i-1)),
 la:endcons(px,la)), 
 lb:[],
 for i:1 thru m1 do(
 lb:endcons(la[i]*s^(i-1),lb)
 ),
 if  r=l then
 return(simplode(lb,"+")),
 if r=h  then
 (return(simplode(reverse(lb),"+")))
 )$

syntax:
=====
pn :orderless polynoom
s    : variable of the polynoom
r     : order , see 'below'

m1;

order : low => high, thrid argument function: l

p7a:lrerangep(p6,s,l);

order: high => low,thrid argument function:h

p7b:lrerangep(p6,s,h);

if s ≠ s , by example  s= x
===================

p8:lrerangep1(pn,s,r):=block([px,la,lb],
la:[ev(pn,s=0)],
m1:hipow(pn,s)+1,
for i:2 thru m1 do(
px:ratcoef(pn,s^(i-1)),
 la:endcons(px,la)), 
 lb:[],
 for i:1 thru m1 do(
 lb:endcons(la[i]*s^(i-1),lb)
 ),
if  r=l then
((for i:1 thru 0 do(
 lb:endcons(la[i]*s^(i-1),lb))), 
 return(simplode(lb,"+"))),
 if r=h then
 ((for i:m1+1 thru 1 do(
 lb:endcons(la[i]*s^(i-1),lb))),
 return(simplode(reverse(lb),"+")))
 )$

result : p8a,p8b  ' = string'.
------------------------------------

p8a:lrerangep1(p6,s,l);

p8b:lrerangep1(p6,s,h);

 example :polynoom ,var. :'x'
======================

p9:subst([s=x],p1+c*x);

p9a:subst([x=s],p9);

=> low to high, no problem :see below.

p9l:lrerangep1(p9a,s,l);

because : simplode  =>  'string'.

p9ll:eval_string(p9l);

p9lll:subst([s=x],%);

=> high to low  , problem : see below,

p9h:lrerangep1(p9a,s,h);

because : simplode  =>  'string'.

p9hh:eval_string(p9h);

powerdisp;

p9hhh:subst([s=x],p9hh);

change option 'powerdisp' : true

powerdisp:true;

p9hhhh:subst([s=x],p9hh);

new commands : simplode ( txt mode output) => eval_string
see: above how to use.