
(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}
M_m = (fabs.f64 M)
NOTE: w0, M_m, D, h, l, and d should be sorted in increasing order before calling this function.
(FPCore (w0 M_m D h l d)
:precision binary64
(let* ((t_0 (- 1.0 (* (pow (/ (* M_m D) (* 2.0 d)) 2.0) (/ h l))))
(t_1 (/ M_m (/ d (* D 0.5)))))
(if (<= t_0 5e+292)
(* w0 (sqrt t_0))
(* w0 (sqrt (- 1.0 (* h (* t_1 (/ t_1 l)))))))))M_m = fabs(M);
assert(w0 < M_m && M_m < D && D < h && h < l && l < d);
double code(double w0, double M_m, double D, double h, double l, double d) {
double t_0 = 1.0 - (pow(((M_m * D) / (2.0 * d)), 2.0) * (h / l));
double t_1 = M_m / (d / (D * 0.5));
double tmp;
if (t_0 <= 5e+292) {
tmp = w0 * sqrt(t_0);
} else {
tmp = w0 * sqrt((1.0 - (h * (t_1 * (t_1 / l)))));
}
return tmp;
}
M_m = abs(M)
NOTE: w0, M_m, D, h, l, and d should be sorted in increasing order before calling this function.
real(8) function code(w0, m_m, d, h, l, d_1)
real(8), intent (in) :: w0
real(8), intent (in) :: m_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) :: t_1
real(8) :: tmp
t_0 = 1.0d0 - ((((m_m * d) / (2.0d0 * d_1)) ** 2.0d0) * (h / l))
t_1 = m_m / (d_1 / (d * 0.5d0))
if (t_0 <= 5d+292) then
tmp = w0 * sqrt(t_0)
else
tmp = w0 * sqrt((1.0d0 - (h * (t_1 * (t_1 / l)))))
end if
code = tmp
end function
M_m = Math.abs(M);
assert w0 < M_m && M_m < D && D < h && h < l && l < d;
public static double code(double w0, double M_m, double D, double h, double l, double d) {
double t_0 = 1.0 - (Math.pow(((M_m * D) / (2.0 * d)), 2.0) * (h / l));
double t_1 = M_m / (d / (D * 0.5));
double tmp;
if (t_0 <= 5e+292) {
tmp = w0 * Math.sqrt(t_0);
} else {
tmp = w0 * Math.sqrt((1.0 - (h * (t_1 * (t_1 / l)))));
}
return tmp;
}
M_m = math.fabs(M) [w0, M_m, D, h, l, d] = sort([w0, M_m, D, h, l, d]) def code(w0, M_m, D, h, l, d): t_0 = 1.0 - (math.pow(((M_m * D) / (2.0 * d)), 2.0) * (h / l)) t_1 = M_m / (d / (D * 0.5)) tmp = 0 if t_0 <= 5e+292: tmp = w0 * math.sqrt(t_0) else: tmp = w0 * math.sqrt((1.0 - (h * (t_1 * (t_1 / l))))) return tmp
M_m = abs(M) w0, M_m, D, h, l, d = sort([w0, M_m, D, h, l, d]) function code(w0, M_m, D, h, l, d) t_0 = Float64(1.0 - Float64((Float64(Float64(M_m * D) / Float64(2.0 * d)) ^ 2.0) * Float64(h / l))) t_1 = Float64(M_m / Float64(d / Float64(D * 0.5))) tmp = 0.0 if (t_0 <= 5e+292) tmp = Float64(w0 * sqrt(t_0)); else tmp = Float64(w0 * sqrt(Float64(1.0 - Float64(h * Float64(t_1 * Float64(t_1 / l)))))); end return tmp end
M_m = abs(M);
w0, M_m, D, h, l, d = num2cell(sort([w0, M_m, D, h, l, d])){:}
function tmp_2 = code(w0, M_m, D, h, l, d)
t_0 = 1.0 - ((((M_m * D) / (2.0 * d)) ^ 2.0) * (h / l));
t_1 = M_m / (d / (D * 0.5));
tmp = 0.0;
if (t_0 <= 5e+292)
tmp = w0 * sqrt(t_0);
else
tmp = w0 * sqrt((1.0 - (h * (t_1 * (t_1 / l)))));
end
tmp_2 = tmp;
end
M_m = N[Abs[M], $MachinePrecision]
NOTE: w0, M_m, D, h, l, and d should be sorted in increasing order before calling this function.
code[w0_, M$95$m_, D_, h_, l_, d_] := Block[{t$95$0 = N[(1.0 - N[(N[Power[N[(N[(M$95$m * D), $MachinePrecision] / N[(2.0 * d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(M$95$m / N[(d / N[(D * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 5e+292], N[(w0 * N[Sqrt[t$95$0], $MachinePrecision]), $MachinePrecision], N[(w0 * N[Sqrt[N[(1.0 - N[(h * N[(t$95$1 * N[(t$95$1 / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
M_m = \left|M\right|
\\
[w0, M_m, D, h, l, d] = \mathsf{sort}([w0, M_m, D, h, l, d])\\
\\
\begin{array}{l}
t_0 := 1 - {\left(\frac{M\_m \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}\\
t_1 := \frac{M\_m}{\frac{d}{D \cdot 0.5}}\\
\mathbf{if}\;t\_0 \leq 5 \cdot 10^{+292}:\\
\;\;\;\;w0 \cdot \sqrt{t\_0}\\
\mathbf{else}:\\
\;\;\;\;w0 \cdot \sqrt{1 - h \cdot \left(t\_1 \cdot \frac{t\_1}{\ell}\right)}\\
\end{array}
\end{array}
if (-.f64 1 (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 2 d)) 2) (/.f64 h l))) < 4.9999999999999996e292Initial program 99.9%
if 4.9999999999999996e292 < (-.f64 1 (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 2 d)) 2) (/.f64 h l))) Initial program 39.5%
Simplified41.7%
associate-/l*39.5%
clear-num39.5%
un-div-inv39.9%
associate-/l*42.1%
div-inv42.1%
clear-num42.1%
associate-/r*42.1%
Applied egg-rr42.1%
associate-/r/59.9%
associate-*r/59.4%
div-inv59.4%
metadata-eval59.4%
Applied egg-rr59.4%
unpow259.4%
*-un-lft-identity59.4%
times-frac67.3%
associate-/l*64.2%
associate-/l*67.2%
Applied egg-rr67.2%
Final simplification88.8%
M_m = (fabs.f64 M) NOTE: w0, M_m, D, h, l, and d should be sorted in increasing order before calling this function. (FPCore (w0 M_m D h l d) :precision binary64 (let* ((t_0 (* (* D 0.5) (/ M_m d)))) (* w0 (sqrt (- 1.0 (* h (* t_0 (/ t_0 l))))))))
M_m = fabs(M);
assert(w0 < M_m && M_m < D && D < h && h < l && l < d);
double code(double w0, double M_m, double D, double h, double l, double d) {
double t_0 = (D * 0.5) * (M_m / d);
return w0 * sqrt((1.0 - (h * (t_0 * (t_0 / l)))));
}
M_m = abs(M)
NOTE: w0, M_m, D, h, l, and d should be sorted in increasing order before calling this function.
real(8) function code(w0, m_m, d, h, l, d_1)
real(8), intent (in) :: w0
real(8), intent (in) :: m_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
t_0 = (d * 0.5d0) * (m_m / d_1)
code = w0 * sqrt((1.0d0 - (h * (t_0 * (t_0 / l)))))
end function
M_m = Math.abs(M);
assert w0 < M_m && M_m < D && D < h && h < l && l < d;
public static double code(double w0, double M_m, double D, double h, double l, double d) {
double t_0 = (D * 0.5) * (M_m / d);
return w0 * Math.sqrt((1.0 - (h * (t_0 * (t_0 / l)))));
}
M_m = math.fabs(M) [w0, M_m, D, h, l, d] = sort([w0, M_m, D, h, l, d]) def code(w0, M_m, D, h, l, d): t_0 = (D * 0.5) * (M_m / d) return w0 * math.sqrt((1.0 - (h * (t_0 * (t_0 / l)))))
M_m = abs(M) w0, M_m, D, h, l, d = sort([w0, M_m, D, h, l, d]) function code(w0, M_m, D, h, l, d) t_0 = Float64(Float64(D * 0.5) * Float64(M_m / d)) return Float64(w0 * sqrt(Float64(1.0 - Float64(h * Float64(t_0 * Float64(t_0 / l)))))) end
M_m = abs(M);
w0, M_m, D, h, l, d = num2cell(sort([w0, M_m, D, h, l, d])){:}
function tmp = code(w0, M_m, D, h, l, d)
t_0 = (D * 0.5) * (M_m / d);
tmp = w0 * sqrt((1.0 - (h * (t_0 * (t_0 / l)))));
end
M_m = N[Abs[M], $MachinePrecision]
NOTE: w0, M_m, D, h, l, and d should be sorted in increasing order before calling this function.
code[w0_, M$95$m_, D_, h_, l_, d_] := Block[{t$95$0 = N[(N[(D * 0.5), $MachinePrecision] * N[(M$95$m / d), $MachinePrecision]), $MachinePrecision]}, N[(w0 * N[Sqrt[N[(1.0 - N[(h * N[(t$95$0 * N[(t$95$0 / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
M_m = \left|M\right|
\\
[w0, M_m, D, h, l, d] = \mathsf{sort}([w0, M_m, D, h, l, d])\\
\\
\begin{array}{l}
t_0 := \left(D \cdot 0.5\right) \cdot \frac{M\_m}{d}\\
w0 \cdot \sqrt{1 - h \cdot \left(t\_0 \cdot \frac{t\_0}{\ell}\right)}
\end{array}
\end{array}
Initial program 79.4%
Simplified79.0%
associate-/l*79.4%
clear-num79.4%
un-div-inv79.5%
associate-/l*79.2%
div-inv79.1%
clear-num79.2%
associate-/r*79.2%
Applied egg-rr79.2%
associate-/r/83.3%
associate-*r/84.3%
div-inv84.3%
metadata-eval84.3%
Applied egg-rr84.3%
unpow284.3%
associate-/l*82.6%
associate-/l*83.3%
Applied egg-rr83.3%
associate-*r/85.8%
*-commutative85.8%
associate-/r/85.1%
associate-/r/87.2%
Applied egg-rr87.2%
Final simplification87.2%
M_m = (fabs.f64 M) NOTE: w0, M_m, D, h, l, and d should be sorted in increasing order before calling this function. (FPCore (w0 M_m D h l d) :precision binary64 w0)
M_m = fabs(M);
assert(w0 < M_m && M_m < D && D < h && h < l && l < d);
double code(double w0, double M_m, double D, double h, double l, double d) {
return w0;
}
M_m = abs(M)
NOTE: w0, M_m, D, h, l, and d should be sorted in increasing order before calling this function.
real(8) function code(w0, m_m, d, h, l, d_1)
real(8), intent (in) :: w0
real(8), intent (in) :: m_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
M_m = Math.abs(M);
assert w0 < M_m && M_m < D && D < h && h < l && l < d;
public static double code(double w0, double M_m, double D, double h, double l, double d) {
return w0;
}
M_m = math.fabs(M) [w0, M_m, D, h, l, d] = sort([w0, M_m, D, h, l, d]) def code(w0, M_m, D, h, l, d): return w0
M_m = abs(M) w0, M_m, D, h, l, d = sort([w0, M_m, D, h, l, d]) function code(w0, M_m, D, h, l, d) return w0 end
M_m = abs(M);
w0, M_m, D, h, l, d = num2cell(sort([w0, M_m, D, h, l, d])){:}
function tmp = code(w0, M_m, D, h, l, d)
tmp = w0;
end
M_m = N[Abs[M], $MachinePrecision] NOTE: w0, M_m, D, h, l, and d should be sorted in increasing order before calling this function. code[w0_, M$95$m_, D_, h_, l_, d_] := w0
\begin{array}{l}
M_m = \left|M\right|
\\
[w0, M_m, D, h, l, d] = \mathsf{sort}([w0, M_m, D, h, l, d])\\
\\
w0
\end{array}
Initial program 79.4%
Simplified79.0%
Taylor expanded in M around 0 63.4%
Final simplification63.4%
herbie shell --seed 2024027
(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))))))