
(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 19 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)
M_m = (fabs.f64 M)
NOTE: w0, M_m, D_m, h, l, and d should be sorted in increasing order before calling this function.
(FPCore (w0 M_m D_m h l d)
:precision binary64
(let* ((t_0 (/ (* M_m D_m) (* d 2.0))))
(if (<= (* (pow t_0 2.0) (/ h l)) 2e-11)
(* w0 (sqrt (fma t_0 (* (/ (* M_m D_m) (* d -2.0)) (/ h l)) 1.0)))
(*
w0
(sqrt
(fma (* h (* D_m (/ (* M_m (* M_m -0.25)) (* d (* d l))))) D_m 1.0))))))D_m = fabs(D);
M_m = fabs(M);
assert(w0 < M_m && M_m < D_m && D_m < h && h < l && l < d);
double code(double w0, double M_m, double D_m, double h, double l, double d) {
double t_0 = (M_m * D_m) / (d * 2.0);
double tmp;
if ((pow(t_0, 2.0) * (h / l)) <= 2e-11) {
tmp = w0 * sqrt(fma(t_0, (((M_m * D_m) / (d * -2.0)) * (h / l)), 1.0));
} else {
tmp = w0 * sqrt(fma((h * (D_m * ((M_m * (M_m * -0.25)) / (d * (d * l))))), D_m, 1.0));
}
return tmp;
}
D_m = abs(D) M_m = abs(M) w0, M_m, D_m, h, l, d = sort([w0, M_m, D_m, h, l, d]) function code(w0, M_m, D_m, h, l, d) t_0 = Float64(Float64(M_m * D_m) / Float64(d * 2.0)) tmp = 0.0 if (Float64((t_0 ^ 2.0) * Float64(h / l)) <= 2e-11) tmp = Float64(w0 * sqrt(fma(t_0, Float64(Float64(Float64(M_m * D_m) / Float64(d * -2.0)) * Float64(h / l)), 1.0))); else tmp = Float64(w0 * sqrt(fma(Float64(h * Float64(D_m * Float64(Float64(M_m * Float64(M_m * -0.25)) / Float64(d * Float64(d * l))))), D_m, 1.0))); end return tmp end
D_m = N[Abs[D], $MachinePrecision]
M_m = N[Abs[M], $MachinePrecision]
NOTE: w0, M_m, D_m, h, l, and d should be sorted in increasing order before calling this function.
code[w0_, M$95$m_, D$95$m_, h_, l_, d_] := Block[{t$95$0 = N[(N[(M$95$m * D$95$m), $MachinePrecision] / N[(d * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[Power[t$95$0, 2.0], $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision], 2e-11], N[(w0 * N[Sqrt[N[(t$95$0 * N[(N[(N[(M$95$m * D$95$m), $MachinePrecision] / N[(d * -2.0), $MachinePrecision]), $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(w0 * N[Sqrt[N[(N[(h * N[(D$95$m * N[(N[(M$95$m * N[(M$95$m * -0.25), $MachinePrecision]), $MachinePrecision] / N[(d * N[(d * l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * D$95$m + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
D_m = \left|D\right|
\\
M_m = \left|M\right|
\\
[w0, M_m, D_m, h, l, d] = \mathsf{sort}([w0, M_m, D_m, h, l, d])\\
\\
\begin{array}{l}
t_0 := \frac{M\_m \cdot D\_m}{d \cdot 2}\\
\mathbf{if}\;{t\_0}^{2} \cdot \frac{h}{\ell} \leq 2 \cdot 10^{-11}:\\
\;\;\;\;w0 \cdot \sqrt{\mathsf{fma}\left(t\_0, \frac{M\_m \cdot D\_m}{d \cdot -2} \cdot \frac{h}{\ell}, 1\right)}\\
\mathbf{else}:\\
\;\;\;\;w0 \cdot \sqrt{\mathsf{fma}\left(h \cdot \left(D\_m \cdot \frac{M\_m \cdot \left(M\_m \cdot -0.25\right)}{d \cdot \left(d \cdot \ell\right)}\right), D\_m, 1\right)}\\
\end{array}
\end{array}
if (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) #s(literal 2 binary64)) (/.f64 h l)) < 1.99999999999999988e-11Initial program 87.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 rewrites89.4%
if 1.99999999999999988e-11 < (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) #s(literal 2 binary64)) (/.f64 h l)) Initial program 7.1%
Taylor expanded in M around 0
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
associate-*l*N/A
metadata-evalN/A
distribute-rgt-neg-inN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites64.3%
Applied rewrites86.7%
Applied rewrites93.3%
Final simplification89.6%
D_m = (fabs.f64 D)
M_m = (fabs.f64 M)
NOTE: w0, M_m, D_m, h, l, and d should be sorted in increasing order before calling this function.
(FPCore (w0 M_m D_m h l d)
:precision binary64
(if (<= (* (pow (/ (* M_m D_m) (* d 2.0)) 2.0) (/ h l)) -0.02)
(*
w0
(sqrt
(fma (* (/ (* M_m D_m) l) (/ (* M_m D_m) (* (* d 4.0) (- d)))) h 1.0)))
(* w0 1.0)))D_m = fabs(D);
M_m = fabs(M);
assert(w0 < M_m && M_m < D_m && D_m < h && h < l && l < d);
double code(double w0, double M_m, double D_m, double h, double l, double d) {
double tmp;
if ((pow(((M_m * D_m) / (d * 2.0)), 2.0) * (h / l)) <= -0.02) {
tmp = w0 * sqrt(fma((((M_m * D_m) / l) * ((M_m * D_m) / ((d * 4.0) * -d))), h, 1.0));
} else {
tmp = w0 * 1.0;
}
return tmp;
}
D_m = abs(D) M_m = abs(M) w0, M_m, D_m, h, l, d = sort([w0, M_m, D_m, h, l, d]) function code(w0, M_m, D_m, h, l, d) tmp = 0.0 if (Float64((Float64(Float64(M_m * D_m) / Float64(d * 2.0)) ^ 2.0) * Float64(h / l)) <= -0.02) tmp = Float64(w0 * sqrt(fma(Float64(Float64(Float64(M_m * D_m) / l) * Float64(Float64(M_m * D_m) / Float64(Float64(d * 4.0) * Float64(-d)))), h, 1.0))); else tmp = Float64(w0 * 1.0); end return tmp end
D_m = N[Abs[D], $MachinePrecision] M_m = N[Abs[M], $MachinePrecision] NOTE: w0, M_m, D_m, h, l, and d should be sorted in increasing order before calling this function. code[w0_, M$95$m_, D$95$m_, h_, l_, d_] := If[LessEqual[N[(N[Power[N[(N[(M$95$m * D$95$m), $MachinePrecision] / N[(d * 2.0), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision], -0.02], N[(w0 * N[Sqrt[N[(N[(N[(N[(M$95$m * D$95$m), $MachinePrecision] / l), $MachinePrecision] * N[(N[(M$95$m * D$95$m), $MachinePrecision] / N[(N[(d * 4.0), $MachinePrecision] * (-d)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * h + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(w0 * 1.0), $MachinePrecision]]
\begin{array}{l}
D_m = \left|D\right|
\\
M_m = \left|M\right|
\\
[w0, M_m, D_m, h, l, d] = \mathsf{sort}([w0, M_m, D_m, h, l, d])\\
\\
\begin{array}{l}
\mathbf{if}\;{\left(\frac{M\_m \cdot D\_m}{d \cdot 2}\right)}^{2} \cdot \frac{h}{\ell} \leq -0.02:\\
\;\;\;\;w0 \cdot \sqrt{\mathsf{fma}\left(\frac{M\_m \cdot D\_m}{\ell} \cdot \frac{M\_m \cdot D\_m}{\left(d \cdot 4\right) \cdot \left(-d\right)}, h, 1\right)}\\
\mathbf{else}:\\
\;\;\;\;w0 \cdot 1\\
\end{array}
\end{array}
if (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) #s(literal 2 binary64)) (/.f64 h l)) < -0.0200000000000000004Initial program 64.3%
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
associate-/r/N/A
lower-fma.f64N/A
Applied rewrites50.4%
lift-/.f64N/A
lift-/.f64N/A
associate-/l/N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lift-*.f64N/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f6455.2
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f6455.2
Applied rewrites55.2%
if -0.0200000000000000004 < (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) #s(literal 2 binary64)) (/.f64 h l)) Initial program 89.4%
Taylor expanded in M around 0
Applied rewrites96.4%
Final simplification83.6%
herbie shell --seed 2024223
(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))))))