# What is the difference between x RadToDeg cos x div and COSC?

\documentclass[border=10pt,pstricks]{standalone}
\usepackage{amsmath,pst-func}
\begin{document}
\pstVerb{
/SINC { dup 0 eq { pop 1 } { dup SIN exch div } ifelse } bind def %% in pst-math.pro
/COSC { dup 0 eq { pop 1 } { dup COS exch div } ifelse } bind def %% based on \SINC
}
\psset{xunit=.5,yunit=2}
\begin{pspicture}(-15,-2)(15,2)
\uput[0](1,1){$y=\dfrac{cos(x)}{x}$}
\end{pspicture}

\begin{pspicture}(-15,-2)(15,2)
\psplot[plotpoints=500]{-15}{15}{x COSC}
\uput[0](1,1){$y=\dfrac{cos(x)}{x}$}
\end{pspicture}
\end{document}


Question:

What is the difference between x RadToDeg cos x div and COSC ; Div and div?

The definition of COSC states dup COS exch div. Looking at the PostScript Stack Commands Reference (http://www.ugrad.math.ubc.ca/Flat/stack-ref.html) this means:

1. add a duplicate copy of the top object of the stack to the stack

2. COS

3. exchange the position of the top two elements on the stack

4. divide

In pst-math the COS function is defined as cosine on radians. From the manual on page 4:

pst-math introduces natural trigonometric PostScript operators COS, SIN and TAN defined by

cos: ℝ → [−1,1], x → cos(x)

So x COSC becomes:

x dup COS exch div

x x COS exch div

x COS x div

x radian_cos x div,

i.e., x RadToDeg cos x div.

• Oh, I haven't seen, can you answer the second problem? It is Div and div . – Trong Vuong Jun 24 at 11:34
• @TrongVuong your code didn't contain DIV or Div, so I wasn't sure what you meant by that question. But you can see the answer given by Red-Cloud below. – Marijn Jun 24 at 11:53

3 4 div is valid, but 3 0 div throws an error. With 3 0 DIV it is valid but returns simply 3. That is the difference between div and DIV

In order to understand what DIV and COSC do behind the scene, it will be better if you can recreate them only with pst-plot as follows.

\documentclass[border=10pt,pstricks]{standalone}
\usepackage{pst-plot}
\pstVerb{
/DIV {dup 0 eq {pop 1}{} ifelse div} bind def
/COSC {dup RadtoDeg cos exch DIV} bind def
}
\psset{xunit=.5,yunit=2}
\begin{document}
\begin{pspicture}(-15,-5)(15,5)
\psplot[plotpoints=500]{-15}{15}{x COSC}
\end{pspicture}
\end{document}


Notes:

• DIV is just an operator that takes two operands x and y and returns x/y if y is not 0. Otherwise, it returns x/1=x.

Let's trace it step by step for non zero y.

x y DIV
x y dup 0 eq {pop 1}{} ifelse div
x y y 0 eq {pop 1}{} ifelse div


As y 0 eq return false then the continuation jumps to {} which is empty.

x y div


Let's trace it step by step for y=0.

x 0 DIV
x 0 dup 0 eq {pop 1}{} ifelse div
x 0 0 0 eq {pop 1}{} ifelse div


As 0 0 eq return true then the continuation jumps to {pop 1}.

x 0 pop 1 div


pop removes the top operand which is 0.

x 1 div
x

• COSC is also just an operator that takes one operand x (in radian) and return cos(x)/x for non zero x and returns cos(x) for x=0.

x  COSC
x  dup RadtoDeg cos exch DIV
x  x RadtoDeg cos exch DIV
x  x_deg cos exch DIV
x  cos(x_deg) exch DIV
cos(x_deg) x DIV


Final result is cos(x_deg)/x for non zero x but cos(x_deg) for x=0`.