(FPCore (k) :precision binary64 (- (/ 4.0 (+ (* k 4.0) 1.0)) (/ 4.0 (+ (* k 4.0) 3.0))))
double code(double k) { return (4.0 / ((k * 4.0) + 1.0)) - (4.0 / ((k * 4.0) + 3.0)); }
real(8) function code(k) real(8), intent (in) :: k code = (4.0d0 / ((k * 4.0d0) + 1.0d0)) - (4.0d0 / ((k * 4.0d0) + 3.0d0)) end function
public static double code(double k) { return (4.0 / ((k * 4.0) + 1.0)) - (4.0 / ((k * 4.0) + 3.0)); }
def code(k): return (4.0 / ((k * 4.0) + 1.0)) - (4.0 / ((k * 4.0) + 3.0))
function code(k) return Float64(Float64(4.0 / Float64(Float64(k * 4.0) + 1.0)) - Float64(4.0 / Float64(Float64(k * 4.0) + 3.0))) end
function tmp = code(k) tmp = (4.0 / ((k * 4.0) + 1.0)) - (4.0 / ((k * 4.0) + 3.0)); end
code[k_] := N[(N[(4.0 / N[(N[(k * 4.0), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] - N[(4.0 / N[(N[(k * 4.0), $MachinePrecision] + 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l} \\ \frac{4}{k \cdot 4 + 1} - \frac{4}{k \cdot 4 + 3} \end{array}
Sampling outcomes in binary64 precision:
Herbie found 4 alternatives:
Alternative | Accuracy | Speedup |
---|
(FPCore (k) :precision binary64 (- (/ 4.0 (+ (* k 4.0) 1.0)) (/ 4.0 (+ (* k 4.0) 3.0))))
double code(double k) { return (4.0 / ((k * 4.0) + 1.0)) - (4.0 / ((k * 4.0) + 3.0)); }
real(8) function code(k) real(8), intent (in) :: k code = (4.0d0 / ((k * 4.0d0) + 1.0d0)) - (4.0d0 / ((k * 4.0d0) + 3.0d0)) end function
public static double code(double k) { return (4.0 / ((k * 4.0) + 1.0)) - (4.0 / ((k * 4.0) + 3.0)); }
def code(k): return (4.0 / ((k * 4.0) + 1.0)) - (4.0 / ((k * 4.0) + 3.0))
function code(k) return Float64(Float64(4.0 / Float64(Float64(k * 4.0) + 1.0)) - Float64(4.0 / Float64(Float64(k * 4.0) + 3.0))) end
function tmp = code(k) tmp = (4.0 / ((k * 4.0) + 1.0)) - (4.0 / ((k * 4.0) + 3.0)); end
code[k_] := N[(N[(4.0 / N[(N[(k * 4.0), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] - N[(4.0 / N[(N[(k * 4.0), $MachinePrecision] + 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l} \\ \frac{4}{k \cdot 4 + 1} - \frac{4}{k \cdot 4 + 3} \end{array}
(FPCore (k) :precision binary64 (/ 8.0 (* (fma 4.0 k 3.0) (fma 4.0 k 1.0))))
double code(double k) { return 8.0 / (fma(4.0, k, 3.0) * fma(4.0, k, 1.0)); }
function code(k) return Float64(8.0 / Float64(fma(4.0, k, 3.0) * fma(4.0, k, 1.0))) end
code[k_] := N[(8.0 / N[(N[(4.0 * k + 3.0), $MachinePrecision] * N[(4.0 * k + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l} \\ \frac{8}{\mathsf{fma}\left(4, k, 3\right) \cdot \mathsf{fma}\left(4, k, 1\right)} \end{array}
Initial program 98.0%
lift--.f64
N/A
sub-neg
N/A
lift-/.f64
N/A
lift-/.f64
N/A
distribute-neg-frac
N/A
frac-add
N/A
lower-/.f64
N/A
Applied rewrites99.9%
Taylor expanded in k around 0
Applied rewrites100.0%
(FPCore (k) :precision binary64 (fma (fma 61.629629629629626 k -14.222222222222221) k 2.6666666666666665))
double code(double k) { return fma(fma(61.629629629629626, k, -14.222222222222221), k, 2.6666666666666665); }
function code(k) return fma(fma(61.629629629629626, k, -14.222222222222221), k, 2.6666666666666665) end
code[k_] := N[(N[(61.629629629629626 * k + -14.222222222222221), $MachinePrecision] * k + 2.6666666666666665), $MachinePrecision]
\begin{array}{l} \\ \mathsf{fma}\left(\mathsf{fma}\left(61.629629629629626, k, -14.222222222222221\right), k, 2.6666666666666665\right) \end{array}
Initial program 98.0%
Taylor expanded in k around 0
+-commutative
N/A
*-commutative
N/A
lower-fma.f64
N/A
sub-neg
N/A
metadata-eval
N/A
lower-fma.f64
96.8
Applied rewrites96.8%
(FPCore (k) :precision binary64 (fma -14.222222222222221 k 2.6666666666666665))
double code(double k) { return fma(-14.222222222222221, k, 2.6666666666666665); }
function code(k) return fma(-14.222222222222221, k, 2.6666666666666665) end
code[k_] := N[(-14.222222222222221 * k + 2.6666666666666665), $MachinePrecision]
\begin{array}{l} \\ \mathsf{fma}\left(-14.222222222222221, k, 2.6666666666666665\right) \end{array}
Initial program 98.0%
Taylor expanded in k around 0
+-commutative
N/A
lower-fma.f64
96.2
Applied rewrites96.2%
(FPCore (k) :precision binary64 2.6666666666666665)
double code(double k) { return 2.6666666666666665; }
real(8) function code(k) real(8), intent (in) :: k code = 2.6666666666666665d0 end function
public static double code(double k) { return 2.6666666666666665; }
def code(k): return 2.6666666666666665
function code(k) return 2.6666666666666665 end
function tmp = code(k) tmp = 2.6666666666666665; end
code[k_] := 2.6666666666666665
\begin{array}{l} \\ 2.6666666666666665 \end{array}
Initial program 98.0%
Taylor expanded in k around 0
Applied rewrites95.3%
herbie shell --seed 1
(FPCore (k)
:name "4/(k*4 + 1) - 4/(k*4 + 3)"
:precision binary64
:pre (and (<= 0.0 k) (<= k 16777216.0))
(- (/ 4.0 (+ (* k 4.0) 1.0)) (/ 4.0 (+ (* k 4.0) 3.0))))