
(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 9 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 37.8%
*-commutative37.8%
exp-lft-sqr37.9%
difference-of-sqr-138.3%
associate-/l*38.3%
*-inverses100.0%
/-rgt-identity100.0%
+-commutative100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x) :precision binary64 (if (<= x -4.2) (+ 1.0 (/ 1.0 x)) (hypot 1.0 (+ 1.0 (* x (+ 0.5 (* x 0.125)))))))
double code(double x) {
double tmp;
if (x <= -4.2) {
tmp = 1.0 + (1.0 / x);
} else {
tmp = hypot(1.0, (1.0 + (x * (0.5 + (x * 0.125)))));
}
return tmp;
}
public static double code(double x) {
double tmp;
if (x <= -4.2) {
tmp = 1.0 + (1.0 / x);
} else {
tmp = Math.hypot(1.0, (1.0 + (x * (0.5 + (x * 0.125)))));
}
return tmp;
}
def code(x): tmp = 0 if x <= -4.2: tmp = 1.0 + (1.0 / x) else: tmp = math.hypot(1.0, (1.0 + (x * (0.5 + (x * 0.125))))) return tmp
function code(x) tmp = 0.0 if (x <= -4.2) tmp = Float64(1.0 + Float64(1.0 / x)); else tmp = hypot(1.0, Float64(1.0 + Float64(x * Float64(0.5 + Float64(x * 0.125))))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= -4.2) tmp = 1.0 + (1.0 / x); else tmp = hypot(1.0, (1.0 + (x * (0.5 + (x * 0.125))))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -4.2], N[(1.0 + N[(1.0 / x), $MachinePrecision]), $MachinePrecision], N[Sqrt[1.0 ^ 2 + N[(1.0 + N[(x * N[(0.5 + N[(x * 0.125), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.2:\\
\;\;\;\;1 + \frac{1}{x}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{hypot}\left(1, 1 + x \cdot \left(0.5 + x \cdot 0.125\right)\right)\\
\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%
add-log-exp100.0%
*-un-lft-identity100.0%
log-prod100.0%
metadata-eval100.0%
add-log-exp100.0%
add-sqr-sqrt100.0%
hypot-1-def100.0%
Applied egg-rr100.0%
+-lft-identity100.0%
Simplified100.0%
Taylor expanded in x around 0 5.2%
Taylor expanded in x around inf 1.1%
Taylor expanded in x around 0 98.8%
if -4.20000000000000018 < x Initial program 4.7%
*-commutative4.7%
exp-lft-sqr4.8%
difference-of-sqr-15.4%
associate-/l*5.4%
*-inverses100.0%
/-rgt-identity100.0%
+-commutative100.0%
Simplified100.0%
add-log-exp100.0%
*-un-lft-identity100.0%
log-prod100.0%
metadata-eval100.0%
add-log-exp100.0%
add-sqr-sqrt100.0%
hypot-1-def100.0%
Applied egg-rr100.0%
+-lft-identity100.0%
Simplified100.0%
Taylor expanded in x around 0 97.0%
+-commutative97.0%
*-commutative97.0%
*-commutative97.0%
unpow297.0%
associate-*l*97.0%
distribute-lft-out97.0%
Simplified97.0%
Final simplification97.6%
(FPCore (x) :precision binary64 (if (<= x -4.2) (+ 1.0 (/ 1.0 x)) (hypot 1.0 (+ 1.0 (* x 0.5)))))
double code(double x) {
double tmp;
if (x <= -4.2) {
tmp = 1.0 + (1.0 / x);
} else {
tmp = hypot(1.0, (1.0 + (x * 0.5)));
}
return tmp;
}
public static double code(double x) {
double tmp;
if (x <= -4.2) {
tmp = 1.0 + (1.0 / x);
} else {
tmp = Math.hypot(1.0, (1.0 + (x * 0.5)));
}
return tmp;
}
def code(x): tmp = 0 if x <= -4.2: tmp = 1.0 + (1.0 / x) else: tmp = math.hypot(1.0, (1.0 + (x * 0.5))) return tmp
function code(x) tmp = 0.0 if (x <= -4.2) tmp = Float64(1.0 + Float64(1.0 / x)); else tmp = hypot(1.0, Float64(1.0 + Float64(x * 0.5))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= -4.2) tmp = 1.0 + (1.0 / x); else tmp = hypot(1.0, (1.0 + (x * 0.5))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -4.2], N[(1.0 + N[(1.0 / x), $MachinePrecision]), $MachinePrecision], N[Sqrt[1.0 ^ 2 + N[(1.0 + N[(x * 0.5), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.2:\\
\;\;\;\;1 + \frac{1}{x}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{hypot}\left(1, 1 + x \cdot 0.5\right)\\
\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%
add-log-exp100.0%
*-un-lft-identity100.0%
log-prod100.0%
metadata-eval100.0%
add-log-exp100.0%
add-sqr-sqrt100.0%
hypot-1-def100.0%
Applied egg-rr100.0%
+-lft-identity100.0%
Simplified100.0%
Taylor expanded in x around 0 5.2%
Taylor expanded in x around inf 1.1%
Taylor expanded in x around 0 98.8%
if -4.20000000000000018 < x Initial program 4.7%
*-commutative4.7%
exp-lft-sqr4.8%
difference-of-sqr-15.4%
associate-/l*5.4%
*-inverses100.0%
/-rgt-identity100.0%
+-commutative100.0%
Simplified100.0%
add-log-exp100.0%
*-un-lft-identity100.0%
log-prod100.0%
metadata-eval100.0%
add-log-exp100.0%
add-sqr-sqrt100.0%
hypot-1-def100.0%
Applied egg-rr100.0%
+-lft-identity100.0%
Simplified100.0%
Taylor expanded in x around 0 96.6%
Final simplification97.3%
(FPCore (x) :precision binary64 (if (<= x -1.8) (+ 1.0 (/ 1.0 x)) (sqrt (+ x 2.0))))
double code(double x) {
double tmp;
if (x <= -1.8) {
tmp = 1.0 + (1.0 / x);
} else {
tmp = sqrt((x + 2.0));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-1.8d0)) then
tmp = 1.0d0 + (1.0d0 / x)
else
tmp = sqrt((x + 2.0d0))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= -1.8) {
tmp = 1.0 + (1.0 / x);
} else {
tmp = Math.sqrt((x + 2.0));
}
return tmp;
}
def code(x): tmp = 0 if x <= -1.8: tmp = 1.0 + (1.0 / x) else: tmp = math.sqrt((x + 2.0)) return tmp
function code(x) tmp = 0.0 if (x <= -1.8) tmp = Float64(1.0 + Float64(1.0 / x)); else tmp = sqrt(Float64(x + 2.0)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= -1.8) tmp = 1.0 + (1.0 / x); else tmp = sqrt((x + 2.0)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -1.8], N[(1.0 + N[(1.0 / x), $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(x + 2.0), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.8:\\
\;\;\;\;1 + \frac{1}{x}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{x + 2}\\
\end{array}
\end{array}
if x < -1.80000000000000004Initial 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%
add-log-exp100.0%
*-un-lft-identity100.0%
log-prod100.0%
metadata-eval100.0%
add-log-exp100.0%
add-sqr-sqrt100.0%
hypot-1-def100.0%
Applied egg-rr100.0%
+-lft-identity100.0%
Simplified100.0%
Taylor expanded in x around 0 5.2%
Taylor expanded in x around inf 1.1%
Taylor expanded in x around 0 98.8%
if -1.80000000000000004 < x Initial program 4.7%
*-commutative4.7%
exp-lft-sqr4.8%
difference-of-sqr-15.4%
associate-/l*5.4%
*-inverses100.0%
/-rgt-identity100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 96.5%
Final simplification97.3%
(FPCore (x) :precision binary64 (if (<= x -5.0) (+ 1.0 (/ 1.0 x)) (sqrt 2.0)))
double code(double x) {
double tmp;
if (x <= -5.0) {
tmp = 1.0 + (1.0 / x);
} else {
tmp = sqrt(2.0);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-5.0d0)) then
tmp = 1.0d0 + (1.0d0 / x)
else
tmp = sqrt(2.0d0)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= -5.0) {
tmp = 1.0 + (1.0 / x);
} else {
tmp = Math.sqrt(2.0);
}
return tmp;
}
def code(x): tmp = 0 if x <= -5.0: tmp = 1.0 + (1.0 / x) else: tmp = math.sqrt(2.0) return tmp
function code(x) tmp = 0.0 if (x <= -5.0) tmp = Float64(1.0 + Float64(1.0 / x)); else tmp = sqrt(2.0); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= -5.0) tmp = 1.0 + (1.0 / x); else tmp = sqrt(2.0); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -5.0], N[(1.0 + N[(1.0 / x), $MachinePrecision]), $MachinePrecision], N[Sqrt[2.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5:\\
\;\;\;\;1 + \frac{1}{x}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{2}\\
\end{array}
\end{array}
if x < -5Initial 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%
add-log-exp100.0%
*-un-lft-identity100.0%
log-prod100.0%
metadata-eval100.0%
add-log-exp100.0%
add-sqr-sqrt100.0%
hypot-1-def100.0%
Applied egg-rr100.0%
+-lft-identity100.0%
Simplified100.0%
Taylor expanded in x around 0 5.2%
Taylor expanded in x around inf 1.1%
Taylor expanded in x around 0 98.8%
if -5 < x Initial program 4.7%
*-commutative4.7%
exp-lft-sqr4.8%
difference-of-sqr-15.4%
associate-/l*5.4%
*-inverses100.0%
/-rgt-identity100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 95.7%
Final simplification96.8%
(FPCore (x) :precision binary64 (if (<= x -1.4) (+ 1.0 (/ 1.0 x)) (+ 1.0 (* x 0.5))))
double code(double x) {
double tmp;
if (x <= -1.4) {
tmp = 1.0 + (1.0 / x);
} else {
tmp = 1.0 + (x * 0.5);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-1.4d0)) then
tmp = 1.0d0 + (1.0d0 / x)
else
tmp = 1.0d0 + (x * 0.5d0)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= -1.4) {
tmp = 1.0 + (1.0 / x);
} else {
tmp = 1.0 + (x * 0.5);
}
return tmp;
}
def code(x): tmp = 0 if x <= -1.4: tmp = 1.0 + (1.0 / x) else: tmp = 1.0 + (x * 0.5) return tmp
function code(x) tmp = 0.0 if (x <= -1.4) tmp = Float64(1.0 + Float64(1.0 / x)); else tmp = Float64(1.0 + Float64(x * 0.5)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= -1.4) tmp = 1.0 + (1.0 / x); else tmp = 1.0 + (x * 0.5); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -1.4], N[(1.0 + N[(1.0 / x), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.4:\\
\;\;\;\;1 + \frac{1}{x}\\
\mathbf{else}:\\
\;\;\;\;1 + x \cdot 0.5\\
\end{array}
\end{array}
if x < -1.3999999999999999Initial 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%
add-log-exp100.0%
*-un-lft-identity100.0%
log-prod100.0%
metadata-eval100.0%
add-log-exp100.0%
add-sqr-sqrt100.0%
hypot-1-def100.0%
Applied egg-rr100.0%
+-lft-identity100.0%
Simplified100.0%
Taylor expanded in x around 0 5.2%
Taylor expanded in x around inf 1.1%
Taylor expanded in x around 0 98.8%
if -1.3999999999999999 < x Initial program 4.7%
*-commutative4.7%
exp-lft-sqr4.8%
difference-of-sqr-15.4%
associate-/l*5.4%
*-inverses100.0%
/-rgt-identity100.0%
+-commutative100.0%
Simplified100.0%
add-log-exp100.0%
*-un-lft-identity100.0%
log-prod100.0%
metadata-eval100.0%
add-log-exp100.0%
add-sqr-sqrt100.0%
hypot-1-def100.0%
Applied egg-rr100.0%
+-lft-identity100.0%
Simplified100.0%
Taylor expanded in x around 0 96.6%
Taylor expanded in x around inf 20.5%
Final simplification47.7%
(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 37.8%
*-commutative37.8%
exp-lft-sqr37.9%
difference-of-sqr-138.3%
associate-/l*38.3%
*-inverses100.0%
/-rgt-identity100.0%
+-commutative100.0%
Simplified100.0%
add-log-exp100.0%
*-un-lft-identity100.0%
log-prod100.0%
metadata-eval100.0%
add-log-exp100.0%
add-sqr-sqrt100.0%
hypot-1-def100.0%
Applied egg-rr100.0%
+-lft-identity100.0%
Simplified100.0%
Taylor expanded in x around 0 64.8%
Taylor expanded in x around inf 13.7%
Final simplification13.7%
(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 37.8%
*-commutative37.8%
exp-lft-sqr37.9%
difference-of-sqr-138.3%
associate-/l*38.3%
*-inverses100.0%
/-rgt-identity100.0%
+-commutative100.0%
Simplified100.0%
add-log-exp100.0%
*-un-lft-identity100.0%
log-prod100.0%
metadata-eval100.0%
add-log-exp100.0%
add-sqr-sqrt100.0%
hypot-1-def100.0%
Applied egg-rr100.0%
+-lft-identity100.0%
Simplified100.0%
Taylor expanded in x around 0 64.8%
Taylor expanded in x around inf 3.0%
Final simplification3.0%
(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 37.8%
*-commutative37.8%
exp-lft-sqr37.9%
difference-of-sqr-138.3%
associate-/l*38.3%
*-inverses100.0%
/-rgt-identity100.0%
+-commutative100.0%
Simplified100.0%
add-log-exp100.0%
*-un-lft-identity100.0%
log-prod100.0%
metadata-eval100.0%
add-log-exp100.0%
add-sqr-sqrt100.0%
hypot-1-def100.0%
Applied egg-rr100.0%
+-lft-identity100.0%
Simplified100.0%
Taylor expanded in x around 0 64.8%
Taylor expanded in x around -inf 4.2%
*-commutative4.2%
Simplified4.2%
Final simplification4.2%
herbie shell --seed 2024041
(FPCore (x)
:name "sqrtexp (problem 3.4.4)"
:precision binary64
(sqrt (/ (- (exp (* 2.0 x)) 1.0) (- (exp x) 1.0))))