| Alternative 1 | |
|---|---|
| Error | 17.9 |
| Cost | 30541 |
(FPCore (c0 w h D d M)
:precision binary64
(*
(/ c0 (* 2.0 w))
(+
(/ (* c0 (* d d)) (* (* w h) (* D D)))
(sqrt
(-
(*
(/ (* c0 (* d d)) (* (* w h) (* D D)))
(/ (* c0 (* d d)) (* (* w h) (* D D))))
(* M M))))))(FPCore (c0 w h D d M)
:precision binary64
(if (<= h -4.5e+152)
(* 0.25 (* (* D (* (/ M d) (/ h (/ d M)))) (* (cbrt D) (pow (cbrt D) 2.0))))
(if (<= h 3e-285)
(* 0.25 (* (/ (* h M) (/ d D)) (* D (/ M d))))
(pow (/ (* M (* D (sqrt h))) (/ d 0.5)) 2.0))))double code(double c0, double w, double h, double D, double d, double M) {
return (c0 / (2.0 * w)) * (((c0 * (d * d)) / ((w * h) * (D * D))) + sqrt(((((c0 * (d * d)) / ((w * h) * (D * D))) * ((c0 * (d * d)) / ((w * h) * (D * D)))) - (M * M))));
}
double code(double c0, double w, double h, double D, double d, double M) {
double tmp;
if (h <= -4.5e+152) {
tmp = 0.25 * ((D * ((M / d) * (h / (d / M)))) * (cbrt(D) * pow(cbrt(D), 2.0)));
} else if (h <= 3e-285) {
tmp = 0.25 * (((h * M) / (d / D)) * (D * (M / d)));
} else {
tmp = pow(((M * (D * sqrt(h))) / (d / 0.5)), 2.0);
}
return tmp;
}
public static double code(double c0, double w, double h, double D, double d, double M) {
return (c0 / (2.0 * w)) * (((c0 * (d * d)) / ((w * h) * (D * D))) + Math.sqrt(((((c0 * (d * d)) / ((w * h) * (D * D))) * ((c0 * (d * d)) / ((w * h) * (D * D)))) - (M * M))));
}
public static double code(double c0, double w, double h, double D, double d, double M) {
double tmp;
if (h <= -4.5e+152) {
tmp = 0.25 * ((D * ((M / d) * (h / (d / M)))) * (Math.cbrt(D) * Math.pow(Math.cbrt(D), 2.0)));
} else if (h <= 3e-285) {
tmp = 0.25 * (((h * M) / (d / D)) * (D * (M / d)));
} else {
tmp = Math.pow(((M * (D * Math.sqrt(h))) / (d / 0.5)), 2.0);
}
return tmp;
}
function code(c0, w, h, D, d, M) return Float64(Float64(c0 / Float64(2.0 * w)) * Float64(Float64(Float64(c0 * Float64(d * d)) / Float64(Float64(w * h) * Float64(D * D))) + sqrt(Float64(Float64(Float64(Float64(c0 * Float64(d * d)) / Float64(Float64(w * h) * Float64(D * D))) * Float64(Float64(c0 * Float64(d * d)) / Float64(Float64(w * h) * Float64(D * D)))) - Float64(M * M))))) end
function code(c0, w, h, D, d, M) tmp = 0.0 if (h <= -4.5e+152) tmp = Float64(0.25 * Float64(Float64(D * Float64(Float64(M / d) * Float64(h / Float64(d / M)))) * Float64(cbrt(D) * (cbrt(D) ^ 2.0)))); elseif (h <= 3e-285) tmp = Float64(0.25 * Float64(Float64(Float64(h * M) / Float64(d / D)) * Float64(D * Float64(M / d)))); else tmp = Float64(Float64(M * Float64(D * sqrt(h))) / Float64(d / 0.5)) ^ 2.0; end return tmp end
code[c0_, w_, h_, D_, d_, M_] := N[(N[(c0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision] * N[(N[(N[(c0 * N[(d * d), $MachinePrecision]), $MachinePrecision] / N[(N[(w * h), $MachinePrecision] * N[(D * D), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[Sqrt[N[(N[(N[(N[(c0 * N[(d * d), $MachinePrecision]), $MachinePrecision] / N[(N[(w * h), $MachinePrecision] * N[(D * D), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[(c0 * N[(d * d), $MachinePrecision]), $MachinePrecision] / N[(N[(w * h), $MachinePrecision] * N[(D * D), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(M * M), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[c0_, w_, h_, D_, d_, M_] := If[LessEqual[h, -4.5e+152], N[(0.25 * N[(N[(D * N[(N[(M / d), $MachinePrecision] * N[(h / N[(d / M), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[Power[D, 1/3], $MachinePrecision] * N[Power[N[Power[D, 1/3], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[h, 3e-285], N[(0.25 * N[(N[(N[(h * M), $MachinePrecision] / N[(d / D), $MachinePrecision]), $MachinePrecision] * N[(D * N[(M / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Power[N[(N[(M * N[(D * N[Sqrt[h], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(d / 0.5), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]]]
\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right)
\begin{array}{l}
\mathbf{if}\;h \leq -4.5 \cdot 10^{+152}:\\
\;\;\;\;0.25 \cdot \left(\left(D \cdot \left(\frac{M}{d} \cdot \frac{h}{\frac{d}{M}}\right)\right) \cdot \left(\sqrt[3]{D} \cdot {\left(\sqrt[3]{D}\right)}^{2}\right)\right)\\
\mathbf{elif}\;h \leq 3 \cdot 10^{-285}:\\
\;\;\;\;0.25 \cdot \left(\frac{h \cdot M}{\frac{d}{D}} \cdot \left(D \cdot \frac{M}{d}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;{\left(\frac{M \cdot \left(D \cdot \sqrt{h}\right)}{\frac{d}{0.5}}\right)}^{2}\\
\end{array}
Results
if h < -4.5000000000000001e152Initial program 61.0
Simplified61.2
[Start]61.0 | \[ \frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right)
\] |
|---|---|
times-frac [=>]61.8 | \[ \frac{c0}{2 \cdot w} \cdot \left(\color{blue}{\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right)
\] |
fma-neg [=>]61.8 | \[ \frac{c0}{2 \cdot w} \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D} + \sqrt{\color{blue}{\mathsf{fma}\left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}, \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}, -M \cdot M\right)}}\right)
\] |
times-frac [=>]61.6 | \[ \frac{c0}{2 \cdot w} \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D} + \sqrt{\mathsf{fma}\left(\color{blue}{\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}}, \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}, -M \cdot M\right)}\right)
\] |
times-frac [=>]61.2 | \[ \frac{c0}{2 \cdot w} \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D} + \sqrt{\mathsf{fma}\left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}, \color{blue}{\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}}, -M \cdot M\right)}\right)
\] |
Taylor expanded in c0 around -inf 60.8
Simplified44.6
[Start]60.8 | \[ -0.5 \cdot \frac{\left(\frac{{d}^{2}}{{D}^{2} \cdot \left(w \cdot h\right)} + -1 \cdot \frac{{d}^{2}}{{D}^{2} \cdot \left(w \cdot h\right)}\right) \cdot {c0}^{2}}{w} + 0.25 \cdot \frac{{D}^{2} \cdot \left({M}^{2} \cdot h\right)}{{d}^{2}}
\] |
|---|
Taylor expanded in w around 0 35.0
Applied egg-rr30.1
Simplified23.6
[Start]30.1 | \[ 0 + 0.25 \cdot \left(\frac{\frac{M \cdot \left(h \cdot M\right)}{\frac{d}{D}}}{\frac{d}{{\left(\sqrt[3]{D}\right)}^{2}}} \cdot \sqrt[3]{D}\right)
\] |
|---|---|
associate-/r/ [=>]31.4 | \[ 0 + 0.25 \cdot \left(\color{blue}{\left(\frac{\frac{M \cdot \left(h \cdot M\right)}{\frac{d}{D}}}{d} \cdot {\left(\sqrt[3]{D}\right)}^{2}\right)} \cdot \sqrt[3]{D}\right)
\] |
associate-*l* [=>]31.4 | \[ 0 + 0.25 \cdot \color{blue}{\left(\frac{\frac{M \cdot \left(h \cdot M\right)}{\frac{d}{D}}}{d} \cdot \left({\left(\sqrt[3]{D}\right)}^{2} \cdot \sqrt[3]{D}\right)\right)}
\] |
associate-/r/ [=>]31.7 | \[ 0 + 0.25 \cdot \left(\frac{\color{blue}{\frac{M \cdot \left(h \cdot M\right)}{d} \cdot D}}{d} \cdot \left({\left(\sqrt[3]{D}\right)}^{2} \cdot \sqrt[3]{D}\right)\right)
\] |
associate-*l/ [<=]33.2 | \[ 0 + 0.25 \cdot \left(\color{blue}{\left(\frac{\frac{M \cdot \left(h \cdot M\right)}{d}}{d} \cdot D\right)} \cdot \left({\left(\sqrt[3]{D}\right)}^{2} \cdot \sqrt[3]{D}\right)\right)
\] |
associate-/r* [<=]35.3 | \[ 0 + 0.25 \cdot \left(\left(\color{blue}{\frac{M \cdot \left(h \cdot M\right)}{d \cdot d}} \cdot D\right) \cdot \left({\left(\sqrt[3]{D}\right)}^{2} \cdot \sqrt[3]{D}\right)\right)
\] |
*-commutative [=>]35.3 | \[ 0 + 0.25 \cdot \left(\color{blue}{\left(D \cdot \frac{M \cdot \left(h \cdot M\right)}{d \cdot d}\right)} \cdot \left({\left(\sqrt[3]{D}\right)}^{2} \cdot \sqrt[3]{D}\right)\right)
\] |
times-frac [=>]30.7 | \[ 0 + 0.25 \cdot \left(\left(D \cdot \color{blue}{\left(\frac{M}{d} \cdot \frac{h \cdot M}{d}\right)}\right) \cdot \left({\left(\sqrt[3]{D}\right)}^{2} \cdot \sqrt[3]{D}\right)\right)
\] |
associate-/l* [=>]23.6 | \[ 0 + 0.25 \cdot \left(\left(D \cdot \left(\frac{M}{d} \cdot \color{blue}{\frac{h}{\frac{d}{M}}}\right)\right) \cdot \left({\left(\sqrt[3]{D}\right)}^{2} \cdot \sqrt[3]{D}\right)\right)
\] |
if -4.5000000000000001e152 < h < 3.00000000000000003e-285Initial program 59.4
Simplified59.1
[Start]59.4 | \[ \frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right)
\] |
|---|---|
times-frac [=>]60.5 | \[ \frac{c0}{2 \cdot w} \cdot \left(\color{blue}{\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right)
\] |
fma-neg [=>]60.5 | \[ \frac{c0}{2 \cdot w} \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D} + \sqrt{\color{blue}{\mathsf{fma}\left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}, \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}, -M \cdot M\right)}}\right)
\] |
times-frac [=>]60.3 | \[ \frac{c0}{2 \cdot w} \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D} + \sqrt{\mathsf{fma}\left(\color{blue}{\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}}, \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}, -M \cdot M\right)}\right)
\] |
times-frac [=>]59.1 | \[ \frac{c0}{2 \cdot w} \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D} + \sqrt{\mathsf{fma}\left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}, \color{blue}{\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}}, -M \cdot M\right)}\right)
\] |
Taylor expanded in c0 around -inf 60.5
Simplified37.1
[Start]60.5 | \[ -0.5 \cdot \frac{\left(\frac{{d}^{2}}{{D}^{2} \cdot \left(w \cdot h\right)} + -1 \cdot \frac{{d}^{2}}{{D}^{2} \cdot \left(w \cdot h\right)}\right) \cdot {c0}^{2}}{w} + 0.25 \cdot \frac{{D}^{2} \cdot \left({M}^{2} \cdot h\right)}{{d}^{2}}
\] |
|---|
Taylor expanded in w around 0 27.0
Applied egg-rr17.9
if 3.00000000000000003e-285 < h Initial program 59.6
Simplified59.2
[Start]59.6 | \[ \frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right)
\] |
|---|---|
times-frac [=>]60.4 | \[ \frac{c0}{2 \cdot w} \cdot \left(\color{blue}{\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right)
\] |
fma-neg [=>]60.4 | \[ \frac{c0}{2 \cdot w} \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D} + \sqrt{\color{blue}{\mathsf{fma}\left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}, \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}, -M \cdot M\right)}}\right)
\] |
times-frac [=>]60.3 | \[ \frac{c0}{2 \cdot w} \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D} + \sqrt{\mathsf{fma}\left(\color{blue}{\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}}, \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}, -M \cdot M\right)}\right)
\] |
times-frac [=>]59.2 | \[ \frac{c0}{2 \cdot w} \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D} + \sqrt{\mathsf{fma}\left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}, \color{blue}{\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}}, -M \cdot M\right)}\right)
\] |
Taylor expanded in c0 around -inf 60.2
Simplified38.4
[Start]60.2 | \[ -0.5 \cdot \frac{\left(\frac{{d}^{2}}{{D}^{2} \cdot \left(w \cdot h\right)} + -1 \cdot \frac{{d}^{2}}{{D}^{2} \cdot \left(w \cdot h\right)}\right) \cdot {c0}^{2}}{w} + 0.25 \cdot \frac{{D}^{2} \cdot \left({M}^{2} \cdot h\right)}{{d}^{2}}
\] |
|---|
Taylor expanded in w around 0 29.3
Applied egg-rr28.0
Simplified18.2
[Start]28.0 | \[ 0 + \left(e^{\mathsf{log1p}\left(0.25 \cdot {\left(\frac{M \cdot \sqrt{h}}{d} \cdot D\right)}^{2}\right)} - 1\right)
\] |
|---|---|
expm1-def [=>]18.8 | \[ 0 + \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(0.25 \cdot {\left(\frac{M \cdot \sqrt{h}}{d} \cdot D\right)}^{2}\right)\right)}
\] |
expm1-log1p [=>]18.4 | \[ 0 + \color{blue}{0.25 \cdot {\left(\frac{M \cdot \sqrt{h}}{d} \cdot D\right)}^{2}}
\] |
metadata-eval [<=]18.4 | \[ 0 + \color{blue}{\left(0.5 \cdot 0.5\right)} \cdot {\left(\frac{M \cdot \sqrt{h}}{d} \cdot D\right)}^{2}
\] |
unpow2 [=>]18.4 | \[ 0 + \left(0.5 \cdot 0.5\right) \cdot \color{blue}{\left(\left(\frac{M \cdot \sqrt{h}}{d} \cdot D\right) \cdot \left(\frac{M \cdot \sqrt{h}}{d} \cdot D\right)\right)}
\] |
swap-sqr [<=]18.4 | \[ 0 + \color{blue}{\left(0.5 \cdot \left(\frac{M \cdot \sqrt{h}}{d} \cdot D\right)\right) \cdot \left(0.5 \cdot \left(\frac{M \cdot \sqrt{h}}{d} \cdot D\right)\right)}
\] |
unpow2 [<=]18.4 | \[ 0 + \color{blue}{{\left(0.5 \cdot \left(\frac{M \cdot \sqrt{h}}{d} \cdot D\right)\right)}^{2}}
\] |
*-commutative [=>]18.4 | \[ 0 + {\color{blue}{\left(\left(\frac{M \cdot \sqrt{h}}{d} \cdot D\right) \cdot 0.5\right)}}^{2}
\] |
associate-*l/ [=>]18.5 | \[ 0 + {\left(\color{blue}{\frac{\left(M \cdot \sqrt{h}\right) \cdot D}{d}} \cdot 0.5\right)}^{2}
\] |
associate-*l/ [=>]18.5 | \[ 0 + {\color{blue}{\left(\frac{\left(\left(M \cdot \sqrt{h}\right) \cdot D\right) \cdot 0.5}{d}\right)}}^{2}
\] |
associate-/l* [=>]18.5 | \[ 0 + {\color{blue}{\left(\frac{\left(M \cdot \sqrt{h}\right) \cdot D}{\frac{d}{0.5}}\right)}}^{2}
\] |
associate-*l* [=>]18.2 | \[ 0 + {\left(\frac{\color{blue}{M \cdot \left(\sqrt{h} \cdot D\right)}}{\frac{d}{0.5}}\right)}^{2}
\] |
*-commutative [=>]18.2 | \[ 0 + {\left(\frac{M \cdot \color{blue}{\left(D \cdot \sqrt{h}\right)}}{\frac{d}{0.5}}\right)}^{2}
\] |
Final simplification18.5
| Alternative 1 | |
|---|---|
| Error | 17.9 |
| Cost | 30541 |
| Alternative 2 | |
|---|---|
| Error | 28.6 |
| Cost | 1621 |
| Alternative 3 | |
|---|---|
| Error | 27.6 |
| Cost | 1620 |
| Alternative 4 | |
|---|---|
| Error | 30.2 |
| Cost | 1489 |
| Alternative 5 | |
|---|---|
| Error | 30.4 |
| Cost | 1488 |
| Alternative 6 | |
|---|---|
| Error | 23.6 |
| Cost | 1481 |
| Alternative 7 | |
|---|---|
| Error | 29.1 |
| Cost | 1480 |
| Alternative 8 | |
|---|---|
| Error | 21.3 |
| Cost | 1480 |
| Alternative 9 | |
|---|---|
| Error | 31.9 |
| Cost | 64 |
herbie shell --seed 2023073
(FPCore (c0 w h D d M)
:name "Henrywood and Agarwal, Equation (13)"
:precision binary64
(* (/ c0 (* 2.0 w)) (+ (/ (* c0 (* d d)) (* (* w h) (* D D))) (sqrt (- (* (/ (* c0 (* d d)) (* (* w h) (* D D))) (/ (* c0 (* d d)) (* (* w h) (* D D)))) (* M M))))))