
(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 6 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 (+ (pow (exp (- x)) -1.0) 1.0)))
double code(double x) {
return sqrt((pow(exp(-x), -1.0) + 1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = sqrt(((exp(-x) ** (-1.0d0)) + 1.0d0))
end function
public static double code(double x) {
return Math.sqrt((Math.pow(Math.exp(-x), -1.0) + 1.0));
}
def code(x): return math.sqrt((math.pow(math.exp(-x), -1.0) + 1.0))
function code(x) return sqrt(Float64((exp(Float64(-x)) ^ -1.0) + 1.0)) end
function tmp = code(x) tmp = sqrt(((exp(-x) ^ -1.0) + 1.0)); end
code[x_] := N[Sqrt[N[(N[Power[N[Exp[(-x)], $MachinePrecision], -1.0], $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{{\left(e^{-x}\right)}^{-1} + 1}
\end{array}
Initial program 41.1%
lift-/.f64N/A
lift--.f64N/A
lift-exp.f64N/A
lift-*.f64N/A
*-commutativeN/A
exp-lft-sqr-revN/A
lift-exp.f64N/A
lift-exp.f64N/A
metadata-evalN/A
lift--.f64N/A
flip-+N/A
lower-+.f64100.0
Applied rewrites100.0%
lift-exp.f64N/A
sinh-+-cosh-revN/A
lift-cosh.f64N/A
lift-sinh.f64N/A
flip-+N/A
lift-cosh.f64N/A
lift-cosh.f64N/A
lift-sinh.f64N/A
lift-sinh.f64N/A
sinh-coshN/A
lift-cosh.f64N/A
lift-sinh.f64N/A
sinh---cosh-revN/A
lower-/.f64N/A
lower-exp.f64N/A
lower-neg.f64100.0
Applied rewrites100.0%
Final simplification100.0%
(FPCore (x) :precision binary64 (sqrt (+ (pow (fma (- (* (fma -0.16666666666666666 x 0.5) x) 1.0) x 1.0) -1.0) 1.0)))
double code(double x) {
return sqrt((pow(fma(((fma(-0.16666666666666666, x, 0.5) * x) - 1.0), x, 1.0), -1.0) + 1.0));
}
function code(x) return sqrt(Float64((fma(Float64(Float64(fma(-0.16666666666666666, x, 0.5) * x) - 1.0), x, 1.0) ^ -1.0) + 1.0)) end
code[x_] := N[Sqrt[N[(N[Power[N[(N[(N[(N[(-0.16666666666666666 * x + 0.5), $MachinePrecision] * x), $MachinePrecision] - 1.0), $MachinePrecision] * x + 1.0), $MachinePrecision], -1.0], $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{{\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.16666666666666666, x, 0.5\right) \cdot x - 1, x, 1\right)\right)}^{-1} + 1}
\end{array}
Initial program 41.1%
lift-/.f64N/A
lift--.f64N/A
lift-exp.f64N/A
lift-*.f64N/A
*-commutativeN/A
exp-lft-sqr-revN/A
lift-exp.f64N/A
lift-exp.f64N/A
metadata-evalN/A
lift--.f64N/A
flip-+N/A
lower-+.f64100.0
Applied rewrites100.0%
lift-exp.f64N/A
sinh-+-cosh-revN/A
lift-cosh.f64N/A
lift-sinh.f64N/A
flip-+N/A
lift-cosh.f64N/A
lift-cosh.f64N/A
lift-sinh.f64N/A
lift-sinh.f64N/A
sinh-coshN/A
lift-cosh.f64N/A
lift-sinh.f64N/A
sinh---cosh-revN/A
lower-/.f64N/A
lower-exp.f64N/A
lower-neg.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f6497.9
Applied rewrites97.9%
Final simplification97.9%
(FPCore (x) :precision binary64 (sqrt (+ (pow (fma (- (* 0.5 x) 1.0) x 1.0) -1.0) 1.0)))
double code(double x) {
return sqrt((pow(fma(((0.5 * x) - 1.0), x, 1.0), -1.0) + 1.0));
}
function code(x) return sqrt(Float64((fma(Float64(Float64(0.5 * x) - 1.0), x, 1.0) ^ -1.0) + 1.0)) end
code[x_] := N[Sqrt[N[(N[Power[N[(N[(N[(0.5 * x), $MachinePrecision] - 1.0), $MachinePrecision] * x + 1.0), $MachinePrecision], -1.0], $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{{\left(\mathsf{fma}\left(0.5 \cdot x - 1, x, 1\right)\right)}^{-1} + 1}
\end{array}
Initial program 41.1%
lift-/.f64N/A
lift--.f64N/A
lift-exp.f64N/A
lift-*.f64N/A
*-commutativeN/A
exp-lft-sqr-revN/A
lift-exp.f64N/A
lift-exp.f64N/A
metadata-evalN/A
lift--.f64N/A
flip-+N/A
lower-+.f64100.0
Applied rewrites100.0%
lift-exp.f64N/A
sinh-+-cosh-revN/A
lift-cosh.f64N/A
lift-sinh.f64N/A
flip-+N/A
lift-cosh.f64N/A
lift-cosh.f64N/A
lift-sinh.f64N/A
lift-sinh.f64N/A
sinh-coshN/A
lift-cosh.f64N/A
lift-sinh.f64N/A
sinh---cosh-revN/A
lower-/.f64N/A
lower-exp.f64N/A
lower-neg.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-*.f6497.5
Applied rewrites97.5%
Final simplification97.5%
(FPCore (x) :precision binary64 (sqrt (+ (pow (- 1.0 x) -1.0) 1.0)))
double code(double x) {
return sqrt((pow((1.0 - x), -1.0) + 1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = sqrt((((1.0d0 - x) ** (-1.0d0)) + 1.0d0))
end function
public static double code(double x) {
return Math.sqrt((Math.pow((1.0 - x), -1.0) + 1.0));
}
def code(x): return math.sqrt((math.pow((1.0 - x), -1.0) + 1.0))
function code(x) return sqrt(Float64((Float64(1.0 - x) ^ -1.0) + 1.0)) end
function tmp = code(x) tmp = sqrt((((1.0 - x) ^ -1.0) + 1.0)); end
code[x_] := N[Sqrt[N[(N[Power[N[(1.0 - x), $MachinePrecision], -1.0], $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{{\left(1 - x\right)}^{-1} + 1}
\end{array}
Initial program 41.1%
lift-/.f64N/A
lift--.f64N/A
lift-exp.f64N/A
lift-*.f64N/A
*-commutativeN/A
exp-lft-sqr-revN/A
lift-exp.f64N/A
lift-exp.f64N/A
metadata-evalN/A
lift--.f64N/A
flip-+N/A
lower-+.f64100.0
Applied rewrites100.0%
lift-exp.f64N/A
sinh-+-cosh-revN/A
lift-cosh.f64N/A
lift-sinh.f64N/A
flip-+N/A
lift-cosh.f64N/A
lift-cosh.f64N/A
lift-sinh.f64N/A
lift-sinh.f64N/A
sinh-coshN/A
lift-cosh.f64N/A
lift-sinh.f64N/A
sinh---cosh-revN/A
lower-/.f64N/A
lower-exp.f64N/A
lower-neg.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
*-commutativeN/A
fp-cancel-sign-sub-invN/A
*-commutativeN/A
mul-1-negN/A
remove-double-negN/A
lower--.f6496.7
Applied rewrites96.7%
Final simplification96.7%
(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 41.1%
lift-/.f64N/A
lift--.f64N/A
lift-exp.f64N/A
lift-*.f64N/A
*-commutativeN/A
exp-lft-sqr-revN/A
lift-exp.f64N/A
lift-exp.f64N/A
metadata-evalN/A
lift--.f64N/A
flip-+N/A
lower-+.f64100.0
Applied rewrites100.0%
(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 41.1%
Taylor expanded in x around 0
Applied rewrites68.1%
herbie shell --seed 2024342
(FPCore (x)
:name "sqrtexp (problem 3.4.4)"
:precision binary64
(sqrt (/ (- (exp (* 2.0 x)) 1.0) (- (exp x) 1.0))))