| Alternative 1 | |
|---|---|
| Error | 30.3 |
| Cost | 320 |
\[\frac{x - x}{x}
\]
(FPCore (x) :precision binary64 (- (/ x x) (* (/ 1.0 x) (sqrt (* x x)))))
(FPCore (x) :precision binary64 (if (<= x -4e-310) (/ (- x (- x)) x) (/ (- x x) x)))
double code(double x) {
return (x / x) - ((1.0 / x) * sqrt((x * x)));
}
double code(double x) {
double tmp;
if (x <= -4e-310) {
tmp = (x - -x) / x;
} else {
tmp = (x - x) / x;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x / x) - ((1.0d0 / x) * sqrt((x * x)))
end function
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-4d-310)) then
tmp = (x - -x) / x
else
tmp = (x - x) / x
end if
code = tmp
end function
public static double code(double x) {
return (x / x) - ((1.0 / x) * Math.sqrt((x * x)));
}
public static double code(double x) {
double tmp;
if (x <= -4e-310) {
tmp = (x - -x) / x;
} else {
tmp = (x - x) / x;
}
return tmp;
}
def code(x): return (x / x) - ((1.0 / x) * math.sqrt((x * x)))
def code(x): tmp = 0 if x <= -4e-310: tmp = (x - -x) / x else: tmp = (x - x) / x return tmp
function code(x) return Float64(Float64(x / x) - Float64(Float64(1.0 / x) * sqrt(Float64(x * x)))) end
function code(x) tmp = 0.0 if (x <= -4e-310) tmp = Float64(Float64(x - Float64(-x)) / x); else tmp = Float64(Float64(x - x) / x); end return tmp end
function tmp = code(x) tmp = (x / x) - ((1.0 / x) * sqrt((x * x))); end
function tmp_2 = code(x) tmp = 0.0; if (x <= -4e-310) tmp = (x - -x) / x; else tmp = (x - x) / x; end tmp_2 = tmp; end
code[x_] := N[(N[(x / x), $MachinePrecision] - N[(N[(1.0 / x), $MachinePrecision] * N[Sqrt[N[(x * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_] := If[LessEqual[x, -4e-310], N[(N[(x - (-x)), $MachinePrecision] / x), $MachinePrecision], N[(N[(x - x), $MachinePrecision] / x), $MachinePrecision]]
\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x}
\begin{array}{l}
\mathbf{if}\;x \leq -4 \cdot 10^{-310}:\\
\;\;\;\;\frac{x - \left(-x\right)}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{x - x}{x}\\
\end{array}
Results
| Original | 32.1 |
|---|---|
| Target | 0 |
| Herbie | 0.0 |
if x < -3.999999999999988e-310Initial program 28.6
Simplified28.6
[Start]28.6 | \[ \frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x}
\] |
|---|---|
rational_best-simplify-1 [=>]28.6 | \[ \frac{x}{x} - \color{blue}{\sqrt{x \cdot x} \cdot \frac{1}{x}}
\] |
rational_best-simplify-55 [=>]28.6 | \[ \frac{x}{x} - \color{blue}{1 \cdot \frac{\sqrt{x \cdot x}}{x}}
\] |
rational_best-simplify-1 [=>]28.6 | \[ \frac{x}{x} - \color{blue}{\frac{\sqrt{x \cdot x}}{x} \cdot 1}
\] |
rational_best-simplify-7 [=>]28.6 | \[ \frac{x}{x} - \color{blue}{\frac{\sqrt{x \cdot x}}{x}}
\] |
rational_best-simplify-66 [=>]28.6 | \[ \color{blue}{\frac{x - \sqrt{x \cdot x}}{x}}
\] |
Taylor expanded in x around -inf 0.1
Simplified0.1
[Start]0.1 | \[ \frac{x - -1 \cdot x}{x}
\] |
|---|---|
rational_best-simplify-1 [=>]0.1 | \[ \frac{x - \color{blue}{x \cdot -1}}{x}
\] |
rational_best-simplify-11 [<=]0.1 | \[ \frac{x - \color{blue}{\left(-x\right)}}{x}
\] |
if -3.999999999999988e-310 < x Initial program 35.4
Simplified30.5
[Start]35.4 | \[ \frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x}
\] |
|---|---|
rational_best-simplify-1 [=>]35.4 | \[ \frac{x}{x} - \color{blue}{\sqrt{x \cdot x} \cdot \frac{1}{x}}
\] |
rational_best-simplify-55 [=>]30.5 | \[ \frac{x}{x} - \color{blue}{1 \cdot \frac{\sqrt{x \cdot x}}{x}}
\] |
rational_best-simplify-1 [=>]30.5 | \[ \frac{x}{x} - \color{blue}{\frac{\sqrt{x \cdot x}}{x} \cdot 1}
\] |
rational_best-simplify-7 [=>]30.5 | \[ \frac{x}{x} - \color{blue}{\frac{\sqrt{x \cdot x}}{x}}
\] |
rational_best-simplify-66 [=>]30.5 | \[ \color{blue}{\frac{x - \sqrt{x \cdot x}}{x}}
\] |
Taylor expanded in x around 0 0
Final simplification0.0
| Alternative 1 | |
|---|---|
| Error | 30.3 |
| Cost | 320 |
herbie shell --seed 2023099
(FPCore (x)
:name "sqrt sqr"
:precision binary64
:herbie-target
(if (< x 0.0) 2.0 0.0)
(- (/ x x) (* (/ 1.0 x) (sqrt (* x x)))))