?

Average Error: 31.2 → 12.5
Time: 7.2s
Precision: binary64
Cost: 13836

?

\[\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 := \frac{x}{y} \cdot \frac{x}{y \cdot 4} + -1\\ \mathbf{if}\;y \leq -1.15 \cdot 10^{+119}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -1.7 \cdot 10^{-162}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 2.7 \cdot 10^{-157}:\\ \;\;\;\;\mathsf{fma}\left(-4, 1 + \left({\left(\frac{y}{x}\right)}^{2} + -1\right), 1\right)\\ \mathbf{elif}\;y \leq 4.8 \cdot 10^{+24}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 2.6 \cdot 10^{+63}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 2.6 \cdot 10^{+116}:\\ \;\;\;\;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 (/ (+ (* x x) (* y (* y -4.0))) (+ (* x x) (* y (* y 4.0)))))
        (t_1 (+ (* (/ x y) (/ x (* y 4.0))) -1.0)))
   (if (<= y -1.15e+119)
     t_1
     (if (<= y -1.7e-162)
       t_0
       (if (<= y 2.7e-157)
         (fma -4.0 (+ 1.0 (+ (pow (/ y x) 2.0) -1.0)) 1.0)
         (if (<= y 4.8e+24)
           t_0
           (if (<= y 2.6e+63) 1.0 (if (<= y 2.6e+116) 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 = ((x * x) + (y * (y * -4.0))) / ((x * x) + (y * (y * 4.0)));
	double t_1 = ((x / y) * (x / (y * 4.0))) + -1.0;
	double tmp;
	if (y <= -1.15e+119) {
		tmp = t_1;
	} else if (y <= -1.7e-162) {
		tmp = t_0;
	} else if (y <= 2.7e-157) {
		tmp = fma(-4.0, (1.0 + (pow((y / x), 2.0) + -1.0)), 1.0);
	} else if (y <= 4.8e+24) {
		tmp = t_0;
	} else if (y <= 2.6e+63) {
		tmp = 1.0;
	} else if (y <= 2.6e+116) {
		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(Float64(Float64(x * x) + Float64(y * Float64(y * -4.0))) / Float64(Float64(x * x) + Float64(y * Float64(y * 4.0))))
	t_1 = Float64(Float64(Float64(x / y) * Float64(x / Float64(y * 4.0))) + -1.0)
	tmp = 0.0
	if (y <= -1.15e+119)
		tmp = t_1;
	elseif (y <= -1.7e-162)
		tmp = t_0;
	elseif (y <= 2.7e-157)
		tmp = fma(-4.0, Float64(1.0 + Float64((Float64(y / x) ^ 2.0) + -1.0)), 1.0);
	elseif (y <= 4.8e+24)
		tmp = t_0;
	elseif (y <= 2.6e+63)
		tmp = 1.0;
	elseif (y <= 2.6e+116)
		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[(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[(N[(x / y), $MachinePrecision] * N[(x / N[(y * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]}, If[LessEqual[y, -1.15e+119], t$95$1, If[LessEqual[y, -1.7e-162], t$95$0, If[LessEqual[y, 2.7e-157], N[(-4.0 * N[(1.0 + N[(N[Power[N[(y / x), $MachinePrecision], 2.0], $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision], If[LessEqual[y, 4.8e+24], t$95$0, If[LessEqual[y, 2.6e+63], 1.0, If[LessEqual[y, 2.6e+116], 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{x \cdot x + y \cdot \left(y \cdot -4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\
t_1 := \frac{x}{y} \cdot \frac{x}{y \cdot 4} + -1\\
\mathbf{if}\;y \leq -1.15 \cdot 10^{+119}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;y \leq -1.7 \cdot 10^{-162}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;y \leq 2.7 \cdot 10^{-157}:\\
\;\;\;\;\mathsf{fma}\left(-4, 1 + \left({\left(\frac{y}{x}\right)}^{2} + -1\right), 1\right)\\

\mathbf{elif}\;y \leq 4.8 \cdot 10^{+24}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;y \leq 2.6 \cdot 10^{+63}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \leq 2.6 \cdot 10^{+116}:\\
\;\;\;\;t_0\\

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


\end{array}

Error?

Target

Original31.2
Target30.9
Herbie12.5
\[\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 y < -1.15e119 or 2.59999999999999987e116 < y

    1. Initial program 54.0

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

      \[\leadsto \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\color{blue}{4 \cdot {y}^{2}}} \]
    3. Simplified54.5

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

      [Start]54.5

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

      *-commutative [=>]54.5

      \[ \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\color{blue}{{y}^{2} \cdot 4}} \]

      unpow2 [=>]54.5

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

      associate-*r* [<=]54.5

      \[ \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\color{blue}{y \cdot \left(y \cdot 4\right)}} \]
    4. Applied egg-rr10.3

      \[\leadsto \color{blue}{\frac{x}{y} \cdot \frac{x}{y \cdot 4} - 1} \]

    if -1.15e119 < y < -1.7e-162 or 2.7e-157 < y < 4.8000000000000001e24 or 2.6000000000000001e63 < y < 2.59999999999999987e116

    1. Initial program 15.3

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

    if -1.7e-162 < y < 2.7e-157

    1. Initial program 30.4

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

      \[\leadsto \frac{\color{blue}{{x}^{2}}}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
    3. Simplified30.7

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

      [Start]30.7

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

      unpow2 [=>]30.7

      \[ \frac{\color{blue}{x \cdot x}}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
    4. Taylor expanded in x around inf 15.2

      \[\leadsto \color{blue}{1 + -4 \cdot \frac{{y}^{2}}{{x}^{2}}} \]
    5. Simplified7.4

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

      [Start]15.2

      \[ 1 + -4 \cdot \frac{{y}^{2}}{{x}^{2}} \]

      +-commutative [=>]15.2

      \[ \color{blue}{-4 \cdot \frac{{y}^{2}}{{x}^{2}} + 1} \]

      fma-def [=>]15.2

      \[ \color{blue}{\mathsf{fma}\left(-4, \frac{{y}^{2}}{{x}^{2}}, 1\right)} \]

      unpow2 [=>]15.2

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

      unpow2 [=>]15.2

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

      times-frac [=>]7.4

      \[ \mathsf{fma}\left(-4, \color{blue}{\frac{y}{x} \cdot \frac{y}{x}}, 1\right) \]
    6. Applied egg-rr7.4

      \[\leadsto \mathsf{fma}\left(-4, \color{blue}{\left(1 + {\left(\frac{y}{x}\right)}^{2}\right) - 1}, 1\right) \]
    7. Applied egg-rr7.4

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

    if 4.8000000000000001e24 < y < 2.6000000000000001e63

    1. Initial program 18.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 36.8

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.15 \cdot 10^{+119}:\\ \;\;\;\;\frac{x}{y} \cdot \frac{x}{y \cdot 4} + -1\\ \mathbf{elif}\;y \leq -1.7 \cdot 10^{-162}:\\ \;\;\;\;\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 2.7 \cdot 10^{-157}:\\ \;\;\;\;\mathsf{fma}\left(-4, 1 + \left({\left(\frac{y}{x}\right)}^{2} + -1\right), 1\right)\\ \mathbf{elif}\;y \leq 4.8 \cdot 10^{+24}:\\ \;\;\;\;\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 2.6 \cdot 10^{+63}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 2.6 \cdot 10^{+116}:\\ \;\;\;\;\frac{x \cdot x + y \cdot \left(y \cdot -4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y} \cdot \frac{x}{y \cdot 4} + -1\\ \end{array} \]

Alternatives

Alternative 1
Error12.5
Cost2008
\[\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 := \frac{x}{y} \cdot \frac{x}{y \cdot 4} + -1\\ \mathbf{if}\;y \leq -1.28 \cdot 10^{+122}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -4.3 \cdot 10^{-162}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.55 \cdot 10^{-158}:\\ \;\;\;\;1 + \frac{y}{x} \cdot \frac{y \cdot -4}{x}\\ \mathbf{elif}\;y \leq 6.6 \cdot 10^{+24}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 4.8 \cdot 10^{+63}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 2.2 \cdot 10^{+115}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error17.5
Cost1620
\[\begin{array}{l} t_0 := 1 + \frac{y}{x} \cdot \frac{y \cdot -4}{x}\\ t_1 := \frac{x}{y} \cdot \frac{x}{y \cdot 4} + -1\\ \mathbf{if}\;y \leq -750000000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 7.5 \cdot 10^{-157}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 4 \cdot 10^{-125}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 2.1 \cdot 10^{-41}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 6.6 \cdot 10^{+24}:\\ \;\;\;\;\frac{x \cdot x + y \cdot \left(y \cdot -4\right)}{y \cdot \left(y \cdot 4\right)}\\ \mathbf{elif}\;y \leq 5.2 \cdot 10^{+98}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error17.6
Cost1497
\[\begin{array}{l} t_0 := 1 + \frac{y}{x} \cdot \frac{y \cdot -4}{x}\\ t_1 := \frac{x}{y} \cdot \frac{x}{y \cdot 4} + -1\\ \mathbf{if}\;y \leq -2.6 \cdot 10^{+14}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 7.5 \cdot 10^{-157}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 3.8 \cdot 10^{-125}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 2.4 \cdot 10^{-43}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 6 \cdot 10^{+24} \lor \neg \left(y \leq 5.6 \cdot 10^{+98}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 4
Error17.8
Cost1232
\[\begin{array}{l} t_0 := 1 + \frac{y}{x} \cdot \frac{y \cdot -4}{x}\\ \mathbf{if}\;y \leq -42000000000000:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 7.5 \cdot 10^{-157}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 3.8 \cdot 10^{-125}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 1.3 \cdot 10^{-41}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 4.3 \cdot 10^{+24}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 1.5 \cdot 10^{+99}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
Alternative 5
Error18.0
Cost856
\[\begin{array}{l} \mathbf{if}\;y \leq -200000000000:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 10^{-157}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 4 \cdot 10^{-125}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 3 \cdot 10^{-43}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 6 \cdot 10^{+24}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 5.2 \cdot 10^{+98}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
Alternative 6
Error32.0
Cost64
\[-1 \]

Error

Reproduce?

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