# What is the RPN operator defined in PSTricks to convert an infix expression to the postfix one?

The following code does not compile as I failed to convert the abscissa from infix to postfix.

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-plot}

% defining an RPN operator that converts Infix Cartesian to Postfix Polar
\pstVerb{/ICtoPP {tx@AlgToPs begin AlgToPs end exch cvx /x ED cvx /y ED y x RadtoDeg PtoC} def }

\begin{document}
\def\Infix#1{(2^(#1/10))}% needs outer parentheses (...)
\begin{pspicture}[showgrid](-3,-3)(3,3)
\psplot[algebraic,polarplot]{2 Pi mul neg}{2 Pi mul}{\Infix{x}}
\qdisk(! (3*Pi/2) \Infix{(3*Pi/2)} ICtoPP){2pt}
\end{pspicture}
\end{document}


The procedure AlgToPs converts only a single expression. If both coordinates are given with infix notation, you must invoke it twice. And for convenience, pstricks has a procedure AlgParser which is defined as tx@AlgToPs begin AlgToPs end.

I also had a problem with the parenthesis in the \qdisk node expression. The following works:

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-plot}

% defining an RPN operator that converts Infix Cartesian to Postfix Polar
\pstVerb{/ICtoPP {AlgParser cvx exec exch AlgParser cvx exec RadtoDeg PtoC} def }

\begin{document}
\def\Infix#1{(2^(#1/10))}% needs outer parentheses (...)
\begin{pspicture}[showgrid](-3,-3)(3,3)
\psplot[algebraic,polarplot]{2 Pi mul neg}{2 Pi mul}{\Infix{x}}
\def\myval{(3*Pi/2) }
\qdisk(! \myval \Infix{\myval} ICtoPP){2pt}
\end{pspicture}
\end{document}

• Nice. I also tried that way, however the error thrown by the parenthesis problem was to cryptic for me. I find your solution more elegant. – Adam B. Nov 27 '13 at 8:59
• Is it safe to rename my operator ICtoPP to IC2PP? – kiss my armpit Nov 27 '13 at 13:39
• What do you mean by 'safe'? It may overwrite an existing operator with this name, but I don't think it exists. – Christoph Nov 27 '13 at 13:48
• I meant that is it safe to use numbers inserted between letters when defining an name for PS operators or variables or constants? – kiss my armpit Nov 27 '13 at 19:45
• Yes, citing from the Redbook: „Any token that consists entirely of regular characters and cannot be interpreted as a number is treated as a name object (more precisely, an executable name). All characters except delimiters and white-space characters can appear in names, including characters ordinarily considered to be punctuation. The following are examples of valid names: abc Offset  23A 13−456 a.b \$MyDict @pattern – Christoph Nov 28 '13 at 8:19

You could take a look at the infix-RPN package (which is used by the pst-infixplot package), even if that's not exactly a PSTricks operator. The following MWE does the job.

\documentclass[pstricks,border=12pt]{standalone}
%\usepackage{pst-plot}
\usepackage{pst-infixplot}

% defining an RPN operator that converts Infix Cartesian to Postfix Polar
\pstVerb{/ICtoPP {tx@AlgToPs begin AlgToPs end exch cvx /x ED cvx /y ED y x RadtoDeg PtoC} def }

\begin{document}
\def\Infix#1{(2^(#1/10))}% needs outer parentheses (...)
\begin{pspicture}[showgrid](-3,-3)(3,3)
\psplot[algebraic,polarplot,plotpoints=100]{2 Pi mul neg}{2 Pi mul}{\Infix{x}}
\def\abscissa{(3*Pi/2)}
\infixtoRPN{\abscissa}
\qdisk(! \RPN \Infix{\abscissa} ICtoPP){2pt}
\end{pspicture}
\end{document}

• +1 as well even though it is not what I am looking for. :-) – kiss my armpit Nov 27 '13 at 13:10
\documentclass[pstricks,border=12pt]{standalone}