Weby shortcut
teste

SUBS

  • This routine substitutes one of the sub-summands of a given polynomial, produced in the list by the  function SEARCH.
  • This function calls other functions: COEF_STRG, MON_STRG and STRETCH.

 

SUBS:=function(pol, rel)
local pol_s, lm, lc, rs, ind, i;

if pol = Zero(pol) then
    return pol;
else
    pol_s:=String(pol);
    pol_s:=STRETCH(pol_s);
    pol_s:=SplitString(pol_s, "+");
fi;


lm:=List(pol_s, mon -> MON_STRG(mon));
lc:=List(pol_s, mon -> COEF_STRG(mon));

if rel[1] = Zero(pol) and rel[2] <> Zero(pol) then
    rs[1]:="(0)*U";
    rs[2]:=STRETCH(String(rel[2]));
elif rel[1] <> Zero(pol) and rel[2] = Zero(pol) then
    rs:=[];
    rs[1]:=STRETCH(String(rel[1]));
    rs[2]:="(0)*U";
else
    rs:=List(rel, i -> STRETCH(String(i)));
fi;

i:=1;
for ind in [1..Size(lm)] do
    if EvalString(lc[ind]) / EvalStringCOEF_STRG(rs[1]) ) in Integers and PositionSublist(lm[ind], MON_STRG(rs[1]))<> fail then
        lc[ind]:= Concatenation("(" ,String(EvalString(lc[ind]) / EvalStringCOEF_STRG(rs[1])  )), ")");        
        lm[ind]:= ReplacedString(lm[ind], MON_STRG(rs[1]), Concatenation("(", rs[2], ")")    );
        i:=i+1;
    fi;
od;

if i<>1 then
    for ind in [1..Size(lm)] do
        pol_s[ind] := Concatenation( lc[ind], "*", lm[ind]);
    od;
    pol_s:= JoinStringsWithSeparator(pol_s, "+");
    return EvalString(pol_s);
else
    return pol;    
fi;

end;

Listar Todas Voltar