| Alternative 1 | |
|---|---|
| Error | 1.0 |
| Cost | 32832 |
(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)))))))
(FPCore (t l Om Omc)
:precision binary64
(let* ((t_1 (- 1.0 (pow (/ Om Omc) 2.0))))
(if (<= (/ t l) -1e+115)
(- (asin (* (/ l t) (sqrt 0.5))))
(if (<= (/ t l) 2e+126)
(asin (sqrt (/ t_1 (+ 1.0 (* 2.0 (pow (/ t l) 2.0))))))
(asin (* l (/ (sqrt (* t_1 0.5)) t)))))))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))))));
}
double code(double t, double l, double Om, double Omc) {
double t_1 = 1.0 - pow((Om / Omc), 2.0);
double tmp;
if ((t / l) <= -1e+115) {
tmp = -asin(((l / t) * sqrt(0.5)));
} else if ((t / l) <= 2e+126) {
tmp = asin(sqrt((t_1 / (1.0 + (2.0 * pow((t / l), 2.0))))));
} else {
tmp = asin((l * (sqrt((t_1 * 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
code = asin(sqrt(((1.0d0 - ((om / omc) ** 2.0d0)) / (1.0d0 + (2.0d0 * ((t / l) ** 2.0d0))))))
end function
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) :: t_1
real(8) :: tmp
t_1 = 1.0d0 - ((om / omc) ** 2.0d0)
if ((t / l) <= (-1d+115)) then
tmp = -asin(((l / t) * sqrt(0.5d0)))
else if ((t / l) <= 2d+126) then
tmp = asin(sqrt((t_1 / (1.0d0 + (2.0d0 * ((t / l) ** 2.0d0))))))
else
tmp = asin((l * (sqrt((t_1 * 0.5d0)) / t)))
end if
code = tmp
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))))));
}
public static double code(double t, double l, double Om, double Omc) {
double t_1 = 1.0 - Math.pow((Om / Omc), 2.0);
double tmp;
if ((t / l) <= -1e+115) {
tmp = -Math.asin(((l / t) * Math.sqrt(0.5)));
} else if ((t / l) <= 2e+126) {
tmp = Math.asin(Math.sqrt((t_1 / (1.0 + (2.0 * Math.pow((t / l), 2.0))))));
} else {
tmp = Math.asin((l * (Math.sqrt((t_1 * 0.5)) / t)));
}
return tmp;
}
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))))))
def code(t, l, Om, Omc): t_1 = 1.0 - math.pow((Om / Omc), 2.0) tmp = 0 if (t / l) <= -1e+115: tmp = -math.asin(((l / t) * math.sqrt(0.5))) elif (t / l) <= 2e+126: tmp = math.asin(math.sqrt((t_1 / (1.0 + (2.0 * math.pow((t / l), 2.0)))))) else: tmp = math.asin((l * (math.sqrt((t_1 * 0.5)) / t))) return tmp
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 code(t, l, Om, Omc) t_1 = Float64(1.0 - (Float64(Om / Omc) ^ 2.0)) tmp = 0.0 if (Float64(t / l) <= -1e+115) tmp = Float64(-asin(Float64(Float64(l / t) * sqrt(0.5)))); elseif (Float64(t / l) <= 2e+126) tmp = asin(sqrt(Float64(t_1 / Float64(1.0 + Float64(2.0 * (Float64(t / l) ^ 2.0)))))); else tmp = asin(Float64(l * Float64(sqrt(Float64(t_1 * 0.5)) / t))); end return tmp 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
function tmp_2 = code(t, l, Om, Omc) t_1 = 1.0 - ((Om / Omc) ^ 2.0); tmp = 0.0; if ((t / l) <= -1e+115) tmp = -asin(((l / t) * sqrt(0.5))); elseif ((t / l) <= 2e+126) tmp = asin(sqrt((t_1 / (1.0 + (2.0 * ((t / l) ^ 2.0)))))); else tmp = asin((l * (sqrt((t_1 * 0.5)) / t))); end tmp_2 = tmp; 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]
code[t_, l_, Om_, Omc_] := Block[{t$95$1 = N[(1.0 - N[Power[N[(Om / Omc), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(t / l), $MachinePrecision], -1e+115], (-N[ArcSin[N[(N[(l / t), $MachinePrecision] * N[Sqrt[0.5], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), If[LessEqual[N[(t / l), $MachinePrecision], 2e+126], N[ArcSin[N[Sqrt[N[(t$95$1 / N[(1.0 + N[(2.0 * N[Power[N[(t / l), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision], N[ArcSin[N[(l * N[(N[Sqrt[N[(t$95$1 * 0.5), $MachinePrecision]], $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]]
\sin^{-1} \left(\sqrt{\frac{1 - {\left(\frac{Om}{Omc}\right)}^{2}}{1 + 2 \cdot {\left(\frac{t}{\ell}\right)}^{2}}}\right)
\begin{array}{l}
t_1 := 1 - {\left(\frac{Om}{Omc}\right)}^{2}\\
\mathbf{if}\;\frac{t}{\ell} \leq -1 \cdot 10^{+115}:\\
\;\;\;\;-\sin^{-1} \left(\frac{\ell}{t} \cdot \sqrt{0.5}\right)\\
\mathbf{elif}\;\frac{t}{\ell} \leq 2 \cdot 10^{+126}:\\
\;\;\;\;\sin^{-1} \left(\sqrt{\frac{t_1}{1 + 2 \cdot {\left(\frac{t}{\ell}\right)}^{2}}}\right)\\
\mathbf{else}:\\
\;\;\;\;\sin^{-1} \left(\ell \cdot \frac{\sqrt{t_1 \cdot 0.5}}{t}\right)\\
\end{array}
Results
if (/.f64 t l) < -1e115Initial program 29.3
Taylor expanded in t around -inf 7.7
Simplified8.3
[Start]7.7 | \[ \sin^{-1} \left(-1 \cdot \left(\frac{\sqrt{0.5} \cdot \ell}{t} \cdot \sqrt{1 - \frac{{Om}^{2}}{{Omc}^{2}}}\right)\right)
\] |
|---|---|
mul-1-neg [=>]7.7 | \[ \sin^{-1} \color{blue}{\left(-\frac{\sqrt{0.5} \cdot \ell}{t} \cdot \sqrt{1 - \frac{{Om}^{2}}{{Omc}^{2}}}\right)}
\] |
*-commutative [=>]7.7 | \[ \sin^{-1} \left(-\color{blue}{\sqrt{1 - \frac{{Om}^{2}}{{Omc}^{2}}} \cdot \frac{\sqrt{0.5} \cdot \ell}{t}}\right)
\] |
unpow2 [=>]7.7 | \[ \sin^{-1} \left(-\sqrt{1 - \frac{\color{blue}{Om \cdot Om}}{{Omc}^{2}}} \cdot \frac{\sqrt{0.5} \cdot \ell}{t}\right)
\] |
unpow2 [=>]7.7 | \[ \sin^{-1} \left(-\sqrt{1 - \frac{Om \cdot Om}{\color{blue}{Omc \cdot Omc}}} \cdot \frac{\sqrt{0.5} \cdot \ell}{t}\right)
\] |
associate-/l* [=>]8.3 | \[ \sin^{-1} \left(-\sqrt{1 - \frac{Om \cdot Om}{Omc \cdot Omc}} \cdot \color{blue}{\frac{\sqrt{0.5}}{\frac{t}{\ell}}}\right)
\] |
Applied egg-rr38.3
Simplified0.3
[Start]38.3 | \[ \left(0 - e^{\mathsf{log1p}\left(\sin^{-1} \left(\sqrt{\left(1 - {\left(\frac{Om}{Omc}\right)}^{2}\right) \cdot 0.5} \cdot \frac{\ell}{t}\right)\right)}\right) + 1
\] |
|---|---|
associate-+l- [=>]38.3 | \[ \color{blue}{0 - \left(e^{\mathsf{log1p}\left(\sin^{-1} \left(\sqrt{\left(1 - {\left(\frac{Om}{Omc}\right)}^{2}\right) \cdot 0.5} \cdot \frac{\ell}{t}\right)\right)} - 1\right)}
\] |
expm1-def [=>]0.3 | \[ 0 - \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin^{-1} \left(\sqrt{\left(1 - {\left(\frac{Om}{Omc}\right)}^{2}\right) \cdot 0.5} \cdot \frac{\ell}{t}\right)\right)\right)}
\] |
expm1-log1p [=>]0.3 | \[ 0 - \color{blue}{\sin^{-1} \left(\sqrt{\left(1 - {\left(\frac{Om}{Omc}\right)}^{2}\right) \cdot 0.5} \cdot \frac{\ell}{t}\right)}
\] |
sub0-neg [=>]0.3 | \[ \color{blue}{-\sin^{-1} \left(\sqrt{\left(1 - {\left(\frac{Om}{Omc}\right)}^{2}\right) \cdot 0.5} \cdot \frac{\ell}{t}\right)}
\] |
associate-*r/ [=>]0.3 | \[ -\sin^{-1} \color{blue}{\left(\frac{\sqrt{\left(1 - {\left(\frac{Om}{Omc}\right)}^{2}\right) \cdot 0.5} \cdot \ell}{t}\right)}
\] |
associate-*l/ [<=]0.3 | \[ -\sin^{-1} \color{blue}{\left(\frac{\sqrt{\left(1 - {\left(\frac{Om}{Omc}\right)}^{2}\right) \cdot 0.5}}{t} \cdot \ell\right)}
\] |
*-commutative [=>]0.3 | \[ -\sin^{-1} \color{blue}{\left(\ell \cdot \frac{\sqrt{\left(1 - {\left(\frac{Om}{Omc}\right)}^{2}\right) \cdot 0.5}}{t}\right)}
\] |
*-commutative [=>]0.3 | \[ -\sin^{-1} \left(\ell \cdot \frac{\sqrt{\color{blue}{0.5 \cdot \left(1 - {\left(\frac{Om}{Omc}\right)}^{2}\right)}}}{t}\right)
\] |
Taylor expanded in Om around 0 0.8
Applied egg-rr0.8
if -1e115 < (/.f64 t l) < 1.99999999999999985e126Initial program 0.9
if 1.99999999999999985e126 < (/.f64 t l) Initial program 31.3
Taylor expanded in t around -inf 40.6
Simplified40.5
[Start]40.6 | \[ \sin^{-1} \left(-1 \cdot \left(\frac{\sqrt{0.5} \cdot \ell}{t} \cdot \sqrt{1 - \frac{{Om}^{2}}{{Omc}^{2}}}\right)\right)
\] |
|---|---|
mul-1-neg [=>]40.6 | \[ \sin^{-1} \color{blue}{\left(-\frac{\sqrt{0.5} \cdot \ell}{t} \cdot \sqrt{1 - \frac{{Om}^{2}}{{Omc}^{2}}}\right)}
\] |
*-commutative [=>]40.6 | \[ \sin^{-1} \left(-\color{blue}{\sqrt{1 - \frac{{Om}^{2}}{{Omc}^{2}}} \cdot \frac{\sqrt{0.5} \cdot \ell}{t}}\right)
\] |
unpow2 [=>]40.6 | \[ \sin^{-1} \left(-\sqrt{1 - \frac{\color{blue}{Om \cdot Om}}{{Omc}^{2}}} \cdot \frac{\sqrt{0.5} \cdot \ell}{t}\right)
\] |
unpow2 [=>]40.6 | \[ \sin^{-1} \left(-\sqrt{1 - \frac{Om \cdot Om}{\color{blue}{Omc \cdot Omc}}} \cdot \frac{\sqrt{0.5} \cdot \ell}{t}\right)
\] |
associate-/l* [=>]40.5 | \[ \sin^{-1} \left(-\sqrt{1 - \frac{Om \cdot Om}{Omc \cdot Omc}} \cdot \color{blue}{\frac{\sqrt{0.5}}{\frac{t}{\ell}}}\right)
\] |
Applied egg-rr0.3
Simplified0.3
[Start]0.3 | \[ 0 + \sin^{-1} \left(\sqrt{\left(1 - {\left(\frac{Om}{Omc}\right)}^{2}\right) \cdot 0.5} \cdot \frac{\ell}{t}\right)
\] |
|---|---|
+-lft-identity [=>]0.3 | \[ \color{blue}{\sin^{-1} \left(\sqrt{\left(1 - {\left(\frac{Om}{Omc}\right)}^{2}\right) \cdot 0.5} \cdot \frac{\ell}{t}\right)}
\] |
associate-*r/ [=>]0.3 | \[ \sin^{-1} \color{blue}{\left(\frac{\sqrt{\left(1 - {\left(\frac{Om}{Omc}\right)}^{2}\right) \cdot 0.5} \cdot \ell}{t}\right)}
\] |
associate-*l/ [<=]0.3 | \[ \sin^{-1} \color{blue}{\left(\frac{\sqrt{\left(1 - {\left(\frac{Om}{Omc}\right)}^{2}\right) \cdot 0.5}}{t} \cdot \ell\right)}
\] |
*-commutative [=>]0.3 | \[ \sin^{-1} \color{blue}{\left(\ell \cdot \frac{\sqrt{\left(1 - {\left(\frac{Om}{Omc}\right)}^{2}\right) \cdot 0.5}}{t}\right)}
\] |
*-commutative [=>]0.3 | \[ \sin^{-1} \left(\ell \cdot \frac{\sqrt{\color{blue}{0.5 \cdot \left(1 - {\left(\frac{Om}{Omc}\right)}^{2}\right)}}}{t}\right)
\] |
Final simplification0.8
| Alternative 1 | |
|---|---|
| Error | 1.0 |
| Cost | 32832 |
| Alternative 2 | |
|---|---|
| Error | 1.1 |
| Cost | 20872 |
| Alternative 3 | |
|---|---|
| Error | 1.7 |
| Cost | 13896 |
| Alternative 4 | |
|---|---|
| Error | 33.0 |
| Cost | 13444 |
| Alternative 5 | |
|---|---|
| Error | 44.2 |
| Cost | 13120 |
herbie shell --seed 2023053
(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)))))))