
(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 (+ 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 38.6%
*-commutative38.6%
exp-lft-sqr39.6%
difference-of-sqr-140.2%
associate-*r/40.6%
*-inverses100.0%
*-rgt-identity100.0%
+-commutative100.0%
Simplified100.0%
(FPCore (x) :precision binary64 (sqrt (+ 2.0 (* x (+ 1.0 (* x 0.5))))))
double code(double x) {
return sqrt((2.0 + (x * (1.0 + (x * 0.5)))));
}
real(8) function code(x)
real(8), intent (in) :: x
code = sqrt((2.0d0 + (x * (1.0d0 + (x * 0.5d0)))))
end function
public static double code(double x) {
return Math.sqrt((2.0 + (x * (1.0 + (x * 0.5)))));
}
def code(x): return math.sqrt((2.0 + (x * (1.0 + (x * 0.5)))))
function code(x) return sqrt(Float64(2.0 + Float64(x * Float64(1.0 + Float64(x * 0.5))))) end
function tmp = code(x) tmp = sqrt((2.0 + (x * (1.0 + (x * 0.5))))); end
code[x_] := N[Sqrt[N[(2.0 + N[(x * N[(1.0 + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{2 + x \cdot \left(1 + x \cdot 0.5\right)}
\end{array}
Initial program 38.6%
*-commutative38.6%
exp-lft-sqr39.6%
difference-of-sqr-140.2%
associate-*r/40.6%
*-inverses100.0%
*-rgt-identity100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 65.2%
Final simplification65.2%
(FPCore (x) :precision binary64 (/ 1.0 (sqrt (+ 0.5 (* x -0.25)))))
double code(double x) {
return 1.0 / sqrt((0.5 + (x * -0.25)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / sqrt((0.5d0 + (x * (-0.25d0))))
end function
public static double code(double x) {
return 1.0 / Math.sqrt((0.5 + (x * -0.25)));
}
def code(x): return 1.0 / math.sqrt((0.5 + (x * -0.25)))
function code(x) return Float64(1.0 / sqrt(Float64(0.5 + Float64(x * -0.25)))) end
function tmp = code(x) tmp = 1.0 / sqrt((0.5 + (x * -0.25))); end
code[x_] := N[(1.0 / N[Sqrt[N[(0.5 + N[(x * -0.25), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{0.5 + x \cdot -0.25}}
\end{array}
Initial program 38.6%
*-commutative38.6%
exp-lft-sqr39.6%
difference-of-sqr-140.2%
associate-*r/40.6%
*-inverses100.0%
*-rgt-identity100.0%
+-commutative100.0%
Simplified100.0%
+-commutative100.0%
flip-+39.6%
metadata-eval39.6%
exp-lft-sqr38.6%
*-commutative38.6%
expm1-undefine38.5%
expm1-undefine98.8%
clear-num98.8%
sqrt-div97.9%
metadata-eval97.9%
clear-num97.9%
expm1-undefine38.6%
*-commutative38.6%
exp-lft-sqr38.5%
metadata-eval38.5%
expm1-undefine39.6%
flip-+99.1%
+-commutative99.1%
Applied egg-rr99.1%
Taylor expanded in x around 0 65.0%
*-commutative65.0%
Simplified65.0%
(FPCore (x) :precision binary64 (sqrt (+ x 2.0)))
double code(double x) {
return sqrt((x + 2.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = sqrt((x + 2.0d0))
end function
public static double code(double x) {
return Math.sqrt((x + 2.0));
}
def code(x): return math.sqrt((x + 2.0))
function code(x) return sqrt(Float64(x + 2.0)) end
function tmp = code(x) tmp = sqrt((x + 2.0)); end
code[x_] := N[Sqrt[N[(x + 2.0), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{x + 2}
\end{array}
Initial program 38.6%
*-commutative38.6%
exp-lft-sqr39.6%
difference-of-sqr-140.2%
associate-*r/40.6%
*-inverses100.0%
*-rgt-identity100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 63.1%
Final simplification63.1%
herbie shell --seed 2024179
(FPCore (x)
:name "sqrtexp (problem 3.4.4)"
:precision binary64
(sqrt (/ (- (exp (* 2.0 x)) 1.0) (- (exp x) 1.0))))