?

Average Accuracy: 48.9% → 77.2%
Time: 10.5s
Precision: binary64
Cost: 7636

?

\[\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)\\ t_1 := \mathsf{fma}\left(\frac{y}{x} \cdot \frac{y}{x}, -8, 1\right)\\ t_2 := \mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\\ t_3 := \frac{x \cdot x - t_0}{x \cdot x + t_0}\\ \mathbf{if}\;x \leq -9.5 \cdot 10^{+100}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -2.5 \cdot 10^{-109}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq 5.2 \cdot 10^{-146}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 8.5 \cdot 10^{-76}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq 4.6 \cdot 10^{+58}:\\ \;\;\;\;t_2\\ \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 (* y (* y 4.0)))
        (t_1 (fma (* (/ y x) (/ y x)) -8.0 1.0))
        (t_2 (fma 0.5 (* (/ x y) (/ x y)) -1.0))
        (t_3 (/ (- (* x x) t_0) (+ (* x x) t_0))))
   (if (<= x -9.5e+100)
     t_1
     (if (<= x -2.5e-109)
       t_3
       (if (<= x 5.2e-146)
         t_2
         (if (<= x 8.5e-76) t_3 (if (<= x 4.6e+58) t_2 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 = y * (y * 4.0);
	double t_1 = fma(((y / x) * (y / x)), -8.0, 1.0);
	double t_2 = fma(0.5, ((x / y) * (x / y)), -1.0);
	double t_3 = ((x * x) - t_0) / ((x * x) + t_0);
	double tmp;
	if (x <= -9.5e+100) {
		tmp = t_1;
	} else if (x <= -2.5e-109) {
		tmp = t_3;
	} else if (x <= 5.2e-146) {
		tmp = t_2;
	} else if (x <= 8.5e-76) {
		tmp = t_3;
	} else if (x <= 4.6e+58) {
		tmp = t_2;
	} 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(y * Float64(y * 4.0))
	t_1 = fma(Float64(Float64(y / x) * Float64(y / x)), -8.0, 1.0)
	t_2 = fma(0.5, Float64(Float64(x / y) * Float64(x / y)), -1.0)
	t_3 = Float64(Float64(Float64(x * x) - t_0) / Float64(Float64(x * x) + t_0))
	tmp = 0.0
	if (x <= -9.5e+100)
		tmp = t_1;
	elseif (x <= -2.5e-109)
		tmp = t_3;
	elseif (x <= 5.2e-146)
		tmp = t_2;
	elseif (x <= 8.5e-76)
		tmp = t_3;
	elseif (x <= 4.6e+58)
		tmp = t_2;
	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[(y * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(y / x), $MachinePrecision] * N[(y / x), $MachinePrecision]), $MachinePrecision] * -8.0 + 1.0), $MachinePrecision]}, Block[{t$95$2 = N[(0.5 * N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]}, Block[{t$95$3 = N[(N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -9.5e+100], t$95$1, If[LessEqual[x, -2.5e-109], t$95$3, If[LessEqual[x, 5.2e-146], t$95$2, If[LessEqual[x, 8.5e-76], t$95$3, If[LessEqual[x, 4.6e+58], t$95$2, 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 := y \cdot \left(y \cdot 4\right)\\
t_1 := \mathsf{fma}\left(\frac{y}{x} \cdot \frac{y}{x}, -8, 1\right)\\
t_2 := \mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\\
t_3 := \frac{x \cdot x - t_0}{x \cdot x + t_0}\\
\mathbf{if}\;x \leq -9.5 \cdot 10^{+100}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;x \leq -2.5 \cdot 10^{-109}:\\
\;\;\;\;t_3\\

\mathbf{elif}\;x \leq 5.2 \cdot 10^{-146}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;x \leq 8.5 \cdot 10^{-76}:\\
\;\;\;\;t_3\\

\mathbf{elif}\;x \leq 4.6 \cdot 10^{+58}:\\
\;\;\;\;t_2\\

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


\end{array}

Error?

Target

Original48.9%
Target49.4%
Herbie77.2%
\[\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 x < -9.4999999999999995e100 or 4.60000000000000005e58 < x

    1. Initial program 27.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 inf 71.7%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{y}{x} \cdot \frac{y}{x}, -8, 1\right)} \]
      Step-by-step derivation

      [Start]71.7

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

      associate--l+ [=>]71.7

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

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

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

      metadata-eval [=>]71.7

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

      *-commutative [<=]71.7

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

      +-commutative [<=]71.7

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

      *-commutative [=>]71.7

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

      fma-def [=>]71.7

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

      unpow2 [=>]71.7

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

      unpow2 [=>]71.7

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

      times-frac [=>]80.6

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

    if -9.4999999999999995e100 < x < -2.5000000000000001e-109 or 5.19999999999999974e-146 < x < 8.50000000000000038e-76

    1. Initial program 87.0%

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

    if -2.5000000000000001e-109 < x < 5.19999999999999974e-146 or 8.50000000000000038e-76 < x < 4.60000000000000005e58

    1. Initial program 55.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 74.6%

      \[\leadsto \color{blue}{0.5 \cdot \frac{{x}^{2}}{{y}^{2}} - 1} \]
    3. Simplified85.8%

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

      [Start]74.6

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

      fma-neg [=>]74.6

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

      unpow2 [=>]74.6

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

      unpow2 [=>]74.6

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

      times-frac [=>]85.8

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

      metadata-eval [=>]85.8

      \[ \mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, \color{blue}{-1}\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification84.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -9.5 \cdot 10^{+100}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{x} \cdot \frac{y}{x}, -8, 1\right)\\ \mathbf{elif}\;x \leq -2.5 \cdot 10^{-109}:\\ \;\;\;\;\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{elif}\;x \leq 5.2 \cdot 10^{-146}:\\ \;\;\;\;\mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\\ \mathbf{elif}\;x \leq 8.5 \cdot 10^{-76}:\\ \;\;\;\;\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{elif}\;x \leq 4.6 \cdot 10^{+58}:\\ \;\;\;\;\mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{x} \cdot \frac{y}{x}, -8, 1\right)\\ \end{array} \]

Alternatives

Alternative 1
Accuracy77.0%
Cost7636
\[\begin{array}{l} t_0 := y \cdot \left(y \cdot 4\right)\\ t_1 := \frac{x \cdot x - t_0}{x \cdot x + t_0}\\ t_2 := 1 + \frac{\frac{y}{\frac{x}{y}} \cdot -4}{x}\\ t_3 := \mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\\ \mathbf{if}\;x \leq -2 \cdot 10^{+105}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -8.2 \cdot 10^{-109}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3.8 \cdot 10^{-143}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq 8.5 \cdot 10^{-76}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 4.6 \cdot 10^{+58}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 2
Accuracy79.0%
Cost2008
\[\begin{array}{l} t_0 := y \cdot \left(y \cdot 4\right)\\ t_1 := \frac{x \cdot x - t_0}{x \cdot x + t_0}\\ t_2 := \frac{y}{\frac{x}{y}}\\ t_3 := -1 + \frac{x}{4 \cdot t_2}\\ t_4 := 1 + \frac{t_2 \cdot -4}{x}\\ \mathbf{if}\;y \leq -4.8 \cdot 10^{+95}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq -1 \cdot 10^{-119}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 7.8 \cdot 10^{-182}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;y \leq 4.2 \cdot 10^{-162}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 7.4 \cdot 10^{-80}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;y \leq 2.25 \cdot 10^{+64}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 3
Accuracy78.9%
Cost2008
\[\begin{array}{l} t_0 := y \cdot \left(y \cdot 4\right)\\ t_1 := \frac{x \cdot x - t_0}{x \cdot x + t_0}\\ t_2 := \frac{y}{\frac{x}{y}}\\ t_3 := -1 + \frac{x}{4 \cdot t_2}\\ t_4 := \frac{y \cdot \left(y \cdot -4\right)}{x \cdot x}\\ \mathbf{if}\;y \leq -3.6 \cdot 10^{+96}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq -2.8 \cdot 10^{-120}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 7.8 \cdot 10^{-182}:\\ \;\;\;\;1 + \frac{t_2 \cdot -4}{x}\\ \mathbf{elif}\;y \leq 1.6 \cdot 10^{-160}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 4.4 \cdot 10^{-80}:\\ \;\;\;\;t_4 + \left(1 + t_4\right)\\ \mathbf{elif}\;y \leq 2.25 \cdot 10^{+64}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 4
Accuracy73.4%
Cost1484
\[\begin{array}{l} \mathbf{if}\;x \cdot x \leq 5 \cdot 10^{-55}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \leq 5 \cdot 10^{+31}:\\ \;\;\;\;1 + -4 \cdot \frac{y \cdot y}{x \cdot x}\\ \mathbf{elif}\;x \cdot x \leq 4 \cdot 10^{+121}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;1 + \frac{\frac{y}{\frac{x}{y}} \cdot -4}{x}\\ \end{array} \]
Alternative 5
Accuracy73.6%
Cost1484
\[\begin{array}{l} t_0 := \frac{y}{\frac{x}{y}}\\ t_1 := -1 + \frac{x}{4 \cdot t_0}\\ \mathbf{if}\;x \cdot x \leq 10^{-32}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \cdot x \leq 10^{+23}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \cdot x \leq 4 \cdot 10^{+121}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;1 + \frac{t_0 \cdot -4}{x}\\ \end{array} \]
Alternative 6
Accuracy73.7%
Cost1484
\[\begin{array}{l} t_0 := \frac{y}{\frac{x}{y}}\\ t_1 := -1 + \frac{x}{4 \cdot t_0}\\ \mathbf{if}\;x \cdot x \leq 10^{-32}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \cdot x \leq 10^{+23}:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{elif}\;x \cdot x \leq 4 \cdot 10^{+121}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;1 + \frac{t_0 \cdot -4}{x}\\ \end{array} \]
Alternative 7
Accuracy73.3%
Cost1224
\[\begin{array}{l} \mathbf{if}\;x \cdot x \leq 8.6 \cdot 10^{-50}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \leq 6 \cdot 10^{+31}:\\ \;\;\;\;1 + -4 \cdot \frac{y \cdot y}{x \cdot x}\\ \mathbf{elif}\;x \cdot x \leq 2.6 \cdot 10^{+121}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 8
Accuracy73.3%
Cost328
\[\begin{array}{l} \mathbf{if}\;x \leq -2 \cdot 10^{-26}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 8.2 \cdot 10^{+58}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 9
Accuracy50.4%
Cost64
\[-1 \]

Error

Reproduce?

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