
(FPCore (i n) :precision binary64 (* 100.0 (/ (- (pow (+ 1.0 (/ i n)) n) 1.0) (/ i n))))
double code(double i, double n) {
return 100.0 * ((pow((1.0 + (i / n)), n) - 1.0) / (i / 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(i, n)
use fmin_fmax_functions
real(8), intent (in) :: i
real(8), intent (in) :: n
code = 100.0d0 * ((((1.0d0 + (i / n)) ** n) - 1.0d0) / (i / n))
end function
public static double code(double i, double n) {
return 100.0 * ((Math.pow((1.0 + (i / n)), n) - 1.0) / (i / n));
}
def code(i, n): return 100.0 * ((math.pow((1.0 + (i / n)), n) - 1.0) / (i / n))
function code(i, n) return Float64(100.0 * Float64(Float64((Float64(1.0 + Float64(i / n)) ^ n) - 1.0) / Float64(i / n))) end
function tmp = code(i, n) tmp = 100.0 * ((((1.0 + (i / n)) ^ n) - 1.0) / (i / n)); end
code[i_, n_] := N[(100.0 * N[(N[(N[Power[N[(1.0 + N[(i / n), $MachinePrecision]), $MachinePrecision], n], $MachinePrecision] - 1.0), $MachinePrecision] / N[(i / n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (i n) :precision binary64 (* 100.0 (/ (- (pow (+ 1.0 (/ i n)) n) 1.0) (/ i n))))
double code(double i, double n) {
return 100.0 * ((pow((1.0 + (i / n)), n) - 1.0) / (i / 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(i, n)
use fmin_fmax_functions
real(8), intent (in) :: i
real(8), intent (in) :: n
code = 100.0d0 * ((((1.0d0 + (i / n)) ** n) - 1.0d0) / (i / n))
end function
public static double code(double i, double n) {
return 100.0 * ((Math.pow((1.0 + (i / n)), n) - 1.0) / (i / n));
}
def code(i, n): return 100.0 * ((math.pow((1.0 + (i / n)), n) - 1.0) / (i / n))
function code(i, n) return Float64(100.0 * Float64(Float64((Float64(1.0 + Float64(i / n)) ^ n) - 1.0) / Float64(i / n))) end
function tmp = code(i, n) tmp = 100.0 * ((((1.0 + (i / n)) ^ n) - 1.0) / (i / n)); end
code[i_, n_] := N[(100.0 * N[(N[(N[Power[N[(1.0 + N[(i / n), $MachinePrecision]), $MachinePrecision], n], $MachinePrecision] - 1.0), $MachinePrecision] / N[(i / n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}
(FPCore (i n)
:precision binary64
(let* ((t_0 (* 100.0 (* (/ (expm1 i) i) n))))
(if (<= n 2.5e-308)
t_0
(if (<= n 1.16e-40)
(*
(*
n
(+
(log i)
(fma
-1.0
(log n)
(*
n
(fma
0.5
(pow (+ (log i) (* -1.0 (log n))) 2.0)
(/ 1.0 i))))))
(* (/ n i) 100.0))
t_0))))double code(double i, double n) {
double t_0 = 100.0 * ((expm1(i) / i) * n);
double tmp;
if (n <= 2.5e-308) {
tmp = t_0;
} else if (n <= 1.16e-40) {
tmp = (n * (log(i) + fma(-1.0, log(n), (n * fma(0.5, pow((log(i) + (-1.0 * log(n))), 2.0), (1.0 / i)))))) * ((n / i) * 100.0);
} else {
tmp = t_0;
}
return tmp;
}
function code(i, n) t_0 = Float64(100.0 * Float64(Float64(expm1(i) / i) * n)) tmp = 0.0 if (n <= 2.5e-308) tmp = t_0; elseif (n <= 1.16e-40) tmp = Float64(Float64(n * Float64(log(i) + fma(-1.0, log(n), Float64(n * fma(0.5, (Float64(log(i) + Float64(-1.0 * log(n))) ^ 2.0), Float64(1.0 / i)))))) * Float64(Float64(n / i) * 100.0)); else tmp = t_0; end return tmp end
code[i_, n_] := Block[{t$95$0 = N[(100.0 * N[(N[(N[(Exp[i] - 1), $MachinePrecision] / i), $MachinePrecision] * n), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[n, 2.5e-308], t$95$0, If[LessEqual[n, 1.16e-40], N[(N[(n * N[(N[Log[i], $MachinePrecision] + N[(-1.0 * N[Log[n], $MachinePrecision] + N[(n * N[(0.5 * N[Power[N[(N[Log[i], $MachinePrecision] + N[(-1.0 * N[Log[n], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(1.0 / i), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[(n / i), $MachinePrecision] * 100.0), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
t_0 := 100 \cdot \left(\frac{\mathsf{expm1}\left(i\right)}{i} \cdot n\right)\\
\mathbf{if}\;n \leq 2.5 \cdot 10^{-308}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;n \leq 1.16 \cdot 10^{-40}:\\
\;\;\;\;\left(n \cdot \left(\log i + \mathsf{fma}\left(-1, \log n, n \cdot \mathsf{fma}\left(0.5, {\left(\log i + -1 \cdot \log n\right)}^{2}, \frac{1}{i}\right)\right)\right)\right) \cdot \left(\frac{n}{i} \cdot 100\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
if n < 2.4999999999999998e-308 or 1.1599999999999999e-40 < n Initial program 28.6%
Taylor expanded in n around inf
lower-/.f64N/A
lower-*.f64N/A
lower-expm1.f6471.6%
Applied rewrites71.6%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
lift-/.f64N/A
*-commutativeN/A
lower-*.f6475.9%
Applied rewrites75.9%
if 2.4999999999999998e-308 < n < 1.1599999999999999e-40Initial program 28.6%
Taylor expanded in n around 0
lower-*.f64N/A
lower-+.f64N/A
lower-log.f64N/A
lower-*.f64N/A
lower-log.f6410.9%
Applied rewrites10.9%
Applied rewrites15.7%
Taylor expanded in n around 0
lower-*.f64N/A
lower-+.f64N/A
lower-log.f64N/A
lower-fma.f64N/A
lower-log.f64N/A
lower-*.f64N/A
lower-fma.f64N/A
Applied rewrites16.3%
(FPCore (i n)
:precision binary64
(let* ((t_0 (* 100.0 (* (/ (expm1 i) i) n))))
(if (<= n 2.5e-308)
t_0
(if (<= n 1.16e-40)
(* 100.0 (/ (* n (+ (log i) (* -1.0 (log n)))) (/ i n)))
t_0))))double code(double i, double n) {
double t_0 = 100.0 * ((expm1(i) / i) * n);
double tmp;
if (n <= 2.5e-308) {
tmp = t_0;
} else if (n <= 1.16e-40) {
tmp = 100.0 * ((n * (log(i) + (-1.0 * log(n)))) / (i / n));
} else {
tmp = t_0;
}
return tmp;
}
public static double code(double i, double n) {
double t_0 = 100.0 * ((Math.expm1(i) / i) * n);
double tmp;
if (n <= 2.5e-308) {
tmp = t_0;
} else if (n <= 1.16e-40) {
tmp = 100.0 * ((n * (Math.log(i) + (-1.0 * Math.log(n)))) / (i / n));
} else {
tmp = t_0;
}
return tmp;
}
def code(i, n): t_0 = 100.0 * ((math.expm1(i) / i) * n) tmp = 0 if n <= 2.5e-308: tmp = t_0 elif n <= 1.16e-40: tmp = 100.0 * ((n * (math.log(i) + (-1.0 * math.log(n)))) / (i / n)) else: tmp = t_0 return tmp
function code(i, n) t_0 = Float64(100.0 * Float64(Float64(expm1(i) / i) * n)) tmp = 0.0 if (n <= 2.5e-308) tmp = t_0; elseif (n <= 1.16e-40) tmp = Float64(100.0 * Float64(Float64(n * Float64(log(i) + Float64(-1.0 * log(n)))) / Float64(i / n))); else tmp = t_0; end return tmp end
code[i_, n_] := Block[{t$95$0 = N[(100.0 * N[(N[(N[(Exp[i] - 1), $MachinePrecision] / i), $MachinePrecision] * n), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[n, 2.5e-308], t$95$0, If[LessEqual[n, 1.16e-40], N[(100.0 * N[(N[(n * N[(N[Log[i], $MachinePrecision] + N[(-1.0 * N[Log[n], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(i / n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
t_0 := 100 \cdot \left(\frac{\mathsf{expm1}\left(i\right)}{i} \cdot n\right)\\
\mathbf{if}\;n \leq 2.5 \cdot 10^{-308}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;n \leq 1.16 \cdot 10^{-40}:\\
\;\;\;\;100 \cdot \frac{n \cdot \left(\log i + -1 \cdot \log n\right)}{\frac{i}{n}}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
if n < 2.4999999999999998e-308 or 1.1599999999999999e-40 < n Initial program 28.6%
Taylor expanded in n around inf
lower-/.f64N/A
lower-*.f64N/A
lower-expm1.f6471.6%
Applied rewrites71.6%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
lift-/.f64N/A
*-commutativeN/A
lower-*.f6475.9%
Applied rewrites75.9%
if 2.4999999999999998e-308 < n < 1.1599999999999999e-40Initial program 28.6%
Taylor expanded in n around 0
lower-*.f64N/A
lower-+.f64N/A
lower-log.f64N/A
lower-*.f64N/A
lower-log.f6410.9%
Applied rewrites10.9%
(FPCore (i n)
:precision binary64
(let* ((t_0 (* 100.0 (* (/ (expm1 i) i) n))))
(if (<= n -3.1e-217)
t_0
(if (<= n 4e-159) (* 100.0 (/ (- (pow 1.0 n) 1.0) (/ i n))) t_0))))double code(double i, double n) {
double t_0 = 100.0 * ((expm1(i) / i) * n);
double tmp;
if (n <= -3.1e-217) {
tmp = t_0;
} else if (n <= 4e-159) {
tmp = 100.0 * ((pow(1.0, n) - 1.0) / (i / n));
} else {
tmp = t_0;
}
return tmp;
}
public static double code(double i, double n) {
double t_0 = 100.0 * ((Math.expm1(i) / i) * n);
double tmp;
if (n <= -3.1e-217) {
tmp = t_0;
} else if (n <= 4e-159) {
tmp = 100.0 * ((Math.pow(1.0, n) - 1.0) / (i / n));
} else {
tmp = t_0;
}
return tmp;
}
def code(i, n): t_0 = 100.0 * ((math.expm1(i) / i) * n) tmp = 0 if n <= -3.1e-217: tmp = t_0 elif n <= 4e-159: tmp = 100.0 * ((math.pow(1.0, n) - 1.0) / (i / n)) else: tmp = t_0 return tmp
function code(i, n) t_0 = Float64(100.0 * Float64(Float64(expm1(i) / i) * n)) tmp = 0.0 if (n <= -3.1e-217) tmp = t_0; elseif (n <= 4e-159) tmp = Float64(100.0 * Float64(Float64((1.0 ^ n) - 1.0) / Float64(i / n))); else tmp = t_0; end return tmp end
code[i_, n_] := Block[{t$95$0 = N[(100.0 * N[(N[(N[(Exp[i] - 1), $MachinePrecision] / i), $MachinePrecision] * n), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[n, -3.1e-217], t$95$0, If[LessEqual[n, 4e-159], N[(100.0 * N[(N[(N[Power[1.0, n], $MachinePrecision] - 1.0), $MachinePrecision] / N[(i / n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
t_0 := 100 \cdot \left(\frac{\mathsf{expm1}\left(i\right)}{i} \cdot n\right)\\
\mathbf{if}\;n \leq -3.1 \cdot 10^{-217}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;n \leq 4 \cdot 10^{-159}:\\
\;\;\;\;100 \cdot \frac{{1}^{n} - 1}{\frac{i}{n}}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
if n < -3.0999999999999999e-217 or 4e-159 < n Initial program 28.6%
Taylor expanded in n around inf
lower-/.f64N/A
lower-*.f64N/A
lower-expm1.f6471.6%
Applied rewrites71.6%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
lift-/.f64N/A
*-commutativeN/A
lower-*.f6475.9%
Applied rewrites75.9%
if -3.0999999999999999e-217 < n < 4e-159Initial program 28.6%
Taylor expanded in i around 0
Applied rewrites17.3%
(FPCore (i n)
:precision binary64
(let* ((t_0 (* 100.0 (* (/ (expm1 i) i) n))))
(if (<= n -3.1e-217)
t_0
(if (<= n 5.8e-160) (* 100.0 (/ (- (+ 1.0 i) 1.0) (/ i n))) t_0))))double code(double i, double n) {
double t_0 = 100.0 * ((expm1(i) / i) * n);
double tmp;
if (n <= -3.1e-217) {
tmp = t_0;
} else if (n <= 5.8e-160) {
tmp = 100.0 * (((1.0 + i) - 1.0) / (i / n));
} else {
tmp = t_0;
}
return tmp;
}
public static double code(double i, double n) {
double t_0 = 100.0 * ((Math.expm1(i) / i) * n);
double tmp;
if (n <= -3.1e-217) {
tmp = t_0;
} else if (n <= 5.8e-160) {
tmp = 100.0 * (((1.0 + i) - 1.0) / (i / n));
} else {
tmp = t_0;
}
return tmp;
}
def code(i, n): t_0 = 100.0 * ((math.expm1(i) / i) * n) tmp = 0 if n <= -3.1e-217: tmp = t_0 elif n <= 5.8e-160: tmp = 100.0 * (((1.0 + i) - 1.0) / (i / n)) else: tmp = t_0 return tmp
function code(i, n) t_0 = Float64(100.0 * Float64(Float64(expm1(i) / i) * n)) tmp = 0.0 if (n <= -3.1e-217) tmp = t_0; elseif (n <= 5.8e-160) tmp = Float64(100.0 * Float64(Float64(Float64(1.0 + i) - 1.0) / Float64(i / n))); else tmp = t_0; end return tmp end
code[i_, n_] := Block[{t$95$0 = N[(100.0 * N[(N[(N[(Exp[i] - 1), $MachinePrecision] / i), $MachinePrecision] * n), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[n, -3.1e-217], t$95$0, If[LessEqual[n, 5.8e-160], N[(100.0 * N[(N[(N[(1.0 + i), $MachinePrecision] - 1.0), $MachinePrecision] / N[(i / n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
t_0 := 100 \cdot \left(\frac{\mathsf{expm1}\left(i\right)}{i} \cdot n\right)\\
\mathbf{if}\;n \leq -3.1 \cdot 10^{-217}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;n \leq 5.8 \cdot 10^{-160}:\\
\;\;\;\;100 \cdot \frac{\left(1 + i\right) - 1}{\frac{i}{n}}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
if n < -3.0999999999999999e-217 or 5.7999999999999998e-160 < n Initial program 28.6%
Taylor expanded in n around inf
lower-/.f64N/A
lower-*.f64N/A
lower-expm1.f6471.6%
Applied rewrites71.6%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
lift-/.f64N/A
*-commutativeN/A
lower-*.f6475.9%
Applied rewrites75.9%
if -3.0999999999999999e-217 < n < 5.7999999999999998e-160Initial program 28.6%
Taylor expanded in i around 0
lower-+.f6415.4%
Applied rewrites15.4%
(FPCore (i n)
:precision binary64
(if (<=
(* 100.0 (/ (- (pow (+ 1.0 (/ i n)) n) 1.0) (/ i n)))
INFINITY)
(* 100.0 (* (expm1 i) (/ n i)))
(* 100.0 n)))double code(double i, double n) {
double tmp;
if ((100.0 * ((pow((1.0 + (i / n)), n) - 1.0) / (i / n))) <= ((double) INFINITY)) {
tmp = 100.0 * (expm1(i) * (n / i));
} else {
tmp = 100.0 * n;
}
return tmp;
}
public static double code(double i, double n) {
double tmp;
if ((100.0 * ((Math.pow((1.0 + (i / n)), n) - 1.0) / (i / n))) <= Double.POSITIVE_INFINITY) {
tmp = 100.0 * (Math.expm1(i) * (n / i));
} else {
tmp = 100.0 * n;
}
return tmp;
}
def code(i, n): tmp = 0 if (100.0 * ((math.pow((1.0 + (i / n)), n) - 1.0) / (i / n))) <= math.inf: tmp = 100.0 * (math.expm1(i) * (n / i)) else: tmp = 100.0 * n return tmp
function code(i, n) tmp = 0.0 if (Float64(100.0 * Float64(Float64((Float64(1.0 + Float64(i / n)) ^ n) - 1.0) / Float64(i / n))) <= Inf) tmp = Float64(100.0 * Float64(expm1(i) * Float64(n / i))); else tmp = Float64(100.0 * n); end return tmp end
code[i_, n_] := If[LessEqual[N[(100.0 * N[(N[(N[Power[N[(1.0 + N[(i / n), $MachinePrecision]), $MachinePrecision], n], $MachinePrecision] - 1.0), $MachinePrecision] / N[(i / n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], Infinity], N[(100.0 * N[(N[(Exp[i] - 1), $MachinePrecision] * N[(n / i), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(100.0 * n), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}} \leq \infty:\\
\;\;\;\;100 \cdot \left(\mathsf{expm1}\left(i\right) \cdot \frac{n}{i}\right)\\
\mathbf{else}:\\
\;\;\;\;100 \cdot n\\
\end{array}
if (*.f64 #s(literal 100 binary64) (/.f64 (-.f64 (pow.f64 (+.f64 #s(literal 1 binary64) (/.f64 i n)) n) #s(literal 1 binary64)) (/.f64 i n))) < +inf.0Initial program 28.6%
Taylor expanded in n around inf
lower-/.f64N/A
lower-*.f64N/A
lower-expm1.f6471.6%
Applied rewrites71.6%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
lift-/.f64N/A
*-commutativeN/A
lower-*.f6475.9%
Applied rewrites75.9%
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
associate-/l*N/A
div-flip-revN/A
lift-/.f64N/A
lower-*.f64N/A
lift-/.f64N/A
div-flip-revN/A
lift-/.f6461.2%
Applied rewrites61.2%
if +inf.0 < (*.f64 #s(literal 100 binary64) (/.f64 (-.f64 (pow.f64 (+.f64 #s(literal 1 binary64) (/.f64 i n)) n) #s(literal 1 binary64)) (/.f64 i n))) Initial program 28.6%
Taylor expanded in i around 0
Applied rewrites48.5%
(FPCore (i n)
:precision binary64
(let* ((t_0 (* (fma (* 0.5 n) i n) 100.0)))
(if (<= n -2.4e-165)
t_0
(if (<= n 6.5e-156) (* 100.0 (/ (- (+ 1.0 i) 1.0) (/ i n))) t_0))))double code(double i, double n) {
double t_0 = fma((0.5 * n), i, n) * 100.0;
double tmp;
if (n <= -2.4e-165) {
tmp = t_0;
} else if (n <= 6.5e-156) {
tmp = 100.0 * (((1.0 + i) - 1.0) / (i / n));
} else {
tmp = t_0;
}
return tmp;
}
function code(i, n) t_0 = Float64(fma(Float64(0.5 * n), i, n) * 100.0) tmp = 0.0 if (n <= -2.4e-165) tmp = t_0; elseif (n <= 6.5e-156) tmp = Float64(100.0 * Float64(Float64(Float64(1.0 + i) - 1.0) / Float64(i / n))); else tmp = t_0; end return tmp end
code[i_, n_] := Block[{t$95$0 = N[(N[(N[(0.5 * n), $MachinePrecision] * i + n), $MachinePrecision] * 100.0), $MachinePrecision]}, If[LessEqual[n, -2.4e-165], t$95$0, If[LessEqual[n, 6.5e-156], N[(100.0 * N[(N[(N[(1.0 + i), $MachinePrecision] - 1.0), $MachinePrecision] / N[(i / n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
t_0 := \mathsf{fma}\left(0.5 \cdot n, i, n\right) \cdot 100\\
\mathbf{if}\;n \leq -2.4 \cdot 10^{-165}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;n \leq 6.5 \cdot 10^{-156}:\\
\;\;\;\;100 \cdot \frac{\left(1 + i\right) - 1}{\frac{i}{n}}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
if n < -2.4000000000000002e-165 or 6.5000000000000002e-156 < n Initial program 28.6%
Taylor expanded in n around inf
lower-/.f64N/A
lower-*.f64N/A
lower-expm1.f6471.6%
Applied rewrites71.6%
Taylor expanded in i around 0
lower-+.f64N/A
lower-*.f64N/A
lower-fma.f64N/A
lower-*.f64N/A
lower-fma.f64N/A
lower-*.f64N/A
lower-*.f6458.4%
Applied rewrites58.4%
Taylor expanded in i around 0
lower-*.f6454.2%
Applied rewrites54.2%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6454.2%
Applied rewrites54.2%
if -2.4000000000000002e-165 < n < 6.5000000000000002e-156Initial program 28.6%
Taylor expanded in i around 0
lower-+.f6415.4%
Applied rewrites15.4%
(FPCore (i n) :precision binary64 (if (<= i 7.5e-232) (* 100.0 n) (* 100.0 (/ (* i n) i))))
double code(double i, double n) {
double tmp;
if (i <= 7.5e-232) {
tmp = 100.0 * n;
} else {
tmp = 100.0 * ((i * n) / i);
}
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(i, n)
use fmin_fmax_functions
real(8), intent (in) :: i
real(8), intent (in) :: n
real(8) :: tmp
if (i <= 7.5d-232) then
tmp = 100.0d0 * n
else
tmp = 100.0d0 * ((i * n) / i)
end if
code = tmp
end function
public static double code(double i, double n) {
double tmp;
if (i <= 7.5e-232) {
tmp = 100.0 * n;
} else {
tmp = 100.0 * ((i * n) / i);
}
return tmp;
}
def code(i, n): tmp = 0 if i <= 7.5e-232: tmp = 100.0 * n else: tmp = 100.0 * ((i * n) / i) return tmp
function code(i, n) tmp = 0.0 if (i <= 7.5e-232) tmp = Float64(100.0 * n); else tmp = Float64(100.0 * Float64(Float64(i * n) / i)); end return tmp end
function tmp_2 = code(i, n) tmp = 0.0; if (i <= 7.5e-232) tmp = 100.0 * n; else tmp = 100.0 * ((i * n) / i); end tmp_2 = tmp; end
code[i_, n_] := If[LessEqual[i, 7.5e-232], N[(100.0 * n), $MachinePrecision], N[(100.0 * N[(N[(i * n), $MachinePrecision] / i), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;i \leq 7.5 \cdot 10^{-232}:\\
\;\;\;\;100 \cdot n\\
\mathbf{else}:\\
\;\;\;\;100 \cdot \frac{i \cdot n}{i}\\
\end{array}
if i < 7.5000000000000006e-232Initial program 28.6%
Taylor expanded in i around 0
Applied rewrites48.5%
if 7.5000000000000006e-232 < i Initial program 28.6%
Taylor expanded in n around inf
lower-/.f64N/A
lower-*.f64N/A
lower-expm1.f6471.6%
Applied rewrites71.6%
Taylor expanded in i around 0
lower-*.f6449.6%
Applied rewrites49.6%
(FPCore (i n) :precision binary64 (* (fma (* 0.5 n) i n) 100.0))
double code(double i, double n) {
return fma((0.5 * n), i, n) * 100.0;
}
function code(i, n) return Float64(fma(Float64(0.5 * n), i, n) * 100.0) end
code[i_, n_] := N[(N[(N[(0.5 * n), $MachinePrecision] * i + n), $MachinePrecision] * 100.0), $MachinePrecision]
\mathsf{fma}\left(0.5 \cdot n, i, n\right) \cdot 100
Initial program 28.6%
Taylor expanded in n around inf
lower-/.f64N/A
lower-*.f64N/A
lower-expm1.f6471.6%
Applied rewrites71.6%
Taylor expanded in i around 0
lower-+.f64N/A
lower-*.f64N/A
lower-fma.f64N/A
lower-*.f64N/A
lower-fma.f64N/A
lower-*.f64N/A
lower-*.f6458.4%
Applied rewrites58.4%
Taylor expanded in i around 0
lower-*.f6454.2%
Applied rewrites54.2%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6454.2%
Applied rewrites54.2%
(FPCore (i n) :precision binary64 (* 100.0 n))
double code(double i, double n) {
return 100.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(i, n)
use fmin_fmax_functions
real(8), intent (in) :: i
real(8), intent (in) :: n
code = 100.0d0 * n
end function
public static double code(double i, double n) {
return 100.0 * n;
}
def code(i, n): return 100.0 * n
function code(i, n) return Float64(100.0 * n) end
function tmp = code(i, n) tmp = 100.0 * n; end
code[i_, n_] := N[(100.0 * n), $MachinePrecision]
100 \cdot n
Initial program 28.6%
Taylor expanded in i around 0
Applied rewrites48.5%
(FPCore (i n)
:precision binary64
(let* ((t_0 (+ 1.0 (/ i n))))
(*
100.0
(/
(-
(exp
(*
n
(if (== t_0 1.0)
(/ i n)
(/ (* (/ i n) (log t_0)) (- (+ (/ i n) 1.0) 1.0)))))
1.0)
(/ i n)))))double code(double i, double n) {
double t_0 = 1.0 + (i / n);
double tmp;
if (t_0 == 1.0) {
tmp = i / n;
} else {
tmp = ((i / n) * log(t_0)) / (((i / n) + 1.0) - 1.0);
}
return 100.0 * ((exp((n * tmp)) - 1.0) / (i / 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(i, n)
use fmin_fmax_functions
real(8), intent (in) :: i
real(8), intent (in) :: n
real(8) :: t_0
real(8) :: tmp
t_0 = 1.0d0 + (i / n)
if (t_0 == 1.0d0) then
tmp = i / n
else
tmp = ((i / n) * log(t_0)) / (((i / n) + 1.0d0) - 1.0d0)
end if
code = 100.0d0 * ((exp((n * tmp)) - 1.0d0) / (i / n))
end function
public static double code(double i, double n) {
double t_0 = 1.0 + (i / n);
double tmp;
if (t_0 == 1.0) {
tmp = i / n;
} else {
tmp = ((i / n) * Math.log(t_0)) / (((i / n) + 1.0) - 1.0);
}
return 100.0 * ((Math.exp((n * tmp)) - 1.0) / (i / n));
}
def code(i, n): t_0 = 1.0 + (i / n) tmp = 0 if t_0 == 1.0: tmp = i / n else: tmp = ((i / n) * math.log(t_0)) / (((i / n) + 1.0) - 1.0) return 100.0 * ((math.exp((n * tmp)) - 1.0) / (i / n))
function code(i, n) t_0 = Float64(1.0 + Float64(i / n)) tmp = 0.0 if (t_0 == 1.0) tmp = Float64(i / n); else tmp = Float64(Float64(Float64(i / n) * log(t_0)) / Float64(Float64(Float64(i / n) + 1.0) - 1.0)); end return Float64(100.0 * Float64(Float64(exp(Float64(n * tmp)) - 1.0) / Float64(i / n))) end
function tmp_2 = code(i, n) t_0 = 1.0 + (i / n); tmp = 0.0; if (t_0 == 1.0) tmp = i / n; else tmp = ((i / n) * log(t_0)) / (((i / n) + 1.0) - 1.0); end tmp_2 = 100.0 * ((exp((n * tmp)) - 1.0) / (i / n)); end
code[i_, n_] := Block[{t$95$0 = N[(1.0 + N[(i / n), $MachinePrecision]), $MachinePrecision]}, N[(100.0 * N[(N[(N[Exp[N[(n * If[Equal[t$95$0, 1.0], N[(i / n), $MachinePrecision], N[(N[(N[(i / n), $MachinePrecision] * N[Log[t$95$0], $MachinePrecision]), $MachinePrecision] / N[(N[(N[(i / n), $MachinePrecision] + 1.0), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]], $MachinePrecision] - 1.0), $MachinePrecision] / N[(i / n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
t_0 := 1 + \frac{i}{n}\\
100 \cdot \frac{e^{n \cdot \begin{array}{l}
\mathbf{if}\;t\_0 = 1:\\
\;\;\;\;\frac{i}{n}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{i}{n} \cdot \log t\_0}{\left(\frac{i}{n} + 1\right) - 1}\\
\end{array}} - 1}{\frac{i}{n}}
\end{array}
herbie shell --seed 2025212
(FPCore (i n)
:name "Compound Interest"
:precision binary64
:alt
(! :herbie-platform c (let ((lnbase (if (== (+ 1 (/ i n)) 1) (/ i n) (/ (* (/ i n) (log (+ 1 (/ i n)))) (- (+ (/ i n) 1) 1))))) (* 100 (/ (- (exp (* n lnbase)) 1) (/ i n)))))
(* 100.0 (/ (- (pow (+ 1.0 (/ i n)) n) 1.0) (/ i n))))