
(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));
}
real(8) function code(i, n)
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]
\begin{array}{l}
\\
100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 11 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));
}
real(8) function code(i, n)
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]
\begin{array}{l}
\\
100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}
\end{array}
(FPCore (i n)
:precision binary64
(let* ((t_0 (pow (+ 1.0 (/ i n)) n)) (t_1 (/ (+ t_0 -1.0) (/ i n))))
(if (<= t_1 0.0)
(* 100.0 (/ (expm1 (* n (log1p (/ i n)))) (/ i n)))
(if (<= t_1 INFINITY) (* n (/ (+ (* t_0 100.0) -100.0) i)) (* n 100.0)))))
double code(double i, double n) {
double t_0 = pow((1.0 + (i / n)), n);
double t_1 = (t_0 + -1.0) / (i / n);
double tmp;
if (t_1 <= 0.0) {
tmp = 100.0 * (expm1((n * log1p((i / n)))) / (i / n));
} else if (t_1 <= ((double) INFINITY)) {
tmp = n * (((t_0 * 100.0) + -100.0) / i);
} else {
tmp = n * 100.0;
}
return tmp;
}
public static double code(double i, double n) {
double t_0 = Math.pow((1.0 + (i / n)), n);
double t_1 = (t_0 + -1.0) / (i / n);
double tmp;
if (t_1 <= 0.0) {
tmp = 100.0 * (Math.expm1((n * Math.log1p((i / n)))) / (i / n));
} else if (t_1 <= Double.POSITIVE_INFINITY) {
tmp = n * (((t_0 * 100.0) + -100.0) / i);
} else {
tmp = n * 100.0;
}
return tmp;
}
def code(i, n): t_0 = math.pow((1.0 + (i / n)), n) t_1 = (t_0 + -1.0) / (i / n) tmp = 0 if t_1 <= 0.0: tmp = 100.0 * (math.expm1((n * math.log1p((i / n)))) / (i / n)) elif t_1 <= math.inf: tmp = n * (((t_0 * 100.0) + -100.0) / i) else: tmp = n * 100.0 return tmp
function code(i, n) t_0 = Float64(1.0 + Float64(i / n)) ^ n t_1 = Float64(Float64(t_0 + -1.0) / Float64(i / n)) tmp = 0.0 if (t_1 <= 0.0) tmp = Float64(100.0 * Float64(expm1(Float64(n * log1p(Float64(i / n)))) / Float64(i / n))); elseif (t_1 <= Inf) tmp = Float64(n * Float64(Float64(Float64(t_0 * 100.0) + -100.0) / i)); else tmp = Float64(n * 100.0); end return tmp end
code[i_, n_] := Block[{t$95$0 = N[Power[N[(1.0 + N[(i / n), $MachinePrecision]), $MachinePrecision], n], $MachinePrecision]}, Block[{t$95$1 = N[(N[(t$95$0 + -1.0), $MachinePrecision] / N[(i / n), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, 0.0], N[(100.0 * N[(N[(Exp[N[(n * N[Log[1 + N[(i / n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]] - 1), $MachinePrecision] / N[(i / n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, Infinity], N[(n * N[(N[(N[(t$95$0 * 100.0), $MachinePrecision] + -100.0), $MachinePrecision] / i), $MachinePrecision]), $MachinePrecision], N[(n * 100.0), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\left(1 + \frac{i}{n}\right)}^{n}\\
t_1 := \frac{t\_0 + -1}{\frac{i}{n}}\\
\mathbf{if}\;t\_1 \leq 0:\\
\;\;\;\;100 \cdot \frac{\mathsf{expm1}\left(n \cdot \mathsf{log1p}\left(\frac{i}{n}\right)\right)}{\frac{i}{n}}\\
\mathbf{elif}\;t\_1 \leq \infty:\\
\;\;\;\;n \cdot \frac{t\_0 \cdot 100 + -100}{i}\\
\mathbf{else}:\\
\;\;\;\;n \cdot 100\\
\end{array}
\end{array}
if (/.f64 (-.f64 (pow.f64 (+.f64 #s(literal 1 binary64) (/.f64 i n)) n) #s(literal 1 binary64)) (/.f64 i n)) < 0.0Initial program 24.2%
sub-neg24.2%
metadata-eval24.2%
Applied egg-rr24.2%
metadata-eval24.2%
sub-neg24.2%
exp-to-pow23.6%
log1p-undefine48.6%
*-commutative48.6%
expm1-undefine99.2%
Simplified99.2%
if 0.0 < (/.f64 (-.f64 (pow.f64 (+.f64 #s(literal 1 binary64) (/.f64 i n)) n) #s(literal 1 binary64)) (/.f64 i n)) < +inf.0Initial program 99.8%
associate-/r/99.7%
associate-*r*99.9%
*-commutative99.9%
associate-*r/100.0%
sub-neg100.0%
distribute-lft-in100.0%
metadata-eval100.0%
metadata-eval100.0%
metadata-eval100.0%
fma-define100.0%
metadata-eval100.0%
Simplified100.0%
fma-undefine100.0%
*-commutative100.0%
Applied egg-rr100.0%
if +inf.0 < (/.f64 (-.f64 (pow.f64 (+.f64 #s(literal 1 binary64) (/.f64 i n)) n) #s(literal 1 binary64)) (/.f64 i n)) Initial program 0.0%
Taylor expanded in i around 0 78.4%
*-commutative78.4%
Simplified78.4%
Final simplification95.7%
(FPCore (i n)
:precision binary64
(let* ((t_0 (* n (* 100.0 (/ (expm1 i) i)))))
(if (<= n -6.5e-217)
t_0
(if (<= n 2.65e-237) 0.0 (if (<= n 2.0) (* 100.0 (/ i (/ i n))) t_0)))))
double code(double i, double n) {
double t_0 = n * (100.0 * (expm1(i) / i));
double tmp;
if (n <= -6.5e-217) {
tmp = t_0;
} else if (n <= 2.65e-237) {
tmp = 0.0;
} else if (n <= 2.0) {
tmp = 100.0 * (i / (i / n));
} else {
tmp = t_0;
}
return tmp;
}
public static double code(double i, double n) {
double t_0 = n * (100.0 * (Math.expm1(i) / i));
double tmp;
if (n <= -6.5e-217) {
tmp = t_0;
} else if (n <= 2.65e-237) {
tmp = 0.0;
} else if (n <= 2.0) {
tmp = 100.0 * (i / (i / n));
} else {
tmp = t_0;
}
return tmp;
}
def code(i, n): t_0 = n * (100.0 * (math.expm1(i) / i)) tmp = 0 if n <= -6.5e-217: tmp = t_0 elif n <= 2.65e-237: tmp = 0.0 elif n <= 2.0: tmp = 100.0 * (i / (i / n)) else: tmp = t_0 return tmp
function code(i, n) t_0 = Float64(n * Float64(100.0 * Float64(expm1(i) / i))) tmp = 0.0 if (n <= -6.5e-217) tmp = t_0; elseif (n <= 2.65e-237) tmp = 0.0; elseif (n <= 2.0) tmp = Float64(100.0 * Float64(i / Float64(i / n))); else tmp = t_0; end return tmp end
code[i_, n_] := Block[{t$95$0 = N[(n * N[(100.0 * N[(N[(Exp[i] - 1), $MachinePrecision] / i), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[n, -6.5e-217], t$95$0, If[LessEqual[n, 2.65e-237], 0.0, If[LessEqual[n, 2.0], N[(100.0 * N[(i / N[(i / n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := n \cdot \left(100 \cdot \frac{\mathsf{expm1}\left(i\right)}{i}\right)\\
\mathbf{if}\;n \leq -6.5 \cdot 10^{-217}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;n \leq 2.65 \cdot 10^{-237}:\\
\;\;\;\;0\\
\mathbf{elif}\;n \leq 2:\\
\;\;\;\;100 \cdot \frac{i}{\frac{i}{n}}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if n < -6.4999999999999996e-217 or 2 < n Initial program 24.7%
associate-/r/24.7%
associate-*r*24.8%
*-commutative24.8%
associate-*r/24.8%
sub-neg24.8%
distribute-lft-in24.8%
metadata-eval24.8%
metadata-eval24.8%
metadata-eval24.8%
fma-define24.8%
metadata-eval24.8%
Simplified24.8%
Taylor expanded in n around inf 40.8%
sub-neg40.8%
metadata-eval40.8%
metadata-eval40.8%
distribute-lft-in40.8%
metadata-eval40.8%
sub-neg40.8%
associate-*r/40.8%
*-commutative40.8%
expm1-define89.1%
Simplified89.1%
if -6.4999999999999996e-217 < n < 2.64999999999999977e-237Initial program 66.7%
associate-*r/66.7%
sub-neg66.7%
distribute-rgt-in66.7%
metadata-eval66.7%
metadata-eval66.7%
Simplified66.7%
Taylor expanded in i around 0 81.7%
Taylor expanded in i around 0 81.7%
if 2.64999999999999977e-237 < n < 2Initial program 14.5%
Taylor expanded in i around 0 61.0%
Final simplification84.6%
(FPCore (i n)
:precision binary64
(if (<= i -1.4)
0.0
(*
100.0
(+
n
(*
i
(+
(* n 0.5)
(*
i
(+ (* 0.041666666666666664 (* i n)) (* n 0.16666666666666666)))))))))
double code(double i, double n) {
double tmp;
if (i <= -1.4) {
tmp = 0.0;
} else {
tmp = 100.0 * (n + (i * ((n * 0.5) + (i * ((0.041666666666666664 * (i * n)) + (n * 0.16666666666666666))))));
}
return tmp;
}
real(8) function code(i, n)
real(8), intent (in) :: i
real(8), intent (in) :: n
real(8) :: tmp
if (i <= (-1.4d0)) then
tmp = 0.0d0
else
tmp = 100.0d0 * (n + (i * ((n * 0.5d0) + (i * ((0.041666666666666664d0 * (i * n)) + (n * 0.16666666666666666d0))))))
end if
code = tmp
end function
public static double code(double i, double n) {
double tmp;
if (i <= -1.4) {
tmp = 0.0;
} else {
tmp = 100.0 * (n + (i * ((n * 0.5) + (i * ((0.041666666666666664 * (i * n)) + (n * 0.16666666666666666))))));
}
return tmp;
}
def code(i, n): tmp = 0 if i <= -1.4: tmp = 0.0 else: tmp = 100.0 * (n + (i * ((n * 0.5) + (i * ((0.041666666666666664 * (i * n)) + (n * 0.16666666666666666)))))) return tmp
function code(i, n) tmp = 0.0 if (i <= -1.4) tmp = 0.0; else tmp = Float64(100.0 * Float64(n + Float64(i * Float64(Float64(n * 0.5) + Float64(i * Float64(Float64(0.041666666666666664 * Float64(i * n)) + Float64(n * 0.16666666666666666))))))); end return tmp end
function tmp_2 = code(i, n) tmp = 0.0; if (i <= -1.4) tmp = 0.0; else tmp = 100.0 * (n + (i * ((n * 0.5) + (i * ((0.041666666666666664 * (i * n)) + (n * 0.16666666666666666)))))); end tmp_2 = tmp; end
code[i_, n_] := If[LessEqual[i, -1.4], 0.0, N[(100.0 * N[(n + N[(i * N[(N[(n * 0.5), $MachinePrecision] + N[(i * N[(N[(0.041666666666666664 * N[(i * n), $MachinePrecision]), $MachinePrecision] + N[(n * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;i \leq -1.4:\\
\;\;\;\;0\\
\mathbf{else}:\\
\;\;\;\;100 \cdot \left(n + i \cdot \left(n \cdot 0.5 + i \cdot \left(0.041666666666666664 \cdot \left(i \cdot n\right) + n \cdot 0.16666666666666666\right)\right)\right)\\
\end{array}
\end{array}
if i < -1.3999999999999999Initial program 60.0%
associate-*r/60.0%
sub-neg60.0%
distribute-rgt-in60.0%
metadata-eval60.0%
metadata-eval60.0%
Simplified60.0%
Taylor expanded in i around 0 37.5%
Taylor expanded in i around 0 37.5%
if -1.3999999999999999 < i Initial program 18.8%
Taylor expanded in n around inf 28.3%
*-commutative28.3%
associate-/l*28.3%
expm1-define78.4%
Simplified78.4%
Taylor expanded in i around 0 72.2%
Final simplification65.7%
(FPCore (i n)
:precision binary64
(if (<= i -1.9)
0.0
(*
n
(+
100.0
(* i (+ 50.0 (* i (+ 16.666666666666668 (* i 4.166666666666667)))))))))
double code(double i, double n) {
double tmp;
if (i <= -1.9) {
tmp = 0.0;
} else {
tmp = n * (100.0 + (i * (50.0 + (i * (16.666666666666668 + (i * 4.166666666666667))))));
}
return tmp;
}
real(8) function code(i, n)
real(8), intent (in) :: i
real(8), intent (in) :: n
real(8) :: tmp
if (i <= (-1.9d0)) then
tmp = 0.0d0
else
tmp = n * (100.0d0 + (i * (50.0d0 + (i * (16.666666666666668d0 + (i * 4.166666666666667d0))))))
end if
code = tmp
end function
public static double code(double i, double n) {
double tmp;
if (i <= -1.9) {
tmp = 0.0;
} else {
tmp = n * (100.0 + (i * (50.0 + (i * (16.666666666666668 + (i * 4.166666666666667))))));
}
return tmp;
}
def code(i, n): tmp = 0 if i <= -1.9: tmp = 0.0 else: tmp = n * (100.0 + (i * (50.0 + (i * (16.666666666666668 + (i * 4.166666666666667)))))) return tmp
function code(i, n) tmp = 0.0 if (i <= -1.9) tmp = 0.0; else tmp = Float64(n * Float64(100.0 + Float64(i * Float64(50.0 + Float64(i * Float64(16.666666666666668 + Float64(i * 4.166666666666667))))))); end return tmp end
function tmp_2 = code(i, n) tmp = 0.0; if (i <= -1.9) tmp = 0.0; else tmp = n * (100.0 + (i * (50.0 + (i * (16.666666666666668 + (i * 4.166666666666667)))))); end tmp_2 = tmp; end
code[i_, n_] := If[LessEqual[i, -1.9], 0.0, N[(n * N[(100.0 + N[(i * N[(50.0 + N[(i * N[(16.666666666666668 + N[(i * 4.166666666666667), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;i \leq -1.9:\\
\;\;\;\;0\\
\mathbf{else}:\\
\;\;\;\;n \cdot \left(100 + i \cdot \left(50 + i \cdot \left(16.666666666666668 + i \cdot 4.166666666666667\right)\right)\right)\\
\end{array}
\end{array}
if i < -1.8999999999999999Initial program 60.0%
associate-*r/60.0%
sub-neg60.0%
distribute-rgt-in60.0%
metadata-eval60.0%
metadata-eval60.0%
Simplified60.0%
Taylor expanded in i around 0 37.5%
Taylor expanded in i around 0 37.5%
if -1.8999999999999999 < i Initial program 18.8%
associate-/r/19.2%
associate-*r*19.2%
*-commutative19.2%
associate-*r/19.2%
sub-neg19.2%
distribute-lft-in19.2%
metadata-eval19.2%
metadata-eval19.2%
metadata-eval19.2%
fma-define19.2%
metadata-eval19.2%
Simplified19.2%
Taylor expanded in n around inf 28.3%
sub-neg28.3%
metadata-eval28.3%
metadata-eval28.3%
distribute-lft-in28.3%
metadata-eval28.3%
sub-neg28.3%
associate-*r/28.3%
*-commutative28.3%
expm1-define78.4%
Simplified78.4%
Taylor expanded in i around 0 72.2%
*-commutative72.2%
Simplified72.2%
(FPCore (i n) :precision binary64 (if (<= i -8.6e+23) 0.0 (if (<= i 0.0152) (* 100.0 (+ n (* i -0.5))) (* (* i n) 50.0))))
double code(double i, double n) {
double tmp;
if (i <= -8.6e+23) {
tmp = 0.0;
} else if (i <= 0.0152) {
tmp = 100.0 * (n + (i * -0.5));
} else {
tmp = (i * n) * 50.0;
}
return tmp;
}
real(8) function code(i, n)
real(8), intent (in) :: i
real(8), intent (in) :: n
real(8) :: tmp
if (i <= (-8.6d+23)) then
tmp = 0.0d0
else if (i <= 0.0152d0) then
tmp = 100.0d0 * (n + (i * (-0.5d0)))
else
tmp = (i * n) * 50.0d0
end if
code = tmp
end function
public static double code(double i, double n) {
double tmp;
if (i <= -8.6e+23) {
tmp = 0.0;
} else if (i <= 0.0152) {
tmp = 100.0 * (n + (i * -0.5));
} else {
tmp = (i * n) * 50.0;
}
return tmp;
}
def code(i, n): tmp = 0 if i <= -8.6e+23: tmp = 0.0 elif i <= 0.0152: tmp = 100.0 * (n + (i * -0.5)) else: tmp = (i * n) * 50.0 return tmp
function code(i, n) tmp = 0.0 if (i <= -8.6e+23) tmp = 0.0; elseif (i <= 0.0152) tmp = Float64(100.0 * Float64(n + Float64(i * -0.5))); else tmp = Float64(Float64(i * n) * 50.0); end return tmp end
function tmp_2 = code(i, n) tmp = 0.0; if (i <= -8.6e+23) tmp = 0.0; elseif (i <= 0.0152) tmp = 100.0 * (n + (i * -0.5)); else tmp = (i * n) * 50.0; end tmp_2 = tmp; end
code[i_, n_] := If[LessEqual[i, -8.6e+23], 0.0, If[LessEqual[i, 0.0152], N[(100.0 * N[(n + N[(i * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(i * n), $MachinePrecision] * 50.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;i \leq -8.6 \cdot 10^{+23}:\\
\;\;\;\;0\\
\mathbf{elif}\;i \leq 0.0152:\\
\;\;\;\;100 \cdot \left(n + i \cdot -0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\left(i \cdot n\right) \cdot 50\\
\end{array}
\end{array}
if i < -8.5999999999999997e23Initial program 67.6%
associate-*r/67.6%
sub-neg67.6%
distribute-rgt-in67.6%
metadata-eval67.6%
metadata-eval67.6%
Simplified67.6%
Taylor expanded in i around 0 43.6%
Taylor expanded in i around 0 43.6%
if -8.5999999999999997e23 < i < 0.0152Initial program 8.7%
Taylor expanded in i around 0 82.7%
associate-*r*82.5%
associate-*r/82.5%
metadata-eval82.5%
Simplified82.5%
Taylor expanded in n around 0 82.7%
*-commutative82.7%
Simplified82.7%
if 0.0152 < i Initial program 38.5%
associate-/r/38.7%
associate-*r*38.8%
*-commutative38.8%
associate-*r/38.8%
sub-neg38.8%
distribute-lft-in38.8%
metadata-eval38.8%
metadata-eval38.8%
metadata-eval38.8%
fma-define38.8%
metadata-eval38.8%
Simplified38.8%
Taylor expanded in n around inf 63.1%
sub-neg63.1%
metadata-eval63.1%
metadata-eval63.1%
distribute-lft-in63.1%
metadata-eval63.1%
sub-neg63.1%
associate-*r/63.1%
*-commutative63.1%
expm1-define63.1%
Simplified63.1%
Taylor expanded in i around 0 29.9%
Taylor expanded in i around inf 29.9%
Final simplification61.6%
(FPCore (i n) :precision binary64 (if (<= i -5.2e+19) 0.0 (* n (+ 100.0 (* i (+ 50.0 (* i 16.666666666666668)))))))
double code(double i, double n) {
double tmp;
if (i <= -5.2e+19) {
tmp = 0.0;
} else {
tmp = n * (100.0 + (i * (50.0 + (i * 16.666666666666668))));
}
return tmp;
}
real(8) function code(i, n)
real(8), intent (in) :: i
real(8), intent (in) :: n
real(8) :: tmp
if (i <= (-5.2d+19)) then
tmp = 0.0d0
else
tmp = n * (100.0d0 + (i * (50.0d0 + (i * 16.666666666666668d0))))
end if
code = tmp
end function
public static double code(double i, double n) {
double tmp;
if (i <= -5.2e+19) {
tmp = 0.0;
} else {
tmp = n * (100.0 + (i * (50.0 + (i * 16.666666666666668))));
}
return tmp;
}
def code(i, n): tmp = 0 if i <= -5.2e+19: tmp = 0.0 else: tmp = n * (100.0 + (i * (50.0 + (i * 16.666666666666668)))) return tmp
function code(i, n) tmp = 0.0 if (i <= -5.2e+19) tmp = 0.0; else tmp = Float64(n * Float64(100.0 + Float64(i * Float64(50.0 + Float64(i * 16.666666666666668))))); end return tmp end
function tmp_2 = code(i, n) tmp = 0.0; if (i <= -5.2e+19) tmp = 0.0; else tmp = n * (100.0 + (i * (50.0 + (i * 16.666666666666668)))); end tmp_2 = tmp; end
code[i_, n_] := If[LessEqual[i, -5.2e+19], 0.0, N[(n * N[(100.0 + N[(i * N[(50.0 + N[(i * 16.666666666666668), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;i \leq -5.2 \cdot 10^{+19}:\\
\;\;\;\;0\\
\mathbf{else}:\\
\;\;\;\;n \cdot \left(100 + i \cdot \left(50 + i \cdot 16.666666666666668\right)\right)\\
\end{array}
\end{array}
if i < -5.2e19Initial program 67.6%
associate-*r/67.6%
sub-neg67.6%
distribute-rgt-in67.6%
metadata-eval67.6%
metadata-eval67.6%
Simplified67.6%
Taylor expanded in i around 0 43.6%
Taylor expanded in i around 0 43.6%
if -5.2e19 < i Initial program 18.7%
associate-/r/19.1%
associate-*r*19.1%
*-commutative19.1%
associate-*r/19.1%
sub-neg19.1%
distribute-lft-in19.1%
metadata-eval19.1%
metadata-eval19.1%
metadata-eval19.1%
fma-define19.1%
metadata-eval19.1%
Simplified19.1%
Taylor expanded in n around inf 30.3%
sub-neg30.3%
metadata-eval30.3%
metadata-eval30.3%
distribute-lft-in30.3%
metadata-eval30.3%
sub-neg30.3%
associate-*r/30.3%
*-commutative30.3%
expm1-define78.8%
Simplified78.8%
Taylor expanded in i around 0 69.3%
*-commutative69.3%
Simplified69.3%
(FPCore (i n) :precision binary64 (if (<= i -4.2e+20) 0.0 (if (<= i 0.0152) (* n 100.0) (* (* i n) 50.0))))
double code(double i, double n) {
double tmp;
if (i <= -4.2e+20) {
tmp = 0.0;
} else if (i <= 0.0152) {
tmp = n * 100.0;
} else {
tmp = (i * n) * 50.0;
}
return tmp;
}
real(8) function code(i, n)
real(8), intent (in) :: i
real(8), intent (in) :: n
real(8) :: tmp
if (i <= (-4.2d+20)) then
tmp = 0.0d0
else if (i <= 0.0152d0) then
tmp = n * 100.0d0
else
tmp = (i * n) * 50.0d0
end if
code = tmp
end function
public static double code(double i, double n) {
double tmp;
if (i <= -4.2e+20) {
tmp = 0.0;
} else if (i <= 0.0152) {
tmp = n * 100.0;
} else {
tmp = (i * n) * 50.0;
}
return tmp;
}
def code(i, n): tmp = 0 if i <= -4.2e+20: tmp = 0.0 elif i <= 0.0152: tmp = n * 100.0 else: tmp = (i * n) * 50.0 return tmp
function code(i, n) tmp = 0.0 if (i <= -4.2e+20) tmp = 0.0; elseif (i <= 0.0152) tmp = Float64(n * 100.0); else tmp = Float64(Float64(i * n) * 50.0); end return tmp end
function tmp_2 = code(i, n) tmp = 0.0; if (i <= -4.2e+20) tmp = 0.0; elseif (i <= 0.0152) tmp = n * 100.0; else tmp = (i * n) * 50.0; end tmp_2 = tmp; end
code[i_, n_] := If[LessEqual[i, -4.2e+20], 0.0, If[LessEqual[i, 0.0152], N[(n * 100.0), $MachinePrecision], N[(N[(i * n), $MachinePrecision] * 50.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;i \leq -4.2 \cdot 10^{+20}:\\
\;\;\;\;0\\
\mathbf{elif}\;i \leq 0.0152:\\
\;\;\;\;n \cdot 100\\
\mathbf{else}:\\
\;\;\;\;\left(i \cdot n\right) \cdot 50\\
\end{array}
\end{array}
if i < -4.2e20Initial program 67.6%
associate-*r/67.6%
sub-neg67.6%
distribute-rgt-in67.6%
metadata-eval67.6%
metadata-eval67.6%
Simplified67.6%
Taylor expanded in i around 0 43.6%
Taylor expanded in i around 0 43.6%
if -4.2e20 < i < 0.0152Initial program 8.7%
Taylor expanded in i around 0 82.4%
*-commutative82.4%
Simplified82.4%
if 0.0152 < i Initial program 38.5%
associate-/r/38.7%
associate-*r*38.8%
*-commutative38.8%
associate-*r/38.8%
sub-neg38.8%
distribute-lft-in38.8%
metadata-eval38.8%
metadata-eval38.8%
metadata-eval38.8%
fma-define38.8%
metadata-eval38.8%
Simplified38.8%
Taylor expanded in n around inf 63.1%
sub-neg63.1%
metadata-eval63.1%
metadata-eval63.1%
distribute-lft-in63.1%
metadata-eval63.1%
sub-neg63.1%
associate-*r/63.1%
*-commutative63.1%
expm1-define63.1%
Simplified63.1%
Taylor expanded in i around 0 29.9%
Taylor expanded in i around inf 29.9%
Final simplification61.4%
(FPCore (i n) :precision binary64 (if (<= i -2.0) 0.0 (+ (* n 100.0) (* (* i n) 50.0))))
double code(double i, double n) {
double tmp;
if (i <= -2.0) {
tmp = 0.0;
} else {
tmp = (n * 100.0) + ((i * n) * 50.0);
}
return tmp;
}
real(8) function code(i, n)
real(8), intent (in) :: i
real(8), intent (in) :: n
real(8) :: tmp
if (i <= (-2.0d0)) then
tmp = 0.0d0
else
tmp = (n * 100.0d0) + ((i * n) * 50.0d0)
end if
code = tmp
end function
public static double code(double i, double n) {
double tmp;
if (i <= -2.0) {
tmp = 0.0;
} else {
tmp = (n * 100.0) + ((i * n) * 50.0);
}
return tmp;
}
def code(i, n): tmp = 0 if i <= -2.0: tmp = 0.0 else: tmp = (n * 100.0) + ((i * n) * 50.0) return tmp
function code(i, n) tmp = 0.0 if (i <= -2.0) tmp = 0.0; else tmp = Float64(Float64(n * 100.0) + Float64(Float64(i * n) * 50.0)); end return tmp end
function tmp_2 = code(i, n) tmp = 0.0; if (i <= -2.0) tmp = 0.0; else tmp = (n * 100.0) + ((i * n) * 50.0); end tmp_2 = tmp; end
code[i_, n_] := If[LessEqual[i, -2.0], 0.0, N[(N[(n * 100.0), $MachinePrecision] + N[(N[(i * n), $MachinePrecision] * 50.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;i \leq -2:\\
\;\;\;\;0\\
\mathbf{else}:\\
\;\;\;\;n \cdot 100 + \left(i \cdot n\right) \cdot 50\\
\end{array}
\end{array}
if i < -2Initial program 60.0%
associate-*r/60.0%
sub-neg60.0%
distribute-rgt-in60.0%
metadata-eval60.0%
metadata-eval60.0%
Simplified60.0%
Taylor expanded in i around 0 37.5%
Taylor expanded in i around 0 37.5%
if -2 < i Initial program 18.8%
associate-/r/19.2%
associate-*r*19.2%
*-commutative19.2%
associate-*r/19.2%
sub-neg19.2%
distribute-lft-in19.2%
metadata-eval19.2%
metadata-eval19.2%
metadata-eval19.2%
fma-define19.2%
metadata-eval19.2%
Simplified19.2%
Taylor expanded in n around inf 28.3%
sub-neg28.3%
metadata-eval28.3%
metadata-eval28.3%
distribute-lft-in28.3%
metadata-eval28.3%
sub-neg28.3%
associate-*r/28.3%
*-commutative28.3%
expm1-define78.4%
Simplified78.4%
Taylor expanded in i around 0 67.0%
Final simplification61.4%
(FPCore (i n) :precision binary64 (if (<= i -1.4e+25) 0.0 (if (<= i 2.8e+19) (* n 100.0) 0.0)))
double code(double i, double n) {
double tmp;
if (i <= -1.4e+25) {
tmp = 0.0;
} else if (i <= 2.8e+19) {
tmp = n * 100.0;
} else {
tmp = 0.0;
}
return tmp;
}
real(8) function code(i, n)
real(8), intent (in) :: i
real(8), intent (in) :: n
real(8) :: tmp
if (i <= (-1.4d+25)) then
tmp = 0.0d0
else if (i <= 2.8d+19) then
tmp = n * 100.0d0
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double i, double n) {
double tmp;
if (i <= -1.4e+25) {
tmp = 0.0;
} else if (i <= 2.8e+19) {
tmp = n * 100.0;
} else {
tmp = 0.0;
}
return tmp;
}
def code(i, n): tmp = 0 if i <= -1.4e+25: tmp = 0.0 elif i <= 2.8e+19: tmp = n * 100.0 else: tmp = 0.0 return tmp
function code(i, n) tmp = 0.0 if (i <= -1.4e+25) tmp = 0.0; elseif (i <= 2.8e+19) tmp = Float64(n * 100.0); else tmp = 0.0; end return tmp end
function tmp_2 = code(i, n) tmp = 0.0; if (i <= -1.4e+25) tmp = 0.0; elseif (i <= 2.8e+19) tmp = n * 100.0; else tmp = 0.0; end tmp_2 = tmp; end
code[i_, n_] := If[LessEqual[i, -1.4e+25], 0.0, If[LessEqual[i, 2.8e+19], N[(n * 100.0), $MachinePrecision], 0.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;i \leq -1.4 \cdot 10^{+25}:\\
\;\;\;\;0\\
\mathbf{elif}\;i \leq 2.8 \cdot 10^{+19}:\\
\;\;\;\;n \cdot 100\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if i < -1.4000000000000001e25 or 2.8e19 < i Initial program 52.2%
associate-*r/52.2%
sub-neg52.2%
distribute-rgt-in52.2%
metadata-eval52.2%
metadata-eval52.2%
Simplified52.2%
Taylor expanded in i around 0 30.7%
Taylor expanded in i around 0 30.7%
if -1.4000000000000001e25 < i < 2.8e19Initial program 8.9%
Taylor expanded in i around 0 77.8%
*-commutative77.8%
Simplified77.8%
(FPCore (i n) :precision binary64 (if (<= i -2.0) 0.0 (* n (+ 100.0 (* i 50.0)))))
double code(double i, double n) {
double tmp;
if (i <= -2.0) {
tmp = 0.0;
} else {
tmp = n * (100.0 + (i * 50.0));
}
return tmp;
}
real(8) function code(i, n)
real(8), intent (in) :: i
real(8), intent (in) :: n
real(8) :: tmp
if (i <= (-2.0d0)) then
tmp = 0.0d0
else
tmp = n * (100.0d0 + (i * 50.0d0))
end if
code = tmp
end function
public static double code(double i, double n) {
double tmp;
if (i <= -2.0) {
tmp = 0.0;
} else {
tmp = n * (100.0 + (i * 50.0));
}
return tmp;
}
def code(i, n): tmp = 0 if i <= -2.0: tmp = 0.0 else: tmp = n * (100.0 + (i * 50.0)) return tmp
function code(i, n) tmp = 0.0 if (i <= -2.0) tmp = 0.0; else tmp = Float64(n * Float64(100.0 + Float64(i * 50.0))); end return tmp end
function tmp_2 = code(i, n) tmp = 0.0; if (i <= -2.0) tmp = 0.0; else tmp = n * (100.0 + (i * 50.0)); end tmp_2 = tmp; end
code[i_, n_] := If[LessEqual[i, -2.0], 0.0, N[(n * N[(100.0 + N[(i * 50.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;i \leq -2:\\
\;\;\;\;0\\
\mathbf{else}:\\
\;\;\;\;n \cdot \left(100 + i \cdot 50\right)\\
\end{array}
\end{array}
if i < -2Initial program 60.0%
associate-*r/60.0%
sub-neg60.0%
distribute-rgt-in60.0%
metadata-eval60.0%
metadata-eval60.0%
Simplified60.0%
Taylor expanded in i around 0 37.5%
Taylor expanded in i around 0 37.5%
if -2 < i Initial program 18.8%
associate-/r/19.2%
associate-*r*19.2%
*-commutative19.2%
associate-*r/19.2%
sub-neg19.2%
distribute-lft-in19.2%
metadata-eval19.2%
metadata-eval19.2%
metadata-eval19.2%
fma-define19.2%
metadata-eval19.2%
Simplified19.2%
Taylor expanded in n around inf 28.3%
sub-neg28.3%
metadata-eval28.3%
metadata-eval28.3%
distribute-lft-in28.3%
metadata-eval28.3%
sub-neg28.3%
associate-*r/28.3%
*-commutative28.3%
expm1-define78.4%
Simplified78.4%
Taylor expanded in i around 0 66.9%
*-commutative66.9%
Simplified66.9%
(FPCore (i n) :precision binary64 0.0)
double code(double i, double n) {
return 0.0;
}
real(8) function code(i, n)
real(8), intent (in) :: i
real(8), intent (in) :: n
code = 0.0d0
end function
public static double code(double i, double n) {
return 0.0;
}
def code(i, n): return 0.0
function code(i, n) return 0.0 end
function tmp = code(i, n) tmp = 0.0; end
code[i_, n_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 26.5%
associate-*r/26.5%
sub-neg26.5%
distribute-rgt-in26.5%
metadata-eval26.5%
metadata-eval26.5%
Simplified26.5%
Taylor expanded in i around 0 17.0%
Taylor expanded in i around 0 17.3%
(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));
}
real(8) function code(i, n)
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}
\\
\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}
\end{array}
herbie shell --seed 2024100
(FPCore (i n)
:name "Compound Interest"
:precision binary64
:alt
(* 100.0 (/ (- (exp (* n (if (== (+ 1.0 (/ i n)) 1.0) (/ i n) (/ (* (/ i n) (log (+ 1.0 (/ i n)))) (- (+ (/ i n) 1.0) 1.0))))) 1.0) (/ i n)))
(* 100.0 (/ (- (pow (+ 1.0 (/ i n)) n) 1.0) (/ i n))))