Average Error: 35.7 → 27.3
Time: 12.2s
Precision: binary64
\[\frac{\tan \left(\frac{x}{y \cdot 2}\right)}{\sin \left(\frac{x}{y \cdot 2}\right)} \]
\[\begin{array}{l} t_0 := \frac{x}{y \cdot 2}\\ \mathbf{if}\;t_0 \leq -1.8386381635474647 \cdot 10^{+201}:\\ \;\;\;\;1\\ \mathbf{elif}\;t_0 \leq 3.9210386054208765 \cdot 10^{+66}:\\ \;\;\;\;\frac{1}{\cos \left(0.5 \cdot \frac{x}{y}\right)}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
\frac{\tan \left(\frac{x}{y \cdot 2}\right)}{\sin \left(\frac{x}{y \cdot 2}\right)}
\begin{array}{l}
t_0 := \frac{x}{y \cdot 2}\\
\mathbf{if}\;t_0 \leq -1.8386381635474647 \cdot 10^{+201}:\\
\;\;\;\;1\\

\mathbf{elif}\;t_0 \leq 3.9210386054208765 \cdot 10^{+66}:\\
\;\;\;\;\frac{1}{\cos \left(0.5 \cdot \frac{x}{y}\right)}\\

\mathbf{else}:\\
\;\;\;\;1\\


\end{array}
(FPCore (x y)
 :precision binary64
 (/ (tan (/ x (* y 2.0))) (sin (/ x (* y 2.0)))))
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (/ x (* y 2.0))))
   (if (<= t_0 -1.8386381635474647e+201)
     1.0
     (if (<= t_0 3.9210386054208765e+66) (/ 1.0 (cos (* 0.5 (/ x y)))) 1.0))))
double code(double x, double y) {
	return tan((x / (y * 2.0))) / sin((x / (y * 2.0)));
}
double code(double x, double y) {
	double t_0 = x / (y * 2.0);
	double tmp;
	if (t_0 <= -1.8386381635474647e+201) {
		tmp = 1.0;
	} else if (t_0 <= 3.9210386054208765e+66) {
		tmp = 1.0 / cos((0.5 * (x / y)));
	} else {
		tmp = 1.0;
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original35.7
Target29.0
Herbie27.3
\[\begin{array}{l} \mathbf{if}\;y < -1.2303690911306994 \cdot 10^{+114}:\\ \;\;\;\;1\\ \mathbf{elif}\;y < -9.102852406811914 \cdot 10^{-222}:\\ \;\;\;\;\frac{\sin \left(\frac{x}{y \cdot 2}\right)}{\sin \left(\frac{x}{y \cdot 2}\right) \cdot \log \left(e^{\cos \left(\frac{x}{y \cdot 2}\right)}\right)}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]

Derivation

  1. Split input into 2 regimes
  2. if (/.f64 x (*.f64 y 2)) < -1.8386381635474647e201 or 3.9210386054208765e66 < (/.f64 x (*.f64 y 2))

    1. Initial program 60.0

      \[\frac{\tan \left(\frac{x}{y \cdot 2}\right)}{\sin \left(\frac{x}{y \cdot 2}\right)} \]
    2. Taylor expanded in x around 0 56.4

      \[\leadsto \color{blue}{1} \]

    if -1.8386381635474647e201 < (/.f64 x (*.f64 y 2)) < 3.9210386054208765e66

    1. Initial program 24.7

      \[\frac{\tan \left(\frac{x}{y \cdot 2}\right)}{\sin \left(\frac{x}{y \cdot 2}\right)} \]
    2. Taylor expanded in x around inf 14.1

      \[\leadsto \color{blue}{\frac{1}{\cos \left(0.5 \cdot \frac{x}{y}\right)}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification27.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x}{y \cdot 2} \leq -1.8386381635474647 \cdot 10^{+201}:\\ \;\;\;\;1\\ \mathbf{elif}\;\frac{x}{y \cdot 2} \leq 3.9210386054208765 \cdot 10^{+66}:\\ \;\;\;\;\frac{1}{\cos \left(0.5 \cdot \frac{x}{y}\right)}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]

Reproduce

herbie shell --seed 2022130 
(FPCore (x y)
  :name "Diagrams.TwoD.Layout.CirclePacking:approxRadius from diagrams-contrib-1.3.0.5"
  :precision binary64

  :herbie-target
  (if (< y -1.2303690911306994e+114) 1.0 (if (< y -9.102852406811914e-222) (/ (sin (/ x (* y 2.0))) (* (sin (/ x (* y 2.0))) (log (exp (cos (/ x (* y 2.0))))))) 1.0))

  (/ (tan (/ x (* y 2.0))) (sin (/ x (* y 2.0)))))