
(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));
}
real(8) function code(x, n)
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 10 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));
}
real(8) function code(x, n)
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 4e-106)
(* x (- (/ 1.0 n) (/ (log x) (* x n))))
(if (<= x 0.092)
(cbrt (pow (/ (- x (log x)) n) 3.0))
(/ (/ (pow x (/ 1.0 n)) n) x))))
double code(double x, double n) {
double tmp;
if (x <= 4e-106) {
tmp = x * ((1.0 / n) - (log(x) / (x * n)));
} else if (x <= 0.092) {
tmp = cbrt(pow(((x - log(x)) / n), 3.0));
} else {
tmp = (pow(x, (1.0 / n)) / n) / x;
}
return tmp;
}
public static double code(double x, double n) {
double tmp;
if (x <= 4e-106) {
tmp = x * ((1.0 / n) - (Math.log(x) / (x * n)));
} else if (x <= 0.092) {
tmp = Math.cbrt(Math.pow(((x - Math.log(x)) / n), 3.0));
} else {
tmp = (Math.pow(x, (1.0 / n)) / n) / x;
}
return tmp;
}
function code(x, n) tmp = 0.0 if (x <= 4e-106) tmp = Float64(x * Float64(Float64(1.0 / n) - Float64(log(x) / Float64(x * n)))); elseif (x <= 0.092) tmp = cbrt((Float64(Float64(x - log(x)) / n) ^ 3.0)); else tmp = Float64(Float64((x ^ Float64(1.0 / n)) / n) / x); end return tmp end
code[x_, n_] := If[LessEqual[x, 4e-106], N[(x * N[(N[(1.0 / n), $MachinePrecision] - N[(N[Log[x], $MachinePrecision] / N[(x * n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 0.092], N[Power[N[Power[N[(N[(x - N[Log[x], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision], 3.0], $MachinePrecision], 1/3], $MachinePrecision], N[(N[(N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision] / n), $MachinePrecision] / x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 4 \cdot 10^{-106}:\\
\;\;\;\;x \cdot \left(\frac{1}{n} - \frac{\log x}{x \cdot n}\right)\\
\mathbf{elif}\;x \leq 0.092:\\
\;\;\;\;\sqrt[3]{{\left(\frac{x - \log x}{n}\right)}^{3}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{{x}^{\left(\frac{1}{n}\right)}}{n}}{x}\\
\end{array}
\end{array}
if x < 3.99999999999999976e-106Initial program 45.4%
Taylor expanded in x around 0 45.7%
Taylor expanded in n around inf 52.4%
clear-num52.3%
inv-pow52.3%
Applied egg-rr52.3%
unpow-152.3%
Simplified52.3%
Taylor expanded in x around inf 76.1%
log-rec76.1%
distribute-frac-neg76.1%
unsub-neg76.1%
*-commutative76.1%
Simplified76.1%
if 3.99999999999999976e-106 < x < 0.091999999999999998Initial program 42.5%
Taylor expanded in x around 0 39.2%
Taylor expanded in n around inf 44.1%
add-cbrt-cube76.0%
pow376.0%
Applied egg-rr76.0%
if 0.091999999999999998 < x Initial program 56.8%
Taylor expanded in x around inf 97.2%
associate-/r*98.2%
mul-1-neg98.2%
log-rec98.2%
mul-1-neg98.2%
distribute-neg-frac98.2%
mul-1-neg98.2%
remove-double-neg98.2%
*-rgt-identity98.2%
associate-/l*98.2%
exp-to-pow98.2%
Simplified98.2%
(FPCore (x n) :precision binary64 (if (<= x 6.5e-25) (/ (log x) (- n)) (if (<= x 0.00215) (- 1.0 (pow x (/ 1.0 n))) (/ (/ 1.0 x) n))))
double code(double x, double n) {
double tmp;
if (x <= 6.5e-25) {
tmp = log(x) / -n;
} else if (x <= 0.00215) {
tmp = 1.0 - pow(x, (1.0 / n));
} else {
tmp = (1.0 / x) / n;
}
return tmp;
}
real(8) function code(x, n)
real(8), intent (in) :: x
real(8), intent (in) :: n
real(8) :: tmp
if (x <= 6.5d-25) then
tmp = log(x) / -n
else if (x <= 0.00215d0) then
tmp = 1.0d0 - (x ** (1.0d0 / n))
else
tmp = (1.0d0 / x) / n
end if
code = tmp
end function
public static double code(double x, double n) {
double tmp;
if (x <= 6.5e-25) {
tmp = Math.log(x) / -n;
} else if (x <= 0.00215) {
tmp = 1.0 - Math.pow(x, (1.0 / n));
} else {
tmp = (1.0 / x) / n;
}
return tmp;
}
def code(x, n): tmp = 0 if x <= 6.5e-25: tmp = math.log(x) / -n elif x <= 0.00215: tmp = 1.0 - math.pow(x, (1.0 / n)) else: tmp = (1.0 / x) / n return tmp
function code(x, n) tmp = 0.0 if (x <= 6.5e-25) tmp = Float64(log(x) / Float64(-n)); elseif (x <= 0.00215) tmp = Float64(1.0 - (x ^ Float64(1.0 / n))); else tmp = Float64(Float64(1.0 / x) / n); end return tmp end
function tmp_2 = code(x, n) tmp = 0.0; if (x <= 6.5e-25) tmp = log(x) / -n; elseif (x <= 0.00215) tmp = 1.0 - (x ^ (1.0 / n)); else tmp = (1.0 / x) / n; end tmp_2 = tmp; end
code[x_, n_] := If[LessEqual[x, 6.5e-25], N[(N[Log[x], $MachinePrecision] / (-n)), $MachinePrecision], If[LessEqual[x, 0.00215], N[(1.0 - N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / x), $MachinePrecision] / n), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 6.5 \cdot 10^{-25}:\\
\;\;\;\;\frac{\log x}{-n}\\
\mathbf{elif}\;x \leq 0.00215:\\
\;\;\;\;1 - {x}^{\left(\frac{1}{n}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{x}}{n}\\
\end{array}
\end{array}
if x < 6.5e-25Initial program 40.2%
Taylor expanded in x around 0 40.2%
*-rgt-identity40.2%
associate-*l/40.2%
associate-/l*40.2%
exp-to-pow40.2%
Simplified40.2%
Taylor expanded in n around inf 52.6%
mul-1-neg52.6%
distribute-frac-neg252.6%
Simplified52.6%
if 6.5e-25 < x < 0.00215Initial program 91.3%
Taylor expanded in x around 0 82.5%
*-rgt-identity82.5%
associate-*l/82.5%
associate-/l*82.5%
exp-to-pow82.5%
Simplified82.5%
if 0.00215 < x Initial program 56.7%
Taylor expanded in x around inf 95.7%
mul-1-neg95.7%
log-rec95.7%
mul-1-neg95.7%
distribute-neg-frac95.7%
mul-1-neg95.7%
remove-double-neg95.7%
*-commutative95.7%
Simplified95.7%
Taylor expanded in n around inf 66.1%
*-commutative66.1%
associate-/r*67.2%
Simplified67.2%
(FPCore (x n) :precision binary64 (if (<= x 1.35e-24) (* x (- (/ 1.0 n) (/ (log x) (* x n)))) (/ (/ (pow x (/ 1.0 n)) n) x)))
double code(double x, double n) {
double tmp;
if (x <= 1.35e-24) {
tmp = x * ((1.0 / n) - (log(x) / (x * n)));
} else {
tmp = (pow(x, (1.0 / n)) / n) / x;
}
return tmp;
}
real(8) function code(x, n)
real(8), intent (in) :: x
real(8), intent (in) :: n
real(8) :: tmp
if (x <= 1.35d-24) then
tmp = x * ((1.0d0 / n) - (log(x) / (x * n)))
else
tmp = ((x ** (1.0d0 / n)) / n) / x
end if
code = tmp
end function
public static double code(double x, double n) {
double tmp;
if (x <= 1.35e-24) {
tmp = x * ((1.0 / n) - (Math.log(x) / (x * n)));
} else {
tmp = (Math.pow(x, (1.0 / n)) / n) / x;
}
return tmp;
}
def code(x, n): tmp = 0 if x <= 1.35e-24: tmp = x * ((1.0 / n) - (math.log(x) / (x * n))) else: tmp = (math.pow(x, (1.0 / n)) / n) / x return tmp
function code(x, n) tmp = 0.0 if (x <= 1.35e-24) tmp = Float64(x * Float64(Float64(1.0 / n) - Float64(log(x) / Float64(x * n)))); else tmp = Float64(Float64((x ^ Float64(1.0 / n)) / n) / x); end return tmp end
function tmp_2 = code(x, n) tmp = 0.0; if (x <= 1.35e-24) tmp = x * ((1.0 / n) - (log(x) / (x * n))); else tmp = ((x ^ (1.0 / n)) / n) / x; end tmp_2 = tmp; end
code[x_, n_] := If[LessEqual[x, 1.35e-24], N[(x * N[(N[(1.0 / n), $MachinePrecision] - N[(N[Log[x], $MachinePrecision] / N[(x * n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision] / n), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.35 \cdot 10^{-24}:\\
\;\;\;\;x \cdot \left(\frac{1}{n} - \frac{\log x}{x \cdot n}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{{x}^{\left(\frac{1}{n}\right)}}{n}}{x}\\
\end{array}
\end{array}
if x < 1.35000000000000003e-24Initial program 40.2%
Taylor expanded in x around 0 40.5%
Taylor expanded in n around inf 52.6%
clear-num52.5%
inv-pow52.5%
Applied egg-rr52.5%
unpow-152.5%
Simplified52.5%
Taylor expanded in x around inf 73.2%
log-rec73.2%
distribute-frac-neg73.2%
unsub-neg73.2%
*-commutative73.2%
Simplified73.2%
if 1.35000000000000003e-24 < x Initial program 59.7%
Taylor expanded in x around inf 94.6%
associate-/r*95.5%
mul-1-neg95.5%
log-rec95.5%
mul-1-neg95.5%
distribute-neg-frac95.5%
mul-1-neg95.5%
remove-double-neg95.5%
*-rgt-identity95.5%
associate-/l*95.5%
exp-to-pow95.5%
Simplified95.5%
(FPCore (x n) :precision binary64 (if (<= x 4e-25) (/ (log x) (- n)) (/ (/ (pow x (/ 1.0 n)) n) x)))
double code(double x, double n) {
double tmp;
if (x <= 4e-25) {
tmp = log(x) / -n;
} else {
tmp = (pow(x, (1.0 / n)) / n) / x;
}
return tmp;
}
real(8) function code(x, n)
real(8), intent (in) :: x
real(8), intent (in) :: n
real(8) :: tmp
if (x <= 4d-25) then
tmp = log(x) / -n
else
tmp = ((x ** (1.0d0 / n)) / n) / x
end if
code = tmp
end function
public static double code(double x, double n) {
double tmp;
if (x <= 4e-25) {
tmp = Math.log(x) / -n;
} else {
tmp = (Math.pow(x, (1.0 / n)) / n) / x;
}
return tmp;
}
def code(x, n): tmp = 0 if x <= 4e-25: tmp = math.log(x) / -n else: tmp = (math.pow(x, (1.0 / n)) / n) / x return tmp
function code(x, n) tmp = 0.0 if (x <= 4e-25) tmp = Float64(log(x) / Float64(-n)); else tmp = Float64(Float64((x ^ Float64(1.0 / n)) / n) / x); end return tmp end
function tmp_2 = code(x, n) tmp = 0.0; if (x <= 4e-25) tmp = log(x) / -n; else tmp = ((x ^ (1.0 / n)) / n) / x; end tmp_2 = tmp; end
code[x_, n_] := If[LessEqual[x, 4e-25], N[(N[Log[x], $MachinePrecision] / (-n)), $MachinePrecision], N[(N[(N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision] / n), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 4 \cdot 10^{-25}:\\
\;\;\;\;\frac{\log x}{-n}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{{x}^{\left(\frac{1}{n}\right)}}{n}}{x}\\
\end{array}
\end{array}
if x < 4.00000000000000015e-25Initial program 40.2%
Taylor expanded in x around 0 40.2%
*-rgt-identity40.2%
associate-*l/40.2%
associate-/l*40.2%
exp-to-pow40.2%
Simplified40.2%
Taylor expanded in n around inf 52.6%
mul-1-neg52.6%
distribute-frac-neg252.6%
Simplified52.6%
if 4.00000000000000015e-25 < x Initial program 59.7%
Taylor expanded in x around inf 94.6%
associate-/r*95.5%
mul-1-neg95.5%
log-rec95.5%
mul-1-neg95.5%
distribute-neg-frac95.5%
mul-1-neg95.5%
remove-double-neg95.5%
*-rgt-identity95.5%
associate-/l*95.5%
exp-to-pow95.5%
Simplified95.5%
(FPCore (x n) :precision binary64 (if (<= x 1.0) (/ (- x (log x)) n) (/ (/ 1.0 x) n)))
double code(double x, double n) {
double tmp;
if (x <= 1.0) {
tmp = (x - log(x)) / n;
} else {
tmp = (1.0 / x) / n;
}
return tmp;
}
real(8) function code(x, n)
real(8), intent (in) :: x
real(8), intent (in) :: n
real(8) :: tmp
if (x <= 1.0d0) then
tmp = (x - log(x)) / n
else
tmp = (1.0d0 / x) / n
end if
code = tmp
end function
public static double code(double x, double n) {
double tmp;
if (x <= 1.0) {
tmp = (x - Math.log(x)) / n;
} else {
tmp = (1.0 / x) / n;
}
return tmp;
}
def code(x, n): tmp = 0 if x <= 1.0: tmp = (x - math.log(x)) / n else: tmp = (1.0 / x) / n return tmp
function code(x, n) tmp = 0.0 if (x <= 1.0) tmp = Float64(Float64(x - log(x)) / n); else tmp = Float64(Float64(1.0 / x) / n); end return tmp end
function tmp_2 = code(x, n) tmp = 0.0; if (x <= 1.0) tmp = (x - log(x)) / n; else tmp = (1.0 / x) / n; end tmp_2 = tmp; end
code[x_, n_] := If[LessEqual[x, 1.0], N[(N[(x - N[Log[x], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision], N[(N[(1.0 / x), $MachinePrecision] / n), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;\frac{x - \log x}{n}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{x}}{n}\\
\end{array}
\end{array}
if x < 1Initial program 44.1%
Taylor expanded in x around 0 43.0%
Taylor expanded in n around inf 49.2%
if 1 < x Initial program 57.3%
Taylor expanded in x around inf 97.9%
mul-1-neg97.9%
log-rec97.9%
mul-1-neg97.9%
distribute-neg-frac97.9%
mul-1-neg97.9%
remove-double-neg97.9%
*-commutative97.9%
Simplified97.9%
Taylor expanded in n around inf 67.5%
*-commutative67.5%
associate-/r*68.6%
Simplified68.6%
(FPCore (x n) :precision binary64 (if (<= x 0.55) (/ (log x) (- n)) (/ (/ 1.0 x) n)))
double code(double x, double n) {
double tmp;
if (x <= 0.55) {
tmp = log(x) / -n;
} else {
tmp = (1.0 / x) / n;
}
return tmp;
}
real(8) function code(x, n)
real(8), intent (in) :: x
real(8), intent (in) :: n
real(8) :: tmp
if (x <= 0.55d0) then
tmp = log(x) / -n
else
tmp = (1.0d0 / x) / n
end if
code = tmp
end function
public static double code(double x, double n) {
double tmp;
if (x <= 0.55) {
tmp = Math.log(x) / -n;
} else {
tmp = (1.0 / x) / n;
}
return tmp;
}
def code(x, n): tmp = 0 if x <= 0.55: tmp = math.log(x) / -n else: tmp = (1.0 / x) / n return tmp
function code(x, n) tmp = 0.0 if (x <= 0.55) tmp = Float64(log(x) / Float64(-n)); else tmp = Float64(Float64(1.0 / x) / n); end return tmp end
function tmp_2 = code(x, n) tmp = 0.0; if (x <= 0.55) tmp = log(x) / -n; else tmp = (1.0 / x) / n; end tmp_2 = tmp; end
code[x_, n_] := If[LessEqual[x, 0.55], N[(N[Log[x], $MachinePrecision] / (-n)), $MachinePrecision], N[(N[(1.0 / x), $MachinePrecision] / n), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.55:\\
\;\;\;\;\frac{\log x}{-n}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{x}}{n}\\
\end{array}
\end{array}
if x < 0.55000000000000004Initial program 44.1%
Taylor expanded in x around 0 42.7%
*-rgt-identity42.7%
associate-*l/42.7%
associate-/l*42.7%
exp-to-pow42.7%
Simplified42.7%
Taylor expanded in n around inf 48.9%
mul-1-neg48.9%
distribute-frac-neg248.9%
Simplified48.9%
if 0.55000000000000004 < x Initial program 57.3%
Taylor expanded in x around inf 97.9%
mul-1-neg97.9%
log-rec97.9%
mul-1-neg97.9%
distribute-neg-frac97.9%
mul-1-neg97.9%
remove-double-neg97.9%
*-commutative97.9%
Simplified97.9%
Taylor expanded in n around inf 67.5%
*-commutative67.5%
associate-/r*68.6%
Simplified68.6%
(FPCore (x n) :precision binary64 (/ (/ 1.0 x) n))
double code(double x, double n) {
return (1.0 / x) / n;
}
real(8) function code(x, n)
real(8), intent (in) :: x
real(8), intent (in) :: n
code = (1.0d0 / x) / n
end function
public static double code(double x, double n) {
return (1.0 / x) / n;
}
def code(x, n): return (1.0 / x) / n
function code(x, n) return Float64(Float64(1.0 / x) / n) end
function tmp = code(x, n) tmp = (1.0 / x) / n; end
code[x_, n_] := N[(N[(1.0 / x), $MachinePrecision] / n), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{1}{x}}{n}
\end{array}
Initial program 49.9%
Taylor expanded in x around inf 59.7%
mul-1-neg59.7%
log-rec59.7%
mul-1-neg59.7%
distribute-neg-frac59.7%
mul-1-neg59.7%
remove-double-neg59.7%
*-commutative59.7%
Simplified59.7%
Taylor expanded in n around inf 43.3%
*-commutative43.3%
associate-/r*43.7%
Simplified43.7%
(FPCore (x n) :precision binary64 (/ (/ 1.0 n) x))
double code(double x, double n) {
return (1.0 / n) / x;
}
real(8) function code(x, n)
real(8), intent (in) :: x
real(8), intent (in) :: n
code = (1.0d0 / n) / x
end function
public static double code(double x, double n) {
return (1.0 / n) / x;
}
def code(x, n): return (1.0 / n) / x
function code(x, n) return Float64(Float64(1.0 / n) / x) end
function tmp = code(x, n) tmp = (1.0 / n) / x; end
code[x_, n_] := N[(N[(1.0 / n), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{1}{n}}{x}
\end{array}
Initial program 49.9%
Taylor expanded in x around inf 59.7%
associate-/r*60.3%
mul-1-neg60.3%
log-rec60.3%
mul-1-neg60.3%
distribute-neg-frac60.3%
mul-1-neg60.3%
remove-double-neg60.3%
*-rgt-identity60.3%
associate-/l*60.3%
exp-to-pow60.3%
Simplified60.3%
Taylor expanded in n around inf 43.7%
(FPCore (x n) :precision binary64 (/ 1.0 (* x n)))
double code(double x, double n) {
return 1.0 / (x * n);
}
real(8) function code(x, n)
real(8), intent (in) :: x
real(8), intent (in) :: n
code = 1.0d0 / (x * n)
end function
public static double code(double x, double n) {
return 1.0 / (x * n);
}
def code(x, n): return 1.0 / (x * n)
function code(x, n) return Float64(1.0 / Float64(x * n)) end
function tmp = code(x, n) tmp = 1.0 / (x * n); end
code[x_, n_] := N[(1.0 / N[(x * n), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x \cdot n}
\end{array}
Initial program 49.9%
Taylor expanded in x around inf 59.7%
mul-1-neg59.7%
log-rec59.7%
mul-1-neg59.7%
distribute-neg-frac59.7%
mul-1-neg59.7%
remove-double-neg59.7%
*-commutative59.7%
Simplified59.7%
Taylor expanded in n around inf 43.3%
(FPCore (x n) :precision binary64 (/ x n))
double code(double x, double n) {
return x / n;
}
real(8) function code(x, n)
real(8), intent (in) :: x
real(8), intent (in) :: n
code = x / n
end function
public static double code(double x, double n) {
return x / n;
}
def code(x, n): return x / n
function code(x, n) return Float64(x / n) end
function tmp = code(x, n) tmp = x / n; end
code[x_, n_] := N[(x / n), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{n}
\end{array}
Initial program 49.9%
Taylor expanded in x around 0 30.6%
Taylor expanded in x around inf 4.6%
herbie shell --seed 2024106
(FPCore (x n)
:name "2nthrt (problem 3.4.6)"
:precision binary64
(- (pow (+ x 1.0) (/ 1.0 n)) (pow x (/ 1.0 n))))