
(FPCore (x l t) :precision binary64 (/ (* (sqrt 2.0) t) (sqrt (- (* (/ (+ x 1.0) (- x 1.0)) (+ (* l l) (* 2.0 (* t t)))) (* l l)))))
double code(double x, double l, double t) {
return (sqrt(2.0) * t) / sqrt(((((x + 1.0) / (x - 1.0)) * ((l * l) + (2.0 * (t * t)))) - (l * l)));
}
real(8) function code(x, l, t)
real(8), intent (in) :: x
real(8), intent (in) :: l
real(8), intent (in) :: t
code = (sqrt(2.0d0) * t) / sqrt(((((x + 1.0d0) / (x - 1.0d0)) * ((l * l) + (2.0d0 * (t * t)))) - (l * l)))
end function
public static double code(double x, double l, double t) {
return (Math.sqrt(2.0) * t) / Math.sqrt(((((x + 1.0) / (x - 1.0)) * ((l * l) + (2.0 * (t * t)))) - (l * l)));
}
def code(x, l, t): return (math.sqrt(2.0) * t) / math.sqrt(((((x + 1.0) / (x - 1.0)) * ((l * l) + (2.0 * (t * t)))) - (l * l)))
function code(x, l, t) return Float64(Float64(sqrt(2.0) * t) / sqrt(Float64(Float64(Float64(Float64(x + 1.0) / Float64(x - 1.0)) * Float64(Float64(l * l) + Float64(2.0 * Float64(t * t)))) - Float64(l * l)))) end
function tmp = code(x, l, t) tmp = (sqrt(2.0) * t) / sqrt(((((x + 1.0) / (x - 1.0)) * ((l * l) + (2.0 * (t * t)))) - (l * l))); end
code[x_, l_, t_] := N[(N[(N[Sqrt[2.0], $MachinePrecision] * t), $MachinePrecision] / N[Sqrt[N[(N[(N[(N[(x + 1.0), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision] * N[(N[(l * l), $MachinePrecision] + N[(2.0 * N[(t * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(l * l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt{2} \cdot t}{\sqrt{\frac{x + 1}{x - 1} \cdot \left(\ell \cdot \ell + 2 \cdot \left(t \cdot t\right)\right) - \ell \cdot \ell}}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x l t) :precision binary64 (/ (* (sqrt 2.0) t) (sqrt (- (* (/ (+ x 1.0) (- x 1.0)) (+ (* l l) (* 2.0 (* t t)))) (* l l)))))
double code(double x, double l, double t) {
return (sqrt(2.0) * t) / sqrt(((((x + 1.0) / (x - 1.0)) * ((l * l) + (2.0 * (t * t)))) - (l * l)));
}
real(8) function code(x, l, t)
real(8), intent (in) :: x
real(8), intent (in) :: l
real(8), intent (in) :: t
code = (sqrt(2.0d0) * t) / sqrt(((((x + 1.0d0) / (x - 1.0d0)) * ((l * l) + (2.0d0 * (t * t)))) - (l * l)))
end function
public static double code(double x, double l, double t) {
return (Math.sqrt(2.0) * t) / Math.sqrt(((((x + 1.0) / (x - 1.0)) * ((l * l) + (2.0 * (t * t)))) - (l * l)));
}
def code(x, l, t): return (math.sqrt(2.0) * t) / math.sqrt(((((x + 1.0) / (x - 1.0)) * ((l * l) + (2.0 * (t * t)))) - (l * l)))
function code(x, l, t) return Float64(Float64(sqrt(2.0) * t) / sqrt(Float64(Float64(Float64(Float64(x + 1.0) / Float64(x - 1.0)) * Float64(Float64(l * l) + Float64(2.0 * Float64(t * t)))) - Float64(l * l)))) end
function tmp = code(x, l, t) tmp = (sqrt(2.0) * t) / sqrt(((((x + 1.0) / (x - 1.0)) * ((l * l) + (2.0 * (t * t)))) - (l * l))); end
code[x_, l_, t_] := N[(N[(N[Sqrt[2.0], $MachinePrecision] * t), $MachinePrecision] / N[Sqrt[N[(N[(N[(N[(x + 1.0), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision] * N[(N[(l * l), $MachinePrecision] + N[(2.0 * N[(t * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(l * l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt{2} \cdot t}{\sqrt{\frac{x + 1}{x - 1} \cdot \left(\ell \cdot \ell + 2 \cdot \left(t \cdot t\right)\right) - \ell \cdot \ell}}
\end{array}
l_m = (fabs.f64 l)
t\_m = (fabs.f64 t)
t\_s = (copysign.f64 #s(literal 1 binary64) t)
(FPCore (t_s x l_m t_m)
:precision binary64
(let* ((t_2 (* t_m (sqrt 2.0))) (t_3 (fma 2.0 (* t_m t_m) (* l_m l_m))))
(*
t_s
(if (<= t_m 5.5e-236)
(/ t_2 (* l_m (sqrt (/ 2.0 x))))
(if (<= t_m 7.5e-155)
(/ t_2 (fma 0.5 (/ (* 2.0 t_3) (* t_2 x)) t_2))
(if (<= t_m 8e-9)
(*
t_m
(sqrt
(/
2.0
(+
(fma
2.0
(/ (* t_m t_m) x)
(fma 2.0 (* t_m t_m) (/ (* l_m l_m) x)))
(/ t_3 x)))))
(sqrt (/ (+ x -1.0) (+ x 1.0)))))))))l_m = fabs(l);
t\_m = fabs(t);
t\_s = copysign(1.0, t);
double code(double t_s, double x, double l_m, double t_m) {
double t_2 = t_m * sqrt(2.0);
double t_3 = fma(2.0, (t_m * t_m), (l_m * l_m));
double tmp;
if (t_m <= 5.5e-236) {
tmp = t_2 / (l_m * sqrt((2.0 / x)));
} else if (t_m <= 7.5e-155) {
tmp = t_2 / fma(0.5, ((2.0 * t_3) / (t_2 * x)), t_2);
} else if (t_m <= 8e-9) {
tmp = t_m * sqrt((2.0 / (fma(2.0, ((t_m * t_m) / x), fma(2.0, (t_m * t_m), ((l_m * l_m) / x))) + (t_3 / x))));
} else {
tmp = sqrt(((x + -1.0) / (x + 1.0)));
}
return t_s * tmp;
}
l_m = abs(l) t\_m = abs(t) t\_s = copysign(1.0, t) function code(t_s, x, l_m, t_m) t_2 = Float64(t_m * sqrt(2.0)) t_3 = fma(2.0, Float64(t_m * t_m), Float64(l_m * l_m)) tmp = 0.0 if (t_m <= 5.5e-236) tmp = Float64(t_2 / Float64(l_m * sqrt(Float64(2.0 / x)))); elseif (t_m <= 7.5e-155) tmp = Float64(t_2 / fma(0.5, Float64(Float64(2.0 * t_3) / Float64(t_2 * x)), t_2)); elseif (t_m <= 8e-9) tmp = Float64(t_m * sqrt(Float64(2.0 / Float64(fma(2.0, Float64(Float64(t_m * t_m) / x), fma(2.0, Float64(t_m * t_m), Float64(Float64(l_m * l_m) / x))) + Float64(t_3 / x))))); else tmp = sqrt(Float64(Float64(x + -1.0) / Float64(x + 1.0))); end return Float64(t_s * tmp) end
l_m = N[Abs[l], $MachinePrecision]
t\_m = N[Abs[t], $MachinePrecision]
t\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[t]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[t$95$s_, x_, l$95$m_, t$95$m_] := Block[{t$95$2 = N[(t$95$m * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(2.0 * N[(t$95$m * t$95$m), $MachinePrecision] + N[(l$95$m * l$95$m), $MachinePrecision]), $MachinePrecision]}, N[(t$95$s * If[LessEqual[t$95$m, 5.5e-236], N[(t$95$2 / N[(l$95$m * N[Sqrt[N[(2.0 / x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$m, 7.5e-155], N[(t$95$2 / N[(0.5 * N[(N[(2.0 * t$95$3), $MachinePrecision] / N[(t$95$2 * x), $MachinePrecision]), $MachinePrecision] + t$95$2), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$m, 8e-9], N[(t$95$m * N[Sqrt[N[(2.0 / N[(N[(2.0 * N[(N[(t$95$m * t$95$m), $MachinePrecision] / x), $MachinePrecision] + N[(2.0 * N[(t$95$m * t$95$m), $MachinePrecision] + N[(N[(l$95$m * l$95$m), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(t$95$3 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(N[(x + -1.0), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]]), $MachinePrecision]]]
\begin{array}{l}
l_m = \left|\ell\right|
\\
t\_m = \left|t\right|
\\
t\_s = \mathsf{copysign}\left(1, t\right)
\\
\begin{array}{l}
t_2 := t\_m \cdot \sqrt{2}\\
t_3 := \mathsf{fma}\left(2, t\_m \cdot t\_m, l\_m \cdot l\_m\right)\\
t\_s \cdot \begin{array}{l}
\mathbf{if}\;t\_m \leq 5.5 \cdot 10^{-236}:\\
\;\;\;\;\frac{t\_2}{l\_m \cdot \sqrt{\frac{2}{x}}}\\
\mathbf{elif}\;t\_m \leq 7.5 \cdot 10^{-155}:\\
\;\;\;\;\frac{t\_2}{\mathsf{fma}\left(0.5, \frac{2 \cdot t\_3}{t\_2 \cdot x}, t\_2\right)}\\
\mathbf{elif}\;t\_m \leq 8 \cdot 10^{-9}:\\
\;\;\;\;t\_m \cdot \sqrt{\frac{2}{\mathsf{fma}\left(2, \frac{t\_m \cdot t\_m}{x}, \mathsf{fma}\left(2, t\_m \cdot t\_m, \frac{l\_m \cdot l\_m}{x}\right)\right) + \frac{t\_3}{x}}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{x + -1}{x + 1}}\\
\end{array}
\end{array}
\end{array}
if t < 5.49999999999999959e-236Initial program 6.3%
Taylor expanded in l around inf
lower-*.f64N/A
lower-sqrt.f64N/A
sub-negN/A
+-commutativeN/A
metadata-evalN/A
associate-+l+N/A
lower-+.f64N/A
lower-/.f64N/A
sub-negN/A
metadata-evalN/A
lower-+.f64N/A
lower-+.f64N/A
lower-/.f64N/A
sub-negN/A
metadata-evalN/A
lower-+.f6411.5
Applied rewrites11.5%
Taylor expanded in x around inf
Applied rewrites80.8%
if 5.49999999999999959e-236 < t < 7.5000000000000006e-155Initial program 3.6%
Taylor expanded in x around inf
lower-fma.f64N/A
Applied rewrites73.2%
if 7.5000000000000006e-155 < t < 8.0000000000000005e-9Initial program 52.8%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
sqrt-undivN/A
lower-sqrt.f64N/A
lower-/.f6453.0
lift--.f64N/A
Applied rewrites53.0%
Taylor expanded in x around inf
sub-negN/A
mul-1-negN/A
remove-double-negN/A
lower-+.f64N/A
lower-fma.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
Applied rewrites77.5%
if 8.0000000000000005e-9 < t Initial program 37.0%
Taylor expanded in l around 0
lower-*.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-+.f64N/A
sub-negN/A
metadata-evalN/A
lower-+.f6492.7
Applied rewrites92.7%
Applied rewrites92.7%
Taylor expanded in t around inf
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
sub-negN/A
metadata-evalN/A
lower-+.f64N/A
+-commutativeN/A
lower-+.f6491.3
Applied rewrites91.3%
Applied rewrites92.8%
Final simplification85.7%
l_m = (fabs.f64 l)
t\_m = (fabs.f64 t)
t\_s = (copysign.f64 #s(literal 1 binary64) t)
(FPCore (t_s x l_m t_m)
:precision binary64
(let* ((t_2 (* t_m (sqrt 2.0))) (t_3 (fma 2.0 (* t_m t_m) (* l_m l_m))))
(*
t_s
(if (<= t_m 5.5e-236)
(/ t_2 (* l_m (sqrt (/ 2.0 x))))
(if (<= t_m 3.4e-157)
(/ t_2 (fma 0.5 (/ (* 2.0 t_3) (* t_2 x)) t_2))
(if (<= t_m 2.75e-17)
(/ t_2 (sqrt (* 2.0 (+ (* t_m t_m) (/ t_3 x)))))
(sqrt (/ (+ x -1.0) (+ x 1.0)))))))))l_m = fabs(l);
t\_m = fabs(t);
t\_s = copysign(1.0, t);
double code(double t_s, double x, double l_m, double t_m) {
double t_2 = t_m * sqrt(2.0);
double t_3 = fma(2.0, (t_m * t_m), (l_m * l_m));
double tmp;
if (t_m <= 5.5e-236) {
tmp = t_2 / (l_m * sqrt((2.0 / x)));
} else if (t_m <= 3.4e-157) {
tmp = t_2 / fma(0.5, ((2.0 * t_3) / (t_2 * x)), t_2);
} else if (t_m <= 2.75e-17) {
tmp = t_2 / sqrt((2.0 * ((t_m * t_m) + (t_3 / x))));
} else {
tmp = sqrt(((x + -1.0) / (x + 1.0)));
}
return t_s * tmp;
}
l_m = abs(l) t\_m = abs(t) t\_s = copysign(1.0, t) function code(t_s, x, l_m, t_m) t_2 = Float64(t_m * sqrt(2.0)) t_3 = fma(2.0, Float64(t_m * t_m), Float64(l_m * l_m)) tmp = 0.0 if (t_m <= 5.5e-236) tmp = Float64(t_2 / Float64(l_m * sqrt(Float64(2.0 / x)))); elseif (t_m <= 3.4e-157) tmp = Float64(t_2 / fma(0.5, Float64(Float64(2.0 * t_3) / Float64(t_2 * x)), t_2)); elseif (t_m <= 2.75e-17) tmp = Float64(t_2 / sqrt(Float64(2.0 * Float64(Float64(t_m * t_m) + Float64(t_3 / x))))); else tmp = sqrt(Float64(Float64(x + -1.0) / Float64(x + 1.0))); end return Float64(t_s * tmp) end
l_m = N[Abs[l], $MachinePrecision]
t\_m = N[Abs[t], $MachinePrecision]
t\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[t]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[t$95$s_, x_, l$95$m_, t$95$m_] := Block[{t$95$2 = N[(t$95$m * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(2.0 * N[(t$95$m * t$95$m), $MachinePrecision] + N[(l$95$m * l$95$m), $MachinePrecision]), $MachinePrecision]}, N[(t$95$s * If[LessEqual[t$95$m, 5.5e-236], N[(t$95$2 / N[(l$95$m * N[Sqrt[N[(2.0 / x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$m, 3.4e-157], N[(t$95$2 / N[(0.5 * N[(N[(2.0 * t$95$3), $MachinePrecision] / N[(t$95$2 * x), $MachinePrecision]), $MachinePrecision] + t$95$2), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$m, 2.75e-17], N[(t$95$2 / N[Sqrt[N[(2.0 * N[(N[(t$95$m * t$95$m), $MachinePrecision] + N[(t$95$3 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(N[(x + -1.0), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]]), $MachinePrecision]]]
\begin{array}{l}
l_m = \left|\ell\right|
\\
t\_m = \left|t\right|
\\
t\_s = \mathsf{copysign}\left(1, t\right)
\\
\begin{array}{l}
t_2 := t\_m \cdot \sqrt{2}\\
t_3 := \mathsf{fma}\left(2, t\_m \cdot t\_m, l\_m \cdot l\_m\right)\\
t\_s \cdot \begin{array}{l}
\mathbf{if}\;t\_m \leq 5.5 \cdot 10^{-236}:\\
\;\;\;\;\frac{t\_2}{l\_m \cdot \sqrt{\frac{2}{x}}}\\
\mathbf{elif}\;t\_m \leq 3.4 \cdot 10^{-157}:\\
\;\;\;\;\frac{t\_2}{\mathsf{fma}\left(0.5, \frac{2 \cdot t\_3}{t\_2 \cdot x}, t\_2\right)}\\
\mathbf{elif}\;t\_m \leq 2.75 \cdot 10^{-17}:\\
\;\;\;\;\frac{t\_2}{\sqrt{2 \cdot \left(t\_m \cdot t\_m + \frac{t\_3}{x}\right)}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{x + -1}{x + 1}}\\
\end{array}
\end{array}
\end{array}
if t < 5.49999999999999959e-236Initial program 3.7%
Taylor expanded in l around inf
lower-*.f64N/A
lower-sqrt.f64N/A
sub-negN/A
+-commutativeN/A
metadata-evalN/A
associate-+l+N/A
lower-+.f64N/A
lower-/.f64N/A
sub-negN/A
metadata-evalN/A
lower-+.f64N/A
lower-+.f64N/A
lower-/.f64N/A
sub-negN/A
metadata-evalN/A
lower-+.f646.4
Applied rewrites6.4%
Taylor expanded in x around inf
Applied rewrites71.6%
if 5.49999999999999959e-236 < t < 3.39999999999999977e-157Initial program 4.2%
Taylor expanded in x around inf
lower-fma.f64N/A
Applied rewrites67.4%
if 3.39999999999999977e-157 < t < 2.75e-17Initial program 51.2%
Applied rewrites14.6%
Taylor expanded in x around inf
distribute-lft-outN/A
lower-*.f64N/A
lower-+.f64N/A
lower-/.f64N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6486.2
Applied rewrites86.2%
if 2.75e-17 < t Initial program 36.5%
Taylor expanded in l around 0
lower-*.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-+.f64N/A
sub-negN/A
metadata-evalN/A
lower-+.f6491.5
Applied rewrites91.5%
Applied rewrites91.5%
Taylor expanded in t around inf
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
sub-negN/A
metadata-evalN/A
lower-+.f64N/A
+-commutativeN/A
lower-+.f6490.1
Applied rewrites90.1%
Applied rewrites91.5%
Final simplification86.2%
herbie shell --seed 2024222
(FPCore (x l t)
:name "Toniolo and Linder, Equation (7)"
:precision binary64
(/ (* (sqrt 2.0) t) (sqrt (- (* (/ (+ x 1.0) (- x 1.0)) (+ (* l l) (* 2.0 (* t t)))) (* l l)))))