
(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 8 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 (hypot 1.0 (sqrt (exp x))))
double code(double x) {
return hypot(1.0, sqrt(exp(x)));
}
public static double code(double x) {
return Math.hypot(1.0, Math.sqrt(Math.exp(x)));
}
def code(x): return math.hypot(1.0, math.sqrt(math.exp(x)))
function code(x) return hypot(1.0, sqrt(exp(x))) end
function tmp = code(x) tmp = hypot(1.0, sqrt(exp(x))); end
code[x_] := N[Sqrt[1.0 ^ 2 + N[Sqrt[N[Exp[x], $MachinePrecision]], $MachinePrecision] ^ 2], $MachinePrecision]
\begin{array}{l}
\\
\mathsf{hypot}\left(1, \sqrt{e^{x}}\right)
\end{array}
Initial program 40.8%
*-commutative40.8%
exp-lft-sqr41.5%
difference-of-sqr-142.5%
associate-/l*42.5%
*-inverses100.0%
/-rgt-identity100.0%
+-commutative100.0%
Simplified100.0%
add-sqr-sqrt100.0%
hypot-1-def100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x) :precision binary64 (hypot 1.0 (exp (* x 0.5))))
double code(double x) {
return hypot(1.0, exp((x * 0.5)));
}
public static double code(double x) {
return Math.hypot(1.0, Math.exp((x * 0.5)));
}
def code(x): return math.hypot(1.0, math.exp((x * 0.5)))
function code(x) return hypot(1.0, exp(Float64(x * 0.5))) end
function tmp = code(x) tmp = hypot(1.0, exp((x * 0.5))); end
code[x_] := N[Sqrt[1.0 ^ 2 + N[Exp[N[(x * 0.5), $MachinePrecision]], $MachinePrecision] ^ 2], $MachinePrecision]
\begin{array}{l}
\\
\mathsf{hypot}\left(1, e^{x \cdot 0.5}\right)
\end{array}
Initial program 40.8%
*-commutative40.8%
exp-lft-sqr41.5%
difference-of-sqr-142.5%
associate-/l*42.5%
*-inverses100.0%
/-rgt-identity100.0%
+-commutative100.0%
Simplified100.0%
add-sqr-sqrt100.0%
hypot-1-def100.0%
Applied egg-rr100.0%
pow1/2100.0%
pow-exp100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x) :precision binary64 (sqrt (+ 1.0 (exp x))))
double code(double x) {
return sqrt((1.0 + exp(x)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = sqrt((1.0d0 + exp(x)))
end function
public static double code(double x) {
return Math.sqrt((1.0 + Math.exp(x)));
}
def code(x): return math.sqrt((1.0 + math.exp(x)))
function code(x) return sqrt(Float64(1.0 + exp(x))) end
function tmp = code(x) tmp = sqrt((1.0 + exp(x))); end
code[x_] := N[Sqrt[N[(1.0 + N[Exp[x], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{1 + e^{x}}
\end{array}
Initial program 40.8%
*-commutative40.8%
exp-lft-sqr41.5%
difference-of-sqr-142.5%
associate-/l*42.5%
*-inverses100.0%
/-rgt-identity100.0%
+-commutative100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x) :precision binary64 (if (<= x -4.2) (sqrt 2.0) (pow (+ 0.5 (* x -0.25)) -0.5)))
double code(double x) {
double tmp;
if (x <= -4.2) {
tmp = sqrt(2.0);
} else {
tmp = pow((0.5 + (x * -0.25)), -0.5);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-4.2d0)) then
tmp = sqrt(2.0d0)
else
tmp = (0.5d0 + (x * (-0.25d0))) ** (-0.5d0)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= -4.2) {
tmp = Math.sqrt(2.0);
} else {
tmp = Math.pow((0.5 + (x * -0.25)), -0.5);
}
return tmp;
}
def code(x): tmp = 0 if x <= -4.2: tmp = math.sqrt(2.0) else: tmp = math.pow((0.5 + (x * -0.25)), -0.5) return tmp
function code(x) tmp = 0.0 if (x <= -4.2) tmp = sqrt(2.0); else tmp = Float64(0.5 + Float64(x * -0.25)) ^ -0.5; end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= -4.2) tmp = sqrt(2.0); else tmp = (0.5 + (x * -0.25)) ^ -0.5; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -4.2], N[Sqrt[2.0], $MachinePrecision], N[Power[N[(0.5 + N[(x * -0.25), $MachinePrecision]), $MachinePrecision], -0.5], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.2:\\
\;\;\;\;\sqrt{2}\\
\mathbf{else}:\\
\;\;\;\;{\left(0.5 + x \cdot -0.25\right)}^{-0.5}\\
\end{array}
\end{array}
if x < -4.20000000000000018Initial program 100.0%
*-commutative100.0%
exp-lft-sqr100.0%
difference-of-sqr-1100.0%
associate-/l*100.0%
*-inverses100.0%
/-rgt-identity100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 20.7%
if -4.20000000000000018 < x Initial program 7.6%
*-commutative7.6%
exp-lft-sqr8.7%
difference-of-sqr-110.3%
associate-/l*10.3%
*-inverses100.0%
/-rgt-identity100.0%
+-commutative100.0%
Simplified100.0%
pow1/2100.0%
+-commutative100.0%
flip-+8.7%
metadata-eval8.7%
prod-exp7.6%
expm1-udef9.6%
expm1-udef100.0%
div-inv99.7%
div-inv100.0%
clear-num99.9%
inv-pow99.9%
metadata-eval99.9%
pow-pow100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 98.5%
*-commutative98.5%
Simplified98.5%
Final simplification70.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 40.8%
*-commutative40.8%
exp-lft-sqr41.5%
difference-of-sqr-142.5%
associate-/l*42.5%
*-inverses100.0%
/-rgt-identity100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 68.8%
Final simplification68.8%
(FPCore (x) :precision binary64 (+ 1.0 (* x 0.5)))
double code(double x) {
return 1.0 + (x * 0.5);
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 + (x * 0.5d0)
end function
public static double code(double x) {
return 1.0 + (x * 0.5);
}
def code(x): return 1.0 + (x * 0.5)
function code(x) return Float64(1.0 + Float64(x * 0.5)) end
function tmp = code(x) tmp = 1.0 + (x * 0.5); end
code[x_] := N[(1.0 + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 + x \cdot 0.5
\end{array}
Initial program 40.8%
*-commutative40.8%
exp-lft-sqr41.5%
difference-of-sqr-142.5%
associate-/l*42.5%
*-inverses100.0%
/-rgt-identity100.0%
+-commutative100.0%
Simplified100.0%
add-sqr-sqrt100.0%
hypot-1-def100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 64.6%
Taylor expanded in x around inf 13.6%
Final simplification13.6%
(FPCore (x) :precision binary64 (* x 0.5))
double code(double x) {
return x * 0.5;
}
real(8) function code(x)
real(8), intent (in) :: x
code = x * 0.5d0
end function
public static double code(double x) {
return x * 0.5;
}
def code(x): return x * 0.5
function code(x) return Float64(x * 0.5) end
function tmp = code(x) tmp = x * 0.5; end
code[x_] := N[(x * 0.5), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 0.5
\end{array}
Initial program 40.8%
*-commutative40.8%
exp-lft-sqr41.5%
difference-of-sqr-142.5%
associate-/l*42.5%
*-inverses100.0%
/-rgt-identity100.0%
+-commutative100.0%
Simplified100.0%
add-sqr-sqrt100.0%
hypot-1-def100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 64.6%
Taylor expanded in x around inf 3.1%
Final simplification3.1%
(FPCore (x) :precision binary64 (* x -0.5))
double code(double x) {
return x * -0.5;
}
real(8) function code(x)
real(8), intent (in) :: x
code = x * (-0.5d0)
end function
public static double code(double x) {
return x * -0.5;
}
def code(x): return x * -0.5
function code(x) return Float64(x * -0.5) end
function tmp = code(x) tmp = x * -0.5; end
code[x_] := N[(x * -0.5), $MachinePrecision]
\begin{array}{l}
\\
x \cdot -0.5
\end{array}
Initial program 40.8%
*-commutative40.8%
exp-lft-sqr41.5%
difference-of-sqr-142.5%
associate-/l*42.5%
*-inverses100.0%
/-rgt-identity100.0%
+-commutative100.0%
Simplified100.0%
add-sqr-sqrt100.0%
hypot-1-def100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 64.6%
Taylor expanded in x around -inf 4.3%
*-commutative4.3%
Simplified4.3%
Final simplification4.3%
herbie shell --seed 2023192
(FPCore (x)
:name "sqrtexp (problem 3.4.4)"
:precision binary64
(sqrt (/ (- (exp (* 2.0 x)) 1.0) (- (exp x) 1.0))))