Average Error: 31.7 → 13.1
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} t_0 := y \cdot \left(y \cdot 4\right)\\ \mathbf{if}\;t_0 \leq 1.3166629128057913 \cdot 10^{-308}:\\ \;\;\;\;1\\ \mathbf{elif}\;t_0 \leq 1.4594307950120908 \cdot 10^{+220}:\\ \;\;\;\;\log \left({e}^{\left(\frac{\mathsf{fma}\left(-4, y \cdot y, x \cdot x\right)}{\mathsf{fma}\left(x, x, t_0\right)}\right)}\right)\\ \mathbf{elif}\;t_0 \leq 2.488256767306917 \cdot 10^{+251}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \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}
t_0 := y \cdot \left(y \cdot 4\right)\\
\mathbf{if}\;t_0 \leq 1.3166629128057913 \cdot 10^{-308}:\\
\;\;\;\;1\\

\mathbf{elif}\;t_0 \leq 1.4594307950120908 \cdot 10^{+220}:\\
\;\;\;\;\log \left({e}^{\left(\frac{\mathsf{fma}\left(-4, y \cdot y, x \cdot x\right)}{\mathsf{fma}\left(x, x, t_0\right)}\right)}\right)\\

\mathbf{elif}\;t_0 \leq 2.488256767306917 \cdot 10^{+251}:\\
\;\;\;\;1\\

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


\end{array}
(FPCore (x y)
 :precision binary64
 (/ (- (* x x) (* (* y 4.0) y)) (+ (* x x) (* (* y 4.0) y))))
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (* y (* y 4.0))))
   (if (<= t_0 1.3166629128057913e-308)
     1.0
     (if (<= t_0 1.4594307950120908e+220)
       (log (pow E (/ (fma -4.0 (* y y) (* x x)) (fma x x t_0))))
       (if (<= t_0 2.488256767306917e+251) 1.0 -1.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 t_0 = y * (y * 4.0);
	double tmp;
	if (t_0 <= 1.3166629128057913e-308) {
		tmp = 1.0;
	} else if (t_0 <= 1.4594307950120908e+220) {
		tmp = log(pow(((double) M_E), (fma(-4.0, (y * y), (x * x)) / fma(x, x, t_0))));
	} else if (t_0 <= 2.488256767306917e+251) {
		tmp = 1.0;
	} else {
		tmp = -1.0;
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Target

Original31.7
Target31.4
Herbie13.1
\[\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 3 regimes
  2. if (*.f64 (*.f64 y 4) y) < 1.316662912805791e-308 or 1.4594307950120908e220 < (*.f64 (*.f64 y 4) y) < 2.48825676730691721e251

    1. Initial program 29.5

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
    2. Simplified29.7

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(-4, y \cdot y, x \cdot x\right)}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}} \]
    3. Taylor expanded in y around 0 11.1

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

    if 1.316662912805791e-308 < (*.f64 (*.f64 y 4) y) < 1.4594307950120908e220

    1. Initial program 16.0

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
    2. Simplified16.0

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(-4, y \cdot y, x \cdot x\right)}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}} \]
    3. Applied add-log-exp_binary6416.0

      \[\leadsto \color{blue}{\log \left(e^{\frac{\mathsf{fma}\left(-4, y \cdot y, x \cdot x\right)}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}}\right)} \]
    4. Applied *-un-lft-identity_binary6416.0

      \[\leadsto \log \left(e^{\frac{\mathsf{fma}\left(-4, y \cdot y, x \cdot x\right)}{\color{blue}{1 \cdot \mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}}}\right) \]
    5. Applied *-un-lft-identity_binary6416.0

      \[\leadsto \log \left(e^{\frac{\color{blue}{1 \cdot \mathsf{fma}\left(-4, y \cdot y, x \cdot x\right)}}{1 \cdot \mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}}\right) \]
    6. Applied times-frac_binary6416.0

      \[\leadsto \log \left(e^{\color{blue}{\frac{1}{1} \cdot \frac{\mathsf{fma}\left(-4, y \cdot y, x \cdot x\right)}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}}}\right) \]
    7. Applied exp-prod_binary6416.0

      \[\leadsto \log \color{blue}{\left({\left(e^{\frac{1}{1}}\right)}^{\left(\frac{\mathsf{fma}\left(-4, y \cdot y, x \cdot x\right)}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}\right)}\right)} \]
    8. Simplified16.0

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

    if 2.48825676730691721e251 < (*.f64 (*.f64 y 4) y)

    1. Initial program 56.6

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
    2. Simplified56.6

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(-4, y \cdot y, x \cdot x\right)}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}} \]
    3. Taylor expanded in y around inf 10.7

      \[\leadsto \color{blue}{-1} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification13.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \cdot \left(y \cdot 4\right) \leq 1.3166629128057913 \cdot 10^{-308}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \cdot \left(y \cdot 4\right) \leq 1.4594307950120908 \cdot 10^{+220}:\\ \;\;\;\;\log \left({e}^{\left(\frac{\mathsf{fma}\left(-4, y \cdot y, x \cdot x\right)}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}\right)}\right)\\ \mathbf{elif}\;y \cdot \left(y \cdot 4\right) \leq 2.488256767306917 \cdot 10^{+251}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]

Reproduce

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