[pstricks] Thomae's Function
Jean-Côme Charpentier
jean-come.charpentier at wanadoo.fr
Sun Jun 8 11:19:34 CEST 2008
Herbert Voss a écrit :
> sebastian perez schrieb:
>
>> I'd like to know if it is possible to use pstricks to make the graph of Thomae's function
>>
>>
>> http://en.wikipedia.org/wiki/Thomae's_function
>
>
> not yet possible
... with a direct way. Otherwise, we can cheat :-)
\documentclass{article}
\usepackage{pstricks-add}
\usepackage{multido}
\makeatletter
\newcommand\IfRelPrime[4]{%
\def\reserved at a{#1}%
\def\reserved at b{#2}%
\loop\ifnum\reserved at b>0
\pst at mod\reserved at a\reserved at b\reserved at c
\let\reserved at a\reserved at b
\let\reserved at b\reserved at c
\repeat
\ifnum\reserved at a=1
\def\reserved at c{#3}%
\else
\def\reserved at c{#4}%
\fi
\reserved at c\ignorespaces
}
\makeatother
\begin{document}
\begin{center}
\psset{unit=4cm,dotsize=1pt 0}
\begin{pspicture}(2.5,1.5)
\psaxes{->}(0,0)(2.5,1.5)
\multido{\ip=1+1}{50}{%
\multido{\iq=1+1}{100}{%
\unless\ifnum\ip>\numexpr2*\iq % for x \in [0,2]
\IfRelPrime{\ip}{\iq}{%
\psdots(!\ip\space \iq\space div 1 \iq\space div)
}{\relax}
\fi
}%
}%
\end{pspicture}
\end{center}
\end{document}
Attention! The two loops can't be extended. For instance, with
\multido{\ip=1+1}{80}{%
\multido{\iq=1+1}{160}{%
I obtain a beautiful
Runaway text?
" tx at Dict begin STP newpath 0.8 SLW 0 setgray [ 41 147 div 1 147 di\ETC.
! TeX capacity exceeded, sorry [main memory size=1500000].
\pst at code ...r .5 add exch itransform Dot } repeat
l.36 }
%
No pages of output.
I suppose (I'm not sure) that it's working with recursive macro rather
multido but I'm too lasy to test it :-)
Jean-Côme Charpentier
More information about the PSTricks
mailing list