| Alternative 1 | |
|---|---|
| Error | 13.14% |
| Cost | 7744 |
(FPCore (w0 M D h l d) :precision binary64 (* w0 (sqrt (- 1.0 (* (pow (/ (* M D) (* 2.0 d)) 2.0) (/ h l))))))
(FPCore (w0 M D h l d)
:precision binary64
(let* ((t_0 (* (/ D d) M)))
(if (<= (/ h l) (- INFINITY))
(*
w0
(sqrt (+ 1.0 (* (* M (* h (/ D (* l (/ (/ (* d d) D) M))))) -0.25))))
(if (<= (/ h l) -6e-321)
(* w0 (sqrt (+ 1.0 (* (* t_0 (* t_0 (/ h l))) -0.25))))
w0))))double code(double w0, double M, double D, double h, double l, double d) {
return w0 * sqrt((1.0 - (pow(((M * D) / (2.0 * d)), 2.0) * (h / l))));
}
double code(double w0, double M, double D, double h, double l, double d) {
double t_0 = (D / d) * M;
double tmp;
if ((h / l) <= -((double) INFINITY)) {
tmp = w0 * sqrt((1.0 + ((M * (h * (D / (l * (((d * d) / D) / M))))) * -0.25)));
} else if ((h / l) <= -6e-321) {
tmp = w0 * sqrt((1.0 + ((t_0 * (t_0 * (h / l))) * -0.25)));
} else {
tmp = w0;
}
return tmp;
}
public static double code(double w0, double M, double D, double h, double l, double d) {
return w0 * Math.sqrt((1.0 - (Math.pow(((M * D) / (2.0 * d)), 2.0) * (h / l))));
}
public static double code(double w0, double M, double D, double h, double l, double d) {
double t_0 = (D / d) * M;
double tmp;
if ((h / l) <= -Double.POSITIVE_INFINITY) {
tmp = w0 * Math.sqrt((1.0 + ((M * (h * (D / (l * (((d * d) / D) / M))))) * -0.25)));
} else if ((h / l) <= -6e-321) {
tmp = w0 * Math.sqrt((1.0 + ((t_0 * (t_0 * (h / l))) * -0.25)));
} else {
tmp = w0;
}
return tmp;
}
def code(w0, M, D, h, l, d): return w0 * math.sqrt((1.0 - (math.pow(((M * D) / (2.0 * d)), 2.0) * (h / l))))
def code(w0, M, D, h, l, d): t_0 = (D / d) * M tmp = 0 if (h / l) <= -math.inf: tmp = w0 * math.sqrt((1.0 + ((M * (h * (D / (l * (((d * d) / D) / M))))) * -0.25))) elif (h / l) <= -6e-321: tmp = w0 * math.sqrt((1.0 + ((t_0 * (t_0 * (h / l))) * -0.25))) else: tmp = w0 return tmp
function code(w0, M, D, h, l, d) return Float64(w0 * sqrt(Float64(1.0 - Float64((Float64(Float64(M * D) / Float64(2.0 * d)) ^ 2.0) * Float64(h / l))))) end
function code(w0, M, D, h, l, d) t_0 = Float64(Float64(D / d) * M) tmp = 0.0 if (Float64(h / l) <= Float64(-Inf)) tmp = Float64(w0 * sqrt(Float64(1.0 + Float64(Float64(M * Float64(h * Float64(D / Float64(l * Float64(Float64(Float64(d * d) / D) / M))))) * -0.25)))); elseif (Float64(h / l) <= -6e-321) tmp = Float64(w0 * sqrt(Float64(1.0 + Float64(Float64(t_0 * Float64(t_0 * Float64(h / l))) * -0.25)))); else tmp = w0; end return tmp end
function tmp = code(w0, M, D, h, l, d) tmp = w0 * sqrt((1.0 - ((((M * D) / (2.0 * d)) ^ 2.0) * (h / l)))); end
function tmp_2 = code(w0, M, D, h, l, d) t_0 = (D / d) * M; tmp = 0.0; if ((h / l) <= -Inf) tmp = w0 * sqrt((1.0 + ((M * (h * (D / (l * (((d * d) / D) / M))))) * -0.25))); elseif ((h / l) <= -6e-321) tmp = w0 * sqrt((1.0 + ((t_0 * (t_0 * (h / l))) * -0.25))); else tmp = w0; end tmp_2 = tmp; end
code[w0_, M_, D_, h_, l_, d_] := N[(w0 * N[Sqrt[N[(1.0 - N[(N[Power[N[(N[(M * D), $MachinePrecision] / N[(2.0 * d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
code[w0_, M_, D_, h_, l_, d_] := Block[{t$95$0 = N[(N[(D / d), $MachinePrecision] * M), $MachinePrecision]}, If[LessEqual[N[(h / l), $MachinePrecision], (-Infinity)], N[(w0 * N[Sqrt[N[(1.0 + N[(N[(M * N[(h * N[(D / N[(l * N[(N[(N[(d * d), $MachinePrecision] / D), $MachinePrecision] / M), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(h / l), $MachinePrecision], -6e-321], N[(w0 * N[Sqrt[N[(1.0 + N[(N[(t$95$0 * N[(t$95$0 * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], w0]]]
w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}}
\begin{array}{l}
t_0 := \frac{D}{d} \cdot M\\
\mathbf{if}\;\frac{h}{\ell} \leq -\infty:\\
\;\;\;\;w0 \cdot \sqrt{1 + \left(M \cdot \left(h \cdot \frac{D}{\ell \cdot \frac{\frac{d \cdot d}{D}}{M}}\right)\right) \cdot -0.25}\\
\mathbf{elif}\;\frac{h}{\ell} \leq -6 \cdot 10^{-321}:\\
\;\;\;\;w0 \cdot \sqrt{1 + \left(t_0 \cdot \left(t_0 \cdot \frac{h}{\ell}\right)\right) \cdot -0.25}\\
\mathbf{else}:\\
\;\;\;\;w0\\
\end{array}
Results
if (/.f64 h l) < -inf.0Initial program 100
Simplified100
[Start]100 | \[ w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}}
\] |
|---|---|
associate-*l/ [<=]100 | \[ w0 \cdot \sqrt{1 - {\color{blue}{\left(\frac{M}{2 \cdot d} \cdot D\right)}}^{2} \cdot \frac{h}{\ell}}
\] |
*-commutative [=>]100 | \[ w0 \cdot \sqrt{1 - {\color{blue}{\left(D \cdot \frac{M}{2 \cdot d}\right)}}^{2} \cdot \frac{h}{\ell}}
\] |
Taylor expanded in D around 0 68.03
Simplified51.8
[Start]68.03 | \[ w0 \cdot \sqrt{1 - 0.25 \cdot \frac{{D}^{2} \cdot \left({M}^{2} \cdot h\right)}{\ell \cdot {d}^{2}}}
\] |
|---|---|
*-commutative [=>]68.03 | \[ w0 \cdot \sqrt{1 - 0.25 \cdot \frac{{D}^{2} \cdot \color{blue}{\left(h \cdot {M}^{2}\right)}}{\ell \cdot {d}^{2}}}
\] |
*-commutative [=>]68.03 | \[ w0 \cdot \sqrt{1 - 0.25 \cdot \frac{{D}^{2} \cdot \left(h \cdot {M}^{2}\right)}{\color{blue}{{d}^{2} \cdot \ell}}}
\] |
*-commutative [<=]68.03 | \[ w0 \cdot \sqrt{1 - 0.25 \cdot \frac{{D}^{2} \cdot \color{blue}{\left({M}^{2} \cdot h\right)}}{{d}^{2} \cdot \ell}}
\] |
associate-*r* [=>]64.39 | \[ w0 \cdot \sqrt{1 - 0.25 \cdot \frac{\color{blue}{\left({D}^{2} \cdot {M}^{2}\right) \cdot h}}{{d}^{2} \cdot \ell}}
\] |
unpow2 [=>]64.39 | \[ w0 \cdot \sqrt{1 - 0.25 \cdot \frac{\left(\color{blue}{\left(D \cdot D\right)} \cdot {M}^{2}\right) \cdot h}{{d}^{2} \cdot \ell}}
\] |
unpow2 [=>]64.39 | \[ w0 \cdot \sqrt{1 - 0.25 \cdot \frac{\left(\left(D \cdot D\right) \cdot \color{blue}{\left(M \cdot M\right)}\right) \cdot h}{{d}^{2} \cdot \ell}}
\] |
swap-sqr [<=]55.97 | \[ w0 \cdot \sqrt{1 - 0.25 \cdot \frac{\color{blue}{\left(\left(D \cdot M\right) \cdot \left(D \cdot M\right)\right)} \cdot h}{{d}^{2} \cdot \ell}}
\] |
associate-*l* [=>]54.14 | \[ w0 \cdot \sqrt{1 - 0.25 \cdot \frac{\color{blue}{\left(D \cdot M\right) \cdot \left(\left(D \cdot M\right) \cdot h\right)}}{{d}^{2} \cdot \ell}}
\] |
unpow2 [=>]54.14 | \[ w0 \cdot \sqrt{1 - 0.25 \cdot \frac{\left(D \cdot M\right) \cdot \left(\left(D \cdot M\right) \cdot h\right)}{\color{blue}{\left(d \cdot d\right)} \cdot \ell}}
\] |
associate-*l* [=>]51.8 | \[ w0 \cdot \sqrt{1 - 0.25 \cdot \frac{\left(D \cdot M\right) \cdot \left(\left(D \cdot M\right) \cdot h\right)}{\color{blue}{d \cdot \left(d \cdot \ell\right)}}}
\] |
Applied egg-rr62.1
Taylor expanded in D around 0 66.05
Simplified51.75
[Start]66.05 | \[ w0 \cdot \sqrt{1 - 0.25 \cdot \left(\frac{{D}^{2} \cdot \left(h \cdot M\right)}{{d}^{2} \cdot \ell} \cdot M\right)}
\] |
|---|---|
*-commutative [=>]66.05 | \[ w0 \cdot \sqrt{1 - 0.25 \cdot \left(\frac{{D}^{2} \cdot \color{blue}{\left(M \cdot h\right)}}{{d}^{2} \cdot \ell} \cdot M\right)}
\] |
times-frac [=>]73.43 | \[ w0 \cdot \sqrt{1 - 0.25 \cdot \left(\color{blue}{\left(\frac{{D}^{2}}{{d}^{2}} \cdot \frac{M \cdot h}{\ell}\right)} \cdot M\right)}
\] |
unpow2 [=>]73.43 | \[ w0 \cdot \sqrt{1 - 0.25 \cdot \left(\left(\frac{{D}^{2}}{\color{blue}{d \cdot d}} \cdot \frac{M \cdot h}{\ell}\right) \cdot M\right)}
\] |
associate-/r* [=>]70.43 | \[ w0 \cdot \sqrt{1 - 0.25 \cdot \left(\left(\color{blue}{\frac{\frac{{D}^{2}}{d}}{d}} \cdot \frac{M \cdot h}{\ell}\right) \cdot M\right)}
\] |
unpow2 [=>]70.43 | \[ w0 \cdot \sqrt{1 - 0.25 \cdot \left(\left(\frac{\frac{\color{blue}{D \cdot D}}{d}}{d} \cdot \frac{M \cdot h}{\ell}\right) \cdot M\right)}
\] |
associate-*r/ [<=]67.37 | \[ w0 \cdot \sqrt{1 - 0.25 \cdot \left(\left(\frac{\color{blue}{D \cdot \frac{D}{d}}}{d} \cdot \frac{M \cdot h}{\ell}\right) \cdot M\right)}
\] |
associate-*l/ [<=]67.36 | \[ w0 \cdot \sqrt{1 - 0.25 \cdot \left(\left(\frac{D \cdot \frac{D}{d}}{d} \cdot \color{blue}{\left(\frac{M}{\ell} \cdot h\right)}\right) \cdot M\right)}
\] |
associate-*r* [=>]52.07 | \[ w0 \cdot \sqrt{1 - 0.25 \cdot \left(\color{blue}{\left(\left(\frac{D \cdot \frac{D}{d}}{d} \cdot \frac{M}{\ell}\right) \cdot h\right)} \cdot M\right)}
\] |
associate-/r/ [<=]51.38 | \[ w0 \cdot \sqrt{1 - 0.25 \cdot \left(\left(\color{blue}{\frac{D \cdot \frac{D}{d}}{\frac{d}{\frac{M}{\ell}}}} \cdot h\right) \cdot M\right)}
\] |
*-commutative [=>]51.38 | \[ w0 \cdot \sqrt{1 - 0.25 \cdot \left(\color{blue}{\left(h \cdot \frac{D \cdot \frac{D}{d}}{\frac{d}{\frac{M}{\ell}}}\right)} \cdot M\right)}
\] |
associate-/l* [=>]51.16 | \[ w0 \cdot \sqrt{1 - 0.25 \cdot \left(\left(h \cdot \color{blue}{\frac{D}{\frac{\frac{d}{\frac{M}{\ell}}}{\frac{D}{d}}}}\right) \cdot M\right)}
\] |
associate-/l* [<=]54.09 | \[ w0 \cdot \sqrt{1 - 0.25 \cdot \left(\left(h \cdot \frac{D}{\color{blue}{\frac{\frac{d}{\frac{M}{\ell}} \cdot d}{D}}}\right) \cdot M\right)}
\] |
associate-*r/ [<=]51.16 | \[ w0 \cdot \sqrt{1 - 0.25 \cdot \left(\left(h \cdot \frac{D}{\color{blue}{\frac{d}{\frac{M}{\ell}} \cdot \frac{d}{D}}}\right) \cdot M\right)}
\] |
*-commutative [=>]51.16 | \[ w0 \cdot \sqrt{1 - 0.25 \cdot \left(\left(h \cdot \frac{D}{\color{blue}{\frac{d}{D} \cdot \frac{d}{\frac{M}{\ell}}}}\right) \cdot M\right)}
\] |
associate-/r/ [=>]45.91 | \[ w0 \cdot \sqrt{1 - 0.25 \cdot \left(\left(h \cdot \frac{D}{\frac{d}{D} \cdot \color{blue}{\left(\frac{d}{M} \cdot \ell\right)}}\right) \cdot M\right)}
\] |
associate-*r* [=>]45.89 | \[ w0 \cdot \sqrt{1 - 0.25 \cdot \left(\left(h \cdot \frac{D}{\color{blue}{\left(\frac{d}{D} \cdot \frac{d}{M}\right) \cdot \ell}}\right) \cdot M\right)}
\] |
*-commutative [=>]45.89 | \[ w0 \cdot \sqrt{1 - 0.25 \cdot \left(\left(h \cdot \frac{D}{\color{blue}{\ell \cdot \left(\frac{d}{D} \cdot \frac{d}{M}\right)}}\right) \cdot M\right)}
\] |
associate-*r/ [=>]47.73 | \[ w0 \cdot \sqrt{1 - 0.25 \cdot \left(\left(h \cdot \frac{D}{\ell \cdot \color{blue}{\frac{\frac{d}{D} \cdot d}{M}}}\right) \cdot M\right)}
\] |
associate-*l/ [=>]51.75 | \[ w0 \cdot \sqrt{1 - 0.25 \cdot \left(\left(h \cdot \frac{D}{\ell \cdot \frac{\color{blue}{\frac{d \cdot d}{D}}}{M}}\right) \cdot M\right)}
\] |
if -inf.0 < (/.f64 h l) < -5.99796e-321Initial program 22.16
Simplified21.96
[Start]22.16 | \[ w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}}
\] |
|---|---|
associate-*l/ [<=]21.96 | \[ w0 \cdot \sqrt{1 - {\color{blue}{\left(\frac{M}{2 \cdot d} \cdot D\right)}}^{2} \cdot \frac{h}{\ell}}
\] |
*-commutative [=>]21.96 | \[ w0 \cdot \sqrt{1 - {\color{blue}{\left(D \cdot \frac{M}{2 \cdot d}\right)}}^{2} \cdot \frac{h}{\ell}}
\] |
Taylor expanded in D around 0 57.55
Simplified37.61
[Start]57.55 | \[ w0 \cdot \sqrt{1 - 0.25 \cdot \frac{{D}^{2} \cdot \left({M}^{2} \cdot h\right)}{\ell \cdot {d}^{2}}}
\] |
|---|---|
*-commutative [=>]57.55 | \[ w0 \cdot \sqrt{1 - 0.25 \cdot \frac{{D}^{2} \cdot \color{blue}{\left(h \cdot {M}^{2}\right)}}{\ell \cdot {d}^{2}}}
\] |
*-commutative [=>]57.55 | \[ w0 \cdot \sqrt{1 - 0.25 \cdot \frac{{D}^{2} \cdot \left(h \cdot {M}^{2}\right)}{\color{blue}{{d}^{2} \cdot \ell}}}
\] |
*-commutative [<=]57.55 | \[ w0 \cdot \sqrt{1 - 0.25 \cdot \frac{{D}^{2} \cdot \color{blue}{\left({M}^{2} \cdot h\right)}}{{d}^{2} \cdot \ell}}
\] |
associate-*r* [=>]56.28 | \[ w0 \cdot \sqrt{1 - 0.25 \cdot \frac{\color{blue}{\left({D}^{2} \cdot {M}^{2}\right) \cdot h}}{{d}^{2} \cdot \ell}}
\] |
unpow2 [=>]56.28 | \[ w0 \cdot \sqrt{1 - 0.25 \cdot \frac{\left(\color{blue}{\left(D \cdot D\right)} \cdot {M}^{2}\right) \cdot h}{{d}^{2} \cdot \ell}}
\] |
unpow2 [=>]56.28 | \[ w0 \cdot \sqrt{1 - 0.25 \cdot \frac{\left(\left(D \cdot D\right) \cdot \color{blue}{\left(M \cdot M\right)}\right) \cdot h}{{d}^{2} \cdot \ell}}
\] |
swap-sqr [<=]43.64 | \[ w0 \cdot \sqrt{1 - 0.25 \cdot \frac{\color{blue}{\left(\left(D \cdot M\right) \cdot \left(D \cdot M\right)\right)} \cdot h}{{d}^{2} \cdot \ell}}
\] |
associate-*l* [=>]41.36 | \[ w0 \cdot \sqrt{1 - 0.25 \cdot \frac{\color{blue}{\left(D \cdot M\right) \cdot \left(\left(D \cdot M\right) \cdot h\right)}}{{d}^{2} \cdot \ell}}
\] |
unpow2 [=>]41.36 | \[ w0 \cdot \sqrt{1 - 0.25 \cdot \frac{\left(D \cdot M\right) \cdot \left(\left(D \cdot M\right) \cdot h\right)}{\color{blue}{\left(d \cdot d\right)} \cdot \ell}}
\] |
associate-*l* [=>]37.61 | \[ w0 \cdot \sqrt{1 - 0.25 \cdot \frac{\left(D \cdot M\right) \cdot \left(\left(D \cdot M\right) \cdot h\right)}{\color{blue}{d \cdot \left(d \cdot \ell\right)}}}
\] |
Applied egg-rr19.36
if -5.99796e-321 < (/.f64 h l) Initial program 11.35
Simplified11.42
[Start]11.35 | \[ w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}}
\] |
|---|---|
associate-*l/ [<=]11.42 | \[ w0 \cdot \sqrt{1 - {\color{blue}{\left(\frac{M}{2 \cdot d} \cdot D\right)}}^{2} \cdot \frac{h}{\ell}}
\] |
*-commutative [=>]11.42 | \[ w0 \cdot \sqrt{1 - {\color{blue}{\left(D \cdot \frac{M}{2 \cdot d}\right)}}^{2} \cdot \frac{h}{\ell}}
\] |
Taylor expanded in D around 0 3.75
Final simplification13.73
| Alternative 1 | |
|---|---|
| Error | 13.14% |
| Cost | 7744 |
| Alternative 2 | |
|---|---|
| Error | 21.3% |
| Cost | 64 |
herbie shell --seed 2023090
(FPCore (w0 M D h l d)
:name "Henrywood and Agarwal, Equation (9a)"
:precision binary64
(* w0 (sqrt (- 1.0 (* (pow (/ (* M D) (* 2.0 d)) 2.0) (/ h l))))))