
(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 4 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 (+ 2.0 (expm1 x))))
double code(double x) {
return sqrt((2.0 + expm1(x)));
}
public static double code(double x) {
return Math.sqrt((2.0 + Math.expm1(x)));
}
def code(x): return math.sqrt((2.0 + math.expm1(x)))
function code(x) return sqrt(Float64(2.0 + expm1(x))) end
code[x_] := N[Sqrt[N[(2.0 + N[(Exp[x] - 1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{2 + \mathsf{expm1}\left(x\right)}
\end{array}
Initial program 33.2%
*-commutative33.2%
exp-lft-sqr34.3%
difference-of-sqr-134.8%
associate-*r/34.8%
*-inverses100.0%
*-rgt-identity100.0%
+-commutative100.0%
Simplified100.0%
expm1-log1p-u99.0%
expm1-undefine99.0%
Applied egg-rr99.0%
log1p-undefine100.0%
rem-exp-log100.0%
associate-+r+100.0%
metadata-eval100.0%
associate--l+100.0%
expm1-define100.0%
Simplified100.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 33.2%
*-commutative33.2%
exp-lft-sqr34.3%
difference-of-sqr-134.8%
associate-*r/34.8%
*-inverses100.0%
*-rgt-identity100.0%
+-commutative100.0%
Simplified100.0%
Final simplification100.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 33.2%
*-commutative33.2%
exp-lft-sqr34.3%
difference-of-sqr-134.8%
associate-*r/34.8%
*-inverses100.0%
*-rgt-identity100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 73.2%
Final simplification73.2%
(FPCore (x) :precision binary64 (- x))
double code(double x) {
return -x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = -x
end function
public static double code(double x) {
return -x;
}
def code(x): return -x
function code(x) return Float64(-x) end
function tmp = code(x) tmp = -x; end
code[x_] := (-x)
\begin{array}{l}
\\
-x
\end{array}
Initial program 33.2%
*-commutative33.2%
exp-lft-sqr34.3%
difference-of-sqr-134.8%
associate-*r/34.8%
*-inverses100.0%
*-rgt-identity100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 67.4%
expm1-log1p-u67.4%
expm1-undefine66.4%
log1p-undefine66.4%
rem-exp-log66.4%
Applied egg-rr66.4%
flip-+66.4%
clear-num66.4%
metadata-eval66.4%
add-sqr-sqrt65.4%
associate--r+65.4%
metadata-eval65.4%
Applied egg-rr65.4%
Taylor expanded in x around -inf 4.1%
neg-mul-14.1%
Simplified4.1%
Final simplification4.1%
herbie shell --seed 2024039
(FPCore (x)
:name "sqrtexp (problem 3.4.4)"
:precision binary64
(sqrt (/ (- (exp (* 2.0 x)) 1.0) (- (exp x) 1.0))))