?

Average Error: 49.08% → 19.7%
Time: 12.8s
Precision: binary64
Cost: 7752

?

\[\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 := {\left(\frac{x}{y}\right)}^{2} \cdot 0.5 + -1\\ t_1 := x \cdot x + y \cdot \left(y \cdot 4\right)\\ \mathbf{if}\;y \leq -1.45 \cdot 10^{+123}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -6.5 \cdot 10^{-143}:\\ \;\;\;\;\frac{\mathsf{fma}\left(y, y \cdot -4, x \cdot x\right)}{t_1}\\ \mathbf{elif}\;y \leq 1.05 \cdot 10^{-35}:\\ \;\;\;\;1 + \frac{y}{x} \cdot \left(y \cdot \frac{-8}{x}\right)\\ \mathbf{elif}\;y \leq 2.5 \cdot 10^{+113}:\\ \;\;\;\;\frac{x \cdot x + y \cdot \left(y \cdot -4\right)}{t_1}\\ \mathbf{elif}\;y \leq 4.3 \cdot 10^{+133}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \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 (+ (* (pow (/ x y) 2.0) 0.5) -1.0))
        (t_1 (+ (* x x) (* y (* y 4.0)))))
   (if (<= y -1.45e+123)
     t_0
     (if (<= y -6.5e-143)
       (/ (fma y (* y -4.0) (* x x)) t_1)
       (if (<= y 1.05e-35)
         (+ 1.0 (* (/ y x) (* y (/ -8.0 x))))
         (if (<= y 2.5e+113)
           (/ (+ (* x x) (* y (* y -4.0))) t_1)
           (if (<= y 4.3e+133) 1.0 t_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 = (pow((x / y), 2.0) * 0.5) + -1.0;
	double t_1 = (x * x) + (y * (y * 4.0));
	double tmp;
	if (y <= -1.45e+123) {
		tmp = t_0;
	} else if (y <= -6.5e-143) {
		tmp = fma(y, (y * -4.0), (x * x)) / t_1;
	} else if (y <= 1.05e-35) {
		tmp = 1.0 + ((y / x) * (y * (-8.0 / x)));
	} else if (y <= 2.5e+113) {
		tmp = ((x * x) + (y * (y * -4.0))) / t_1;
	} else if (y <= 4.3e+133) {
		tmp = 1.0;
	} else {
		tmp = t_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 / y) ^ 2.0) * 0.5) + -1.0)
	t_1 = Float64(Float64(x * x) + Float64(y * Float64(y * 4.0)))
	tmp = 0.0
	if (y <= -1.45e+123)
		tmp = t_0;
	elseif (y <= -6.5e-143)
		tmp = Float64(fma(y, Float64(y * -4.0), Float64(x * x)) / t_1);
	elseif (y <= 1.05e-35)
		tmp = Float64(1.0 + Float64(Float64(y / x) * Float64(y * Float64(-8.0 / x))));
	elseif (y <= 2.5e+113)
		tmp = Float64(Float64(Float64(x * x) + Float64(y * Float64(y * -4.0))) / t_1);
	elseif (y <= 4.3e+133)
		tmp = 1.0;
	else
		tmp = t_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[Power[N[(x / y), $MachinePrecision], 2.0], $MachinePrecision] * 0.5), $MachinePrecision] + -1.0), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x * x), $MachinePrecision] + N[(y * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.45e+123], t$95$0, If[LessEqual[y, -6.5e-143], N[(N[(y * N[(y * -4.0), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision] / t$95$1), $MachinePrecision], If[LessEqual[y, 1.05e-35], N[(1.0 + N[(N[(y / x), $MachinePrecision] * N[(y * N[(-8.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.5e+113], N[(N[(N[(x * x), $MachinePrecision] + N[(y * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / t$95$1), $MachinePrecision], If[LessEqual[y, 4.3e+133], 1.0, t$95$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 := {\left(\frac{x}{y}\right)}^{2} \cdot 0.5 + -1\\
t_1 := x \cdot x + y \cdot \left(y \cdot 4\right)\\
\mathbf{if}\;y \leq -1.45 \cdot 10^{+123}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;y \leq -6.5 \cdot 10^{-143}:\\
\;\;\;\;\frac{\mathsf{fma}\left(y, y \cdot -4, x \cdot x\right)}{t_1}\\

\mathbf{elif}\;y \leq 1.05 \cdot 10^{-35}:\\
\;\;\;\;1 + \frac{y}{x} \cdot \left(y \cdot \frac{-8}{x}\right)\\

\mathbf{elif}\;y \leq 2.5 \cdot 10^{+113}:\\
\;\;\;\;\frac{x \cdot x + y \cdot \left(y \cdot -4\right)}{t_1}\\

\mathbf{elif}\;y \leq 4.3 \cdot 10^{+133}:\\
\;\;\;\;1\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}

Error?

Target

Original49.08%
Target48.62%
Herbie19.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 5 regimes
  2. if y < -1.45000000000000005e123 or 4.29999999999999994e133 < y

    1. Initial program 89.25

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

      \[\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)}} \]
      Proof

      [Start]89.25

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

      cancel-sign-sub-inv [=>]89.25

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

      +-commutative [=>]89.25

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

      *-commutative [=>]89.25

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

      fma-def [=>]89.25

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

      distribute-rgt-neg-in [=>]89.25

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

      metadata-eval [=>]89.25

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

      fma-def [=>]89.25

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

      *-commutative [=>]89.25

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

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

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

      [Start]26

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

      associate--r+ [=>]26

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

      distribute-rgt-out-- [=>]26

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

      metadata-eval [=>]26

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

      fma-neg [=>]26

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

      unpow2 [=>]26

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

      unpow2 [=>]26

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

      times-frac [=>]14.5

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

      metadata-eval [=>]14.5

      \[ \mathsf{fma}\left(\frac{x}{y} \cdot \frac{x}{y}, 0.5, \color{blue}{-1}\right) \]
    5. Applied egg-rr14.5

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

    if -1.45000000000000005e123 < y < -6.4999999999999999e-143

    1. Initial program 22.7

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

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

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

      [Start]22.7

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

      unpow2 [=>]22.7

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

      *-commutative [=>]22.7

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

      unpow2 [=>]22.7

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

      associate-*r* [<=]22.7

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

      fma-def [=>]22.7

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

    if -6.4999999999999999e-143 < y < 1.05e-35

    1. Initial program 41.12

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
    2. Applied egg-rr42.84

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

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

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

      [Start]25.99

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

      mul-1-neg [=>]25.99

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

      unsub-neg [=>]25.99

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

      distribute-rgt-out-- [=>]25.99

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

      metadata-eval [=>]25.99

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

      unpow2 [=>]25.99

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

      associate-/l* [=>]26.09

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

      unpow2 [=>]26.09

      \[ 1 - \frac{\color{blue}{y \cdot y}}{\frac{x \cdot x}{8}} \]
    5. Applied egg-rr18.2

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

    if 1.05e-35 < y < 2.5e113

    1. Initial program 25.18

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

    if 2.5e113 < y < 4.29999999999999994e133

    1. Initial program 27.75

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.45 \cdot 10^{+123}:\\ \;\;\;\;{\left(\frac{x}{y}\right)}^{2} \cdot 0.5 + -1\\ \mathbf{elif}\;y \leq -6.5 \cdot 10^{-143}:\\ \;\;\;\;\frac{\mathsf{fma}\left(y, y \cdot -4, x \cdot x\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{elif}\;y \leq 1.05 \cdot 10^{-35}:\\ \;\;\;\;1 + \frac{y}{x} \cdot \left(y \cdot \frac{-8}{x}\right)\\ \mathbf{elif}\;y \leq 2.5 \cdot 10^{+113}:\\ \;\;\;\;\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 4.3 \cdot 10^{+133}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;{\left(\frac{x}{y}\right)}^{2} \cdot 0.5 + -1\\ \end{array} \]

Alternatives

Alternative 1
Error19.71%
Cost7572
\[\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 := {\left(\frac{x}{y}\right)}^{2} \cdot 0.5 + -1\\ \mathbf{if}\;y \leq -1.85 \cdot 10^{+124}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -7.5 \cdot 10^{-143}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.15 \cdot 10^{-35}:\\ \;\;\;\;1 + \frac{y}{x} \cdot \left(y \cdot \frac{-8}{x}\right)\\ \mathbf{elif}\;y \leq 1.35 \cdot 10^{+113}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 4.3 \cdot 10^{+133}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error19.9%
Cost1744
\[\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 -8.8 \cdot 10^{+123}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq -5 \cdot 10^{-143}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 2.6 \cdot 10^{-36}:\\ \;\;\;\;1 + \frac{y}{x} \cdot \left(y \cdot \frac{-8}{x}\right)\\ \mathbf{elif}\;y \leq 2.5 \cdot 10^{+113}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 4.3 \cdot 10^{+133}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1 + \frac{0.5 \cdot \frac{x}{\frac{y}{x}}}{y}\\ \end{array} \]
Alternative 3
Error26.4%
Cost1233
\[\begin{array}{l} t_0 := -1 + \frac{0.5 \cdot \frac{x}{\frac{y}{x}}}{y}\\ \mathbf{if}\;y \leq -7.8 \cdot 10^{-101}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 6.9 \cdot 10^{-12}:\\ \;\;\;\;1 + \frac{y}{x} \cdot \frac{y \cdot -4}{x}\\ \mathbf{elif}\;y \leq 2.5 \cdot 10^{+113} \lor \neg \left(y \leq 4.4 \cdot 10^{+133}\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 4
Error26.2%
Cost1233
\[\begin{array}{l} t_0 := -1 + \frac{0.5 \cdot \frac{x}{\frac{y}{x}}}{y}\\ \mathbf{if}\;y \leq -7.8 \cdot 10^{-101}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 0.027:\\ \;\;\;\;1 + \frac{y}{x} \cdot \left(y \cdot \frac{-8}{x}\right)\\ \mathbf{elif}\;y \leq 2.5 \cdot 10^{+113} \lor \neg \left(y \leq 4.3 \cdot 10^{+133}\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 5
Error26.87%
Cost968
\[\begin{array}{l} \mathbf{if}\;y \leq -5.1 \cdot 10^{-101}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 4.3 \cdot 10^{-19}:\\ \;\;\;\;1 + \frac{y}{x} \cdot \frac{y \cdot -4}{x}\\ \mathbf{elif}\;y \leq 2.5 \cdot 10^{+113}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 4.3 \cdot 10^{+133}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
Alternative 6
Error26.82%
Cost592
\[\begin{array}{l} \mathbf{if}\;y \leq -5.6 \cdot 10^{-96}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 5 \cdot 10^{-19}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 2.5 \cdot 10^{+113}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 4.3 \cdot 10^{+133}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
Alternative 7
Error49.61%
Cost64
\[-1 \]

Error

Reproduce?

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