Average Error: 35.4 → 27.4
Time: 13.6s
Precision: binary64
Cost: 33220
\[\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}\;\frac{\tan t_0}{\sin t_0} \leq 4:\\ \;\;\;\;\frac{1}{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos \left(\frac{x}{y} \cdot 0.5\right)\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{expm1}\left(\log 2 + -0.0625 \cdot \frac{x \cdot x}{y \cdot y}\right)}\\ \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 (<= (/ (tan t_0) (sin t_0)) 4.0)
     (/ 1.0 (expm1 (log1p (cos (* (/ x y) 0.5)))))
     (/ 1.0 (expm1 (+ (log 2.0) (* -0.0625 (/ (* x x) (* y y)))))))))
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 ((tan(t_0) / sin(t_0)) <= 4.0) {
		tmp = 1.0 / expm1(log1p(cos(((x / y) * 0.5))));
	} else {
		tmp = 1.0 / expm1((log(2.0) + (-0.0625 * ((x * x) / (y * y)))));
	}
	return tmp;
}
public static double code(double x, double y) {
	return Math.tan((x / (y * 2.0))) / Math.sin((x / (y * 2.0)));
}
public static double code(double x, double y) {
	double t_0 = x / (y * 2.0);
	double tmp;
	if ((Math.tan(t_0) / Math.sin(t_0)) <= 4.0) {
		tmp = 1.0 / Math.expm1(Math.log1p(Math.cos(((x / y) * 0.5))));
	} else {
		tmp = 1.0 / Math.expm1((Math.log(2.0) + (-0.0625 * ((x * x) / (y * y)))));
	}
	return tmp;
}
def code(x, y):
	return math.tan((x / (y * 2.0))) / math.sin((x / (y * 2.0)))
def code(x, y):
	t_0 = x / (y * 2.0)
	tmp = 0
	if (math.tan(t_0) / math.sin(t_0)) <= 4.0:
		tmp = 1.0 / math.expm1(math.log1p(math.cos(((x / y) * 0.5))))
	else:
		tmp = 1.0 / math.expm1((math.log(2.0) + (-0.0625 * ((x * x) / (y * y)))))
	return tmp
function code(x, y)
	return Float64(tan(Float64(x / Float64(y * 2.0))) / sin(Float64(x / Float64(y * 2.0))))
end
function code(x, y)
	t_0 = Float64(x / Float64(y * 2.0))
	tmp = 0.0
	if (Float64(tan(t_0) / sin(t_0)) <= 4.0)
		tmp = Float64(1.0 / expm1(log1p(cos(Float64(Float64(x / y) * 0.5)))));
	else
		tmp = Float64(1.0 / expm1(Float64(log(2.0) + Float64(-0.0625 * Float64(Float64(x * x) / Float64(y * y))))));
	end
	return tmp
end
code[x_, y_] := N[(N[Tan[N[(x / N[(y * 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sin[N[(x / N[(y * 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
code[x_, y_] := Block[{t$95$0 = N[(x / N[(y * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[Tan[t$95$0], $MachinePrecision] / N[Sin[t$95$0], $MachinePrecision]), $MachinePrecision], 4.0], N[(1.0 / N[(Exp[N[Log[1 + N[Cos[N[(N[(x / y), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(Exp[N[(N[Log[2.0], $MachinePrecision] + N[(-0.0625 * N[(N[(x * x), $MachinePrecision] / N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]] - 1), $MachinePrecision]), $MachinePrecision]]]
\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}\;\frac{\tan t_0}{\sin t_0} \leq 4:\\
\;\;\;\;\frac{1}{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos \left(\frac{x}{y} \cdot 0.5\right)\right)\right)}\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{expm1}\left(\log 2 + -0.0625 \cdot \frac{x \cdot x}{y \cdot y}\right)}\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original35.4
Target28.7
Herbie27.4
\[\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 (tan.f64 (/.f64 x (*.f64 y 2))) (sin.f64 (/.f64 x (*.f64 y 2)))) < 4

    1. Initial program 25.6

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

      \[\leadsto \color{blue}{\frac{1}{\cos \left(0.5 \cdot \frac{x}{y}\right)}} \]
    3. Applied egg-rr25.6

      \[\leadsto \frac{1}{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos \left(0.5 \cdot \frac{x}{y}\right)\right)\right)}} \]

    if 4 < (/.f64 (tan.f64 (/.f64 x (*.f64 y 2))) (sin.f64 (/.f64 x (*.f64 y 2))))

    1. Initial program 63.0

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

      \[\leadsto \color{blue}{\frac{1}{\cos \left(0.5 \cdot \frac{x}{y}\right)}} \]
    3. Applied egg-rr35.6

      \[\leadsto \frac{1}{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos \left(0.5 \cdot \frac{x}{y}\right)\right)\right)}} \]
    4. Taylor expanded in x around 0 32.6

      \[\leadsto \frac{1}{\mathsf{expm1}\left(\color{blue}{\log 2 + -0.0625 \cdot \frac{{x}^{2}}{{y}^{2}}}\right)} \]
    5. Simplified32.6

      \[\leadsto \frac{1}{\mathsf{expm1}\left(\color{blue}{\log 2 + -0.0625 \cdot \frac{x \cdot x}{y \cdot y}}\right)} \]
      Proof
      (/.f64 1 (expm1.f64 (+.f64 (log.f64 2) (*.f64 -1/16 (/.f64 (*.f64 x x) (*.f64 y y)))))): 0 points increase in error, 0 points decrease in error
      (/.f64 1 (expm1.f64 (+.f64 (log.f64 2) (*.f64 -1/16 (/.f64 (Rewrite<= unpow2_binary64 (pow.f64 x 2)) (*.f64 y y)))))): 0 points increase in error, 0 points decrease in error
      (/.f64 1 (expm1.f64 (+.f64 (log.f64 2) (*.f64 -1/16 (/.f64 (pow.f64 x 2) (Rewrite<= unpow2_binary64 (pow.f64 y 2))))))): 0 points increase in error, 0 points decrease in error
  3. Recombined 2 regimes into one program.
  4. Final simplification27.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\tan \left(\frac{x}{y \cdot 2}\right)}{\sin \left(\frac{x}{y \cdot 2}\right)} \leq 4:\\ \;\;\;\;\frac{1}{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos \left(\frac{x}{y} \cdot 0.5\right)\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{expm1}\left(\log 2 + -0.0625 \cdot \frac{x \cdot x}{y \cdot y}\right)}\\ \end{array} \]

Alternatives

Alternative 1
Error27.4
Cost27204
\[\begin{array}{l} t_0 := \frac{x}{y \cdot 2}\\ t_1 := \frac{\tan t_0}{\sin t_0}\\ \mathbf{if}\;t_1 \leq 4:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{expm1}\left(\log 2 + -0.0625 \cdot \frac{x \cdot x}{y \cdot y}\right)}\\ \end{array} \]
Alternative 2
Error28.1
Cost19904
\[\frac{1}{\mathsf{expm1}\left(\mathsf{fma}\left(-0.0625, \frac{x}{y} \cdot \frac{x}{y}, \log 2\right)\right)} \]
Alternative 3
Error28.2
Cost6848
\[\frac{1}{\cos \left(\frac{x}{y} \cdot 0.5\right)} \]
Alternative 4
Error28.2
Cost6848
\[\frac{1}{\cos \left(x \cdot \frac{0.5}{y}\right)} \]
Alternative 5
Error28.2
Cost64
\[1 \]

Error

Reproduce

herbie shell --seed 2022343 
(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)))))