
(FPCore (x) :precision binary64 (sqrt (/ (- (exp (* 2.0 x)) 1.0) (- (exp x) 1.0))))
double code(double x) {
return sqrt(((exp((2.0 * x)) - 1.0) / (exp(x) - 1.0)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = sqrt(((exp((2.0d0 * x)) - 1.0d0) / (exp(x) - 1.0d0)))
end function
public static double code(double x) {
return Math.sqrt(((Math.exp((2.0 * x)) - 1.0) / (Math.exp(x) - 1.0)));
}
def code(x): return math.sqrt(((math.exp((2.0 * x)) - 1.0) / (math.exp(x) - 1.0)))
function code(x) return sqrt(Float64(Float64(exp(Float64(2.0 * x)) - 1.0) / Float64(exp(x) - 1.0))) end
function tmp = code(x) tmp = sqrt(((exp((2.0 * x)) - 1.0) / (exp(x) - 1.0))); end
code[x_] := N[Sqrt[N[(N[(N[Exp[N[(2.0 * x), $MachinePrecision]], $MachinePrecision] - 1.0), $MachinePrecision] / N[(N[Exp[x], $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\frac{e^{2 \cdot x} - 1}{e^{x} - 1}}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (sqrt (/ (- (exp (* 2.0 x)) 1.0) (- (exp x) 1.0))))
double code(double x) {
return sqrt(((exp((2.0 * x)) - 1.0) / (exp(x) - 1.0)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = sqrt(((exp((2.0d0 * x)) - 1.0d0) / (exp(x) - 1.0d0)))
end function
public static double code(double x) {
return Math.sqrt(((Math.exp((2.0 * x)) - 1.0) / (Math.exp(x) - 1.0)));
}
def code(x): return math.sqrt(((math.exp((2.0 * x)) - 1.0) / (math.exp(x) - 1.0)))
function code(x) return sqrt(Float64(Float64(exp(Float64(2.0 * x)) - 1.0) / Float64(exp(x) - 1.0))) end
function tmp = code(x) tmp = sqrt(((exp((2.0 * x)) - 1.0) / (exp(x) - 1.0))); end
code[x_] := N[Sqrt[N[(N[(N[Exp[N[(2.0 * x), $MachinePrecision]], $MachinePrecision] - 1.0), $MachinePrecision] / N[(N[Exp[x], $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\frac{e^{2 \cdot x} - 1}{e^{x} - 1}}
\end{array}
(FPCore (x) :precision binary64 (sqrt (+ -1.0 (+ 2.0 (exp x)))))
double code(double x) {
return sqrt((-1.0 + (2.0 + exp(x))));
}
real(8) function code(x)
real(8), intent (in) :: x
code = sqrt(((-1.0d0) + (2.0d0 + exp(x))))
end function
public static double code(double x) {
return Math.sqrt((-1.0 + (2.0 + Math.exp(x))));
}
def code(x): return math.sqrt((-1.0 + (2.0 + math.exp(x))))
function code(x) return sqrt(Float64(-1.0 + Float64(2.0 + exp(x)))) end
function tmp = code(x) tmp = sqrt((-1.0 + (2.0 + exp(x)))); end
code[x_] := N[Sqrt[N[(-1.0 + N[(2.0 + N[Exp[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{-1 + \left(2 + e^{x}\right)}
\end{array}
Initial program 32.1%
*-commutative32.1%
exp-lft-sqr32.5%
difference-of-sqr-132.8%
associate-*r/32.8%
*-inverses99.6%
*-rgt-identity99.6%
+-commutative99.6%
Simplified99.6%
expm1-log1p-u98.6%
expm1-undefine98.6%
Applied egg-rr98.6%
sub-neg98.6%
metadata-eval98.6%
+-commutative98.6%
log1p-undefine99.6%
rem-exp-log99.6%
associate-+r+99.6%
metadata-eval99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (x) :precision binary64 (sqrt (+ (exp x) 1.0)))
double code(double x) {
return sqrt((exp(x) + 1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = sqrt((exp(x) + 1.0d0))
end function
public static double code(double x) {
return Math.sqrt((Math.exp(x) + 1.0));
}
def code(x): return math.sqrt((math.exp(x) + 1.0))
function code(x) return sqrt(Float64(exp(x) + 1.0)) end
function tmp = code(x) tmp = sqrt((exp(x) + 1.0)); end
code[x_] := N[Sqrt[N[(N[Exp[x], $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{e^{x} + 1}
\end{array}
Initial program 32.1%
*-commutative32.1%
exp-lft-sqr32.5%
difference-of-sqr-132.8%
associate-*r/32.8%
*-inverses99.6%
*-rgt-identity99.6%
+-commutative99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (x) :precision binary64 (sqrt 2.0))
double code(double x) {
return sqrt(2.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = sqrt(2.0d0)
end function
public static double code(double x) {
return Math.sqrt(2.0);
}
def code(x): return math.sqrt(2.0)
function code(x) return sqrt(2.0) end
function tmp = code(x) tmp = sqrt(2.0); end
code[x_] := N[Sqrt[2.0], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{2}
\end{array}
Initial program 32.1%
*-commutative32.1%
exp-lft-sqr32.5%
difference-of-sqr-132.8%
associate-*r/32.8%
*-inverses99.6%
*-rgt-identity99.6%
+-commutative99.6%
Simplified99.6%
Taylor expanded in x around 0 74.5%
Final simplification74.5%
herbie shell --seed 2024051
(FPCore (x)
:name "sqrtexp (problem 3.4.4)"
:precision binary64
(sqrt (/ (- (exp (* 2.0 x)) 1.0) (- (exp x) 1.0))))