
(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 10 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)))
(if (<= n -3.3e+226)
(/ (/ (/ t_0 (/ i n)) (/ i n)) (/ i n))
(if (<= n 1.65e+157)
(* 100.0 (/ (- t_0 1.0) (/ i n)))
(/ (pow (+ 1.0 t_0) n) (/ i n))))))
double code(double i, double n) {
double t_0 = pow((1.0 + (i / n)), n);
double tmp;
if (n <= -3.3e+226) {
tmp = ((t_0 / (i / n)) / (i / n)) / (i / n);
} else if (n <= 1.65e+157) {
tmp = 100.0 * ((t_0 - 1.0) / (i / n));
} else {
tmp = pow((1.0 + t_0), n) / (i / n);
}
return tmp;
}
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)) ** n
if (n <= (-3.3d+226)) then
tmp = ((t_0 / (i / n)) / (i / n)) / (i / n)
else if (n <= 1.65d+157) then
tmp = 100.0d0 * ((t_0 - 1.0d0) / (i / n))
else
tmp = ((1.0d0 + t_0) ** n) / (i / n)
end if
code = tmp
end function
public static double code(double i, double n) {
double t_0 = Math.pow((1.0 + (i / n)), n);
double tmp;
if (n <= -3.3e+226) {
tmp = ((t_0 / (i / n)) / (i / n)) / (i / n);
} else if (n <= 1.65e+157) {
tmp = 100.0 * ((t_0 - 1.0) / (i / n));
} else {
tmp = Math.pow((1.0 + t_0), n) / (i / n);
}
return tmp;
}
def code(i, n): t_0 = math.pow((1.0 + (i / n)), n) tmp = 0 if n <= -3.3e+226: tmp = ((t_0 / (i / n)) / (i / n)) / (i / n) elif n <= 1.65e+157: tmp = 100.0 * ((t_0 - 1.0) / (i / n)) else: tmp = math.pow((1.0 + t_0), n) / (i / n) return tmp
function code(i, n) t_0 = Float64(1.0 + Float64(i / n)) ^ n tmp = 0.0 if (n <= -3.3e+226) tmp = Float64(Float64(Float64(t_0 / Float64(i / n)) / Float64(i / n)) / Float64(i / n)); elseif (n <= 1.65e+157) tmp = Float64(100.0 * Float64(Float64(t_0 - 1.0) / Float64(i / n))); else tmp = Float64((Float64(1.0 + t_0) ^ n) / Float64(i / n)); end return tmp end
function tmp_2 = code(i, n) t_0 = (1.0 + (i / n)) ^ n; tmp = 0.0; if (n <= -3.3e+226) tmp = ((t_0 / (i / n)) / (i / n)) / (i / n); elseif (n <= 1.65e+157) tmp = 100.0 * ((t_0 - 1.0) / (i / n)); else tmp = ((1.0 + t_0) ^ n) / (i / n); end tmp_2 = tmp; end
code[i_, n_] := Block[{t$95$0 = N[Power[N[(1.0 + N[(i / n), $MachinePrecision]), $MachinePrecision], n], $MachinePrecision]}, If[LessEqual[n, -3.3e+226], N[(N[(N[(t$95$0 / N[(i / n), $MachinePrecision]), $MachinePrecision] / N[(i / n), $MachinePrecision]), $MachinePrecision] / N[(i / n), $MachinePrecision]), $MachinePrecision], If[LessEqual[n, 1.65e+157], N[(100.0 * N[(N[(t$95$0 - 1.0), $MachinePrecision] / N[(i / n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Power[N[(1.0 + t$95$0), $MachinePrecision], n], $MachinePrecision] / N[(i / n), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\left(1 + \frac{i}{n}\right)}^{n}\\
\mathbf{if}\;n \leq -3.3 \cdot 10^{+226}:\\
\;\;\;\;\frac{\frac{\frac{t\_0}{\frac{i}{n}}}{\frac{i}{n}}}{\frac{i}{n}}\\
\mathbf{elif}\;n \leq 1.65 \cdot 10^{+157}:\\
\;\;\;\;100 \cdot \frac{t\_0 - 1}{\frac{i}{n}}\\
\mathbf{else}:\\
\;\;\;\;\frac{{\left(1 + t\_0\right)}^{n}}{\frac{i}{n}}\\
\end{array}
\end{array}
if n < -3.29999999999999978e226Initial program 5.5%
Taylor expanded in i around 0
Applied rewrites1.6%
Taylor expanded in i around 0
Applied rewrites3.4%
Taylor expanded in i around 0
Applied rewrites1.0%
Taylor expanded in i around 0
Applied rewrites24.8%
if -3.29999999999999978e226 < n < 1.6500000000000001e157Initial program 31.7%
if 1.6500000000000001e157 < n Initial program 18.8%
Taylor expanded in i around 0
Applied rewrites16.9%
Taylor expanded in i around 0
Applied rewrites17.8%
Taylor expanded in i around 0
Applied rewrites36.6%
(FPCore (i n)
:precision binary64
(let* ((t_0 (pow (+ 1.0 (/ i n)) n)))
(if (<= n -3.3e+226)
(/ (/ (/ t_0 (/ i n)) (/ i n)) (/ i n))
(if (<= n 1.65e+172)
(* 100.0 (/ (- t_0 1.0) (/ i n)))
(pow (+ 1.0 t_0) n)))))
double code(double i, double n) {
double t_0 = pow((1.0 + (i / n)), n);
double tmp;
if (n <= -3.3e+226) {
tmp = ((t_0 / (i / n)) / (i / n)) / (i / n);
} else if (n <= 1.65e+172) {
tmp = 100.0 * ((t_0 - 1.0) / (i / n));
} else {
tmp = pow((1.0 + t_0), n);
}
return tmp;
}
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)) ** n
if (n <= (-3.3d+226)) then
tmp = ((t_0 / (i / n)) / (i / n)) / (i / n)
else if (n <= 1.65d+172) then
tmp = 100.0d0 * ((t_0 - 1.0d0) / (i / n))
else
tmp = (1.0d0 + t_0) ** n
end if
code = tmp
end function
public static double code(double i, double n) {
double t_0 = Math.pow((1.0 + (i / n)), n);
double tmp;
if (n <= -3.3e+226) {
tmp = ((t_0 / (i / n)) / (i / n)) / (i / n);
} else if (n <= 1.65e+172) {
tmp = 100.0 * ((t_0 - 1.0) / (i / n));
} else {
tmp = Math.pow((1.0 + t_0), n);
}
return tmp;
}
def code(i, n): t_0 = math.pow((1.0 + (i / n)), n) tmp = 0 if n <= -3.3e+226: tmp = ((t_0 / (i / n)) / (i / n)) / (i / n) elif n <= 1.65e+172: tmp = 100.0 * ((t_0 - 1.0) / (i / n)) else: tmp = math.pow((1.0 + t_0), n) return tmp
function code(i, n) t_0 = Float64(1.0 + Float64(i / n)) ^ n tmp = 0.0 if (n <= -3.3e+226) tmp = Float64(Float64(Float64(t_0 / Float64(i / n)) / Float64(i / n)) / Float64(i / n)); elseif (n <= 1.65e+172) tmp = Float64(100.0 * Float64(Float64(t_0 - 1.0) / Float64(i / n))); else tmp = Float64(1.0 + t_0) ^ n; end return tmp end
function tmp_2 = code(i, n) t_0 = (1.0 + (i / n)) ^ n; tmp = 0.0; if (n <= -3.3e+226) tmp = ((t_0 / (i / n)) / (i / n)) / (i / n); elseif (n <= 1.65e+172) tmp = 100.0 * ((t_0 - 1.0) / (i / n)); else tmp = (1.0 + t_0) ^ n; end tmp_2 = tmp; end
code[i_, n_] := Block[{t$95$0 = N[Power[N[(1.0 + N[(i / n), $MachinePrecision]), $MachinePrecision], n], $MachinePrecision]}, If[LessEqual[n, -3.3e+226], N[(N[(N[(t$95$0 / N[(i / n), $MachinePrecision]), $MachinePrecision] / N[(i / n), $MachinePrecision]), $MachinePrecision] / N[(i / n), $MachinePrecision]), $MachinePrecision], If[LessEqual[n, 1.65e+172], N[(100.0 * N[(N[(t$95$0 - 1.0), $MachinePrecision] / N[(i / n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Power[N[(1.0 + t$95$0), $MachinePrecision], n], $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\left(1 + \frac{i}{n}\right)}^{n}\\
\mathbf{if}\;n \leq -3.3 \cdot 10^{+226}:\\
\;\;\;\;\frac{\frac{\frac{t\_0}{\frac{i}{n}}}{\frac{i}{n}}}{\frac{i}{n}}\\
\mathbf{elif}\;n \leq 1.65 \cdot 10^{+172}:\\
\;\;\;\;100 \cdot \frac{t\_0 - 1}{\frac{i}{n}}\\
\mathbf{else}:\\
\;\;\;\;{\left(1 + t\_0\right)}^{n}\\
\end{array}
\end{array}
if n < -3.29999999999999978e226Initial program 5.5%
Taylor expanded in i around 0
Applied rewrites1.6%
Taylor expanded in i around 0
Applied rewrites3.4%
Taylor expanded in i around 0
Applied rewrites1.0%
Taylor expanded in i around 0
Applied rewrites24.8%
if -3.29999999999999978e226 < n < 1.64999999999999991e172Initial program 31.5%
if 1.64999999999999991e172 < n Initial program 18.1%
Taylor expanded in i around 0
Applied rewrites16.0%
Taylor expanded in i around 0
Applied rewrites16.9%
Taylor expanded in i around 0
Applied rewrites37.7%
Taylor expanded in i around 0
Applied rewrites36.1%
(FPCore (i n)
:precision binary64
(let* ((t_0 (pow (+ 1.0 (/ i n)) n)) (t_1 (* 100.0 (/ (- t_0 1.0) (/ i n)))))
(if (<= i 7.8e-169)
t_1
(if (<= i 6.5e+195) (/ (/ (/ t_0 (/ i n)) (/ i n)) (/ i n)) t_1))))
double code(double i, double n) {
double t_0 = pow((1.0 + (i / n)), n);
double t_1 = 100.0 * ((t_0 - 1.0) / (i / n));
double tmp;
if (i <= 7.8e-169) {
tmp = t_1;
} else if (i <= 6.5e+195) {
tmp = ((t_0 / (i / n)) / (i / n)) / (i / n);
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(i, n)
real(8), intent (in) :: i
real(8), intent (in) :: n
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = (1.0d0 + (i / n)) ** n
t_1 = 100.0d0 * ((t_0 - 1.0d0) / (i / n))
if (i <= 7.8d-169) then
tmp = t_1
else if (i <= 6.5d+195) then
tmp = ((t_0 / (i / n)) / (i / n)) / (i / n)
else
tmp = t_1
end if
code = tmp
end function
public static double code(double i, double n) {
double t_0 = Math.pow((1.0 + (i / n)), n);
double t_1 = 100.0 * ((t_0 - 1.0) / (i / n));
double tmp;
if (i <= 7.8e-169) {
tmp = t_1;
} else if (i <= 6.5e+195) {
tmp = ((t_0 / (i / n)) / (i / n)) / (i / n);
} else {
tmp = t_1;
}
return tmp;
}
def code(i, n): t_0 = math.pow((1.0 + (i / n)), n) t_1 = 100.0 * ((t_0 - 1.0) / (i / n)) tmp = 0 if i <= 7.8e-169: tmp = t_1 elif i <= 6.5e+195: tmp = ((t_0 / (i / n)) / (i / n)) / (i / n) else: tmp = t_1 return tmp
function code(i, n) t_0 = Float64(1.0 + Float64(i / n)) ^ n t_1 = Float64(100.0 * Float64(Float64(t_0 - 1.0) / Float64(i / n))) tmp = 0.0 if (i <= 7.8e-169) tmp = t_1; elseif (i <= 6.5e+195) tmp = Float64(Float64(Float64(t_0 / Float64(i / n)) / Float64(i / n)) / Float64(i / n)); else tmp = t_1; end return tmp end
function tmp_2 = code(i, n) t_0 = (1.0 + (i / n)) ^ n; t_1 = 100.0 * ((t_0 - 1.0) / (i / n)); tmp = 0.0; if (i <= 7.8e-169) tmp = t_1; elseif (i <= 6.5e+195) tmp = ((t_0 / (i / n)) / (i / n)) / (i / n); else tmp = t_1; end tmp_2 = 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[(100.0 * N[(N[(t$95$0 - 1.0), $MachinePrecision] / N[(i / n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[i, 7.8e-169], t$95$1, If[LessEqual[i, 6.5e+195], N[(N[(N[(t$95$0 / N[(i / n), $MachinePrecision]), $MachinePrecision] / N[(i / n), $MachinePrecision]), $MachinePrecision] / N[(i / n), $MachinePrecision]), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\left(1 + \frac{i}{n}\right)}^{n}\\
t_1 := 100 \cdot \frac{t\_0 - 1}{\frac{i}{n}}\\
\mathbf{if}\;i \leq 7.8 \cdot 10^{-169}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;i \leq 6.5 \cdot 10^{+195}:\\
\;\;\;\;\frac{\frac{\frac{t\_0}{\frac{i}{n}}}{\frac{i}{n}}}{\frac{i}{n}}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if i < 7.79999999999999954e-169 or 6.5000000000000003e195 < i Initial program 28.7%
if 7.79999999999999954e-169 < i < 6.5000000000000003e195Initial program 22.4%
Taylor expanded in i around 0
Applied rewrites19.7%
Taylor expanded in i around 0
Applied rewrites16.3%
Taylor expanded in i around 0
Applied rewrites23.3%
Taylor expanded in i around 0
Applied rewrites36.2%
(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}
Initial program 27.1%
(FPCore (i n) :precision binary64 (let* ((t_0 (pow (+ 1.0 (/ i n)) n))) (if (<= i -7.8e+170) (/ t_0 (/ i n)) (- t_0 1.0))))
double code(double i, double n) {
double t_0 = pow((1.0 + (i / n)), n);
double tmp;
if (i <= -7.8e+170) {
tmp = t_0 / (i / n);
} else {
tmp = t_0 - 1.0;
}
return tmp;
}
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)) ** n
if (i <= (-7.8d+170)) then
tmp = t_0 / (i / n)
else
tmp = t_0 - 1.0d0
end if
code = tmp
end function
public static double code(double i, double n) {
double t_0 = Math.pow((1.0 + (i / n)), n);
double tmp;
if (i <= -7.8e+170) {
tmp = t_0 / (i / n);
} else {
tmp = t_0 - 1.0;
}
return tmp;
}
def code(i, n): t_0 = math.pow((1.0 + (i / n)), n) tmp = 0 if i <= -7.8e+170: tmp = t_0 / (i / n) else: tmp = t_0 - 1.0 return tmp
function code(i, n) t_0 = Float64(1.0 + Float64(i / n)) ^ n tmp = 0.0 if (i <= -7.8e+170) tmp = Float64(t_0 / Float64(i / n)); else tmp = Float64(t_0 - 1.0); end return tmp end
function tmp_2 = code(i, n) t_0 = (1.0 + (i / n)) ^ n; tmp = 0.0; if (i <= -7.8e+170) tmp = t_0 / (i / n); else tmp = t_0 - 1.0; end tmp_2 = tmp; end
code[i_, n_] := Block[{t$95$0 = N[Power[N[(1.0 + N[(i / n), $MachinePrecision]), $MachinePrecision], n], $MachinePrecision]}, If[LessEqual[i, -7.8e+170], N[(t$95$0 / N[(i / n), $MachinePrecision]), $MachinePrecision], N[(t$95$0 - 1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\left(1 + \frac{i}{n}\right)}^{n}\\
\mathbf{if}\;i \leq -7.8 \cdot 10^{+170}:\\
\;\;\;\;\frac{t\_0}{\frac{i}{n}}\\
\mathbf{else}:\\
\;\;\;\;t\_0 - 1\\
\end{array}
\end{array}
if i < -7.8000000000000005e170Initial program 85.9%
Taylor expanded in i around 0
Applied rewrites57.6%
Taylor expanded in i around 0
Applied rewrites49.8%
if -7.8000000000000005e170 < i Initial program 21.9%
Taylor expanded in i around 0
Applied rewrites14.0%
(FPCore (i n) :precision binary64 (/ (- (pow (+ 1.0 (/ i n)) n) 1.0) (/ i n)))
double code(double i, double n) {
return (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 = (((1.0d0 + (i / n)) ** n) - 1.0d0) / (i / n)
end function
public static double code(double i, double n) {
return (Math.pow((1.0 + (i / n)), n) - 1.0) / (i / n);
}
def code(i, n): return (math.pow((1.0 + (i / n)), n) - 1.0) / (i / n)
function code(i, n) return Float64(Float64((Float64(1.0 + Float64(i / n)) ^ n) - 1.0) / Float64(i / n)) end
function tmp = code(i, n) tmp = (((1.0 + (i / n)) ^ n) - 1.0) / (i / n); end
code[i_, n_] := N[(N[(N[Power[N[(1.0 + N[(i / n), $MachinePrecision]), $MachinePrecision], n], $MachinePrecision] - 1.0), $MachinePrecision] / N[(i / n), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}
\end{array}
Initial program 27.1%
Taylor expanded in i around 0
Applied rewrites19.6%
(FPCore (i n) :precision binary64 (let* ((t_0 (pow (+ 1.0 (/ i n)) n))) (if (<= i -6.5e+114) t_0 (- t_0 1.0))))
double code(double i, double n) {
double t_0 = pow((1.0 + (i / n)), n);
double tmp;
if (i <= -6.5e+114) {
tmp = t_0;
} else {
tmp = t_0 - 1.0;
}
return tmp;
}
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)) ** n
if (i <= (-6.5d+114)) then
tmp = t_0
else
tmp = t_0 - 1.0d0
end if
code = tmp
end function
public static double code(double i, double n) {
double t_0 = Math.pow((1.0 + (i / n)), n);
double tmp;
if (i <= -6.5e+114) {
tmp = t_0;
} else {
tmp = t_0 - 1.0;
}
return tmp;
}
def code(i, n): t_0 = math.pow((1.0 + (i / n)), n) tmp = 0 if i <= -6.5e+114: tmp = t_0 else: tmp = t_0 - 1.0 return tmp
function code(i, n) t_0 = Float64(1.0 + Float64(i / n)) ^ n tmp = 0.0 if (i <= -6.5e+114) tmp = t_0; else tmp = Float64(t_0 - 1.0); end return tmp end
function tmp_2 = code(i, n) t_0 = (1.0 + (i / n)) ^ n; tmp = 0.0; if (i <= -6.5e+114) tmp = t_0; else tmp = t_0 - 1.0; end tmp_2 = tmp; end
code[i_, n_] := Block[{t$95$0 = N[Power[N[(1.0 + N[(i / n), $MachinePrecision]), $MachinePrecision], n], $MachinePrecision]}, If[LessEqual[i, -6.5e+114], t$95$0, N[(t$95$0 - 1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\left(1 + \frac{i}{n}\right)}^{n}\\
\mathbf{if}\;i \leq -6.5 \cdot 10^{+114}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_0 - 1\\
\end{array}
\end{array}
if i < -6.5000000000000001e114Initial program 66.3%
Taylor expanded in i around 0
Applied rewrites26.7%
if -6.5000000000000001e114 < i Initial program 22.1%
Taylor expanded in i around 0
Applied rewrites14.4%
(FPCore (i n) :precision binary64 (pow (+ 1.0 (/ i n)) n))
double code(double i, double n) {
return pow((1.0 + (i / n)), n);
}
real(8) function code(i, n)
real(8), intent (in) :: i
real(8), intent (in) :: n
code = (1.0d0 + (i / n)) ** n
end function
public static double code(double i, double n) {
return Math.pow((1.0 + (i / n)), n);
}
def code(i, n): return math.pow((1.0 + (i / n)), n)
function code(i, n) return Float64(1.0 + Float64(i / n)) ^ n end
function tmp = code(i, n) tmp = (1.0 + (i / n)) ^ n; end
code[i_, n_] := N[Power[N[(1.0 + N[(i / n), $MachinePrecision]), $MachinePrecision], n], $MachinePrecision]
\begin{array}{l}
\\
{\left(1 + \frac{i}{n}\right)}^{n}
\end{array}
Initial program 27.1%
Taylor expanded in i around 0
Applied rewrites10.9%
(FPCore (i n) :precision binary64 (+ 1.0 (/ i n)))
double code(double i, double n) {
return 1.0 + (i / n);
}
real(8) function code(i, n)
real(8), intent (in) :: i
real(8), intent (in) :: n
code = 1.0d0 + (i / n)
end function
public static double code(double i, double n) {
return 1.0 + (i / n);
}
def code(i, n): return 1.0 + (i / n)
function code(i, n) return Float64(1.0 + Float64(i / n)) end
function tmp = code(i, n) tmp = 1.0 + (i / n); end
code[i_, n_] := N[(1.0 + N[(i / n), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 + \frac{i}{n}
\end{array}
Initial program 27.1%
Taylor expanded in i around 0
Applied rewrites13.5%
Taylor expanded in i around 0
Applied rewrites3.1%
(FPCore (i n) :precision binary64 (/ i n))
double code(double i, double n) {
return i / n;
}
real(8) function code(i, n)
real(8), intent (in) :: i
real(8), intent (in) :: n
code = i / n
end function
public static double code(double i, double n) {
return i / n;
}
def code(i, n): return i / n
function code(i, n) return Float64(i / n) end
function tmp = code(i, n) tmp = i / n; end
code[i_, n_] := N[(i / n), $MachinePrecision]
\begin{array}{l}
\\
\frac{i}{n}
\end{array}
Initial program 27.1%
Taylor expanded in i around 0
Applied rewrites13.5%
Taylor expanded in i around 0
Applied rewrites2.6%
(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 2024321
(FPCore (i n)
:name "Compound Interest"
:precision binary64
:pre (TRUE)
:alt
(! :herbie-platform default (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))))