
(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)
D_m = (fabs.f64 D)
d_m = (fabs.f64 d)
NOTE: w0, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
(FPCore (w0 M_m D_m h l d_m)
:precision binary64
(if (<= (* (pow (/ (* M_m D_m) (* 2.0 d_m)) 2.0) (/ h l)) (- INFINITY))
(pow
(*
(cbrt w0)
(exp
(*
0.16666666666666666
(+
(log (* 0.25 (/ (* h (pow (* M_m D_m) 2.0)) (- l))))
(* -2.0 (log d_m))))))
3.0)
(*
w0
(sqrt
(-
1.0
(*
h
(* (* D_m (* 0.5 (/ M_m d_m))) (* D_m (* (/ M_m d_m) (/ 0.5 l))))))))))M_m = fabs(M);
D_m = fabs(D);
d_m = fabs(d);
assert(w0 < M_m && M_m < D_m && D_m < h && h < l && l < d_m);
double code(double w0, double M_m, double D_m, double h, double l, double d_m) {
double tmp;
if ((pow(((M_m * D_m) / (2.0 * d_m)), 2.0) * (h / l)) <= -((double) INFINITY)) {
tmp = pow((cbrt(w0) * exp((0.16666666666666666 * (log((0.25 * ((h * pow((M_m * D_m), 2.0)) / -l))) + (-2.0 * log(d_m)))))), 3.0);
} else {
tmp = w0 * sqrt((1.0 - (h * ((D_m * (0.5 * (M_m / d_m))) * (D_m * ((M_m / d_m) * (0.5 / l)))))));
}
return tmp;
}
M_m = Math.abs(M);
D_m = Math.abs(D);
d_m = Math.abs(d);
assert w0 < M_m && M_m < D_m && D_m < h && h < l && l < d_m;
public static double code(double w0, double M_m, double D_m, double h, double l, double d_m) {
double tmp;
if ((Math.pow(((M_m * D_m) / (2.0 * d_m)), 2.0) * (h / l)) <= -Double.POSITIVE_INFINITY) {
tmp = Math.pow((Math.cbrt(w0) * Math.exp((0.16666666666666666 * (Math.log((0.25 * ((h * Math.pow((M_m * D_m), 2.0)) / -l))) + (-2.0 * Math.log(d_m)))))), 3.0);
} else {
tmp = w0 * Math.sqrt((1.0 - (h * ((D_m * (0.5 * (M_m / d_m))) * (D_m * ((M_m / d_m) * (0.5 / l)))))));
}
return tmp;
}
M_m = abs(M) D_m = abs(D) d_m = abs(d) w0, M_m, D_m, h, l, d_m = sort([w0, M_m, D_m, h, l, d_m]) function code(w0, M_m, D_m, h, l, d_m) tmp = 0.0 if (Float64((Float64(Float64(M_m * D_m) / Float64(2.0 * d_m)) ^ 2.0) * Float64(h / l)) <= Float64(-Inf)) tmp = Float64(cbrt(w0) * exp(Float64(0.16666666666666666 * Float64(log(Float64(0.25 * Float64(Float64(h * (Float64(M_m * D_m) ^ 2.0)) / Float64(-l)))) + Float64(-2.0 * log(d_m)))))) ^ 3.0; else tmp = Float64(w0 * sqrt(Float64(1.0 - Float64(h * Float64(Float64(D_m * Float64(0.5 * Float64(M_m / d_m))) * Float64(D_m * Float64(Float64(M_m / d_m) * Float64(0.5 / l)))))))); end return tmp end
M_m = N[Abs[M], $MachinePrecision] D_m = N[Abs[D], $MachinePrecision] d_m = N[Abs[d], $MachinePrecision] NOTE: w0, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function. code[w0_, M$95$m_, D$95$m_, h_, l_, d$95$m_] := If[LessEqual[N[(N[Power[N[(N[(M$95$m * D$95$m), $MachinePrecision] / N[(2.0 * d$95$m), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision], (-Infinity)], N[Power[N[(N[Power[w0, 1/3], $MachinePrecision] * N[Exp[N[(0.16666666666666666 * N[(N[Log[N[(0.25 * N[(N[(h * N[Power[N[(M$95$m * D$95$m), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / (-l)), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + N[(-2.0 * N[Log[d$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 3.0], $MachinePrecision], N[(w0 * N[Sqrt[N[(1.0 - N[(h * N[(N[(D$95$m * N[(0.5 * N[(M$95$m / d$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(D$95$m * N[(N[(M$95$m / d$95$m), $MachinePrecision] * N[(0.5 / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
d_m = \left|d\right|
\\
[w0, M_m, D_m, h, l, d_m] = \mathsf{sort}([w0, M_m, D_m, h, l, d_m])\\
\\
\begin{array}{l}
\mathbf{if}\;{\left(\frac{M\_m \cdot D\_m}{2 \cdot d\_m}\right)}^{2} \cdot \frac{h}{\ell} \leq -\infty:\\
\;\;\;\;{\left(\sqrt[3]{w0} \cdot e^{0.16666666666666666 \cdot \left(\log \left(0.25 \cdot \frac{h \cdot {\left(M\_m \cdot D\_m\right)}^{2}}{-\ell}\right) + -2 \cdot \log d\_m\right)}\right)}^{3}\\
\mathbf{else}:\\
\;\;\;\;w0 \cdot \sqrt{1 - h \cdot \left(\left(D\_m \cdot \left(0.5 \cdot \frac{M\_m}{d\_m}\right)\right) \cdot \left(D\_m \cdot \left(\frac{M\_m}{d\_m} \cdot \frac{0.5}{\ell}\right)\right)\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)) < -inf.0Initial program 53.9%
Simplified55.3%
*-commutative55.3%
add-cbrt-cube55.3%
add-cbrt-cube46.5%
cbrt-unprod46.5%
Applied egg-rr46.5%
Simplified47.9%
Applied egg-rr55.3%
Taylor expanded in d around 0 25.6%
pow125.6%
associate-*r*24.4%
pow-prod-down29.6%
Applied egg-rr29.6%
unpow129.6%
*-commutative29.6%
Simplified29.6%
if -inf.0 < (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) #s(literal 2 binary64)) (/.f64 h l)) Initial program 88.2%
Simplified88.8%
add-sqr-sqrt41.1%
sqrt-unprod25.1%
*-commutative25.1%
*-commutative25.1%
swap-sqr25.1%
Applied egg-rr25.1%
associate-*l/27.9%
associate-/l*27.9%
associate-*l/27.9%
*-commutative27.9%
associate-*l/27.9%
associate-/l/27.9%
associate-/r/27.9%
associate-*l/27.9%
*-commutative27.9%
associate-*r/27.9%
*-commutative27.9%
associate-/l/27.9%
associate-/l*27.9%
Simplified27.9%
unpow227.9%
associate-/l*27.9%
*-un-lft-identity27.9%
times-frac27.9%
metadata-eval27.9%
*-un-lft-identity27.9%
times-frac27.9%
metadata-eval27.9%
Applied egg-rr27.9%
associate-/l*27.4%
associate-*r/27.4%
Applied egg-rr27.4%
*-commutative27.4%
sqrt-prod27.4%
sqrt-pow195.6%
metadata-eval95.6%
pow195.6%
associate-*r*95.6%
associate-*r*95.6%
associate-/l/93.7%
Applied egg-rr93.7%
associate-*l*93.7%
associate-*l*93.7%
times-frac95.6%
Simplified95.6%
Final simplification78.1%
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
d_m = (fabs.f64 d)
NOTE: w0, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
(FPCore (w0 M_m D_m h l d_m)
:precision binary64
(*
w0
(sqrt
(-
1.0
(* h (* (* D_m (* 0.5 (/ M_m d_m))) (* D_m (* (/ M_m d_m) (/ 0.5 l)))))))))M_m = fabs(M);
D_m = fabs(D);
d_m = fabs(d);
assert(w0 < M_m && M_m < D_m && D_m < h && h < l && l < d_m);
double code(double w0, double M_m, double D_m, double h, double l, double d_m) {
return w0 * sqrt((1.0 - (h * ((D_m * (0.5 * (M_m / d_m))) * (D_m * ((M_m / d_m) * (0.5 / l)))))));
}
M_m = abs(m)
D_m = abs(d)
d_m = abs(d)
NOTE: w0, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
real(8) function code(w0, m_m, d_m, h, l, d_m_1)
real(8), intent (in) :: w0
real(8), intent (in) :: m_m
real(8), intent (in) :: d_m
real(8), intent (in) :: h
real(8), intent (in) :: l
real(8), intent (in) :: d_m_1
code = w0 * sqrt((1.0d0 - (h * ((d_m * (0.5d0 * (m_m / d_m_1))) * (d_m * ((m_m / d_m_1) * (0.5d0 / l)))))))
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
d_m = Math.abs(d);
assert w0 < M_m && M_m < D_m && D_m < h && h < l && l < d_m;
public static double code(double w0, double M_m, double D_m, double h, double l, double d_m) {
return w0 * Math.sqrt((1.0 - (h * ((D_m * (0.5 * (M_m / d_m))) * (D_m * ((M_m / d_m) * (0.5 / l)))))));
}
M_m = math.fabs(M) D_m = math.fabs(D) d_m = math.fabs(d) [w0, M_m, D_m, h, l, d_m] = sort([w0, M_m, D_m, h, l, d_m]) def code(w0, M_m, D_m, h, l, d_m): return w0 * math.sqrt((1.0 - (h * ((D_m * (0.5 * (M_m / d_m))) * (D_m * ((M_m / d_m) * (0.5 / l)))))))
M_m = abs(M) D_m = abs(D) d_m = abs(d) w0, M_m, D_m, h, l, d_m = sort([w0, M_m, D_m, h, l, d_m]) function code(w0, M_m, D_m, h, l, d_m) return Float64(w0 * sqrt(Float64(1.0 - Float64(h * Float64(Float64(D_m * Float64(0.5 * Float64(M_m / d_m))) * Float64(D_m * Float64(Float64(M_m / d_m) * Float64(0.5 / l)))))))) end
M_m = abs(M);
D_m = abs(D);
d_m = abs(d);
w0, M_m, D_m, h, l, d_m = num2cell(sort([w0, M_m, D_m, h, l, d_m])){:}
function tmp = code(w0, M_m, D_m, h, l, d_m)
tmp = w0 * sqrt((1.0 - (h * ((D_m * (0.5 * (M_m / d_m))) * (D_m * ((M_m / d_m) * (0.5 / l)))))));
end
M_m = N[Abs[M], $MachinePrecision] D_m = N[Abs[D], $MachinePrecision] d_m = N[Abs[d], $MachinePrecision] NOTE: w0, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function. code[w0_, M$95$m_, D$95$m_, h_, l_, d$95$m_] := N[(w0 * N[Sqrt[N[(1.0 - N[(h * N[(N[(D$95$m * N[(0.5 * N[(M$95$m / d$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(D$95$m * N[(N[(M$95$m / d$95$m), $MachinePrecision] * N[(0.5 / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
d_m = \left|d\right|
\\
[w0, M_m, D_m, h, l, d_m] = \mathsf{sort}([w0, M_m, D_m, h, l, d_m])\\
\\
w0 \cdot \sqrt{1 - h \cdot \left(\left(D\_m \cdot \left(0.5 \cdot \frac{M\_m}{d\_m}\right)\right) \cdot \left(D\_m \cdot \left(\frac{M\_m}{d\_m} \cdot \frac{0.5}{\ell}\right)\right)\right)}
\end{array}
Initial program 79.1%
Simplified79.9%
add-sqr-sqrt38.8%
sqrt-unprod26.7%
*-commutative26.7%
*-commutative26.7%
swap-sqr26.5%
Applied egg-rr26.5%
associate-*l/29.0%
associate-/l*29.0%
associate-*l/29.0%
*-commutative29.0%
associate-*l/29.0%
associate-/l/29.0%
associate-/r/29.0%
associate-*l/29.0%
*-commutative29.0%
associate-*r/29.0%
*-commutative29.0%
associate-/l/29.0%
associate-/l*29.0%
Simplified29.0%
unpow229.0%
associate-/l*29.1%
*-un-lft-identity29.1%
times-frac29.1%
metadata-eval29.1%
*-un-lft-identity29.1%
times-frac29.1%
metadata-eval29.1%
Applied egg-rr29.1%
associate-/l*28.7%
associate-*r/28.7%
Applied egg-rr28.7%
*-commutative28.7%
sqrt-prod29.1%
sqrt-pow186.0%
metadata-eval86.0%
pow186.0%
associate-*r*85.7%
associate-*r*85.7%
associate-/l/83.4%
Applied egg-rr83.4%
associate-*l*83.9%
associate-*l*83.9%
times-frac86.0%
Simplified86.0%
Final simplification86.0%
M_m = (fabs.f64 M) D_m = (fabs.f64 D) d_m = (fabs.f64 d) NOTE: w0, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function. (FPCore (w0 M_m D_m h l d_m) :precision binary64 w0)
M_m = fabs(M);
D_m = fabs(D);
d_m = fabs(d);
assert(w0 < M_m && M_m < D_m && D_m < h && h < l && l < d_m);
double code(double w0, double M_m, double D_m, double h, double l, double d_m) {
return w0;
}
M_m = abs(m)
D_m = abs(d)
d_m = abs(d)
NOTE: w0, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
real(8) function code(w0, m_m, d_m, h, l, d_m_1)
real(8), intent (in) :: w0
real(8), intent (in) :: m_m
real(8), intent (in) :: d_m
real(8), intent (in) :: h
real(8), intent (in) :: l
real(8), intent (in) :: d_m_1
code = w0
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
d_m = Math.abs(d);
assert w0 < M_m && M_m < D_m && D_m < h && h < l && l < d_m;
public static double code(double w0, double M_m, double D_m, double h, double l, double d_m) {
return w0;
}
M_m = math.fabs(M) D_m = math.fabs(D) d_m = math.fabs(d) [w0, M_m, D_m, h, l, d_m] = sort([w0, M_m, D_m, h, l, d_m]) def code(w0, M_m, D_m, h, l, d_m): return w0
M_m = abs(M) D_m = abs(D) d_m = abs(d) w0, M_m, D_m, h, l, d_m = sort([w0, M_m, D_m, h, l, d_m]) function code(w0, M_m, D_m, h, l, d_m) return w0 end
M_m = abs(M);
D_m = abs(D);
d_m = abs(d);
w0, M_m, D_m, h, l, d_m = num2cell(sort([w0, M_m, D_m, h, l, d_m])){:}
function tmp = code(w0, M_m, D_m, h, l, d_m)
tmp = w0;
end
M_m = N[Abs[M], $MachinePrecision] D_m = N[Abs[D], $MachinePrecision] d_m = N[Abs[d], $MachinePrecision] NOTE: w0, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function. code[w0_, M$95$m_, D$95$m_, h_, l_, d$95$m_] := w0
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
d_m = \left|d\right|
\\
[w0, M_m, D_m, h, l, d_m] = \mathsf{sort}([w0, M_m, D_m, h, l, d_m])\\
\\
w0
\end{array}
Initial program 79.1%
Simplified79.9%
Taylor expanded in D around 0 66.3%
herbie shell --seed 2024102
(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))))))