Average Error: 32.4 → 13.9
Time: 7.4s
Precision: binary64
Cost: 14232
\[\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{x \cdot x + y \cdot \left(y \cdot -4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ t_1 := \mathsf{fma}\left(2 \cdot \left(-1 + \mathsf{hypot}\left(1, \frac{y}{x}\right)\right), -8, 1\right)\\ \mathbf{if}\;y \leq -5.2124856436834405 \cdot 10^{+116}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq -3.276338429551299 \cdot 10^{+96}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -5.890265063404712 \cdot 10^{+47}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -1118285162071.6514:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -2.93963781802403 \cdot 10^{-47}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 5.150561606422027 \cdot 10^{-33}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 2.54478194731829 \cdot 10^{+141}:\\ \;\;\;\;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 (/ (+ (* x x) (* y (* y -4.0))) (+ (* x x) (* y (* y 4.0)))))
        (t_1 (fma (* 2.0 (+ -1.0 (hypot 1.0 (/ y x)))) -8.0 1.0)))
   (if (<= y -5.2124856436834405e+116)
     -1.0
     (if (<= y -3.276338429551299e+96)
       t_1
       (if (<= y -5.890265063404712e+47)
         t_0
         (if (<= y -1118285162071.6514)
           t_1
           (if (<= y -2.93963781802403e-47)
             t_0
             (if (<= y 5.150561606422027e-33)
               t_1
               (if (<= y 2.54478194731829e+141) 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 = ((x * x) + (y * (y * -4.0))) / ((x * x) + (y * (y * 4.0)));
	double t_1 = fma((2.0 * (-1.0 + hypot(1.0, (y / x)))), -8.0, 1.0);
	double tmp;
	if (y <= -5.2124856436834405e+116) {
		tmp = -1.0;
	} else if (y <= -3.276338429551299e+96) {
		tmp = t_1;
	} else if (y <= -5.890265063404712e+47) {
		tmp = t_0;
	} else if (y <= -1118285162071.6514) {
		tmp = t_1;
	} else if (y <= -2.93963781802403e-47) {
		tmp = t_0;
	} else if (y <= 5.150561606422027e-33) {
		tmp = t_1;
	} else if (y <= 2.54478194731829e+141) {
		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(Float64(Float64(x * x) + Float64(y * Float64(y * -4.0))) / Float64(Float64(x * x) + Float64(y * Float64(y * 4.0))))
	t_1 = fma(Float64(2.0 * Float64(-1.0 + hypot(1.0, Float64(y / x)))), -8.0, 1.0)
	tmp = 0.0
	if (y <= -5.2124856436834405e+116)
		tmp = -1.0;
	elseif (y <= -3.276338429551299e+96)
		tmp = t_1;
	elseif (y <= -5.890265063404712e+47)
		tmp = t_0;
	elseif (y <= -1118285162071.6514)
		tmp = t_1;
	elseif (y <= -2.93963781802403e-47)
		tmp = t_0;
	elseif (y <= 5.150561606422027e-33)
		tmp = t_1;
	elseif (y <= 2.54478194731829e+141)
		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[(N[(x * x), $MachinePrecision] + N[(y * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + N[(y * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(2.0 * N[(-1.0 + N[Sqrt[1.0 ^ 2 + N[(y / x), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * -8.0 + 1.0), $MachinePrecision]}, If[LessEqual[y, -5.2124856436834405e+116], -1.0, If[LessEqual[y, -3.276338429551299e+96], t$95$1, If[LessEqual[y, -5.890265063404712e+47], t$95$0, If[LessEqual[y, -1118285162071.6514], t$95$1, If[LessEqual[y, -2.93963781802403e-47], t$95$0, If[LessEqual[y, 5.150561606422027e-33], t$95$1, If[LessEqual[y, 2.54478194731829e+141], 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{x \cdot x + y \cdot \left(y \cdot -4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\
t_1 := \mathsf{fma}\left(2 \cdot \left(-1 + \mathsf{hypot}\left(1, \frac{y}{x}\right)\right), -8, 1\right)\\
\mathbf{if}\;y \leq -5.2124856436834405 \cdot 10^{+116}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \leq -3.276338429551299 \cdot 10^{+96}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;y \leq -5.890265063404712 \cdot 10^{+47}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;y \leq -1118285162071.6514:\\
\;\;\;\;t_1\\

\mathbf{elif}\;y \leq -2.93963781802403 \cdot 10^{-47}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;y \leq 5.150561606422027 \cdot 10^{-33}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;y \leq 2.54478194731829 \cdot 10^{+141}:\\
\;\;\;\;t_0\\

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


\end{array}

Error

Target

Original32.4
Target32.1
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 3 regimes
  2. if y < -5.21248564368344052e116 or 2.54478194731829e141 < y

    1. Initial program 57.5

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

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

    if -5.21248564368344052e116 < y < -3.27633842955129883e96 or -5.8902650634047122e47 < y < -1118285162071.6514 or -2.93963781802403e-47 < y < 5.150561606422027e-33

    1. Initial program 24.5

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{y}{x} \cdot \frac{y}{x}, -8, 1\right)} \]
      Proof
      (fma.f64 (*.f64 (/.f64 y x) (/.f64 y x)) -8 1): 0 points increase in error, 0 points decrease in error
      (fma.f64 (Rewrite<= times-frac_binary64 (/.f64 (*.f64 y y) (*.f64 x x))) -8 1): 49 points increase in error, 2 points decrease in error
      (fma.f64 (/.f64 (Rewrite<= unpow2_binary64 (pow.f64 y 2)) (*.f64 x x)) -8 1): 0 points increase in error, 0 points decrease in error
      (fma.f64 (/.f64 (pow.f64 y 2) (Rewrite<= unpow2_binary64 (pow.f64 x 2))) -8 1): 0 points increase in error, 0 points decrease in error
      (Rewrite<= fma-def_binary64 (+.f64 (*.f64 (/.f64 (pow.f64 y 2) (pow.f64 x 2)) -8) 1)): 0 points increase in error, 0 points decrease in error
      (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 -8 (/.f64 (pow.f64 y 2) (pow.f64 x 2)))) 1): 0 points increase in error, 0 points decrease in error
      (Rewrite=> +-commutative_binary64 (+.f64 1 (*.f64 -8 (/.f64 (pow.f64 y 2) (pow.f64 x 2))))): 0 points increase in error, 0 points decrease in error
      (+.f64 1 (Rewrite=> *-commutative_binary64 (*.f64 (/.f64 (pow.f64 y 2) (pow.f64 x 2)) -8))): 0 points increase in error, 0 points decrease in error
      (+.f64 1 (*.f64 (/.f64 (pow.f64 y 2) (pow.f64 x 2)) (Rewrite<= metadata-eval (-.f64 -4 4)))): 0 points increase in error, 0 points decrease in error
      (+.f64 1 (Rewrite<= distribute-rgt-out--_binary64 (-.f64 (*.f64 -4 (/.f64 (pow.f64 y 2) (pow.f64 x 2))) (*.f64 4 (/.f64 (pow.f64 y 2) (pow.f64 x 2)))))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate--l+_binary64 (-.f64 (+.f64 1 (*.f64 -4 (/.f64 (pow.f64 y 2) (pow.f64 x 2)))) (*.f64 4 (/.f64 (pow.f64 y 2) (pow.f64 x 2))))): 1 points increase in error, 0 points decrease in error
    4. Applied egg-rr15.6

      \[\leadsto \mathsf{fma}\left(\color{blue}{\left(1 + {\left(\frac{y}{x}\right)}^{2}\right) - 1}, -8, 1\right) \]
    5. Applied egg-rr15.6

      \[\leadsto \mathsf{fma}\left(\color{blue}{\left(\mathsf{hypot}\left(1, \frac{y}{x}\right) + 1\right) \cdot \left(\mathsf{hypot}\left(1, \frac{y}{x}\right) - 1\right)}, -8, 1\right) \]
    6. Taylor expanded in y around 0 15.2

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

    if -3.27633842955129883e96 < y < -5.8902650634047122e47 or -1118285162071.6514 < y < -2.93963781802403e-47 or 5.150561606422027e-33 < y < 2.54478194731829e141

    1. Initial program 16.4

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification13.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -5.2124856436834405 \cdot 10^{+116}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq -3.276338429551299 \cdot 10^{+96}:\\ \;\;\;\;\mathsf{fma}\left(2 \cdot \left(-1 + \mathsf{hypot}\left(1, \frac{y}{x}\right)\right), -8, 1\right)\\ \mathbf{elif}\;y \leq -5.890265063404712 \cdot 10^{+47}:\\ \;\;\;\;\frac{x \cdot x + y \cdot \left(y \cdot -4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{elif}\;y \leq -1118285162071.6514:\\ \;\;\;\;\mathsf{fma}\left(2 \cdot \left(-1 + \mathsf{hypot}\left(1, \frac{y}{x}\right)\right), -8, 1\right)\\ \mathbf{elif}\;y \leq -2.93963781802403 \cdot 10^{-47}:\\ \;\;\;\;\frac{x \cdot x + y \cdot \left(y \cdot -4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{elif}\;y \leq 5.150561606422027 \cdot 10^{-33}:\\ \;\;\;\;\mathsf{fma}\left(2 \cdot \left(-1 + \mathsf{hypot}\left(1, \frac{y}{x}\right)\right), -8, 1\right)\\ \mathbf{elif}\;y \leq 2.54478194731829 \cdot 10^{+141}:\\ \;\;\;\;\frac{x \cdot x + y \cdot \left(y \cdot -4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]

Alternatives

Alternative 1
Error14.0
Cost13704
\[\begin{array}{l} t_0 := \mathsf{fma}\left(\frac{y}{x} \cdot \frac{y}{x}, -8, 1\right)\\ t_1 := \frac{x \cdot x + y \cdot \left(y \cdot -4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{if}\;y \leq -5.2124856436834405 \cdot 10^{+116}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq -3.276338429551299 \cdot 10^{+96}:\\ \;\;\;\;\mathsf{fma}\left(-1 + \left(1 + {\left(\frac{y}{x}\right)}^{2}\right), -8, 1\right)\\ \mathbf{elif}\;y \leq -5.890265063404712 \cdot 10^{+47}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -1118285162071.6514:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -2.93963781802403 \cdot 10^{-47}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 5.150561606422027 \cdot 10^{-33}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 2.54478194731829 \cdot 10^{+141}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
Alternative 2
Error14.0
Cost7768
\[\begin{array}{l} t_0 := \frac{x \cdot x + y \cdot \left(y \cdot -4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ t_1 := \mathsf{fma}\left(\frac{y}{x} \cdot \frac{y}{x}, -8, 1\right)\\ \mathbf{if}\;y \leq -5.2124856436834405 \cdot 10^{+116}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq -3.276338429551299 \cdot 10^{+96}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -5.890265063404712 \cdot 10^{+47}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -1118285162071.6514:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -2.93963781802403 \cdot 10^{-47}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 5.150561606422027 \cdot 10^{-33}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 2.54478194731829 \cdot 10^{+141}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
Alternative 3
Error14.3
Cost2140
\[\begin{array}{l} t_0 := \frac{x \cdot x + y \cdot \left(y \cdot -4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{if}\;y \leq -5.2124856436834405 \cdot 10^{+116}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq -3.276338429551299 \cdot 10^{+96}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq -5.890265063404712 \cdot 10^{+47}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -1118285162071.6514:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq -2.93963781802403 \cdot 10^{-47}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 5.150561606422027 \cdot 10^{-33}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 2.54478194731829 \cdot 10^{+141}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
Alternative 4
Error16.2
Cost328
\[\begin{array}{l} \mathbf{if}\;x \leq -0.0008571395046742114:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 6.891669567071435 \cdot 10^{+22}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 5
Error31.7
Cost64
\[1 \]

Error

Reproduce

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