
(FPCore (x n) :precision binary64 (- (pow (+ x 1.0) (/ 1.0 n)) (pow x (/ 1.0 n))))
double code(double x, double n) {
return pow((x + 1.0), (1.0 / n)) - pow(x, (1.0 / n));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, n)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: n
code = ((x + 1.0d0) ** (1.0d0 / n)) - (x ** (1.0d0 / n))
end function
public static double code(double x, double n) {
return Math.pow((x + 1.0), (1.0 / n)) - Math.pow(x, (1.0 / n));
}
def code(x, n): return math.pow((x + 1.0), (1.0 / n)) - math.pow(x, (1.0 / n))
function code(x, n) return Float64((Float64(x + 1.0) ^ Float64(1.0 / n)) - (x ^ Float64(1.0 / n))) end
function tmp = code(x, n) tmp = ((x + 1.0) ^ (1.0 / n)) - (x ^ (1.0 / n)); end
code[x_, n_] := N[(N[Power[N[(x + 1.0), $MachinePrecision], N[(1.0 / n), $MachinePrecision]], $MachinePrecision] - N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x n) :precision binary64 (- (pow (+ x 1.0) (/ 1.0 n)) (pow x (/ 1.0 n))))
double code(double x, double n) {
return pow((x + 1.0), (1.0 / n)) - pow(x, (1.0 / n));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, n)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: n
code = ((x + 1.0d0) ** (1.0d0 / n)) - (x ** (1.0d0 / n))
end function
public static double code(double x, double n) {
return Math.pow((x + 1.0), (1.0 / n)) - Math.pow(x, (1.0 / n));
}
def code(x, n): return math.pow((x + 1.0), (1.0 / n)) - math.pow(x, (1.0 / n))
function code(x, n) return Float64((Float64(x + 1.0) ^ Float64(1.0 / n)) - (x ^ Float64(1.0 / n))) end
function tmp = code(x, n) tmp = ((x + 1.0) ^ (1.0 / n)) - (x ^ (1.0 / n)); end
code[x_, n_] := N[(N[Power[N[(x + 1.0), $MachinePrecision], N[(1.0 / n), $MachinePrecision]], $MachinePrecision] - N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)}
\end{array}
(FPCore (x n)
:precision binary64
(if (or (<= n -110000.0) (not (<= n 122000.0)))
(-
(/
(fma
-1.0
(log1p x)
(/
(-
(fma
-1.0
(/
(-
(fma
-1.0
(-
(/ (* 0.041666666666666664 (pow (log1p x) 4.0)) n)
(/ (* 0.041666666666666664 (pow (log x) 4.0)) n))
(* -0.16666666666666666 (pow (log1p x) 3.0)))
(* -0.16666666666666666 (pow (log x) 3.0)))
n)
(* 0.5 (pow (log1p x) 2.0)))
(* 0.5 (pow (log x) 2.0)))
(* -1.0 n)))
(* -1.0 n))
(* -1.0 (/ (* -1.0 (log x)) n)))
(- (exp (* (log1p x) (pow n -1.0))) (pow x (/ 1.0 n)))))
double code(double x, double n) {
double tmp;
if ((n <= -110000.0) || !(n <= 122000.0)) {
tmp = (fma(-1.0, log1p(x), ((fma(-1.0, ((fma(-1.0, (((0.041666666666666664 * pow(log1p(x), 4.0)) / n) - ((0.041666666666666664 * pow(log(x), 4.0)) / n)), (-0.16666666666666666 * pow(log1p(x), 3.0))) - (-0.16666666666666666 * pow(log(x), 3.0))) / n), (0.5 * pow(log1p(x), 2.0))) - (0.5 * pow(log(x), 2.0))) / (-1.0 * n))) / (-1.0 * n)) - (-1.0 * ((-1.0 * log(x)) / n));
} else {
tmp = exp((log1p(x) * pow(n, -1.0))) - pow(x, (1.0 / n));
}
return tmp;
}
function code(x, n) tmp = 0.0 if ((n <= -110000.0) || !(n <= 122000.0)) tmp = Float64(Float64(fma(-1.0, log1p(x), Float64(Float64(fma(-1.0, Float64(Float64(fma(-1.0, Float64(Float64(Float64(0.041666666666666664 * (log1p(x) ^ 4.0)) / n) - Float64(Float64(0.041666666666666664 * (log(x) ^ 4.0)) / n)), Float64(-0.16666666666666666 * (log1p(x) ^ 3.0))) - Float64(-0.16666666666666666 * (log(x) ^ 3.0))) / n), Float64(0.5 * (log1p(x) ^ 2.0))) - Float64(0.5 * (log(x) ^ 2.0))) / Float64(-1.0 * n))) / Float64(-1.0 * n)) - Float64(-1.0 * Float64(Float64(-1.0 * log(x)) / n))); else tmp = Float64(exp(Float64(log1p(x) * (n ^ -1.0))) - (x ^ Float64(1.0 / n))); end return tmp end
code[x_, n_] := If[Or[LessEqual[n, -110000.0], N[Not[LessEqual[n, 122000.0]], $MachinePrecision]], N[(N[(N[(-1.0 * N[Log[1 + x], $MachinePrecision] + N[(N[(N[(-1.0 * N[(N[(N[(-1.0 * N[(N[(N[(0.041666666666666664 * N[Power[N[Log[1 + x], $MachinePrecision], 4.0], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision] - N[(N[(0.041666666666666664 * N[Power[N[Log[x], $MachinePrecision], 4.0], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision]), $MachinePrecision] + N[(-0.16666666666666666 * N[Power[N[Log[1 + x], $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(-0.16666666666666666 * N[Power[N[Log[x], $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision] + N[(0.5 * N[Power[N[Log[1 + x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(0.5 * N[Power[N[Log[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(-1.0 * n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(-1.0 * n), $MachinePrecision]), $MachinePrecision] - N[(-1.0 * N[(N[(-1.0 * N[Log[x], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Exp[N[(N[Log[1 + x], $MachinePrecision] * N[Power[n, -1.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;n \leq -110000 \lor \neg \left(n \leq 122000\right):\\
\;\;\;\;\frac{\mathsf{fma}\left(-1, \mathsf{log1p}\left(x\right), \frac{\mathsf{fma}\left(-1, \frac{\mathsf{fma}\left(-1, \frac{0.041666666666666664 \cdot {\left(\mathsf{log1p}\left(x\right)\right)}^{4}}{n} - \frac{0.041666666666666664 \cdot {\log x}^{4}}{n}, -0.16666666666666666 \cdot {\left(\mathsf{log1p}\left(x\right)\right)}^{3}\right) - -0.16666666666666666 \cdot {\log x}^{3}}{n}, 0.5 \cdot {\left(\mathsf{log1p}\left(x\right)\right)}^{2}\right) - 0.5 \cdot {\log x}^{2}}{-1 \cdot n}\right)}{-1 \cdot n} - -1 \cdot \frac{-1 \cdot \log x}{n}\\
\mathbf{else}:\\
\;\;\;\;e^{\mathsf{log1p}\left(x\right) \cdot {n}^{-1}} - {x}^{\left(\frac{1}{n}\right)}\\
\end{array}
\end{array}
if n < -1.1e5 or 122000 < n Initial program 33.5%
Taylor expanded in n around -inf
Applied rewrites51.0%
Taylor expanded in n around -inf
Applied rewrites77.7%
Applied rewrites77.7%
if -1.1e5 < n < 122000Initial program 74.5%
lift-+.f64N/A
lift-/.f64N/A
lift-pow.f64N/A
pow-to-expN/A
lower-exp.f64N/A
+-commutativeN/A
lower-*.f64N/A
lower-log1p.f64N/A
inv-powN/A
lower-pow.f6498.2
Applied rewrites98.2%
Final simplification86.9%
(FPCore (x n)
:precision binary64
(let* ((t_0 (pow (log x) 2.0)) (t_1 (/ (* -1.0 (log x)) n)))
(if (<= (/ 1.0 n) -100000000.0)
(/ (pow (exp -1.0) t_1) (* n x))
(if (<= (/ 1.0 n) 2e-33)
(-
(/
(fma
-1.0
(log1p x)
(/
(-
(fma
-1.0
(/
(-
(fma
-1.0
(-
(/ (* 0.041666666666666664 (pow (log1p x) 4.0)) n)
(/ (* 0.041666666666666664 (pow (log x) 4.0)) n))
(* -0.16666666666666666 (pow (log1p x) 3.0)))
(* -0.16666666666666666 (pow (log x) 3.0)))
n)
(* 0.5 (pow (log1p x) 2.0)))
(* 0.5 t_0))
(* -1.0 n)))
(* -1.0 n))
(* -1.0 t_1))
(/
(- (/ (fma 0.5 (/ t_0 (* n x)) (/ (log x) x)) (* -1.0 n)) (pow x -1.0))
(* -1.0 n))))))
double code(double x, double n) {
double t_0 = pow(log(x), 2.0);
double t_1 = (-1.0 * log(x)) / n;
double tmp;
if ((1.0 / n) <= -100000000.0) {
tmp = pow(exp(-1.0), t_1) / (n * x);
} else if ((1.0 / n) <= 2e-33) {
tmp = (fma(-1.0, log1p(x), ((fma(-1.0, ((fma(-1.0, (((0.041666666666666664 * pow(log1p(x), 4.0)) / n) - ((0.041666666666666664 * pow(log(x), 4.0)) / n)), (-0.16666666666666666 * pow(log1p(x), 3.0))) - (-0.16666666666666666 * pow(log(x), 3.0))) / n), (0.5 * pow(log1p(x), 2.0))) - (0.5 * t_0)) / (-1.0 * n))) / (-1.0 * n)) - (-1.0 * t_1);
} else {
tmp = ((fma(0.5, (t_0 / (n * x)), (log(x) / x)) / (-1.0 * n)) - pow(x, -1.0)) / (-1.0 * n);
}
return tmp;
}
function code(x, n) t_0 = log(x) ^ 2.0 t_1 = Float64(Float64(-1.0 * log(x)) / n) tmp = 0.0 if (Float64(1.0 / n) <= -100000000.0) tmp = Float64((exp(-1.0) ^ t_1) / Float64(n * x)); elseif (Float64(1.0 / n) <= 2e-33) tmp = Float64(Float64(fma(-1.0, log1p(x), Float64(Float64(fma(-1.0, Float64(Float64(fma(-1.0, Float64(Float64(Float64(0.041666666666666664 * (log1p(x) ^ 4.0)) / n) - Float64(Float64(0.041666666666666664 * (log(x) ^ 4.0)) / n)), Float64(-0.16666666666666666 * (log1p(x) ^ 3.0))) - Float64(-0.16666666666666666 * (log(x) ^ 3.0))) / n), Float64(0.5 * (log1p(x) ^ 2.0))) - Float64(0.5 * t_0)) / Float64(-1.0 * n))) / Float64(-1.0 * n)) - Float64(-1.0 * t_1)); else tmp = Float64(Float64(Float64(fma(0.5, Float64(t_0 / Float64(n * x)), Float64(log(x) / x)) / Float64(-1.0 * n)) - (x ^ -1.0)) / Float64(-1.0 * n)); end return tmp end
code[x_, n_] := Block[{t$95$0 = N[Power[N[Log[x], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$1 = N[(N[(-1.0 * N[Log[x], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision]}, If[LessEqual[N[(1.0 / n), $MachinePrecision], -100000000.0], N[(N[Power[N[Exp[-1.0], $MachinePrecision], t$95$1], $MachinePrecision] / N[(n * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 2e-33], N[(N[(N[(-1.0 * N[Log[1 + x], $MachinePrecision] + N[(N[(N[(-1.0 * N[(N[(N[(-1.0 * N[(N[(N[(0.041666666666666664 * N[Power[N[Log[1 + x], $MachinePrecision], 4.0], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision] - N[(N[(0.041666666666666664 * N[Power[N[Log[x], $MachinePrecision], 4.0], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision]), $MachinePrecision] + N[(-0.16666666666666666 * N[Power[N[Log[1 + x], $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(-0.16666666666666666 * N[Power[N[Log[x], $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision] + N[(0.5 * N[Power[N[Log[1 + x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(0.5 * t$95$0), $MachinePrecision]), $MachinePrecision] / N[(-1.0 * n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(-1.0 * n), $MachinePrecision]), $MachinePrecision] - N[(-1.0 * t$95$1), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(0.5 * N[(t$95$0 / N[(n * x), $MachinePrecision]), $MachinePrecision] + N[(N[Log[x], $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision] / N[(-1.0 * n), $MachinePrecision]), $MachinePrecision] - N[Power[x, -1.0], $MachinePrecision]), $MachinePrecision] / N[(-1.0 * n), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\log x}^{2}\\
t_1 := \frac{-1 \cdot \log x}{n}\\
\mathbf{if}\;\frac{1}{n} \leq -100000000:\\
\;\;\;\;\frac{{\left(e^{-1}\right)}^{t\_1}}{n \cdot x}\\
\mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{-33}:\\
\;\;\;\;\frac{\mathsf{fma}\left(-1, \mathsf{log1p}\left(x\right), \frac{\mathsf{fma}\left(-1, \frac{\mathsf{fma}\left(-1, \frac{0.041666666666666664 \cdot {\left(\mathsf{log1p}\left(x\right)\right)}^{4}}{n} - \frac{0.041666666666666664 \cdot {\log x}^{4}}{n}, -0.16666666666666666 \cdot {\left(\mathsf{log1p}\left(x\right)\right)}^{3}\right) - -0.16666666666666666 \cdot {\log x}^{3}}{n}, 0.5 \cdot {\left(\mathsf{log1p}\left(x\right)\right)}^{2}\right) - 0.5 \cdot t\_0}{-1 \cdot n}\right)}{-1 \cdot n} - -1 \cdot t\_1\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(0.5, \frac{t\_0}{n \cdot x}, \frac{\log x}{x}\right)}{-1 \cdot n} - {x}^{-1}}{-1 \cdot n}\\
\end{array}
\end{array}
if (/.f64 #s(literal 1 binary64) n) < -1e8Initial program 100.0%
Taylor expanded in x around inf
lower-/.f64N/A
exp-prodN/A
log-recN/A
mul-1-negN/A
lower-pow.f64N/A
lower-exp.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-log.f64N/A
lower-*.f64100.0
Applied rewrites100.0%
if -1e8 < (/.f64 #s(literal 1 binary64) n) < 2.0000000000000001e-33Initial program 34.2%
Taylor expanded in n around -inf
Applied rewrites52.1%
Taylor expanded in n around -inf
Applied rewrites80.0%
Applied rewrites80.1%
if 2.0000000000000001e-33 < (/.f64 #s(literal 1 binary64) n) Initial program 42.7%
Taylor expanded in x around inf
lower-/.f64N/A
exp-prodN/A
log-recN/A
mul-1-negN/A
lower-pow.f64N/A
lower-exp.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-log.f64N/A
lower-*.f6412.5
Applied rewrites12.5%
Taylor expanded in n around -inf
lower-*.f64N/A
lower-/.f64N/A
Applied rewrites52.1%
Final simplification78.2%
(FPCore (x n)
:precision binary64
(let* ((t_0 (pow (log x) 2.0)))
(if (<= (/ 1.0 n) 2e-33)
(-
(/
(fma
-1.0
(log1p x)
(/
(-
(fma
-1.0
(/
(-
(fma
-1.0
(-
(/ (* 0.041666666666666664 (pow (log1p x) 4.0)) n)
(/ (* 0.041666666666666664 (pow (log x) 4.0)) n))
(* -0.16666666666666666 (pow (log1p x) 3.0)))
(* -0.16666666666666666 (pow (log x) 3.0)))
n)
(* 0.5 (pow (log1p x) 2.0)))
(* 0.5 t_0))
(* -1.0 n)))
(* -1.0 n))
(* -1.0 (/ (* -1.0 (log x)) n)))
(/
(- (/ (fma 0.5 (/ t_0 (* n x)) (/ (log x) x)) (* -1.0 n)) (pow x -1.0))
(* -1.0 n)))))
double code(double x, double n) {
double t_0 = pow(log(x), 2.0);
double tmp;
if ((1.0 / n) <= 2e-33) {
tmp = (fma(-1.0, log1p(x), ((fma(-1.0, ((fma(-1.0, (((0.041666666666666664 * pow(log1p(x), 4.0)) / n) - ((0.041666666666666664 * pow(log(x), 4.0)) / n)), (-0.16666666666666666 * pow(log1p(x), 3.0))) - (-0.16666666666666666 * pow(log(x), 3.0))) / n), (0.5 * pow(log1p(x), 2.0))) - (0.5 * t_0)) / (-1.0 * n))) / (-1.0 * n)) - (-1.0 * ((-1.0 * log(x)) / n));
} else {
tmp = ((fma(0.5, (t_0 / (n * x)), (log(x) / x)) / (-1.0 * n)) - pow(x, -1.0)) / (-1.0 * n);
}
return tmp;
}
function code(x, n) t_0 = log(x) ^ 2.0 tmp = 0.0 if (Float64(1.0 / n) <= 2e-33) tmp = Float64(Float64(fma(-1.0, log1p(x), Float64(Float64(fma(-1.0, Float64(Float64(fma(-1.0, Float64(Float64(Float64(0.041666666666666664 * (log1p(x) ^ 4.0)) / n) - Float64(Float64(0.041666666666666664 * (log(x) ^ 4.0)) / n)), Float64(-0.16666666666666666 * (log1p(x) ^ 3.0))) - Float64(-0.16666666666666666 * (log(x) ^ 3.0))) / n), Float64(0.5 * (log1p(x) ^ 2.0))) - Float64(0.5 * t_0)) / Float64(-1.0 * n))) / Float64(-1.0 * n)) - Float64(-1.0 * Float64(Float64(-1.0 * log(x)) / n))); else tmp = Float64(Float64(Float64(fma(0.5, Float64(t_0 / Float64(n * x)), Float64(log(x) / x)) / Float64(-1.0 * n)) - (x ^ -1.0)) / Float64(-1.0 * n)); end return tmp end
code[x_, n_] := Block[{t$95$0 = N[Power[N[Log[x], $MachinePrecision], 2.0], $MachinePrecision]}, If[LessEqual[N[(1.0 / n), $MachinePrecision], 2e-33], N[(N[(N[(-1.0 * N[Log[1 + x], $MachinePrecision] + N[(N[(N[(-1.0 * N[(N[(N[(-1.0 * N[(N[(N[(0.041666666666666664 * N[Power[N[Log[1 + x], $MachinePrecision], 4.0], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision] - N[(N[(0.041666666666666664 * N[Power[N[Log[x], $MachinePrecision], 4.0], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision]), $MachinePrecision] + N[(-0.16666666666666666 * N[Power[N[Log[1 + x], $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(-0.16666666666666666 * N[Power[N[Log[x], $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision] + N[(0.5 * N[Power[N[Log[1 + x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(0.5 * t$95$0), $MachinePrecision]), $MachinePrecision] / N[(-1.0 * n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(-1.0 * n), $MachinePrecision]), $MachinePrecision] - N[(-1.0 * N[(N[(-1.0 * N[Log[x], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(0.5 * N[(t$95$0 / N[(n * x), $MachinePrecision]), $MachinePrecision] + N[(N[Log[x], $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision] / N[(-1.0 * n), $MachinePrecision]), $MachinePrecision] - N[Power[x, -1.0], $MachinePrecision]), $MachinePrecision] / N[(-1.0 * n), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\log x}^{2}\\
\mathbf{if}\;\frac{1}{n} \leq 2 \cdot 10^{-33}:\\
\;\;\;\;\frac{\mathsf{fma}\left(-1, \mathsf{log1p}\left(x\right), \frac{\mathsf{fma}\left(-1, \frac{\mathsf{fma}\left(-1, \frac{0.041666666666666664 \cdot {\left(\mathsf{log1p}\left(x\right)\right)}^{4}}{n} - \frac{0.041666666666666664 \cdot {\log x}^{4}}{n}, -0.16666666666666666 \cdot {\left(\mathsf{log1p}\left(x\right)\right)}^{3}\right) - -0.16666666666666666 \cdot {\log x}^{3}}{n}, 0.5 \cdot {\left(\mathsf{log1p}\left(x\right)\right)}^{2}\right) - 0.5 \cdot t\_0}{-1 \cdot n}\right)}{-1 \cdot n} - -1 \cdot \frac{-1 \cdot \log x}{n}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(0.5, \frac{t\_0}{n \cdot x}, \frac{\log x}{x}\right)}{-1 \cdot n} - {x}^{-1}}{-1 \cdot n}\\
\end{array}
\end{array}
if (/.f64 #s(literal 1 binary64) n) < 2.0000000000000001e-33Initial program 54.8%
Taylor expanded in n around -inf
Applied rewrites51.1%
Taylor expanded in n around -inf
Applied rewrites79.9%
Applied rewrites79.9%
if 2.0000000000000001e-33 < (/.f64 #s(literal 1 binary64) n) Initial program 42.7%
Taylor expanded in x around inf
lower-/.f64N/A
exp-prodN/A
log-recN/A
mul-1-negN/A
lower-pow.f64N/A
lower-exp.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-log.f64N/A
lower-*.f6412.5
Applied rewrites12.5%
Taylor expanded in n around -inf
lower-*.f64N/A
lower-/.f64N/A
Applied rewrites52.1%
Final simplification73.3%
(FPCore (x n) :precision binary64 (/ (- (/ (fma 0.5 (/ (pow (log x) 2.0) (* n x)) (/ (log x) x)) (* -1.0 n)) (pow x -1.0)) (* -1.0 n)))
double code(double x, double n) {
return ((fma(0.5, (pow(log(x), 2.0) / (n * x)), (log(x) / x)) / (-1.0 * n)) - pow(x, -1.0)) / (-1.0 * n);
}
function code(x, n) return Float64(Float64(Float64(fma(0.5, Float64((log(x) ^ 2.0) / Float64(n * x)), Float64(log(x) / x)) / Float64(-1.0 * n)) - (x ^ -1.0)) / Float64(-1.0 * n)) end
code[x_, n_] := N[(N[(N[(N[(0.5 * N[(N[Power[N[Log[x], $MachinePrecision], 2.0], $MachinePrecision] / N[(n * x), $MachinePrecision]), $MachinePrecision] + N[(N[Log[x], $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision] / N[(-1.0 * n), $MachinePrecision]), $MachinePrecision] - N[Power[x, -1.0], $MachinePrecision]), $MachinePrecision] / N[(-1.0 * n), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{\mathsf{fma}\left(0.5, \frac{{\log x}^{2}}{n \cdot x}, \frac{\log x}{x}\right)}{-1 \cdot n} - {x}^{-1}}{-1 \cdot n}
\end{array}
Initial program 51.9%
Taylor expanded in x around inf
lower-/.f64N/A
exp-prodN/A
log-recN/A
mul-1-negN/A
lower-pow.f64N/A
lower-exp.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-log.f64N/A
lower-*.f6454.5
Applied rewrites54.5%
Taylor expanded in n around -inf
lower-*.f64N/A
lower-/.f64N/A
Applied rewrites52.0%
Final simplification52.0%
(FPCore (x n)
:precision binary64
(let* ((t_0 (/ (* -1.0 (log x)) n))
(t_1 (pow (exp -1.0) t_0))
(t_2 (* n t_1))
(t_3 (exp (* -1.0 t_0)))
(t_4 (/ t_3 (pow x 4.0)))
(t_5 (* (* x x) x))
(t_6 (/ t_3 t_5)))
(/
(fma
0.041666666666666664
t_4
(*
n
(fma
-0.25
t_4
(fma
0.16666666666666666
t_6
(*
n
(fma
-1.0
(/
(+
(* (* -1.0 n) t_1)
(fma
-0.3333333333333333
(/ t_2 (* x x))
(fma 0.25 (/ t_2 t_5) (* 0.5 (/ t_2 x)))))
x)
(fma
-0.5
t_6
(fma 0.4583333333333333 t_4 (* 0.5 (/ t_3 (* x x)))))))))))
(pow n 4.0))))
double code(double x, double n) {
double t_0 = (-1.0 * log(x)) / n;
double t_1 = pow(exp(-1.0), t_0);
double t_2 = n * t_1;
double t_3 = exp((-1.0 * t_0));
double t_4 = t_3 / pow(x, 4.0);
double t_5 = (x * x) * x;
double t_6 = t_3 / t_5;
return fma(0.041666666666666664, t_4, (n * fma(-0.25, t_4, fma(0.16666666666666666, t_6, (n * fma(-1.0, ((((-1.0 * n) * t_1) + fma(-0.3333333333333333, (t_2 / (x * x)), fma(0.25, (t_2 / t_5), (0.5 * (t_2 / x))))) / x), fma(-0.5, t_6, fma(0.4583333333333333, t_4, (0.5 * (t_3 / (x * x))))))))))) / pow(n, 4.0);
}
function code(x, n) t_0 = Float64(Float64(-1.0 * log(x)) / n) t_1 = exp(-1.0) ^ t_0 t_2 = Float64(n * t_1) t_3 = exp(Float64(-1.0 * t_0)) t_4 = Float64(t_3 / (x ^ 4.0)) t_5 = Float64(Float64(x * x) * x) t_6 = Float64(t_3 / t_5) return Float64(fma(0.041666666666666664, t_4, Float64(n * fma(-0.25, t_4, fma(0.16666666666666666, t_6, Float64(n * fma(-1.0, Float64(Float64(Float64(Float64(-1.0 * n) * t_1) + fma(-0.3333333333333333, Float64(t_2 / Float64(x * x)), fma(0.25, Float64(t_2 / t_5), Float64(0.5 * Float64(t_2 / x))))) / x), fma(-0.5, t_6, fma(0.4583333333333333, t_4, Float64(0.5 * Float64(t_3 / Float64(x * x))))))))))) / (n ^ 4.0)) end
code[x_, n_] := Block[{t$95$0 = N[(N[(-1.0 * N[Log[x], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision]}, Block[{t$95$1 = N[Power[N[Exp[-1.0], $MachinePrecision], t$95$0], $MachinePrecision]}, Block[{t$95$2 = N[(n * t$95$1), $MachinePrecision]}, Block[{t$95$3 = N[Exp[N[(-1.0 * t$95$0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$4 = N[(t$95$3 / N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$5 = N[(N[(x * x), $MachinePrecision] * x), $MachinePrecision]}, Block[{t$95$6 = N[(t$95$3 / t$95$5), $MachinePrecision]}, N[(N[(0.041666666666666664 * t$95$4 + N[(n * N[(-0.25 * t$95$4 + N[(0.16666666666666666 * t$95$6 + N[(n * N[(-1.0 * N[(N[(N[(N[(-1.0 * n), $MachinePrecision] * t$95$1), $MachinePrecision] + N[(-0.3333333333333333 * N[(t$95$2 / N[(x * x), $MachinePrecision]), $MachinePrecision] + N[(0.25 * N[(t$95$2 / t$95$5), $MachinePrecision] + N[(0.5 * N[(t$95$2 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] + N[(-0.5 * t$95$6 + N[(0.4583333333333333 * t$95$4 + N[(0.5 * N[(t$95$3 / N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Power[n, 4.0], $MachinePrecision]), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-1 \cdot \log x}{n}\\
t_1 := {\left(e^{-1}\right)}^{t\_0}\\
t_2 := n \cdot t\_1\\
t_3 := e^{-1 \cdot t\_0}\\
t_4 := \frac{t\_3}{{x}^{4}}\\
t_5 := \left(x \cdot x\right) \cdot x\\
t_6 := \frac{t\_3}{t\_5}\\
\frac{\mathsf{fma}\left(0.041666666666666664, t\_4, n \cdot \mathsf{fma}\left(-0.25, t\_4, \mathsf{fma}\left(0.16666666666666666, t\_6, n \cdot \mathsf{fma}\left(-1, \frac{\left(-1 \cdot n\right) \cdot t\_1 + \mathsf{fma}\left(-0.3333333333333333, \frac{t\_2}{x \cdot x}, \mathsf{fma}\left(0.25, \frac{t\_2}{t\_5}, 0.5 \cdot \frac{t\_2}{x}\right)\right)}{x}, \mathsf{fma}\left(-0.5, t\_6, \mathsf{fma}\left(0.4583333333333333, t\_4, 0.5 \cdot \frac{t\_3}{x \cdot x}\right)\right)\right)\right)\right)\right)}{{n}^{4}}
\end{array}
\end{array}
Initial program 51.9%
Taylor expanded in x around inf
Applied rewrites9.7%
Taylor expanded in n around 0
Applied rewrites12.8%
Taylor expanded in x around inf
lower-/.f64N/A
Applied rewrites12.8%
Final simplification12.8%
herbie shell --seed 2025066
(FPCore (x n)
:name "2nthrt (problem 3.4.6)"
:precision binary64
(- (pow (+ x 1.0) (/ 1.0 n)) (pow x (/ 1.0 n))))