
(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 6 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 (/ (* t (sqrt 2.0)) l)))))
double code(double t, double l, double Om, double Omc) {
return asin((sqrt((1.0 - ((Om / Omc) / (Omc / Om)))) / hypot(1.0, ((t * sqrt(2.0)) / 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, ((t * Math.sqrt(2.0)) / l))));
}
def code(t, l, Om, Omc): return math.asin((math.sqrt((1.0 - ((Om / Omc) / (Omc / Om)))) / math.hypot(1.0, ((t * math.sqrt(2.0)) / 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(t * sqrt(2.0)) / l)))) end
function tmp = code(t, l, Om, Omc) tmp = asin((sqrt((1.0 - ((Om / Omc) / (Omc / Om)))) / hypot(1.0, ((t * sqrt(2.0)) / 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[(t * N[Sqrt[2.0], $MachinePrecision]), $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{t \cdot \sqrt{2}}{\ell}\right)}\right)
\end{array}
Initial program 78.4%
sqrt-div78.3%
add-sqr-sqrt78.3%
hypot-1-def78.3%
*-commutative78.3%
sqrt-prod78.2%
unpow278.2%
sqrt-prod55.0%
add-sqr-sqrt98.0%
Applied egg-rr98.0%
Taylor expanded in t around 0 98.1%
unpow298.1%
clear-num98.1%
un-div-inv98.1%
Applied egg-rr98.1%
Final simplification98.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 78.4%
sqrt-div78.3%
add-sqr-sqrt78.3%
hypot-1-def78.3%
*-commutative78.3%
sqrt-prod78.2%
unpow278.2%
sqrt-prod55.0%
add-sqr-sqrt98.0%
Applied egg-rr98.0%
Taylor expanded in Om around 0 96.8%
Final simplification96.8%
(FPCore (t l Om Omc) :precision binary64 (asin (/ 1.0 (hypot 1.0 (/ (* t (sqrt 2.0)) l)))))
double code(double t, double l, double Om, double Omc) {
return asin((1.0 / hypot(1.0, ((t * sqrt(2.0)) / l))));
}
public static double code(double t, double l, double Om, double Omc) {
return Math.asin((1.0 / Math.hypot(1.0, ((t * Math.sqrt(2.0)) / l))));
}
def code(t, l, Om, Omc): return math.asin((1.0 / math.hypot(1.0, ((t * math.sqrt(2.0)) / l))))
function code(t, l, Om, Omc) return asin(Float64(1.0 / hypot(1.0, Float64(Float64(t * sqrt(2.0)) / l)))) end
function tmp = code(t, l, Om, Omc) tmp = asin((1.0 / hypot(1.0, ((t * sqrt(2.0)) / l)))); end
code[t_, l_, Om_, Omc_] := N[ArcSin[N[(1.0 / N[Sqrt[1.0 ^ 2 + N[(N[(t * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sin^{-1} \left(\frac{1}{\mathsf{hypot}\left(1, \frac{t \cdot \sqrt{2}}{\ell}\right)}\right)
\end{array}
Initial program 78.4%
sqrt-div78.3%
add-sqr-sqrt78.3%
hypot-1-def78.3%
*-commutative78.3%
sqrt-prod78.2%
unpow278.2%
sqrt-prod55.0%
add-sqr-sqrt98.0%
Applied egg-rr98.0%
Taylor expanded in t around 0 98.1%
unpow298.1%
clear-num98.1%
un-div-inv98.1%
Applied egg-rr98.1%
Taylor expanded in Om around 0 96.8%
Final simplification96.8%
(FPCore (t l Om Omc)
:precision binary64
(let* ((t_1 (asin (/ (/ (- l) t) (sqrt 2.0))))
(t_2 (asin (sqrt (- 1.0 (/ (/ Om Omc) (/ Omc Om)))))))
(if (<= l -1.06e+151)
t_2
(if (<= l -1.5e+15)
t_1
(if (<= l -2.9e-58) (asin 1.0) (if (<= l 1e-138) t_1 t_2))))))
double code(double t, double l, double Om, double Omc) {
double t_1 = asin(((-l / t) / sqrt(2.0)));
double t_2 = asin(sqrt((1.0 - ((Om / Omc) / (Omc / Om)))));
double tmp;
if (l <= -1.06e+151) {
tmp = t_2;
} else if (l <= -1.5e+15) {
tmp = t_1;
} else if (l <= -2.9e-58) {
tmp = asin(1.0);
} else if (l <= 1e-138) {
tmp = t_1;
} else {
tmp = t_2;
}
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) :: t_1
real(8) :: t_2
real(8) :: tmp
t_1 = asin(((-l / t) / sqrt(2.0d0)))
t_2 = asin(sqrt((1.0d0 - ((om / omc) / (omc / om)))))
if (l <= (-1.06d+151)) then
tmp = t_2
else if (l <= (-1.5d+15)) then
tmp = t_1
else if (l <= (-2.9d-58)) then
tmp = asin(1.0d0)
else if (l <= 1d-138) then
tmp = t_1
else
tmp = t_2
end if
code = tmp
end function
public static double code(double t, double l, double Om, double Omc) {
double t_1 = Math.asin(((-l / t) / Math.sqrt(2.0)));
double t_2 = Math.asin(Math.sqrt((1.0 - ((Om / Omc) / (Omc / Om)))));
double tmp;
if (l <= -1.06e+151) {
tmp = t_2;
} else if (l <= -1.5e+15) {
tmp = t_1;
} else if (l <= -2.9e-58) {
tmp = Math.asin(1.0);
} else if (l <= 1e-138) {
tmp = t_1;
} else {
tmp = t_2;
}
return tmp;
}
def code(t, l, Om, Omc): t_1 = math.asin(((-l / t) / math.sqrt(2.0))) t_2 = math.asin(math.sqrt((1.0 - ((Om / Omc) / (Omc / Om))))) tmp = 0 if l <= -1.06e+151: tmp = t_2 elif l <= -1.5e+15: tmp = t_1 elif l <= -2.9e-58: tmp = math.asin(1.0) elif l <= 1e-138: tmp = t_1 else: tmp = t_2 return tmp
function code(t, l, Om, Omc) t_1 = asin(Float64(Float64(Float64(-l) / t) / sqrt(2.0))) t_2 = asin(sqrt(Float64(1.0 - Float64(Float64(Om / Omc) / Float64(Omc / Om))))) tmp = 0.0 if (l <= -1.06e+151) tmp = t_2; elseif (l <= -1.5e+15) tmp = t_1; elseif (l <= -2.9e-58) tmp = asin(1.0); elseif (l <= 1e-138) tmp = t_1; else tmp = t_2; end return tmp end
function tmp_2 = code(t, l, Om, Omc) t_1 = asin(((-l / t) / sqrt(2.0))); t_2 = asin(sqrt((1.0 - ((Om / Omc) / (Omc / Om))))); tmp = 0.0; if (l <= -1.06e+151) tmp = t_2; elseif (l <= -1.5e+15) tmp = t_1; elseif (l <= -2.9e-58) tmp = asin(1.0); elseif (l <= 1e-138) tmp = t_1; else tmp = t_2; end tmp_2 = tmp; end
code[t_, l_, Om_, Omc_] := Block[{t$95$1 = N[ArcSin[N[(N[((-l) / t), $MachinePrecision] / N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[ArcSin[N[Sqrt[N[(1.0 - N[(N[(Om / Omc), $MachinePrecision] / N[(Omc / Om), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]}, If[LessEqual[l, -1.06e+151], t$95$2, If[LessEqual[l, -1.5e+15], t$95$1, If[LessEqual[l, -2.9e-58], N[ArcSin[1.0], $MachinePrecision], If[LessEqual[l, 1e-138], t$95$1, t$95$2]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \sin^{-1} \left(\frac{\frac{-\ell}{t}}{\sqrt{2}}\right)\\
t_2 := \sin^{-1} \left(\sqrt{1 - \frac{\frac{Om}{Omc}}{\frac{Omc}{Om}}}\right)\\
\mathbf{if}\;\ell \leq -1.06 \cdot 10^{+151}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;\ell \leq -1.5 \cdot 10^{+15}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;\ell \leq -2.9 \cdot 10^{-58}:\\
\;\;\;\;\sin^{-1} 1\\
\mathbf{elif}\;\ell \leq 10^{-138}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_2\\
\end{array}
\end{array}
if l < -1.06000000000000003e151 or 1.00000000000000007e-138 < l Initial program 86.4%
Taylor expanded in t around 0 57.3%
unpow257.3%
unpow257.3%
times-frac66.7%
unpow266.7%
Simplified66.7%
unpow298.2%
clear-num98.2%
un-div-inv98.2%
Applied egg-rr66.7%
if -1.06000000000000003e151 < l < -1.5e15 or -2.8999999999999999e-58 < l < 1.00000000000000007e-138Initial program 67.2%
sqrt-div67.1%
add-sqr-sqrt67.1%
hypot-1-def67.1%
*-commutative67.1%
sqrt-prod67.1%
unpow267.1%
sqrt-prod48.3%
add-sqr-sqrt97.7%
Applied egg-rr97.7%
Taylor expanded in t around 0 97.6%
Taylor expanded in t around -inf 44.7%
mul-1-neg44.7%
*-commutative44.7%
distribute-rgt-neg-in44.7%
unpow244.7%
unpow244.7%
times-frac50.1%
unpow250.1%
associate-/r*50.1%
Simplified50.1%
Taylor expanded in Om around 0 49.6%
if -1.5e15 < l < -2.8999999999999999e-58Initial program 94.1%
Taylor expanded in t around 0 70.8%
unpow270.8%
unpow270.8%
times-frac70.8%
unpow270.8%
Simplified70.8%
Taylor expanded in Om around 0 70.8%
Final simplification59.3%
(FPCore (t l Om Omc)
:precision binary64
(if (<= l -1.06e+151)
(asin 1.0)
(if (or (<= l -6.2e+14) (and (not (<= l -6e-60)) (<= l 2.35e-138)))
(asin (/ (/ (- l) t) (sqrt 2.0)))
(asin 1.0))))
double code(double t, double l, double Om, double Omc) {
double tmp;
if (l <= -1.06e+151) {
tmp = asin(1.0);
} else if ((l <= -6.2e+14) || (!(l <= -6e-60) && (l <= 2.35e-138))) {
tmp = asin(((-l / t) / sqrt(2.0)));
} else {
tmp = asin(1.0);
}
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 (l <= (-1.06d+151)) then
tmp = asin(1.0d0)
else if ((l <= (-6.2d+14)) .or. (.not. (l <= (-6d-60))) .and. (l <= 2.35d-138)) then
tmp = asin(((-l / t) / sqrt(2.0d0)))
else
tmp = asin(1.0d0)
end if
code = tmp
end function
public static double code(double t, double l, double Om, double Omc) {
double tmp;
if (l <= -1.06e+151) {
tmp = Math.asin(1.0);
} else if ((l <= -6.2e+14) || (!(l <= -6e-60) && (l <= 2.35e-138))) {
tmp = Math.asin(((-l / t) / Math.sqrt(2.0)));
} else {
tmp = Math.asin(1.0);
}
return tmp;
}
def code(t, l, Om, Omc): tmp = 0 if l <= -1.06e+151: tmp = math.asin(1.0) elif (l <= -6.2e+14) or (not (l <= -6e-60) and (l <= 2.35e-138)): tmp = math.asin(((-l / t) / math.sqrt(2.0))) else: tmp = math.asin(1.0) return tmp
function code(t, l, Om, Omc) tmp = 0.0 if (l <= -1.06e+151) tmp = asin(1.0); elseif ((l <= -6.2e+14) || (!(l <= -6e-60) && (l <= 2.35e-138))) tmp = asin(Float64(Float64(Float64(-l) / t) / sqrt(2.0))); else tmp = asin(1.0); end return tmp end
function tmp_2 = code(t, l, Om, Omc) tmp = 0.0; if (l <= -1.06e+151) tmp = asin(1.0); elseif ((l <= -6.2e+14) || (~((l <= -6e-60)) && (l <= 2.35e-138))) tmp = asin(((-l / t) / sqrt(2.0))); else tmp = asin(1.0); end tmp_2 = tmp; end
code[t_, l_, Om_, Omc_] := If[LessEqual[l, -1.06e+151], N[ArcSin[1.0], $MachinePrecision], If[Or[LessEqual[l, -6.2e+14], And[N[Not[LessEqual[l, -6e-60]], $MachinePrecision], LessEqual[l, 2.35e-138]]], N[ArcSin[N[(N[((-l) / t), $MachinePrecision] / N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[ArcSin[1.0], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -1.06 \cdot 10^{+151}:\\
\;\;\;\;\sin^{-1} 1\\
\mathbf{elif}\;\ell \leq -6.2 \cdot 10^{+14} \lor \neg \left(\ell \leq -6 \cdot 10^{-60}\right) \land \ell \leq 2.35 \cdot 10^{-138}:\\
\;\;\;\;\sin^{-1} \left(\frac{\frac{-\ell}{t}}{\sqrt{2}}\right)\\
\mathbf{else}:\\
\;\;\;\;\sin^{-1} 1\\
\end{array}
\end{array}
if l < -1.06000000000000003e151 or -6.2e14 < l < -6.00000000000000038e-60 or 2.3500000000000001e-138 < l Initial program 87.3%
Taylor expanded in t around 0 58.8%
unpow258.8%
unpow258.8%
times-frac67.1%
unpow267.1%
Simplified67.1%
Taylor expanded in Om around 0 65.8%
if -1.06000000000000003e151 < l < -6.2e14 or -6.00000000000000038e-60 < l < 2.3500000000000001e-138Initial program 67.2%
sqrt-div67.1%
add-sqr-sqrt67.1%
hypot-1-def67.1%
*-commutative67.1%
sqrt-prod67.1%
unpow267.1%
sqrt-prod48.3%
add-sqr-sqrt97.7%
Applied egg-rr97.7%
Taylor expanded in t around 0 97.6%
Taylor expanded in t around -inf 44.7%
mul-1-neg44.7%
*-commutative44.7%
distribute-rgt-neg-in44.7%
unpow244.7%
unpow244.7%
times-frac50.1%
unpow250.1%
associate-/r*50.1%
Simplified50.1%
Taylor expanded in Om around 0 49.6%
Final simplification58.6%
(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 78.4%
Taylor expanded in t around 0 39.5%
unpow239.5%
unpow239.5%
times-frac45.1%
unpow245.1%
Simplified45.1%
Taylor expanded in Om around 0 44.4%
Final simplification44.4%
herbie shell --seed 2023319
(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)))))))