
(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 17 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
(let* ((t_0 (pow x (/ (pow n -1.0) 4.0))))
(if (<= (pow n -1.0) -5e-57)
(/ (exp (/ (log x) n)) (* n x))
(if (<= (pow n -1.0) 2e-5)
(/
(/
(fma
(log (/ x (+ 1.0 x)))
n
(* (- (pow (log1p x) 2.0) (pow (log x) 2.0)) -0.5))
n)
(- n))
(fma
(* (sqrt (pow x (pow n -1.0))) (- t_0))
t_0
(exp (/ (log1p x) n)))))))
double code(double x, double n) {
double t_0 = pow(x, (pow(n, -1.0) / 4.0));
double tmp;
if (pow(n, -1.0) <= -5e-57) {
tmp = exp((log(x) / n)) / (n * x);
} else if (pow(n, -1.0) <= 2e-5) {
tmp = (fma(log((x / (1.0 + x))), n, ((pow(log1p(x), 2.0) - pow(log(x), 2.0)) * -0.5)) / n) / -n;
} else {
tmp = fma((sqrt(pow(x, pow(n, -1.0))) * -t_0), t_0, exp((log1p(x) / n)));
}
return tmp;
}
function code(x, n) t_0 = x ^ Float64((n ^ -1.0) / 4.0) tmp = 0.0 if ((n ^ -1.0) <= -5e-57) tmp = Float64(exp(Float64(log(x) / n)) / Float64(n * x)); elseif ((n ^ -1.0) <= 2e-5) tmp = Float64(Float64(fma(log(Float64(x / Float64(1.0 + x))), n, Float64(Float64((log1p(x) ^ 2.0) - (log(x) ^ 2.0)) * -0.5)) / n) / Float64(-n)); else tmp = fma(Float64(sqrt((x ^ (n ^ -1.0))) * Float64(-t_0)), t_0, exp(Float64(log1p(x) / n))); end return tmp end
code[x_, n_] := Block[{t$95$0 = N[Power[x, N[(N[Power[n, -1.0], $MachinePrecision] / 4.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[Power[n, -1.0], $MachinePrecision], -5e-57], N[(N[Exp[N[(N[Log[x], $MachinePrecision] / n), $MachinePrecision]], $MachinePrecision] / N[(n * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Power[n, -1.0], $MachinePrecision], 2e-5], N[(N[(N[(N[Log[N[(x / N[(1.0 + x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * n + N[(N[(N[Power[N[Log[1 + x], $MachinePrecision], 2.0], $MachinePrecision] - N[Power[N[Log[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision] / (-n)), $MachinePrecision], N[(N[(N[Sqrt[N[Power[x, N[Power[n, -1.0], $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * (-t$95$0)), $MachinePrecision] * t$95$0 + N[Exp[N[(N[Log[1 + x], $MachinePrecision] / n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {x}^{\left(\frac{{n}^{-1}}{4}\right)}\\
\mathbf{if}\;{n}^{-1} \leq -5 \cdot 10^{-57}:\\
\;\;\;\;\frac{e^{\frac{\log x}{n}}}{n \cdot x}\\
\mathbf{elif}\;{n}^{-1} \leq 2 \cdot 10^{-5}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(\log \left(\frac{x}{1 + x}\right), n, \left({\left(\mathsf{log1p}\left(x\right)\right)}^{2} - {\log x}^{2}\right) \cdot -0.5\right)}{n}}{-n}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\sqrt{{x}^{\left({n}^{-1}\right)}} \cdot \left(-t\_0\right), t\_0, e^{\frac{\mathsf{log1p}\left(x\right)}{n}}\right)\\
\end{array}
\end{array}
if (/.f64 #s(literal 1 binary64) n) < -5.0000000000000002e-57Initial program 83.4%
Taylor expanded in x around inf
lower-/.f64N/A
*-commutativeN/A
log-recN/A
mul-1-negN/A
*-commutativeN/A
associate-*r/N/A
mul-1-negN/A
distribute-lft-neg-inN/A
metadata-evalN/A
*-lft-identityN/A
lower-exp.f64N/A
lower-/.f64N/A
lower-log.f64N/A
lower-*.f6496.6
Applied rewrites96.6%
if -5.0000000000000002e-57 < (/.f64 #s(literal 1 binary64) n) < 2.00000000000000016e-5Initial program 31.1%
Taylor expanded in n around -inf
mul-1-negN/A
distribute-neg-frac2N/A
lower-/.f64N/A
Applied rewrites80.6%
Taylor expanded in n around 0
Applied rewrites80.6%
Applied rewrites80.8%
if 2.00000000000000016e-5 < (/.f64 #s(literal 1 binary64) n) Initial program 58.0%
lift--.f64N/A
lift-pow.f64N/A
sqr-powN/A
fp-cancel-sub-sign-invN/A
distribute-lft-neg-inN/A
sqr-powN/A
lift-pow.f64N/A
+-commutativeN/A
lift-pow.f64N/A
sqr-powN/A
distribute-lft-neg-inN/A
sqr-powN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites95.1%
Final simplification88.5%
(FPCore (x n)
:precision binary64
(let* ((t_0 (pow x (pow n -1.0))) (t_1 (- (pow (+ x 1.0) (pow n -1.0)) t_0)))
(if (<= t_1 (- INFINITY))
(- 1.0 t_0)
(if (<= t_1 0.0001)
(/ (- (log1p x) (log x)) n)
(- (fma (fma (/ (+ -0.5 (/ 0.5 n)) n) x (pow n -1.0)) x 1.0) t_0)))))
double code(double x, double n) {
double t_0 = pow(x, pow(n, -1.0));
double t_1 = pow((x + 1.0), pow(n, -1.0)) - t_0;
double tmp;
if (t_1 <= -((double) INFINITY)) {
tmp = 1.0 - t_0;
} else if (t_1 <= 0.0001) {
tmp = (log1p(x) - log(x)) / n;
} else {
tmp = fma(fma(((-0.5 + (0.5 / n)) / n), x, pow(n, -1.0)), x, 1.0) - t_0;
}
return tmp;
}
function code(x, n) t_0 = x ^ (n ^ -1.0) t_1 = Float64((Float64(x + 1.0) ^ (n ^ -1.0)) - t_0) tmp = 0.0 if (t_1 <= Float64(-Inf)) tmp = Float64(1.0 - t_0); elseif (t_1 <= 0.0001) tmp = Float64(Float64(log1p(x) - log(x)) / n); else tmp = Float64(fma(fma(Float64(Float64(-0.5 + Float64(0.5 / n)) / n), x, (n ^ -1.0)), x, 1.0) - t_0); end return tmp end
code[x_, n_] := Block[{t$95$0 = N[Power[x, N[Power[n, -1.0], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Power[N[(x + 1.0), $MachinePrecision], N[Power[n, -1.0], $MachinePrecision]], $MachinePrecision] - t$95$0), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], N[(1.0 - t$95$0), $MachinePrecision], If[LessEqual[t$95$1, 0.0001], N[(N[(N[Log[1 + x], $MachinePrecision] - N[Log[x], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision], N[(N[(N[(N[(N[(-0.5 + N[(0.5 / n), $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision] * x + N[Power[n, -1.0], $MachinePrecision]), $MachinePrecision] * x + 1.0), $MachinePrecision] - t$95$0), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {x}^{\left({n}^{-1}\right)}\\
t_1 := {\left(x + 1\right)}^{\left({n}^{-1}\right)} - t\_0\\
\mathbf{if}\;t\_1 \leq -\infty:\\
\;\;\;\;1 - t\_0\\
\mathbf{elif}\;t\_1 \leq 0.0001:\\
\;\;\;\;\frac{\mathsf{log1p}\left(x\right) - \log x}{n}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\frac{-0.5 + \frac{0.5}{n}}{n}, x, {n}^{-1}\right), x, 1\right) - t\_0\\
\end{array}
\end{array}
if (-.f64 (pow.f64 (+.f64 x #s(literal 1 binary64)) (/.f64 #s(literal 1 binary64) n)) (pow.f64 x (/.f64 #s(literal 1 binary64) n))) < -inf.0Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites100.0%
if -inf.0 < (-.f64 (pow.f64 (+.f64 x #s(literal 1 binary64)) (/.f64 #s(literal 1 binary64) n)) (pow.f64 x (/.f64 #s(literal 1 binary64) n))) < 1.00000000000000005e-4Initial program 44.1%
Taylor expanded in n around inf
lower-/.f64N/A
lower--.f64N/A
lower-log1p.f64N/A
lower-log.f6477.9
Applied rewrites77.9%
if 1.00000000000000005e-4 < (-.f64 (pow.f64 (+.f64 x #s(literal 1 binary64)) (/.f64 #s(literal 1 binary64) n)) (pow.f64 x (/.f64 #s(literal 1 binary64) n))) Initial program 58.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites65.1%
Final simplification78.9%
(FPCore (x n)
:precision binary64
(if (<= x 4100000.0)
(/
(-
(+
(log1p x)
(/
(fma
0.16666666666666666
(/ (- (pow (log1p x) 3.0) (pow (log x) 3.0)) n)
(* (- (pow (log1p x) 2.0) (pow (log x) 2.0)) 0.5))
n))
(log x))
n)
(/ (/ (exp (/ (log x) n)) x) n)))
double code(double x, double n) {
double tmp;
if (x <= 4100000.0) {
tmp = ((log1p(x) + (fma(0.16666666666666666, ((pow(log1p(x), 3.0) - pow(log(x), 3.0)) / n), ((pow(log1p(x), 2.0) - pow(log(x), 2.0)) * 0.5)) / n)) - log(x)) / n;
} else {
tmp = (exp((log(x) / n)) / x) / n;
}
return tmp;
}
function code(x, n) tmp = 0.0 if (x <= 4100000.0) tmp = Float64(Float64(Float64(log1p(x) + Float64(fma(0.16666666666666666, Float64(Float64((log1p(x) ^ 3.0) - (log(x) ^ 3.0)) / n), Float64(Float64((log1p(x) ^ 2.0) - (log(x) ^ 2.0)) * 0.5)) / n)) - log(x)) / n); else tmp = Float64(Float64(exp(Float64(log(x) / n)) / x) / n); end return tmp end
code[x_, n_] := If[LessEqual[x, 4100000.0], N[(N[(N[(N[Log[1 + x], $MachinePrecision] + N[(N[(0.16666666666666666 * N[(N[(N[Power[N[Log[1 + x], $MachinePrecision], 3.0], $MachinePrecision] - N[Power[N[Log[x], $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision] + N[(N[(N[Power[N[Log[1 + x], $MachinePrecision], 2.0], $MachinePrecision] - N[Power[N[Log[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision]), $MachinePrecision] - N[Log[x], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision], N[(N[(N[Exp[N[(N[Log[x], $MachinePrecision] / n), $MachinePrecision]], $MachinePrecision] / x), $MachinePrecision] / n), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 4100000:\\
\;\;\;\;\frac{\left(\mathsf{log1p}\left(x\right) + \frac{\mathsf{fma}\left(0.16666666666666666, \frac{{\left(\mathsf{log1p}\left(x\right)\right)}^{3} - {\log x}^{3}}{n}, \left({\left(\mathsf{log1p}\left(x\right)\right)}^{2} - {\log x}^{2}\right) \cdot 0.5\right)}{n}\right) - \log x}{n}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{e^{\frac{\log x}{n}}}{x}}{n}\\
\end{array}
\end{array}
if x < 4.1e6Initial program 42.0%
Taylor expanded in n around -inf
Applied rewrites79.4%
if 4.1e6 < x Initial program 66.8%
Taylor expanded in x around inf
lower-/.f64N/A
*-commutativeN/A
log-recN/A
mul-1-negN/A
*-commutativeN/A
associate-*r/N/A
mul-1-negN/A
distribute-lft-neg-inN/A
metadata-evalN/A
*-lft-identityN/A
lower-exp.f64N/A
lower-/.f64N/A
lower-log.f64N/A
lower-*.f6498.8
Applied rewrites98.8%
Applied rewrites99.2%
Final simplification88.4%
(FPCore (x n)
:precision binary64
(if (<= x 4100000.0)
(/
(-
(+
(log1p x)
(/
(fma
0.16666666666666666
(/
(- (* (fma (- (* 1.75 x) 1.5) x 1.0) (pow x 3.0)) (pow (log x) 3.0))
n)
(* (- (pow (log1p x) 2.0) (pow (log x) 2.0)) 0.5))
n))
(log x))
n)
(/ (/ (exp (/ (log x) n)) x) n)))
double code(double x, double n) {
double tmp;
if (x <= 4100000.0) {
tmp = ((log1p(x) + (fma(0.16666666666666666, (((fma(((1.75 * x) - 1.5), x, 1.0) * pow(x, 3.0)) - pow(log(x), 3.0)) / n), ((pow(log1p(x), 2.0) - pow(log(x), 2.0)) * 0.5)) / n)) - log(x)) / n;
} else {
tmp = (exp((log(x) / n)) / x) / n;
}
return tmp;
}
function code(x, n) tmp = 0.0 if (x <= 4100000.0) tmp = Float64(Float64(Float64(log1p(x) + Float64(fma(0.16666666666666666, Float64(Float64(Float64(fma(Float64(Float64(1.75 * x) - 1.5), x, 1.0) * (x ^ 3.0)) - (log(x) ^ 3.0)) / n), Float64(Float64((log1p(x) ^ 2.0) - (log(x) ^ 2.0)) * 0.5)) / n)) - log(x)) / n); else tmp = Float64(Float64(exp(Float64(log(x) / n)) / x) / n); end return tmp end
code[x_, n_] := If[LessEqual[x, 4100000.0], N[(N[(N[(N[Log[1 + x], $MachinePrecision] + N[(N[(0.16666666666666666 * N[(N[(N[(N[(N[(N[(1.75 * x), $MachinePrecision] - 1.5), $MachinePrecision] * x + 1.0), $MachinePrecision] * N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision] - N[Power[N[Log[x], $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision] + N[(N[(N[Power[N[Log[1 + x], $MachinePrecision], 2.0], $MachinePrecision] - N[Power[N[Log[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision]), $MachinePrecision] - N[Log[x], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision], N[(N[(N[Exp[N[(N[Log[x], $MachinePrecision] / n), $MachinePrecision]], $MachinePrecision] / x), $MachinePrecision] / n), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 4100000:\\
\;\;\;\;\frac{\left(\mathsf{log1p}\left(x\right) + \frac{\mathsf{fma}\left(0.16666666666666666, \frac{\mathsf{fma}\left(1.75 \cdot x - 1.5, x, 1\right) \cdot {x}^{3} - {\log x}^{3}}{n}, \left({\left(\mathsf{log1p}\left(x\right)\right)}^{2} - {\log x}^{2}\right) \cdot 0.5\right)}{n}\right) - \log x}{n}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{e^{\frac{\log x}{n}}}{x}}{n}\\
\end{array}
\end{array}
if x < 4.1e6Initial program 42.0%
Taylor expanded in n around -inf
Applied rewrites79.4%
Taylor expanded in x around 0
Applied rewrites79.4%
if 4.1e6 < x Initial program 66.8%
Taylor expanded in x around inf
lower-/.f64N/A
*-commutativeN/A
log-recN/A
mul-1-negN/A
*-commutativeN/A
associate-*r/N/A
mul-1-negN/A
distribute-lft-neg-inN/A
metadata-evalN/A
*-lft-identityN/A
lower-exp.f64N/A
lower-/.f64N/A
lower-log.f64N/A
lower-*.f6498.8
Applied rewrites98.8%
Applied rewrites99.2%
Final simplification88.4%
(FPCore (x n)
:precision binary64
(if (<= x 4100000.0)
(/
(-
(+
(log1p x)
(/
(fma
0.16666666666666666
(/ (- (* (fma -1.5 x 1.0) (pow x 3.0)) (pow (log x) 3.0)) n)
(* (- (pow (log1p x) 2.0) (pow (log x) 2.0)) 0.5))
n))
(log x))
n)
(/ (/ (exp (/ (log x) n)) x) n)))
double code(double x, double n) {
double tmp;
if (x <= 4100000.0) {
tmp = ((log1p(x) + (fma(0.16666666666666666, (((fma(-1.5, x, 1.0) * pow(x, 3.0)) - pow(log(x), 3.0)) / n), ((pow(log1p(x), 2.0) - pow(log(x), 2.0)) * 0.5)) / n)) - log(x)) / n;
} else {
tmp = (exp((log(x) / n)) / x) / n;
}
return tmp;
}
function code(x, n) tmp = 0.0 if (x <= 4100000.0) tmp = Float64(Float64(Float64(log1p(x) + Float64(fma(0.16666666666666666, Float64(Float64(Float64(fma(-1.5, x, 1.0) * (x ^ 3.0)) - (log(x) ^ 3.0)) / n), Float64(Float64((log1p(x) ^ 2.0) - (log(x) ^ 2.0)) * 0.5)) / n)) - log(x)) / n); else tmp = Float64(Float64(exp(Float64(log(x) / n)) / x) / n); end return tmp end
code[x_, n_] := If[LessEqual[x, 4100000.0], N[(N[(N[(N[Log[1 + x], $MachinePrecision] + N[(N[(0.16666666666666666 * N[(N[(N[(N[(-1.5 * x + 1.0), $MachinePrecision] * N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision] - N[Power[N[Log[x], $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision] + N[(N[(N[Power[N[Log[1 + x], $MachinePrecision], 2.0], $MachinePrecision] - N[Power[N[Log[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision]), $MachinePrecision] - N[Log[x], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision], N[(N[(N[Exp[N[(N[Log[x], $MachinePrecision] / n), $MachinePrecision]], $MachinePrecision] / x), $MachinePrecision] / n), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 4100000:\\
\;\;\;\;\frac{\left(\mathsf{log1p}\left(x\right) + \frac{\mathsf{fma}\left(0.16666666666666666, \frac{\mathsf{fma}\left(-1.5, x, 1\right) \cdot {x}^{3} - {\log x}^{3}}{n}, \left({\left(\mathsf{log1p}\left(x\right)\right)}^{2} - {\log x}^{2}\right) \cdot 0.5\right)}{n}\right) - \log x}{n}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{e^{\frac{\log x}{n}}}{x}}{n}\\
\end{array}
\end{array}
if x < 4.1e6Initial program 42.0%
Taylor expanded in n around -inf
Applied rewrites79.4%
Taylor expanded in x around 0
Applied rewrites79.4%
if 4.1e6 < x Initial program 66.8%
Taylor expanded in x around inf
lower-/.f64N/A
*-commutativeN/A
log-recN/A
mul-1-negN/A
*-commutativeN/A
associate-*r/N/A
mul-1-negN/A
distribute-lft-neg-inN/A
metadata-evalN/A
*-lft-identityN/A
lower-exp.f64N/A
lower-/.f64N/A
lower-log.f64N/A
lower-*.f6498.8
Applied rewrites98.8%
Applied rewrites99.2%
Final simplification88.4%
(FPCore (x n)
:precision binary64
(if (<= (pow n -1.0) -5e-57)
(/ (exp (/ (log x) n)) (* n x))
(if (<= (pow n -1.0) 1e-14)
(/
(/
(fma
(log (/ x (+ 1.0 x)))
n
(* (- (pow (log1p x) 2.0) (pow (log x) 2.0)) -0.5))
n)
(- n))
(- (exp (/ (log1p x) n)) (pow x (pow n -1.0))))))
double code(double x, double n) {
double tmp;
if (pow(n, -1.0) <= -5e-57) {
tmp = exp((log(x) / n)) / (n * x);
} else if (pow(n, -1.0) <= 1e-14) {
tmp = (fma(log((x / (1.0 + x))), n, ((pow(log1p(x), 2.0) - pow(log(x), 2.0)) * -0.5)) / n) / -n;
} else {
tmp = exp((log1p(x) / n)) - pow(x, pow(n, -1.0));
}
return tmp;
}
function code(x, n) tmp = 0.0 if ((n ^ -1.0) <= -5e-57) tmp = Float64(exp(Float64(log(x) / n)) / Float64(n * x)); elseif ((n ^ -1.0) <= 1e-14) tmp = Float64(Float64(fma(log(Float64(x / Float64(1.0 + x))), n, Float64(Float64((log1p(x) ^ 2.0) - (log(x) ^ 2.0)) * -0.5)) / n) / Float64(-n)); else tmp = Float64(exp(Float64(log1p(x) / n)) - (x ^ (n ^ -1.0))); end return tmp end
code[x_, n_] := If[LessEqual[N[Power[n, -1.0], $MachinePrecision], -5e-57], N[(N[Exp[N[(N[Log[x], $MachinePrecision] / n), $MachinePrecision]], $MachinePrecision] / N[(n * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Power[n, -1.0], $MachinePrecision], 1e-14], N[(N[(N[(N[Log[N[(x / N[(1.0 + x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * n + N[(N[(N[Power[N[Log[1 + x], $MachinePrecision], 2.0], $MachinePrecision] - N[Power[N[Log[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision] / (-n)), $MachinePrecision], N[(N[Exp[N[(N[Log[1 + x], $MachinePrecision] / n), $MachinePrecision]], $MachinePrecision] - N[Power[x, N[Power[n, -1.0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;{n}^{-1} \leq -5 \cdot 10^{-57}:\\
\;\;\;\;\frac{e^{\frac{\log x}{n}}}{n \cdot x}\\
\mathbf{elif}\;{n}^{-1} \leq 10^{-14}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(\log \left(\frac{x}{1 + x}\right), n, \left({\left(\mathsf{log1p}\left(x\right)\right)}^{2} - {\log x}^{2}\right) \cdot -0.5\right)}{n}}{-n}\\
\mathbf{else}:\\
\;\;\;\;e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left({n}^{-1}\right)}\\
\end{array}
\end{array}
if (/.f64 #s(literal 1 binary64) n) < -5.0000000000000002e-57Initial program 83.4%
Taylor expanded in x around inf
lower-/.f64N/A
*-commutativeN/A
log-recN/A
mul-1-negN/A
*-commutativeN/A
associate-*r/N/A
mul-1-negN/A
distribute-lft-neg-inN/A
metadata-evalN/A
*-lft-identityN/A
lower-exp.f64N/A
lower-/.f64N/A
lower-log.f64N/A
lower-*.f6496.6
Applied rewrites96.6%
if -5.0000000000000002e-57 < (/.f64 #s(literal 1 binary64) n) < 9.99999999999999999e-15Initial program 31.3%
Taylor expanded in n around -inf
mul-1-negN/A
distribute-neg-frac2N/A
lower-/.f64N/A
Applied rewrites81.2%
Taylor expanded in n around 0
Applied rewrites81.2%
Applied rewrites81.4%
if 9.99999999999999999e-15 < (/.f64 #s(literal 1 binary64) n) Initial program 56.6%
lift-pow.f64N/A
pow-to-expN/A
lower-exp.f64N/A
lift-/.f64N/A
associate-*r/N/A
*-rgt-identityN/A
lower-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lower-log1p.f6492.8
Applied rewrites92.8%
Final simplification88.4%
(FPCore (x n)
:precision binary64
(if (<= (pow n -1.0) -5e-57)
(/ (exp (/ (log x) n)) (* n x))
(if (<= (pow n -1.0) 1e-14)
(/ (- (log1p x) (log x)) n)
(- (exp (/ (log1p x) n)) (pow x (pow n -1.0))))))
double code(double x, double n) {
double tmp;
if (pow(n, -1.0) <= -5e-57) {
tmp = exp((log(x) / n)) / (n * x);
} else if (pow(n, -1.0) <= 1e-14) {
tmp = (log1p(x) - log(x)) / n;
} else {
tmp = exp((log1p(x) / n)) - pow(x, pow(n, -1.0));
}
return tmp;
}
public static double code(double x, double n) {
double tmp;
if (Math.pow(n, -1.0) <= -5e-57) {
tmp = Math.exp((Math.log(x) / n)) / (n * x);
} else if (Math.pow(n, -1.0) <= 1e-14) {
tmp = (Math.log1p(x) - Math.log(x)) / n;
} else {
tmp = Math.exp((Math.log1p(x) / n)) - Math.pow(x, Math.pow(n, -1.0));
}
return tmp;
}
def code(x, n): tmp = 0 if math.pow(n, -1.0) <= -5e-57: tmp = math.exp((math.log(x) / n)) / (n * x) elif math.pow(n, -1.0) <= 1e-14: tmp = (math.log1p(x) - math.log(x)) / n else: tmp = math.exp((math.log1p(x) / n)) - math.pow(x, math.pow(n, -1.0)) return tmp
function code(x, n) tmp = 0.0 if ((n ^ -1.0) <= -5e-57) tmp = Float64(exp(Float64(log(x) / n)) / Float64(n * x)); elseif ((n ^ -1.0) <= 1e-14) tmp = Float64(Float64(log1p(x) - log(x)) / n); else tmp = Float64(exp(Float64(log1p(x) / n)) - (x ^ (n ^ -1.0))); end return tmp end
code[x_, n_] := If[LessEqual[N[Power[n, -1.0], $MachinePrecision], -5e-57], N[(N[Exp[N[(N[Log[x], $MachinePrecision] / n), $MachinePrecision]], $MachinePrecision] / N[(n * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Power[n, -1.0], $MachinePrecision], 1e-14], N[(N[(N[Log[1 + x], $MachinePrecision] - N[Log[x], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision], N[(N[Exp[N[(N[Log[1 + x], $MachinePrecision] / n), $MachinePrecision]], $MachinePrecision] - N[Power[x, N[Power[n, -1.0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;{n}^{-1} \leq -5 \cdot 10^{-57}:\\
\;\;\;\;\frac{e^{\frac{\log x}{n}}}{n \cdot x}\\
\mathbf{elif}\;{n}^{-1} \leq 10^{-14}:\\
\;\;\;\;\frac{\mathsf{log1p}\left(x\right) - \log x}{n}\\
\mathbf{else}:\\
\;\;\;\;e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left({n}^{-1}\right)}\\
\end{array}
\end{array}
if (/.f64 #s(literal 1 binary64) n) < -5.0000000000000002e-57Initial program 83.4%
Taylor expanded in x around inf
lower-/.f64N/A
*-commutativeN/A
log-recN/A
mul-1-negN/A
*-commutativeN/A
associate-*r/N/A
mul-1-negN/A
distribute-lft-neg-inN/A
metadata-evalN/A
*-lft-identityN/A
lower-exp.f64N/A
lower-/.f64N/A
lower-log.f64N/A
lower-*.f6496.6
Applied rewrites96.6%
if -5.0000000000000002e-57 < (/.f64 #s(literal 1 binary64) n) < 9.99999999999999999e-15Initial program 31.3%
Taylor expanded in n around inf
lower-/.f64N/A
lower--.f64N/A
lower-log1p.f64N/A
lower-log.f6481.2
Applied rewrites81.2%
if 9.99999999999999999e-15 < (/.f64 #s(literal 1 binary64) n) Initial program 56.6%
lift-pow.f64N/A
pow-to-expN/A
lower-exp.f64N/A
lift-/.f64N/A
associate-*r/N/A
*-rgt-identityN/A
lower-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lower-log1p.f6492.8
Applied rewrites92.8%
Final simplification88.3%
(FPCore (x n)
:precision binary64
(if (<= (pow n -1.0) -5e-57)
(/ (exp (/ (log x) n)) (* n x))
(if (<= (pow n -1.0) 100000.0)
(/ (- (log1p x) (log x)) n)
(-
(fma (fma (/ (+ -0.5 (/ 0.5 n)) n) x (pow n -1.0)) x 1.0)
(pow x (pow n -1.0))))))
double code(double x, double n) {
double tmp;
if (pow(n, -1.0) <= -5e-57) {
tmp = exp((log(x) / n)) / (n * x);
} else if (pow(n, -1.0) <= 100000.0) {
tmp = (log1p(x) - log(x)) / n;
} else {
tmp = fma(fma(((-0.5 + (0.5 / n)) / n), x, pow(n, -1.0)), x, 1.0) - pow(x, pow(n, -1.0));
}
return tmp;
}
function code(x, n) tmp = 0.0 if ((n ^ -1.0) <= -5e-57) tmp = Float64(exp(Float64(log(x) / n)) / Float64(n * x)); elseif ((n ^ -1.0) <= 100000.0) tmp = Float64(Float64(log1p(x) - log(x)) / n); else tmp = Float64(fma(fma(Float64(Float64(-0.5 + Float64(0.5 / n)) / n), x, (n ^ -1.0)), x, 1.0) - (x ^ (n ^ -1.0))); end return tmp end
code[x_, n_] := If[LessEqual[N[Power[n, -1.0], $MachinePrecision], -5e-57], N[(N[Exp[N[(N[Log[x], $MachinePrecision] / n), $MachinePrecision]], $MachinePrecision] / N[(n * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Power[n, -1.0], $MachinePrecision], 100000.0], N[(N[(N[Log[1 + x], $MachinePrecision] - N[Log[x], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision], N[(N[(N[(N[(N[(-0.5 + N[(0.5 / n), $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision] * x + N[Power[n, -1.0], $MachinePrecision]), $MachinePrecision] * x + 1.0), $MachinePrecision] - N[Power[x, N[Power[n, -1.0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;{n}^{-1} \leq -5 \cdot 10^{-57}:\\
\;\;\;\;\frac{e^{\frac{\log x}{n}}}{n \cdot x}\\
\mathbf{elif}\;{n}^{-1} \leq 100000:\\
\;\;\;\;\frac{\mathsf{log1p}\left(x\right) - \log x}{n}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\frac{-0.5 + \frac{0.5}{n}}{n}, x, {n}^{-1}\right), x, 1\right) - {x}^{\left({n}^{-1}\right)}\\
\end{array}
\end{array}
if (/.f64 #s(literal 1 binary64) n) < -5.0000000000000002e-57Initial program 83.4%
Taylor expanded in x around inf
lower-/.f64N/A
*-commutativeN/A
log-recN/A
mul-1-negN/A
*-commutativeN/A
associate-*r/N/A
mul-1-negN/A
distribute-lft-neg-inN/A
metadata-evalN/A
*-lft-identityN/A
lower-exp.f64N/A
lower-/.f64N/A
lower-log.f64N/A
lower-*.f6496.6
Applied rewrites96.6%
if -5.0000000000000002e-57 < (/.f64 #s(literal 1 binary64) n) < 1e5Initial program 31.2%
Taylor expanded in n around inf
lower-/.f64N/A
lower--.f64N/A
lower-log1p.f64N/A
lower-log.f6479.3
Applied rewrites79.3%
if 1e5 < (/.f64 #s(literal 1 binary64) n) Initial program 59.7%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites66.9%
Final simplification83.6%
(FPCore (x n)
:precision binary64
(if (<= (pow n -1.0) -5e-57)
(/ (exp (/ (log x) n)) (* n x))
(if (<= (pow n -1.0) 100000.0)
(/ (- (log1p x) (log x)) n)
(- (pow (fma 0.5 (/ x n) 1.0) 2.0) (pow x (pow n -1.0))))))
double code(double x, double n) {
double tmp;
if (pow(n, -1.0) <= -5e-57) {
tmp = exp((log(x) / n)) / (n * x);
} else if (pow(n, -1.0) <= 100000.0) {
tmp = (log1p(x) - log(x)) / n;
} else {
tmp = pow(fma(0.5, (x / n), 1.0), 2.0) - pow(x, pow(n, -1.0));
}
return tmp;
}
function code(x, n) tmp = 0.0 if ((n ^ -1.0) <= -5e-57) tmp = Float64(exp(Float64(log(x) / n)) / Float64(n * x)); elseif ((n ^ -1.0) <= 100000.0) tmp = Float64(Float64(log1p(x) - log(x)) / n); else tmp = Float64((fma(0.5, Float64(x / n), 1.0) ^ 2.0) - (x ^ (n ^ -1.0))); end return tmp end
code[x_, n_] := If[LessEqual[N[Power[n, -1.0], $MachinePrecision], -5e-57], N[(N[Exp[N[(N[Log[x], $MachinePrecision] / n), $MachinePrecision]], $MachinePrecision] / N[(n * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Power[n, -1.0], $MachinePrecision], 100000.0], N[(N[(N[Log[1 + x], $MachinePrecision] - N[Log[x], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision], N[(N[Power[N[(0.5 * N[(x / n), $MachinePrecision] + 1.0), $MachinePrecision], 2.0], $MachinePrecision] - N[Power[x, N[Power[n, -1.0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;{n}^{-1} \leq -5 \cdot 10^{-57}:\\
\;\;\;\;\frac{e^{\frac{\log x}{n}}}{n \cdot x}\\
\mathbf{elif}\;{n}^{-1} \leq 100000:\\
\;\;\;\;\frac{\mathsf{log1p}\left(x\right) - \log x}{n}\\
\mathbf{else}:\\
\;\;\;\;{\left(\mathsf{fma}\left(0.5, \frac{x}{n}, 1\right)\right)}^{2} - {x}^{\left({n}^{-1}\right)}\\
\end{array}
\end{array}
if (/.f64 #s(literal 1 binary64) n) < -5.0000000000000002e-57Initial program 83.4%
Taylor expanded in x around inf
lower-/.f64N/A
*-commutativeN/A
log-recN/A
mul-1-negN/A
*-commutativeN/A
associate-*r/N/A
mul-1-negN/A
distribute-lft-neg-inN/A
metadata-evalN/A
*-lft-identityN/A
lower-exp.f64N/A
lower-/.f64N/A
lower-log.f64N/A
lower-*.f6496.6
Applied rewrites96.6%
if -5.0000000000000002e-57 < (/.f64 #s(literal 1 binary64) n) < 1e5Initial program 31.2%
Taylor expanded in n around inf
lower-/.f64N/A
lower--.f64N/A
lower-log1p.f64N/A
lower-log.f6479.3
Applied rewrites79.3%
if 1e5 < (/.f64 #s(literal 1 binary64) n) Initial program 59.7%
lift-pow.f64N/A
sqr-powN/A
pow-sqrN/A
sqr-powN/A
pow2N/A
lower-pow.f64N/A
lower-pow.f64N/A
lift-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-/.f64N/A
count-2-revN/A
div-add-revN/A
lower-/.f64N/A
lift-/.f64N/A
lift-/.f64N/A
div-add-revN/A
metadata-evalN/A
lower-/.f6459.7
Applied rewrites59.7%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
lower-/.f6473.5
Applied rewrites73.5%
Final simplification84.5%
(FPCore (x n) :precision binary64 (if (<= (- (pow (+ x 1.0) (pow n -1.0)) (pow x (pow n -1.0))) 0.0001) (/ (pow n -1.0) x) (* (* (- x) x) (- (/ 0.5 n) (/ 0.5 (* n n))))))
double code(double x, double n) {
double tmp;
if ((pow((x + 1.0), pow(n, -1.0)) - pow(x, pow(n, -1.0))) <= 0.0001) {
tmp = pow(n, -1.0) / x;
} else {
tmp = (-x * x) * ((0.5 / n) - (0.5 / (n * n)));
}
return tmp;
}
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
real(8) :: tmp
if ((((x + 1.0d0) ** (n ** (-1.0d0))) - (x ** (n ** (-1.0d0)))) <= 0.0001d0) then
tmp = (n ** (-1.0d0)) / x
else
tmp = (-x * x) * ((0.5d0 / n) - (0.5d0 / (n * n)))
end if
code = tmp
end function
public static double code(double x, double n) {
double tmp;
if ((Math.pow((x + 1.0), Math.pow(n, -1.0)) - Math.pow(x, Math.pow(n, -1.0))) <= 0.0001) {
tmp = Math.pow(n, -1.0) / x;
} else {
tmp = (-x * x) * ((0.5 / n) - (0.5 / (n * n)));
}
return tmp;
}
def code(x, n): tmp = 0 if (math.pow((x + 1.0), math.pow(n, -1.0)) - math.pow(x, math.pow(n, -1.0))) <= 0.0001: tmp = math.pow(n, -1.0) / x else: tmp = (-x * x) * ((0.5 / n) - (0.5 / (n * n))) return tmp
function code(x, n) tmp = 0.0 if (Float64((Float64(x + 1.0) ^ (n ^ -1.0)) - (x ^ (n ^ -1.0))) <= 0.0001) tmp = Float64((n ^ -1.0) / x); else tmp = Float64(Float64(Float64(-x) * x) * Float64(Float64(0.5 / n) - Float64(0.5 / Float64(n * n)))); end return tmp end
function tmp_2 = code(x, n) tmp = 0.0; if ((((x + 1.0) ^ (n ^ -1.0)) - (x ^ (n ^ -1.0))) <= 0.0001) tmp = (n ^ -1.0) / x; else tmp = (-x * x) * ((0.5 / n) - (0.5 / (n * n))); end tmp_2 = tmp; end
code[x_, n_] := If[LessEqual[N[(N[Power[N[(x + 1.0), $MachinePrecision], N[Power[n, -1.0], $MachinePrecision]], $MachinePrecision] - N[Power[x, N[Power[n, -1.0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 0.0001], N[(N[Power[n, -1.0], $MachinePrecision] / x), $MachinePrecision], N[(N[((-x) * x), $MachinePrecision] * N[(N[(0.5 / n), $MachinePrecision] - N[(0.5 / N[(n * n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;{\left(x + 1\right)}^{\left({n}^{-1}\right)} - {x}^{\left({n}^{-1}\right)} \leq 0.0001:\\
\;\;\;\;\frac{{n}^{-1}}{x}\\
\mathbf{else}:\\
\;\;\;\;\left(\left(-x\right) \cdot x\right) \cdot \left(\frac{0.5}{n} - \frac{0.5}{n \cdot n}\right)\\
\end{array}
\end{array}
if (-.f64 (pow.f64 (+.f64 x #s(literal 1 binary64)) (/.f64 #s(literal 1 binary64) n)) (pow.f64 x (/.f64 #s(literal 1 binary64) n))) < 1.00000000000000005e-4Initial program 52.5%
Taylor expanded in x around inf
lower-/.f64N/A
*-commutativeN/A
log-recN/A
mul-1-negN/A
*-commutativeN/A
associate-*r/N/A
mul-1-negN/A
distribute-lft-neg-inN/A
metadata-evalN/A
*-lft-identityN/A
lower-exp.f64N/A
lower-/.f64N/A
lower-log.f64N/A
lower-*.f6469.0
Applied rewrites69.0%
Taylor expanded in n around inf
Applied rewrites44.3%
if 1.00000000000000005e-4 < (-.f64 (pow.f64 (+.f64 x #s(literal 1 binary64)) (/.f64 #s(literal 1 binary64) n)) (pow.f64 x (/.f64 #s(literal 1 binary64) n))) Initial program 58.0%
Taylor expanded in n around -inf
mul-1-negN/A
distribute-neg-frac2N/A
lower-/.f64N/A
Applied rewrites0.6%
Taylor expanded in x around 0
Applied rewrites3.1%
Taylor expanded in x around inf
Applied rewrites29.4%
Final simplification42.2%
(FPCore (x n) :precision binary64 (if (<= x 1.0) (- 1.0 (pow x (pow n -1.0))) (/ (pow n -1.0) x)))
double code(double x, double n) {
double tmp;
if (x <= 1.0) {
tmp = 1.0 - pow(x, pow(n, -1.0));
} else {
tmp = pow(n, -1.0) / x;
}
return tmp;
}
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
real(8) :: tmp
if (x <= 1.0d0) then
tmp = 1.0d0 - (x ** (n ** (-1.0d0)))
else
tmp = (n ** (-1.0d0)) / x
end if
code = tmp
end function
public static double code(double x, double n) {
double tmp;
if (x <= 1.0) {
tmp = 1.0 - Math.pow(x, Math.pow(n, -1.0));
} else {
tmp = Math.pow(n, -1.0) / x;
}
return tmp;
}
def code(x, n): tmp = 0 if x <= 1.0: tmp = 1.0 - math.pow(x, math.pow(n, -1.0)) else: tmp = math.pow(n, -1.0) / x return tmp
function code(x, n) tmp = 0.0 if (x <= 1.0) tmp = Float64(1.0 - (x ^ (n ^ -1.0))); else tmp = Float64((n ^ -1.0) / x); end return tmp end
function tmp_2 = code(x, n) tmp = 0.0; if (x <= 1.0) tmp = 1.0 - (x ^ (n ^ -1.0)); else tmp = (n ^ -1.0) / x; end tmp_2 = tmp; end
code[x_, n_] := If[LessEqual[x, 1.0], N[(1.0 - N[Power[x, N[Power[n, -1.0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[Power[n, -1.0], $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;1 - {x}^{\left({n}^{-1}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{{n}^{-1}}{x}\\
\end{array}
\end{array}
if x < 1Initial program 43.1%
Taylor expanded in x around 0
Applied rewrites41.3%
if 1 < x Initial program 64.8%
Taylor expanded in x around inf
lower-/.f64N/A
*-commutativeN/A
log-recN/A
mul-1-negN/A
*-commutativeN/A
associate-*r/N/A
mul-1-negN/A
distribute-lft-neg-inN/A
metadata-evalN/A
*-lft-identityN/A
lower-exp.f64N/A
lower-/.f64N/A
lower-log.f64N/A
lower-*.f6496.8
Applied rewrites96.8%
Taylor expanded in n around inf
Applied rewrites63.0%
Final simplification51.5%
(FPCore (x n) :precision binary64 (if (<= x 0.205) (/ (fma (fma -0.5 x 1.0) x (- (log x))) n) (/ (/ (+ (/ (log x) n) 1.0) x) n)))
double code(double x, double n) {
double tmp;
if (x <= 0.205) {
tmp = fma(fma(-0.5, x, 1.0), x, -log(x)) / n;
} else {
tmp = (((log(x) / n) + 1.0) / x) / n;
}
return tmp;
}
function code(x, n) tmp = 0.0 if (x <= 0.205) tmp = Float64(fma(fma(-0.5, x, 1.0), x, Float64(-log(x))) / n); else tmp = Float64(Float64(Float64(Float64(log(x) / n) + 1.0) / x) / n); end return tmp end
code[x_, n_] := If[LessEqual[x, 0.205], N[(N[(N[(-0.5 * x + 1.0), $MachinePrecision] * x + (-N[Log[x], $MachinePrecision])), $MachinePrecision] / n), $MachinePrecision], N[(N[(N[(N[(N[Log[x], $MachinePrecision] / n), $MachinePrecision] + 1.0), $MachinePrecision] / x), $MachinePrecision] / n), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.205:\\
\;\;\;\;\frac{\mathsf{fma}\left(\mathsf{fma}\left(-0.5, x, 1\right), x, -\log x\right)}{n}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{\frac{\log x}{n} + 1}{x}}{n}\\
\end{array}
\end{array}
if x < 0.204999999999999988Initial program 42.7%
Taylor expanded in n around -inf
mul-1-negN/A
distribute-neg-frac2N/A
lower-/.f64N/A
Applied rewrites66.0%
Taylor expanded in x around 0
Applied rewrites50.4%
Taylor expanded in n around inf
Applied rewrites51.9%
if 0.204999999999999988 < x Initial program 65.1%
Taylor expanded in x around inf
lower-/.f64N/A
*-commutativeN/A
log-recN/A
mul-1-negN/A
*-commutativeN/A
associate-*r/N/A
mul-1-negN/A
distribute-lft-neg-inN/A
metadata-evalN/A
*-lft-identityN/A
lower-exp.f64N/A
lower-/.f64N/A
lower-log.f64N/A
lower-*.f6496.8
Applied rewrites96.8%
Taylor expanded in n around inf
Applied rewrites63.7%
(FPCore (x n)
:precision binary64
(let* ((t_0 (- (log x))))
(if (<= x 0.205)
(/ (fma (fma -0.5 x 1.0) x t_0) n)
(/ (fma (/ t_0 n) -1.0 1.0) (* n x)))))
double code(double x, double n) {
double t_0 = -log(x);
double tmp;
if (x <= 0.205) {
tmp = fma(fma(-0.5, x, 1.0), x, t_0) / n;
} else {
tmp = fma((t_0 / n), -1.0, 1.0) / (n * x);
}
return tmp;
}
function code(x, n) t_0 = Float64(-log(x)) tmp = 0.0 if (x <= 0.205) tmp = Float64(fma(fma(-0.5, x, 1.0), x, t_0) / n); else tmp = Float64(fma(Float64(t_0 / n), -1.0, 1.0) / Float64(n * x)); end return tmp end
code[x_, n_] := Block[{t$95$0 = (-N[Log[x], $MachinePrecision])}, If[LessEqual[x, 0.205], N[(N[(N[(-0.5 * x + 1.0), $MachinePrecision] * x + t$95$0), $MachinePrecision] / n), $MachinePrecision], N[(N[(N[(t$95$0 / n), $MachinePrecision] * -1.0 + 1.0), $MachinePrecision] / N[(n * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -\log x\\
\mathbf{if}\;x \leq 0.205:\\
\;\;\;\;\frac{\mathsf{fma}\left(\mathsf{fma}\left(-0.5, x, 1\right), x, t\_0\right)}{n}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{t\_0}{n}, -1, 1\right)}{n \cdot x}\\
\end{array}
\end{array}
if x < 0.204999999999999988Initial program 42.7%
Taylor expanded in n around -inf
mul-1-negN/A
distribute-neg-frac2N/A
lower-/.f64N/A
Applied rewrites66.0%
Taylor expanded in x around 0
Applied rewrites50.4%
Taylor expanded in n around inf
Applied rewrites51.9%
if 0.204999999999999988 < x Initial program 65.1%
Taylor expanded in n around -inf
mul-1-negN/A
distribute-neg-frac2N/A
lower-/.f64N/A
Applied rewrites65.8%
Taylor expanded in x around inf
Applied rewrites63.3%
(FPCore (x n) :precision binary64 (if (<= x 0.205) (/ (fma (fma -0.5 x 1.0) x (- (log x))) n) (/ (/ (- (+ n (log x))) (* n x)) (- n))))
double code(double x, double n) {
double tmp;
if (x <= 0.205) {
tmp = fma(fma(-0.5, x, 1.0), x, -log(x)) / n;
} else {
tmp = (-(n + log(x)) / (n * x)) / -n;
}
return tmp;
}
function code(x, n) tmp = 0.0 if (x <= 0.205) tmp = Float64(fma(fma(-0.5, x, 1.0), x, Float64(-log(x))) / n); else tmp = Float64(Float64(Float64(-Float64(n + log(x))) / Float64(n * x)) / Float64(-n)); end return tmp end
code[x_, n_] := If[LessEqual[x, 0.205], N[(N[(N[(-0.5 * x + 1.0), $MachinePrecision] * x + (-N[Log[x], $MachinePrecision])), $MachinePrecision] / n), $MachinePrecision], N[(N[((-N[(n + N[Log[x], $MachinePrecision]), $MachinePrecision]) / N[(n * x), $MachinePrecision]), $MachinePrecision] / (-n)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.205:\\
\;\;\;\;\frac{\mathsf{fma}\left(\mathsf{fma}\left(-0.5, x, 1\right), x, -\log x\right)}{n}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{-\left(n + \log x\right)}{n \cdot x}}{-n}\\
\end{array}
\end{array}
if x < 0.204999999999999988Initial program 42.7%
Taylor expanded in n around -inf
mul-1-negN/A
distribute-neg-frac2N/A
lower-/.f64N/A
Applied rewrites66.0%
Taylor expanded in x around 0
Applied rewrites50.4%
Taylor expanded in n around inf
Applied rewrites51.9%
if 0.204999999999999988 < x Initial program 65.1%
Taylor expanded in n around -inf
mul-1-negN/A
distribute-neg-frac2N/A
lower-/.f64N/A
Applied rewrites65.8%
Taylor expanded in n around 0
Applied rewrites65.8%
Taylor expanded in x around inf
Applied rewrites63.3%
(FPCore (x n) :precision binary64 (if (<= x 0.295) (/ (fma (fma -0.5 x 1.0) x (- (log x))) n) (/ (pow n -1.0) x)))
double code(double x, double n) {
double tmp;
if (x <= 0.295) {
tmp = fma(fma(-0.5, x, 1.0), x, -log(x)) / n;
} else {
tmp = pow(n, -1.0) / x;
}
return tmp;
}
function code(x, n) tmp = 0.0 if (x <= 0.295) tmp = Float64(fma(fma(-0.5, x, 1.0), x, Float64(-log(x))) / n); else tmp = Float64((n ^ -1.0) / x); end return tmp end
code[x_, n_] := If[LessEqual[x, 0.295], N[(N[(N[(-0.5 * x + 1.0), $MachinePrecision] * x + (-N[Log[x], $MachinePrecision])), $MachinePrecision] / n), $MachinePrecision], N[(N[Power[n, -1.0], $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.295:\\
\;\;\;\;\frac{\mathsf{fma}\left(\mathsf{fma}\left(-0.5, x, 1\right), x, -\log x\right)}{n}\\
\mathbf{else}:\\
\;\;\;\;\frac{{n}^{-1}}{x}\\
\end{array}
\end{array}
if x < 0.294999999999999984Initial program 42.7%
Taylor expanded in n around -inf
mul-1-negN/A
distribute-neg-frac2N/A
lower-/.f64N/A
Applied rewrites66.0%
Taylor expanded in x around 0
Applied rewrites50.4%
Taylor expanded in n around inf
Applied rewrites51.9%
if 0.294999999999999984 < x Initial program 65.1%
Taylor expanded in x around inf
lower-/.f64N/A
*-commutativeN/A
log-recN/A
mul-1-negN/A
*-commutativeN/A
associate-*r/N/A
mul-1-negN/A
distribute-lft-neg-inN/A
metadata-evalN/A
*-lft-identityN/A
lower-exp.f64N/A
lower-/.f64N/A
lower-log.f64N/A
lower-*.f6496.8
Applied rewrites96.8%
Taylor expanded in n around inf
Applied rewrites62.6%
Final simplification56.9%
(FPCore (x n) :precision binary64 (/ (pow n -1.0) x))
double code(double x, double n) {
return pow(n, -1.0) / x;
}
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 = (n ** (-1.0d0)) / x
end function
public static double code(double x, double n) {
return Math.pow(n, -1.0) / x;
}
def code(x, n): return math.pow(n, -1.0) / x
function code(x, n) return Float64((n ^ -1.0) / x) end
function tmp = code(x, n) tmp = (n ^ -1.0) / x; end
code[x_, n_] := N[(N[Power[n, -1.0], $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{{n}^{-1}}{x}
\end{array}
Initial program 53.3%
Taylor expanded in x around inf
lower-/.f64N/A
*-commutativeN/A
log-recN/A
mul-1-negN/A
*-commutativeN/A
associate-*r/N/A
mul-1-negN/A
distribute-lft-neg-inN/A
metadata-evalN/A
*-lft-identityN/A
lower-exp.f64N/A
lower-/.f64N/A
lower-log.f64N/A
lower-*.f6459.9
Applied rewrites59.9%
Taylor expanded in n around inf
Applied rewrites40.6%
Final simplification40.6%
(FPCore (x n) :precision binary64 (pow (* n x) -1.0))
double code(double x, double n) {
return pow((n * x), -1.0);
}
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 = (n * x) ** (-1.0d0)
end function
public static double code(double x, double n) {
return Math.pow((n * x), -1.0);
}
def code(x, n): return math.pow((n * x), -1.0)
function code(x, n) return Float64(n * x) ^ -1.0 end
function tmp = code(x, n) tmp = (n * x) ^ -1.0; end
code[x_, n_] := N[Power[N[(n * x), $MachinePrecision], -1.0], $MachinePrecision]
\begin{array}{l}
\\
{\left(n \cdot x\right)}^{-1}
\end{array}
Initial program 53.3%
Taylor expanded in x around inf
lower-/.f64N/A
*-commutativeN/A
log-recN/A
mul-1-negN/A
*-commutativeN/A
associate-*r/N/A
mul-1-negN/A
distribute-lft-neg-inN/A
metadata-evalN/A
*-lft-identityN/A
lower-exp.f64N/A
lower-/.f64N/A
lower-log.f64N/A
lower-*.f6459.9
Applied rewrites59.9%
Taylor expanded in n around inf
Applied rewrites40.6%
Applied rewrites40.3%
Final simplification40.3%
herbie shell --seed 2024364
(FPCore (x n)
:name "2nthrt (problem 3.4.6)"
:precision binary64
(- (pow (+ x 1.0) (/ 1.0 n)) (pow x (/ 1.0 n))))