
(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 7 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 (log (exp (- (exp (/ (log1p x) n)) (pow x (/ 1.0 n))))))
double code(double x, double n) {
return log(exp((exp((log1p(x) / n)) - pow(x, (1.0 / n)))));
}
public static double code(double x, double n) {
return Math.log(Math.exp((Math.exp((Math.log1p(x) / n)) - Math.pow(x, (1.0 / n)))));
}
def code(x, n): return math.log(math.exp((math.exp((math.log1p(x) / n)) - math.pow(x, (1.0 / n)))))
function code(x, n) return log(exp(Float64(exp(Float64(log1p(x) / n)) - (x ^ Float64(1.0 / n))))) end
code[x_, n_] := N[Log[N[Exp[N[(N[Exp[N[(N[Log[1 + x], $MachinePrecision] / n), $MachinePrecision]], $MachinePrecision] - N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\log \left(e^{e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}}\right)
\end{array}
Initial program 56.8%
add-log-exp56.8%
add-exp-log56.8%
log-pow56.8%
+-commutative56.8%
log1p-udef62.6%
*-commutative62.6%
un-div-inv62.6%
Applied egg-rr62.6%
Final simplification62.6%
(FPCore (x n) :precision binary64 (- (exp (/ (log1p x) n)) (pow x (/ 1.0 n))))
double code(double x, double n) {
return exp((log1p(x) / n)) - pow(x, (1.0 / n));
}
public static double code(double x, double n) {
return Math.exp((Math.log1p(x) / n)) - Math.pow(x, (1.0 / n));
}
def code(x, n): return math.exp((math.log1p(x) / n)) - math.pow(x, (1.0 / n))
function code(x, n) return Float64(exp(Float64(log1p(x) / n)) - (x ^ Float64(1.0 / n))) end
code[x_, n_] := N[(N[Exp[N[(N[Log[1 + x], $MachinePrecision] / n), $MachinePrecision]], $MachinePrecision] - N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}
\end{array}
Initial program 56.8%
Taylor expanded in n around 0 56.8%
log1p-def62.6%
Simplified62.6%
Final simplification62.6%
(FPCore (x n) :precision binary64 (/ (exp (/ (log x) n)) (* x n)))
double code(double x, double n) {
return exp((log(x) / n)) / (x * n);
}
real(8) function code(x, n)
real(8), intent (in) :: x
real(8), intent (in) :: n
code = exp((log(x) / n)) / (x * n)
end function
public static double code(double x, double n) {
return Math.exp((Math.log(x) / n)) / (x * n);
}
def code(x, n): return math.exp((math.log(x) / n)) / (x * n)
function code(x, n) return Float64(exp(Float64(log(x) / n)) / Float64(x * n)) end
function tmp = code(x, n) tmp = exp((log(x) / n)) / (x * n); end
code[x_, n_] := N[(N[Exp[N[(N[Log[x], $MachinePrecision] / n), $MachinePrecision]], $MachinePrecision] / N[(x * n), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{e^{\frac{\log x}{n}}}{x \cdot n}
\end{array}
Initial program 56.8%
Taylor expanded in x around inf 58.4%
mul-1-neg58.4%
log-rec58.4%
mul-1-neg58.4%
distribute-neg-frac58.4%
mul-1-neg58.4%
remove-double-neg58.4%
*-commutative58.4%
Simplified58.4%
Final simplification58.4%
(FPCore (x n) :precision binary64 (/ (log (/ (+ x 1.0) x)) n))
double code(double x, double n) {
return log(((x + 1.0) / x)) / n;
}
real(8) function code(x, n)
real(8), intent (in) :: x
real(8), intent (in) :: n
code = log(((x + 1.0d0) / x)) / n
end function
public static double code(double x, double n) {
return Math.log(((x + 1.0) / x)) / n;
}
def code(x, n): return math.log(((x + 1.0) / x)) / n
function code(x, n) return Float64(log(Float64(Float64(x + 1.0) / x)) / n) end
function tmp = code(x, n) tmp = log(((x + 1.0) / x)) / n; end
code[x_, n_] := N[(N[Log[N[(N[(x + 1.0), $MachinePrecision] / x), $MachinePrecision]], $MachinePrecision] / n), $MachinePrecision]
\begin{array}{l}
\\
\frac{\log \left(\frac{x + 1}{x}\right)}{n}
\end{array}
Initial program 56.8%
Taylor expanded in n around inf 61.9%
log1p-def61.9%
Simplified61.9%
log1p-udef61.9%
diff-log62.1%
Applied egg-rr62.1%
Final simplification62.1%
(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 56.8%
Taylor expanded in n around inf 61.9%
log1p-def61.9%
Simplified61.9%
Taylor expanded in x around inf 37.7%
*-commutative37.7%
Simplified37.7%
Final simplification37.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 56.8%
Taylor expanded in n around inf 61.9%
log1p-def61.9%
Simplified61.9%
Taylor expanded in x around inf 37.7%
associate-/r*38.2%
Simplified38.2%
Final simplification38.2%
(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 56.8%
Taylor expanded in n around inf 61.9%
log1p-def61.9%
Simplified61.9%
Taylor expanded in x around inf 38.2%
Final simplification38.2%
herbie shell --seed 2024033
(FPCore (x n)
:name "2nthrt (problem 3.4.6)"
:precision binary64
(- (pow (+ x 1.0) (/ 1.0 n)) (pow x (/ 1.0 n))))