
(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 21 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}
(FPCore (w0 M D h l d)
:precision binary64
(let* ((t_0 (/ (* M D) (* d 2.0))))
(if (<= (* (pow t_0 2.0) (/ h l)) 4e-147)
(* w0 (sqrt (fma t_0 (* (/ (* M D) (* d -2.0)) (/ h l)) 1.0)))
(* w0 (sqrt (fma t_0 (/ (/ (* (* M D) h) (* d 2.0)) (- l)) 1.0))))))
double code(double w0, double M, double D, double h, double l, double d) {
double t_0 = (M * D) / (d * 2.0);
double tmp;
if ((pow(t_0, 2.0) * (h / l)) <= 4e-147) {
tmp = w0 * sqrt(fma(t_0, (((M * D) / (d * -2.0)) * (h / l)), 1.0));
} else {
tmp = w0 * sqrt(fma(t_0, ((((M * D) * h) / (d * 2.0)) / -l), 1.0));
}
return tmp;
}
function code(w0, M, D, h, l, d) t_0 = Float64(Float64(M * D) / Float64(d * 2.0)) tmp = 0.0 if (Float64((t_0 ^ 2.0) * Float64(h / l)) <= 4e-147) tmp = Float64(w0 * sqrt(fma(t_0, Float64(Float64(Float64(M * D) / Float64(d * -2.0)) * Float64(h / l)), 1.0))); else tmp = Float64(w0 * sqrt(fma(t_0, Float64(Float64(Float64(Float64(M * D) * h) / Float64(d * 2.0)) / Float64(-l)), 1.0))); end return tmp end
code[w0_, M_, D_, h_, l_, d_] := Block[{t$95$0 = N[(N[(M * D), $MachinePrecision] / N[(d * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[Power[t$95$0, 2.0], $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision], 4e-147], N[(w0 * N[Sqrt[N[(t$95$0 * N[(N[(N[(M * D), $MachinePrecision] / N[(d * -2.0), $MachinePrecision]), $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(w0 * N[Sqrt[N[(t$95$0 * N[(N[(N[(N[(M * D), $MachinePrecision] * h), $MachinePrecision] / N[(d * 2.0), $MachinePrecision]), $MachinePrecision] / (-l)), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{M \cdot D}{d \cdot 2}\\
\mathbf{if}\;{t\_0}^{2} \cdot \frac{h}{\ell} \leq 4 \cdot 10^{-147}:\\
\;\;\;\;w0 \cdot \sqrt{\mathsf{fma}\left(t\_0, \frac{M \cdot D}{d \cdot -2} \cdot \frac{h}{\ell}, 1\right)}\\
\mathbf{else}:\\
\;\;\;\;w0 \cdot \sqrt{\mathsf{fma}\left(t\_0, \frac{\frac{\left(M \cdot D\right) \cdot h}{d \cdot 2}}{-\ell}, 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)) < 3.9999999999999999e-147Initial program 89.1%
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 rewrites91.1%
if 3.9999999999999999e-147 < (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) #s(literal 2 binary64)) (/.f64 h l)) Initial program 27.6%
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 rewrites86.6%
Final simplification90.6%
(FPCore (w0 M D h l d)
:precision binary64
(let* ((t_0 (/ (* M D) (* d 2.0))) (t_1 (/ (* M D) (* d -2.0))))
(if (<= (* (pow t_0 2.0) (/ h l)) 2e-48)
(* w0 (sqrt (fma t_0 (* t_1 (/ h l)) 1.0)))
(* w0 (sqrt (fma (/ t_1 l) (* (* M D) (* h (/ 0.5 d))) 1.0))))))
double code(double w0, double M, double D, double h, double l, double d) {
double t_0 = (M * D) / (d * 2.0);
double t_1 = (M * D) / (d * -2.0);
double tmp;
if ((pow(t_0, 2.0) * (h / l)) <= 2e-48) {
tmp = w0 * sqrt(fma(t_0, (t_1 * (h / l)), 1.0));
} else {
tmp = w0 * sqrt(fma((t_1 / l), ((M * D) * (h * (0.5 / d))), 1.0));
}
return tmp;
}
function code(w0, M, D, h, l, d) t_0 = Float64(Float64(M * D) / Float64(d * 2.0)) t_1 = Float64(Float64(M * D) / Float64(d * -2.0)) tmp = 0.0 if (Float64((t_0 ^ 2.0) * Float64(h / l)) <= 2e-48) tmp = Float64(w0 * sqrt(fma(t_0, Float64(t_1 * Float64(h / l)), 1.0))); else tmp = Float64(w0 * sqrt(fma(Float64(t_1 / l), Float64(Float64(M * D) * Float64(h * Float64(0.5 / d))), 1.0))); end return tmp end
code[w0_, M_, D_, h_, l_, d_] := Block[{t$95$0 = N[(N[(M * D), $MachinePrecision] / N[(d * 2.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(M * D), $MachinePrecision] / N[(d * -2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[Power[t$95$0, 2.0], $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision], 2e-48], N[(w0 * N[Sqrt[N[(t$95$0 * N[(t$95$1 * N[(h / l), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(w0 * N[Sqrt[N[(N[(t$95$1 / l), $MachinePrecision] * N[(N[(M * D), $MachinePrecision] * N[(h * N[(0.5 / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{M \cdot D}{d \cdot 2}\\
t_1 := \frac{M \cdot D}{d \cdot -2}\\
\mathbf{if}\;{t\_0}^{2} \cdot \frac{h}{\ell} \leq 2 \cdot 10^{-48}:\\
\;\;\;\;w0 \cdot \sqrt{\mathsf{fma}\left(t\_0, t\_1 \cdot \frac{h}{\ell}, 1\right)}\\
\mathbf{else}:\\
\;\;\;\;w0 \cdot \sqrt{\mathsf{fma}\left(\frac{t\_1}{\ell}, \left(M \cdot D\right) \cdot \left(h \cdot \frac{0.5}{d}\right), 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.9999999999999999e-48Initial program 88.3%
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.6%
if 1.9999999999999999e-48 < (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) #s(literal 2 binary64)) (/.f64 h l)) Initial program 13.5%
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 rewrites82.7%
lift-/.f64N/A
lift-/.f64N/A
associate-/r/N/A
/-rgt-identityN/A
lift-/.f64N/A
div-invN/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f64N/A
lift-*.f64N/A
associate-/r*N/A
metadata-evalN/A
lower-/.f6476.2
Applied rewrites76.2%
Final simplification88.4%
herbie shell --seed 2024229
(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))))))