
(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 16 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 (<= x 6500000.0)
(/
(fma
1.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)) (* n x))))
double code(double x, double n) {
double tmp;
if (x <= 6500000.0) {
tmp = fma(1.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;
} else {
tmp = exp((log(x) / n)) / (n * x);
}
return tmp;
}
function code(x, n) tmp = 0.0 if (x <= 6500000.0) tmp = Float64(fma(1.0, log1p(x), Float64(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(exp(Float64(log(x) / n)) / Float64(n * x)); end return tmp end
code[x_, n_] := If[LessEqual[x, 6500000.0], N[(N[(1.0 * N[Log[1 + x], $MachinePrecision] + N[(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] - N[Log[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision], N[(N[Exp[N[(N[Log[x], $MachinePrecision] / n), $MachinePrecision]], $MachinePrecision] / N[(n * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 6500000:\\
\;\;\;\;\frac{\mathsf{fma}\left(1, \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} - \log x\right)}{n}\\
\mathbf{else}:\\
\;\;\;\;\frac{e^{\frac{\log x}{n}}}{n \cdot x}\\
\end{array}
\end{array}
if x < 6.5e6Initial program 41.1%
Taylor expanded in n around -inf
Applied rewrites84.4%
if 6.5e6 < x Initial program 72.2%
Taylor expanded in x around inf
Applied rewrites97.8%
(FPCore (x n)
:precision binary64
(let* ((t_0 (pow x (/ 1.0 n))) (t_1 (- (pow (- x -1.0) (/ 1.0 n)) t_0)))
(if (<= t_1 -2e-8)
(- 1.0 t_0)
(if (<= t_1 1e-11)
(/ (- (log1p x) (log x)) n)
(-
(fma
(fma
(/
(-
(fma
-0.3333333333333333
x
(/ (- (fma (/ x n) 0.16666666666666666 (* -0.5 x)) -0.5) (- n)))
-0.5)
(- n))
x
(/ 1.0 n))
x
1.0)
t_0)))))
double code(double x, double n) {
double t_0 = pow(x, (1.0 / n));
double t_1 = pow((x - -1.0), (1.0 / n)) - t_0;
double tmp;
if (t_1 <= -2e-8) {
tmp = 1.0 - t_0;
} else if (t_1 <= 1e-11) {
tmp = (log1p(x) - log(x)) / n;
} else {
tmp = fma(fma(((fma(-0.3333333333333333, x, ((fma((x / n), 0.16666666666666666, (-0.5 * x)) - -0.5) / -n)) - -0.5) / -n), x, (1.0 / n)), x, 1.0) - t_0;
}
return tmp;
}
function code(x, n) t_0 = x ^ Float64(1.0 / n) t_1 = Float64((Float64(x - -1.0) ^ Float64(1.0 / n)) - t_0) tmp = 0.0 if (t_1 <= -2e-8) tmp = Float64(1.0 - t_0); elseif (t_1 <= 1e-11) tmp = Float64(Float64(log1p(x) - log(x)) / n); else tmp = Float64(fma(fma(Float64(Float64(fma(-0.3333333333333333, x, Float64(Float64(fma(Float64(x / n), 0.16666666666666666, Float64(-0.5 * x)) - -0.5) / Float64(-n))) - -0.5) / Float64(-n)), x, Float64(1.0 / n)), x, 1.0) - t_0); end return tmp end
code[x_, n_] := Block[{t$95$0 = N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Power[N[(x - -1.0), $MachinePrecision], N[(1.0 / n), $MachinePrecision]], $MachinePrecision] - t$95$0), $MachinePrecision]}, If[LessEqual[t$95$1, -2e-8], N[(1.0 - t$95$0), $MachinePrecision], If[LessEqual[t$95$1, 1e-11], N[(N[(N[Log[1 + x], $MachinePrecision] - N[Log[x], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision], N[(N[(N[(N[(N[(N[(-0.3333333333333333 * x + N[(N[(N[(N[(x / n), $MachinePrecision] * 0.16666666666666666 + N[(-0.5 * x), $MachinePrecision]), $MachinePrecision] - -0.5), $MachinePrecision] / (-n)), $MachinePrecision]), $MachinePrecision] - -0.5), $MachinePrecision] / (-n)), $MachinePrecision] * x + N[(1.0 / n), $MachinePrecision]), $MachinePrecision] * x + 1.0), $MachinePrecision] - t$95$0), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {x}^{\left(\frac{1}{n}\right)}\\
t_1 := {\left(x - -1\right)}^{\left(\frac{1}{n}\right)} - t\_0\\
\mathbf{if}\;t\_1 \leq -2 \cdot 10^{-8}:\\
\;\;\;\;1 - t\_0\\
\mathbf{elif}\;t\_1 \leq 10^{-11}:\\
\;\;\;\;\frac{\mathsf{log1p}\left(x\right) - \log x}{n}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\frac{\mathsf{fma}\left(-0.3333333333333333, x, \frac{\mathsf{fma}\left(\frac{x}{n}, 0.16666666666666666, -0.5 \cdot x\right) - -0.5}{-n}\right) - -0.5}{-n}, x, \frac{1}{n}\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))) < -2e-8Initial program 98.3%
Taylor expanded in x around 0
Applied rewrites98.3%
if -2e-8 < (-.f64 (pow.f64 (+.f64 x #s(literal 1 binary64)) (/.f64 #s(literal 1 binary64) n)) (pow.f64 x (/.f64 #s(literal 1 binary64) n))) < 9.99999999999999939e-12Initial program 46.1%
Taylor expanded in n around inf
Applied rewrites82.6%
if 9.99999999999999939e-12 < (-.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 33.5%
Taylor expanded in x around 0
Applied rewrites24.8%
Taylor expanded in n around -inf
Applied rewrites75.6%
Final simplification84.3%
(FPCore (x n)
:precision binary64
(let* ((t_0 (pow x (/ 1.0 n))) (t_1 (- (pow (- x -1.0) (/ 1.0 n)) t_0)))
(if (<= t_1 -2e-16)
(- 1.0 t_0)
(if (<= t_1 0.0)
(- 1.0 1.0)
(- (fma (fma (/ (+ -0.5 (/ 0.5 n)) n) x (/ 1.0 n)) x 1.0) t_0)))))
double code(double x, double n) {
double t_0 = pow(x, (1.0 / n));
double t_1 = pow((x - -1.0), (1.0 / n)) - t_0;
double tmp;
if (t_1 <= -2e-16) {
tmp = 1.0 - t_0;
} else if (t_1 <= 0.0) {
tmp = 1.0 - 1.0;
} else {
tmp = fma(fma(((-0.5 + (0.5 / n)) / n), x, (1.0 / n)), x, 1.0) - t_0;
}
return tmp;
}
function code(x, n) t_0 = x ^ Float64(1.0 / n) t_1 = Float64((Float64(x - -1.0) ^ Float64(1.0 / n)) - t_0) tmp = 0.0 if (t_1 <= -2e-16) tmp = Float64(1.0 - t_0); elseif (t_1 <= 0.0) tmp = Float64(1.0 - 1.0); else tmp = Float64(fma(fma(Float64(Float64(-0.5 + Float64(0.5 / n)) / n), x, Float64(1.0 / n)), x, 1.0) - t_0); end return tmp end
code[x_, n_] := Block[{t$95$0 = N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Power[N[(x - -1.0), $MachinePrecision], N[(1.0 / n), $MachinePrecision]], $MachinePrecision] - t$95$0), $MachinePrecision]}, If[LessEqual[t$95$1, -2e-16], N[(1.0 - t$95$0), $MachinePrecision], If[LessEqual[t$95$1, 0.0], N[(1.0 - 1.0), $MachinePrecision], N[(N[(N[(N[(N[(-0.5 + N[(0.5 / n), $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision] * x + N[(1.0 / n), $MachinePrecision]), $MachinePrecision] * x + 1.0), $MachinePrecision] - t$95$0), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {x}^{\left(\frac{1}{n}\right)}\\
t_1 := {\left(x - -1\right)}^{\left(\frac{1}{n}\right)} - t\_0\\
\mathbf{if}\;t\_1 \leq -2 \cdot 10^{-16}:\\
\;\;\;\;1 - t\_0\\
\mathbf{elif}\;t\_1 \leq 0:\\
\;\;\;\;1 - 1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\frac{-0.5 + \frac{0.5}{n}}{n}, x, \frac{1}{n}\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))) < -2e-16Initial program 96.7%
Taylor expanded in x around 0
Applied rewrites96.7%
if -2e-16 < (-.f64 (pow.f64 (+.f64 x #s(literal 1 binary64)) (/.f64 #s(literal 1 binary64) n)) (pow.f64 x (/.f64 #s(literal 1 binary64) n))) < 0.0Initial program 46.4%
Taylor expanded in x around 0
Applied rewrites17.7%
Taylor expanded in n around inf
Applied rewrites46.4%
if 0.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))) Initial program 33.7%
Taylor expanded in x around 0
Applied rewrites71.2%
Final simplification59.8%
(FPCore (x n)
:precision binary64
(let* ((t_0 (pow x (/ 1.0 n))) (t_1 (- (pow (- x -1.0) (/ 1.0 n)) t_0)))
(if (<= t_1 -2e-16)
(- 1.0 t_0)
(if (<= t_1 0.0) (- 1.0 1.0) (- (fma (* (/ x (* n n)) 0.5) x 1.0) t_0)))))
double code(double x, double n) {
double t_0 = pow(x, (1.0 / n));
double t_1 = pow((x - -1.0), (1.0 / n)) - t_0;
double tmp;
if (t_1 <= -2e-16) {
tmp = 1.0 - t_0;
} else if (t_1 <= 0.0) {
tmp = 1.0 - 1.0;
} else {
tmp = fma(((x / (n * n)) * 0.5), x, 1.0) - t_0;
}
return tmp;
}
function code(x, n) t_0 = x ^ Float64(1.0 / n) t_1 = Float64((Float64(x - -1.0) ^ Float64(1.0 / n)) - t_0) tmp = 0.0 if (t_1 <= -2e-16) tmp = Float64(1.0 - t_0); elseif (t_1 <= 0.0) tmp = Float64(1.0 - 1.0); else tmp = Float64(fma(Float64(Float64(x / Float64(n * n)) * 0.5), x, 1.0) - t_0); end return tmp end
code[x_, n_] := Block[{t$95$0 = N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Power[N[(x - -1.0), $MachinePrecision], N[(1.0 / n), $MachinePrecision]], $MachinePrecision] - t$95$0), $MachinePrecision]}, If[LessEqual[t$95$1, -2e-16], N[(1.0 - t$95$0), $MachinePrecision], If[LessEqual[t$95$1, 0.0], N[(1.0 - 1.0), $MachinePrecision], N[(N[(N[(N[(x / N[(n * n), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision] * x + 1.0), $MachinePrecision] - t$95$0), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {x}^{\left(\frac{1}{n}\right)}\\
t_1 := {\left(x - -1\right)}^{\left(\frac{1}{n}\right)} - t\_0\\
\mathbf{if}\;t\_1 \leq -2 \cdot 10^{-16}:\\
\;\;\;\;1 - t\_0\\
\mathbf{elif}\;t\_1 \leq 0:\\
\;\;\;\;1 - 1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{n \cdot n} \cdot 0.5, 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))) < -2e-16Initial program 96.7%
Taylor expanded in x around 0
Applied rewrites96.7%
if -2e-16 < (-.f64 (pow.f64 (+.f64 x #s(literal 1 binary64)) (/.f64 #s(literal 1 binary64) n)) (pow.f64 x (/.f64 #s(literal 1 binary64) n))) < 0.0Initial program 46.4%
Taylor expanded in x around 0
Applied rewrites17.7%
Taylor expanded in n around inf
Applied rewrites46.4%
if 0.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))) Initial program 33.7%
Taylor expanded in x around 0
Applied rewrites71.2%
Taylor expanded in n around 0
Applied rewrites69.9%
Final simplification59.6%
(FPCore (x n)
:precision binary64
(let* ((t_0 (/ (log x) n)))
(if (<= x 0.095)
(-
(fma
(/ -0.5 n)
(/ (pow (log x) 2.0) n)
(fma (pow t_0 3.0) -0.16666666666666666 (/ x n)))
t_0)
(/ (exp t_0) (* n x)))))
double code(double x, double n) {
double t_0 = log(x) / n;
double tmp;
if (x <= 0.095) {
tmp = fma((-0.5 / n), (pow(log(x), 2.0) / n), fma(pow(t_0, 3.0), -0.16666666666666666, (x / n))) - t_0;
} else {
tmp = exp(t_0) / (n * x);
}
return tmp;
}
function code(x, n) t_0 = Float64(log(x) / n) tmp = 0.0 if (x <= 0.095) tmp = Float64(fma(Float64(-0.5 / n), Float64((log(x) ^ 2.0) / n), fma((t_0 ^ 3.0), -0.16666666666666666, Float64(x / n))) - t_0); else tmp = Float64(exp(t_0) / Float64(n * x)); end return tmp end
code[x_, n_] := Block[{t$95$0 = N[(N[Log[x], $MachinePrecision] / n), $MachinePrecision]}, If[LessEqual[x, 0.095], N[(N[(N[(-0.5 / n), $MachinePrecision] * N[(N[Power[N[Log[x], $MachinePrecision], 2.0], $MachinePrecision] / n), $MachinePrecision] + N[(N[Power[t$95$0, 3.0], $MachinePrecision] * -0.16666666666666666 + N[(x / n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision], N[(N[Exp[t$95$0], $MachinePrecision] / N[(n * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\log x}{n}\\
\mathbf{if}\;x \leq 0.095:\\
\;\;\;\;\mathsf{fma}\left(\frac{-0.5}{n}, \frac{{\log x}^{2}}{n}, \mathsf{fma}\left({t\_0}^{3}, -0.16666666666666666, \frac{x}{n}\right)\right) - t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{e^{t\_0}}{n \cdot x}\\
\end{array}
\end{array}
if x < 0.095000000000000001Initial program 41.2%
Taylor expanded in n around -inf
Applied rewrites84.3%
Taylor expanded in x around 0
Applied rewrites84.0%
if 0.095000000000000001 < x Initial program 71.2%
Taylor expanded in x around inf
Applied rewrites96.7%
(FPCore (x n)
:precision binary64
(if (<= x 0.029)
(/
(-
(fma
(/ -0.16666666666666666 n)
(/ (pow (log x) 3.0) n)
(* (/ (pow (log x) 2.0) n) -0.5))
(log x))
n)
(/ (exp (/ (log x) n)) (* n x))))
double code(double x, double n) {
double tmp;
if (x <= 0.029) {
tmp = (fma((-0.16666666666666666 / n), (pow(log(x), 3.0) / n), ((pow(log(x), 2.0) / n) * -0.5)) - log(x)) / n;
} else {
tmp = exp((log(x) / n)) / (n * x);
}
return tmp;
}
function code(x, n) tmp = 0.0 if (x <= 0.029) tmp = Float64(Float64(fma(Float64(-0.16666666666666666 / n), Float64((log(x) ^ 3.0) / n), Float64(Float64((log(x) ^ 2.0) / n) * -0.5)) - log(x)) / n); else tmp = Float64(exp(Float64(log(x) / n)) / Float64(n * x)); end return tmp end
code[x_, n_] := If[LessEqual[x, 0.029], N[(N[(N[(N[(-0.16666666666666666 / n), $MachinePrecision] * N[(N[Power[N[Log[x], $MachinePrecision], 3.0], $MachinePrecision] / n), $MachinePrecision] + N[(N[(N[Power[N[Log[x], $MachinePrecision], 2.0], $MachinePrecision] / n), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision] - N[Log[x], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision], N[(N[Exp[N[(N[Log[x], $MachinePrecision] / n), $MachinePrecision]], $MachinePrecision] / N[(n * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.029:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{-0.16666666666666666}{n}, \frac{{\log x}^{3}}{n}, \frac{{\log x}^{2}}{n} \cdot -0.5\right) - \log x}{n}\\
\mathbf{else}:\\
\;\;\;\;\frac{e^{\frac{\log x}{n}}}{n \cdot x}\\
\end{array}
\end{array}
if x < 0.0290000000000000015Initial program 41.2%
Taylor expanded in n around -inf
Applied rewrites84.3%
Taylor expanded in x around 0
Applied rewrites83.7%
if 0.0290000000000000015 < x Initial program 71.2%
Taylor expanded in x around inf
Applied rewrites96.7%
(FPCore (x n)
:precision binary64
(if (<= (/ 1.0 n) -5e-5)
(/ (exp (/ (log x) n)) (* n x))
(if (<= (/ 1.0 n) 1000000.0)
(/ (- (log1p x) (log x)) n)
(- (exp (/ (log1p x) n)) (pow x (/ 1.0 n))))))
double code(double x, double n) {
double tmp;
if ((1.0 / n) <= -5e-5) {
tmp = exp((log(x) / n)) / (n * x);
} else if ((1.0 / n) <= 1000000.0) {
tmp = (log1p(x) - log(x)) / n;
} else {
tmp = exp((log1p(x) / n)) - pow(x, (1.0 / n));
}
return tmp;
}
public static double code(double x, double n) {
double tmp;
if ((1.0 / n) <= -5e-5) {
tmp = Math.exp((Math.log(x) / n)) / (n * x);
} else if ((1.0 / n) <= 1000000.0) {
tmp = (Math.log1p(x) - Math.log(x)) / n;
} else {
tmp = Math.exp((Math.log1p(x) / n)) - Math.pow(x, (1.0 / n));
}
return tmp;
}
def code(x, n): tmp = 0 if (1.0 / n) <= -5e-5: tmp = math.exp((math.log(x) / n)) / (n * x) elif (1.0 / n) <= 1000000.0: tmp = (math.log1p(x) - math.log(x)) / n else: tmp = math.exp((math.log1p(x) / n)) - math.pow(x, (1.0 / n)) return tmp
function code(x, n) tmp = 0.0 if (Float64(1.0 / n) <= -5e-5) tmp = Float64(exp(Float64(log(x) / n)) / Float64(n * x)); elseif (Float64(1.0 / n) <= 1000000.0) tmp = Float64(Float64(log1p(x) - log(x)) / n); else tmp = Float64(exp(Float64(log1p(x) / n)) - (x ^ Float64(1.0 / n))); end return tmp end
code[x_, n_] := If[LessEqual[N[(1.0 / n), $MachinePrecision], -5e-5], N[(N[Exp[N[(N[Log[x], $MachinePrecision] / n), $MachinePrecision]], $MachinePrecision] / N[(n * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 1000000.0], 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[(1.0 / n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{1}{n} \leq -5 \cdot 10^{-5}:\\
\;\;\;\;\frac{e^{\frac{\log x}{n}}}{n \cdot x}\\
\mathbf{elif}\;\frac{1}{n} \leq 1000000:\\
\;\;\;\;\frac{\mathsf{log1p}\left(x\right) - \log x}{n}\\
\mathbf{else}:\\
\;\;\;\;e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}\\
\end{array}
\end{array}
if (/.f64 #s(literal 1 binary64) n) < -5.00000000000000024e-5Initial program 98.0%
Taylor expanded in x around inf
Applied rewrites100.0%
if -5.00000000000000024e-5 < (/.f64 #s(literal 1 binary64) n) < 1e6Initial program 25.5%
Taylor expanded in n around inf
Applied rewrites76.2%
if 1e6 < (/.f64 #s(literal 1 binary64) n) Initial program 34.4%
Taylor expanded in n around 0
Applied rewrites100.0%
(FPCore (x n)
:precision binary64
(if (<= (/ 1.0 n) -5e-5)
(/ (exp (/ (log x) n)) (* n x))
(if (<= (/ 1.0 n) 1000000.0)
(/ (- (log1p x) (log x)) n)
(-
(fma
(fma
(/
(-
(fma
-0.3333333333333333
x
(/ (- (fma (/ x n) 0.16666666666666666 (* -0.5 x)) -0.5) (- n)))
-0.5)
(- n))
x
(/ 1.0 n))
x
1.0)
(pow x (/ 1.0 n))))))
double code(double x, double n) {
double tmp;
if ((1.0 / n) <= -5e-5) {
tmp = exp((log(x) / n)) / (n * x);
} else if ((1.0 / n) <= 1000000.0) {
tmp = (log1p(x) - log(x)) / n;
} else {
tmp = fma(fma(((fma(-0.3333333333333333, x, ((fma((x / n), 0.16666666666666666, (-0.5 * x)) - -0.5) / -n)) - -0.5) / -n), x, (1.0 / n)), x, 1.0) - pow(x, (1.0 / n));
}
return tmp;
}
function code(x, n) tmp = 0.0 if (Float64(1.0 / n) <= -5e-5) tmp = Float64(exp(Float64(log(x) / n)) / Float64(n * x)); elseif (Float64(1.0 / n) <= 1000000.0) tmp = Float64(Float64(log1p(x) - log(x)) / n); else tmp = Float64(fma(fma(Float64(Float64(fma(-0.3333333333333333, x, Float64(Float64(fma(Float64(x / n), 0.16666666666666666, Float64(-0.5 * x)) - -0.5) / Float64(-n))) - -0.5) / Float64(-n)), x, Float64(1.0 / n)), x, 1.0) - (x ^ Float64(1.0 / n))); end return tmp end
code[x_, n_] := If[LessEqual[N[(1.0 / n), $MachinePrecision], -5e-5], N[(N[Exp[N[(N[Log[x], $MachinePrecision] / n), $MachinePrecision]], $MachinePrecision] / N[(n * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 1000000.0], N[(N[(N[Log[1 + x], $MachinePrecision] - N[Log[x], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision], N[(N[(N[(N[(N[(N[(-0.3333333333333333 * x + N[(N[(N[(N[(x / n), $MachinePrecision] * 0.16666666666666666 + N[(-0.5 * x), $MachinePrecision]), $MachinePrecision] - -0.5), $MachinePrecision] / (-n)), $MachinePrecision]), $MachinePrecision] - -0.5), $MachinePrecision] / (-n)), $MachinePrecision] * x + N[(1.0 / n), $MachinePrecision]), $MachinePrecision] * x + 1.0), $MachinePrecision] - N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{1}{n} \leq -5 \cdot 10^{-5}:\\
\;\;\;\;\frac{e^{\frac{\log x}{n}}}{n \cdot x}\\
\mathbf{elif}\;\frac{1}{n} \leq 1000000:\\
\;\;\;\;\frac{\mathsf{log1p}\left(x\right) - \log x}{n}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\frac{\mathsf{fma}\left(-0.3333333333333333, x, \frac{\mathsf{fma}\left(\frac{x}{n}, 0.16666666666666666, -0.5 \cdot x\right) - -0.5}{-n}\right) - -0.5}{-n}, x, \frac{1}{n}\right), x, 1\right) - {x}^{\left(\frac{1}{n}\right)}\\
\end{array}
\end{array}
if (/.f64 #s(literal 1 binary64) n) < -5.00000000000000024e-5Initial program 98.0%
Taylor expanded in x around inf
Applied rewrites100.0%
if -5.00000000000000024e-5 < (/.f64 #s(literal 1 binary64) n) < 1e6Initial program 25.5%
Taylor expanded in n around inf
Applied rewrites76.2%
if 1e6 < (/.f64 #s(literal 1 binary64) n) Initial program 34.4%
Taylor expanded in x around 0
Applied rewrites25.5%
Taylor expanded in n around -inf
Applied rewrites77.5%
Final simplification85.1%
(FPCore (x n)
:precision binary64
(let* ((t_0 (pow x (/ 1.0 n)))
(t_1
(-
(fma
(/
(-
(fma
(fma -0.3333333333333333 x 0.5)
x
(/ (* (fma (- (/ 0.16666666666666666 n) 0.5) x 0.5) x) (- n)))
1.0)
(- n))
x
1.0)
t_0))
(t_2 (/ (- (log x)) n)))
(if (<= x 1.45e-136)
t_1
(if (<= x 2.9e-124)
t_2
(if (<= x 5.6e-84)
(-
(fma
(fma
(/
(-
(fma
-0.3333333333333333
x
(/ (- (fma (/ x n) 0.16666666666666666 (* -0.5 x)) -0.5) (- n)))
-0.5)
(- n))
x
(/ 1.0 n))
x
1.0)
t_0)
(if (<= x 1.45e-44) t_2 (if (<= x 1.0) t_1 (- 1.0 1.0))))))))
double code(double x, double n) {
double t_0 = pow(x, (1.0 / n));
double t_1 = fma(((fma(fma(-0.3333333333333333, x, 0.5), x, ((fma(((0.16666666666666666 / n) - 0.5), x, 0.5) * x) / -n)) - 1.0) / -n), x, 1.0) - t_0;
double t_2 = -log(x) / n;
double tmp;
if (x <= 1.45e-136) {
tmp = t_1;
} else if (x <= 2.9e-124) {
tmp = t_2;
} else if (x <= 5.6e-84) {
tmp = fma(fma(((fma(-0.3333333333333333, x, ((fma((x / n), 0.16666666666666666, (-0.5 * x)) - -0.5) / -n)) - -0.5) / -n), x, (1.0 / n)), x, 1.0) - t_0;
} else if (x <= 1.45e-44) {
tmp = t_2;
} else if (x <= 1.0) {
tmp = t_1;
} else {
tmp = 1.0 - 1.0;
}
return tmp;
}
function code(x, n) t_0 = x ^ Float64(1.0 / n) t_1 = Float64(fma(Float64(Float64(fma(fma(-0.3333333333333333, x, 0.5), x, Float64(Float64(fma(Float64(Float64(0.16666666666666666 / n) - 0.5), x, 0.5) * x) / Float64(-n))) - 1.0) / Float64(-n)), x, 1.0) - t_0) t_2 = Float64(Float64(-log(x)) / n) tmp = 0.0 if (x <= 1.45e-136) tmp = t_1; elseif (x <= 2.9e-124) tmp = t_2; elseif (x <= 5.6e-84) tmp = Float64(fma(fma(Float64(Float64(fma(-0.3333333333333333, x, Float64(Float64(fma(Float64(x / n), 0.16666666666666666, Float64(-0.5 * x)) - -0.5) / Float64(-n))) - -0.5) / Float64(-n)), x, Float64(1.0 / n)), x, 1.0) - t_0); elseif (x <= 1.45e-44) tmp = t_2; elseif (x <= 1.0) tmp = t_1; else tmp = Float64(1.0 - 1.0); end return tmp end
code[x_, n_] := Block[{t$95$0 = N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(N[(N[(N[(-0.3333333333333333 * x + 0.5), $MachinePrecision] * x + N[(N[(N[(N[(N[(0.16666666666666666 / n), $MachinePrecision] - 0.5), $MachinePrecision] * x + 0.5), $MachinePrecision] * x), $MachinePrecision] / (-n)), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision] / (-n)), $MachinePrecision] * x + 1.0), $MachinePrecision] - t$95$0), $MachinePrecision]}, Block[{t$95$2 = N[((-N[Log[x], $MachinePrecision]) / n), $MachinePrecision]}, If[LessEqual[x, 1.45e-136], t$95$1, If[LessEqual[x, 2.9e-124], t$95$2, If[LessEqual[x, 5.6e-84], N[(N[(N[(N[(N[(N[(-0.3333333333333333 * x + N[(N[(N[(N[(x / n), $MachinePrecision] * 0.16666666666666666 + N[(-0.5 * x), $MachinePrecision]), $MachinePrecision] - -0.5), $MachinePrecision] / (-n)), $MachinePrecision]), $MachinePrecision] - -0.5), $MachinePrecision] / (-n)), $MachinePrecision] * x + N[(1.0 / n), $MachinePrecision]), $MachinePrecision] * x + 1.0), $MachinePrecision] - t$95$0), $MachinePrecision], If[LessEqual[x, 1.45e-44], t$95$2, If[LessEqual[x, 1.0], t$95$1, N[(1.0 - 1.0), $MachinePrecision]]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {x}^{\left(\frac{1}{n}\right)}\\
t_1 := \mathsf{fma}\left(\frac{\mathsf{fma}\left(\mathsf{fma}\left(-0.3333333333333333, x, 0.5\right), x, \frac{\mathsf{fma}\left(\frac{0.16666666666666666}{n} - 0.5, x, 0.5\right) \cdot x}{-n}\right) - 1}{-n}, x, 1\right) - t\_0\\
t_2 := \frac{-\log x}{n}\\
\mathbf{if}\;x \leq 1.45 \cdot 10^{-136}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \leq 2.9 \cdot 10^{-124}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;x \leq 5.6 \cdot 10^{-84}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\frac{\mathsf{fma}\left(-0.3333333333333333, x, \frac{\mathsf{fma}\left(\frac{x}{n}, 0.16666666666666666, -0.5 \cdot x\right) - -0.5}{-n}\right) - -0.5}{-n}, x, \frac{1}{n}\right), x, 1\right) - t\_0\\
\mathbf{elif}\;x \leq 1.45 \cdot 10^{-44}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;1 - 1\\
\end{array}
\end{array}
if x < 1.44999999999999997e-136 or 1.4500000000000001e-44 < x < 1Initial program 47.6%
Taylor expanded in x around 0
Applied rewrites21.6%
Taylor expanded in n around -inf
Applied rewrites53.7%
Taylor expanded in x around 0
Applied rewrites58.5%
if 1.44999999999999997e-136 < x < 2.9000000000000002e-124 or 5.59999999999999964e-84 < x < 1.4500000000000001e-44Initial program 9.6%
Taylor expanded in n around inf
Applied rewrites84.4%
Applied rewrites84.0%
Taylor expanded in x around 0
Applied rewrites84.0%
Taylor expanded in n around inf
Applied rewrites84.2%
if 2.9000000000000002e-124 < x < 5.59999999999999964e-84Initial program 50.5%
Taylor expanded in x around 0
Applied rewrites28.9%
Taylor expanded in n around -inf
Applied rewrites66.7%
if 1 < x Initial program 70.9%
Taylor expanded in x around 0
Applied rewrites25.1%
Taylor expanded in n around inf
Applied rewrites70.9%
Final simplification66.9%
(FPCore (x n)
:precision binary64
(let* ((t_0
(-
(fma
(/
(-
(fma
(fma -0.3333333333333333 x 0.5)
x
(/ (* (fma (- (/ 0.16666666666666666 n) 0.5) x 0.5) x) (- n)))
1.0)
(- n))
x
1.0)
(pow x (/ 1.0 n)))))
(if (<= x 1.45e-136)
t_0
(if (<= x 1.45e-44) (/ (- (log x)) n) (if (<= x 1.0) t_0 (- 1.0 1.0))))))
double code(double x, double n) {
double t_0 = fma(((fma(fma(-0.3333333333333333, x, 0.5), x, ((fma(((0.16666666666666666 / n) - 0.5), x, 0.5) * x) / -n)) - 1.0) / -n), x, 1.0) - pow(x, (1.0 / n));
double tmp;
if (x <= 1.45e-136) {
tmp = t_0;
} else if (x <= 1.45e-44) {
tmp = -log(x) / n;
} else if (x <= 1.0) {
tmp = t_0;
} else {
tmp = 1.0 - 1.0;
}
return tmp;
}
function code(x, n) t_0 = Float64(fma(Float64(Float64(fma(fma(-0.3333333333333333, x, 0.5), x, Float64(Float64(fma(Float64(Float64(0.16666666666666666 / n) - 0.5), x, 0.5) * x) / Float64(-n))) - 1.0) / Float64(-n)), x, 1.0) - (x ^ Float64(1.0 / n))) tmp = 0.0 if (x <= 1.45e-136) tmp = t_0; elseif (x <= 1.45e-44) tmp = Float64(Float64(-log(x)) / n); elseif (x <= 1.0) tmp = t_0; else tmp = Float64(1.0 - 1.0); end return tmp end
code[x_, n_] := Block[{t$95$0 = N[(N[(N[(N[(N[(N[(-0.3333333333333333 * x + 0.5), $MachinePrecision] * x + N[(N[(N[(N[(N[(0.16666666666666666 / n), $MachinePrecision] - 0.5), $MachinePrecision] * x + 0.5), $MachinePrecision] * x), $MachinePrecision] / (-n)), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision] / (-n)), $MachinePrecision] * x + 1.0), $MachinePrecision] - N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, 1.45e-136], t$95$0, If[LessEqual[x, 1.45e-44], N[((-N[Log[x], $MachinePrecision]) / n), $MachinePrecision], If[LessEqual[x, 1.0], t$95$0, N[(1.0 - 1.0), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\frac{\mathsf{fma}\left(\mathsf{fma}\left(-0.3333333333333333, x, 0.5\right), x, \frac{\mathsf{fma}\left(\frac{0.16666666666666666}{n} - 0.5, x, 0.5\right) \cdot x}{-n}\right) - 1}{-n}, x, 1\right) - {x}^{\left(\frac{1}{n}\right)}\\
\mathbf{if}\;x \leq 1.45 \cdot 10^{-136}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.45 \cdot 10^{-44}:\\
\;\;\;\;\frac{-\log x}{n}\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;1 - 1\\
\end{array}
\end{array}
if x < 1.44999999999999997e-136 or 1.4500000000000001e-44 < x < 1Initial program 47.6%
Taylor expanded in x around 0
Applied rewrites21.6%
Taylor expanded in n around -inf
Applied rewrites53.7%
Taylor expanded in x around 0
Applied rewrites58.5%
if 1.44999999999999997e-136 < x < 1.4500000000000001e-44Initial program 29.2%
Taylor expanded in n around inf
Applied rewrites72.7%
Applied rewrites70.5%
Taylor expanded in x around 0
Applied rewrites70.5%
Taylor expanded in n around inf
Applied rewrites59.5%
if 1 < x Initial program 70.9%
Taylor expanded in x around 0
Applied rewrites25.1%
Taylor expanded in n around inf
Applied rewrites70.9%
Final simplification63.7%
(FPCore (x n) :precision binary64 (if (<= x 9.5e-216) (- (- (/ x n) -1.0) (pow x (/ 1.0 n))) (if (<= x 1.0) (/ (- (log x)) n) (- 1.0 1.0))))
double code(double x, double n) {
double tmp;
if (x <= 9.5e-216) {
tmp = ((x / n) - -1.0) - pow(x, (1.0 / n));
} else if (x <= 1.0) {
tmp = -log(x) / n;
} else {
tmp = 1.0 - 1.0;
}
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 <= 9.5d-216) then
tmp = ((x / n) - (-1.0d0)) - (x ** (1.0d0 / n))
else if (x <= 1.0d0) then
tmp = -log(x) / n
else
tmp = 1.0d0 - 1.0d0
end if
code = tmp
end function
public static double code(double x, double n) {
double tmp;
if (x <= 9.5e-216) {
tmp = ((x / n) - -1.0) - Math.pow(x, (1.0 / n));
} else if (x <= 1.0) {
tmp = -Math.log(x) / n;
} else {
tmp = 1.0 - 1.0;
}
return tmp;
}
def code(x, n): tmp = 0 if x <= 9.5e-216: tmp = ((x / n) - -1.0) - math.pow(x, (1.0 / n)) elif x <= 1.0: tmp = -math.log(x) / n else: tmp = 1.0 - 1.0 return tmp
function code(x, n) tmp = 0.0 if (x <= 9.5e-216) tmp = Float64(Float64(Float64(x / n) - -1.0) - (x ^ Float64(1.0 / n))); elseif (x <= 1.0) tmp = Float64(Float64(-log(x)) / n); else tmp = Float64(1.0 - 1.0); end return tmp end
function tmp_2 = code(x, n) tmp = 0.0; if (x <= 9.5e-216) tmp = ((x / n) - -1.0) - (x ^ (1.0 / n)); elseif (x <= 1.0) tmp = -log(x) / n; else tmp = 1.0 - 1.0; end tmp_2 = tmp; end
code[x_, n_] := If[LessEqual[x, 9.5e-216], N[(N[(N[(x / n), $MachinePrecision] - -1.0), $MachinePrecision] - N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.0], N[((-N[Log[x], $MachinePrecision]) / n), $MachinePrecision], N[(1.0 - 1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 9.5 \cdot 10^{-216}:\\
\;\;\;\;\left(\frac{x}{n} - -1\right) - {x}^{\left(\frac{1}{n}\right)}\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;\frac{-\log x}{n}\\
\mathbf{else}:\\
\;\;\;\;1 - 1\\
\end{array}
\end{array}
if x < 9.49999999999999943e-216Initial program 56.0%
Taylor expanded in x around 0
Applied rewrites56.0%
if 9.49999999999999943e-216 < x < 1Initial program 35.9%
Taylor expanded in n around inf
Applied rewrites65.7%
Applied rewrites64.7%
Taylor expanded in x around 0
Applied rewrites63.8%
Taylor expanded in n around inf
Applied rewrites49.1%
if 1 < x Initial program 70.9%
Taylor expanded in x around 0
Applied rewrites25.1%
Taylor expanded in n around inf
Applied rewrites70.9%
Final simplification59.1%
(FPCore (x n) :precision binary64 (if (<= x 9.5e-216) (- 1.0 (pow x (/ 1.0 n))) (if (<= x 1.0) (/ (- (log x)) n) (- 1.0 1.0))))
double code(double x, double n) {
double tmp;
if (x <= 9.5e-216) {
tmp = 1.0 - pow(x, (1.0 / n));
} else if (x <= 1.0) {
tmp = -log(x) / n;
} else {
tmp = 1.0 - 1.0;
}
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 <= 9.5d-216) then
tmp = 1.0d0 - (x ** (1.0d0 / n))
else if (x <= 1.0d0) then
tmp = -log(x) / n
else
tmp = 1.0d0 - 1.0d0
end if
code = tmp
end function
public static double code(double x, double n) {
double tmp;
if (x <= 9.5e-216) {
tmp = 1.0 - Math.pow(x, (1.0 / n));
} else if (x <= 1.0) {
tmp = -Math.log(x) / n;
} else {
tmp = 1.0 - 1.0;
}
return tmp;
}
def code(x, n): tmp = 0 if x <= 9.5e-216: tmp = 1.0 - math.pow(x, (1.0 / n)) elif x <= 1.0: tmp = -math.log(x) / n else: tmp = 1.0 - 1.0 return tmp
function code(x, n) tmp = 0.0 if (x <= 9.5e-216) tmp = Float64(1.0 - (x ^ Float64(1.0 / n))); elseif (x <= 1.0) tmp = Float64(Float64(-log(x)) / n); else tmp = Float64(1.0 - 1.0); end return tmp end
function tmp_2 = code(x, n) tmp = 0.0; if (x <= 9.5e-216) tmp = 1.0 - (x ^ (1.0 / n)); elseif (x <= 1.0) tmp = -log(x) / n; else tmp = 1.0 - 1.0; end tmp_2 = tmp; end
code[x_, n_] := If[LessEqual[x, 9.5e-216], N[(1.0 - N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.0], N[((-N[Log[x], $MachinePrecision]) / n), $MachinePrecision], N[(1.0 - 1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 9.5 \cdot 10^{-216}:\\
\;\;\;\;1 - {x}^{\left(\frac{1}{n}\right)}\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;\frac{-\log x}{n}\\
\mathbf{else}:\\
\;\;\;\;1 - 1\\
\end{array}
\end{array}
if x < 9.49999999999999943e-216Initial program 56.0%
Taylor expanded in x around 0
Applied rewrites56.0%
if 9.49999999999999943e-216 < x < 1Initial program 35.9%
Taylor expanded in n around inf
Applied rewrites65.7%
Applied rewrites64.7%
Taylor expanded in x around 0
Applied rewrites63.8%
Taylor expanded in n around inf
Applied rewrites49.1%
if 1 < x Initial program 70.9%
Taylor expanded in x around 0
Applied rewrites25.1%
Taylor expanded in n around inf
Applied rewrites70.9%
(FPCore (x n) :precision binary64 (if (<= x 1.0) (/ (- (log x)) n) (- 1.0 1.0)))
double code(double x, double n) {
double tmp;
if (x <= 1.0) {
tmp = -log(x) / n;
} else {
tmp = 1.0 - 1.0;
}
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 = -log(x) / n
else
tmp = 1.0d0 - 1.0d0
end if
code = tmp
end function
public static double code(double x, double n) {
double tmp;
if (x <= 1.0) {
tmp = -Math.log(x) / n;
} else {
tmp = 1.0 - 1.0;
}
return tmp;
}
def code(x, n): tmp = 0 if x <= 1.0: tmp = -math.log(x) / n else: tmp = 1.0 - 1.0 return tmp
function code(x, n) tmp = 0.0 if (x <= 1.0) tmp = Float64(Float64(-log(x)) / n); else tmp = Float64(1.0 - 1.0); end return tmp end
function tmp_2 = code(x, n) tmp = 0.0; if (x <= 1.0) tmp = -log(x) / n; else tmp = 1.0 - 1.0; end tmp_2 = tmp; end
code[x_, n_] := If[LessEqual[x, 1.0], N[((-N[Log[x], $MachinePrecision]) / n), $MachinePrecision], N[(1.0 - 1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;\frac{-\log x}{n}\\
\mathbf{else}:\\
\;\;\;\;1 - 1\\
\end{array}
\end{array}
if x < 1Initial program 41.6%
Taylor expanded in n around inf
Applied rewrites63.1%
Applied rewrites61.7%
Taylor expanded in x around 0
Applied rewrites61.1%
Taylor expanded in n around inf
Applied rewrites46.8%
if 1 < x Initial program 70.9%
Taylor expanded in x around 0
Applied rewrites25.1%
Taylor expanded in n around inf
Applied rewrites70.9%
(FPCore (x n)
:precision binary64
(let* ((t_0 (/ (/ 1.0 x) n)))
(if (<= (/ 1.0 n) -5e+264)
t_0
(if (<= (/ 1.0 n) -2000000.0)
(- 1.0 1.0)
(if (<= (/ 1.0 n) 5e+132)
t_0
(- (fma (fma (/ (+ -0.5 (/ 0.5 n)) n) x (/ 1.0 n)) x 1.0) 1.0))))))
double code(double x, double n) {
double t_0 = (1.0 / x) / n;
double tmp;
if ((1.0 / n) <= -5e+264) {
tmp = t_0;
} else if ((1.0 / n) <= -2000000.0) {
tmp = 1.0 - 1.0;
} else if ((1.0 / n) <= 5e+132) {
tmp = t_0;
} else {
tmp = fma(fma(((-0.5 + (0.5 / n)) / n), x, (1.0 / n)), x, 1.0) - 1.0;
}
return tmp;
}
function code(x, n) t_0 = Float64(Float64(1.0 / x) / n) tmp = 0.0 if (Float64(1.0 / n) <= -5e+264) tmp = t_0; elseif (Float64(1.0 / n) <= -2000000.0) tmp = Float64(1.0 - 1.0); elseif (Float64(1.0 / n) <= 5e+132) tmp = t_0; else tmp = Float64(fma(fma(Float64(Float64(-0.5 + Float64(0.5 / n)) / n), x, Float64(1.0 / n)), x, 1.0) - 1.0); end return tmp end
code[x_, n_] := Block[{t$95$0 = N[(N[(1.0 / x), $MachinePrecision] / n), $MachinePrecision]}, If[LessEqual[N[(1.0 / n), $MachinePrecision], -5e+264], t$95$0, If[LessEqual[N[(1.0 / n), $MachinePrecision], -2000000.0], N[(1.0 - 1.0), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 5e+132], t$95$0, N[(N[(N[(N[(N[(-0.5 + N[(0.5 / n), $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision] * x + N[(1.0 / n), $MachinePrecision]), $MachinePrecision] * x + 1.0), $MachinePrecision] - 1.0), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\frac{1}{x}}{n}\\
\mathbf{if}\;\frac{1}{n} \leq -5 \cdot 10^{+264}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;\frac{1}{n} \leq -2000000:\\
\;\;\;\;1 - 1\\
\mathbf{elif}\;\frac{1}{n} \leq 5 \cdot 10^{+132}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\frac{-0.5 + \frac{0.5}{n}}{n}, x, \frac{1}{n}\right), x, 1\right) - 1\\
\end{array}
\end{array}
if (/.f64 #s(literal 1 binary64) n) < -5.00000000000000033e264 or -2e6 < (/.f64 #s(literal 1 binary64) n) < 5.0000000000000001e132Initial program 35.6%
Taylor expanded in n around inf
Applied rewrites71.9%
Taylor expanded in x around inf
Applied rewrites42.9%
Taylor expanded in n around inf
Applied rewrites43.0%
if -5.00000000000000033e264 < (/.f64 #s(literal 1 binary64) n) < -2e6Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites43.9%
Taylor expanded in n around inf
Applied rewrites58.6%
if 5.0000000000000001e132 < (/.f64 #s(literal 1 binary64) n) Initial program 24.5%
Taylor expanded in x around 0
Applied rewrites81.1%
Taylor expanded in n around inf
Applied rewrites76.5%
(FPCore (x n) :precision binary64 (if (or (<= n -0.66) (not (<= n -1.86e-265))) (/ (/ 1.0 x) n) (- 1.0 1.0)))
double code(double x, double n) {
double tmp;
if ((n <= -0.66) || !(n <= -1.86e-265)) {
tmp = (1.0 / x) / n;
} else {
tmp = 1.0 - 1.0;
}
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 ((n <= (-0.66d0)) .or. (.not. (n <= (-1.86d-265)))) then
tmp = (1.0d0 / x) / n
else
tmp = 1.0d0 - 1.0d0
end if
code = tmp
end function
public static double code(double x, double n) {
double tmp;
if ((n <= -0.66) || !(n <= -1.86e-265)) {
tmp = (1.0 / x) / n;
} else {
tmp = 1.0 - 1.0;
}
return tmp;
}
def code(x, n): tmp = 0 if (n <= -0.66) or not (n <= -1.86e-265): tmp = (1.0 / x) / n else: tmp = 1.0 - 1.0 return tmp
function code(x, n) tmp = 0.0 if ((n <= -0.66) || !(n <= -1.86e-265)) tmp = Float64(Float64(1.0 / x) / n); else tmp = Float64(1.0 - 1.0); end return tmp end
function tmp_2 = code(x, n) tmp = 0.0; if ((n <= -0.66) || ~((n <= -1.86e-265))) tmp = (1.0 / x) / n; else tmp = 1.0 - 1.0; end tmp_2 = tmp; end
code[x_, n_] := If[Or[LessEqual[n, -0.66], N[Not[LessEqual[n, -1.86e-265]], $MachinePrecision]], N[(N[(1.0 / x), $MachinePrecision] / n), $MachinePrecision], N[(1.0 - 1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;n \leq -0.66 \lor \neg \left(n \leq -1.86 \cdot 10^{-265}\right):\\
\;\;\;\;\frac{\frac{1}{x}}{n}\\
\mathbf{else}:\\
\;\;\;\;1 - 1\\
\end{array}
\end{array}
if n < -0.660000000000000031 or -1.86e-265 < n Initial program 33.8%
Taylor expanded in n around inf
Applied rewrites60.7%
Taylor expanded in x around inf
Applied rewrites36.3%
Taylor expanded in n around inf
Applied rewrites45.1%
if -0.660000000000000031 < n < -1.86e-265Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites43.9%
Taylor expanded in n around inf
Applied rewrites58.6%
Final simplification49.1%
(FPCore (x n) :precision binary64 (- 1.0 1.0))
double code(double x, double n) {
return 1.0 - 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 = 1.0d0 - 1.0d0
end function
public static double code(double x, double n) {
return 1.0 - 1.0;
}
def code(x, n): return 1.0 - 1.0
function code(x, n) return Float64(1.0 - 1.0) end
function tmp = code(x, n) tmp = 1.0 - 1.0; end
code[x_, n_] := N[(1.0 - 1.0), $MachinePrecision]
\begin{array}{l}
\\
1 - 1
\end{array}
Initial program 53.5%
Taylor expanded in x around 0
Applied rewrites34.5%
Taylor expanded in n around inf
Applied rewrites30.7%
herbie shell --seed 2025019
(FPCore (x n)
:name "2nthrt (problem 3.4.6)"
:precision binary64
(- (pow (+ x 1.0) (/ 1.0 n)) (pow x (/ 1.0 n))))