Average Error: 31.9 → 13.7
Time: 2.2s
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)}\\ t_1 := \mathsf{fma}\left(\frac{x}{y}, \frac{x \cdot 0.5}{y}, -1\right)\\ \mathbf{if}\;y \leq -5.621818950017379 \cdot 10^{+106}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -3.7554906204978623 \cdot 10^{-79}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 4.336739521244769 \cdot 10^{-163}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 1.9675824600358294 \cdot 10^{-51}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 0.8751567774769502:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 1.4096815754389695 \cdot 10^{+38}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_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)))))
        (t_1 (fma (/ x y) (/ (* x 0.5) y) -1.0)))
   (if (<= y -5.621818950017379e+106)
     t_1
     (if (<= y -3.7554906204978623e-79)
       t_0
       (if (<= y 4.336739521244769e-163)
         1.0
         (if (<= y 1.9675824600358294e-51)
           t_0
           (if (<= y 0.8751567774769502)
             1.0
             (if (<= y 1.4096815754389695e+38) t_0 t_1))))))))
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 t_1 = fma((x / y), ((x * 0.5) / y), -1.0);
	double tmp;
	if (y <= -5.621818950017379e+106) {
		tmp = t_1;
	} else if (y <= -3.7554906204978623e-79) {
		tmp = t_0;
	} else if (y <= 4.336739521244769e-163) {
		tmp = 1.0;
	} else if (y <= 1.9675824600358294e-51) {
		tmp = t_0;
	} else if (y <= 0.8751567774769502) {
		tmp = 1.0;
	} else if (y <= 1.4096815754389695e+38) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	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))))
	t_1 = fma(Float64(x / y), Float64(Float64(x * 0.5) / y), -1.0)
	tmp = 0.0
	if (y <= -5.621818950017379e+106)
		tmp = t_1;
	elseif (y <= -3.7554906204978623e-79)
		tmp = t_0;
	elseif (y <= 4.336739521244769e-163)
		tmp = 1.0;
	elseif (y <= 1.9675824600358294e-51)
		tmp = t_0;
	elseif (y <= 0.8751567774769502)
		tmp = 1.0;
	elseif (y <= 1.4096815754389695e+38)
		tmp = t_0;
	else
		tmp = t_1;
	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]}, Block[{t$95$1 = N[(N[(x / y), $MachinePrecision] * N[(N[(x * 0.5), $MachinePrecision] / y), $MachinePrecision] + -1.0), $MachinePrecision]}, If[LessEqual[y, -5.621818950017379e+106], t$95$1, If[LessEqual[y, -3.7554906204978623e-79], t$95$0, If[LessEqual[y, 4.336739521244769e-163], 1.0, If[LessEqual[y, 1.9675824600358294e-51], t$95$0, If[LessEqual[y, 0.8751567774769502], 1.0, If[LessEqual[y, 1.4096815754389695e+38], t$95$0, t$95$1]]]]]]]]
\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)}\\
t_1 := \mathsf{fma}\left(\frac{x}{y}, \frac{x \cdot 0.5}{y}, -1\right)\\
\mathbf{if}\;y \leq -5.621818950017379 \cdot 10^{+106}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;y \leq -3.7554906204978623 \cdot 10^{-79}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;y \leq 4.336739521244769 \cdot 10^{-163}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \leq 1.9675824600358294 \cdot 10^{-51}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;y \leq 0.8751567774769502:\\
\;\;\;\;1\\

\mathbf{elif}\;y \leq 1.4096815754389695 \cdot 10^{+38}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}

Error

Target

Original31.9
Target31.6
Herbie13.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 3 regimes
  2. if y < -5.6218189500173787e106 or 1.40968157543896953e38 < y

    1. Initial program 47.7

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

      \[\leadsto \color{blue}{\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)}} \]
    3. Taylor expanded in y around inf 17.9

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

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

    if -5.6218189500173787e106 < y < -3.75549062049786231e-79 or 4.336739521244769e-163 < y < 1.96758246003582941e-51 or 0.8751567774769502 < y < 1.40968157543896953e38

    1. Initial program 15.7

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

      \[\leadsto \color{blue}{\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)}} \]

    if -3.75549062049786231e-79 < y < 4.336739521244769e-163 or 1.96758246003582941e-51 < y < 0.8751567774769502

    1. Initial program 27.1

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

      \[\leadsto \color{blue}{\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)}} \]
    3. Taylor expanded in y around 0 13.8

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -5.621818950017379 \cdot 10^{+106}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{y}, \frac{x \cdot 0.5}{y}, -1\right)\\ \mathbf{elif}\;y \leq -3.7554906204978623 \cdot 10^{-79}:\\ \;\;\;\;\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}\;y \leq 4.336739521244769 \cdot 10^{-163}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 1.9675824600358294 \cdot 10^{-51}:\\ \;\;\;\;\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}\;y \leq 0.8751567774769502:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 1.4096815754389695 \cdot 10^{+38}:\\ \;\;\;\;\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}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{y}, \frac{x \cdot 0.5}{y}, -1\right)\\ \end{array} \]

Reproduce

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