
(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 5 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 (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 36.4%
*-commutative36.4%
exp-lft-sqr36.5%
difference-of-sqr-137.1%
associate-/l*37.1%
*-inverses100.0%
/-rgt-identity100.0%
+-commutative100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x)
:precision binary64
(if (<= x -6.0)
(sqrt 2.0)
(sqrt
(+ x (+ 2.0 (/ (* x (* x 0.25)) (+ 0.5 (* x -0.16666666666666666))))))))
double code(double x) {
double tmp;
if (x <= -6.0) {
tmp = sqrt(2.0);
} else {
tmp = sqrt((x + (2.0 + ((x * (x * 0.25)) / (0.5 + (x * -0.16666666666666666))))));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-6.0d0)) then
tmp = sqrt(2.0d0)
else
tmp = sqrt((x + (2.0d0 + ((x * (x * 0.25d0)) / (0.5d0 + (x * (-0.16666666666666666d0)))))))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= -6.0) {
tmp = Math.sqrt(2.0);
} else {
tmp = Math.sqrt((x + (2.0 + ((x * (x * 0.25)) / (0.5 + (x * -0.16666666666666666))))));
}
return tmp;
}
def code(x): tmp = 0 if x <= -6.0: tmp = math.sqrt(2.0) else: tmp = math.sqrt((x + (2.0 + ((x * (x * 0.25)) / (0.5 + (x * -0.16666666666666666)))))) return tmp
function code(x) tmp = 0.0 if (x <= -6.0) tmp = sqrt(2.0); else tmp = sqrt(Float64(x + Float64(2.0 + Float64(Float64(x * Float64(x * 0.25)) / Float64(0.5 + Float64(x * -0.16666666666666666)))))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= -6.0) tmp = sqrt(2.0); else tmp = sqrt((x + (2.0 + ((x * (x * 0.25)) / (0.5 + (x * -0.16666666666666666)))))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -6.0], N[Sqrt[2.0], $MachinePrecision], N[Sqrt[N[(x + N[(2.0 + N[(N[(x * N[(x * 0.25), $MachinePrecision]), $MachinePrecision] / N[(0.5 + N[(x * -0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6:\\
\;\;\;\;\sqrt{2}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{x + \left(2 + \frac{x \cdot \left(x \cdot 0.25\right)}{0.5 + x \cdot -0.16666666666666666}\right)}\\
\end{array}
\end{array}
if x < -6Initial 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 -6 < x Initial program 8.0%
*-commutative8.0%
exp-lft-sqr8.2%
difference-of-sqr-19.0%
associate-/l*9.0%
*-inverses100.0%
/-rgt-identity100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 97.1%
+-commutative97.1%
associate-+l+97.1%
+-commutative97.1%
*-commutative97.1%
*-commutative97.1%
unpow397.1%
unpow297.1%
associate-*l*97.1%
distribute-lft-out97.1%
unpow297.1%
Simplified97.1%
*-commutative97.1%
flip-+97.1%
associate-*l/97.1%
metadata-eval97.1%
swap-sqr97.1%
metadata-eval97.1%
*-commutative97.1%
cancel-sign-sub-inv97.1%
metadata-eval97.1%
Applied egg-rr97.1%
Taylor expanded in x around 0 97.3%
unpow297.3%
*-commutative97.3%
associate-*l*97.3%
Simplified97.3%
Final simplification73.7%
(FPCore (x) :precision binary64 (if (<= x -1.95) (sqrt 2.0) (sqrt (+ x (+ 2.0 (* (* x x) (+ 0.5 (* x 0.16666666666666666))))))))
double code(double x) {
double tmp;
if (x <= -1.95) {
tmp = sqrt(2.0);
} else {
tmp = sqrt((x + (2.0 + ((x * x) * (0.5 + (x * 0.16666666666666666))))));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-1.95d0)) then
tmp = sqrt(2.0d0)
else
tmp = sqrt((x + (2.0d0 + ((x * x) * (0.5d0 + (x * 0.16666666666666666d0))))))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= -1.95) {
tmp = Math.sqrt(2.0);
} else {
tmp = Math.sqrt((x + (2.0 + ((x * x) * (0.5 + (x * 0.16666666666666666))))));
}
return tmp;
}
def code(x): tmp = 0 if x <= -1.95: tmp = math.sqrt(2.0) else: tmp = math.sqrt((x + (2.0 + ((x * x) * (0.5 + (x * 0.16666666666666666)))))) return tmp
function code(x) tmp = 0.0 if (x <= -1.95) tmp = sqrt(2.0); else tmp = sqrt(Float64(x + Float64(2.0 + Float64(Float64(x * x) * Float64(0.5 + Float64(x * 0.16666666666666666)))))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= -1.95) tmp = sqrt(2.0); else tmp = sqrt((x + (2.0 + ((x * x) * (0.5 + (x * 0.16666666666666666)))))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -1.95], N[Sqrt[2.0], $MachinePrecision], N[Sqrt[N[(x + N[(2.0 + N[(N[(x * x), $MachinePrecision] * N[(0.5 + N[(x * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.95:\\
\;\;\;\;\sqrt{2}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{x + \left(2 + \left(x \cdot x\right) \cdot \left(0.5 + x \cdot 0.16666666666666666\right)\right)}\\
\end{array}
\end{array}
if x < -1.94999999999999996Initial 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 -1.94999999999999996 < x Initial program 7.5%
*-commutative7.5%
exp-lft-sqr7.7%
difference-of-sqr-18.5%
associate-/l*8.5%
*-inverses100.0%
/-rgt-identity100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 97.7%
+-commutative97.7%
associate-+l+97.7%
+-commutative97.7%
*-commutative97.7%
*-commutative97.7%
unpow397.7%
unpow297.7%
associate-*l*97.7%
distribute-lft-out97.7%
unpow297.7%
Simplified97.7%
Final simplification73.6%
(FPCore (x) :precision binary64 (if (<= x -2.0) (sqrt 2.0) (sqrt (+ (+ x 2.0) (* 0.5 (* x x))))))
double code(double x) {
double tmp;
if (x <= -2.0) {
tmp = sqrt(2.0);
} else {
tmp = sqrt(((x + 2.0) + (0.5 * (x * x))));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-2.0d0)) then
tmp = sqrt(2.0d0)
else
tmp = sqrt(((x + 2.0d0) + (0.5d0 * (x * x))))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= -2.0) {
tmp = Math.sqrt(2.0);
} else {
tmp = Math.sqrt(((x + 2.0) + (0.5 * (x * x))));
}
return tmp;
}
def code(x): tmp = 0 if x <= -2.0: tmp = math.sqrt(2.0) else: tmp = math.sqrt(((x + 2.0) + (0.5 * (x * x)))) return tmp
function code(x) tmp = 0.0 if (x <= -2.0) tmp = sqrt(2.0); else tmp = sqrt(Float64(Float64(x + 2.0) + Float64(0.5 * Float64(x * x)))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= -2.0) tmp = sqrt(2.0); else tmp = sqrt(((x + 2.0) + (0.5 * (x * x)))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -2.0], N[Sqrt[2.0], $MachinePrecision], N[Sqrt[N[(N[(x + 2.0), $MachinePrecision] + N[(0.5 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2:\\
\;\;\;\;\sqrt{2}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\left(x + 2\right) + 0.5 \cdot \left(x \cdot x\right)}\\
\end{array}
\end{array}
if x < -2Initial 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 -2 < x Initial program 7.5%
*-commutative7.5%
exp-lft-sqr7.7%
difference-of-sqr-18.5%
associate-/l*8.5%
*-inverses100.0%
/-rgt-identity100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 97.1%
associate-+r+97.1%
unpow297.1%
Simplified97.1%
Final simplification73.2%
(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 36.4%
*-commutative36.4%
exp-lft-sqr36.5%
difference-of-sqr-137.1%
associate-/l*37.1%
*-inverses100.0%
/-rgt-identity100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 71.6%
Final simplification71.6%
herbie shell --seed 2023275
(FPCore (x)
:name "sqrtexp (problem 3.4.4)"
:precision binary64
(sqrt (/ (- (exp (* 2.0 x)) 1.0) (- (exp x) 1.0))))