
(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 (sqrt (/ (expm1 (* 2.0 x)) (expm1 x))))
double code(double x) {
return sqrt((expm1((2.0 * x)) / expm1(x)));
}
public static double code(double x) {
return Math.sqrt((Math.expm1((2.0 * x)) / Math.expm1(x)));
}
def code(x): return math.sqrt((math.expm1((2.0 * x)) / math.expm1(x)))
function code(x) return sqrt(Float64(expm1(Float64(2.0 * x)) / expm1(x))) end
code[x_] := N[Sqrt[N[(N[(Exp[N[(2.0 * x), $MachinePrecision]] - 1), $MachinePrecision] / N[(Exp[x] - 1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\frac{\mathsf{expm1}\left(2 \cdot x\right)}{\mathsf{expm1}\left(x\right)}}
\end{array}
Initial program 34.3%
expm1-define35.1%
expm1-define100.0%
Simplified100.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 34.3%
*-commutative34.3%
exp-lft-sqr35.0%
difference-of-sqr-135.5%
associate-*r/35.5%
*-inverses100.0%
*-rgt-identity100.0%
+-commutative100.0%
Simplified100.0%
(FPCore (x) :precision binary64 (if (<= x -1.6) 1.0 (sqrt (+ 2.0 (* x (+ 1.0 (* x (+ 0.5 (* x 0.16666666666666666)))))))))
double code(double x) {
double tmp;
if (x <= -1.6) {
tmp = 1.0;
} else {
tmp = sqrt((2.0 + (x * (1.0 + (x * (0.5 + (x * 0.16666666666666666)))))));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-1.6d0)) then
tmp = 1.0d0
else
tmp = sqrt((2.0d0 + (x * (1.0d0 + (x * (0.5d0 + (x * 0.16666666666666666d0)))))))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= -1.6) {
tmp = 1.0;
} else {
tmp = Math.sqrt((2.0 + (x * (1.0 + (x * (0.5 + (x * 0.16666666666666666)))))));
}
return tmp;
}
def code(x): tmp = 0 if x <= -1.6: tmp = 1.0 else: tmp = math.sqrt((2.0 + (x * (1.0 + (x * (0.5 + (x * 0.16666666666666666))))))) return tmp
function code(x) tmp = 0.0 if (x <= -1.6) tmp = 1.0; else tmp = sqrt(Float64(2.0 + Float64(x * Float64(1.0 + Float64(x * Float64(0.5 + Float64(x * 0.16666666666666666))))))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= -1.6) tmp = 1.0; else tmp = sqrt((2.0 + (x * (1.0 + (x * (0.5 + (x * 0.16666666666666666))))))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -1.6], 1.0, N[Sqrt[N[(2.0 + N[(x * N[(1.0 + N[(x * N[(0.5 + N[(x * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.6:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\sqrt{2 + x \cdot \left(1 + x \cdot \left(0.5 + x \cdot 0.16666666666666666\right)\right)}\\
\end{array}
\end{array}
if x < -1.6000000000000001Initial program 100.0%
*-commutative100.0%
exp-lft-sqr100.0%
difference-of-sqr-1100.0%
associate-*r/100.0%
*-inverses100.0%
*-rgt-identity100.0%
+-commutative100.0%
Simplified100.0%
+-commutative100.0%
flip-+100.0%
metadata-eval100.0%
exp-lft-sqr100.0%
*-commutative100.0%
expm1-undefine100.0%
expm1-undefine100.0%
clear-num100.0%
sqrt-div100.0%
metadata-eval100.0%
clear-num100.0%
expm1-undefine100.0%
*-commutative100.0%
exp-lft-sqr100.0%
metadata-eval100.0%
expm1-undefine100.0%
flip-+100.0%
+-commutative100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 20.7%
Applied egg-rr99.1%
if -1.6000000000000001 < x Initial program 3.8%
*-commutative3.8%
exp-lft-sqr4.9%
difference-of-sqr-15.7%
associate-*r/5.7%
*-inverses100.0%
*-rgt-identity100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 99.4%
*-commutative99.4%
Simplified99.4%
(FPCore (x) :precision binary64 (if (<= x -1.35) 1.0 (sqrt (+ 2.0 (* x (+ 1.0 (* x 0.5)))))))
double code(double x) {
double tmp;
if (x <= -1.35) {
tmp = 1.0;
} else {
tmp = sqrt((2.0 + (x * (1.0 + (x * 0.5)))));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-1.35d0)) then
tmp = 1.0d0
else
tmp = sqrt((2.0d0 + (x * (1.0d0 + (x * 0.5d0)))))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= -1.35) {
tmp = 1.0;
} else {
tmp = Math.sqrt((2.0 + (x * (1.0 + (x * 0.5)))));
}
return tmp;
}
def code(x): tmp = 0 if x <= -1.35: tmp = 1.0 else: tmp = math.sqrt((2.0 + (x * (1.0 + (x * 0.5))))) return tmp
function code(x) tmp = 0.0 if (x <= -1.35) tmp = 1.0; else tmp = sqrt(Float64(2.0 + Float64(x * Float64(1.0 + Float64(x * 0.5))))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= -1.35) tmp = 1.0; else tmp = sqrt((2.0 + (x * (1.0 + (x * 0.5))))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -1.35], 1.0, N[Sqrt[N[(2.0 + N[(x * N[(1.0 + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.35:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\sqrt{2 + x \cdot \left(1 + x \cdot 0.5\right)}\\
\end{array}
\end{array}
if x < -1.3500000000000001Initial program 100.0%
*-commutative100.0%
exp-lft-sqr100.0%
difference-of-sqr-1100.0%
associate-*r/100.0%
*-inverses100.0%
*-rgt-identity100.0%
+-commutative100.0%
Simplified100.0%
+-commutative100.0%
flip-+100.0%
metadata-eval100.0%
exp-lft-sqr100.0%
*-commutative100.0%
expm1-undefine100.0%
expm1-undefine100.0%
clear-num100.0%
sqrt-div100.0%
metadata-eval100.0%
clear-num100.0%
expm1-undefine100.0%
*-commutative100.0%
exp-lft-sqr100.0%
metadata-eval100.0%
expm1-undefine100.0%
flip-+100.0%
+-commutative100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 20.7%
Applied egg-rr99.1%
if -1.3500000000000001 < x Initial program 3.8%
*-commutative3.8%
exp-lft-sqr4.9%
difference-of-sqr-15.7%
associate-*r/5.7%
*-inverses100.0%
*-rgt-identity100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 99.2%
Final simplification99.2%
(FPCore (x) :precision binary64 (if (<= x -1.0) 1.0 (sqrt (+ 2.0 x))))
double code(double x) {
double tmp;
if (x <= -1.0) {
tmp = 1.0;
} else {
tmp = sqrt((2.0 + x));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-1.0d0)) then
tmp = 1.0d0
else
tmp = sqrt((2.0d0 + x))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= -1.0) {
tmp = 1.0;
} else {
tmp = Math.sqrt((2.0 + x));
}
return tmp;
}
def code(x): tmp = 0 if x <= -1.0: tmp = 1.0 else: tmp = math.sqrt((2.0 + x)) return tmp
function code(x) tmp = 0.0 if (x <= -1.0) tmp = 1.0; else tmp = sqrt(Float64(2.0 + x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= -1.0) tmp = 1.0; else tmp = sqrt((2.0 + x)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -1.0], 1.0, N[Sqrt[N[(2.0 + x), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\sqrt{2 + x}\\
\end{array}
\end{array}
if x < -1Initial program 100.0%
*-commutative100.0%
exp-lft-sqr100.0%
difference-of-sqr-1100.0%
associate-*r/100.0%
*-inverses100.0%
*-rgt-identity100.0%
+-commutative100.0%
Simplified100.0%
+-commutative100.0%
flip-+100.0%
metadata-eval100.0%
exp-lft-sqr100.0%
*-commutative100.0%
expm1-undefine100.0%
expm1-undefine100.0%
clear-num100.0%
sqrt-div100.0%
metadata-eval100.0%
clear-num100.0%
expm1-undefine100.0%
*-commutative100.0%
exp-lft-sqr100.0%
metadata-eval100.0%
expm1-undefine100.0%
flip-+100.0%
+-commutative100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 20.7%
Applied egg-rr99.1%
if -1 < x Initial program 3.8%
*-commutative3.8%
exp-lft-sqr4.9%
difference-of-sqr-15.7%
associate-*r/5.7%
*-inverses100.0%
*-rgt-identity100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 98.8%
(FPCore (x) :precision binary64 (if (<= x -0.78) 1.0 (sqrt 2.0)))
double code(double x) {
double tmp;
if (x <= -0.78) {
tmp = 1.0;
} else {
tmp = sqrt(2.0);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-0.78d0)) then
tmp = 1.0d0
else
tmp = sqrt(2.0d0)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= -0.78) {
tmp = 1.0;
} else {
tmp = Math.sqrt(2.0);
}
return tmp;
}
def code(x): tmp = 0 if x <= -0.78: tmp = 1.0 else: tmp = math.sqrt(2.0) return tmp
function code(x) tmp = 0.0 if (x <= -0.78) tmp = 1.0; else tmp = sqrt(2.0); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= -0.78) tmp = 1.0; else tmp = sqrt(2.0); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -0.78], 1.0, N[Sqrt[2.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.78:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\sqrt{2}\\
\end{array}
\end{array}
if x < -0.78000000000000003Initial program 100.0%
*-commutative100.0%
exp-lft-sqr100.0%
difference-of-sqr-1100.0%
associate-*r/100.0%
*-inverses100.0%
*-rgt-identity100.0%
+-commutative100.0%
Simplified100.0%
+-commutative100.0%
flip-+100.0%
metadata-eval100.0%
exp-lft-sqr100.0%
*-commutative100.0%
expm1-undefine100.0%
expm1-undefine100.0%
clear-num100.0%
sqrt-div100.0%
metadata-eval100.0%
clear-num100.0%
expm1-undefine100.0%
*-commutative100.0%
exp-lft-sqr100.0%
metadata-eval100.0%
expm1-undefine100.0%
flip-+100.0%
+-commutative100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 20.7%
Applied egg-rr99.1%
if -0.78000000000000003 < x Initial program 3.8%
*-commutative3.8%
exp-lft-sqr4.9%
difference-of-sqr-15.7%
associate-*r/5.7%
*-inverses100.0%
*-rgt-identity100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 97.8%
(FPCore (x) :precision binary64 (if (<= x -0.56) 1.0 1.5))
double code(double x) {
double tmp;
if (x <= -0.56) {
tmp = 1.0;
} else {
tmp = 1.5;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-0.56d0)) then
tmp = 1.0d0
else
tmp = 1.5d0
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= -0.56) {
tmp = 1.0;
} else {
tmp = 1.5;
}
return tmp;
}
def code(x): tmp = 0 if x <= -0.56: tmp = 1.0 else: tmp = 1.5 return tmp
function code(x) tmp = 0.0 if (x <= -0.56) tmp = 1.0; else tmp = 1.5; end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= -0.56) tmp = 1.0; else tmp = 1.5; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -0.56], 1.0, 1.5]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.56:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;1.5\\
\end{array}
\end{array}
if x < -0.56000000000000005Initial program 100.0%
*-commutative100.0%
exp-lft-sqr100.0%
difference-of-sqr-1100.0%
associate-*r/100.0%
*-inverses100.0%
*-rgt-identity100.0%
+-commutative100.0%
Simplified100.0%
+-commutative100.0%
flip-+100.0%
metadata-eval100.0%
exp-lft-sqr100.0%
*-commutative100.0%
expm1-undefine100.0%
expm1-undefine100.0%
clear-num100.0%
sqrt-div100.0%
metadata-eval100.0%
clear-num100.0%
expm1-undefine100.0%
*-commutative100.0%
exp-lft-sqr100.0%
metadata-eval100.0%
expm1-undefine100.0%
flip-+100.0%
+-commutative100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 20.7%
Applied egg-rr99.1%
if -0.56000000000000005 < x Initial program 3.8%
*-commutative3.8%
exp-lft-sqr4.9%
difference-of-sqr-15.7%
associate-*r/5.7%
*-inverses100.0%
*-rgt-identity100.0%
+-commutative100.0%
Simplified100.0%
+-commutative100.0%
flip-+4.9%
metadata-eval4.9%
exp-lft-sqr3.8%
*-commutative3.8%
expm1-undefine5.1%
expm1-undefine100.0%
clear-num100.0%
sqrt-div98.5%
metadata-eval98.5%
clear-num98.5%
expm1-undefine5.3%
*-commutative5.3%
exp-lft-sqr5.1%
metadata-eval5.1%
expm1-undefine4.9%
flip-+98.5%
+-commutative98.5%
Applied egg-rr98.5%
Taylor expanded in x around 0 96.4%
Applied egg-rr24.3%
(FPCore (x) :precision binary64 1.0)
double code(double x) {
return 1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0
end function
public static double code(double x) {
return 1.0;
}
def code(x): return 1.0
function code(x) return 1.0 end
function tmp = code(x) tmp = 1.0; end
code[x_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 34.3%
*-commutative34.3%
exp-lft-sqr35.0%
difference-of-sqr-135.5%
associate-*r/35.5%
*-inverses100.0%
*-rgt-identity100.0%
+-commutative100.0%
Simplified100.0%
+-commutative100.0%
flip-+35.0%
metadata-eval35.0%
exp-lft-sqr34.3%
*-commutative34.3%
expm1-undefine35.1%
expm1-undefine100.0%
clear-num100.0%
sqrt-div99.0%
metadata-eval99.0%
clear-num99.0%
expm1-undefine35.2%
*-commutative35.2%
exp-lft-sqr35.1%
metadata-eval35.1%
expm1-undefine35.0%
flip-+99.0%
+-commutative99.0%
Applied egg-rr99.0%
Taylor expanded in x around 0 72.4%
Applied egg-rr45.5%
herbie shell --seed 2024108
(FPCore (x)
:name "sqrtexp (problem 3.4.4)"
:precision binary64
(sqrt (/ (- (exp (* 2.0 x)) 1.0) (- (exp x) 1.0))))