
(FPCore (x) :precision binary64 (- (/ x x) (* (/ 1.0 x) (sqrt (* x x)))))
double code(double x) {
return (x / x) - ((1.0 / x) * sqrt((x * x)));
}
real(8) function code(x)
use fmin_fmax_functions
real(8), intent (in) :: x
code = (x / x) - ((1.0d0 / x) * sqrt((x * x)))
end function
public static double code(double x) {
return (x / x) - ((1.0 / x) * Math.sqrt((x * x)));
}
def code(x): return (x / x) - ((1.0 / x) * math.sqrt((x * x)))
function code(x) return Float64(Float64(x / x) - Float64(Float64(1.0 / x) * sqrt(Float64(x * x)))) end
function tmp = code(x) tmp = (x / x) - ((1.0 / x) * sqrt((x * x))); end
code[x_] := N[(N[(x / x), $MachinePrecision] - N[(N[(1.0 / x), $MachinePrecision] * N[Sqrt[N[(x * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x}
Herbie found 2 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (- (/ x x) (* (/ 1.0 x) (sqrt (* x x)))))
double code(double x) {
return (x / x) - ((1.0 / x) * sqrt((x * x)));
}
real(8) function code(x)
use fmin_fmax_functions
real(8), intent (in) :: x
code = (x / x) - ((1.0d0 / x) * sqrt((x * x)))
end function
public static double code(double x) {
return (x / x) - ((1.0 / x) * Math.sqrt((x * x)));
}
def code(x): return (x / x) - ((1.0 / x) * math.sqrt((x * x)))
function code(x) return Float64(Float64(x / x) - Float64(Float64(1.0 / x) * sqrt(Float64(x * x)))) end
function tmp = code(x) tmp = (x / x) - ((1.0 / x) * sqrt((x * x))); end
code[x_] := N[(N[(x / x), $MachinePrecision] - N[(N[(1.0 / x), $MachinePrecision] * N[Sqrt[N[(x * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x}
(FPCore (x) :precision binary64 (if (<= x -4e-308) 2.0 (- (copysign 1.0 x) 1.0)))
double code(double x) {
double tmp;
if (x <= -4e-308) {
tmp = 2.0;
} else {
tmp = copysign(1.0, x) - 1.0;
}
return tmp;
}
public static double code(double x) {
double tmp;
if (x <= -4e-308) {
tmp = 2.0;
} else {
tmp = Math.copySign(1.0, x) - 1.0;
}
return tmp;
}
def code(x): tmp = 0 if x <= -4e-308: tmp = 2.0 else: tmp = math.copysign(1.0, x) - 1.0 return tmp
function code(x) tmp = 0.0 if (x <= -4e-308) tmp = 2.0; else tmp = Float64(copysign(1.0, x) - 1.0); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= -4e-308) tmp = 2.0; else tmp = (sign(x) * abs(1.0)) - 1.0; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -4e-308], 2.0, N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] - 1.0), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;x \leq -4 \cdot 10^{-308}:\\
\;\;\;\;2\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(1, x\right) - 1\\
\end{array}
if x < -4.0000000000000001e-308Initial program 50.2%
Taylor expanded in x around -inf
Applied rewrites50.5%
if -4.0000000000000001e-308 < x Initial program 50.2%
Applied rewrites51.9%
(FPCore (x) :precision binary64 2.0)
double code(double x) {
return 2.0;
}
real(8) function code(x)
use fmin_fmax_functions
real(8), intent (in) :: x
code = 2.0d0
end function
public static double code(double x) {
return 2.0;
}
def code(x): return 2.0
function code(x) return 2.0 end
function tmp = code(x) tmp = 2.0; end
code[x_] := 2.0
2
Initial program 50.2%
Taylor expanded in x around -inf
Applied rewrites50.5%
herbie shell --seed 2025326
(FPCore (x)
:name "sqrt sqr"
:precision binary64
(- (/ x x) (* (/ 1.0 x) (sqrt (* x x)))))