
(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 16 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)
NOTE: w0, M, D_m, h, l, and d should be sorted in increasing order before calling this function.
(FPCore (w0 M D_m h l d)
:precision binary64
(if (<= (* (/ h l) (pow (/ (* D_m M) (* 2.0 d)) 2.0)) 4e-44)
(*
(sqrt
(fma (* (* (* (/ D_m d) M) -0.5) (/ h l)) (* D_m (* M (/ 0.5 d))) 1.0))
w0)
(*
(sqrt (fma (* (* (/ (* -0.25 M) l) M) (/ D_m d)) (* (/ D_m d) h) 1.0))
w0)))D_m = fabs(D);
assert(w0 < M && M < D_m && D_m < h && h < l && l < d);
double code(double w0, double M, double D_m, double h, double l, double d) {
double tmp;
if (((h / l) * pow(((D_m * M) / (2.0 * d)), 2.0)) <= 4e-44) {
tmp = sqrt(fma(((((D_m / d) * M) * -0.5) * (h / l)), (D_m * (M * (0.5 / d))), 1.0)) * w0;
} else {
tmp = sqrt(fma(((((-0.25 * M) / l) * M) * (D_m / d)), ((D_m / d) * h), 1.0)) * w0;
}
return tmp;
}
D_m = abs(D) w0, M, D_m, h, l, d = sort([w0, M, D_m, h, l, d]) function code(w0, M, D_m, h, l, d) tmp = 0.0 if (Float64(Float64(h / l) * (Float64(Float64(D_m * M) / Float64(2.0 * d)) ^ 2.0)) <= 4e-44) tmp = Float64(sqrt(fma(Float64(Float64(Float64(Float64(D_m / d) * M) * -0.5) * Float64(h / l)), Float64(D_m * Float64(M * Float64(0.5 / d))), 1.0)) * w0); else tmp = Float64(sqrt(fma(Float64(Float64(Float64(Float64(-0.25 * M) / l) * M) * Float64(D_m / d)), Float64(Float64(D_m / d) * h), 1.0)) * w0); end return tmp end
D_m = N[Abs[D], $MachinePrecision] NOTE: w0, M, D_m, h, l, and d should be sorted in increasing order before calling this function. code[w0_, M_, D$95$m_, h_, l_, d_] := If[LessEqual[N[(N[(h / l), $MachinePrecision] * N[Power[N[(N[(D$95$m * M), $MachinePrecision] / N[(2.0 * d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision], 4e-44], N[(N[Sqrt[N[(N[(N[(N[(N[(D$95$m / d), $MachinePrecision] * M), $MachinePrecision] * -0.5), $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision] * N[(D$95$m * N[(M * N[(0.5 / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision] * w0), $MachinePrecision], N[(N[Sqrt[N[(N[(N[(N[(N[(-0.25 * M), $MachinePrecision] / l), $MachinePrecision] * M), $MachinePrecision] * N[(D$95$m / d), $MachinePrecision]), $MachinePrecision] * N[(N[(D$95$m / d), $MachinePrecision] * h), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision] * w0), $MachinePrecision]]
\begin{array}{l}
D_m = \left|D\right|
\\
[w0, M, D_m, h, l, d] = \mathsf{sort}([w0, M, D_m, h, l, d])\\
\\
\begin{array}{l}
\mathbf{if}\;\frac{h}{\ell} \cdot {\left(\frac{D\_m \cdot M}{2 \cdot d}\right)}^{2} \leq 4 \cdot 10^{-44}:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(\left(\left(\frac{D\_m}{d} \cdot M\right) \cdot -0.5\right) \cdot \frac{h}{\ell}, D\_m \cdot \left(M \cdot \frac{0.5}{d}\right), 1\right)} \cdot w0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(\left(\frac{-0.25 \cdot M}{\ell} \cdot M\right) \cdot \frac{D\_m}{d}, \frac{D\_m}{d} \cdot h, 1\right)} \cdot w0\\
\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)) < 3.99999999999999981e-44Initial program 89.9%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lift-pow.f64N/A
unpow2N/A
distribute-lft-neg-inN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites90.5%
if 3.99999999999999981e-44 < (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) #s(literal 2 binary64)) (/.f64 h l)) Initial program 4.0%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
distribute-neg-frac2N/A
lift-pow.f64N/A
unpow2N/A
associate-*l*N/A
associate-/l*N/A
lower-fma.f64N/A
Applied rewrites84.7%
Applied rewrites84.8%
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6496.1
Applied rewrites96.1%
Final simplification91.0%
D_m = (fabs.f64 D)
NOTE: w0, M, D_m, h, l, and d should be sorted in increasing order before calling this function.
(FPCore (w0 M D_m h l d)
:precision binary64
(if (<= (- 1.0 (* (/ h l) (pow (/ (* D_m M) (* 2.0 d)) 2.0))) 1.0)
(* 1.0 w0)
(*
(sqrt (fma (- D_m) (/ (* (* (* D_m M) h) M) (* (* (* 4.0 l) d) d)) 1.0))
w0)))D_m = fabs(D);
assert(w0 < M && M < D_m && D_m < h && h < l && l < d);
double code(double w0, double M, double D_m, double h, double l, double d) {
double tmp;
if ((1.0 - ((h / l) * pow(((D_m * M) / (2.0 * d)), 2.0))) <= 1.0) {
tmp = 1.0 * w0;
} else {
tmp = sqrt(fma(-D_m, ((((D_m * M) * h) * M) / (((4.0 * l) * d) * d)), 1.0)) * w0;
}
return tmp;
}
D_m = abs(D) w0, M, D_m, h, l, d = sort([w0, M, D_m, h, l, d]) function code(w0, M, D_m, h, l, d) tmp = 0.0 if (Float64(1.0 - Float64(Float64(h / l) * (Float64(Float64(D_m * M) / Float64(2.0 * d)) ^ 2.0))) <= 1.0) tmp = Float64(1.0 * w0); else tmp = Float64(sqrt(fma(Float64(-D_m), Float64(Float64(Float64(Float64(D_m * M) * h) * M) / Float64(Float64(Float64(4.0 * l) * d) * d)), 1.0)) * w0); end return tmp end
D_m = N[Abs[D], $MachinePrecision] NOTE: w0, M, D_m, h, l, and d should be sorted in increasing order before calling this function. code[w0_, M_, D$95$m_, h_, l_, d_] := If[LessEqual[N[(1.0 - N[(N[(h / l), $MachinePrecision] * N[Power[N[(N[(D$95$m * M), $MachinePrecision] / N[(2.0 * d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1.0], N[(1.0 * w0), $MachinePrecision], N[(N[Sqrt[N[((-D$95$m) * N[(N[(N[(N[(D$95$m * M), $MachinePrecision] * h), $MachinePrecision] * M), $MachinePrecision] / N[(N[(N[(4.0 * l), $MachinePrecision] * d), $MachinePrecision] * d), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision] * w0), $MachinePrecision]]
\begin{array}{l}
D_m = \left|D\right|
\\
[w0, M, D_m, h, l, d] = \mathsf{sort}([w0, M, D_m, h, l, d])\\
\\
\begin{array}{l}
\mathbf{if}\;1 - \frac{h}{\ell} \cdot {\left(\frac{D\_m \cdot M}{2 \cdot d}\right)}^{2} \leq 1:\\
\;\;\;\;1 \cdot w0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(-D\_m, \frac{\left(\left(D\_m \cdot M\right) \cdot h\right) \cdot M}{\left(\left(4 \cdot \ell\right) \cdot d\right) \cdot d}, 1\right)} \cdot w0\\
\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))) < 1Initial program 99.6%
Taylor expanded in M around 0
Applied rewrites99.4%
if 1 < (-.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 53.3%
lift-*.f64N/A
lift-/.f64N/A
clear-numN/A
un-div-invN/A
lift-pow.f64N/A
unpow2N/A
lift-/.f64N/A
clear-numN/A
un-div-invN/A
lift-/.f64N/A
associate-/r*N/A
associate-/l/N/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
lower-/.f64N/A
associate-*r/N/A
lower-/.f64N/A
Applied rewrites48.3%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6448.3
Applied rewrites55.4%
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6454.0
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lift-*.f64N/A
lower-*.f6454.3
lift-*.f64N/A
*-commutativeN/A
lower-*.f6454.3
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
associate-*r*N/A
associate-*l*N/A
lift-*.f64N/A
lower-*.f64N/A
Applied rewrites58.3%
Final simplification83.6%
herbie shell --seed 2024234
(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))))))