Average Error: 32.1 → 12.7
Time: 2.6s
Precision: binary64
\[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;y \cdot \left(y \cdot 4\right) \leq 6.819785607400204 \cdot 10^{-243}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \cdot \left(y \cdot 4\right) \leq 1.391055848722249 \cdot 10^{-30}:\\ \;\;\;\;\frac{1}{\frac{y \cdot \left(y \cdot 4\right) + x \cdot x}{x \cdot x - y \cdot \left(y \cdot 4\right)}}\\ \mathbf{elif}\;y \cdot \left(y \cdot 4\right) \leq 6.062263388767952 \cdot 10^{-08}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \cdot \left(y \cdot 4\right) \leq 5.256578097418344 \cdot 10^{+213}:\\ \;\;\;\;\log \left(e^{\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{y \cdot \left(y \cdot 4\right) + x \cdot x}}\right)\\ \mathbf{else}:\\ \;\;\;\;-1 + 0.5 \cdot \sqrt[3]{{\left(\frac{x}{y}\right)}^{6}}\\ \end{array}\]
\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\begin{array}{l}
\mathbf{if}\;y \cdot \left(y \cdot 4\right) \leq 6.819785607400204 \cdot 10^{-243}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \cdot \left(y \cdot 4\right) \leq 1.391055848722249 \cdot 10^{-30}:\\
\;\;\;\;\frac{1}{\frac{y \cdot \left(y \cdot 4\right) + x \cdot x}{x \cdot x - y \cdot \left(y \cdot 4\right)}}\\

\mathbf{elif}\;y \cdot \left(y \cdot 4\right) \leq 6.062263388767952 \cdot 10^{-08}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \cdot \left(y \cdot 4\right) \leq 5.256578097418344 \cdot 10^{+213}:\\
\;\;\;\;\log \left(e^{\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{y \cdot \left(y \cdot 4\right) + x \cdot x}}\right)\\

\mathbf{else}:\\
\;\;\;\;-1 + 0.5 \cdot \sqrt[3]{{\left(\frac{x}{y}\right)}^{6}}\\

\end{array}
(FPCore (x y)
 :precision binary64
 (/ (- (* x x) (* (* y 4.0) y)) (+ (* x x) (* (* y 4.0) y))))
(FPCore (x y)
 :precision binary64
 (if (<= (* y (* y 4.0)) 6.819785607400204e-243)
   1.0
   (if (<= (* y (* y 4.0)) 1.391055848722249e-30)
     (/ 1.0 (/ (+ (* y (* y 4.0)) (* x x)) (- (* x x) (* y (* y 4.0)))))
     (if (<= (* y (* y 4.0)) 6.062263388767952e-08)
       1.0
       (if (<= (* y (* y 4.0)) 5.256578097418344e+213)
         (log
          (exp (/ (- (* x x) (* y (* y 4.0))) (+ (* y (* y 4.0)) (* x x)))))
         (+ -1.0 (* 0.5 (cbrt (pow (/ x y) 6.0)))))))))
double code(double x, double y) {
	return ((x * x) - ((y * 4.0) * y)) / ((x * x) + ((y * 4.0) * y));
}
double code(double x, double y) {
	double tmp;
	if ((y * (y * 4.0)) <= 6.819785607400204e-243) {
		tmp = 1.0;
	} else if ((y * (y * 4.0)) <= 1.391055848722249e-30) {
		tmp = 1.0 / (((y * (y * 4.0)) + (x * x)) / ((x * x) - (y * (y * 4.0))));
	} else if ((y * (y * 4.0)) <= 6.062263388767952e-08) {
		tmp = 1.0;
	} else if ((y * (y * 4.0)) <= 5.256578097418344e+213) {
		tmp = log(exp(((x * x) - (y * (y * 4.0))) / ((y * (y * 4.0)) + (x * x))));
	} else {
		tmp = -1.0 + (0.5 * cbrt(pow((x / y), 6.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

Original32.1
Target31.8
Herbie12.7
\[\begin{array}{l} \mathbf{if}\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y} < 0.9743233849626781:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + \left(y \cdot y\right) \cdot 4} - \frac{\left(y \cdot y\right) \cdot 4}{x \cdot x + \left(y \cdot y\right) \cdot 4}\\ \mathbf{else}:\\ \;\;\;\;{\left(\frac{x}{\sqrt{x \cdot x + \left(y \cdot y\right) \cdot 4}}\right)}^{2} - \frac{\left(y \cdot y\right) \cdot 4}{x \cdot x + \left(y \cdot y\right) \cdot 4}\\ \end{array}\]

Derivation

  1. Split input into 4 regimes
  2. if (*.f64 (*.f64 y 4) y) < 6.81978560740020417e-243 or 1.39105584872224907e-30 < (*.f64 (*.f64 y 4) y) < 6.06226338876795223e-8

    1. Initial program 28.8

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    2. Taylor expanded around inf 11.6

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

    if 6.81978560740020417e-243 < (*.f64 (*.f64 y 4) y) < 1.39105584872224907e-30

    1. Initial program 16.2

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    2. Using strategy rm
    3. Applied clear-num_binary64_1610416.2

      \[\leadsto \color{blue}{\frac{1}{\frac{x \cdot x + \left(y \cdot 4\right) \cdot y}{x \cdot x - \left(y \cdot 4\right) \cdot y}}}\]

    if 6.06226338876795223e-8 < (*.f64 (*.f64 y 4) y) < 5.2565780974183442e213

    1. Initial program 15.5

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    2. Using strategy rm
    3. Applied add-log-exp_binary64_1614415.5

      \[\leadsto \color{blue}{\log \left(e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right)}\]

    if 5.2565780974183442e213 < (*.f64 (*.f64 y 4) y)

    1. Initial program 52.7

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    2. Taylor expanded around 0 17.1

      \[\leadsto \color{blue}{0.5 \cdot \frac{{x}^{2}}{{y}^{2}} - 1}\]
    3. Simplified17.1

      \[\leadsto \color{blue}{-1 + 0.5 \cdot \frac{x \cdot x}{y \cdot y}}\]
    4. Using strategy rm
    5. Applied add-cbrt-cube_binary64_1614117.1

      \[\leadsto -1 + 0.5 \cdot \color{blue}{\sqrt[3]{\left(\frac{x \cdot x}{y \cdot y} \cdot \frac{x \cdot x}{y \cdot y}\right) \cdot \frac{x \cdot x}{y \cdot y}}}\]
    6. Simplified10.5

      \[\leadsto -1 + 0.5 \cdot \sqrt[3]{\color{blue}{{\left(\frac{x}{y}\right)}^{6}}}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification12.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \cdot \left(y \cdot 4\right) \leq 6.819785607400204 \cdot 10^{-243}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \cdot \left(y \cdot 4\right) \leq 1.391055848722249 \cdot 10^{-30}:\\ \;\;\;\;\frac{1}{\frac{y \cdot \left(y \cdot 4\right) + x \cdot x}{x \cdot x - y \cdot \left(y \cdot 4\right)}}\\ \mathbf{elif}\;y \cdot \left(y \cdot 4\right) \leq 6.062263388767952 \cdot 10^{-08}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \cdot \left(y \cdot 4\right) \leq 5.256578097418344 \cdot 10^{+213}:\\ \;\;\;\;\log \left(e^{\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{y \cdot \left(y \cdot 4\right) + x \cdot x}}\right)\\ \mathbf{else}:\\ \;\;\;\;-1 + 0.5 \cdot \sqrt[3]{{\left(\frac{x}{y}\right)}^{6}}\\ \end{array}\]

Reproduce

herbie shell --seed 2021059 
(FPCore (x y)
  :name "Diagrams.TwoD.Arc:arcBetween from diagrams-lib-1.3.0.3"
  :precision binary64

  :herbie-target
  (if (< (/ (- (* x x) (* (* y 4.0) y)) (+ (* x x) (* (* y 4.0) y))) 0.9743233849626781) (- (/ (* x x) (+ (* x x) (* (* y y) 4.0))) (/ (* (* y y) 4.0) (+ (* x x) (* (* y y) 4.0)))) (- (pow (/ x (sqrt (+ (* x x) (* (* y y) 4.0)))) 2.0) (/ (* (* y y) 4.0) (+ (* x x) (* (* y y) 4.0)))))

  (/ (- (* x x) (* (* y 4.0) y)) (+ (* x x) (* (* y 4.0) y))))