
(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 12 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}
t\_m = (fabs.f64 t)
t\_s = (copysign.f64 #s(literal 1 binary64) t)
(FPCore (t_s x l t_m)
:precision binary64
(let* ((t_2 (fma 2.0 (* t_m t_m) (* l l)))
(t_3 (* t_m (sqrt 2.0)))
(t_4 (fma 2.0 (* t_m t_m) (fma l l t_2))))
(*
t_s
(if (<= t_m 4.2e-281)
(* (/ t_m (sqrt (* 2.0 (fma t_m t_m (/ t_2 x))))) (sqrt 2.0))
(if (<= t_m 1.7e-145)
(/ t_3 (fma t_m (sqrt 2.0) (/ (* l l) (* x t_3))))
(if (<= t_m 3e+48)
(/
t_3
(sqrt
(+
(* 2.0 (* t_m t_m))
(/ (+ t_2 (+ t_2 (/ (+ t_4 (/ t_4 x)) x))) x))))
(/ t_3 (* t_m (sqrt (* 2.0 (/ (+ x 1.0) (+ -1.0 x))))))))))))t\_m = fabs(t);
t\_s = copysign(1.0, t);
double code(double t_s, double x, double l, double t_m) {
double t_2 = fma(2.0, (t_m * t_m), (l * l));
double t_3 = t_m * sqrt(2.0);
double t_4 = fma(2.0, (t_m * t_m), fma(l, l, t_2));
double tmp;
if (t_m <= 4.2e-281) {
tmp = (t_m / sqrt((2.0 * fma(t_m, t_m, (t_2 / x))))) * sqrt(2.0);
} else if (t_m <= 1.7e-145) {
tmp = t_3 / fma(t_m, sqrt(2.0), ((l * l) / (x * t_3)));
} else if (t_m <= 3e+48) {
tmp = t_3 / sqrt(((2.0 * (t_m * t_m)) + ((t_2 + (t_2 + ((t_4 + (t_4 / x)) / x))) / x)));
} else {
tmp = t_3 / (t_m * sqrt((2.0 * ((x + 1.0) / (-1.0 + x)))));
}
return t_s * tmp;
}
t\_m = abs(t) t\_s = copysign(1.0, t) function code(t_s, x, l, t_m) t_2 = fma(2.0, Float64(t_m * t_m), Float64(l * l)) t_3 = Float64(t_m * sqrt(2.0)) t_4 = fma(2.0, Float64(t_m * t_m), fma(l, l, t_2)) tmp = 0.0 if (t_m <= 4.2e-281) tmp = Float64(Float64(t_m / sqrt(Float64(2.0 * fma(t_m, t_m, Float64(t_2 / x))))) * sqrt(2.0)); elseif (t_m <= 1.7e-145) tmp = Float64(t_3 / fma(t_m, sqrt(2.0), Float64(Float64(l * l) / Float64(x * t_3)))); elseif (t_m <= 3e+48) tmp = Float64(t_3 / sqrt(Float64(Float64(2.0 * Float64(t_m * t_m)) + Float64(Float64(t_2 + Float64(t_2 + Float64(Float64(t_4 + Float64(t_4 / x)) / x))) / x)))); else tmp = Float64(t_3 / Float64(t_m * sqrt(Float64(2.0 * Float64(Float64(x + 1.0) / Float64(-1.0 + x)))))); end return Float64(t_s * tmp) end
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_, t$95$m_] := Block[{t$95$2 = N[(2.0 * N[(t$95$m * t$95$m), $MachinePrecision] + N[(l * l), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(t$95$m * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[(2.0 * N[(t$95$m * t$95$m), $MachinePrecision] + N[(l * l + t$95$2), $MachinePrecision]), $MachinePrecision]}, N[(t$95$s * If[LessEqual[t$95$m, 4.2e-281], N[(N[(t$95$m / N[Sqrt[N[(2.0 * N[(t$95$m * t$95$m + N[(t$95$2 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$m, 1.7e-145], N[(t$95$3 / N[(t$95$m * N[Sqrt[2.0], $MachinePrecision] + N[(N[(l * l), $MachinePrecision] / N[(x * t$95$3), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$m, 3e+48], N[(t$95$3 / N[Sqrt[N[(N[(2.0 * N[(t$95$m * t$95$m), $MachinePrecision]), $MachinePrecision] + N[(N[(t$95$2 + N[(t$95$2 + N[(N[(t$95$4 + N[(t$95$4 / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(t$95$3 / N[(t$95$m * N[Sqrt[N[(2.0 * N[(N[(x + 1.0), $MachinePrecision] / N[(-1.0 + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]), $MachinePrecision]]]]
\begin{array}{l}
t\_m = \left|t\right|
\\
t\_s = \mathsf{copysign}\left(1, t\right)
\\
\begin{array}{l}
t_2 := \mathsf{fma}\left(2, t\_m \cdot t\_m, \ell \cdot \ell\right)\\
t_3 := t\_m \cdot \sqrt{2}\\
t_4 := \mathsf{fma}\left(2, t\_m \cdot t\_m, \mathsf{fma}\left(\ell, \ell, t\_2\right)\right)\\
t\_s \cdot \begin{array}{l}
\mathbf{if}\;t\_m \leq 4.2 \cdot 10^{-281}:\\
\;\;\;\;\frac{t\_m}{\sqrt{2 \cdot \mathsf{fma}\left(t\_m, t\_m, \frac{t\_2}{x}\right)}} \cdot \sqrt{2}\\
\mathbf{elif}\;t\_m \leq 1.7 \cdot 10^{-145}:\\
\;\;\;\;\frac{t\_3}{\mathsf{fma}\left(t\_m, \sqrt{2}, \frac{\ell \cdot \ell}{x \cdot t\_3}\right)}\\
\mathbf{elif}\;t\_m \leq 3 \cdot 10^{+48}:\\
\;\;\;\;\frac{t\_3}{\sqrt{2 \cdot \left(t\_m \cdot t\_m\right) + \frac{t\_2 + \left(t\_2 + \frac{t\_4 + \frac{t\_4}{x}}{x}\right)}{x}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_3}{t\_m \cdot \sqrt{2 \cdot \frac{x + 1}{-1 + x}}}\\
\end{array}
\end{array}
\end{array}
if t < 4.1999999999999998e-281Initial program 2.0%
lift--.f64N/A
sub-negN/A
lift-*.f64N/A
lift-/.f64N/A
frac-2negN/A
div-invN/A
associate-*l*N/A
lower-fma.f64N/A
Applied rewrites6.0%
Taylor expanded in x around -inf
+-commutativeN/A
mul-1-negN/A
distribute-frac-negN/A
sub-negN/A
mul-1-negN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
sub-negN/A
Applied rewrites99.6%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites100.0%
if 4.1999999999999998e-281 < t < 1.6999999999999999e-145Initial program 6.2%
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-+.f6453.6
Applied rewrites53.6%
Taylor expanded in x around inf
+-commutativeN/A
lower-fma.f64N/A
lower-sqrt.f64N/A
associate-*r/N/A
lower-/.f64N/A
Applied rewrites70.5%
Taylor expanded in t around 0
Applied rewrites70.5%
if 1.6999999999999999e-145 < t < 3e48Initial program 48.4%
lift--.f64N/A
sub-negN/A
lift-*.f64N/A
lift-/.f64N/A
frac-2negN/A
div-invN/A
associate-*l*N/A
lower-fma.f64N/A
Applied rewrites39.0%
Taylor expanded in x around -inf
+-commutativeN/A
mul-1-negN/A
distribute-frac-negN/A
sub-negN/A
mul-1-negN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
sub-negN/A
Applied rewrites80.8%
Taylor expanded in x around -inf
Applied rewrites82.5%
if 3e48 < t Initial program 35.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-+.f6494.8
Applied rewrites94.8%
Applied rewrites94.9%
Final simplification86.9%
t\_m = (fabs.f64 t)
t\_s = (copysign.f64 #s(literal 1 binary64) t)
(FPCore (t_s x l t_m)
:precision binary64
(let* ((t_2 (fma 2.0 (* t_m t_m) (* l l)))
(t_3 (* t_2 -2.0))
(t_4 (* t_m (sqrt 2.0))))
(*
t_s
(if (<= t_m 4.2e-281)
(* (/ t_m (sqrt (* 2.0 (fma t_m t_m (/ t_2 x))))) (sqrt 2.0))
(if (<= t_m 1.7e-145)
(/ t_4 (fma t_m (sqrt 2.0) (/ (* l l) (* x t_4))))
(if (<= t_m 3e+48)
(/
t_4
(sqrt
(- (* 2.0 (* t_m t_m)) (/ (+ t_3 (/ (+ t_3 (/ t_3 x)) x)) x))))
(/ t_4 (* t_m (sqrt (* 2.0 (/ (+ x 1.0) (+ -1.0 x))))))))))))t\_m = fabs(t);
t\_s = copysign(1.0, t);
double code(double t_s, double x, double l, double t_m) {
double t_2 = fma(2.0, (t_m * t_m), (l * l));
double t_3 = t_2 * -2.0;
double t_4 = t_m * sqrt(2.0);
double tmp;
if (t_m <= 4.2e-281) {
tmp = (t_m / sqrt((2.0 * fma(t_m, t_m, (t_2 / x))))) * sqrt(2.0);
} else if (t_m <= 1.7e-145) {
tmp = t_4 / fma(t_m, sqrt(2.0), ((l * l) / (x * t_4)));
} else if (t_m <= 3e+48) {
tmp = t_4 / sqrt(((2.0 * (t_m * t_m)) - ((t_3 + ((t_3 + (t_3 / x)) / x)) / x)));
} else {
tmp = t_4 / (t_m * sqrt((2.0 * ((x + 1.0) / (-1.0 + x)))));
}
return t_s * tmp;
}
t\_m = abs(t) t\_s = copysign(1.0, t) function code(t_s, x, l, t_m) t_2 = fma(2.0, Float64(t_m * t_m), Float64(l * l)) t_3 = Float64(t_2 * -2.0) t_4 = Float64(t_m * sqrt(2.0)) tmp = 0.0 if (t_m <= 4.2e-281) tmp = Float64(Float64(t_m / sqrt(Float64(2.0 * fma(t_m, t_m, Float64(t_2 / x))))) * sqrt(2.0)); elseif (t_m <= 1.7e-145) tmp = Float64(t_4 / fma(t_m, sqrt(2.0), Float64(Float64(l * l) / Float64(x * t_4)))); elseif (t_m <= 3e+48) tmp = Float64(t_4 / sqrt(Float64(Float64(2.0 * Float64(t_m * t_m)) - Float64(Float64(t_3 + Float64(Float64(t_3 + Float64(t_3 / x)) / x)) / x)))); else tmp = Float64(t_4 / Float64(t_m * sqrt(Float64(2.0 * Float64(Float64(x + 1.0) / Float64(-1.0 + x)))))); end return Float64(t_s * tmp) end
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_, t$95$m_] := Block[{t$95$2 = N[(2.0 * N[(t$95$m * t$95$m), $MachinePrecision] + N[(l * l), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(t$95$2 * -2.0), $MachinePrecision]}, Block[{t$95$4 = N[(t$95$m * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]}, N[(t$95$s * If[LessEqual[t$95$m, 4.2e-281], N[(N[(t$95$m / N[Sqrt[N[(2.0 * N[(t$95$m * t$95$m + N[(t$95$2 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$m, 1.7e-145], N[(t$95$4 / N[(t$95$m * N[Sqrt[2.0], $MachinePrecision] + N[(N[(l * l), $MachinePrecision] / N[(x * t$95$4), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$m, 3e+48], N[(t$95$4 / N[Sqrt[N[(N[(2.0 * N[(t$95$m * t$95$m), $MachinePrecision]), $MachinePrecision] - N[(N[(t$95$3 + N[(N[(t$95$3 + N[(t$95$3 / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(t$95$4 / N[(t$95$m * N[Sqrt[N[(2.0 * N[(N[(x + 1.0), $MachinePrecision] / N[(-1.0 + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]), $MachinePrecision]]]]
\begin{array}{l}
t\_m = \left|t\right|
\\
t\_s = \mathsf{copysign}\left(1, t\right)
\\
\begin{array}{l}
t_2 := \mathsf{fma}\left(2, t\_m \cdot t\_m, \ell \cdot \ell\right)\\
t_3 := t\_2 \cdot -2\\
t_4 := t\_m \cdot \sqrt{2}\\
t\_s \cdot \begin{array}{l}
\mathbf{if}\;t\_m \leq 4.2 \cdot 10^{-281}:\\
\;\;\;\;\frac{t\_m}{\sqrt{2 \cdot \mathsf{fma}\left(t\_m, t\_m, \frac{t\_2}{x}\right)}} \cdot \sqrt{2}\\
\mathbf{elif}\;t\_m \leq 1.7 \cdot 10^{-145}:\\
\;\;\;\;\frac{t\_4}{\mathsf{fma}\left(t\_m, \sqrt{2}, \frac{\ell \cdot \ell}{x \cdot t\_4}\right)}\\
\mathbf{elif}\;t\_m \leq 3 \cdot 10^{+48}:\\
\;\;\;\;\frac{t\_4}{\sqrt{2 \cdot \left(t\_m \cdot t\_m\right) - \frac{t\_3 + \frac{t\_3 + \frac{t\_3}{x}}{x}}{x}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_4}{t\_m \cdot \sqrt{2 \cdot \frac{x + 1}{-1 + x}}}\\
\end{array}
\end{array}
\end{array}
if t < 4.1999999999999998e-281Initial program 4.0%
lift--.f64N/A
sub-negN/A
lift-*.f64N/A
lift-/.f64N/A
frac-2negN/A
div-invN/A
associate-*l*N/A
lower-fma.f64N/A
Applied rewrites9.1%
Taylor expanded in x around -inf
+-commutativeN/A
mul-1-negN/A
distribute-frac-negN/A
sub-negN/A
mul-1-negN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
sub-negN/A
Applied rewrites56.0%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites55.9%
if 4.1999999999999998e-281 < t < 1.6999999999999999e-145Initial program 7.8%
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-+.f6446.8
Applied rewrites46.8%
Taylor expanded in x around inf
+-commutativeN/A
lower-fma.f64N/A
lower-sqrt.f64N/A
associate-*r/N/A
lower-/.f64N/A
Applied rewrites62.1%
Taylor expanded in t around 0
Applied rewrites62.0%
if 1.6999999999999999e-145 < t < 3e48Initial program 55.6%
lift--.f64N/A
sub-negN/A
lift-*.f64N/A
lift-/.f64N/A
frac-2negN/A
div-invN/A
associate-*l*N/A
lower-fma.f64N/A
Applied rewrites41.6%
Taylor expanded in x around -inf
Applied rewrites84.8%
if 3e48 < t Initial program 29.6%
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-+.f6493.7
Applied rewrites93.7%
Applied rewrites93.7%
Final simplification84.2%
herbie shell --seed 2024226
(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)))))