| Alternative 1 | |
|---|---|
| Error | 12.3 |
| Cost | 8528 |
(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 (+ (* x x) (* y (* y -4.0)))))
(if (<= t_0 2e-289)
(+ 1.0 (/ (/ y x) (/ x (* y -8.0))))
(if (<= t_0 4e-89)
(/ t_1 (fma x x t_0))
(if (<= t_0 5e-36)
(+ 1.0 (* (* y -8.0) (/ y (* x x))))
(if (<= t_0 2e+228)
(/ t_1 (+ t_0 (* x x)))
(fma 0.5 (* (/ x y) (/ x y)) -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 t_1 = (x * x) + (y * (y * -4.0));
double tmp;
if (t_0 <= 2e-289) {
tmp = 1.0 + ((y / x) / (x / (y * -8.0)));
} else if (t_0 <= 4e-89) {
tmp = t_1 / fma(x, x, t_0);
} else if (t_0 <= 5e-36) {
tmp = 1.0 + ((y * -8.0) * (y / (x * x)));
} else if (t_0 <= 2e+228) {
tmp = t_1 / (t_0 + (x * x));
} else {
tmp = fma(0.5, ((x / y) * (x / y)), -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)) t_1 = Float64(Float64(x * x) + Float64(y * Float64(y * -4.0))) tmp = 0.0 if (t_0 <= 2e-289) tmp = Float64(1.0 + Float64(Float64(y / x) / Float64(x / Float64(y * -8.0)))); elseif (t_0 <= 4e-89) tmp = Float64(t_1 / fma(x, x, t_0)); elseif (t_0 <= 5e-36) tmp = Float64(1.0 + Float64(Float64(y * -8.0) * Float64(y / Float64(x * x)))); elseif (t_0 <= 2e+228) tmp = Float64(t_1 / Float64(t_0 + Float64(x * x))); else tmp = fma(0.5, Float64(Float64(x / y) * Float64(x / y)), -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]}, Block[{t$95$1 = N[(N[(x * x), $MachinePrecision] + N[(y * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 2e-289], N[(1.0 + N[(N[(y / x), $MachinePrecision] / N[(x / N[(y * -8.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 4e-89], N[(t$95$1 / N[(x * x + t$95$0), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 5e-36], N[(1.0 + N[(N[(y * -8.0), $MachinePrecision] * N[(y / N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 2e+228], N[(t$95$1 / N[(t$95$0 + N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $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)\\
t_1 := x \cdot x + y \cdot \left(y \cdot -4\right)\\
\mathbf{if}\;t_0 \leq 2 \cdot 10^{-289}:\\
\;\;\;\;1 + \frac{\frac{y}{x}}{\frac{x}{y \cdot -8}}\\
\mathbf{elif}\;t_0 \leq 4 \cdot 10^{-89}:\\
\;\;\;\;\frac{t_1}{\mathsf{fma}\left(x, x, t_0\right)}\\
\mathbf{elif}\;t_0 \leq 5 \cdot 10^{-36}:\\
\;\;\;\;1 + \left(y \cdot -8\right) \cdot \frac{y}{x \cdot x}\\
\mathbf{elif}\;t_0 \leq 2 \cdot 10^{+228}:\\
\;\;\;\;\frac{t_1}{t_0 + x \cdot x}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\\
\end{array}
| Original | 31.9 |
|---|---|
| Target | 31.6 |
| Herbie | 12.3 |
if (*.f64 (*.f64 y 4) y) < 2e-289Initial program 30.1
Taylor expanded in x around inf 16.2
Simplified16.2
[Start]16.2 | \[ \left(1 + -4 \cdot \frac{{y}^{2}}{{x}^{2}}\right) - 4 \cdot \frac{{y}^{2}}{{x}^{2}}
\] |
|---|---|
cancel-sign-sub-inv [=>]16.2 | \[ \color{blue}{\left(1 + -4 \cdot \frac{{y}^{2}}{{x}^{2}}\right) + \left(-4\right) \cdot \frac{{y}^{2}}{{x}^{2}}}
\] |
metadata-eval [=>]16.2 | \[ \left(1 + -4 \cdot \frac{{y}^{2}}{{x}^{2}}\right) + \color{blue}{-4} \cdot \frac{{y}^{2}}{{x}^{2}}
\] |
associate-+l+ [=>]16.2 | \[ \color{blue}{1 + \left(-4 \cdot \frac{{y}^{2}}{{x}^{2}} + -4 \cdot \frac{{y}^{2}}{{x}^{2}}\right)}
\] |
associate-*r/ [=>]16.2 | \[ 1 + \left(\color{blue}{\frac{-4 \cdot {y}^{2}}{{x}^{2}}} + -4 \cdot \frac{{y}^{2}}{{x}^{2}}\right)
\] |
*-commutative [=>]16.2 | \[ 1 + \left(\frac{\color{blue}{{y}^{2} \cdot -4}}{{x}^{2}} + -4 \cdot \frac{{y}^{2}}{{x}^{2}}\right)
\] |
unpow2 [=>]16.2 | \[ 1 + \left(\frac{\color{blue}{\left(y \cdot y\right)} \cdot -4}{{x}^{2}} + -4 \cdot \frac{{y}^{2}}{{x}^{2}}\right)
\] |
associate-*r* [<=]16.2 | \[ 1 + \left(\frac{\color{blue}{y \cdot \left(y \cdot -4\right)}}{{x}^{2}} + -4 \cdot \frac{{y}^{2}}{{x}^{2}}\right)
\] |
unpow2 [=>]16.2 | \[ 1 + \left(\frac{y \cdot \left(y \cdot -4\right)}{\color{blue}{x \cdot x}} + -4 \cdot \frac{{y}^{2}}{{x}^{2}}\right)
\] |
associate-/l* [=>]16.2 | \[ 1 + \left(\color{blue}{\frac{y}{\frac{x \cdot x}{y \cdot -4}}} + -4 \cdot \frac{{y}^{2}}{{x}^{2}}\right)
\] |
associate-*r/ [=>]16.2 | \[ 1 + \left(\frac{y}{\frac{x \cdot x}{y \cdot -4}} + \color{blue}{\frac{-4 \cdot {y}^{2}}{{x}^{2}}}\right)
\] |
*-commutative [=>]16.2 | \[ 1 + \left(\frac{y}{\frac{x \cdot x}{y \cdot -4}} + \frac{\color{blue}{{y}^{2} \cdot -4}}{{x}^{2}}\right)
\] |
unpow2 [=>]16.2 | \[ 1 + \left(\frac{y}{\frac{x \cdot x}{y \cdot -4}} + \frac{\color{blue}{\left(y \cdot y\right)} \cdot -4}{{x}^{2}}\right)
\] |
associate-*r* [<=]16.2 | \[ 1 + \left(\frac{y}{\frac{x \cdot x}{y \cdot -4}} + \frac{\color{blue}{y \cdot \left(y \cdot -4\right)}}{{x}^{2}}\right)
\] |
unpow2 [=>]16.2 | \[ 1 + \left(\frac{y}{\frac{x \cdot x}{y \cdot -4}} + \frac{y \cdot \left(y \cdot -4\right)}{\color{blue}{x \cdot x}}\right)
\] |
associate-/l* [=>]16.2 | \[ 1 + \left(\frac{y}{\frac{x \cdot x}{y \cdot -4}} + \color{blue}{\frac{y}{\frac{x \cdot x}{y \cdot -4}}}\right)
\] |
Applied egg-rr16.2
Applied egg-rr8.5
if 2e-289 < (*.f64 (*.f64 y 4) y) < 4.00000000000000015e-89Initial program 15.0
Simplified15.0
[Start]15.0 | \[ \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
|---|---|
*-commutative [=>]15.0 | \[ \frac{x \cdot x - \color{blue}{y \cdot \left(y \cdot 4\right)}}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
fma-def [=>]15.0 | \[ \frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{\color{blue}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}
\] |
*-commutative [=>]15.0 | \[ \frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{\mathsf{fma}\left(x, x, \color{blue}{y \cdot \left(y \cdot 4\right)}\right)}
\] |
if 4.00000000000000015e-89 < (*.f64 (*.f64 y 4) y) < 5.00000000000000004e-36Initial program 16.6
Taylor expanded in x around inf 27.0
Simplified27.0
[Start]27.0 | \[ \left(1 + -4 \cdot \frac{{y}^{2}}{{x}^{2}}\right) - 4 \cdot \frac{{y}^{2}}{{x}^{2}}
\] |
|---|---|
cancel-sign-sub-inv [=>]27.0 | \[ \color{blue}{\left(1 + -4 \cdot \frac{{y}^{2}}{{x}^{2}}\right) + \left(-4\right) \cdot \frac{{y}^{2}}{{x}^{2}}}
\] |
metadata-eval [=>]27.0 | \[ \left(1 + -4 \cdot \frac{{y}^{2}}{{x}^{2}}\right) + \color{blue}{-4} \cdot \frac{{y}^{2}}{{x}^{2}}
\] |
associate-+l+ [=>]27.0 | \[ \color{blue}{1 + \left(-4 \cdot \frac{{y}^{2}}{{x}^{2}} + -4 \cdot \frac{{y}^{2}}{{x}^{2}}\right)}
\] |
associate-*r/ [=>]27.0 | \[ 1 + \left(\color{blue}{\frac{-4 \cdot {y}^{2}}{{x}^{2}}} + -4 \cdot \frac{{y}^{2}}{{x}^{2}}\right)
\] |
*-commutative [=>]27.0 | \[ 1 + \left(\frac{\color{blue}{{y}^{2} \cdot -4}}{{x}^{2}} + -4 \cdot \frac{{y}^{2}}{{x}^{2}}\right)
\] |
unpow2 [=>]27.0 | \[ 1 + \left(\frac{\color{blue}{\left(y \cdot y\right)} \cdot -4}{{x}^{2}} + -4 \cdot \frac{{y}^{2}}{{x}^{2}}\right)
\] |
associate-*r* [<=]27.0 | \[ 1 + \left(\frac{\color{blue}{y \cdot \left(y \cdot -4\right)}}{{x}^{2}} + -4 \cdot \frac{{y}^{2}}{{x}^{2}}\right)
\] |
unpow2 [=>]27.0 | \[ 1 + \left(\frac{y \cdot \left(y \cdot -4\right)}{\color{blue}{x \cdot x}} + -4 \cdot \frac{{y}^{2}}{{x}^{2}}\right)
\] |
associate-/l* [=>]27.0 | \[ 1 + \left(\color{blue}{\frac{y}{\frac{x \cdot x}{y \cdot -4}}} + -4 \cdot \frac{{y}^{2}}{{x}^{2}}\right)
\] |
associate-*r/ [=>]27.0 | \[ 1 + \left(\frac{y}{\frac{x \cdot x}{y \cdot -4}} + \color{blue}{\frac{-4 \cdot {y}^{2}}{{x}^{2}}}\right)
\] |
*-commutative [=>]27.0 | \[ 1 + \left(\frac{y}{\frac{x \cdot x}{y \cdot -4}} + \frac{\color{blue}{{y}^{2} \cdot -4}}{{x}^{2}}\right)
\] |
unpow2 [=>]27.0 | \[ 1 + \left(\frac{y}{\frac{x \cdot x}{y \cdot -4}} + \frac{\color{blue}{\left(y \cdot y\right)} \cdot -4}{{x}^{2}}\right)
\] |
associate-*r* [<=]27.0 | \[ 1 + \left(\frac{y}{\frac{x \cdot x}{y \cdot -4}} + \frac{\color{blue}{y \cdot \left(y \cdot -4\right)}}{{x}^{2}}\right)
\] |
unpow2 [=>]27.0 | \[ 1 + \left(\frac{y}{\frac{x \cdot x}{y \cdot -4}} + \frac{y \cdot \left(y \cdot -4\right)}{\color{blue}{x \cdot x}}\right)
\] |
associate-/l* [=>]27.0 | \[ 1 + \left(\frac{y}{\frac{x \cdot x}{y \cdot -4}} + \color{blue}{\frac{y}{\frac{x \cdot x}{y \cdot -4}}}\right)
\] |
Applied egg-rr27.0
if 5.00000000000000004e-36 < (*.f64 (*.f64 y 4) y) < 1.9999999999999998e228Initial program 16.0
if 1.9999999999999998e228 < (*.f64 (*.f64 y 4) y) Initial program 54.2
Simplified54.2
[Start]54.2 | \[ \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
|---|---|
*-commutative [=>]54.2 | \[ \frac{x \cdot x - \color{blue}{y \cdot \left(y \cdot 4\right)}}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
fma-def [=>]54.2 | \[ \frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{\color{blue}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}
\] |
*-commutative [=>]54.2 | \[ \frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{\mathsf{fma}\left(x, x, \color{blue}{y \cdot \left(y \cdot 4\right)}\right)}
\] |
Taylor expanded in x around 0 16.6
Simplified9.7
[Start]16.6 | \[ 0.5 \cdot \frac{{x}^{2}}{{y}^{2}} - 1
\] |
|---|---|
fma-neg [=>]16.6 | \[ \color{blue}{\mathsf{fma}\left(0.5, \frac{{x}^{2}}{{y}^{2}}, -1\right)}
\] |
unpow2 [=>]16.6 | \[ \mathsf{fma}\left(0.5, \frac{\color{blue}{x \cdot x}}{{y}^{2}}, -1\right)
\] |
unpow2 [=>]16.6 | \[ \mathsf{fma}\left(0.5, \frac{x \cdot x}{\color{blue}{y \cdot y}}, -1\right)
\] |
times-frac [=>]9.7 | \[ \mathsf{fma}\left(0.5, \color{blue}{\frac{x}{y} \cdot \frac{x}{y}}, -1\right)
\] |
metadata-eval [=>]9.7 | \[ \mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, \color{blue}{-1}\right)
\] |
Final simplification12.3
| Alternative 1 | |
|---|---|
| Error | 12.3 |
| Cost | 8528 |
| Alternative 2 | |
|---|---|
| Error | 12.4 |
| Cost | 2768 |
| Alternative 3 | |
|---|---|
| Error | 16.2 |
| Cost | 1868 |
| Alternative 4 | |
|---|---|
| Error | 17.5 |
| Cost | 1496 |
| Alternative 5 | |
|---|---|
| Error | 17.3 |
| Cost | 1496 |
| Alternative 6 | |
|---|---|
| Error | 16.7 |
| Cost | 592 |
| Alternative 7 | |
|---|---|
| Error | 31.2 |
| Cost | 64 |
herbie shell --seed 2022354
(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))))