
(FPCore (c0 A V l) :precision binary64 (* c0 (sqrt (/ A (* V l)))))
double code(double c0, double A, double V, double l) {
return c0 * sqrt((A / (V * l)));
}
real(8) function code(c0, a, v, l)
real(8), intent (in) :: c0
real(8), intent (in) :: a
real(8), intent (in) :: v
real(8), intent (in) :: l
code = c0 * sqrt((a / (v * l)))
end function
public static double code(double c0, double A, double V, double l) {
return c0 * Math.sqrt((A / (V * l)));
}
def code(c0, A, V, l): return c0 * math.sqrt((A / (V * l)))
function code(c0, A, V, l) return Float64(c0 * sqrt(Float64(A / Float64(V * l)))) end
function tmp = code(c0, A, V, l) tmp = c0 * sqrt((A / (V * l))); end
code[c0_, A_, V_, l_] := N[(c0 * N[Sqrt[N[(A / N[(V * l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
c0 \cdot \sqrt{\frac{A}{V \cdot \ell}}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 11 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (c0 A V l) :precision binary64 (* c0 (sqrt (/ A (* V l)))))
double code(double c0, double A, double V, double l) {
return c0 * sqrt((A / (V * l)));
}
real(8) function code(c0, a, v, l)
real(8), intent (in) :: c0
real(8), intent (in) :: a
real(8), intent (in) :: v
real(8), intent (in) :: l
code = c0 * sqrt((a / (v * l)))
end function
public static double code(double c0, double A, double V, double l) {
return c0 * Math.sqrt((A / (V * l)));
}
def code(c0, A, V, l): return c0 * math.sqrt((A / (V * l)))
function code(c0, A, V, l) return Float64(c0 * sqrt(Float64(A / Float64(V * l)))) end
function tmp = code(c0, A, V, l) tmp = c0 * sqrt((A / (V * l))); end
code[c0_, A_, V_, l_] := N[(c0 * N[Sqrt[N[(A / N[(V * l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
c0 \cdot \sqrt{\frac{A}{V \cdot \ell}}
\end{array}
NOTE: c0, A, V, and l should be sorted in increasing order before calling this function.
(FPCore (c0 A V l)
:precision binary64
(let* ((t_0 (sqrt (- V))))
(if (<= V -5.4e-163)
(* c0 (/ (sqrt (/ A (- l))) t_0))
(if (<= V -4e-310)
(/ (* (sqrt (- A)) c0) (* (sqrt l) t_0))
(/ (* c0 (sqrt A)) (* (sqrt l) (sqrt V)))))))assert(c0 < A && A < V && V < l);
double code(double c0, double A, double V, double l) {
double t_0 = sqrt(-V);
double tmp;
if (V <= -5.4e-163) {
tmp = c0 * (sqrt((A / -l)) / t_0);
} else if (V <= -4e-310) {
tmp = (sqrt(-A) * c0) / (sqrt(l) * t_0);
} else {
tmp = (c0 * sqrt(A)) / (sqrt(l) * sqrt(V));
}
return tmp;
}
NOTE: c0, A, V, and l should be sorted in increasing order before calling this function.
real(8) function code(c0, a, v, l)
real(8), intent (in) :: c0
real(8), intent (in) :: a
real(8), intent (in) :: v
real(8), intent (in) :: l
real(8) :: t_0
real(8) :: tmp
t_0 = sqrt(-v)
if (v <= (-5.4d-163)) then
tmp = c0 * (sqrt((a / -l)) / t_0)
else if (v <= (-4d-310)) then
tmp = (sqrt(-a) * c0) / (sqrt(l) * t_0)
else
tmp = (c0 * sqrt(a)) / (sqrt(l) * sqrt(v))
end if
code = tmp
end function
assert c0 < A && A < V && V < l;
public static double code(double c0, double A, double V, double l) {
double t_0 = Math.sqrt(-V);
double tmp;
if (V <= -5.4e-163) {
tmp = c0 * (Math.sqrt((A / -l)) / t_0);
} else if (V <= -4e-310) {
tmp = (Math.sqrt(-A) * c0) / (Math.sqrt(l) * t_0);
} else {
tmp = (c0 * Math.sqrt(A)) / (Math.sqrt(l) * Math.sqrt(V));
}
return tmp;
}
[c0, A, V, l] = sort([c0, A, V, l]) def code(c0, A, V, l): t_0 = math.sqrt(-V) tmp = 0 if V <= -5.4e-163: tmp = c0 * (math.sqrt((A / -l)) / t_0) elif V <= -4e-310: tmp = (math.sqrt(-A) * c0) / (math.sqrt(l) * t_0) else: tmp = (c0 * math.sqrt(A)) / (math.sqrt(l) * math.sqrt(V)) return tmp
c0, A, V, l = sort([c0, A, V, l]) function code(c0, A, V, l) t_0 = sqrt(Float64(-V)) tmp = 0.0 if (V <= -5.4e-163) tmp = Float64(c0 * Float64(sqrt(Float64(A / Float64(-l))) / t_0)); elseif (V <= -4e-310) tmp = Float64(Float64(sqrt(Float64(-A)) * c0) / Float64(sqrt(l) * t_0)); else tmp = Float64(Float64(c0 * sqrt(A)) / Float64(sqrt(l) * sqrt(V))); end return tmp end
c0, A, V, l = num2cell(sort([c0, A, V, l])){:}
function tmp_2 = code(c0, A, V, l)
t_0 = sqrt(-V);
tmp = 0.0;
if (V <= -5.4e-163)
tmp = c0 * (sqrt((A / -l)) / t_0);
elseif (V <= -4e-310)
tmp = (sqrt(-A) * c0) / (sqrt(l) * t_0);
else
tmp = (c0 * sqrt(A)) / (sqrt(l) * sqrt(V));
end
tmp_2 = tmp;
end
NOTE: c0, A, V, and l should be sorted in increasing order before calling this function.
code[c0_, A_, V_, l_] := Block[{t$95$0 = N[Sqrt[(-V)], $MachinePrecision]}, If[LessEqual[V, -5.4e-163], N[(c0 * N[(N[Sqrt[N[(A / (-l)), $MachinePrecision]], $MachinePrecision] / t$95$0), $MachinePrecision]), $MachinePrecision], If[LessEqual[V, -4e-310], N[(N[(N[Sqrt[(-A)], $MachinePrecision] * c0), $MachinePrecision] / N[(N[Sqrt[l], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision], N[(N[(c0 * N[Sqrt[A], $MachinePrecision]), $MachinePrecision] / N[(N[Sqrt[l], $MachinePrecision] * N[Sqrt[V], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
[c0, A, V, l] = \mathsf{sort}([c0, A, V, l])\\
\\
\begin{array}{l}
t_0 := \sqrt{-V}\\
\mathbf{if}\;V \leq -5.4 \cdot 10^{-163}:\\
\;\;\;\;c0 \cdot \frac{\sqrt{\frac{A}{-\ell}}}{t\_0}\\
\mathbf{elif}\;V \leq -4 \cdot 10^{-310}:\\
\;\;\;\;\frac{\sqrt{-A} \cdot c0}{\sqrt{\ell} \cdot t\_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{c0 \cdot \sqrt{A}}{\sqrt{\ell} \cdot \sqrt{V}}\\
\end{array}
\end{array}
if V < -5.40000000000000029e-163Initial program 76.5%
associate-/l/N/A
lower-/.f64N/A
lower-/.f6476.0
Applied egg-rr76.0%
lift-/.f64N/A
frac-2negN/A
sqrt-divN/A
lower-/.f64N/A
lower-sqrt.f64N/A
lift-/.f64N/A
distribute-neg-fracN/A
lower-/.f64N/A
lower-neg.f64N/A
lower-sqrt.f64N/A
lower-neg.f6484.3
Applied egg-rr84.3%
if -5.40000000000000029e-163 < V < -3.999999999999988e-310Initial program 62.7%
associate-/l/N/A
lower-/.f64N/A
lower-/.f6467.9
Applied egg-rr67.9%
lift-/.f64N/A
div-invN/A
lift-/.f64N/A
clear-numN/A
frac-2negN/A
metadata-evalN/A
frac-timesN/A
metadata-evalN/A
lower-/.f64N/A
lower-*.f64N/A
distribute-neg-frac2N/A
lower-/.f64N/A
lower-neg.f6467.9
Applied egg-rr67.9%
Applied egg-rr99.2%
if -3.999999999999988e-310 < V Initial program 73.3%
lift-*.f64N/A
sqrt-divN/A
associate-*r/N/A
*-commutativeN/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f6480.0
Applied egg-rr80.0%
*-commutativeN/A
sqrt-prodN/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
lower-*.f6496.8
Applied egg-rr96.8%
Final simplification90.2%
NOTE: c0, A, V, and l should be sorted in increasing order before calling this function.
(FPCore (c0 A V l)
:precision binary64
(if (<= (* l V) -5e-322)
(* c0 (/ (sqrt (- A)) (sqrt (* V (- l)))))
(if (<= (* l V) 4e-317)
(* c0 (/ (sqrt (/ A V)) (sqrt l)))
(* c0 (/ (sqrt A) (sqrt (* l V)))))))assert(c0 < A && A < V && V < l);
double code(double c0, double A, double V, double l) {
double tmp;
if ((l * V) <= -5e-322) {
tmp = c0 * (sqrt(-A) / sqrt((V * -l)));
} else if ((l * V) <= 4e-317) {
tmp = c0 * (sqrt((A / V)) / sqrt(l));
} else {
tmp = c0 * (sqrt(A) / sqrt((l * V)));
}
return tmp;
}
NOTE: c0, A, V, and l should be sorted in increasing order before calling this function.
real(8) function code(c0, a, v, l)
real(8), intent (in) :: c0
real(8), intent (in) :: a
real(8), intent (in) :: v
real(8), intent (in) :: l
real(8) :: tmp
if ((l * v) <= (-5d-322)) then
tmp = c0 * (sqrt(-a) / sqrt((v * -l)))
else if ((l * v) <= 4d-317) then
tmp = c0 * (sqrt((a / v)) / sqrt(l))
else
tmp = c0 * (sqrt(a) / sqrt((l * v)))
end if
code = tmp
end function
assert c0 < A && A < V && V < l;
public static double code(double c0, double A, double V, double l) {
double tmp;
if ((l * V) <= -5e-322) {
tmp = c0 * (Math.sqrt(-A) / Math.sqrt((V * -l)));
} else if ((l * V) <= 4e-317) {
tmp = c0 * (Math.sqrt((A / V)) / Math.sqrt(l));
} else {
tmp = c0 * (Math.sqrt(A) / Math.sqrt((l * V)));
}
return tmp;
}
[c0, A, V, l] = sort([c0, A, V, l]) def code(c0, A, V, l): tmp = 0 if (l * V) <= -5e-322: tmp = c0 * (math.sqrt(-A) / math.sqrt((V * -l))) elif (l * V) <= 4e-317: tmp = c0 * (math.sqrt((A / V)) / math.sqrt(l)) else: tmp = c0 * (math.sqrt(A) / math.sqrt((l * V))) return tmp
c0, A, V, l = sort([c0, A, V, l]) function code(c0, A, V, l) tmp = 0.0 if (Float64(l * V) <= -5e-322) tmp = Float64(c0 * Float64(sqrt(Float64(-A)) / sqrt(Float64(V * Float64(-l))))); elseif (Float64(l * V) <= 4e-317) tmp = Float64(c0 * Float64(sqrt(Float64(A / V)) / sqrt(l))); else tmp = Float64(c0 * Float64(sqrt(A) / sqrt(Float64(l * V)))); end return tmp end
c0, A, V, l = num2cell(sort([c0, A, V, l])){:}
function tmp_2 = code(c0, A, V, l)
tmp = 0.0;
if ((l * V) <= -5e-322)
tmp = c0 * (sqrt(-A) / sqrt((V * -l)));
elseif ((l * V) <= 4e-317)
tmp = c0 * (sqrt((A / V)) / sqrt(l));
else
tmp = c0 * (sqrt(A) / sqrt((l * V)));
end
tmp_2 = tmp;
end
NOTE: c0, A, V, and l should be sorted in increasing order before calling this function. code[c0_, A_, V_, l_] := If[LessEqual[N[(l * V), $MachinePrecision], -5e-322], N[(c0 * N[(N[Sqrt[(-A)], $MachinePrecision] / N[Sqrt[N[(V * (-l)), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(l * V), $MachinePrecision], 4e-317], N[(c0 * N[(N[Sqrt[N[(A / V), $MachinePrecision]], $MachinePrecision] / N[Sqrt[l], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(c0 * N[(N[Sqrt[A], $MachinePrecision] / N[Sqrt[N[(l * V), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[c0, A, V, l] = \mathsf{sort}([c0, A, V, l])\\
\\
\begin{array}{l}
\mathbf{if}\;\ell \cdot V \leq -5 \cdot 10^{-322}:\\
\;\;\;\;c0 \cdot \frac{\sqrt{-A}}{\sqrt{V \cdot \left(-\ell\right)}}\\
\mathbf{elif}\;\ell \cdot V \leq 4 \cdot 10^{-317}:\\
\;\;\;\;c0 \cdot \frac{\sqrt{\frac{A}{V}}}{\sqrt{\ell}}\\
\mathbf{else}:\\
\;\;\;\;c0 \cdot \frac{\sqrt{A}}{\sqrt{\ell \cdot V}}\\
\end{array}
\end{array}
if (*.f64 V l) < -4.99006e-322Initial program 79.2%
associate-/l/N/A
lower-/.f64N/A
lower-/.f6476.1
Applied egg-rr76.1%
associate-/l/N/A
lift-*.f64N/A
frac-2negN/A
sqrt-divN/A
lower-/.f64N/A
lower-sqrt.f64N/A
lower-neg.f64N/A
lower-sqrt.f64N/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-*.f64N/A
lower-neg.f6490.5
Applied egg-rr90.5%
if -4.99006e-322 < (*.f64 V l) < 3.99999993e-317Initial program 39.4%
associate-/r*N/A
sqrt-divN/A
lower-/.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-sqrt.f6460.9
Applied egg-rr60.9%
if 3.99999993e-317 < (*.f64 V l) Initial program 78.2%
lift-*.f64N/A
sqrt-divN/A
lower-/.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f6489.6
Applied egg-rr89.6%
Final simplification86.6%
herbie shell --seed 2024218
(FPCore (c0 A V l)
:name "Henrywood and Agarwal, Equation (3)"
:precision binary64
(* c0 (sqrt (/ A (* V l)))))