| Alternative 1 | |
|---|---|
| Error | 13.8 |
| Cost | 14280 |
(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 (+ -1.0 (log1p (* 0.5 (pow (/ x y) 2.0)))))
(t_1 (fma x x (* y (* y 4.0)))))
(if (<= (* x x) 5e-157)
t_0
(if (<= (* x x) 1e-66)
(/ (fma x x (* (* y y) -4.0)) t_1)
(if (<= (* x x) 4e+91)
t_0
(if (<= (* x x) 1e+268)
(/ (fma y (* y -4.0) (* x x)) t_1)
(+ (* (pow (/ y x) 2.0) -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 = -1.0 + log1p((0.5 * pow((x / y), 2.0)));
double t_1 = fma(x, x, (y * (y * 4.0)));
double tmp;
if ((x * x) <= 5e-157) {
tmp = t_0;
} else if ((x * x) <= 1e-66) {
tmp = fma(x, x, ((y * y) * -4.0)) / t_1;
} else if ((x * x) <= 4e+91) {
tmp = t_0;
} else if ((x * x) <= 1e+268) {
tmp = fma(y, (y * -4.0), (x * x)) / t_1;
} else {
tmp = (pow((y / x), 2.0) * -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(-1.0 + log1p(Float64(0.5 * (Float64(x / y) ^ 2.0)))) t_1 = fma(x, x, Float64(y * Float64(y * 4.0))) tmp = 0.0 if (Float64(x * x) <= 5e-157) tmp = t_0; elseif (Float64(x * x) <= 1e-66) tmp = Float64(fma(x, x, Float64(Float64(y * y) * -4.0)) / t_1); elseif (Float64(x * x) <= 4e+91) tmp = t_0; elseif (Float64(x * x) <= 1e+268) tmp = Float64(fma(y, Float64(y * -4.0), Float64(x * x)) / t_1); else tmp = Float64(Float64((Float64(y / x) ^ 2.0) * -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[(-1.0 + N[Log[1 + N[(0.5 * N[Power[N[(x / y), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x * x + N[(y * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * x), $MachinePrecision], 5e-157], t$95$0, If[LessEqual[N[(x * x), $MachinePrecision], 1e-66], N[(N[(x * x + N[(N[(y * y), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision] / t$95$1), $MachinePrecision], If[LessEqual[N[(x * x), $MachinePrecision], 4e+91], t$95$0, If[LessEqual[N[(x * x), $MachinePrecision], 1e+268], N[(N[(y * N[(y * -4.0), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision] / t$95$1), $MachinePrecision], N[(N[(N[Power[N[(y / x), $MachinePrecision], 2.0], $MachinePrecision] * -8.0), $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 := -1 + \mathsf{log1p}\left(0.5 \cdot {\left(\frac{x}{y}\right)}^{2}\right)\\
t_1 := \mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)\\
\mathbf{if}\;x \cdot x \leq 5 \cdot 10^{-157}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \cdot x \leq 10^{-66}:\\
\;\;\;\;\frac{\mathsf{fma}\left(x, x, \left(y \cdot y\right) \cdot -4\right)}{t_1}\\
\mathbf{elif}\;x \cdot x \leq 4 \cdot 10^{+91}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \cdot x \leq 10^{+268}:\\
\;\;\;\;\frac{\mathsf{fma}\left(y, y \cdot -4, x \cdot x\right)}{t_1}\\
\mathbf{else}:\\
\;\;\;\;{\left(\frac{y}{x}\right)}^{2} \cdot -8 + 1\\
\end{array}
| Original | 31.1 |
|---|---|
| Target | 30.8 |
| Herbie | 13.8 |
if (*.f64 x x) < 5.0000000000000002e-157 or 9.9999999999999998e-67 < (*.f64 x x) < 4.00000000000000032e91Initial program 23.1
Simplified23.1
[Start]23.1 | \[ \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
|---|---|
cancel-sign-sub-inv [=>]23.1 | \[ \frac{\color{blue}{x \cdot x + \left(-y \cdot 4\right) \cdot y}}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
+-commutative [=>]23.1 | \[ \frac{\color{blue}{\left(-y \cdot 4\right) \cdot y + x \cdot x}}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
*-commutative [=>]23.1 | \[ \frac{\color{blue}{y \cdot \left(-y \cdot 4\right)} + x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
fma-def [=>]23.1 | \[ \frac{\color{blue}{\mathsf{fma}\left(y, -y \cdot 4, x \cdot x\right)}}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
distribute-rgt-neg-in [=>]23.1 | \[ \frac{\mathsf{fma}\left(y, \color{blue}{y \cdot \left(-4\right)}, x \cdot x\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
metadata-eval [=>]23.1 | \[ \frac{\mathsf{fma}\left(y, y \cdot \color{blue}{-4}, x \cdot x\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
fma-def [=>]23.1 | \[ \frac{\mathsf{fma}\left(y, y \cdot -4, x \cdot x\right)}{\color{blue}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}
\] |
*-commutative [=>]23.1 | \[ \frac{\mathsf{fma}\left(y, y \cdot -4, x \cdot x\right)}{\mathsf{fma}\left(x, x, \color{blue}{y \cdot \left(y \cdot 4\right)}\right)}
\] |
Taylor expanded in y around inf 21.2
Simplified17.1
[Start]21.2 | \[ 0.25 \cdot \frac{{x}^{2}}{{y}^{2}} - \left(-0.25 \cdot \frac{{x}^{2}}{{y}^{2}} + 1\right)
\] |
|---|---|
associate--r+ [=>]21.2 | \[ \color{blue}{\left(0.25 \cdot \frac{{x}^{2}}{{y}^{2}} - -0.25 \cdot \frac{{x}^{2}}{{y}^{2}}\right) - 1}
\] |
distribute-rgt-out-- [=>]21.2 | \[ \color{blue}{\frac{{x}^{2}}{{y}^{2}} \cdot \left(0.25 - -0.25\right)} - 1
\] |
metadata-eval [=>]21.2 | \[ \frac{{x}^{2}}{{y}^{2}} \cdot \color{blue}{0.5} - 1
\] |
fma-neg [=>]21.2 | \[ \color{blue}{\mathsf{fma}\left(\frac{{x}^{2}}{{y}^{2}}, 0.5, -1\right)}
\] |
unpow2 [=>]21.2 | \[ \mathsf{fma}\left(\frac{\color{blue}{x \cdot x}}{{y}^{2}}, 0.5, -1\right)
\] |
unpow2 [=>]21.2 | \[ \mathsf{fma}\left(\frac{x \cdot x}{\color{blue}{y \cdot y}}, 0.5, -1\right)
\] |
times-frac [=>]17.1 | \[ \mathsf{fma}\left(\color{blue}{\frac{x}{y} \cdot \frac{x}{y}}, 0.5, -1\right)
\] |
metadata-eval [=>]17.1 | \[ \mathsf{fma}\left(\frac{x}{y} \cdot \frac{x}{y}, 0.5, \color{blue}{-1}\right)
\] |
Applied egg-rr17.8
Taylor expanded in x around 0 20.7
Simplified16.0
[Start]20.7 | \[ \log \left(0.5 \cdot \frac{e^{-1} \cdot {x}^{2}}{{y}^{2}} + e^{-1}\right)
\] |
|---|---|
fma-def [=>]20.7 | \[ \log \color{blue}{\left(\mathsf{fma}\left(0.5, \frac{e^{-1} \cdot {x}^{2}}{{y}^{2}}, e^{-1}\right)\right)}
\] |
*-commutative [=>]20.7 | \[ \log \left(\mathsf{fma}\left(0.5, \frac{\color{blue}{{x}^{2} \cdot e^{-1}}}{{y}^{2}}, e^{-1}\right)\right)
\] |
associate-/l* [=>]20.7 | \[ \log \left(\mathsf{fma}\left(0.5, \color{blue}{\frac{{x}^{2}}{\frac{{y}^{2}}{e^{-1}}}}, e^{-1}\right)\right)
\] |
associate-/r/ [=>]20.7 | \[ \log \left(\mathsf{fma}\left(0.5, \color{blue}{\frac{{x}^{2}}{{y}^{2}} \cdot e^{-1}}, e^{-1}\right)\right)
\] |
unpow2 [=>]20.7 | \[ \log \left(\mathsf{fma}\left(0.5, \frac{\color{blue}{x \cdot x}}{{y}^{2}} \cdot e^{-1}, e^{-1}\right)\right)
\] |
unpow2 [=>]20.7 | \[ \log \left(\mathsf{fma}\left(0.5, \frac{x \cdot x}{\color{blue}{y \cdot y}} \cdot e^{-1}, e^{-1}\right)\right)
\] |
times-frac [=>]16.0 | \[ \log \left(\mathsf{fma}\left(0.5, \color{blue}{\left(\frac{x}{y} \cdot \frac{x}{y}\right)} \cdot e^{-1}, e^{-1}\right)\right)
\] |
unpow2 [<=]16.0 | \[ \log \left(\mathsf{fma}\left(0.5, \color{blue}{{\left(\frac{x}{y}\right)}^{2}} \cdot e^{-1}, e^{-1}\right)\right)
\] |
Applied egg-rr16.0
Simplified16.0
[Start]16.0 | \[ \log \left(e^{-1} \cdot \left(1 + 0.5 \cdot {\left(\frac{x}{y}\right)}^{2}\right)\right) + 0
\] |
|---|---|
+-rgt-identity [=>]16.0 | \[ \color{blue}{\log \left(e^{-1} \cdot \left(1 + 0.5 \cdot {\left(\frac{x}{y}\right)}^{2}\right)\right)}
\] |
+-commutative [=>]16.0 | \[ \log \left(e^{-1} \cdot \color{blue}{\left(0.5 \cdot {\left(\frac{x}{y}\right)}^{2} + 1\right)}\right)
\] |
log-prod [=>]16.0 | \[ \color{blue}{\log \left(e^{-1}\right) + \log \left(0.5 \cdot {\left(\frac{x}{y}\right)}^{2} + 1\right)}
\] |
rem-log-exp [=>]16.0 | \[ \color{blue}{-1} + \log \left(0.5 \cdot {\left(\frac{x}{y}\right)}^{2} + 1\right)
\] |
+-commutative [<=]16.0 | \[ -1 + \log \color{blue}{\left(1 + 0.5 \cdot {\left(\frac{x}{y}\right)}^{2}\right)}
\] |
log1p-def [=>]16.0 | \[ -1 + \color{blue}{\mathsf{log1p}\left(0.5 \cdot {\left(\frac{x}{y}\right)}^{2}\right)}
\] |
if 5.0000000000000002e-157 < (*.f64 x x) < 9.9999999999999998e-67Initial program 15.6
Simplified15.6
[Start]15.6 | \[ \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
|---|---|
fma-neg [=>]15.6 | \[ \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 [=>]15.6 | \[ \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* [=>]15.6 | \[ \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 [=>]15.6 | \[ \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 [=>]15.6 | \[ \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 [=>]15.6 | \[ \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 [=>]15.6 | \[ \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)}
\] |
if 4.00000000000000032e91 < (*.f64 x x) < 9.9999999999999997e267Initial program 15.3
Simplified15.3
[Start]15.3 | \[ \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
|---|---|
cancel-sign-sub-inv [=>]15.3 | \[ \frac{\color{blue}{x \cdot x + \left(-y \cdot 4\right) \cdot y}}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
+-commutative [=>]15.3 | \[ \frac{\color{blue}{\left(-y \cdot 4\right) \cdot y + x \cdot x}}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
*-commutative [=>]15.3 | \[ \frac{\color{blue}{y \cdot \left(-y \cdot 4\right)} + x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
fma-def [=>]15.3 | \[ \frac{\color{blue}{\mathsf{fma}\left(y, -y \cdot 4, x \cdot x\right)}}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
distribute-rgt-neg-in [=>]15.3 | \[ \frac{\mathsf{fma}\left(y, \color{blue}{y \cdot \left(-4\right)}, x \cdot x\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
metadata-eval [=>]15.3 | \[ \frac{\mathsf{fma}\left(y, y \cdot \color{blue}{-4}, x \cdot x\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
fma-def [=>]15.3 | \[ \frac{\mathsf{fma}\left(y, y \cdot -4, x \cdot x\right)}{\color{blue}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}
\] |
*-commutative [=>]15.3 | \[ \frac{\mathsf{fma}\left(y, y \cdot -4, x \cdot x\right)}{\mathsf{fma}\left(x, x, \color{blue}{y \cdot \left(y \cdot 4\right)}\right)}
\] |
if 9.9999999999999997e267 < (*.f64 x x) Initial program 58.0
Simplified58.0
[Start]58.0 | \[ \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
|---|---|
fma-neg [=>]58.0 | \[ \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 [=>]58.0 | \[ \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* [=>]58.0 | \[ \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 [=>]58.0 | \[ \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 [=>]58.0 | \[ \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 [=>]58.0 | \[ \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 [=>]58.0 | \[ \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 15.9
Simplified8.4
[Start]15.9 | \[ \left(1 + -4 \cdot \frac{{y}^{2}}{{x}^{2}}\right) - 4 \cdot \frac{{y}^{2}}{{x}^{2}}
\] |
|---|---|
associate--l+ [=>]15.9 | \[ \color{blue}{1 + \left(-4 \cdot \frac{{y}^{2}}{{x}^{2}} - 4 \cdot \frac{{y}^{2}}{{x}^{2}}\right)}
\] |
+-commutative [=>]15.9 | \[ \color{blue}{\left(-4 \cdot \frac{{y}^{2}}{{x}^{2}} - 4 \cdot \frac{{y}^{2}}{{x}^{2}}\right) + 1}
\] |
distribute-rgt-out-- [=>]15.9 | \[ \color{blue}{\frac{{y}^{2}}{{x}^{2}} \cdot \left(-4 - 4\right)} + 1
\] |
metadata-eval [=>]15.9 | \[ \frac{{y}^{2}}{{x}^{2}} \cdot \color{blue}{-8} + 1
\] |
fma-def [=>]15.9 | \[ \color{blue}{\mathsf{fma}\left(\frac{{y}^{2}}{{x}^{2}}, -8, 1\right)}
\] |
unpow2 [=>]15.9 | \[ \mathsf{fma}\left(\frac{\color{blue}{y \cdot y}}{{x}^{2}}, -8, 1\right)
\] |
unpow2 [=>]15.9 | \[ \mathsf{fma}\left(\frac{y \cdot y}{\color{blue}{x \cdot x}}, -8, 1\right)
\] |
times-frac [=>]8.4 | \[ \mathsf{fma}\left(\color{blue}{\frac{y}{x} \cdot \frac{y}{x}}, -8, 1\right)
\] |
Applied egg-rr8.4
Final simplification13.8
| Alternative 1 | |
|---|---|
| Error | 13.8 |
| Cost | 14280 |
| Alternative 2 | |
|---|---|
| Error | 13.8 |
| Cost | 14092 |
| Alternative 3 | |
|---|---|
| Error | 14.6 |
| Cost | 7952 |
| Alternative 4 | |
|---|---|
| Error | 14.6 |
| Cost | 2256 |
| Alternative 5 | |
|---|---|
| Error | 16.8 |
| Cost | 969 |
| Alternative 6 | |
|---|---|
| Error | 16.5 |
| Cost | 969 |
| Alternative 7 | |
|---|---|
| Error | 16.4 |
| Cost | 969 |
| Alternative 8 | |
|---|---|
| Error | 18.5 |
| Cost | 856 |
| Alternative 9 | |
|---|---|
| Error | 32.1 |
| Cost | 64 |
herbie shell --seed 2022364
(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))))