Post Reply 
Algebraic to RPN
02-25-2017, 03:15 PM
Post: #4
RE: Algebraic to RPN
(02-25-2017 02:05 PM)compsystems Wrote:  extract parts and operators with [] acts as the PART command, please create a second version with PART cmd

PHP Code:
(x^2-4*x)[1→ '+'
(x^2-4*x)[2→ x^2
(x^2-4*x)[3→ -4*x

part
(x^2-4*x→ 2
part
(x^2-4*x,1→ x^2
part
(x^2-4*x,2→ -4*x
part
(x^2-4*x,0→ "+" 

I am not sure why you would want a version using the part command, but here:

Code:
#pragma mode( separator(.,;) integer(h32) )
#cas
CRPN(f):=
begin
  local rpn, op, par, n, j, g;

  rpn:="";
  op:="";
  par:="";
  if (type(f) <> DOM_SYMBOLIC) then
    rpn:=string(f);
    return(rpn);
  end;

  op:=string(part(f,0));
  n:=size(op);
  op:=MID(op,2,n-2);
  n:=part(f);

  for j from 1 to n do
    g:=part(f,j);
    if (type(g) <> DOM_SYMBOLIC) then
      par:=string(g);
    else
      par:=CRPN(g);
    end;
    if (j > 1) then rpn:=rpn + " "; end;
    rpn:=rpn + par;
    if ((j > 1) or (n == 1)) then
      rpn:=rpn + " " + op;
    end;
  end;

  return(rpn);
end;
#end

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Algebraic to RPN - Han - 02-24-2017, 09:27 PM
RE: Algebraic to RPN - ggauny@live.fr - 02-25-2017, 12:19 PM
RE: Algebraic to RPN - compsystems - 02-25-2017, 02:05 PM
RE: Algebraic to RPN - Han - 02-25-2017 03:15 PM
RE: Algebraic to RPN - compsystems - 02-26-2017, 02:59 PM
RE: Algebraic to RPN - tcab - 07-29-2018, 07:46 AM
RE: Algebraic to RPN - Joe Horn - 07-29-2018, 12:10 PM
RE: Algebraic to RPN - Komanguy - 07-28-2018, 08:33 PM



User(s) browsing this thread: 1 Guest(s)