| Alternative 1 | |
|---|---|
| Error | 20.94% |
| Cost | 8536 |
(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))))
(t_2 (/ (+ (* x x) t_0) t_1))
(t_3 (fma 0.5 (* (/ x y) (/ x y)) -1.0)))
(if (<= (* x x) 5e-285)
t_3
(if (<= (* x x) 5e-244)
t_2
(if (<= (* x x) 5e-86)
t_3
(if (<= (* x x) 1e+124)
(/ (fma x x t_0) t_1)
(if (<= (* x x) 4e+139)
t_3
(if (<= (* x x) 5e+184)
t_2
(fma (* (/ y x) (/ y x)) -8.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 t_1 = (x * x) + (y * (y * 4.0));
double t_2 = ((x * x) + t_0) / t_1;
double t_3 = fma(0.5, ((x / y) * (x / y)), -1.0);
double tmp;
if ((x * x) <= 5e-285) {
tmp = t_3;
} else if ((x * x) <= 5e-244) {
tmp = t_2;
} else if ((x * x) <= 5e-86) {
tmp = t_3;
} else if ((x * x) <= 1e+124) {
tmp = fma(x, x, t_0) / t_1;
} else if ((x * x) <= 4e+139) {
tmp = t_3;
} else if ((x * x) <= 5e+184) {
tmp = t_2;
} else {
tmp = fma(((y / x) * (y / x)), -8.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)) t_1 = Float64(Float64(x * x) + Float64(y * Float64(y * 4.0))) t_2 = Float64(Float64(Float64(x * x) + t_0) / t_1) t_3 = fma(0.5, Float64(Float64(x / y) * Float64(x / y)), -1.0) tmp = 0.0 if (Float64(x * x) <= 5e-285) tmp = t_3; elseif (Float64(x * x) <= 5e-244) tmp = t_2; elseif (Float64(x * x) <= 5e-86) tmp = t_3; elseif (Float64(x * x) <= 1e+124) tmp = Float64(fma(x, x, t_0) / t_1); elseif (Float64(x * x) <= 4e+139) tmp = t_3; elseif (Float64(x * x) <= 5e+184) tmp = t_2; else tmp = fma(Float64(Float64(y / x) * Float64(y / x)), -8.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]}, Block[{t$95$1 = N[(N[(x * x), $MachinePrecision] + N[(y * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[(x * x), $MachinePrecision] + t$95$0), $MachinePrecision] / t$95$1), $MachinePrecision]}, Block[{t$95$3 = N[(0.5 * N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]}, If[LessEqual[N[(x * x), $MachinePrecision], 5e-285], t$95$3, If[LessEqual[N[(x * x), $MachinePrecision], 5e-244], t$95$2, If[LessEqual[N[(x * x), $MachinePrecision], 5e-86], t$95$3, If[LessEqual[N[(x * x), $MachinePrecision], 1e+124], N[(N[(x * x + t$95$0), $MachinePrecision] / t$95$1), $MachinePrecision], If[LessEqual[N[(x * x), $MachinePrecision], 4e+139], t$95$3, If[LessEqual[N[(x * x), $MachinePrecision], 5e+184], t$95$2, N[(N[(N[(y / x), $MachinePrecision] * N[(y / x), $MachinePrecision]), $MachinePrecision] * -8.0 + 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)\\
t_2 := \frac{x \cdot x + t_0}{t_1}\\
t_3 := \mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\\
\mathbf{if}\;x \cdot x \leq 5 \cdot 10^{-285}:\\
\;\;\;\;t_3\\
\mathbf{elif}\;x \cdot x \leq 5 \cdot 10^{-244}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;x \cdot x \leq 5 \cdot 10^{-86}:\\
\;\;\;\;t_3\\
\mathbf{elif}\;x \cdot x \leq 10^{+124}:\\
\;\;\;\;\frac{\mathsf{fma}\left(x, x, t_0\right)}{t_1}\\
\mathbf{elif}\;x \cdot x \leq 4 \cdot 10^{+139}:\\
\;\;\;\;t_3\\
\mathbf{elif}\;x \cdot x \leq 5 \cdot 10^{+184}:\\
\;\;\;\;t_2\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{x} \cdot \frac{y}{x}, -8, 1\right)\\
\end{array}
| Original | 50.02% |
|---|---|
| Target | 49.54% |
| Herbie | 20.94% |
if (*.f64 x x) < 5.00000000000000018e-285 or 4.99999999999999998e-244 < (*.f64 x x) < 4.9999999999999999e-86 or 9.99999999999999948e123 < (*.f64 x x) < 4.00000000000000013e139Initial program 38.8
Simplified39.01
[Start]38.8 | \[ \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
|---|---|
fma-neg [=>]38.79 | \[ \frac{\color{blue}{\mathsf{fma}\left(x, x, -\left(y \cdot 4\right) \cdot y\right)}}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
*-commutative [=>]38.79 | \[ \frac{\mathsf{fma}\left(x, x, -\color{blue}{y \cdot \left(y \cdot 4\right)}\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
associate-*r* [=>]39.01 | \[ \frac{\mathsf{fma}\left(x, x, -\color{blue}{\left(y \cdot y\right) \cdot 4}\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
distribute-rgt-neg-in [=>]39.01 | \[ \frac{\mathsf{fma}\left(x, x, \color{blue}{\left(y \cdot y\right) \cdot \left(-4\right)}\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
metadata-eval [=>]39.01 | \[ \frac{\mathsf{fma}\left(x, x, \left(y \cdot y\right) \cdot \color{blue}{-4}\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
fma-def [=>]39.01 | \[ \frac{\mathsf{fma}\left(x, x, \left(y \cdot y\right) \cdot -4\right)}{\color{blue}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}
\] |
*-commutative [=>]39.01 | \[ \frac{\mathsf{fma}\left(x, x, \left(y \cdot y\right) \cdot -4\right)}{\mathsf{fma}\left(x, x, \color{blue}{y \cdot \left(y \cdot 4\right)}\right)}
\] |
Taylor expanded in x around 0 29.18
Simplified21.26
[Start]29.18 | \[ 0.5 \cdot \frac{{x}^{2}}{{y}^{2}} - 1
\] |
|---|---|
fma-neg [=>]29.18 | \[ \color{blue}{\mathsf{fma}\left(0.5, \frac{{x}^{2}}{{y}^{2}}, -1\right)}
\] |
unpow2 [=>]29.18 | \[ \mathsf{fma}\left(0.5, \frac{\color{blue}{x \cdot x}}{{y}^{2}}, -1\right)
\] |
unpow2 [=>]29.18 | \[ \mathsf{fma}\left(0.5, \frac{x \cdot x}{\color{blue}{y \cdot y}}, -1\right)
\] |
times-frac [=>]21.26 | \[ \mathsf{fma}\left(0.5, \color{blue}{\frac{x}{y} \cdot \frac{x}{y}}, -1\right)
\] |
metadata-eval [=>]21.26 | \[ \mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, \color{blue}{-1}\right)
\] |
if 5.00000000000000018e-285 < (*.f64 x x) < 4.99999999999999998e-244 or 4.00000000000000013e139 < (*.f64 x x) < 4.9999999999999999e184Initial program 27.86
if 4.9999999999999999e-86 < (*.f64 x x) < 9.99999999999999948e123Initial program 25.85
Taylor expanded in x around 0 25.85
Simplified25.85
[Start]25.85 | \[ \frac{-4 \cdot {y}^{2} + {x}^{2}}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
|---|---|
unpow2 [=>]25.85 | \[ \frac{-4 \cdot {y}^{2} + \color{blue}{x \cdot x}}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
*-commutative [=>]25.85 | \[ \frac{\color{blue}{{y}^{2} \cdot -4} + x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
unpow2 [=>]25.85 | \[ \frac{\color{blue}{\left(y \cdot y\right)} \cdot -4 + x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
associate-*r* [<=]25.85 | \[ \frac{\color{blue}{y \cdot \left(y \cdot -4\right)} + x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
+-commutative [<=]25.85 | \[ \frac{\color{blue}{x \cdot x + y \cdot \left(y \cdot -4\right)}}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
fma-def [=>]25.85 | \[ \frac{\color{blue}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot -4\right)\right)}}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
if 4.9999999999999999e184 < (*.f64 x x) Initial program 79.35
Simplified79.35
[Start]79.35 | \[ \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
|---|---|
fma-neg [=>]79.35 | \[ \frac{\color{blue}{\mathsf{fma}\left(x, x, -\left(y \cdot 4\right) \cdot y\right)}}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
*-commutative [=>]79.35 | \[ \frac{\mathsf{fma}\left(x, x, -\color{blue}{y \cdot \left(y \cdot 4\right)}\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
associate-*r* [=>]79.35 | \[ \frac{\mathsf{fma}\left(x, x, -\color{blue}{\left(y \cdot y\right) \cdot 4}\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
distribute-rgt-neg-in [=>]79.35 | \[ \frac{\mathsf{fma}\left(x, x, \color{blue}{\left(y \cdot y\right) \cdot \left(-4\right)}\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
metadata-eval [=>]79.35 | \[ \frac{\mathsf{fma}\left(x, x, \left(y \cdot y\right) \cdot \color{blue}{-4}\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
fma-def [=>]79.35 | \[ \frac{\mathsf{fma}\left(x, x, \left(y \cdot y\right) \cdot -4\right)}{\color{blue}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}
\] |
*-commutative [=>]79.35 | \[ \frac{\mathsf{fma}\left(x, x, \left(y \cdot y\right) \cdot -4\right)}{\mathsf{fma}\left(x, x, \color{blue}{y \cdot \left(y \cdot 4\right)}\right)}
\] |
Taylor expanded in x around inf 25.96
Simplified16.85
[Start]25.96 | \[ \left(1 + -4 \cdot \frac{{y}^{2}}{{x}^{2}}\right) - 4 \cdot \frac{{y}^{2}}{{x}^{2}}
\] |
|---|---|
associate--l+ [=>]25.95 | \[ \color{blue}{1 + \left(-4 \cdot \frac{{y}^{2}}{{x}^{2}} - 4 \cdot \frac{{y}^{2}}{{x}^{2}}\right)}
\] |
+-commutative [=>]25.95 | \[ \color{blue}{\left(-4 \cdot \frac{{y}^{2}}{{x}^{2}} - 4 \cdot \frac{{y}^{2}}{{x}^{2}}\right) + 1}
\] |
distribute-rgt-out-- [=>]25.95 | \[ \color{blue}{\frac{{y}^{2}}{{x}^{2}} \cdot \left(-4 - 4\right)} + 1
\] |
metadata-eval [=>]25.95 | \[ \frac{{y}^{2}}{{x}^{2}} \cdot \color{blue}{-8} + 1
\] |
fma-def [=>]25.95 | \[ \color{blue}{\mathsf{fma}\left(\frac{{y}^{2}}{{x}^{2}}, -8, 1\right)}
\] |
unpow2 [=>]25.95 | \[ \mathsf{fma}\left(\frac{\color{blue}{y \cdot y}}{{x}^{2}}, -8, 1\right)
\] |
unpow2 [=>]25.95 | \[ \mathsf{fma}\left(\frac{y \cdot y}{\color{blue}{x \cdot x}}, -8, 1\right)
\] |
times-frac [=>]16.85 | \[ \mathsf{fma}\left(\color{blue}{\frac{y}{x} \cdot \frac{y}{x}}, -8, 1\right)
\] |
Final simplification20.94
| Alternative 1 | |
|---|---|
| Error | 20.94% |
| Cost | 8536 |
| Alternative 2 | |
|---|---|
| Error | 21.01% |
| Cost | 8276 |
| Alternative 3 | |
|---|---|
| Error | 21.44% |
| Cost | 2776 |
| Alternative 4 | |
|---|---|
| Error | 25.62% |
| Cost | 1234 |
| Alternative 5 | |
|---|---|
| Error | 25.97% |
| Cost | 592 |
| Alternative 6 | |
|---|---|
| Error | 49.51% |
| Cost | 64 |
herbie shell --seed 2023089
(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))))