
(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 (- (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 40.9%
lift-/.f64N/A
lift--.f64N/A
lift-exp.f64N/A
lift-*.f64N/A
*-commutativeN/A
exp-prodN/A
lift-exp.f64N/A
pow2N/A
metadata-evalN/A
lift--.f64N/A
flip-+N/A
metadata-evalN/A
metadata-evalN/A
sub-negN/A
lower--.f64N/A
metadata-eval100.0
Applied rewrites100.0%
(FPCore (x) :precision binary64 (if (<= (/ (+ -1.0 (exp (* x 2.0))) (+ (exp x) -1.0)) 1.1) (sqrt 2.0) (sqrt (/ 1.0 (fma x (fma x (* x 0.020833333333333332) -0.25) 0.5)))))
double code(double x) {
double tmp;
if (((-1.0 + exp((x * 2.0))) / (exp(x) + -1.0)) <= 1.1) {
tmp = sqrt(2.0);
} else {
tmp = sqrt((1.0 / fma(x, fma(x, (x * 0.020833333333333332), -0.25), 0.5)));
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(Float64(-1.0 + exp(Float64(x * 2.0))) / Float64(exp(x) + -1.0)) <= 1.1) tmp = sqrt(2.0); else tmp = sqrt(Float64(1.0 / fma(x, fma(x, Float64(x * 0.020833333333333332), -0.25), 0.5))); end return tmp end
code[x_] := If[LessEqual[N[(N[(-1.0 + N[Exp[N[(x * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(N[Exp[x], $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision], 1.1], N[Sqrt[2.0], $MachinePrecision], N[Sqrt[N[(1.0 / N[(x * N[(x * N[(x * 0.020833333333333332), $MachinePrecision] + -0.25), $MachinePrecision] + 0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{-1 + e^{x \cdot 2}}{e^{x} + -1} \leq 1.1:\\
\;\;\;\;\sqrt{2}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{1}{\mathsf{fma}\left(x, \mathsf{fma}\left(x, x \cdot 0.020833333333333332, -0.25\right), 0.5\right)}}\\
\end{array}
\end{array}
if (/.f64 (-.f64 (exp.f64 (*.f64 #s(literal 2 binary64) x)) #s(literal 1 binary64)) (-.f64 (exp.f64 x) #s(literal 1 binary64))) < 1.1000000000000001Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites20.7%
if 1.1000000000000001 < (/.f64 (-.f64 (exp.f64 (*.f64 #s(literal 2 binary64) x)) #s(literal 1 binary64)) (-.f64 (exp.f64 x) #s(literal 1 binary64))) Initial program 7.2%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6496.0
Applied rewrites96.0%
Applied rewrites96.0%
Taylor expanded in x around 0
Applied rewrites96.2%
Final simplification68.8%
(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 40.9%
Taylor expanded in x around 0
Applied rewrites67.1%
herbie shell --seed 2024238
(FPCore (x)
:name "sqrtexp (problem 3.4.4)"
:precision binary64
(sqrt (/ (- (exp (* 2.0 x)) 1.0) (- (exp x) 1.0))))