
(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 15 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}
NOTE: w0, M, D, h, l, and d should be sorted in increasing order before calling this function. (FPCore (w0 M D h l d) :precision binary64 (let* ((t_0 (* M (/ D (* 2.0 d))))) (* w0 (sqrt (fma (* h t_0) (* t_0 (/ -1.0 l)) 1.0)))))
assert(w0 < M && M < D && D < h && h < l && l < d);
double code(double w0, double M, double D, double h, double l, double d) {
double t_0 = M * (D / (2.0 * d));
return w0 * sqrt(fma((h * t_0), (t_0 * (-1.0 / l)), 1.0));
}
w0, M, D, h, l, d = sort([w0, M, D, h, l, d]) function code(w0, M, D, h, l, d) t_0 = Float64(M * Float64(D / Float64(2.0 * d))) return Float64(w0 * sqrt(fma(Float64(h * t_0), Float64(t_0 * Float64(-1.0 / l)), 1.0))) end
NOTE: w0, M, D, h, l, and d should be sorted in increasing order before calling this function.
code[w0_, M_, D_, h_, l_, d_] := Block[{t$95$0 = N[(M * N[(D / N[(2.0 * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(w0 * N[Sqrt[N[(N[(h * t$95$0), $MachinePrecision] * N[(t$95$0 * N[(-1.0 / l), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[w0, M, D, h, l, d] = \mathsf{sort}([w0, M, D, h, l, d])\\
\\
\begin{array}{l}
t_0 := M \cdot \frac{D}{2 \cdot d}\\
w0 \cdot \sqrt{\mathsf{fma}\left(h \cdot t\_0, t\_0 \cdot \frac{-1}{\ell}, 1\right)}
\end{array}
\end{array}
Initial program 84.1%
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 rewrites88.0%
lift-fma.f64N/A
*-commutativeN/A
lift-/.f64N/A
div-invN/A
associate-*l*N/A
lower-fma.f64N/A
Applied rewrites91.4%
Final simplification91.4%
NOTE: w0, M, D, h, l, and d should be sorted in increasing order before calling this function. (FPCore (w0 M D h l d) :precision binary64 (if (<= (* (/ h l) (pow (/ (* M D) (* 2.0 d)) 2.0)) -2e+15) (* w0 (sqrt (- 1.0 (* (/ h l) (* (* M D) (/ (* M D) (* 4.0 (* d d)))))))) (* w0 1.0)))
assert(w0 < M && M < D && D < h && h < l && l < d);
double code(double w0, double M, double D, double h, double l, double d) {
double tmp;
if (((h / l) * pow(((M * D) / (2.0 * d)), 2.0)) <= -2e+15) {
tmp = w0 * sqrt((1.0 - ((h / l) * ((M * D) * ((M * D) / (4.0 * (d * d)))))));
} else {
tmp = w0 * 1.0;
}
return tmp;
}
NOTE: w0, M, D, h, l, and d should be sorted in increasing order before calling this function.
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
real(8) :: tmp
if (((h / l) * (((m * d) / (2.0d0 * d_1)) ** 2.0d0)) <= (-2d+15)) then
tmp = w0 * sqrt((1.0d0 - ((h / l) * ((m * d) * ((m * d) / (4.0d0 * (d_1 * d_1)))))))
else
tmp = w0 * 1.0d0
end if
code = tmp
end function
assert w0 < M && M < D && D < h && h < l && l < d;
public static double code(double w0, double M, double D, double h, double l, double d) {
double tmp;
if (((h / l) * Math.pow(((M * D) / (2.0 * d)), 2.0)) <= -2e+15) {
tmp = w0 * Math.sqrt((1.0 - ((h / l) * ((M * D) * ((M * D) / (4.0 * (d * d)))))));
} else {
tmp = w0 * 1.0;
}
return tmp;
}
[w0, M, D, h, l, d] = sort([w0, M, D, h, l, d]) def code(w0, M, D, h, l, d): tmp = 0 if ((h / l) * math.pow(((M * D) / (2.0 * d)), 2.0)) <= -2e+15: tmp = w0 * math.sqrt((1.0 - ((h / l) * ((M * D) * ((M * D) / (4.0 * (d * d))))))) else: tmp = w0 * 1.0 return tmp
w0, M, D, h, l, d = sort([w0, M, D, h, l, d]) function code(w0, M, D, h, l, d) tmp = 0.0 if (Float64(Float64(h / l) * (Float64(Float64(M * D) / Float64(2.0 * d)) ^ 2.0)) <= -2e+15) tmp = Float64(w0 * sqrt(Float64(1.0 - Float64(Float64(h / l) * Float64(Float64(M * D) * Float64(Float64(M * D) / Float64(4.0 * Float64(d * d)))))))); else tmp = Float64(w0 * 1.0); end return tmp end
w0, M, D, h, l, d = num2cell(sort([w0, M, D, h, l, d])){:}
function tmp_2 = code(w0, M, D, h, l, d)
tmp = 0.0;
if (((h / l) * (((M * D) / (2.0 * d)) ^ 2.0)) <= -2e+15)
tmp = w0 * sqrt((1.0 - ((h / l) * ((M * D) * ((M * D) / (4.0 * (d * d)))))));
else
tmp = w0 * 1.0;
end
tmp_2 = tmp;
end
NOTE: w0, M, D, h, l, and d should be sorted in increasing order before calling this function. code[w0_, M_, D_, h_, l_, d_] := If[LessEqual[N[(N[(h / l), $MachinePrecision] * N[Power[N[(N[(M * D), $MachinePrecision] / N[(2.0 * d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision], -2e+15], N[(w0 * N[Sqrt[N[(1.0 - N[(N[(h / l), $MachinePrecision] * N[(N[(M * D), $MachinePrecision] * N[(N[(M * D), $MachinePrecision] / N[(4.0 * N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(w0 * 1.0), $MachinePrecision]]
\begin{array}{l}
[w0, M, D, h, l, d] = \mathsf{sort}([w0, M, D, h, l, d])\\
\\
\begin{array}{l}
\mathbf{if}\;\frac{h}{\ell} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \leq -2 \cdot 10^{+15}:\\
\;\;\;\;w0 \cdot \sqrt{1 - \frac{h}{\ell} \cdot \left(\left(M \cdot D\right) \cdot \frac{M \cdot D}{4 \cdot \left(d \cdot d\right)}\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)) < -2e15Initial program 65.6%
lift-pow.f64N/A
unpow2N/A
lift-/.f64N/A
lift-/.f64N/A
frac-timesN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
swap-sqrN/A
metadata-evalN/A
metadata-evalN/A
lower-*.f64N/A
lower-*.f64N/A
metadata-eval55.1
Applied rewrites55.1%
if -2e15 < (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) #s(literal 2 binary64)) (/.f64 h l)) Initial program 87.6%
Taylor expanded in M around 0
Applied rewrites95.3%
Final simplification82.6%
herbie shell --seed 2024228
(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))))))