# Why do 2 identical function definitions with different names produce two different plots?

In the code snippet below I would have expected both r(x) and s(x) to be the same line, but the output is two radically different lines as shown below.

If there is a problem using the name r as a function name, then I would have expected some sort of error message, but did not find one.

\documentclass{article}
\usepackage{amsmath}
\usepackage{pgfplots}

\pgfmathdeclarefunction{r}{1}{\pgfmathparse{(2.0)}}
\pgfmathdeclarefunction{s}{1}{\pgfmathparse{(2.0)}}

\tikzstyle{MyPlotStyle}=[domain=-5:5, samples=50, ultra thick]

\begin{document}
Plot of $r(x)=2$ and $s(x)=2$ using PGF Version \pgfversion.

\begin{tikzpicture}
\begin{axis}
\addplot[MyPlotStyle, red ]{r(x)};
\addplot[MyPlotStyle, blue]{s(x)};
\end{axis}
\end{tikzpicture}
\end{document}

-
add comment

## 1 Answer

In pgfmathparser.code.tex, r is defined as a math operator that applies the deg function, to be able to specify angles in radians (\pgfmathparse{3.14r}\pgfmathresult yields (almost) 180), so you shouldn't use this name for your own functions. I agree, though, that there should be an error message if you try to define a new function with a name that's already taken by an operator, especially since operators seem to take precedence. You might want to file a bug report / feature request for this.

-
I suspected it was something like that but since I saw no error message, I wasn't sure. Where do I file this bug report? –  Peter Grill May 31 '11 at 9:57
@Peter: The PGF project uses Sourceforge: sourceforge.net/tracker/?group_id=142562 –  Jake May 31 '11 at 10:02
add comment