| Alternative 1 | |
|---|---|
| Error | 0.15% |
| Cost | 708 |
\[\begin{array}{l}
\mathbf{if}\;y \cdot y \leq 2 \cdot 10^{+14}:\\
\;\;\;\;x \cdot \left(1 + y \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(y \cdot x\right)\\
\end{array}
\]
(FPCore (x y) :precision binary64 (* x (+ 1.0 (* y y))))
(FPCore (x y) :precision binary64 (if (or (<= y -9.4e+151) (not (<= y 72000000.0))) (* y (* y x)) (/ x (pow (hypot 1.0 y) -2.0))))
double code(double x, double y) {
return x * (1.0 + (y * y));
}
double code(double x, double y) {
double tmp;
if ((y <= -9.4e+151) || !(y <= 72000000.0)) {
tmp = y * (y * x);
} else {
tmp = x / pow(hypot(1.0, y), -2.0);
}
return tmp;
}
public static double code(double x, double y) {
return x * (1.0 + (y * y));
}
public static double code(double x, double y) {
double tmp;
if ((y <= -9.4e+151) || !(y <= 72000000.0)) {
tmp = y * (y * x);
} else {
tmp = x / Math.pow(Math.hypot(1.0, y), -2.0);
}
return tmp;
}
def code(x, y): return x * (1.0 + (y * y))
def code(x, y): tmp = 0 if (y <= -9.4e+151) or not (y <= 72000000.0): tmp = y * (y * x) else: tmp = x / math.pow(math.hypot(1.0, y), -2.0) return tmp
function code(x, y) return Float64(x * Float64(1.0 + Float64(y * y))) end
function code(x, y) tmp = 0.0 if ((y <= -9.4e+151) || !(y <= 72000000.0)) tmp = Float64(y * Float64(y * x)); else tmp = Float64(x / (hypot(1.0, y) ^ -2.0)); end return tmp end
function tmp = code(x, y) tmp = x * (1.0 + (y * y)); end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -9.4e+151) || ~((y <= 72000000.0))) tmp = y * (y * x); else tmp = x / (hypot(1.0, y) ^ -2.0); end tmp_2 = tmp; end
code[x_, y_] := N[(x * N[(1.0 + N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_] := If[Or[LessEqual[y, -9.4e+151], N[Not[LessEqual[y, 72000000.0]], $MachinePrecision]], N[(y * N[(y * x), $MachinePrecision]), $MachinePrecision], N[(x / N[Power[N[Sqrt[1.0 ^ 2 + y ^ 2], $MachinePrecision], -2.0], $MachinePrecision]), $MachinePrecision]]
x \cdot \left(1 + y \cdot y\right)
\begin{array}{l}
\mathbf{if}\;y \leq -9.4 \cdot 10^{+151} \lor \neg \left(y \leq 72000000\right):\\
\;\;\;\;y \cdot \left(y \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{{\left(\mathsf{hypot}\left(1, y\right)\right)}^{-2}}\\
\end{array}
Results
| Original | 8.62% |
|---|---|
| Target | 0.13% |
| Herbie | 0.16% |
if y < -9.39999999999999978e151 or 7.2e7 < y Initial program 43.12
Taylor expanded in y around inf 43.12
Simplified0.42
[Start]43.12 | \[ {y}^{2} \cdot x
\] |
|---|---|
unpow2 [=>]43.12 | \[ \color{blue}{\left(y \cdot y\right)} \cdot x
\] |
associate-*l* [=>]0.42 | \[ \color{blue}{y \cdot \left(y \cdot x\right)}
\] |
if -9.39999999999999978e151 < y < 7.2e7Initial program 0.08
Applied egg-rr7.44
Applied egg-rr2.18
Applied egg-rr0.11
Applied egg-rr14.84
Simplified0.1
[Start]14.84 | \[ \frac{x}{e^{\mathsf{log1p}\left(\frac{1}{\mathsf{fma}\left(y, y, 1\right)}\right)} - 1}
\] |
|---|---|
expm1-def [=>]0.11 | \[ \frac{x}{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{1}{\mathsf{fma}\left(y, y, 1\right)}\right)\right)}}
\] |
expm1-log1p [=>]0.11 | \[ \frac{x}{\color{blue}{\frac{1}{\mathsf{fma}\left(y, y, 1\right)}}}
\] |
rem-square-sqrt [<=]0.13 | \[ \frac{x}{\frac{1}{\color{blue}{\sqrt{\mathsf{fma}\left(y, y, 1\right)} \cdot \sqrt{\mathsf{fma}\left(y, y, 1\right)}}}}
\] |
associate-/r* [=>]0.13 | \[ \frac{x}{\color{blue}{\frac{\frac{1}{\sqrt{\mathsf{fma}\left(y, y, 1\right)}}}{\sqrt{\mathsf{fma}\left(y, y, 1\right)}}}}
\] |
unpow-1 [<=]0.13 | \[ \frac{x}{\frac{\color{blue}{{\left(\sqrt{\mathsf{fma}\left(y, y, 1\right)}\right)}^{-1}}}{\sqrt{\mathsf{fma}\left(y, y, 1\right)}}}
\] |
*-lft-identity [<=]0.13 | \[ \frac{x}{\frac{\color{blue}{1 \cdot {\left(\sqrt{\mathsf{fma}\left(y, y, 1\right)}\right)}^{-1}}}{\sqrt{\mathsf{fma}\left(y, y, 1\right)}}}
\] |
associate-*l/ [<=]0.18 | \[ \frac{x}{\color{blue}{\frac{1}{\sqrt{\mathsf{fma}\left(y, y, 1\right)}} \cdot {\left(\sqrt{\mathsf{fma}\left(y, y, 1\right)}\right)}^{-1}}}
\] |
unpow-1 [<=]0.18 | \[ \frac{x}{\color{blue}{{\left(\sqrt{\mathsf{fma}\left(y, y, 1\right)}\right)}^{-1}} \cdot {\left(\sqrt{\mathsf{fma}\left(y, y, 1\right)}\right)}^{-1}}
\] |
pow-sqr [=>]0.11 | \[ \frac{x}{\color{blue}{{\left(\sqrt{\mathsf{fma}\left(y, y, 1\right)}\right)}^{\left(2 \cdot -1\right)}}}
\] |
metadata-eval [=>]0.11 | \[ \frac{x}{{\left(\sqrt{\mathsf{fma}\left(y, y, 1\right)}\right)}^{\color{blue}{-2}}}
\] |
fma-udef [=>]0.11 | \[ \frac{x}{{\left(\sqrt{\color{blue}{y \cdot y + 1}}\right)}^{-2}}
\] |
unpow2 [<=]0.11 | \[ \frac{x}{{\left(\sqrt{\color{blue}{{y}^{2}} + 1}\right)}^{-2}}
\] |
+-commutative [<=]0.11 | \[ \frac{x}{{\left(\sqrt{\color{blue}{1 + {y}^{2}}}\right)}^{-2}}
\] |
unpow2 [=>]0.11 | \[ \frac{x}{{\left(\sqrt{1 + \color{blue}{y \cdot y}}\right)}^{-2}}
\] |
hypot-1-def [=>]0.1 | \[ \frac{x}{{\color{blue}{\left(\mathsf{hypot}\left(1, y\right)\right)}}^{-2}}
\] |
Final simplification0.16
| Alternative 1 | |
|---|---|
| Error | 0.15% |
| Cost | 708 |
| Alternative 2 | |
|---|---|
| Error | 0.14% |
| Cost | 708 |
| Alternative 3 | |
|---|---|
| Error | 10.21% |
| Cost | 580 |
| Alternative 4 | |
|---|---|
| Error | 1.8% |
| Cost | 580 |
| Alternative 5 | |
|---|---|
| Error | 32.09% |
| Cost | 64 |
herbie shell --seed 2023088
(FPCore (x y)
:name "Numeric.Integration.TanhSinh:everywhere from integration-0.2.1"
:precision binary64
:herbie-target
(+ x (* (* x y) y))
(* x (+ 1.0 (* y y))))