
(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 3 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.1%
*-commutativeN/A
exp-lft-sqrN/A
difference-of-sqr-1N/A
associate-*r/N/A
*-inversesN/A
*-rgt-identityN/A
sqrt-lowering-sqrt.f64N/A
+-commutativeN/A
+-lowering-+.f64N/A
exp-lowering-exp.f64100.0%
Simplified100.0%
(FPCore (x) :precision binary64 (let* ((t_0 (* x (+ 0.5 (* x 0.16666666666666666))))) (sqrt (+ 2.0 (* x (/ 1.0 (+ 1.0 (* t_0 (+ t_0 -1.0)))))))))
double code(double x) {
double t_0 = x * (0.5 + (x * 0.16666666666666666));
return sqrt((2.0 + (x * (1.0 / (1.0 + (t_0 * (t_0 + -1.0)))))));
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
t_0 = x * (0.5d0 + (x * 0.16666666666666666d0))
code = sqrt((2.0d0 + (x * (1.0d0 / (1.0d0 + (t_0 * (t_0 + (-1.0d0))))))))
end function
public static double code(double x) {
double t_0 = x * (0.5 + (x * 0.16666666666666666));
return Math.sqrt((2.0 + (x * (1.0 / (1.0 + (t_0 * (t_0 + -1.0)))))));
}
def code(x): t_0 = x * (0.5 + (x * 0.16666666666666666)) return math.sqrt((2.0 + (x * (1.0 / (1.0 + (t_0 * (t_0 + -1.0)))))))
function code(x) t_0 = Float64(x * Float64(0.5 + Float64(x * 0.16666666666666666))) return sqrt(Float64(2.0 + Float64(x * Float64(1.0 / Float64(1.0 + Float64(t_0 * Float64(t_0 + -1.0))))))) end
function tmp = code(x) t_0 = x * (0.5 + (x * 0.16666666666666666)); tmp = sqrt((2.0 + (x * (1.0 / (1.0 + (t_0 * (t_0 + -1.0))))))); end
code[x_] := Block[{t$95$0 = N[(x * N[(0.5 + N[(x * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[Sqrt[N[(2.0 + N[(x * N[(1.0 / N[(1.0 + N[(t$95$0 * N[(t$95$0 + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(0.5 + x \cdot 0.16666666666666666\right)\\
\sqrt{2 + x \cdot \frac{1}{1 + t\_0 \cdot \left(t\_0 + -1\right)}}
\end{array}
\end{array}
Initial program 36.1%
*-commutativeN/A
exp-lft-sqrN/A
difference-of-sqr-1N/A
associate-*r/N/A
*-inversesN/A
*-rgt-identityN/A
sqrt-lowering-sqrt.f64N/A
+-commutativeN/A
+-lowering-+.f64N/A
exp-lowering-exp.f64100.0%
Simplified100.0%
Taylor expanded in x around 0
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6464.4%
Simplified64.4%
*-commutativeN/A
flip3-+N/A
associate-*l/N/A
div-invN/A
*-lowering-*.f64N/A
Applied egg-rr64.4%
Taylor expanded in x around 0
Simplified71.2%
Final simplification71.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.1%
*-commutativeN/A
exp-lft-sqrN/A
difference-of-sqr-1N/A
associate-*r/N/A
*-inversesN/A
*-rgt-identityN/A
sqrt-lowering-sqrt.f64N/A
+-commutativeN/A
+-lowering-+.f64N/A
exp-lowering-exp.f64100.0%
Simplified100.0%
Taylor expanded in x around 0
sqrt-lowering-sqrt.f6470.4%
Simplified70.4%
herbie shell --seed 2024152
(FPCore (x)
:name "sqrtexp (problem 3.4.4)"
:precision binary64
(sqrt (/ (- (exp (* 2.0 x)) 1.0) (- (exp x) 1.0))))