?

Average Accuracy: 50.4% → 80.6%
Time: 10.0s
Precision: binary64
Cost: 20164

?

\[\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 := y \cdot \left(y \cdot 4\right)\\ \mathbf{if}\;t_0 \leq 10^{-231}:\\ \;\;\;\;{\left(\sqrt[3]{{\left(\frac{y}{x}\right)}^{2} \cdot -4 + 1}\right)}^{3}\\ \mathbf{elif}\;t_0 \leq 5 \cdot 10^{+244}:\\ \;\;\;\;\frac{x \cdot x + y \cdot \left(y \cdot -4\right)}{t_0 + x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(0.25, \left(1 + {\left(\frac{x}{y}\right)}^{2}\right) + -1, -1\right)\\ \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 (* y (* y 4.0))))
   (if (<= t_0 1e-231)
     (pow (cbrt (+ (* (pow (/ y x) 2.0) -4.0) 1.0)) 3.0)
     (if (<= t_0 5e+244)
       (/ (+ (* x x) (* y (* y -4.0))) (+ t_0 (* x x)))
       (fma 0.25 (+ (+ 1.0 (pow (/ x y) 2.0)) -1.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 = y * (y * 4.0);
	double tmp;
	if (t_0 <= 1e-231) {
		tmp = pow(cbrt(((pow((y / x), 2.0) * -4.0) + 1.0)), 3.0);
	} else if (t_0 <= 5e+244) {
		tmp = ((x * x) + (y * (y * -4.0))) / (t_0 + (x * x));
	} else {
		tmp = fma(0.25, ((1.0 + pow((x / y), 2.0)) + -1.0), -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(y * Float64(y * 4.0))
	tmp = 0.0
	if (t_0 <= 1e-231)
		tmp = cbrt(Float64(Float64((Float64(y / x) ^ 2.0) * -4.0) + 1.0)) ^ 3.0;
	elseif (t_0 <= 5e+244)
		tmp = Float64(Float64(Float64(x * x) + Float64(y * Float64(y * -4.0))) / Float64(t_0 + Float64(x * x)));
	else
		tmp = fma(0.25, Float64(Float64(1.0 + (Float64(x / y) ^ 2.0)) + -1.0), -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[(y * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 1e-231], N[Power[N[Power[N[(N[(N[Power[N[(y / x), $MachinePrecision], 2.0], $MachinePrecision] * -4.0), $MachinePrecision] + 1.0), $MachinePrecision], 1/3], $MachinePrecision], 3.0], $MachinePrecision], If[LessEqual[t$95$0, 5e+244], N[(N[(N[(x * x), $MachinePrecision] + N[(y * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(t$95$0 + N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.25 * N[(N[(1.0 + N[Power[N[(x / y), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision] + -1.0), $MachinePrecision]]]]
\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 := y \cdot \left(y \cdot 4\right)\\
\mathbf{if}\;t_0 \leq 10^{-231}:\\
\;\;\;\;{\left(\sqrt[3]{{\left(\frac{y}{x}\right)}^{2} \cdot -4 + 1}\right)}^{3}\\

\mathbf{elif}\;t_0 \leq 5 \cdot 10^{+244}:\\
\;\;\;\;\frac{x \cdot x + y \cdot \left(y \cdot -4\right)}{t_0 + x \cdot x}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.25, \left(1 + {\left(\frac{x}{y}\right)}^{2}\right) + -1, -1\right)\\


\end{array}

Error?

Target

Original50.4%
Target50.7%
Herbie80.6%
\[\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 (*.f64 (*.f64 y 4) y) < 9.9999999999999999e-232

    1. Initial program 58.1%

      \[\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 51.0%

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

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

      [Start]51.0

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

      unpow2 [=>]51.0

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

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

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

      [Start]74.9

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

      associate-*r/ [=>]74.9

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

      unpow2 [=>]74.9

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

      unpow2 [=>]74.9

      \[ 1 + \frac{-4 \cdot \left(y \cdot y\right)}{\color{blue}{x \cdot x}} \]
    6. Applied egg-rr84.1%

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

      [Start]74.9

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

      associate-*r* [=>]74.9

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

      times-frac [=>]84.1

      \[ 1 + \color{blue}{\frac{-4 \cdot y}{x} \cdot \frac{y}{x}} \]
    7. Applied egg-rr84.1%

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

      [Start]84.1

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

      add-cube-cbrt [=>]84.1

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

      pow3 [=>]84.1

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

      +-commutative [=>]84.1

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

      clear-num [=>]84.1

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

      associate-*l/ [=>]84.1

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

      *-un-lft-identity [<=]84.1

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

      associate-/l/ [<=]84.1

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

      associate-/r/ [=>]84.1

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

      un-div-inv [<=]84.1

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

      clear-num [<=]84.1

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

      pow2 [=>]84.1

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

    if 9.9999999999999999e-232 < (*.f64 (*.f64 y 4) y) < 5.00000000000000022e244

    1. Initial program 74.8%

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

    if 5.00000000000000022e244 < (*.f64 (*.f64 y 4) y)

    1. Initial program 11.3%

      \[\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 10.9%

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

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

      [Start]10.9

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

      *-commutative [=>]10.9

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

      unpow2 [=>]10.9

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

      associate-*r* [<=]10.9

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

      \[\leadsto \color{blue}{0.25 \cdot \frac{{x}^{2}}{{y}^{2}} - 1} \]
    5. Simplified84.2%

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

      [Start]72.8

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

      fma-neg [=>]72.8

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

      unpow2 [=>]72.8

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

      unpow2 [=>]72.8

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

      times-frac [=>]84.2

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

      metadata-eval [=>]84.2

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

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

      [Start]84.2

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

      expm1-log1p-u [=>]84.2

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

      expm1-udef [=>]84.2

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

      log1p-udef [=>]84.2

      \[ \mathsf{fma}\left(0.25, e^{\color{blue}{\log \left(1 + \frac{x}{y} \cdot \frac{x}{y}\right)}} - 1, -1\right) \]

      add-exp-log [<=]84.2

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

      pow2 [=>]84.2

      \[ \mathsf{fma}\left(0.25, \left(1 + \color{blue}{{\left(\frac{x}{y}\right)}^{2}}\right) - 1, -1\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification80.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \cdot \left(y \cdot 4\right) \leq 10^{-231}:\\ \;\;\;\;{\left(\sqrt[3]{{\left(\frac{y}{x}\right)}^{2} \cdot -4 + 1}\right)}^{3}\\ \mathbf{elif}\;y \cdot \left(y \cdot 4\right) \leq 5 \cdot 10^{+244}:\\ \;\;\;\;\frac{x \cdot x + y \cdot \left(y \cdot -4\right)}{y \cdot \left(y \cdot 4\right) + x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(0.25, \left(1 + {\left(\frac{x}{y}\right)}^{2}\right) + -1, -1\right)\\ \end{array} \]

Alternatives

Alternative 1
Accuracy80.6%
Cost14216
\[\begin{array}{l} t_0 := y \cdot \left(y \cdot 4\right)\\ \mathbf{if}\;t_0 \leq 10^{-231}:\\ \;\;\;\;-1 + \left(2 + {\left(\frac{y}{x}\right)}^{2} \cdot -4\right)\\ \mathbf{elif}\;t_0 \leq 5 \cdot 10^{+244}:\\ \;\;\;\;\frac{x \cdot x + y \cdot \left(y \cdot -4\right)}{t_0 + x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(0.25, \left(1 + {\left(\frac{x}{y}\right)}^{2}\right) + -1, -1\right)\\ \end{array} \]
Alternative 2
Accuracy80.6%
Cost7752
\[\begin{array}{l} t_0 := y \cdot \left(y \cdot 4\right)\\ \mathbf{if}\;t_0 \leq 10^{-231}:\\ \;\;\;\;1 + \frac{y}{x} \cdot \frac{y \cdot -4}{x}\\ \mathbf{elif}\;t_0 \leq 5 \cdot 10^{+244}:\\ \;\;\;\;\frac{x \cdot x + y \cdot \left(y \cdot -4\right)}{t_0 + x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(0.25, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\\ \end{array} \]
Alternative 3
Accuracy80.6%
Cost7752
\[\begin{array}{l} t_0 := y \cdot \left(y \cdot 4\right)\\ \mathbf{if}\;t_0 \leq 10^{-231}:\\ \;\;\;\;-1 + \left(2 + {\left(\frac{y}{x}\right)}^{2} \cdot -4\right)\\ \mathbf{elif}\;t_0 \leq 5 \cdot 10^{+244}:\\ \;\;\;\;\frac{x \cdot x + y \cdot \left(y \cdot -4\right)}{t_0 + x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(0.25, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\\ \end{array} \]
Alternative 4
Accuracy80.4%
Cost1992
\[\begin{array}{l} t_0 := y \cdot \left(y \cdot 4\right)\\ \mathbf{if}\;t_0 \leq 10^{-231}:\\ \;\;\;\;1 + \frac{y}{x} \cdot \frac{y \cdot -4}{x}\\ \mathbf{elif}\;t_0 \leq 5 \cdot 10^{+244}:\\ \;\;\;\;\frac{x \cdot x + y \cdot \left(y \cdot -4\right)}{t_0 + x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
Alternative 5
Accuracy74.2%
Cost968
\[\begin{array}{l} \mathbf{if}\;y \leq -2.45 \cdot 10^{-5}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 7.5 \cdot 10^{+63}:\\ \;\;\;\;1 + \frac{y}{x} \cdot \frac{y \cdot -4}{x}\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
Alternative 6
Accuracy74.2%
Cost328
\[\begin{array}{l} \mathbf{if}\;y \leq -1.4 \cdot 10^{-5}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 1.05 \cdot 10^{+25}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
Alternative 7
Accuracy50.2%
Cost64
\[-1 \]

Error

Reproduce?

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