
(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 7 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}
(FPCore (t l Om Omc) :precision binary64 (asin (/ (sqrt (- 1.0 (/ (/ Om Omc) (/ Omc Om)))) (hypot 1.0 (/ (* (sqrt 2.0) t) l)))))
double code(double t, double l, double Om, double Omc) {
return asin((sqrt((1.0 - ((Om / Omc) / (Omc / Om)))) / hypot(1.0, ((sqrt(2.0) * t) / l))));
}
public static double code(double t, double l, double Om, double Omc) {
return Math.asin((Math.sqrt((1.0 - ((Om / Omc) / (Omc / Om)))) / Math.hypot(1.0, ((Math.sqrt(2.0) * t) / l))));
}
def code(t, l, Om, Omc): return math.asin((math.sqrt((1.0 - ((Om / Omc) / (Omc / Om)))) / math.hypot(1.0, ((math.sqrt(2.0) * t) / l))))
function code(t, l, Om, Omc) return asin(Float64(sqrt(Float64(1.0 - Float64(Float64(Om / Omc) / Float64(Omc / Om)))) / hypot(1.0, Float64(Float64(sqrt(2.0) * t) / l)))) end
function tmp = code(t, l, Om, Omc) tmp = asin((sqrt((1.0 - ((Om / Omc) / (Omc / Om)))) / hypot(1.0, ((sqrt(2.0) * t) / l)))); end
code[t_, l_, Om_, Omc_] := N[ArcSin[N[(N[Sqrt[N[(1.0 - N[(N[(Om / Omc), $MachinePrecision] / N[(Omc / Om), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[1.0 ^ 2 + N[(N[(N[Sqrt[2.0], $MachinePrecision] * t), $MachinePrecision] / l), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sin^{-1} \left(\frac{\sqrt{1 - \frac{\frac{Om}{Omc}}{\frac{Omc}{Om}}}}{\mathsf{hypot}\left(1, \frac{\sqrt{2} \cdot t}{\ell}\right)}\right)
\end{array}
Initial program 82.5%
sqrt-div82.5%
div-inv82.5%
add-sqr-sqrt82.5%
hypot-1-def82.5%
*-commutative82.5%
sqrt-prod82.4%
sqrt-pow199.0%
metadata-eval99.0%
pow199.0%
Applied egg-rr99.0%
associate-*r/99.0%
*-rgt-identity99.0%
*-commutative99.0%
associate-*r/99.1%
Simplified99.1%
unpow299.1%
clear-num99.1%
un-div-inv99.1%
Applied egg-rr99.1%
Final simplification99.1%
(FPCore (t l Om Omc) :precision binary64 (asin (/ 1.0 (hypot 1.0 (* (sqrt 2.0) (/ t l))))))
double code(double t, double l, double Om, double Omc) {
return asin((1.0 / hypot(1.0, (sqrt(2.0) * (t / l)))));
}
public static double code(double t, double l, double Om, double Omc) {
return Math.asin((1.0 / Math.hypot(1.0, (Math.sqrt(2.0) * (t / l)))));
}
def code(t, l, Om, Omc): return math.asin((1.0 / math.hypot(1.0, (math.sqrt(2.0) * (t / l)))))
function code(t, l, Om, Omc) return asin(Float64(1.0 / hypot(1.0, Float64(sqrt(2.0) * Float64(t / l))))) end
function tmp = code(t, l, Om, Omc) tmp = asin((1.0 / hypot(1.0, (sqrt(2.0) * (t / l))))); end
code[t_, l_, Om_, Omc_] := N[ArcSin[N[(1.0 / N[Sqrt[1.0 ^ 2 + N[(N[Sqrt[2.0], $MachinePrecision] * N[(t / l), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sin^{-1} \left(\frac{1}{\mathsf{hypot}\left(1, \sqrt{2} \cdot \frac{t}{\ell}\right)}\right)
\end{array}
Initial program 82.5%
expm1-log1p-u82.5%
expm1-undefine82.5%
log1p-undefine82.5%
add-exp-log82.5%
Applied egg-rr82.5%
Taylor expanded in Om around 0 60.0%
associate-*r/60.0%
rem-square-sqrt60.0%
unpow260.0%
*-commutative60.0%
*-commutative60.0%
unpow260.0%
rem-square-sqrt60.0%
Simplified60.0%
*-un-lft-identity60.0%
sqrt-div60.0%
metadata-eval60.0%
add-sqr-sqrt60.0%
hypot-1-def60.0%
sqrt-div63.5%
sqrt-prod63.5%
sqrt-pow179.0%
metadata-eval79.0%
pow179.0%
sqrt-pow197.7%
metadata-eval97.7%
pow197.7%
associate-/l*97.6%
Applied egg-rr97.6%
*-lft-identity97.6%
Simplified97.6%
Final simplification97.6%
(FPCore (t l Om Omc) :precision binary64 (asin (/ 1.0 (hypot 1.0 (/ (* (sqrt 2.0) t) l)))))
double code(double t, double l, double Om, double Omc) {
return asin((1.0 / hypot(1.0, ((sqrt(2.0) * t) / l))));
}
public static double code(double t, double l, double Om, double Omc) {
return Math.asin((1.0 / Math.hypot(1.0, ((Math.sqrt(2.0) * t) / l))));
}
def code(t, l, Om, Omc): return math.asin((1.0 / math.hypot(1.0, ((math.sqrt(2.0) * t) / l))))
function code(t, l, Om, Omc) return asin(Float64(1.0 / hypot(1.0, Float64(Float64(sqrt(2.0) * t) / l)))) end
function tmp = code(t, l, Om, Omc) tmp = asin((1.0 / hypot(1.0, ((sqrt(2.0) * t) / l)))); end
code[t_, l_, Om_, Omc_] := N[ArcSin[N[(1.0 / N[Sqrt[1.0 ^ 2 + N[(N[(N[Sqrt[2.0], $MachinePrecision] * t), $MachinePrecision] / l), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sin^{-1} \left(\frac{1}{\mathsf{hypot}\left(1, \frac{\sqrt{2} \cdot t}{\ell}\right)}\right)
\end{array}
Initial program 82.5%
sqrt-div82.5%
div-inv82.5%
add-sqr-sqrt82.5%
hypot-1-def82.5%
*-commutative82.5%
sqrt-prod82.4%
sqrt-pow199.0%
metadata-eval99.0%
pow199.0%
Applied egg-rr99.0%
associate-*r/99.0%
*-rgt-identity99.0%
*-commutative99.0%
associate-*r/99.1%
Simplified99.1%
unpow299.1%
clear-num99.1%
un-div-inv99.1%
Applied egg-rr99.1%
Taylor expanded in Om around 0 97.7%
Final simplification97.7%
(FPCore (t l Om Omc) :precision binary64 (if (<= t 4e-12) (- (/ PI 2.0) (acos (sqrt (- 1.0 (/ (/ Om Omc) (/ Omc Om)))))) (asin (* l (/ (sqrt 0.5) t)))))
double code(double t, double l, double Om, double Omc) {
double tmp;
if (t <= 4e-12) {
tmp = (((double) M_PI) / 2.0) - acos(sqrt((1.0 - ((Om / Omc) / (Omc / Om)))));
} else {
tmp = asin((l * (sqrt(0.5) / t)));
}
return tmp;
}
public static double code(double t, double l, double Om, double Omc) {
double tmp;
if (t <= 4e-12) {
tmp = (Math.PI / 2.0) - Math.acos(Math.sqrt((1.0 - ((Om / Omc) / (Omc / Om)))));
} else {
tmp = Math.asin((l * (Math.sqrt(0.5) / t)));
}
return tmp;
}
def code(t, l, Om, Omc): tmp = 0 if t <= 4e-12: tmp = (math.pi / 2.0) - math.acos(math.sqrt((1.0 - ((Om / Omc) / (Omc / Om))))) else: tmp = math.asin((l * (math.sqrt(0.5) / t))) return tmp
function code(t, l, Om, Omc) tmp = 0.0 if (t <= 4e-12) tmp = Float64(Float64(pi / 2.0) - acos(sqrt(Float64(1.0 - Float64(Float64(Om / Omc) / Float64(Omc / Om)))))); else tmp = asin(Float64(l * Float64(sqrt(0.5) / t))); end return tmp end
function tmp_2 = code(t, l, Om, Omc) tmp = 0.0; if (t <= 4e-12) tmp = (pi / 2.0) - acos(sqrt((1.0 - ((Om / Omc) / (Omc / Om))))); else tmp = asin((l * (sqrt(0.5) / t))); end tmp_2 = tmp; end
code[t_, l_, Om_, Omc_] := If[LessEqual[t, 4e-12], N[(N[(Pi / 2.0), $MachinePrecision] - N[ArcCos[N[Sqrt[N[(1.0 - N[(N[(Om / Omc), $MachinePrecision] / N[(Omc / Om), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[ArcSin[N[(l * N[(N[Sqrt[0.5], $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq 4 \cdot 10^{-12}:\\
\;\;\;\;\frac{\pi}{2} - \cos^{-1} \left(\sqrt{1 - \frac{\frac{Om}{Omc}}{\frac{Omc}{Om}}}\right)\\
\mathbf{else}:\\
\;\;\;\;\sin^{-1} \left(\ell \cdot \frac{\sqrt{0.5}}{t}\right)\\
\end{array}
\end{array}
if t < 3.99999999999999992e-12Initial program 86.9%
Taylor expanded in t around 0 52.7%
unpow252.7%
unpow252.7%
times-frac57.8%
unpow257.8%
Simplified57.8%
asin-acos57.8%
Applied egg-rr57.8%
unpow299.2%
clear-num99.2%
un-div-inv99.2%
Applied egg-rr57.8%
if 3.99999999999999992e-12 < t Initial program 70.9%
expm1-log1p-u70.9%
expm1-undefine70.9%
log1p-undefine70.9%
add-exp-log70.9%
Applied egg-rr70.9%
Taylor expanded in Om around 0 51.6%
associate-*r/51.6%
rem-square-sqrt51.6%
unpow251.6%
*-commutative51.6%
*-commutative51.6%
unpow251.6%
rem-square-sqrt51.6%
Simplified51.6%
Taylor expanded in t around inf 43.7%
associate-/l*43.8%
Simplified43.8%
Final simplification53.9%
(FPCore (t l Om Omc) :precision binary64 (if (<= t 9.5e-12) (asin (sqrt (- 1.0 (/ (/ Om Omc) (/ Omc Om))))) (asin (* l (/ (sqrt 0.5) t)))))
double code(double t, double l, double Om, double Omc) {
double tmp;
if (t <= 9.5e-12) {
tmp = asin(sqrt((1.0 - ((Om / Omc) / (Omc / Om)))));
} else {
tmp = asin((l * (sqrt(0.5) / t)));
}
return tmp;
}
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
real(8) :: tmp
if (t <= 9.5d-12) then
tmp = asin(sqrt((1.0d0 - ((om / omc) / (omc / om)))))
else
tmp = asin((l * (sqrt(0.5d0) / t)))
end if
code = tmp
end function
public static double code(double t, double l, double Om, double Omc) {
double tmp;
if (t <= 9.5e-12) {
tmp = Math.asin(Math.sqrt((1.0 - ((Om / Omc) / (Omc / Om)))));
} else {
tmp = Math.asin((l * (Math.sqrt(0.5) / t)));
}
return tmp;
}
def code(t, l, Om, Omc): tmp = 0 if t <= 9.5e-12: tmp = math.asin(math.sqrt((1.0 - ((Om / Omc) / (Omc / Om))))) else: tmp = math.asin((l * (math.sqrt(0.5) / t))) return tmp
function code(t, l, Om, Omc) tmp = 0.0 if (t <= 9.5e-12) tmp = asin(sqrt(Float64(1.0 - Float64(Float64(Om / Omc) / Float64(Omc / Om))))); else tmp = asin(Float64(l * Float64(sqrt(0.5) / t))); end return tmp end
function tmp_2 = code(t, l, Om, Omc) tmp = 0.0; if (t <= 9.5e-12) tmp = asin(sqrt((1.0 - ((Om / Omc) / (Omc / Om))))); else tmp = asin((l * (sqrt(0.5) / t))); end tmp_2 = tmp; end
code[t_, l_, Om_, Omc_] := If[LessEqual[t, 9.5e-12], N[ArcSin[N[Sqrt[N[(1.0 - N[(N[(Om / Omc), $MachinePrecision] / N[(Omc / Om), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision], N[ArcSin[N[(l * N[(N[Sqrt[0.5], $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq 9.5 \cdot 10^{-12}:\\
\;\;\;\;\sin^{-1} \left(\sqrt{1 - \frac{\frac{Om}{Omc}}{\frac{Omc}{Om}}}\right)\\
\mathbf{else}:\\
\;\;\;\;\sin^{-1} \left(\ell \cdot \frac{\sqrt{0.5}}{t}\right)\\
\end{array}
\end{array}
if t < 9.4999999999999995e-12Initial program 86.9%
Taylor expanded in t around 0 52.7%
unpow252.7%
unpow252.7%
times-frac57.8%
unpow257.8%
Simplified57.8%
unpow299.2%
clear-num99.2%
un-div-inv99.2%
Applied egg-rr57.8%
if 9.4999999999999995e-12 < t Initial program 70.9%
expm1-log1p-u70.9%
expm1-undefine70.9%
log1p-undefine70.9%
add-exp-log70.9%
Applied egg-rr70.9%
Taylor expanded in Om around 0 51.6%
associate-*r/51.6%
rem-square-sqrt51.6%
unpow251.6%
*-commutative51.6%
*-commutative51.6%
unpow251.6%
rem-square-sqrt51.6%
Simplified51.6%
Taylor expanded in t around inf 43.7%
associate-/l*43.8%
Simplified43.8%
Final simplification53.9%
(FPCore (t l Om Omc) :precision binary64 (if (<= t 9e-12) (asin 1.0) (asin (* l (/ (sqrt 0.5) t)))))
double code(double t, double l, double Om, double Omc) {
double tmp;
if (t <= 9e-12) {
tmp = asin(1.0);
} else {
tmp = asin((l * (sqrt(0.5) / t)));
}
return tmp;
}
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
real(8) :: tmp
if (t <= 9d-12) then
tmp = asin(1.0d0)
else
tmp = asin((l * (sqrt(0.5d0) / t)))
end if
code = tmp
end function
public static double code(double t, double l, double Om, double Omc) {
double tmp;
if (t <= 9e-12) {
tmp = Math.asin(1.0);
} else {
tmp = Math.asin((l * (Math.sqrt(0.5) / t)));
}
return tmp;
}
def code(t, l, Om, Omc): tmp = 0 if t <= 9e-12: tmp = math.asin(1.0) else: tmp = math.asin((l * (math.sqrt(0.5) / t))) return tmp
function code(t, l, Om, Omc) tmp = 0.0 if (t <= 9e-12) tmp = asin(1.0); else tmp = asin(Float64(l * Float64(sqrt(0.5) / t))); end return tmp end
function tmp_2 = code(t, l, Om, Omc) tmp = 0.0; if (t <= 9e-12) tmp = asin(1.0); else tmp = asin((l * (sqrt(0.5) / t))); end tmp_2 = tmp; end
code[t_, l_, Om_, Omc_] := If[LessEqual[t, 9e-12], N[ArcSin[1.0], $MachinePrecision], N[ArcSin[N[(l * N[(N[Sqrt[0.5], $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq 9 \cdot 10^{-12}:\\
\;\;\;\;\sin^{-1} 1\\
\mathbf{else}:\\
\;\;\;\;\sin^{-1} \left(\ell \cdot \frac{\sqrt{0.5}}{t}\right)\\
\end{array}
\end{array}
if t < 8.99999999999999962e-12Initial program 86.9%
Taylor expanded in t around 0 52.7%
unpow252.7%
unpow252.7%
times-frac57.8%
unpow257.8%
Simplified57.8%
unpow299.2%
clear-num99.2%
un-div-inv99.2%
Applied egg-rr57.8%
Taylor expanded in Om around 0 56.4%
if 8.99999999999999962e-12 < t Initial program 70.9%
expm1-log1p-u70.9%
expm1-undefine70.9%
log1p-undefine70.9%
add-exp-log70.9%
Applied egg-rr70.9%
Taylor expanded in Om around 0 51.6%
associate-*r/51.6%
rem-square-sqrt51.6%
unpow251.6%
*-commutative51.6%
*-commutative51.6%
unpow251.6%
rem-square-sqrt51.6%
Simplified51.6%
Taylor expanded in t around inf 43.7%
associate-/l*43.8%
Simplified43.8%
Final simplification52.9%
(FPCore (t l Om Omc) :precision binary64 (asin 1.0))
double code(double t, double l, double Om, double Omc) {
return asin(1.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(1.0d0)
end function
public static double code(double t, double l, double Om, double Omc) {
return Math.asin(1.0);
}
def code(t, l, Om, Omc): return math.asin(1.0)
function code(t, l, Om, Omc) return asin(1.0) end
function tmp = code(t, l, Om, Omc) tmp = asin(1.0); end
code[t_, l_, Om_, Omc_] := N[ArcSin[1.0], $MachinePrecision]
\begin{array}{l}
\\
\sin^{-1} 1
\end{array}
Initial program 82.5%
Taylor expanded in t around 0 45.6%
unpow245.6%
unpow245.6%
times-frac49.3%
unpow249.3%
Simplified49.3%
unpow299.1%
clear-num99.1%
un-div-inv99.1%
Applied egg-rr49.3%
Taylor expanded in Om around 0 48.3%
Final simplification48.3%
herbie shell --seed 2024060
(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)))))))