
(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 5 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}
D_m = (fabs.f64 D) NOTE: w0, M, D_m, h, l, and d should be sorted in increasing order before calling this function. (FPCore (w0 M D_m h l d) :precision binary64 (* w0 (sqrt (- 1.0 (* h (/ (pow (* D_m (* M (/ 0.5 d))) 2.0) l))))))
D_m = fabs(D);
assert(w0 < M && M < D_m && D_m < h && h < l && l < d);
double code(double w0, double M, double D_m, double h, double l, double d) {
return w0 * sqrt((1.0 - (h * (pow((D_m * (M * (0.5 / d))), 2.0) / l))));
}
D_m = abs(d)
NOTE: w0, M, D_m, h, l, and d should be sorted in increasing order before calling this function.
real(8) function code(w0, m, d_m, h, l, d)
real(8), intent (in) :: w0
real(8), intent (in) :: m
real(8), intent (in) :: d_m
real(8), intent (in) :: h
real(8), intent (in) :: l
real(8), intent (in) :: d
code = w0 * sqrt((1.0d0 - (h * (((d_m * (m * (0.5d0 / d))) ** 2.0d0) / l))))
end function
D_m = Math.abs(D);
assert w0 < M && M < D_m && D_m < h && h < l && l < d;
public static double code(double w0, double M, double D_m, double h, double l, double d) {
return w0 * Math.sqrt((1.0 - (h * (Math.pow((D_m * (M * (0.5 / d))), 2.0) / l))));
}
D_m = math.fabs(D) [w0, M, D_m, h, l, d] = sort([w0, M, D_m, h, l, d]) def code(w0, M, D_m, h, l, d): return w0 * math.sqrt((1.0 - (h * (math.pow((D_m * (M * (0.5 / d))), 2.0) / l))))
D_m = abs(D) w0, M, D_m, h, l, d = sort([w0, M, D_m, h, l, d]) function code(w0, M, D_m, h, l, d) return Float64(w0 * sqrt(Float64(1.0 - Float64(h * Float64((Float64(D_m * Float64(M * Float64(0.5 / d))) ^ 2.0) / l))))) end
D_m = abs(D);
w0, M, D_m, h, l, d = num2cell(sort([w0, M, D_m, h, l, d])){:}
function tmp = code(w0, M, D_m, h, l, d)
tmp = w0 * sqrt((1.0 - (h * (((D_m * (M * (0.5 / d))) ^ 2.0) / l))));
end
D_m = N[Abs[D], $MachinePrecision] NOTE: w0, M, D_m, h, l, and d should be sorted in increasing order before calling this function. code[w0_, M_, D$95$m_, h_, l_, d_] := N[(w0 * N[Sqrt[N[(1.0 - N[(h * N[(N[Power[N[(D$95$m * N[(M * N[(0.5 / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
D_m = \left|D\right|
\\
[w0, M, D_m, h, l, d] = \mathsf{sort}([w0, M, D_m, h, l, d])\\
\\
w0 \cdot \sqrt{1 - h \cdot \frac{{\left(D\_m \cdot \left(M \cdot \frac{0.5}{d}\right)\right)}^{2}}{\ell}}
\end{array}
Initial program 84.5%
Simplified84.1%
clear-num84.0%
un-div-inv84.0%
*-commutative84.0%
associate-*l/84.4%
associate-*r/83.5%
div-inv83.5%
metadata-eval83.5%
Applied egg-rr83.5%
associate-/r/86.5%
associate-*l/86.5%
*-commutative86.5%
associate-/l*86.5%
associate-*r/87.4%
*-commutative87.4%
associate-/l*87.0%
associate-*r/87.0%
Simplified87.0%
D_m = (fabs.f64 D) NOTE: w0, M, D_m, h, l, and d should be sorted in increasing order before calling this function. (FPCore (w0 M D_m h l d) :precision binary64 (fma -0.125 (/ (* h (* w0 (pow (* D_m (/ M d)) 2.0))) l) w0))
D_m = fabs(D);
assert(w0 < M && M < D_m && D_m < h && h < l && l < d);
double code(double w0, double M, double D_m, double h, double l, double d) {
return fma(-0.125, ((h * (w0 * pow((D_m * (M / d)), 2.0))) / l), w0);
}
D_m = abs(D) w0, M, D_m, h, l, d = sort([w0, M, D_m, h, l, d]) function code(w0, M, D_m, h, l, d) return fma(-0.125, Float64(Float64(h * Float64(w0 * (Float64(D_m * Float64(M / d)) ^ 2.0))) / l), w0) end
D_m = N[Abs[D], $MachinePrecision] NOTE: w0, M, D_m, h, l, and d should be sorted in increasing order before calling this function. code[w0_, M_, D$95$m_, h_, l_, d_] := N[(-0.125 * N[(N[(h * N[(w0 * N[Power[N[(D$95$m * N[(M / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision] + w0), $MachinePrecision]
\begin{array}{l}
D_m = \left|D\right|
\\
[w0, M, D_m, h, l, d] = \mathsf{sort}([w0, M, D_m, h, l, d])\\
\\
\mathsf{fma}\left(-0.125, \frac{h \cdot \left(w0 \cdot {\left(D\_m \cdot \frac{M}{d}\right)}^{2}\right)}{\ell}, w0\right)
\end{array}
Initial program 84.5%
Simplified84.1%
Taylor expanded in D around 0 57.6%
+-commutative57.6%
fma-define57.6%
associate-*r*57.5%
unpow257.5%
unpow257.5%
swap-sqr64.3%
unpow264.3%
Simplified64.3%
times-frac65.3%
Applied egg-rr65.3%
associate-*r/68.4%
div-inv67.7%
pow-flip67.7%
metadata-eval67.7%
Applied egg-rr67.7%
pow167.7%
*-commutative67.7%
metadata-eval67.7%
pow-flip67.7%
div-inv68.4%
add-sqr-sqrt68.4%
pow268.4%
sqrt-div68.4%
sqrt-pow170.9%
metadata-eval70.9%
pow170.9%
sqrt-pow178.3%
metadata-eval78.3%
pow178.3%
Applied egg-rr78.3%
unpow178.3%
associate-*l*81.9%
associate-/l*81.5%
Simplified81.5%
D_m = (fabs.f64 D)
NOTE: w0, M, D_m, h, l, and d should be sorted in increasing order before calling this function.
(FPCore (w0 M D_m h l d)
:precision binary64
(if (<= M 1.3e-194)
w0
(+
w0
(* -0.5 (* (/ 1.0 (* l 4.0)) (* (* w0 h) (pow (/ (* D_m M) d) 2.0)))))))D_m = fabs(D);
assert(w0 < M && M < D_m && D_m < h && h < l && l < d);
double code(double w0, double M, double D_m, double h, double l, double d) {
double tmp;
if (M <= 1.3e-194) {
tmp = w0;
} else {
tmp = w0 + (-0.5 * ((1.0 / (l * 4.0)) * ((w0 * h) * pow(((D_m * M) / d), 2.0))));
}
return tmp;
}
D_m = abs(d)
NOTE: w0, M, D_m, h, l, and d should be sorted in increasing order before calling this function.
real(8) function code(w0, m, d_m, h, l, d)
real(8), intent (in) :: w0
real(8), intent (in) :: m
real(8), intent (in) :: d_m
real(8), intent (in) :: h
real(8), intent (in) :: l
real(8), intent (in) :: d
real(8) :: tmp
if (m <= 1.3d-194) then
tmp = w0
else
tmp = w0 + ((-0.5d0) * ((1.0d0 / (l * 4.0d0)) * ((w0 * h) * (((d_m * m) / d) ** 2.0d0))))
end if
code = tmp
end function
D_m = Math.abs(D);
assert w0 < M && M < D_m && D_m < h && h < l && l < d;
public static double code(double w0, double M, double D_m, double h, double l, double d) {
double tmp;
if (M <= 1.3e-194) {
tmp = w0;
} else {
tmp = w0 + (-0.5 * ((1.0 / (l * 4.0)) * ((w0 * h) * Math.pow(((D_m * M) / d), 2.0))));
}
return tmp;
}
D_m = math.fabs(D) [w0, M, D_m, h, l, d] = sort([w0, M, D_m, h, l, d]) def code(w0, M, D_m, h, l, d): tmp = 0 if M <= 1.3e-194: tmp = w0 else: tmp = w0 + (-0.5 * ((1.0 / (l * 4.0)) * ((w0 * h) * math.pow(((D_m * M) / d), 2.0)))) return tmp
D_m = abs(D) w0, M, D_m, h, l, d = sort([w0, M, D_m, h, l, d]) function code(w0, M, D_m, h, l, d) tmp = 0.0 if (M <= 1.3e-194) tmp = w0; else tmp = Float64(w0 + Float64(-0.5 * Float64(Float64(1.0 / Float64(l * 4.0)) * Float64(Float64(w0 * h) * (Float64(Float64(D_m * M) / d) ^ 2.0))))); end return tmp end
D_m = abs(D);
w0, M, D_m, h, l, d = num2cell(sort([w0, M, D_m, h, l, d])){:}
function tmp_2 = code(w0, M, D_m, h, l, d)
tmp = 0.0;
if (M <= 1.3e-194)
tmp = w0;
else
tmp = w0 + (-0.5 * ((1.0 / (l * 4.0)) * ((w0 * h) * (((D_m * M) / d) ^ 2.0))));
end
tmp_2 = tmp;
end
D_m = N[Abs[D], $MachinePrecision] NOTE: w0, M, D_m, h, l, and d should be sorted in increasing order before calling this function. code[w0_, M_, D$95$m_, h_, l_, d_] := If[LessEqual[M, 1.3e-194], w0, N[(w0 + N[(-0.5 * N[(N[(1.0 / N[(l * 4.0), $MachinePrecision]), $MachinePrecision] * N[(N[(w0 * h), $MachinePrecision] * N[Power[N[(N[(D$95$m * M), $MachinePrecision] / d), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
D_m = \left|D\right|
\\
[w0, M, D_m, h, l, d] = \mathsf{sort}([w0, M, D_m, h, l, d])\\
\\
\begin{array}{l}
\mathbf{if}\;M \leq 1.3 \cdot 10^{-194}:\\
\;\;\;\;w0\\
\mathbf{else}:\\
\;\;\;\;w0 + -0.5 \cdot \left(\frac{1}{\ell \cdot 4} \cdot \left(\left(w0 \cdot h\right) \cdot {\left(\frac{D\_m \cdot M}{d}\right)}^{2}\right)\right)\\
\end{array}
\end{array}
if M < 1.30000000000000001e-194Initial program 85.7%
Simplified85.7%
Taylor expanded in D around 0 72.3%
if 1.30000000000000001e-194 < M Initial program 82.3%
add-sqr-sqrt39.1%
times-frac40.2%
Applied egg-rr40.2%
Taylor expanded in M around 0 58.0%
associate-*r*56.9%
unpow256.9%
unpow256.9%
swap-sqr57.0%
unpow257.0%
*-commutative57.0%
Simplified57.0%
unpow257.0%
Applied egg-rr57.0%
pow257.0%
*-commutative57.0%
rem-exp-log38.1%
*-un-lft-identity38.1%
*-commutative38.1%
times-frac39.3%
sqrt-pow239.3%
metadata-eval39.3%
metadata-eval39.3%
rem-exp-log59.6%
*-commutative59.6%
*-un-lft-identity59.6%
times-frac62.7%
add-sqr-sqrt62.7%
pow262.7%
Applied egg-rr74.8%
Final simplification73.2%
D_m = (fabs.f64 D) NOTE: w0, M, D_m, h, l, and d should be sorted in increasing order before calling this function. (FPCore (w0 M D_m h l d) :precision binary64 (if (<= M 3.7e-183) w0 (+ w0 (* -0.5 (* (pow (* D_m (/ M d)) 2.0) (* h (/ w0 (* l 4.0))))))))
D_m = fabs(D);
assert(w0 < M && M < D_m && D_m < h && h < l && l < d);
double code(double w0, double M, double D_m, double h, double l, double d) {
double tmp;
if (M <= 3.7e-183) {
tmp = w0;
} else {
tmp = w0 + (-0.5 * (pow((D_m * (M / d)), 2.0) * (h * (w0 / (l * 4.0)))));
}
return tmp;
}
D_m = abs(d)
NOTE: w0, M, D_m, h, l, and d should be sorted in increasing order before calling this function.
real(8) function code(w0, m, d_m, h, l, d)
real(8), intent (in) :: w0
real(8), intent (in) :: m
real(8), intent (in) :: d_m
real(8), intent (in) :: h
real(8), intent (in) :: l
real(8), intent (in) :: d
real(8) :: tmp
if (m <= 3.7d-183) then
tmp = w0
else
tmp = w0 + ((-0.5d0) * (((d_m * (m / d)) ** 2.0d0) * (h * (w0 / (l * 4.0d0)))))
end if
code = tmp
end function
D_m = Math.abs(D);
assert w0 < M && M < D_m && D_m < h && h < l && l < d;
public static double code(double w0, double M, double D_m, double h, double l, double d) {
double tmp;
if (M <= 3.7e-183) {
tmp = w0;
} else {
tmp = w0 + (-0.5 * (Math.pow((D_m * (M / d)), 2.0) * (h * (w0 / (l * 4.0)))));
}
return tmp;
}
D_m = math.fabs(D) [w0, M, D_m, h, l, d] = sort([w0, M, D_m, h, l, d]) def code(w0, M, D_m, h, l, d): tmp = 0 if M <= 3.7e-183: tmp = w0 else: tmp = w0 + (-0.5 * (math.pow((D_m * (M / d)), 2.0) * (h * (w0 / (l * 4.0))))) return tmp
D_m = abs(D) w0, M, D_m, h, l, d = sort([w0, M, D_m, h, l, d]) function code(w0, M, D_m, h, l, d) tmp = 0.0 if (M <= 3.7e-183) tmp = w0; else tmp = Float64(w0 + Float64(-0.5 * Float64((Float64(D_m * Float64(M / d)) ^ 2.0) * Float64(h * Float64(w0 / Float64(l * 4.0)))))); end return tmp end
D_m = abs(D);
w0, M, D_m, h, l, d = num2cell(sort([w0, M, D_m, h, l, d])){:}
function tmp_2 = code(w0, M, D_m, h, l, d)
tmp = 0.0;
if (M <= 3.7e-183)
tmp = w0;
else
tmp = w0 + (-0.5 * (((D_m * (M / d)) ^ 2.0) * (h * (w0 / (l * 4.0)))));
end
tmp_2 = tmp;
end
D_m = N[Abs[D], $MachinePrecision] NOTE: w0, M, D_m, h, l, and d should be sorted in increasing order before calling this function. code[w0_, M_, D$95$m_, h_, l_, d_] := If[LessEqual[M, 3.7e-183], w0, N[(w0 + N[(-0.5 * N[(N[Power[N[(D$95$m * N[(M / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(h * N[(w0 / N[(l * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
D_m = \left|D\right|
\\
[w0, M, D_m, h, l, d] = \mathsf{sort}([w0, M, D_m, h, l, d])\\
\\
\begin{array}{l}
\mathbf{if}\;M \leq 3.7 \cdot 10^{-183}:\\
\;\;\;\;w0\\
\mathbf{else}:\\
\;\;\;\;w0 + -0.5 \cdot \left({\left(D\_m \cdot \frac{M}{d}\right)}^{2} \cdot \left(h \cdot \frac{w0}{\ell \cdot 4}\right)\right)\\
\end{array}
\end{array}
if M < 3.6999999999999999e-183Initial program 85.6%
Simplified85.6%
Taylor expanded in D around 0 73.3%
if 3.6999999999999999e-183 < M Initial program 82.2%
add-sqr-sqrt38.4%
times-frac39.5%
Applied egg-rr39.5%
Taylor expanded in M around 0 56.2%
associate-*r*55.0%
unpow255.0%
unpow255.0%
swap-sqr55.2%
unpow255.2%
*-commutative55.2%
Simplified55.2%
unpow255.2%
Applied egg-rr55.2%
*-un-lft-identity55.2%
pow255.2%
*-commutative55.2%
times-frac57.8%
add-sqr-sqrt57.8%
pow257.8%
sqrt-div57.8%
sqrt-pow161.5%
metadata-eval61.5%
pow161.5%
sqrt-pow170.5%
metadata-eval70.5%
pow170.5%
sqrt-pow270.5%
metadata-eval70.5%
metadata-eval70.5%
Applied egg-rr70.5%
*-lft-identity70.5%
associate-/l*70.4%
associate-/l*71.5%
Simplified71.5%
D_m = (fabs.f64 D) NOTE: w0, M, D_m, h, l, and d should be sorted in increasing order before calling this function. (FPCore (w0 M D_m h l d) :precision binary64 w0)
D_m = fabs(D);
assert(w0 < M && M < D_m && D_m < h && h < l && l < d);
double code(double w0, double M, double D_m, double h, double l, double d) {
return w0;
}
D_m = abs(d)
NOTE: w0, M, D_m, h, l, and d should be sorted in increasing order before calling this function.
real(8) function code(w0, m, d_m, h, l, d)
real(8), intent (in) :: w0
real(8), intent (in) :: m
real(8), intent (in) :: d_m
real(8), intent (in) :: h
real(8), intent (in) :: l
real(8), intent (in) :: d
code = w0
end function
D_m = Math.abs(D);
assert w0 < M && M < D_m && D_m < h && h < l && l < d;
public static double code(double w0, double M, double D_m, double h, double l, double d) {
return w0;
}
D_m = math.fabs(D) [w0, M, D_m, h, l, d] = sort([w0, M, D_m, h, l, d]) def code(w0, M, D_m, h, l, d): return w0
D_m = abs(D) w0, M, D_m, h, l, d = sort([w0, M, D_m, h, l, d]) function code(w0, M, D_m, h, l, d) return w0 end
D_m = abs(D);
w0, M, D_m, h, l, d = num2cell(sort([w0, M, D_m, h, l, d])){:}
function tmp = code(w0, M, D_m, h, l, d)
tmp = w0;
end
D_m = N[Abs[D], $MachinePrecision] NOTE: w0, M, D_m, h, l, and d should be sorted in increasing order before calling this function. code[w0_, M_, D$95$m_, h_, l_, d_] := w0
\begin{array}{l}
D_m = \left|D\right|
\\
[w0, M, D_m, h, l, d] = \mathsf{sort}([w0, M, D_m, h, l, d])\\
\\
w0
\end{array}
Initial program 84.5%
Simplified84.1%
Taylor expanded in D around 0 68.5%
herbie shell --seed 2024108
(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))))))