?

Average Accuracy: 50.6% → 100.0%
Time: 12.6s
Precision: binary64
Cost: 27008.00

?

\[\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}{\mathsf{hypot}\left(x, y \cdot 2\right)}\\ \mathsf{fma}\left(t_0, t_0, \frac{-y}{\mathsf{fma}\left(0.25, x \cdot \frac{x}{y}, y\right)}\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 (/ x (hypot x (* y 2.0)))))
   (fma t_0 t_0 (/ (- y) (fma 0.25 (* x (/ x y)) y)))))
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 / hypot(x, (y * 2.0));
	return fma(t_0, t_0, (-y / fma(0.25, (x * (x / y)), y)));
}
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(x / hypot(x, Float64(y * 2.0)))
	return fma(t_0, t_0, Float64(Float64(-y) / fma(0.25, Float64(x * Float64(x / y)), y)))
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[(x / N[Sqrt[x ^ 2 + N[(y * 2.0), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]}, N[(t$95$0 * t$95$0 + N[((-y) / N[(0.25 * N[(x * N[(x / y), $MachinePrecision]), $MachinePrecision] + y), $MachinePrecision]), $MachinePrecision]), $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 := \frac{x}{\mathsf{hypot}\left(x, y \cdot 2\right)}\\
\mathsf{fma}\left(t_0, t_0, \frac{-y}{\mathsf{fma}\left(0.25, x \cdot \frac{x}{y}, y\right)}\right)
\end{array}

Error?

Target

Original50.6%
Target51.1%
Herbie100.0%
\[\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. Initial program 50.6%

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

    \[\leadsto \color{blue}{\frac{x \cdot x}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)} + \left(-\frac{y \cdot 4}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)} \cdot y\right)} \]
  3. Simplified51.1%

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

    [Start]51.0

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

    sub-neg [<=]51.0

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

    associate-*l/ [=>]50.6

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

    *-commutative [<=]50.6

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

    associate-/l* [=>]51.1

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

    \[\leadsto \frac{x \cdot x}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)} - \frac{y}{\color{blue}{0.25 \cdot \frac{{x}^{2}}{y} + y}} \]
  5. Simplified69.6%

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

    [Start]69.6

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

    fma-def [=>]69.6

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

    unpow2 [=>]69.6

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{x}{\mathsf{hypot}\left(x, y \cdot 2\right)}, \frac{x}{\mathsf{hypot}\left(x, y \cdot 2\right)}, \frac{-y}{\mathsf{fma}\left(0.25, \frac{x}{y} \cdot x, y\right)}\right)} \]
  7. Final simplification100.0%

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

Alternatives

Alternative 1
Accuracy100.0%
Cost20672.00
\[\begin{array}{l} t_0 := \mathsf{hypot}\left(x, y \cdot 2\right)\\ \frac{\frac{x}{t_0}}{\frac{t_0}{x}} - \frac{y}{\mathsf{fma}\left(0.25, x \cdot \frac{x}{y}, y\right)} \end{array} \]
Alternative 2
Accuracy80.4%
Cost14024.00
\[\begin{array}{l} t_0 := y \cdot \left(y \cdot 4\right)\\ \mathbf{if}\;x \leq -6.8 \cdot 10^{+146}:\\ \;\;\;\;1 + \frac{y \cdot -4}{x} \cdot \frac{y}{x}\\ \mathbf{elif}\;x \leq -3.85 \cdot 10^{-103}:\\ \;\;\;\;\frac{\mathsf{fma}\left(x, x, -4 \cdot \left(y \cdot y\right)\right)}{\mathsf{fma}\left(x, x, t_0\right)}\\ \mathbf{elif}\;x \leq 1.65 \cdot 10^{-170}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \leq 2.15 \cdot 10^{+105}:\\ \;\;\;\;\frac{x \cdot x + y \cdot \left(y \cdot -4\right)}{x \cdot x + t_0}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{x} \cdot \frac{y}{x}, -8, 1\right)\\ \end{array} \]
Alternative 3
Accuracy100.0%
Cost14016.00
\[{\left(\frac{x}{\mathsf{hypot}\left(x, y \cdot 2\right)}\right)}^{2} + \frac{y}{\frac{x}{y} \cdot \left(x \cdot -0.25\right) - y} \]
Alternative 4
Accuracy80.4%
Cost7504.00
\[\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}\;x \leq -4.9 \cdot 10^{+144}:\\ \;\;\;\;1 + \frac{y \cdot -4}{x} \cdot \frac{y}{x}\\ \mathbf{elif}\;x \leq -3.7 \cdot 10^{-103}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1.65 \cdot 10^{-170}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \leq 2.25 \cdot 10^{+105}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{x} \cdot \frac{y}{x}, -8, 1\right)\\ \end{array} \]
Alternative 5
Accuracy80.3%
Cost1744.00
\[\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 := 1 + \frac{y \cdot -4}{x} \cdot \frac{y}{x}\\ \mathbf{if}\;x \leq -3.6 \cdot 10^{+144}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -4.3 \cdot 10^{-103}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1.65 \cdot 10^{-170}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \leq 1.8 \cdot 10^{+108}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Accuracy72.2%
Cost1234.00
\[\begin{array}{l} \mathbf{if}\;x \leq -9.5 \cdot 10^{+32} \lor \neg \left(x \leq 4.9 \cdot 10^{-176}\right) \land \left(x \leq 2.1 \cdot 10^{-123} \lor \neg \left(x \leq 3.2 \cdot 10^{+23}\right)\right):\\ \;\;\;\;1 + \frac{y \cdot -4}{x} \cdot \frac{y}{x}\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
Alternative 7
Accuracy72.6%
Cost1232.00
\[\begin{array}{l} t_0 := 1 + \frac{y \cdot -4}{x} \cdot \frac{y}{x}\\ \mathbf{if}\;x \leq -9.5 \cdot 10^{+32}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1.32 \cdot 10^{-157}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \leq 1.85 \cdot 10^{-112}:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{elif}\;x \leq 3.6 \cdot 10^{+23}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 8
Accuracy71.9%
Cost592.00
\[\begin{array}{l} \mathbf{if}\;x \leq -9.5 \cdot 10^{+32}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 4.9 \cdot 10^{-176}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \leq 2.1 \cdot 10^{-123}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 3.3 \cdot 10^{+23}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 9
Accuracy50.7%
Cost64.00
\[-1 \]

Error

Reproduce?

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