
(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 12 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
(if (<= (* V l) -5e-324)
(* c0 (/ (sqrt (- A)) (* (sqrt (- V)) (sqrt l))))
(if (<= (* V l) 1e-318)
(/ c0 (* (sqrt l) (sqrt (/ V A))))
(if (<= (* V l) 4e+296)
(* c0 (/ (sqrt A) (sqrt (* V l))))
(* c0 (sqrt (/ (/ A l) V)))))))assert(c0 < A && A < V && V < l);
double code(double c0, double A, double V, double l) {
double tmp;
if ((V * l) <= -5e-324) {
tmp = c0 * (sqrt(-A) / (sqrt(-V) * sqrt(l)));
} else if ((V * l) <= 1e-318) {
tmp = c0 / (sqrt(l) * sqrt((V / A)));
} else if ((V * l) <= 4e+296) {
tmp = c0 * (sqrt(A) / sqrt((V * l)));
} else {
tmp = c0 * sqrt(((A / 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 ((v * l) <= (-5d-324)) then
tmp = c0 * (sqrt(-a) / (sqrt(-v) * sqrt(l)))
else if ((v * l) <= 1d-318) then
tmp = c0 / (sqrt(l) * sqrt((v / a)))
else if ((v * l) <= 4d+296) then
tmp = c0 * (sqrt(a) / sqrt((v * l)))
else
tmp = c0 * sqrt(((a / 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 ((V * l) <= -5e-324) {
tmp = c0 * (Math.sqrt(-A) / (Math.sqrt(-V) * Math.sqrt(l)));
} else if ((V * l) <= 1e-318) {
tmp = c0 / (Math.sqrt(l) * Math.sqrt((V / A)));
} else if ((V * l) <= 4e+296) {
tmp = c0 * (Math.sqrt(A) / Math.sqrt((V * l)));
} else {
tmp = c0 * Math.sqrt(((A / l) / V));
}
return tmp;
}
[c0, A, V, l] = sort([c0, A, V, l]) def code(c0, A, V, l): tmp = 0 if (V * l) <= -5e-324: tmp = c0 * (math.sqrt(-A) / (math.sqrt(-V) * math.sqrt(l))) elif (V * l) <= 1e-318: tmp = c0 / (math.sqrt(l) * math.sqrt((V / A))) elif (V * l) <= 4e+296: tmp = c0 * (math.sqrt(A) / math.sqrt((V * l))) else: tmp = c0 * math.sqrt(((A / l) / V)) return tmp
c0, A, V, l = sort([c0, A, V, l]) function code(c0, A, V, l) tmp = 0.0 if (Float64(V * l) <= -5e-324) tmp = Float64(c0 * Float64(sqrt(Float64(-A)) / Float64(sqrt(Float64(-V)) * sqrt(l)))); elseif (Float64(V * l) <= 1e-318) tmp = Float64(c0 / Float64(sqrt(l) * sqrt(Float64(V / A)))); elseif (Float64(V * l) <= 4e+296) tmp = Float64(c0 * Float64(sqrt(A) / sqrt(Float64(V * l)))); else tmp = Float64(c0 * sqrt(Float64(Float64(A / 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 ((V * l) <= -5e-324)
tmp = c0 * (sqrt(-A) / (sqrt(-V) * sqrt(l)));
elseif ((V * l) <= 1e-318)
tmp = c0 / (sqrt(l) * sqrt((V / A)));
elseif ((V * l) <= 4e+296)
tmp = c0 * (sqrt(A) / sqrt((V * l)));
else
tmp = c0 * sqrt(((A / 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[(V * l), $MachinePrecision], -5e-324], N[(c0 * N[(N[Sqrt[(-A)], $MachinePrecision] / N[(N[Sqrt[(-V)], $MachinePrecision] * N[Sqrt[l], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(V * l), $MachinePrecision], 1e-318], N[(c0 / N[(N[Sqrt[l], $MachinePrecision] * N[Sqrt[N[(V / A), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(V * l), $MachinePrecision], 4e+296], N[(c0 * N[(N[Sqrt[A], $MachinePrecision] / N[Sqrt[N[(V * l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(c0 * N[Sqrt[N[(N[(A / l), $MachinePrecision] / V), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
[c0, A, V, l] = \mathsf{sort}([c0, A, V, l])\\
\\
\begin{array}{l}
\mathbf{if}\;V \cdot \ell \leq -5 \cdot 10^{-324}:\\
\;\;\;\;c0 \cdot \frac{\sqrt{-A}}{\sqrt{-V} \cdot \sqrt{\ell}}\\
\mathbf{elif}\;V \cdot \ell \leq 10^{-318}:\\
\;\;\;\;\frac{c0}{\sqrt{\ell} \cdot \sqrt{\frac{V}{A}}}\\
\mathbf{elif}\;V \cdot \ell \leq 4 \cdot 10^{+296}:\\
\;\;\;\;c0 \cdot \frac{\sqrt{A}}{\sqrt{V \cdot \ell}}\\
\mathbf{else}:\\
\;\;\;\;c0 \cdot \sqrt{\frac{\frac{A}{\ell}}{V}}\\
\end{array}
\end{array}
if (*.f64 V l) < -4.94066e-324Initial program 78.3%
lift-/.f64N/A
lift-*.f64N/A
associate-/l/N/A
div-invN/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f6474.9
Applied rewrites74.9%
lift-sqrt.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
lift-/.f64N/A
div-invN/A
lift-/.f64N/A
sqrt-divN/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
div-invN/A
frac-2negN/A
metadata-evalN/A
lift-sqrt.f64N/A
lift-/.f64N/A
frac-2negN/A
lift-neg.f64N/A
sqrt-divN/A
lift-sqrt.f64N/A
frac-timesN/A
lower-/.f64N/A
Applied rewrites97.8%
if -4.94066e-324 < (*.f64 V l) < 9.9999875e-319Initial program 36.6%
lift-/.f64N/A
lift-*.f64N/A
associate-/l/N/A
div-invN/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f6469.4
Applied rewrites69.4%
lift-*.f64N/A
lift-sqrt.f64N/A
lift-*.f64N/A
lift-/.f64N/A
lift-/.f64N/A
frac-timesN/A
lift-*.f64N/A
sqrt-divN/A
*-rgt-identityN/A
associate-*r/N/A
associate-*l/N/A
associate-/r/N/A
sqrt-divN/A
lift-/.f64N/A
lift-sqrt.f64N/A
lower-/.f6436.6
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6469.4
Applied rewrites69.4%
lift-sqrt.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
associate-*l/N/A
sqrt-prodN/A
lift-sqrt.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f6481.4
Applied rewrites81.4%
if 9.9999875e-319 < (*.f64 V l) < 3.99999999999999993e296Initial program 84.2%
lift-sqrt.f64N/A
lift-/.f64N/A
sqrt-divN/A
lower-/.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f6499.1
Applied rewrites99.1%
if 3.99999999999999993e296 < (*.f64 V l) Initial program 37.3%
lift-/.f64N/A
lift-*.f64N/A
associate-/l/N/A
lower-/.f64N/A
lower-/.f6468.1
Applied rewrites68.1%
Final simplification94.3%
NOTE: c0, A, V, and l should be sorted in increasing order before calling this function.
(FPCore (c0 A V l)
:precision binary64
(if (<= (* V l) (- INFINITY))
(* c0 (* (sqrt (/ A (- l))) (sqrt (/ -1.0 V))))
(if (<= (* V l) -5e-324)
(* c0 (/ (sqrt (- A)) (sqrt (* V (- l)))))
(if (<= (* V l) 1e-318)
(/ c0 (* (sqrt l) (sqrt (/ V A))))
(if (<= (* V l) 4e+296)
(* c0 (/ (sqrt A) (sqrt (* V l))))
(* c0 (sqrt (/ (/ A l) V))))))))assert(c0 < A && A < V && V < l);
double code(double c0, double A, double V, double l) {
double tmp;
if ((V * l) <= -((double) INFINITY)) {
tmp = c0 * (sqrt((A / -l)) * sqrt((-1.0 / V)));
} else if ((V * l) <= -5e-324) {
tmp = c0 * (sqrt(-A) / sqrt((V * -l)));
} else if ((V * l) <= 1e-318) {
tmp = c0 / (sqrt(l) * sqrt((V / A)));
} else if ((V * l) <= 4e+296) {
tmp = c0 * (sqrt(A) / sqrt((V * l)));
} else {
tmp = c0 * sqrt(((A / l) / V));
}
return tmp;
}
assert c0 < A && A < V && V < l;
public static double code(double c0, double A, double V, double l) {
double tmp;
if ((V * l) <= -Double.POSITIVE_INFINITY) {
tmp = c0 * (Math.sqrt((A / -l)) * Math.sqrt((-1.0 / V)));
} else if ((V * l) <= -5e-324) {
tmp = c0 * (Math.sqrt(-A) / Math.sqrt((V * -l)));
} else if ((V * l) <= 1e-318) {
tmp = c0 / (Math.sqrt(l) * Math.sqrt((V / A)));
} else if ((V * l) <= 4e+296) {
tmp = c0 * (Math.sqrt(A) / Math.sqrt((V * l)));
} else {
tmp = c0 * Math.sqrt(((A / l) / V));
}
return tmp;
}
[c0, A, V, l] = sort([c0, A, V, l]) def code(c0, A, V, l): tmp = 0 if (V * l) <= -math.inf: tmp = c0 * (math.sqrt((A / -l)) * math.sqrt((-1.0 / V))) elif (V * l) <= -5e-324: tmp = c0 * (math.sqrt(-A) / math.sqrt((V * -l))) elif (V * l) <= 1e-318: tmp = c0 / (math.sqrt(l) * math.sqrt((V / A))) elif (V * l) <= 4e+296: tmp = c0 * (math.sqrt(A) / math.sqrt((V * l))) else: tmp = c0 * math.sqrt(((A / l) / V)) return tmp
c0, A, V, l = sort([c0, A, V, l]) function code(c0, A, V, l) tmp = 0.0 if (Float64(V * l) <= Float64(-Inf)) tmp = Float64(c0 * Float64(sqrt(Float64(A / Float64(-l))) * sqrt(Float64(-1.0 / V)))); elseif (Float64(V * l) <= -5e-324) tmp = Float64(c0 * Float64(sqrt(Float64(-A)) / sqrt(Float64(V * Float64(-l))))); elseif (Float64(V * l) <= 1e-318) tmp = Float64(c0 / Float64(sqrt(l) * sqrt(Float64(V / A)))); elseif (Float64(V * l) <= 4e+296) tmp = Float64(c0 * Float64(sqrt(A) / sqrt(Float64(V * l)))); else tmp = Float64(c0 * sqrt(Float64(Float64(A / 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 ((V * l) <= -Inf)
tmp = c0 * (sqrt((A / -l)) * sqrt((-1.0 / V)));
elseif ((V * l) <= -5e-324)
tmp = c0 * (sqrt(-A) / sqrt((V * -l)));
elseif ((V * l) <= 1e-318)
tmp = c0 / (sqrt(l) * sqrt((V / A)));
elseif ((V * l) <= 4e+296)
tmp = c0 * (sqrt(A) / sqrt((V * l)));
else
tmp = c0 * sqrt(((A / 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[(V * l), $MachinePrecision], (-Infinity)], N[(c0 * N[(N[Sqrt[N[(A / (-l)), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(-1.0 / V), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(V * l), $MachinePrecision], -5e-324], N[(c0 * N[(N[Sqrt[(-A)], $MachinePrecision] / N[Sqrt[N[(V * (-l)), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(V * l), $MachinePrecision], 1e-318], N[(c0 / N[(N[Sqrt[l], $MachinePrecision] * N[Sqrt[N[(V / A), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(V * l), $MachinePrecision], 4e+296], N[(c0 * N[(N[Sqrt[A], $MachinePrecision] / N[Sqrt[N[(V * l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(c0 * N[Sqrt[N[(N[(A / l), $MachinePrecision] / V), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
[c0, A, V, l] = \mathsf{sort}([c0, A, V, l])\\
\\
\begin{array}{l}
\mathbf{if}\;V \cdot \ell \leq -\infty:\\
\;\;\;\;c0 \cdot \left(\sqrt{\frac{A}{-\ell}} \cdot \sqrt{\frac{-1}{V}}\right)\\
\mathbf{elif}\;V \cdot \ell \leq -5 \cdot 10^{-324}:\\
\;\;\;\;c0 \cdot \frac{\sqrt{-A}}{\sqrt{V \cdot \left(-\ell\right)}}\\
\mathbf{elif}\;V \cdot \ell \leq 10^{-318}:\\
\;\;\;\;\frac{c0}{\sqrt{\ell} \cdot \sqrt{\frac{V}{A}}}\\
\mathbf{elif}\;V \cdot \ell \leq 4 \cdot 10^{+296}:\\
\;\;\;\;c0 \cdot \frac{\sqrt{A}}{\sqrt{V \cdot \ell}}\\
\mathbf{else}:\\
\;\;\;\;c0 \cdot \sqrt{\frac{\frac{A}{\ell}}{V}}\\
\end{array}
\end{array}
if (*.f64 V l) < -inf.0Initial program 36.2%
lift-/.f64N/A
lift-*.f64N/A
associate-/l/N/A
lower-/.f64N/A
lower-/.f6461.9
Applied rewrites61.9%
lift-sqrt.f64N/A
lift-/.f64N/A
frac-2negN/A
div-invN/A
sqrt-prodN/A
distribute-frac-neg2N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lift-/.f64N/A
distribute-neg-frac2N/A
lower-/.f64N/A
lower-neg.f64N/A
lower-sqrt.f64N/A
distribute-neg-fracN/A
metadata-evalN/A
lower-/.f6483.7
Applied rewrites83.7%
if -inf.0 < (*.f64 V l) < -4.94066e-324Initial program 85.3%
lift-/.f64N/A
lift-*.f64N/A
associate-/l/N/A
lower-/.f64N/A
lower-/.f6478.0
Applied rewrites78.0%
lift-sqrt.f64N/A
lift-/.f64N/A
sqrt-divN/A
lift-/.f64N/A
frac-2negN/A
sqrt-divN/A
associate-/l/N/A
sqrt-prodN/A
distribute-rgt-neg-inN/A
lift-*.f64N/A
lower-/.f64N/A
lower-sqrt.f64N/A
lower-neg.f64N/A
lower-sqrt.f64N/A
lift-*.f64N/A
distribute-rgt-neg-inN/A
lower-*.f64N/A
lower-neg.f6499.0
Applied rewrites99.0%
if -4.94066e-324 < (*.f64 V l) < 9.9999875e-319Initial program 39.0%
lift-/.f64N/A
lift-*.f64N/A
associate-/l/N/A
div-invN/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f6464.8
Applied rewrites64.8%
lift-*.f64N/A
lift-sqrt.f64N/A
lift-*.f64N/A
lift-/.f64N/A
lift-/.f64N/A
frac-timesN/A
lift-*.f64N/A
sqrt-divN/A
*-rgt-identityN/A
associate-*r/N/A
associate-*l/N/A
associate-/r/N/A
sqrt-divN/A
lift-/.f64N/A
lift-sqrt.f64N/A
lower-/.f6439.0
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6466.3
Applied rewrites66.3%
lift-sqrt.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
associate-*l/N/A
sqrt-prodN/A
lift-sqrt.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f6465.6
Applied rewrites65.6%
if 9.9999875e-319 < (*.f64 V l) < 3.99999999999999993e296Initial program 86.0%
lift-sqrt.f64N/A
lift-/.f64N/A
sqrt-divN/A
lower-/.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f6499.4
Applied rewrites99.4%
if 3.99999999999999993e296 < (*.f64 V l) Initial program 37.8%
lift-/.f64N/A
lift-*.f64N/A
associate-/l/N/A
lower-/.f64N/A
lower-/.f6464.9
Applied rewrites64.9%
Final simplification92.1%
herbie shell --seed 2024223
(FPCore (c0 A V l)
:name "Henrywood and Agarwal, Equation (3)"
:precision binary64
(* c0 (sqrt (/ A (* V l)))))