
(FPCore (t l Om Omc) :precision binary64 (asin (sqrt (/ (- 1.0 (pow (/ Om Omc) 2.0)) (+ 1.0 (* 2.0 (pow (/ t l) 2.0)))))))
double code(double t, double l, double Om, double Omc) {
return asin(sqrt(((1.0 - pow((Om / Omc), 2.0)) / (1.0 + (2.0 * pow((t / l), 2.0))))));
}
real(8) function code(t, l, om, omc)
real(8), intent (in) :: t
real(8), intent (in) :: l
real(8), intent (in) :: om
real(8), intent (in) :: omc
code = asin(sqrt(((1.0d0 - ((om / omc) ** 2.0d0)) / (1.0d0 + (2.0d0 * ((t / l) ** 2.0d0))))))
end function
public static double code(double t, double l, double Om, double Omc) {
return Math.asin(Math.sqrt(((1.0 - Math.pow((Om / Omc), 2.0)) / (1.0 + (2.0 * Math.pow((t / l), 2.0))))));
}
def code(t, l, Om, Omc): return math.asin(math.sqrt(((1.0 - math.pow((Om / Omc), 2.0)) / (1.0 + (2.0 * math.pow((t / l), 2.0))))))
function code(t, l, Om, Omc) return asin(sqrt(Float64(Float64(1.0 - (Float64(Om / Omc) ^ 2.0)) / Float64(1.0 + Float64(2.0 * (Float64(t / l) ^ 2.0)))))) end
function tmp = code(t, l, Om, Omc) tmp = asin(sqrt(((1.0 - ((Om / Omc) ^ 2.0)) / (1.0 + (2.0 * ((t / l) ^ 2.0)))))); end
code[t_, l_, Om_, Omc_] := N[ArcSin[N[Sqrt[N[(N[(1.0 - N[Power[N[(Om / Omc), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / N[(1.0 + N[(2.0 * N[Power[N[(t / l), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sin^{-1} \left(\sqrt{\frac{1 - {\left(\frac{Om}{Omc}\right)}^{2}}{1 + 2 \cdot {\left(\frac{t}{\ell}\right)}^{2}}}\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (t l Om Omc) :precision binary64 (asin (sqrt (/ (- 1.0 (pow (/ Om Omc) 2.0)) (+ 1.0 (* 2.0 (pow (/ t l) 2.0)))))))
double code(double t, double l, double Om, double Omc) {
return asin(sqrt(((1.0 - pow((Om / Omc), 2.0)) / (1.0 + (2.0 * pow((t / l), 2.0))))));
}
real(8) function code(t, l, om, omc)
real(8), intent (in) :: t
real(8), intent (in) :: l
real(8), intent (in) :: om
real(8), intent (in) :: omc
code = asin(sqrt(((1.0d0 - ((om / omc) ** 2.0d0)) / (1.0d0 + (2.0d0 * ((t / l) ** 2.0d0))))))
end function
public static double code(double t, double l, double Om, double Omc) {
return Math.asin(Math.sqrt(((1.0 - Math.pow((Om / Omc), 2.0)) / (1.0 + (2.0 * Math.pow((t / l), 2.0))))));
}
def code(t, l, Om, Omc): return math.asin(math.sqrt(((1.0 - math.pow((Om / Omc), 2.0)) / (1.0 + (2.0 * math.pow((t / l), 2.0))))))
function code(t, l, Om, Omc) return asin(sqrt(Float64(Float64(1.0 - (Float64(Om / Omc) ^ 2.0)) / Float64(1.0 + Float64(2.0 * (Float64(t / l) ^ 2.0)))))) end
function tmp = code(t, l, Om, Omc) tmp = asin(sqrt(((1.0 - ((Om / Omc) ^ 2.0)) / (1.0 + (2.0 * ((t / l) ^ 2.0)))))); end
code[t_, l_, Om_, Omc_] := N[ArcSin[N[Sqrt[N[(N[(1.0 - N[Power[N[(Om / Omc), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / N[(1.0 + N[(2.0 * N[Power[N[(t / l), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sin^{-1} \left(\sqrt{\frac{1 - {\left(\frac{Om}{Omc}\right)}^{2}}{1 + 2 \cdot {\left(\frac{t}{\ell}\right)}^{2}}}\right)
\end{array}
l_m = (fabs.f64 l)
t_m = (fabs.f64 t)
(FPCore (t_m l_m Om Omc)
:precision binary64
(if (<= (/ t_m l_m) 5e+147)
(asin
(sqrt
(/ (- 1.0 (pow (/ Om Omc) 2.0)) (+ 1.0 (* 2.0 (pow (/ t_m l_m) 2.0))))))
(asin
(*
l_m
(fma
-0.125
(/ (* l_m l_m) (* (* t_m (* t_m t_m)) (sqrt 0.5)))
(/ (sqrt 0.5) t_m))))))l_m = fabs(l);
t_m = fabs(t);
double code(double t_m, double l_m, double Om, double Omc) {
double tmp;
if ((t_m / l_m) <= 5e+147) {
tmp = asin(sqrt(((1.0 - pow((Om / Omc), 2.0)) / (1.0 + (2.0 * pow((t_m / l_m), 2.0))))));
} else {
tmp = asin((l_m * fma(-0.125, ((l_m * l_m) / ((t_m * (t_m * t_m)) * sqrt(0.5))), (sqrt(0.5) / t_m))));
}
return tmp;
}
l_m = abs(l) t_m = abs(t) function code(t_m, l_m, Om, Omc) tmp = 0.0 if (Float64(t_m / l_m) <= 5e+147) tmp = asin(sqrt(Float64(Float64(1.0 - (Float64(Om / Omc) ^ 2.0)) / Float64(1.0 + Float64(2.0 * (Float64(t_m / l_m) ^ 2.0)))))); else tmp = asin(Float64(l_m * fma(-0.125, Float64(Float64(l_m * l_m) / Float64(Float64(t_m * Float64(t_m * t_m)) * sqrt(0.5))), Float64(sqrt(0.5) / t_m)))); end return tmp end
l_m = N[Abs[l], $MachinePrecision] t_m = N[Abs[t], $MachinePrecision] code[t$95$m_, l$95$m_, Om_, Omc_] := If[LessEqual[N[(t$95$m / l$95$m), $MachinePrecision], 5e+147], N[ArcSin[N[Sqrt[N[(N[(1.0 - N[Power[N[(Om / Omc), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / N[(1.0 + N[(2.0 * N[Power[N[(t$95$m / l$95$m), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision], N[ArcSin[N[(l$95$m * N[(-0.125 * N[(N[(l$95$m * l$95$m), $MachinePrecision] / N[(N[(t$95$m * N[(t$95$m * t$95$m), $MachinePrecision]), $MachinePrecision] * N[Sqrt[0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Sqrt[0.5], $MachinePrecision] / t$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
l_m = \left|\ell\right|
\\
t_m = \left|t\right|
\\
\begin{array}{l}
\mathbf{if}\;\frac{t\_m}{l\_m} \leq 5 \cdot 10^{+147}:\\
\;\;\;\;\sin^{-1} \left(\sqrt{\frac{1 - {\left(\frac{Om}{Omc}\right)}^{2}}{1 + 2 \cdot {\left(\frac{t\_m}{l\_m}\right)}^{2}}}\right)\\
\mathbf{else}:\\
\;\;\;\;\sin^{-1} \left(l\_m \cdot \mathsf{fma}\left(-0.125, \frac{l\_m \cdot l\_m}{\left(t\_m \cdot \left(t\_m \cdot t\_m\right)\right) \cdot \sqrt{0.5}}, \frac{\sqrt{0.5}}{t\_m}\right)\right)\\
\end{array}
\end{array}
if (/.f64 t l) < 5.0000000000000002e147Initial program 98.1%
if 5.0000000000000002e147 < (/.f64 t l) Initial program 44.9%
Taylor expanded in l around 0
Simplified90.4%
Taylor expanded in Om around 0
lower-fma.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
lower-*.f64N/A
cube-multN/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-sqrt.f6499.7
Simplified99.7%
l_m = (fabs.f64 l)
t_m = (fabs.f64 t)
(FPCore (t_m l_m Om Omc)
:precision binary64
(let* ((t_1 (sqrt (/ t_m l_m))))
(if (<= (/ t_m l_m) 5e+147)
(asin
(sqrt
(/
(- 1.0 (pow (/ Om Omc) 2.0))
(fma (* (* (/ t_m l_m) 2.0) t_1) t_1 1.0))))
(asin
(*
l_m
(fma
-0.125
(/ (* l_m l_m) (* (* t_m (* t_m t_m)) (sqrt 0.5)))
(/ (sqrt 0.5) t_m)))))))l_m = fabs(l);
t_m = fabs(t);
double code(double t_m, double l_m, double Om, double Omc) {
double t_1 = sqrt((t_m / l_m));
double tmp;
if ((t_m / l_m) <= 5e+147) {
tmp = asin(sqrt(((1.0 - pow((Om / Omc), 2.0)) / fma((((t_m / l_m) * 2.0) * t_1), t_1, 1.0))));
} else {
tmp = asin((l_m * fma(-0.125, ((l_m * l_m) / ((t_m * (t_m * t_m)) * sqrt(0.5))), (sqrt(0.5) / t_m))));
}
return tmp;
}
l_m = abs(l) t_m = abs(t) function code(t_m, l_m, Om, Omc) t_1 = sqrt(Float64(t_m / l_m)) tmp = 0.0 if (Float64(t_m / l_m) <= 5e+147) tmp = asin(sqrt(Float64(Float64(1.0 - (Float64(Om / Omc) ^ 2.0)) / fma(Float64(Float64(Float64(t_m / l_m) * 2.0) * t_1), t_1, 1.0)))); else tmp = asin(Float64(l_m * fma(-0.125, Float64(Float64(l_m * l_m) / Float64(Float64(t_m * Float64(t_m * t_m)) * sqrt(0.5))), Float64(sqrt(0.5) / t_m)))); end return tmp end
l_m = N[Abs[l], $MachinePrecision]
t_m = N[Abs[t], $MachinePrecision]
code[t$95$m_, l$95$m_, Om_, Omc_] := Block[{t$95$1 = N[Sqrt[N[(t$95$m / l$95$m), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(t$95$m / l$95$m), $MachinePrecision], 5e+147], N[ArcSin[N[Sqrt[N[(N[(1.0 - N[Power[N[(Om / Omc), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / N[(N[(N[(N[(t$95$m / l$95$m), $MachinePrecision] * 2.0), $MachinePrecision] * t$95$1), $MachinePrecision] * t$95$1 + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision], N[ArcSin[N[(l$95$m * N[(-0.125 * N[(N[(l$95$m * l$95$m), $MachinePrecision] / N[(N[(t$95$m * N[(t$95$m * t$95$m), $MachinePrecision]), $MachinePrecision] * N[Sqrt[0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Sqrt[0.5], $MachinePrecision] / t$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
l_m = \left|\ell\right|
\\
t_m = \left|t\right|
\\
\begin{array}{l}
t_1 := \sqrt{\frac{t\_m}{l\_m}}\\
\mathbf{if}\;\frac{t\_m}{l\_m} \leq 5 \cdot 10^{+147}:\\
\;\;\;\;\sin^{-1} \left(\sqrt{\frac{1 - {\left(\frac{Om}{Omc}\right)}^{2}}{\mathsf{fma}\left(\left(\frac{t\_m}{l\_m} \cdot 2\right) \cdot t\_1, t\_1, 1\right)}}\right)\\
\mathbf{else}:\\
\;\;\;\;\sin^{-1} \left(l\_m \cdot \mathsf{fma}\left(-0.125, \frac{l\_m \cdot l\_m}{\left(t\_m \cdot \left(t\_m \cdot t\_m\right)\right) \cdot \sqrt{0.5}}, \frac{\sqrt{0.5}}{t\_m}\right)\right)\\
\end{array}
\end{array}
if (/.f64 t l) < 5.0000000000000002e147Initial program 98.7%
lift-/.f64N/A
lift-pow.f64N/A
lift-*.f64N/A
*-rgt-identityN/A
*-rgt-identityN/A
+-commutativeN/A
lift-*.f64N/A
lift-pow.f64N/A
unpow2N/A
associate-*r*N/A
unpow1N/A
sqr-powN/A
associate-*r*N/A
lower-fma.f64N/A
Applied egg-rr98.6%
if 5.0000000000000002e147 < (/.f64 t l) Initial program 47.3%
Taylor expanded in l around 0
Simplified87.7%
Taylor expanded in Om around 0
lower-fma.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
lower-*.f64N/A
cube-multN/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-sqrt.f6497.9
Simplified97.9%
Final simplification98.4%
herbie shell --seed 2024218
(FPCore (t l Om Omc)
:name "Toniolo and Linder, Equation (2)"
:precision binary64
(asin (sqrt (/ (- 1.0 (pow (/ Om Omc) 2.0)) (+ 1.0 (* 2.0 (pow (/ t l) 2.0)))))))