(FPCore (x) :precision binary64 (- (fabs x) x))
double code(double x) { return fabs(x) - x; }
real(8) function code(x) real(8), intent (in) :: x code = abs(x) - x end function
public static double code(double x) { return Math.abs(x) - x; }
def code(x): return math.fabs(x) - x
function code(x) return Float64(abs(x) - x) end
function tmp = code(x) tmp = abs(x) - x; end
code[x_] := N[(N[Abs[x], $MachinePrecision] - x), $MachinePrecision]
\begin{array}{l} \\ \left|x\right| - x \end{array}
Sampling outcomes in binary64 precision:
Herbie found 3 alternatives:
Alternative | Accuracy | Speedup |
---|
(FPCore (x) :precision binary64 (- (fabs x) x))
double code(double x) { return fabs(x) - x; }
real(8) function code(x) real(8), intent (in) :: x code = abs(x) - x end function
public static double code(double x) { return Math.abs(x) - x; }
def code(x): return math.fabs(x) - x
function code(x) return Float64(abs(x) - x) end
function tmp = code(x) tmp = abs(x) - x; end
code[x_] := N[(N[Abs[x], $MachinePrecision] - x), $MachinePrecision]
\begin{array}{l} \\ \left|x\right| - x \end{array}
(FPCore (x) :precision binary64 (- (fabs x) x))
double code(double x) { return fabs(x) - x; }
real(8) function code(x) real(8), intent (in) :: x code = abs(x) - x end function
public static double code(double x) { return Math.abs(x) - x; }
def code(x): return math.fabs(x) - x
function code(x) return Float64(abs(x) - x) end
function tmp = code(x) tmp = abs(x) - x; end
code[x_] := N[(N[Abs[x], $MachinePrecision] - x), $MachinePrecision]
\begin{array}{l} \\ \left|x\right| - x \end{array}
Initial program 100.0%
(FPCore (x) :precision binary64 (if (<= (- (fabs x) x) 0.0) 0.0 (- x)))
double code(double x) { double tmp; if ((fabs(x) - x) <= 0.0) { tmp = 0.0; } else { tmp = -x; } return tmp; }
real(8) function code(x) real(8), intent (in) :: x real(8) :: tmp if ((abs(x) - x) <= 0.0d0) then tmp = 0.0d0 else tmp = -x end if code = tmp end function
public static double code(double x) { double tmp; if ((Math.abs(x) - x) <= 0.0) { tmp = 0.0; } else { tmp = -x; } return tmp; }
def code(x): tmp = 0 if (math.fabs(x) - x) <= 0.0: tmp = 0.0 else: tmp = -x return tmp
function code(x) tmp = 0.0 if (Float64(abs(x) - x) <= 0.0) tmp = 0.0; else tmp = Float64(-x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((abs(x) - x) <= 0.0) tmp = 0.0; else tmp = -x; end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[(N[Abs[x], $MachinePrecision] - x), $MachinePrecision], 0.0], 0.0, (-x)]
\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\left|x\right| - x \leq 0:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;-x\\ \end{array} \end{array}
if (-.f64 (fabs.f64 x) x) < 0.0
Initial program 100.0%
lift--.f64
N/A
flip--
N/A
lift-fabs.f64
N/A
lift-fabs.f64
N/A
sqr-abs
N/A
div-sub
N/A
+-inverses
100.0
Applied rewrites100.0%
if 0.0 < (-.f64 (fabs.f64 x) x)
Initial program 100.0%
Taylor expanded in x around inf
mul-1-neg
N/A
lower-neg.f64
18.8
Applied rewrites18.8%
(FPCore (x) :precision binary64 0.0)
double code(double x) { return 0.0; }
real(8) function code(x) real(8), intent (in) :: x code = 0.0d0 end function
public static double code(double x) { return 0.0; }
def code(x): return 0.0
function code(x) return 0.0 end
function tmp = code(x) tmp = 0.0; end
code[x_] := 0.0
\begin{array}{l} \\ 0 \end{array}
Initial program 100.0%
lift--.f64
N/A
flip--
N/A
lift-fabs.f64
N/A
lift-fabs.f64
N/A
sqr-abs
N/A
div-sub
N/A
+-inverses
53.2
Applied rewrites53.2%
herbie shell --seed 1
(FPCore (x)
:name "abs(x)-x"
:precision binary64
:pre (and (<= -1000.0 x) (<= x 1000.0))
(- (fabs x) x))