Average Error: 31.4 → 0.0
Time: 6.1s
Precision: binary64
Cost: 14016
\[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
\[\frac{x}{\mathsf{fma}\left(4, y \cdot \frac{y}{x}, x\right)} - \frac{y}{\mathsf{fma}\left(0.25, x \cdot \frac{x}{y}, y\right)} \]
(FPCore (x y)
 :precision binary64
 (/ (- (* x x) (* (* y 4.0) y)) (+ (* x x) (* (* y 4.0) y))))
(FPCore (x y)
 :precision binary64
 (- (/ x (fma 4.0 (* y (/ y x)) x)) (/ 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) {
	return (x / fma(4.0, (y * (y / x)), x)) - (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)
	return Float64(Float64(x / fma(4.0, Float64(y * Float64(y / x)), x)) - 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_] := N[(N[(x / N[(4.0 * N[(y * N[(y / x), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision] - 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}
\frac{x}{\mathsf{fma}\left(4, y \cdot \frac{y}{x}, x\right)} - \frac{y}{\mathsf{fma}\left(0.25, x \cdot \frac{x}{y}, y\right)}

Error

Target

Original31.4
Target31.1
Herbie0.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 31.4

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

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

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

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

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

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

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

Alternatives

Alternative 1
Error13.2
Cost7752
\[\begin{array}{l} t_0 := y \cdot \left(4 \cdot y\right)\\ t_1 := x \cdot x - t_0\\ t_2 := \frac{t_1}{x \cdot x + t_0}\\ \mathbf{if}\;x \leq -5.93 \cdot 10^{+88}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq -1.5320056026564973 \cdot 10^{-159}:\\ \;\;\;\;\frac{t_1}{\mathsf{fma}\left(y, 4 \cdot y, x \cdot x\right)}\\ \mathbf{elif}\;x \leq 5.3338191846062035 \cdot 10^{-160}:\\ \;\;\;\;\mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\\ \mathbf{elif}\;x \leq 2.513118594758546 \cdot 10^{-38}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 1.3353366983569153 \cdot 10^{+24}:\\ \;\;\;\;-1 + 0.25 \cdot \frac{x}{y \cdot \frac{y}{x}}\\ \mathbf{elif}\;x \leq 7.7997048750057435 \cdot 10^{+56}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 2
Error13.2
Cost7372
\[\begin{array}{l} t_0 := y \cdot \left(4 \cdot y\right)\\ t_1 := \frac{x \cdot x - t_0}{x \cdot x + t_0}\\ \mathbf{if}\;x \leq -5.93 \cdot 10^{+88}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq -1.5320056026564973 \cdot 10^{-159}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 5.3338191846062035 \cdot 10^{-160}:\\ \;\;\;\;\mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\\ \mathbf{elif}\;x \leq 2.513118594758546 \cdot 10^{-38}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.3353366983569153 \cdot 10^{+24}:\\ \;\;\;\;-1 + 0.25 \cdot \frac{x}{y \cdot \frac{y}{x}}\\ \mathbf{elif}\;x \leq 7.7997048750057435 \cdot 10^{+56}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 3
Error13.3
Cost2008
\[\begin{array}{l} t_0 := -1 + 0.25 \cdot \frac{x}{y \cdot \frac{y}{x}}\\ t_1 := y \cdot \left(4 \cdot y\right)\\ t_2 := \frac{x \cdot x - t_1}{x \cdot x + t_1}\\ \mathbf{if}\;x \leq -5.93 \cdot 10^{+88}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq -1.5320056026564973 \cdot 10^{-159}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 5.3338191846062035 \cdot 10^{-160}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 2.513118594758546 \cdot 10^{-38}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 1.3353366983569153 \cdot 10^{+24}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 7.7997048750057435 \cdot 10^{+56}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 4
Error16.8
Cost1232
\[\begin{array}{l} t_0 := -1 + 0.25 \cdot \frac{x}{y \cdot \frac{y}{x}}\\ \mathbf{if}\;x \leq -7.704310578785128 \cdot 10^{-76}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 2.7474073122867355 \cdot 10^{-80}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 2.2869123131754153 \cdot 10^{-48}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 1.786843986601673 \cdot 10^{+25}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 5
Error16.8
Cost1232
\[\begin{array}{l} t_0 := -1 + 0.25 \cdot \frac{x}{y \cdot \frac{y}{x}}\\ \mathbf{if}\;x \leq -7.704310578785128 \cdot 10^{-76}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 2.7474073122867355 \cdot 10^{-80}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 2.2869123131754153 \cdot 10^{-48}:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + y \cdot \left(4 \cdot y\right)}\\ \mathbf{elif}\;x \leq 1.786843986601673 \cdot 10^{+25}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 6
Error17.0
Cost592
\[\begin{array}{l} \mathbf{if}\;x \leq -7.704310578785128 \cdot 10^{-76}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 2.7474073122867355 \cdot 10^{-80}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \leq 2.2869123131754153 \cdot 10^{-48}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 1.786843986601673 \cdot 10^{+25}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 7
Error31.6
Cost64
\[1 \]

Error

Reproduce

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