Average Error: 31.8 → 13.9
Time: 2.3s
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 := \frac{\mathsf{fma}\left(y, y \cdot -4, x \cdot x\right)}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}\\ \mathbf{if}\;x \leq -1.7380791032682012 \cdot 10^{+96}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq -2.2617666078219922 \cdot 10^{+61}:\\ \;\;\;\;\mathsf{fma}\left(0.5, \frac{x \cdot x}{y \cdot y}, -1\right)\\ \mathbf{elif}\;x \leq -4.611780839164092 \cdot 10^{-70}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 2.961072780439151 \cdot 10^{-61}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \leq 6.846130813274231 \cdot 10^{+127}:\\ \;\;\;\;t_0\\ \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 (/ (fma y (* y -4.0) (* x x)) (fma x x (* y (* y 4.0))))))
   (if (<= x -1.7380791032682012e+96)
     1.0
     (if (<= x -2.2617666078219922e+61)
       (fma 0.5 (/ (* x x) (* y y)) -1.0)
       (if (<= x -4.611780839164092e-70)
         t_0
         (if (<= x 2.961072780439151e-61)
           -1.0
           (if (<= x 6.846130813274231e+127) t_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 = fma(y, (y * -4.0), (x * x)) / fma(x, x, (y * (y * 4.0)));
	double tmp;
	if (x <= -1.7380791032682012e+96) {
		tmp = 1.0;
	} else if (x <= -2.2617666078219922e+61) {
		tmp = fma(0.5, ((x * x) / (y * y)), -1.0);
	} else if (x <= -4.611780839164092e-70) {
		tmp = t_0;
	} else if (x <= 2.961072780439151e-61) {
		tmp = -1.0;
	} else if (x <= 6.846130813274231e+127) {
		tmp = t_0;
	} else {
		tmp = 1.0;
	}
	return tmp;
}
function code(x, y)
	return Float64(Float64(Float64(x * x) - Float64(Float64(y * 4.0) * y)) / Float64(Float64(x * x) + Float64(Float64(y * 4.0) * y)))
end
function code(x, y)
	t_0 = Float64(fma(y, Float64(y * -4.0), Float64(x * x)) / fma(x, x, Float64(y * Float64(y * 4.0))))
	tmp = 0.0
	if (x <= -1.7380791032682012e+96)
		tmp = 1.0;
	elseif (x <= -2.2617666078219922e+61)
		tmp = fma(0.5, Float64(Float64(x * x) / Float64(y * y)), -1.0);
	elseif (x <= -4.611780839164092e-70)
		tmp = t_0;
	elseif (x <= 2.961072780439151e-61)
		tmp = -1.0;
	elseif (x <= 6.846130813274231e+127)
		tmp = t_0;
	else
		tmp = 1.0;
	end
	return tmp
end
code[x_, y_] := N[(N[(N[(x * x), $MachinePrecision] - N[(N[(y * 4.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + N[(N[(y * 4.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_] := Block[{t$95$0 = N[(N[(y * N[(y * -4.0), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision] / N[(x * x + N[(y * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.7380791032682012e+96], 1.0, If[LessEqual[x, -2.2617666078219922e+61], N[(0.5 * N[(N[(x * x), $MachinePrecision] / N[(y * y), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], If[LessEqual[x, -4.611780839164092e-70], t$95$0, If[LessEqual[x, 2.961072780439151e-61], -1.0, If[LessEqual[x, 6.846130813274231e+127], t$95$0, 1.0]]]]]]
\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 := \frac{\mathsf{fma}\left(y, y \cdot -4, x \cdot x\right)}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}\\
\mathbf{if}\;x \leq -1.7380791032682012 \cdot 10^{+96}:\\
\;\;\;\;1\\

\mathbf{elif}\;x \leq -2.2617666078219922 \cdot 10^{+61}:\\
\;\;\;\;\mathsf{fma}\left(0.5, \frac{x \cdot x}{y \cdot y}, -1\right)\\

\mathbf{elif}\;x \leq -4.611780839164092 \cdot 10^{-70}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x \leq 2.961072780439151 \cdot 10^{-61}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \leq 6.846130813274231 \cdot 10^{+127}:\\
\;\;\;\;t_0\\

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


\end{array}

Error

Bits error versus x

Bits error versus y

Target

Original31.8
Target31.5
Herbie13.9
\[\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 x < -1.73807910326820117e96 or 6.8461308132742313e127 < x

    1. Initial program 54.2

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

      \[\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.3

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

    if -1.73807910326820117e96 < x < -2.26176660782199216e61

    1. Initial program 17.0

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
    2. Simplified17.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. Taylor expanded in y around inf 40.0

      \[\leadsto \color{blue}{0.5 \cdot \frac{{x}^{2}}{{y}^{2}} - 1} \]
    4. Simplified40.0

      \[\leadsto \color{blue}{\mathsf{fma}\left(0.5, \frac{x \cdot x}{y \cdot y}, -1\right)} \]

    if -2.26176660782199216e61 < x < -4.6117808391640921e-70 or 2.961072780439151e-61 < x < 6.8461308132742313e127

    1. Initial program 15.6

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
    2. Simplified15.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 0 15.6

      \[\leadsto \frac{\color{blue}{{x}^{2} - 4 \cdot {y}^{2}}}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)} \]
    4. Simplified15.6

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

    if -4.6117808391640921e-70 < x < 2.961072780439151e-61

    1. Initial program 25.2

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

      \[\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 13.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.7380791032682012 \cdot 10^{+96}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq -2.2617666078219922 \cdot 10^{+61}:\\ \;\;\;\;\mathsf{fma}\left(0.5, \frac{x \cdot x}{y \cdot y}, -1\right)\\ \mathbf{elif}\;x \leq -4.611780839164092 \cdot 10^{-70}:\\ \;\;\;\;\frac{\mathsf{fma}\left(y, y \cdot -4, x \cdot x\right)}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}\\ \mathbf{elif}\;x \leq 2.961072780439151 \cdot 10^{-61}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \leq 6.846130813274231 \cdot 10^{+127}:\\ \;\;\;\;\frac{\mathsf{fma}\left(y, y \cdot -4, x \cdot x\right)}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]

Reproduce

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