
(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 15 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 (- A))))
(if (<= (* l V) -1e+307)
(/ (* t_0 (/ c0 (sqrt l))) (sqrt (- V)))
(if (<= (* l V) -4e-202)
(* c0 (/ t_0 (sqrt (* V (- l)))))
(if (<= (* l V) 0.0)
(/ c0 (sqrt (* V (/ l A))))
(if (<= (* l V) 4e+259)
(* c0 (* (sqrt A) (sqrt (/ 1.0 (* l V)))))
(* c0 (sqrt (/ (/ A V) l)))))))))assert(c0 < A && A < V && V < l);
double code(double c0, double A, double V, double l) {
double t_0 = sqrt(-A);
double tmp;
if ((l * V) <= -1e+307) {
tmp = (t_0 * (c0 / sqrt(l))) / sqrt(-V);
} else if ((l * V) <= -4e-202) {
tmp = c0 * (t_0 / sqrt((V * -l)));
} else if ((l * V) <= 0.0) {
tmp = c0 / sqrt((V * (l / A)));
} else if ((l * V) <= 4e+259) {
tmp = c0 * (sqrt(A) * sqrt((1.0 / (l * V))));
} else {
tmp = c0 * sqrt(((A / V) / l));
}
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(-a)
if ((l * v) <= (-1d+307)) then
tmp = (t_0 * (c0 / sqrt(l))) / sqrt(-v)
else if ((l * v) <= (-4d-202)) then
tmp = c0 * (t_0 / sqrt((v * -l)))
else if ((l * v) <= 0.0d0) then
tmp = c0 / sqrt((v * (l / a)))
else if ((l * v) <= 4d+259) then
tmp = c0 * (sqrt(a) * sqrt((1.0d0 / (l * v))))
else
tmp = c0 * sqrt(((a / v) / l))
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(-A);
double tmp;
if ((l * V) <= -1e+307) {
tmp = (t_0 * (c0 / Math.sqrt(l))) / Math.sqrt(-V);
} else if ((l * V) <= -4e-202) {
tmp = c0 * (t_0 / Math.sqrt((V * -l)));
} else if ((l * V) <= 0.0) {
tmp = c0 / Math.sqrt((V * (l / A)));
} else if ((l * V) <= 4e+259) {
tmp = c0 * (Math.sqrt(A) * Math.sqrt((1.0 / (l * V))));
} else {
tmp = c0 * Math.sqrt(((A / V) / l));
}
return tmp;
}
[c0, A, V, l] = sort([c0, A, V, l]) def code(c0, A, V, l): t_0 = math.sqrt(-A) tmp = 0 if (l * V) <= -1e+307: tmp = (t_0 * (c0 / math.sqrt(l))) / math.sqrt(-V) elif (l * V) <= -4e-202: tmp = c0 * (t_0 / math.sqrt((V * -l))) elif (l * V) <= 0.0: tmp = c0 / math.sqrt((V * (l / A))) elif (l * V) <= 4e+259: tmp = c0 * (math.sqrt(A) * math.sqrt((1.0 / (l * V)))) else: tmp = c0 * math.sqrt(((A / V) / l)) return tmp
c0, A, V, l = sort([c0, A, V, l]) function code(c0, A, V, l) t_0 = sqrt(Float64(-A)) tmp = 0.0 if (Float64(l * V) <= -1e+307) tmp = Float64(Float64(t_0 * Float64(c0 / sqrt(l))) / sqrt(Float64(-V))); elseif (Float64(l * V) <= -4e-202) tmp = Float64(c0 * Float64(t_0 / sqrt(Float64(V * Float64(-l))))); elseif (Float64(l * V) <= 0.0) tmp = Float64(c0 / sqrt(Float64(V * Float64(l / A)))); elseif (Float64(l * V) <= 4e+259) tmp = Float64(c0 * Float64(sqrt(A) * sqrt(Float64(1.0 / Float64(l * V))))); else tmp = Float64(c0 * sqrt(Float64(Float64(A / V) / l))); 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(-A);
tmp = 0.0;
if ((l * V) <= -1e+307)
tmp = (t_0 * (c0 / sqrt(l))) / sqrt(-V);
elseif ((l * V) <= -4e-202)
tmp = c0 * (t_0 / sqrt((V * -l)));
elseif ((l * V) <= 0.0)
tmp = c0 / sqrt((V * (l / A)));
elseif ((l * V) <= 4e+259)
tmp = c0 * (sqrt(A) * sqrt((1.0 / (l * V))));
else
tmp = c0 * sqrt(((A / V) / l));
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[(-A)], $MachinePrecision]}, If[LessEqual[N[(l * V), $MachinePrecision], -1e+307], N[(N[(t$95$0 * N[(c0 / N[Sqrt[l], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[(-V)], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(l * V), $MachinePrecision], -4e-202], N[(c0 * N[(t$95$0 / N[Sqrt[N[(V * (-l)), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(l * V), $MachinePrecision], 0.0], N[(c0 / N[Sqrt[N[(V * N[(l / A), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(l * V), $MachinePrecision], 4e+259], N[(c0 * N[(N[Sqrt[A], $MachinePrecision] * N[Sqrt[N[(1.0 / N[(l * V), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(c0 * N[Sqrt[N[(N[(A / V), $MachinePrecision] / l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
[c0, A, V, l] = \mathsf{sort}([c0, A, V, l])\\
\\
\begin{array}{l}
t_0 := \sqrt{-A}\\
\mathbf{if}\;\ell \cdot V \leq -1 \cdot 10^{+307}:\\
\;\;\;\;\frac{t\_0 \cdot \frac{c0}{\sqrt{\ell}}}{\sqrt{-V}}\\
\mathbf{elif}\;\ell \cdot V \leq -4 \cdot 10^{-202}:\\
\;\;\;\;c0 \cdot \frac{t\_0}{\sqrt{V \cdot \left(-\ell\right)}}\\
\mathbf{elif}\;\ell \cdot V \leq 0:\\
\;\;\;\;\frac{c0}{\sqrt{V \cdot \frac{\ell}{A}}}\\
\mathbf{elif}\;\ell \cdot V \leq 4 \cdot 10^{+259}:\\
\;\;\;\;c0 \cdot \left(\sqrt{A} \cdot \sqrt{\frac{1}{\ell \cdot V}}\right)\\
\mathbf{else}:\\
\;\;\;\;c0 \cdot \sqrt{\frac{\frac{A}{V}}{\ell}}\\
\end{array}
\end{array}
if (*.f64 V l) < -9.99999999999999986e306Initial program 42.8%
lift-/.f64N/A
clear-numN/A
lift-*.f64N/A
associate-/l*N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
lower-/.f6461.9
Applied rewrites61.9%
lift-*.f64N/A
lift-sqrt.f64N/A
lift-/.f64N/A
sqrt-divN/A
pow1/2N/A
associate-*r/N/A
pow1/2N/A
lift-/.f64N/A
sqrt-divN/A
metadata-evalN/A
div-invN/A
associate-/r*N/A
lift-/.f64N/A
sqrt-divN/A
lift-sqrt.f64N/A
associate-/l*N/A
sqrt-prodN/A
lift-*.f64N/A
lift-sqrt.f64N/A
Applied rewrites99.6%
if -9.99999999999999986e306 < (*.f64 V l) < -4.0000000000000001e-202Initial program 83.2%
lift-/.f64N/A
clear-numN/A
lift-*.f64N/A
associate-/l*N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
lower-/.f6477.2
Applied rewrites77.2%
lift-sqrt.f64N/A
lift-/.f64N/A
lift-/.f64N/A
associate-/r/N/A
lift-/.f64N/A
associate-/r*N/A
lift-*.f64N/A
associate-*l/N/A
frac-2negN/A
*-lft-identityN/A
sqrt-divN/A
pow1/2N/A
lower-/.f64N/A
pow1/2N/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.f6499.5
Applied rewrites99.5%
if -4.0000000000000001e-202 < (*.f64 V l) < -0.0Initial program 45.5%
lift-/.f64N/A
lift-*.f64N/A
associate-/l/N/A
lower-/.f64N/A
lower-/.f6461.0
Applied rewrites61.0%
lift-*.f64N/A
lift-sqrt.f64N/A
lift-/.f64N/A
lift-/.f64N/A
associate-/l/N/A
lift-*.f64N/A
sqrt-divN/A
associate-*r/N/A
associate-*l/N/A
associate-/r/N/A
sqrt-divN/A
lift-/.f64N/A
lift-sqrt.f64N/A
lower-/.f6445.5
lift-*.f64N/A
*-commutativeN/A
lower-*.f6445.5
Applied rewrites45.5%
lift-/.f64N/A
lift-*.f64N/A
associate-*l/N/A
lift-/.f64N/A
lift-*.f6461.1
Applied rewrites61.1%
if -0.0 < (*.f64 V l) < 4e259Initial program 91.8%
lift-sqrt.f64N/A
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
sqrt-prodN/A
pow1/2N/A
lower-*.f64N/A
pow1/2N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-sqrt.f6499.4
Applied rewrites99.4%
if 4e259 < (*.f64 V l) Initial program 55.8%
lift-/.f64N/A
lift-*.f64N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6477.1
Applied rewrites77.1%
Final simplification90.9%
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) (- INFINITY))
(/ c0 (* (sqrt l) (sqrt (/ V A))))
(if (<= (* l V) -4e-202)
(* c0 (/ (sqrt (- A)) (sqrt (* V (- l)))))
(if (<= (* l V) 0.0)
(/ c0 (sqrt (* V (/ l A))))
(if (<= (* l V) 4e+259)
(* c0 (* (sqrt A) (sqrt (/ 1.0 (* l V)))))
(* c0 (sqrt (/ (/ A V) l))))))))assert(c0 < A && A < V && V < l);
double code(double c0, double A, double V, double l) {
double tmp;
if ((l * V) <= -((double) INFINITY)) {
tmp = c0 / (sqrt(l) * sqrt((V / A)));
} else if ((l * V) <= -4e-202) {
tmp = c0 * (sqrt(-A) / sqrt((V * -l)));
} else if ((l * V) <= 0.0) {
tmp = c0 / sqrt((V * (l / A)));
} else if ((l * V) <= 4e+259) {
tmp = c0 * (sqrt(A) * sqrt((1.0 / (l * V))));
} else {
tmp = c0 * sqrt(((A / V) / l));
}
return tmp;
}
assert c0 < A && A < V && V < l;
public static double code(double c0, double A, double V, double l) {
double tmp;
if ((l * V) <= -Double.POSITIVE_INFINITY) {
tmp = c0 / (Math.sqrt(l) * Math.sqrt((V / A)));
} else if ((l * V) <= -4e-202) {
tmp = c0 * (Math.sqrt(-A) / Math.sqrt((V * -l)));
} else if ((l * V) <= 0.0) {
tmp = c0 / Math.sqrt((V * (l / A)));
} else if ((l * V) <= 4e+259) {
tmp = c0 * (Math.sqrt(A) * Math.sqrt((1.0 / (l * V))));
} else {
tmp = c0 * Math.sqrt(((A / V) / l));
}
return tmp;
}
[c0, A, V, l] = sort([c0, A, V, l]) def code(c0, A, V, l): tmp = 0 if (l * V) <= -math.inf: tmp = c0 / (math.sqrt(l) * math.sqrt((V / A))) elif (l * V) <= -4e-202: tmp = c0 * (math.sqrt(-A) / math.sqrt((V * -l))) elif (l * V) <= 0.0: tmp = c0 / math.sqrt((V * (l / A))) elif (l * V) <= 4e+259: tmp = c0 * (math.sqrt(A) * math.sqrt((1.0 / (l * V)))) else: tmp = c0 * math.sqrt(((A / V) / l)) return tmp
c0, A, V, l = sort([c0, A, V, l]) function code(c0, A, V, l) tmp = 0.0 if (Float64(l * V) <= Float64(-Inf)) tmp = Float64(c0 / Float64(sqrt(l) * sqrt(Float64(V / A)))); elseif (Float64(l * V) <= -4e-202) tmp = Float64(c0 * Float64(sqrt(Float64(-A)) / sqrt(Float64(V * Float64(-l))))); elseif (Float64(l * V) <= 0.0) tmp = Float64(c0 / sqrt(Float64(V * Float64(l / A)))); elseif (Float64(l * V) <= 4e+259) tmp = Float64(c0 * Float64(sqrt(A) * sqrt(Float64(1.0 / Float64(l * V))))); else tmp = Float64(c0 * sqrt(Float64(Float64(A / V) / l))); 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) <= -Inf)
tmp = c0 / (sqrt(l) * sqrt((V / A)));
elseif ((l * V) <= -4e-202)
tmp = c0 * (sqrt(-A) / sqrt((V * -l)));
elseif ((l * V) <= 0.0)
tmp = c0 / sqrt((V * (l / A)));
elseif ((l * V) <= 4e+259)
tmp = c0 * (sqrt(A) * sqrt((1.0 / (l * V))));
else
tmp = c0 * sqrt(((A / V) / l));
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], (-Infinity)], N[(c0 / N[(N[Sqrt[l], $MachinePrecision] * N[Sqrt[N[(V / A), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(l * V), $MachinePrecision], -4e-202], N[(c0 * N[(N[Sqrt[(-A)], $MachinePrecision] / N[Sqrt[N[(V * (-l)), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(l * V), $MachinePrecision], 0.0], N[(c0 / N[Sqrt[N[(V * N[(l / A), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(l * V), $MachinePrecision], 4e+259], N[(c0 * N[(N[Sqrt[A], $MachinePrecision] * N[Sqrt[N[(1.0 / N[(l * V), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(c0 * N[Sqrt[N[(N[(A / V), $MachinePrecision] / l), $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 -\infty:\\
\;\;\;\;\frac{c0}{\sqrt{\ell} \cdot \sqrt{\frac{V}{A}}}\\
\mathbf{elif}\;\ell \cdot V \leq -4 \cdot 10^{-202}:\\
\;\;\;\;c0 \cdot \frac{\sqrt{-A}}{\sqrt{V \cdot \left(-\ell\right)}}\\
\mathbf{elif}\;\ell \cdot V \leq 0:\\
\;\;\;\;\frac{c0}{\sqrt{V \cdot \frac{\ell}{A}}}\\
\mathbf{elif}\;\ell \cdot V \leq 4 \cdot 10^{+259}:\\
\;\;\;\;c0 \cdot \left(\sqrt{A} \cdot \sqrt{\frac{1}{\ell \cdot V}}\right)\\
\mathbf{else}:\\
\;\;\;\;c0 \cdot \sqrt{\frac{\frac{A}{V}}{\ell}}\\
\end{array}
\end{array}
if (*.f64 V l) < -inf.0Initial program 36.3%
lift-/.f64N/A
lift-*.f64N/A
associate-/l/N/A
lower-/.f64N/A
lower-/.f6461.7
Applied rewrites61.7%
lift-*.f64N/A
lift-sqrt.f64N/A
lift-/.f64N/A
lift-/.f64N/A
associate-/l/N/A
lift-*.f64N/A
sqrt-divN/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.3
lift-*.f64N/A
*-commutativeN/A
lower-*.f6436.3
Applied rewrites36.3%
lift-sqrt.f64N/A
pow1/2N/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
unpow-prod-downN/A
*-commutativeN/A
lower-*.f64N/A
pow1/2N/A
lower-sqrt.f64N/A
lower-/.f64N/A
pow1/2N/A
lower-sqrt.f6482.2
Applied rewrites82.2%
if -inf.0 < (*.f64 V l) < -4.0000000000000001e-202Initial program 87.3%
lift-/.f64N/A
clear-numN/A
lift-*.f64N/A
associate-/l*N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
lower-/.f6479.1
Applied rewrites79.1%
lift-sqrt.f64N/A
lift-/.f64N/A
lift-/.f64N/A
associate-/r/N/A
lift-/.f64N/A
associate-/r*N/A
lift-*.f64N/A
associate-*l/N/A
frac-2negN/A
*-lft-identityN/A
sqrt-divN/A
pow1/2N/A
lower-/.f64N/A
pow1/2N/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.f6499.4
Applied rewrites99.4%
if -4.0000000000000001e-202 < (*.f64 V l) < -0.0Initial program 48.9%
lift-/.f64N/A
lift-*.f64N/A
associate-/l/N/A
lower-/.f64N/A
lower-/.f6466.9
Applied rewrites66.9%
lift-*.f64N/A
lift-sqrt.f64N/A
lift-/.f64N/A
lift-/.f64N/A
associate-/l/N/A
lift-*.f64N/A
sqrt-divN/A
associate-*r/N/A
associate-*l/N/A
associate-/r/N/A
sqrt-divN/A
lift-/.f64N/A
lift-sqrt.f64N/A
lower-/.f6449.4
lift-*.f64N/A
*-commutativeN/A
lower-*.f6449.4
Applied rewrites49.4%
lift-/.f64N/A
lift-*.f64N/A
associate-*l/N/A
lift-/.f64N/A
lift-*.f6467.8
Applied rewrites67.8%
if -0.0 < (*.f64 V l) < 4e259Initial program 86.4%
lift-sqrt.f64N/A
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
sqrt-prodN/A
pow1/2N/A
lower-*.f64N/A
pow1/2N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-sqrt.f6498.5
Applied rewrites98.5%
if 4e259 < (*.f64 V l) Initial program 43.9%
lift-/.f64N/A
lift-*.f64N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6464.4
Applied rewrites64.4%
Final simplification89.7%
herbie shell --seed 2024229
(FPCore (c0 A V l)
:name "Henrywood and Agarwal, Equation (3)"
:precision binary64
(* c0 (sqrt (/ A (* V l)))))