(FPCore (x) :precision binary64 (- (* x (log x)) x))
double code(double x) { return (x * log(x)) - x; }
real(8) function code(x) real(8), intent (in) :: x code = (x * log(x)) - x end function
public static double code(double x) { return (x * Math.log(x)) - x; }
def code(x): return (x * math.log(x)) - x
function code(x) return Float64(Float64(x * log(x)) - x) end
function tmp = code(x) tmp = (x * log(x)) - x; end
code[x_] := N[(N[(x * N[Log[x], $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision]
\begin{array}{l} \\ x \cdot \log x - x \end{array}
Sampling outcomes in binary64 precision:
Herbie found 2 alternatives:
Alternative | Accuracy | Speedup |
---|
(FPCore (x) :precision binary64 (- (* x (log x)) x))
double code(double x) { return (x * log(x)) - x; }
real(8) function code(x) real(8), intent (in) :: x code = (x * log(x)) - x end function
public static double code(double x) { return (x * Math.log(x)) - x; }
def code(x): return (x * math.log(x)) - x
function code(x) return Float64(Float64(x * log(x)) - x) end
function tmp = code(x) tmp = (x * log(x)) - x; end
code[x_] := N[(N[(x * N[Log[x], $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision]
\begin{array}{l} \\ x \cdot \log x - x \end{array}
(FPCore (x) :precision binary64 (fma (log x) x (- x)))
double code(double x) { return fma(log(x), x, -x); }
function code(x) return fma(log(x), x, Float64(-x)) end
code[x_] := N[(N[Log[x], $MachinePrecision] * x + (-x)), $MachinePrecision]
\begin{array}{l} \\ \mathsf{fma}\left(\log x, x, -x\right) \end{array}
Initial program 99.4%
lift--.f64
N/A
sub-neg
N/A
lift-*.f64
N/A
*-commutative
N/A
lower-fma.f64
N/A
lower-neg.f64
99.6
Applied rewrites99.6%
(FPCore (x) :precision binary64 (- (* x (log x)) x))
double code(double x) { return (x * log(x)) - x; }
real(8) function code(x) real(8), intent (in) :: x code = (x * log(x)) - x end function
public static double code(double x) { return (x * Math.log(x)) - x; }
def code(x): return (x * math.log(x)) - x
function code(x) return Float64(Float64(x * log(x)) - x) end
function tmp = code(x) tmp = (x * log(x)) - x; end
code[x_] := N[(N[(x * N[Log[x], $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision]
\begin{array}{l} \\ x \cdot \log x - x \end{array}
Initial program 99.4%
herbie shell --seed 1
(FPCore (x)
:name "x log(x) -x"
:precision binary64
:pre (and (<= 0.0 x) (<= x 1000.0))
(- (* x (log x)) x))