| Alternative 1 | |
|---|---|
| Accuracy | 78.4% |
| Cost | 27724 |

(FPCore (c0 A V l) :precision binary64 (* c0 (sqrt (/ A (* V l)))))
(FPCore (c0 A V l)
:precision binary64
(if (<= (* V l) (- INFINITY))
(* (* (sqrt (/ A V)) c0) (pow l -0.5))
(if (<= (* V l) -2e-323)
(* c0 (/ (sqrt (- A)) (sqrt (* V (- l)))))
(if (<= (* V l) 4e-320)
(sqrt (/ (* A (/ c0 (/ l c0))) V))
(/ c0 (/ (sqrt (* V l)) (sqrt A)))))))double code(double c0, double A, double V, double l) {
return c0 * sqrt((A / (V * l)));
}
double code(double c0, double A, double V, double l) {
double tmp;
if ((V * l) <= -((double) INFINITY)) {
tmp = (sqrt((A / V)) * c0) * pow(l, -0.5);
} else if ((V * l) <= -2e-323) {
tmp = c0 * (sqrt(-A) / sqrt((V * -l)));
} else if ((V * l) <= 4e-320) {
tmp = sqrt(((A * (c0 / (l / c0))) / V));
} else {
tmp = c0 / (sqrt((V * l)) / sqrt(A));
}
return tmp;
}
public static double code(double c0, double A, double V, double l) {
return c0 * Math.sqrt((A / (V * l)));
}
public static double code(double c0, double A, double V, double l) {
double tmp;
if ((V * l) <= -Double.POSITIVE_INFINITY) {
tmp = (Math.sqrt((A / V)) * c0) * Math.pow(l, -0.5);
} else if ((V * l) <= -2e-323) {
tmp = c0 * (Math.sqrt(-A) / Math.sqrt((V * -l)));
} else if ((V * l) <= 4e-320) {
tmp = Math.sqrt(((A * (c0 / (l / c0))) / V));
} else {
tmp = c0 / (Math.sqrt((V * l)) / Math.sqrt(A));
}
return tmp;
}
def code(c0, A, V, l): return c0 * math.sqrt((A / (V * l)))
def code(c0, A, V, l): tmp = 0 if (V * l) <= -math.inf: tmp = (math.sqrt((A / V)) * c0) * math.pow(l, -0.5) elif (V * l) <= -2e-323: tmp = c0 * (math.sqrt(-A) / math.sqrt((V * -l))) elif (V * l) <= 4e-320: tmp = math.sqrt(((A * (c0 / (l / c0))) / V)) else: tmp = c0 / (math.sqrt((V * l)) / math.sqrt(A)) return tmp
function code(c0, A, V, l) return Float64(c0 * sqrt(Float64(A / Float64(V * l)))) end
function code(c0, A, V, l) tmp = 0.0 if (Float64(V * l) <= Float64(-Inf)) tmp = Float64(Float64(sqrt(Float64(A / V)) * c0) * (l ^ -0.5)); elseif (Float64(V * l) <= -2e-323) tmp = Float64(c0 * Float64(sqrt(Float64(-A)) / sqrt(Float64(V * Float64(-l))))); elseif (Float64(V * l) <= 4e-320) tmp = sqrt(Float64(Float64(A * Float64(c0 / Float64(l / c0))) / V)); else tmp = Float64(c0 / Float64(sqrt(Float64(V * l)) / sqrt(A))); end return tmp end
function tmp = code(c0, A, V, l) tmp = c0 * sqrt((A / (V * l))); end
function tmp_2 = code(c0, A, V, l) tmp = 0.0; if ((V * l) <= -Inf) tmp = (sqrt((A / V)) * c0) * (l ^ -0.5); elseif ((V * l) <= -2e-323) tmp = c0 * (sqrt(-A) / sqrt((V * -l))); elseif ((V * l) <= 4e-320) tmp = sqrt(((A * (c0 / (l / c0))) / V)); else tmp = c0 / (sqrt((V * l)) / sqrt(A)); end tmp_2 = tmp; end
code[c0_, A_, V_, l_] := N[(c0 * N[Sqrt[N[(A / N[(V * l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
code[c0_, A_, V_, l_] := If[LessEqual[N[(V * l), $MachinePrecision], (-Infinity)], N[(N[(N[Sqrt[N[(A / V), $MachinePrecision]], $MachinePrecision] * c0), $MachinePrecision] * N[Power[l, -0.5], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(V * l), $MachinePrecision], -2e-323], N[(c0 * N[(N[Sqrt[(-A)], $MachinePrecision] / N[Sqrt[N[(V * (-l)), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(V * l), $MachinePrecision], 4e-320], N[Sqrt[N[(N[(A * N[(c0 / N[(l / c0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / V), $MachinePrecision]], $MachinePrecision], N[(c0 / N[(N[Sqrt[N[(V * l), $MachinePrecision]], $MachinePrecision] / N[Sqrt[A], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
c0 \cdot \sqrt{\frac{A}{V \cdot \ell}}
\begin{array}{l}
\mathbf{if}\;V \cdot \ell \leq -\infty:\\
\;\;\;\;\left(\sqrt{\frac{A}{V}} \cdot c0\right) \cdot {\ell}^{-0.5}\\
\mathbf{elif}\;V \cdot \ell \leq -2 \cdot 10^{-323}:\\
\;\;\;\;c0 \cdot \frac{\sqrt{-A}}{\sqrt{V \cdot \left(-\ell\right)}}\\
\mathbf{elif}\;V \cdot \ell \leq 4 \cdot 10^{-320}:\\
\;\;\;\;\sqrt{\frac{A \cdot \frac{c0}{\frac{\ell}{c0}}}{V}}\\
\mathbf{else}:\\
\;\;\;\;\frac{c0}{\frac{\sqrt{V \cdot \ell}}{\sqrt{A}}}\\
\end{array}
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
if (*.f64 V l) < -inf.0Initial program 40.8%
Applied egg-rr68.0%
[Start]40.8 | \[ c0 \cdot \sqrt{\frac{A}{V \cdot \ell}}
\] |
|---|---|
pow1/2 [=>]40.8 | \[ c0 \cdot \color{blue}{{\left(\frac{A}{V \cdot \ell}\right)}^{0.5}}
\] |
clear-num [=>]40.8 | \[ c0 \cdot {\color{blue}{\left(\frac{1}{\frac{V \cdot \ell}{A}}\right)}}^{0.5}
\] |
inv-pow [=>]40.8 | \[ c0 \cdot {\color{blue}{\left({\left(\frac{V \cdot \ell}{A}\right)}^{-1}\right)}}^{0.5}
\] |
pow-pow [=>]40.8 | \[ c0 \cdot \color{blue}{{\left(\frac{V \cdot \ell}{A}\right)}^{\left(-1 \cdot 0.5\right)}}
\] |
associate-/l* [=>]68.0 | \[ c0 \cdot {\color{blue}{\left(\frac{V}{\frac{A}{\ell}}\right)}}^{\left(-1 \cdot 0.5\right)}
\] |
metadata-eval [=>]68.0 | \[ c0 \cdot {\left(\frac{V}{\frac{A}{\ell}}\right)}^{\color{blue}{-0.5}}
\] |
Simplified40.8%
[Start]68.0 | \[ c0 \cdot {\left(\frac{V}{\frac{A}{\ell}}\right)}^{-0.5}
\] |
|---|---|
associate-/l* [<=]40.8 | \[ c0 \cdot {\color{blue}{\left(\frac{V \cdot \ell}{A}\right)}}^{-0.5}
\] |
Applied egg-rr68.2%
[Start]40.8 | \[ c0 \cdot {\left(\frac{V \cdot \ell}{A}\right)}^{-0.5}
\] |
|---|---|
associate-*r/ [<=]68.2 | \[ c0 \cdot {\color{blue}{\left(V \cdot \frac{\ell}{A}\right)}}^{-0.5}
\] |
metadata-eval [<=]68.2 | \[ c0 \cdot {\left(V \cdot \frac{\ell}{A}\right)}^{\color{blue}{\left(-0.5\right)}}
\] |
pow-flip [<=]68.2 | \[ c0 \cdot \color{blue}{\frac{1}{{\left(V \cdot \frac{\ell}{A}\right)}^{0.5}}}
\] |
pow1/2 [<=]68.2 | \[ c0 \cdot \frac{1}{\color{blue}{\sqrt{V \cdot \frac{\ell}{A}}}}
\] |
un-div-inv [=>]68.2 | \[ \color{blue}{\frac{c0}{\sqrt{V \cdot \frac{\ell}{A}}}}
\] |
Simplified68.2%
[Start]68.2 | \[ \frac{c0}{\sqrt{V \cdot \frac{\ell}{A}}}
\] |
|---|---|
associate-*r/ [=>]40.8 | \[ \frac{c0}{\sqrt{\color{blue}{\frac{V \cdot \ell}{A}}}}
\] |
associate-*l/ [<=]68.2 | \[ \frac{c0}{\sqrt{\color{blue}{\frac{V}{A} \cdot \ell}}}
\] |
*-commutative [<=]68.2 | \[ \frac{c0}{\sqrt{\color{blue}{\ell \cdot \frac{V}{A}}}}
\] |
Applied egg-rr40.0%
[Start]68.2 | \[ \frac{c0}{\sqrt{\ell \cdot \frac{V}{A}}}
\] |
|---|---|
*-un-lft-identity [=>]68.2 | \[ \frac{\color{blue}{1 \cdot c0}}{\sqrt{\ell \cdot \frac{V}{A}}}
\] |
add-sqr-sqrt [=>]68.0 | \[ \frac{1 \cdot c0}{\color{blue}{\sqrt{\sqrt{\ell \cdot \frac{V}{A}}} \cdot \sqrt{\sqrt{\ell \cdot \frac{V}{A}}}}}
\] |
times-frac [=>]68.0 | \[ \color{blue}{\frac{1}{\sqrt{\sqrt{\ell \cdot \frac{V}{A}}}} \cdot \frac{c0}{\sqrt{\sqrt{\ell \cdot \frac{V}{A}}}}}
\] |
Simplified43.1%
[Start]40.0 | \[ \sqrt{\frac{A}{\ell \cdot V} \cdot \left(c0 \cdot c0\right)}
\] |
|---|---|
associate-*l/ [=>]40.0 | \[ \sqrt{\color{blue}{\frac{A \cdot \left(c0 \cdot c0\right)}{\ell \cdot V}}}
\] |
*-commutative [<=]40.0 | \[ \sqrt{\frac{A \cdot \left(c0 \cdot c0\right)}{\color{blue}{V \cdot \ell}}}
\] |
times-frac [=>]43.1 | \[ \sqrt{\color{blue}{\frac{A}{V} \cdot \frac{c0 \cdot c0}{\ell}}}
\] |
Applied egg-rr49.9%
[Start]43.1 | \[ \sqrt{\frac{A}{V} \cdot \frac{c0 \cdot c0}{\ell}}
\] |
|---|---|
associate-*r/ [=>]48.0 | \[ \sqrt{\color{blue}{\frac{\frac{A}{V} \cdot \left(c0 \cdot c0\right)}{\ell}}}
\] |
add-sqr-sqrt [=>]47.3 | \[ \sqrt{\frac{\color{blue}{\left(\sqrt{\frac{A}{V}} \cdot \sqrt{\frac{A}{V}}\right)} \cdot \left(c0 \cdot c0\right)}{\ell}}
\] |
unswap-sqr [=>]47.8 | \[ \sqrt{\frac{\color{blue}{\left(\sqrt{\frac{A}{V}} \cdot c0\right) \cdot \left(\sqrt{\frac{A}{V}} \cdot c0\right)}}{\ell}}
\] |
add-sqr-sqrt [=>]21.9 | \[ \sqrt{\frac{\left(\sqrt{\frac{A}{V}} \cdot c0\right) \cdot \left(\sqrt{\frac{A}{V}} \cdot c0\right)}{\color{blue}{\sqrt{\ell} \cdot \sqrt{\ell}}}}
\] |
frac-times [<=]21.9 | \[ \sqrt{\color{blue}{\frac{\sqrt{\frac{A}{V}} \cdot c0}{\sqrt{\ell}} \cdot \frac{\sqrt{\frac{A}{V}} \cdot c0}{\sqrt{\ell}}}}
\] |
associate-*l/ [<=]21.7 | \[ \sqrt{\color{blue}{\left(\frac{\sqrt{\frac{A}{V}}}{\sqrt{\ell}} \cdot c0\right)} \cdot \frac{\sqrt{\frac{A}{V}} \cdot c0}{\sqrt{\ell}}}
\] |
associate-*l/ [<=]21.7 | \[ \sqrt{\left(\frac{\sqrt{\frac{A}{V}}}{\sqrt{\ell}} \cdot c0\right) \cdot \color{blue}{\left(\frac{\sqrt{\frac{A}{V}}}{\sqrt{\ell}} \cdot c0\right)}}
\] |
sqrt-unprod [<=]33.1 | \[ \color{blue}{\sqrt{\frac{\sqrt{\frac{A}{V}}}{\sqrt{\ell}} \cdot c0} \cdot \sqrt{\frac{\sqrt{\frac{A}{V}}}{\sqrt{\ell}} \cdot c0}}
\] |
add-sqr-sqrt [<=]49.6 | \[ \color{blue}{\frac{\sqrt{\frac{A}{V}}}{\sqrt{\ell}} \cdot c0}
\] |
associate-*l/ [=>]49.7 | \[ \color{blue}{\frac{\sqrt{\frac{A}{V}} \cdot c0}{\sqrt{\ell}}}
\] |
div-inv [=>]49.7 | \[ \color{blue}{\left(\sqrt{\frac{A}{V}} \cdot c0\right) \cdot \frac{1}{\sqrt{\ell}}}
\] |
pow1/2 [=>]49.7 | \[ \left(\sqrt{\frac{A}{V}} \cdot c0\right) \cdot \frac{1}{\color{blue}{{\ell}^{0.5}}}
\] |
pow-flip [=>]49.9 | \[ \left(\sqrt{\frac{A}{V}} \cdot c0\right) \cdot \color{blue}{{\ell}^{\left(-0.5\right)}}
\] |
metadata-eval [=>]49.9 | \[ \left(\sqrt{\frac{A}{V}} \cdot c0\right) \cdot {\ell}^{\color{blue}{-0.5}}
\] |
if -inf.0 < (*.f64 V l) < -1.97626e-323Initial program 83.8%
Applied egg-rr98.8%
[Start]83.8 | \[ c0 \cdot \sqrt{\frac{A}{V \cdot \ell}}
\] |
|---|---|
frac-2neg [=>]83.8 | \[ c0 \cdot \sqrt{\color{blue}{\frac{-A}{-V \cdot \ell}}}
\] |
sqrt-div [=>]98.8 | \[ c0 \cdot \color{blue}{\frac{\sqrt{-A}}{\sqrt{-V \cdot \ell}}}
\] |
*-commutative [=>]98.8 | \[ c0 \cdot \frac{\sqrt{-A}}{\sqrt{-\color{blue}{\ell \cdot V}}}
\] |
distribute-rgt-neg-in [=>]98.8 | \[ c0 \cdot \frac{\sqrt{-A}}{\sqrt{\color{blue}{\ell \cdot \left(-V\right)}}}
\] |
if -1.97626e-323 < (*.f64 V l) < 3.99996e-320Initial program 35.9%
Applied egg-rr50.5%
[Start]35.9 | \[ c0 \cdot \sqrt{\frac{A}{V \cdot \ell}}
\] |
|---|---|
pow1/2 [=>]35.9 | \[ c0 \cdot \color{blue}{{\left(\frac{A}{V \cdot \ell}\right)}^{0.5}}
\] |
clear-num [=>]35.9 | \[ c0 \cdot {\color{blue}{\left(\frac{1}{\frac{V \cdot \ell}{A}}\right)}}^{0.5}
\] |
inv-pow [=>]35.9 | \[ c0 \cdot {\color{blue}{\left({\left(\frac{V \cdot \ell}{A}\right)}^{-1}\right)}}^{0.5}
\] |
pow-pow [=>]35.9 | \[ c0 \cdot \color{blue}{{\left(\frac{V \cdot \ell}{A}\right)}^{\left(-1 \cdot 0.5\right)}}
\] |
associate-/l* [=>]50.5 | \[ c0 \cdot {\color{blue}{\left(\frac{V}{\frac{A}{\ell}}\right)}}^{\left(-1 \cdot 0.5\right)}
\] |
metadata-eval [=>]50.5 | \[ c0 \cdot {\left(\frac{V}{\frac{A}{\ell}}\right)}^{\color{blue}{-0.5}}
\] |
Simplified35.9%
[Start]50.5 | \[ c0 \cdot {\left(\frac{V}{\frac{A}{\ell}}\right)}^{-0.5}
\] |
|---|---|
associate-/l* [<=]35.9 | \[ c0 \cdot {\color{blue}{\left(\frac{V \cdot \ell}{A}\right)}}^{-0.5}
\] |
Applied egg-rr50.5%
[Start]35.9 | \[ c0 \cdot {\left(\frac{V \cdot \ell}{A}\right)}^{-0.5}
\] |
|---|---|
associate-*r/ [<=]50.4 | \[ c0 \cdot {\color{blue}{\left(V \cdot \frac{\ell}{A}\right)}}^{-0.5}
\] |
metadata-eval [<=]50.4 | \[ c0 \cdot {\left(V \cdot \frac{\ell}{A}\right)}^{\color{blue}{\left(-0.5\right)}}
\] |
pow-flip [<=]50.5 | \[ c0 \cdot \color{blue}{\frac{1}{{\left(V \cdot \frac{\ell}{A}\right)}^{0.5}}}
\] |
pow1/2 [<=]50.5 | \[ c0 \cdot \frac{1}{\color{blue}{\sqrt{V \cdot \frac{\ell}{A}}}}
\] |
un-div-inv [=>]50.5 | \[ \color{blue}{\frac{c0}{\sqrt{V \cdot \frac{\ell}{A}}}}
\] |
Simplified50.6%
[Start]50.5 | \[ \frac{c0}{\sqrt{V \cdot \frac{\ell}{A}}}
\] |
|---|---|
associate-*r/ [=>]35.9 | \[ \frac{c0}{\sqrt{\color{blue}{\frac{V \cdot \ell}{A}}}}
\] |
associate-*l/ [<=]50.6 | \[ \frac{c0}{\sqrt{\color{blue}{\frac{V}{A} \cdot \ell}}}
\] |
*-commutative [<=]50.6 | \[ \frac{c0}{\sqrt{\color{blue}{\ell \cdot \frac{V}{A}}}}
\] |
Applied egg-rr24.7%
[Start]50.6 | \[ \frac{c0}{\sqrt{\ell \cdot \frac{V}{A}}}
\] |
|---|---|
*-un-lft-identity [=>]50.6 | \[ \frac{\color{blue}{1 \cdot c0}}{\sqrt{\ell \cdot \frac{V}{A}}}
\] |
add-sqr-sqrt [=>]50.4 | \[ \frac{1 \cdot c0}{\color{blue}{\sqrt{\sqrt{\ell \cdot \frac{V}{A}}} \cdot \sqrt{\sqrt{\ell \cdot \frac{V}{A}}}}}
\] |
times-frac [=>]50.4 | \[ \color{blue}{\frac{1}{\sqrt{\sqrt{\ell \cdot \frac{V}{A}}}} \cdot \frac{c0}{\sqrt{\sqrt{\ell \cdot \frac{V}{A}}}}}
\] |
Simplified41.4%
[Start]24.7 | \[ \sqrt{\frac{A}{\ell \cdot V} \cdot \left(c0 \cdot c0\right)}
\] |
|---|---|
associate-*l/ [=>]23.2 | \[ \sqrt{\color{blue}{\frac{A \cdot \left(c0 \cdot c0\right)}{\ell \cdot V}}}
\] |
*-commutative [<=]23.2 | \[ \sqrt{\frac{A \cdot \left(c0 \cdot c0\right)}{\color{blue}{V \cdot \ell}}}
\] |
times-frac [=>]41.4 | \[ \sqrt{\color{blue}{\frac{A}{V} \cdot \frac{c0 \cdot c0}{\ell}}}
\] |
Applied egg-rr57.0%
[Start]41.4 | \[ \sqrt{\frac{A}{V} \cdot \frac{c0 \cdot c0}{\ell}}
\] |
|---|---|
associate-*l/ [=>]40.9 | \[ \sqrt{\color{blue}{\frac{A \cdot \frac{c0 \cdot c0}{\ell}}{V}}}
\] |
associate-/l* [=>]57.0 | \[ \sqrt{\frac{A \cdot \color{blue}{\frac{c0}{\frac{\ell}{c0}}}}{V}}
\] |
if 3.99996e-320 < (*.f64 V l) Initial program 82.3%
Applied egg-rr91.3%
[Start]82.3 | \[ c0 \cdot \sqrt{\frac{A}{V \cdot \ell}}
\] |
|---|---|
sqrt-div [=>]94.9 | \[ c0 \cdot \color{blue}{\frac{\sqrt{A}}{\sqrt{V \cdot \ell}}}
\] |
associate-*r/ [=>]91.3 | \[ \color{blue}{\frac{c0 \cdot \sqrt{A}}{\sqrt{V \cdot \ell}}}
\] |
Simplified95.0%
[Start]91.3 | \[ \frac{c0 \cdot \sqrt{A}}{\sqrt{V \cdot \ell}}
\] |
|---|---|
associate-/l* [=>]95.0 | \[ \color{blue}{\frac{c0}{\frac{\sqrt{V \cdot \ell}}{\sqrt{A}}}}
\] |
Final simplification89.7%
| Alternative 1 | |
|---|---|
| Accuracy | 78.4% |
| Cost | 27724 |
| Alternative 2 | |
|---|---|
| Accuracy | 78.1% |
| Cost | 27724 |
| Alternative 3 | |
|---|---|
| Accuracy | 81.4% |
| Cost | 13380 |
| Alternative 4 | |
|---|---|
| Accuracy | 83.7% |
| Cost | 13380 |
| Alternative 5 | |
|---|---|
| Accuracy | 79.2% |
| Cost | 7625 |
| Alternative 6 | |
|---|---|
| Accuracy | 78.1% |
| Cost | 7625 |
| Alternative 7 | |
|---|---|
| Accuracy | 75.3% |
| Cost | 7300 |
| Alternative 8 | |
|---|---|
| Accuracy | 75.8% |
| Cost | 7236 |
| Alternative 9 | |
|---|---|
| Accuracy | 73.2% |
| Cost | 6848 |
herbie shell --seed 2023162
(FPCore (c0 A V l)
:name "Henrywood and Agarwal, Equation (3)"
:precision binary64
(* c0 (sqrt (/ A (* V l)))))