
(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 3 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 (if (<= (/ h l) -5e-306) (* w0 (sqrt (- 1.0 (* h (* (pow (* (* D M) (/ 0.5 d)) 2.0) (/ 1.0 l)))))) w0))
double code(double w0, double M, double D, double h, double l, double d) {
double tmp;
if ((h / l) <= -5e-306) {
tmp = w0 * sqrt((1.0 - (h * (pow(((D * M) * (0.5 / d)), 2.0) * (1.0 / l)))));
} else {
tmp = w0;
}
return tmp;
}
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) <= (-5d-306)) then
tmp = w0 * sqrt((1.0d0 - (h * ((((d * m) * (0.5d0 / d_1)) ** 2.0d0) * (1.0d0 / l)))))
else
tmp = w0
end if
code = tmp
end function
public static double code(double w0, double M, double D, double h, double l, double d) {
double tmp;
if ((h / l) <= -5e-306) {
tmp = w0 * Math.sqrt((1.0 - (h * (Math.pow(((D * M) * (0.5 / d)), 2.0) * (1.0 / l)))));
} else {
tmp = w0;
}
return tmp;
}
def code(w0, M, D, h, l, d): tmp = 0 if (h / l) <= -5e-306: tmp = w0 * math.sqrt((1.0 - (h * (math.pow(((D * M) * (0.5 / d)), 2.0) * (1.0 / l))))) else: tmp = w0 return tmp
function code(w0, M, D, h, l, d) tmp = 0.0 if (Float64(h / l) <= -5e-306) tmp = Float64(w0 * sqrt(Float64(1.0 - Float64(h * Float64((Float64(Float64(D * M) * Float64(0.5 / d)) ^ 2.0) * Float64(1.0 / l)))))); else tmp = w0; end return tmp end
function tmp_2 = code(w0, M, D, h, l, d) tmp = 0.0; if ((h / l) <= -5e-306) tmp = w0 * sqrt((1.0 - (h * ((((D * M) * (0.5 / d)) ^ 2.0) * (1.0 / l))))); else tmp = w0; end tmp_2 = tmp; end
code[w0_, M_, D_, h_, l_, d_] := If[LessEqual[N[(h / l), $MachinePrecision], -5e-306], N[(w0 * N[Sqrt[N[(1.0 - N[(h * N[(N[Power[N[(N[(D * M), $MachinePrecision] * N[(0.5 / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(1.0 / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], w0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{h}{\ell} \leq -5 \cdot 10^{-306}:\\
\;\;\;\;w0 \cdot \sqrt{1 - h \cdot \left({\left(\left(D \cdot M\right) \cdot \frac{0.5}{d}\right)}^{2} \cdot \frac{1}{\ell}\right)}\\
\mathbf{else}:\\
\;\;\;\;w0\\
\end{array}
\end{array}
if (/.f64 h l) < -4.99999999999999998e-306Initial program 72.9%
Simplified72.2%
clear-num72.2%
un-div-inv72.9%
*-commutative72.9%
associate-*l/74.1%
associate-*r/71.9%
div-inv71.9%
metadata-eval71.9%
Applied egg-rr71.9%
associate-/r/81.1%
associate-*r/83.9%
*-commutative83.9%
associate-/l*82.0%
associate-*r/82.0%
Simplified82.0%
div-inv82.0%
associate-*r*83.9%
Applied egg-rr83.9%
if -4.99999999999999998e-306 < (/.f64 h l) Initial program 88.7%
Simplified88.7%
Taylor expanded in D around 0 96.4%
Final simplification89.1%
(FPCore (w0 M D h l d)
:precision binary64
(let* ((t_0 (* (* M 0.5) (/ D d))))
(if (<= (* (/ h l) (pow (/ (* D M) (* d 2.0)) 2.0)) -1e-13)
(* w0 (sqrt (- 1.0 (/ (* h (* t_0 t_0)) l))))
w0)))
double code(double w0, double M, double D, double h, double l, double d) {
double t_0 = (M * 0.5) * (D / d);
double tmp;
if (((h / l) * pow(((D * M) / (d * 2.0)), 2.0)) <= -1e-13) {
tmp = w0 * sqrt((1.0 - ((h * (t_0 * t_0)) / l)));
} else {
tmp = w0;
}
return tmp;
}
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) :: t_0
real(8) :: tmp
t_0 = (m * 0.5d0) * (d / d_1)
if (((h / l) * (((d * m) / (d_1 * 2.0d0)) ** 2.0d0)) <= (-1d-13)) then
tmp = w0 * sqrt((1.0d0 - ((h * (t_0 * t_0)) / l)))
else
tmp = w0
end if
code = tmp
end function
public static double code(double w0, double M, double D, double h, double l, double d) {
double t_0 = (M * 0.5) * (D / d);
double tmp;
if (((h / l) * Math.pow(((D * M) / (d * 2.0)), 2.0)) <= -1e-13) {
tmp = w0 * Math.sqrt((1.0 - ((h * (t_0 * t_0)) / l)));
} else {
tmp = w0;
}
return tmp;
}
def code(w0, M, D, h, l, d): t_0 = (M * 0.5) * (D / d) tmp = 0 if ((h / l) * math.pow(((D * M) / (d * 2.0)), 2.0)) <= -1e-13: tmp = w0 * math.sqrt((1.0 - ((h * (t_0 * t_0)) / l))) else: tmp = w0 return tmp
function code(w0, M, D, h, l, d) t_0 = Float64(Float64(M * 0.5) * Float64(D / d)) tmp = 0.0 if (Float64(Float64(h / l) * (Float64(Float64(D * M) / Float64(d * 2.0)) ^ 2.0)) <= -1e-13) tmp = Float64(w0 * sqrt(Float64(1.0 - Float64(Float64(h * Float64(t_0 * t_0)) / l)))); else tmp = w0; end return tmp end
function tmp_2 = code(w0, M, D, h, l, d) t_0 = (M * 0.5) * (D / d); tmp = 0.0; if (((h / l) * (((D * M) / (d * 2.0)) ^ 2.0)) <= -1e-13) tmp = w0 * sqrt((1.0 - ((h * (t_0 * t_0)) / l))); else tmp = w0; end tmp_2 = tmp; end
code[w0_, M_, D_, h_, l_, d_] := Block[{t$95$0 = N[(N[(M * 0.5), $MachinePrecision] * N[(D / d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[(h / l), $MachinePrecision] * N[Power[N[(N[(D * M), $MachinePrecision] / N[(d * 2.0), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision], -1e-13], N[(w0 * N[Sqrt[N[(1.0 - N[(N[(h * N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], w0]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(M \cdot 0.5\right) \cdot \frac{D}{d}\\
\mathbf{if}\;\frac{h}{\ell} \cdot {\left(\frac{D \cdot M}{d \cdot 2}\right)}^{2} \leq -1 \cdot 10^{-13}:\\
\;\;\;\;w0 \cdot \sqrt{1 - \frac{h \cdot \left(t\_0 \cdot t\_0\right)}{\ell}}\\
\mathbf{else}:\\
\;\;\;\;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)) < -1e-13Initial program 59.1%
Simplified57.9%
associate-*r/63.9%
*-commutative63.9%
associate-*l/67.4%
associate-*r/64.7%
div-inv64.7%
metadata-eval64.7%
Applied egg-rr64.7%
unpow264.7%
Applied egg-rr64.7%
if -1e-13 < (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) #s(literal 2 binary64)) (/.f64 h l)) Initial program 88.6%
Simplified88.6%
Taylor expanded in D around 0 97.3%
Final simplification87.1%
(FPCore (w0 M D h l d) :precision binary64 w0)
double code(double w0, double M, double D, double h, double l, double d) {
return w0;
}
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
end function
public static double code(double w0, double M, double D, double h, double l, double d) {
return w0;
}
def code(w0, M, D, h, l, d): return w0
function code(w0, M, D, h, l, d) return w0 end
function tmp = code(w0, M, D, h, l, d) tmp = w0; end
code[w0_, M_, D_, h_, l_, d_] := w0
\begin{array}{l}
\\
w0
\end{array}
Initial program 79.4%
Simplified79.0%
Taylor expanded in D around 0 69.1%
Final simplification69.1%
herbie shell --seed 2024058
(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))))))