| Alternative 1 | |
|---|---|
| Error | 0.4 |
| Cost | 6788 |
\[\begin{array}{l}
t_0 := \sqrt{2} \cdot x\\
\mathbf{if}\;x \leq -5 \cdot 10^{-310}:\\
\;\;\;\;-t_0\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\]
(FPCore (x) :precision binary64 (sqrt (+ (pow x 2.0) (pow x 2.0))))
(FPCore (x) :precision binary64 (if (<= x -5e-310) (- (/ (* x (cbrt (sqrt 2.0))) (cbrt 0.5))) (* (sqrt 2.0) x)))
double code(double x) {
return sqrt((pow(x, 2.0) + pow(x, 2.0)));
}
double code(double x) {
double tmp;
if (x <= -5e-310) {
tmp = -((x * cbrt(sqrt(2.0))) / cbrt(0.5));
} else {
tmp = sqrt(2.0) * x;
}
return tmp;
}
public static double code(double x) {
return Math.sqrt((Math.pow(x, 2.0) + Math.pow(x, 2.0)));
}
public static double code(double x) {
double tmp;
if (x <= -5e-310) {
tmp = -((x * Math.cbrt(Math.sqrt(2.0))) / Math.cbrt(0.5));
} else {
tmp = Math.sqrt(2.0) * x;
}
return tmp;
}
function code(x) return sqrt(Float64((x ^ 2.0) + (x ^ 2.0))) end
function code(x) tmp = 0.0 if (x <= -5e-310) tmp = Float64(-Float64(Float64(x * cbrt(sqrt(2.0))) / cbrt(0.5))); else tmp = Float64(sqrt(2.0) * x); end return tmp end
code[x_] := N[Sqrt[N[(N[Power[x, 2.0], $MachinePrecision] + N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
code[x_] := If[LessEqual[x, -5e-310], (-N[(N[(x * N[Power[N[Sqrt[2.0], $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision] / N[Power[0.5, 1/3], $MachinePrecision]), $MachinePrecision]), N[(N[Sqrt[2.0], $MachinePrecision] * x), $MachinePrecision]]
\sqrt{{x}^{2} + {x}^{2}}
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{-310}:\\
\;\;\;\;-\frac{x \cdot \sqrt[3]{\sqrt{2}}}{\sqrt[3]{0.5}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{2} \cdot x\\
\end{array}
Results
if x < -4.999999999999985e-310Initial program 30.3
Taylor expanded in x around -inf 0.4
Simplified0.4
Applied egg-rr0.3
if -4.999999999999985e-310 < x Initial program 30.1
Taylor expanded in x around 0 0.4
| Alternative 1 | |
|---|---|
| Error | 0.4 |
| Cost | 6788 |
| Alternative 2 | |
|---|---|
| Error | 0.4 |
| Cost | 6788 |
| Alternative 3 | |
|---|---|
| Error | 31.1 |
| Cost | 6592 |
| Alternative 4 | |
|---|---|
| Error | 61.6 |
| Cost | 64 |
herbie shell --seed 2023010
(FPCore (x)
:name "sqrt E (should all be same)"
:precision binary64
(sqrt (+ (pow x 2.0) (pow x 2.0))))