
(FPCore (w0 M D h l d) :precision binary64 (* 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) {
return w0 * sqrt((1.0 - (pow(((M * D) / (2.0 * d)), 2.0) * (h / l))));
}
real(8) function code(w0, m, d, h, l, d_1)
real(8), intent (in) :: w0
real(8), intent (in) :: m
real(8), intent (in) :: d
real(8), intent (in) :: h
real(8), intent (in) :: l
real(8), intent (in) :: d_1
code = w0 * sqrt((1.0d0 - ((((m * d) / (2.0d0 * d_1)) ** 2.0d0) * (h / l))))
end function
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))));
}
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))))
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 tmp = code(w0, M, D, h, l, d) tmp = w0 * sqrt((1.0 - ((((M * D) / (2.0 * d)) ^ 2.0) * (h / l)))); 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]
\begin{array}{l}
\\
w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 23 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (w0 M D h l d) :precision binary64 (* 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) {
return w0 * sqrt((1.0 - (pow(((M * D) / (2.0 * d)), 2.0) * (h / l))));
}
real(8) function code(w0, m, d, h, l, d_1)
real(8), intent (in) :: w0
real(8), intent (in) :: m
real(8), intent (in) :: d
real(8), intent (in) :: h
real(8), intent (in) :: l
real(8), intent (in) :: d_1
code = w0 * sqrt((1.0d0 - ((((m * d) / (2.0d0 * d_1)) ** 2.0d0) * (h / l))))
end function
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))));
}
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))))
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 tmp = code(w0, M, D, h, l, d) tmp = w0 * sqrt((1.0 - ((((M * D) / (2.0 * d)) ^ 2.0) * (h / l)))); 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]
\begin{array}{l}
\\
w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}}
\end{array}
d_m = (fabs.f64 d)
D_m = (fabs.f64 D)
M_m = (fabs.f64 M)
NOTE: w0, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
(FPCore (w0 M_m D_m h l d_m)
:precision binary64
(let* ((t_0 (/ D_m (* d_m 2.0))) (t_1 (/ (* M_m D_m) (* d_m 2.0))))
(if (<= t_1 4e-30)
(* w0 (sqrt (fma (* (* M_m h) t_0) (* (/ -1.0 l) (* M_m t_0)) 1.0)))
(* w0 (sqrt (fma t_1 (* (/ (* M_m D_m) (* d_m -2.0)) (/ h l)) 1.0))))))d_m = fabs(d);
D_m = fabs(D);
M_m = fabs(M);
assert(w0 < M_m && M_m < D_m && D_m < h && h < l && l < d_m);
double code(double w0, double M_m, double D_m, double h, double l, double d_m) {
double t_0 = D_m / (d_m * 2.0);
double t_1 = (M_m * D_m) / (d_m * 2.0);
double tmp;
if (t_1 <= 4e-30) {
tmp = w0 * sqrt(fma(((M_m * h) * t_0), ((-1.0 / l) * (M_m * t_0)), 1.0));
} else {
tmp = w0 * sqrt(fma(t_1, (((M_m * D_m) / (d_m * -2.0)) * (h / l)), 1.0));
}
return tmp;
}
d_m = abs(d) D_m = abs(D) M_m = abs(M) w0, M_m, D_m, h, l, d_m = sort([w0, M_m, D_m, h, l, d_m]) function code(w0, M_m, D_m, h, l, d_m) t_0 = Float64(D_m / Float64(d_m * 2.0)) t_1 = Float64(Float64(M_m * D_m) / Float64(d_m * 2.0)) tmp = 0.0 if (t_1 <= 4e-30) tmp = Float64(w0 * sqrt(fma(Float64(Float64(M_m * h) * t_0), Float64(Float64(-1.0 / l) * Float64(M_m * t_0)), 1.0))); else tmp = Float64(w0 * sqrt(fma(t_1, Float64(Float64(Float64(M_m * D_m) / Float64(d_m * -2.0)) * Float64(h / l)), 1.0))); end return tmp end
d_m = N[Abs[d], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
M_m = N[Abs[M], $MachinePrecision]
NOTE: w0, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
code[w0_, M$95$m_, D$95$m_, h_, l_, d$95$m_] := Block[{t$95$0 = N[(D$95$m / N[(d$95$m * 2.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(M$95$m * D$95$m), $MachinePrecision] / N[(d$95$m * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, 4e-30], N[(w0 * N[Sqrt[N[(N[(N[(M$95$m * h), $MachinePrecision] * t$95$0), $MachinePrecision] * N[(N[(-1.0 / l), $MachinePrecision] * N[(M$95$m * t$95$0), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(w0 * N[Sqrt[N[(t$95$1 * N[(N[(N[(M$95$m * D$95$m), $MachinePrecision] / N[(d$95$m * -2.0), $MachinePrecision]), $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
d_m = \left|d\right|
\\
D_m = \left|D\right|
\\
M_m = \left|M\right|
\\
[w0, M_m, D_m, h, l, d_m] = \mathsf{sort}([w0, M_m, D_m, h, l, d_m])\\
\\
\begin{array}{l}
t_0 := \frac{D\_m}{d\_m \cdot 2}\\
t_1 := \frac{M\_m \cdot D\_m}{d\_m \cdot 2}\\
\mathbf{if}\;t\_1 \leq 4 \cdot 10^{-30}:\\
\;\;\;\;w0 \cdot \sqrt{\mathsf{fma}\left(\left(M\_m \cdot h\right) \cdot t\_0, \frac{-1}{\ell} \cdot \left(M\_m \cdot t\_0\right), 1\right)}\\
\mathbf{else}:\\
\;\;\;\;w0 \cdot \sqrt{\mathsf{fma}\left(t\_1, \frac{M\_m \cdot D\_m}{d\_m \cdot -2} \cdot \frac{h}{\ell}, 1\right)}\\
\end{array}
\end{array}
if (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) < 4e-30Initial program 87.7%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lift-/.f64N/A
clear-numN/A
un-div-invN/A
lift-pow.f64N/A
unpow2N/A
distribute-lft-neg-inN/A
div-invN/A
times-fracN/A
lower-fma.f64N/A
Applied rewrites98.8%
Applied rewrites97.0%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lift-/.f64N/A
lower-*.f6499.4
Applied rewrites99.4%
if 4e-30 < (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) Initial program 70.0%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lift-pow.f64N/A
unpow2N/A
distribute-rgt-neg-inN/A
associate-*l*N/A
lower-fma.f64N/A
Applied rewrites74.0%
Final simplification89.9%
d_m = (fabs.f64 d)
D_m = (fabs.f64 D)
M_m = (fabs.f64 M)
NOTE: w0, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
(FPCore (w0 M_m D_m h l d_m)
:precision binary64
(let* ((t_0 (/ (* M_m D_m) (* d_m 2.0))))
(if (<= (- 1.0 (* (/ h l) (pow t_0 2.0))) 1e+293)
(* w0 (sqrt (fma t_0 (* (/ (* M_m D_m) (* d_m -2.0)) (/ h l)) 1.0)))
(*
w0
(sqrt
(fma
(/ (* M_m D_m) (* (* d_m -2.0) l))
(* (* M_m D_m) (* h (/ 0.5 d_m)))
1.0))))))d_m = fabs(d);
D_m = fabs(D);
M_m = fabs(M);
assert(w0 < M_m && M_m < D_m && D_m < h && h < l && l < d_m);
double code(double w0, double M_m, double D_m, double h, double l, double d_m) {
double t_0 = (M_m * D_m) / (d_m * 2.0);
double tmp;
if ((1.0 - ((h / l) * pow(t_0, 2.0))) <= 1e+293) {
tmp = w0 * sqrt(fma(t_0, (((M_m * D_m) / (d_m * -2.0)) * (h / l)), 1.0));
} else {
tmp = w0 * sqrt(fma(((M_m * D_m) / ((d_m * -2.0) * l)), ((M_m * D_m) * (h * (0.5 / d_m))), 1.0));
}
return tmp;
}
d_m = abs(d) D_m = abs(D) M_m = abs(M) w0, M_m, D_m, h, l, d_m = sort([w0, M_m, D_m, h, l, d_m]) function code(w0, M_m, D_m, h, l, d_m) t_0 = Float64(Float64(M_m * D_m) / Float64(d_m * 2.0)) tmp = 0.0 if (Float64(1.0 - Float64(Float64(h / l) * (t_0 ^ 2.0))) <= 1e+293) tmp = Float64(w0 * sqrt(fma(t_0, Float64(Float64(Float64(M_m * D_m) / Float64(d_m * -2.0)) * Float64(h / l)), 1.0))); else tmp = Float64(w0 * sqrt(fma(Float64(Float64(M_m * D_m) / Float64(Float64(d_m * -2.0) * l)), Float64(Float64(M_m * D_m) * Float64(h * Float64(0.5 / d_m))), 1.0))); end return tmp end
d_m = N[Abs[d], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
M_m = N[Abs[M], $MachinePrecision]
NOTE: w0, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
code[w0_, M$95$m_, D$95$m_, h_, l_, d$95$m_] := Block[{t$95$0 = N[(N[(M$95$m * D$95$m), $MachinePrecision] / N[(d$95$m * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(1.0 - N[(N[(h / l), $MachinePrecision] * N[Power[t$95$0, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1e+293], N[(w0 * N[Sqrt[N[(t$95$0 * N[(N[(N[(M$95$m * D$95$m), $MachinePrecision] / N[(d$95$m * -2.0), $MachinePrecision]), $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(w0 * N[Sqrt[N[(N[(N[(M$95$m * D$95$m), $MachinePrecision] / N[(N[(d$95$m * -2.0), $MachinePrecision] * l), $MachinePrecision]), $MachinePrecision] * N[(N[(M$95$m * D$95$m), $MachinePrecision] * N[(h * N[(0.5 / d$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
d_m = \left|d\right|
\\
D_m = \left|D\right|
\\
M_m = \left|M\right|
\\
[w0, M_m, D_m, h, l, d_m] = \mathsf{sort}([w0, M_m, D_m, h, l, d_m])\\
\\
\begin{array}{l}
t_0 := \frac{M\_m \cdot D\_m}{d\_m \cdot 2}\\
\mathbf{if}\;1 - \frac{h}{\ell} \cdot {t\_0}^{2} \leq 10^{+293}:\\
\;\;\;\;w0 \cdot \sqrt{\mathsf{fma}\left(t\_0, \frac{M\_m \cdot D\_m}{d\_m \cdot -2} \cdot \frac{h}{\ell}, 1\right)}\\
\mathbf{else}:\\
\;\;\;\;w0 \cdot \sqrt{\mathsf{fma}\left(\frac{M\_m \cdot D\_m}{\left(d\_m \cdot -2\right) \cdot \ell}, \left(M\_m \cdot D\_m\right) \cdot \left(h \cdot \frac{0.5}{d\_m}\right), 1\right)}\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) #s(literal 2 binary64)) (/.f64 h l))) < 9.9999999999999992e292Initial program 99.7%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lift-pow.f64N/A
unpow2N/A
distribute-rgt-neg-inN/A
associate-*l*N/A
lower-fma.f64N/A
Applied rewrites99.7%
if 9.9999999999999992e292 < (-.f64 #s(literal 1 binary64) (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) #s(literal 2 binary64)) (/.f64 h l))) Initial program 43.4%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lift-/.f64N/A
clear-numN/A
un-div-invN/A
lift-pow.f64N/A
unpow2N/A
distribute-lft-neg-inN/A
div-invN/A
times-fracN/A
lower-fma.f64N/A
Applied rewrites68.0%
Applied rewrites62.9%
lift-/.f64N/A
div-invN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
*-commutativeN/A
lift-*.f64N/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f64N/A
lift-*.f64N/A
associate-/r*N/A
metadata-evalN/A
lower-/.f6464.8
Applied rewrites64.8%
Final simplification88.4%
herbie shell --seed 2024230
(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))))))