(FPCore (x) :precision binary64 (- (/ x x) (* (/ 1.0 x) (sqrt (* x x)))))
(FPCore (x) :precision binary64 (/ (- x (fabs x)) x))
double code(double x) {
return (x / x) - ((1.0 / x) * sqrt((x * x)));
}
double code(double x) {
return (x - fabs(x)) / x;
}
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
code = (x - abs(x)) / x
end function
public static double code(double x) {
return (x / x) - ((1.0 / x) * Math.sqrt((x * x)));
}
public static double code(double x) {
return (x - Math.abs(x)) / x;
}
def code(x): return (x / x) - ((1.0 / x) * math.sqrt((x * x)))
def code(x): return (x - math.fabs(x)) / x
function code(x) return Float64(Float64(x / x) - Float64(Float64(1.0 / x) * sqrt(Float64(x * x)))) end
function code(x) return Float64(Float64(x - abs(x)) / x) end
function tmp = code(x) tmp = (x / x) - ((1.0 / x) * sqrt((x * x))); end
function tmp = code(x) tmp = (x - abs(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]
code[x_] := N[(N[(x - N[Abs[x], $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]
\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x}
\frac{x - \left|x\right|}{x}
Results
| Original | 32.6 |
|---|---|
| Target | 0 |
| Herbie | 0 |
Initial program 32.6
Simplified0
herbie shell --seed 2023010
(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)))))