
(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 4 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: M should be positive before calling this function NOTE: D should be positive before calling this function NOTE: d should be positive before calling this function NOTE: M and D should be sorted in increasing order before calling this function. (FPCore (w0 M D h l d) :precision binary64 (if (<= (/ (* M D) (* 2.0 d)) 2e+136) (* w0 (sqrt (- 1.0 (/ (* (pow (* 0.5 (/ (* M D) d)) 2.0) h) l)))) (* w0 (/ (* D (sqrt (/ (* h -0.25) l))) (/ d M)))))
M = abs(M);
D = abs(D);
d = abs(d);
assert(M < D);
double code(double w0, double M, double D, double h, double l, double d) {
double tmp;
if (((M * D) / (2.0 * d)) <= 2e+136) {
tmp = w0 * sqrt((1.0 - ((pow((0.5 * ((M * D) / d)), 2.0) * h) / l)));
} else {
tmp = w0 * ((D * sqrt(((h * -0.25) / l))) / (d / M));
}
return tmp;
}
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: d should be positive before calling this function
NOTE: M 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 (((m * d) / (2.0d0 * d_1)) <= 2d+136) then
tmp = w0 * sqrt((1.0d0 - ((((0.5d0 * ((m * d) / d_1)) ** 2.0d0) * h) / l)))
else
tmp = w0 * ((d * sqrt(((h * (-0.25d0)) / l))) / (d_1 / m))
end if
code = tmp
end function
M = Math.abs(M);
D = Math.abs(D);
d = Math.abs(d);
assert M < D;
public static double code(double w0, double M, double D, double h, double l, double d) {
double tmp;
if (((M * D) / (2.0 * d)) <= 2e+136) {
tmp = w0 * Math.sqrt((1.0 - ((Math.pow((0.5 * ((M * D) / d)), 2.0) * h) / l)));
} else {
tmp = w0 * ((D * Math.sqrt(((h * -0.25) / l))) / (d / M));
}
return tmp;
}
M = abs(M) D = abs(D) d = abs(d) [M, D] = sort([M, D]) def code(w0, M, D, h, l, d): tmp = 0 if ((M * D) / (2.0 * d)) <= 2e+136: tmp = w0 * math.sqrt((1.0 - ((math.pow((0.5 * ((M * D) / d)), 2.0) * h) / l))) else: tmp = w0 * ((D * math.sqrt(((h * -0.25) / l))) / (d / M)) return tmp
M = abs(M) D = abs(D) d = abs(d) M, D = sort([M, D]) function code(w0, M, D, h, l, d) tmp = 0.0 if (Float64(Float64(M * D) / Float64(2.0 * d)) <= 2e+136) tmp = Float64(w0 * sqrt(Float64(1.0 - Float64(Float64((Float64(0.5 * Float64(Float64(M * D) / d)) ^ 2.0) * h) / l)))); else tmp = Float64(w0 * Float64(Float64(D * sqrt(Float64(Float64(h * -0.25) / l))) / Float64(d / M))); end return tmp end
M = abs(M)
D = abs(D)
d = abs(d)
M, D = num2cell(sort([M, D])){:}
function tmp_2 = code(w0, M, D, h, l, d)
tmp = 0.0;
if (((M * D) / (2.0 * d)) <= 2e+136)
tmp = w0 * sqrt((1.0 - ((((0.5 * ((M * D) / d)) ^ 2.0) * h) / l)));
else
tmp = w0 * ((D * sqrt(((h * -0.25) / l))) / (d / M));
end
tmp_2 = tmp;
end
NOTE: M should be positive before calling this function NOTE: D should be positive before calling this function NOTE: d should be positive before calling this function NOTE: M and D should be sorted in increasing order before calling this function. code[w0_, M_, D_, h_, l_, d_] := If[LessEqual[N[(N[(M * D), $MachinePrecision] / N[(2.0 * d), $MachinePrecision]), $MachinePrecision], 2e+136], N[(w0 * N[Sqrt[N[(1.0 - N[(N[(N[Power[N[(0.5 * N[(N[(M * D), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * h), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(w0 * N[(N[(D * N[Sqrt[N[(N[(h * -0.25), $MachinePrecision] / l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(d / M), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
M = |M|\\
D = |D|\\
d = |d|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\begin{array}{l}
\mathbf{if}\;\frac{M \cdot D}{2 \cdot d} \leq 2 \cdot 10^{+136}:\\
\;\;\;\;w0 \cdot \sqrt{1 - \frac{{\left(0.5 \cdot \frac{M \cdot D}{d}\right)}^{2} \cdot h}{\ell}}\\
\mathbf{else}:\\
\;\;\;\;w0 \cdot \frac{D \cdot \sqrt{\frac{h \cdot -0.25}{\ell}}}{\frac{d}{M}}\\
\end{array}
\end{array}
if (/.f64 (*.f64 M D) (*.f64 2 d)) < 2.00000000000000012e136Initial program 82.3%
Simplified82.3%
associate-*r/90.6%
frac-times90.6%
*-commutative90.6%
unpow290.6%
unpow290.6%
*-un-lft-identity90.6%
times-frac90.6%
metadata-eval90.6%
*-commutative90.6%
Applied egg-rr90.6%
if 2.00000000000000012e136 < (/.f64 (*.f64 M D) (*.f64 2 d)) Initial program 58.7%
Simplified62.8%
Taylor expanded in D around inf 54.1%
*-commutative54.1%
associate-*r*54.1%
times-frac49.6%
unpow249.6%
unpow249.6%
swap-sqr58.5%
unpow258.5%
Simplified58.5%
associate-*l*58.5%
sqrt-prod58.5%
sqrt-div62.7%
unpow262.7%
sqrt-prod27.2%
add-sqr-sqrt27.3%
unpow227.3%
sqrt-prod31.3%
add-sqr-sqrt71.1%
associate-/l*72.2%
Applied egg-rr72.2%
associate-*l/72.1%
associate-*l/72.1%
Applied egg-rr72.1%
Final simplification89.0%
NOTE: M should be positive before calling this function NOTE: D should be positive before calling this function NOTE: d should be positive before calling this function NOTE: M and D should be sorted in increasing order before calling this function. (FPCore (w0 M D h l d) :precision binary64 (if (<= (* (pow (/ (* M D) (* 2.0 d)) 2.0) (/ h l)) -2e+15) (* w0 (* (/ D (/ d M)) (sqrt (* -0.25 (/ h l))))) w0))
M = abs(M);
D = abs(D);
d = abs(d);
assert(M < D);
double code(double w0, double M, double D, double h, double l, double d) {
double tmp;
if ((pow(((M * D) / (2.0 * d)), 2.0) * (h / l)) <= -2e+15) {
tmp = w0 * ((D / (d / M)) * sqrt((-0.25 * (h / l))));
} else {
tmp = w0;
}
return tmp;
}
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: d should be positive before calling this function
NOTE: M 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 (((((m * d) / (2.0d0 * d_1)) ** 2.0d0) * (h / l)) <= (-2d+15)) then
tmp = w0 * ((d / (d_1 / m)) * sqrt(((-0.25d0) * (h / l))))
else
tmp = w0
end if
code = tmp
end function
M = Math.abs(M);
D = Math.abs(D);
d = Math.abs(d);
assert M < D;
public static double code(double w0, double M, double D, double h, double l, double d) {
double tmp;
if ((Math.pow(((M * D) / (2.0 * d)), 2.0) * (h / l)) <= -2e+15) {
tmp = w0 * ((D / (d / M)) * Math.sqrt((-0.25 * (h / l))));
} else {
tmp = w0;
}
return tmp;
}
M = abs(M) D = abs(D) d = abs(d) [M, D] = sort([M, D]) def code(w0, M, D, h, l, d): tmp = 0 if (math.pow(((M * D) / (2.0 * d)), 2.0) * (h / l)) <= -2e+15: tmp = w0 * ((D / (d / M)) * math.sqrt((-0.25 * (h / l)))) else: tmp = w0 return tmp
M = abs(M) D = abs(D) d = abs(d) M, D = sort([M, D]) function code(w0, M, D, h, l, d) tmp = 0.0 if (Float64((Float64(Float64(M * D) / Float64(2.0 * d)) ^ 2.0) * Float64(h / l)) <= -2e+15) tmp = Float64(w0 * Float64(Float64(D / Float64(d / M)) * sqrt(Float64(-0.25 * Float64(h / l))))); else tmp = w0; end return tmp end
M = abs(M)
D = abs(D)
d = abs(d)
M, D = num2cell(sort([M, D])){:}
function tmp_2 = code(w0, M, D, h, l, d)
tmp = 0.0;
if (((((M * D) / (2.0 * d)) ^ 2.0) * (h / l)) <= -2e+15)
tmp = w0 * ((D / (d / M)) * sqrt((-0.25 * (h / l))));
else
tmp = w0;
end
tmp_2 = tmp;
end
NOTE: M should be positive before calling this function NOTE: D should be positive before calling this function NOTE: d should be positive before calling this function NOTE: M and D should be sorted in increasing order before calling this function. code[w0_, M_, D_, h_, l_, d_] := If[LessEqual[N[(N[Power[N[(N[(M * D), $MachinePrecision] / N[(2.0 * d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision], -2e+15], N[(w0 * N[(N[(D / N[(d / M), $MachinePrecision]), $MachinePrecision] * N[Sqrt[N[(-0.25 * N[(h / l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], w0]
\begin{array}{l}
M = |M|\\
D = |D|\\
d = |d|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\begin{array}{l}
\mathbf{if}\;{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell} \leq -2 \cdot 10^{+15}:\\
\;\;\;\;w0 \cdot \left(\frac{D}{\frac{d}{M}} \cdot \sqrt{-0.25 \cdot \frac{h}{\ell}}\right)\\
\mathbf{else}:\\
\;\;\;\;w0\\
\end{array}
\end{array}
if (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 2 d)) 2) (/.f64 h l)) < -2e15Initial program 69.8%
Simplified70.9%
Taylor expanded in D around inf 39.0%
*-commutative39.0%
associate-*r*39.0%
times-frac42.8%
unpow242.8%
unpow242.8%
swap-sqr51.7%
unpow251.7%
Simplified51.7%
associate-*l*51.7%
sqrt-prod51.7%
sqrt-div52.9%
unpow252.9%
sqrt-prod30.1%
add-sqr-sqrt30.4%
unpow230.4%
sqrt-prod12.5%
add-sqr-sqrt37.2%
associate-/l*37.5%
Applied egg-rr37.5%
if -2e15 < (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 2 d)) 2) (/.f64 h l)) Initial program 85.1%
Simplified85.1%
Taylor expanded in D around 0 95.7%
Final simplification77.1%
NOTE: M should be positive before calling this function NOTE: D should be positive before calling this function NOTE: d should be positive before calling this function NOTE: M and D should be sorted in increasing order before calling this function. (FPCore (w0 M D h l d) :precision binary64 (if (<= M 1.75e-9) w0 (* w0 (* M (* (sqrt (/ (* h -0.25) l)) (/ D d))))))
M = abs(M);
D = abs(D);
d = abs(d);
assert(M < D);
double code(double w0, double M, double D, double h, double l, double d) {
double tmp;
if (M <= 1.75e-9) {
tmp = w0;
} else {
tmp = w0 * (M * (sqrt(((h * -0.25) / l)) * (D / d)));
}
return tmp;
}
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: d should be positive before calling this function
NOTE: M 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 (m <= 1.75d-9) then
tmp = w0
else
tmp = w0 * (m * (sqrt(((h * (-0.25d0)) / l)) * (d / d_1)))
end if
code = tmp
end function
M = Math.abs(M);
D = Math.abs(D);
d = Math.abs(d);
assert M < D;
public static double code(double w0, double M, double D, double h, double l, double d) {
double tmp;
if (M <= 1.75e-9) {
tmp = w0;
} else {
tmp = w0 * (M * (Math.sqrt(((h * -0.25) / l)) * (D / d)));
}
return tmp;
}
M = abs(M) D = abs(D) d = abs(d) [M, D] = sort([M, D]) def code(w0, M, D, h, l, d): tmp = 0 if M <= 1.75e-9: tmp = w0 else: tmp = w0 * (M * (math.sqrt(((h * -0.25) / l)) * (D / d))) return tmp
M = abs(M) D = abs(D) d = abs(d) M, D = sort([M, D]) function code(w0, M, D, h, l, d) tmp = 0.0 if (M <= 1.75e-9) tmp = w0; else tmp = Float64(w0 * Float64(M * Float64(sqrt(Float64(Float64(h * -0.25) / l)) * Float64(D / d)))); end return tmp end
M = abs(M)
D = abs(D)
d = abs(d)
M, D = num2cell(sort([M, D])){:}
function tmp_2 = code(w0, M, D, h, l, d)
tmp = 0.0;
if (M <= 1.75e-9)
tmp = w0;
else
tmp = w0 * (M * (sqrt(((h * -0.25) / l)) * (D / d)));
end
tmp_2 = tmp;
end
NOTE: M should be positive before calling this function NOTE: D should be positive before calling this function NOTE: d should be positive before calling this function NOTE: M and D should be sorted in increasing order before calling this function. code[w0_, M_, D_, h_, l_, d_] := If[LessEqual[M, 1.75e-9], w0, N[(w0 * N[(M * N[(N[Sqrt[N[(N[(h * -0.25), $MachinePrecision] / l), $MachinePrecision]], $MachinePrecision] * N[(D / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
M = |M|\\
D = |D|\\
d = |d|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\begin{array}{l}
\mathbf{if}\;M \leq 1.75 \cdot 10^{-9}:\\
\;\;\;\;w0\\
\mathbf{else}:\\
\;\;\;\;w0 \cdot \left(M \cdot \left(\sqrt{\frac{h \cdot -0.25}{\ell}} \cdot \frac{D}{d}\right)\right)\\
\end{array}
\end{array}
if M < 1.75e-9Initial program 82.6%
Simplified82.6%
Taylor expanded in D around 0 73.6%
if 1.75e-9 < M Initial program 71.2%
Simplified72.8%
Taylor expanded in D around inf 26.9%
*-commutative26.9%
associate-*r*26.9%
times-frac25.3%
unpow225.3%
unpow225.3%
swap-sqr28.1%
unpow228.1%
Simplified28.1%
associate-*l*28.1%
sqrt-prod27.8%
sqrt-div29.7%
unpow229.7%
sqrt-prod17.4%
add-sqr-sqrt18.0%
unpow218.0%
sqrt-prod10.0%
add-sqr-sqrt21.6%
associate-/l*22.0%
Applied egg-rr22.0%
Taylor expanded in D around 0 21.6%
expm1-log1p-u21.1%
expm1-udef21.1%
*-commutative21.1%
associate-*r/24.2%
Applied egg-rr24.2%
expm1-def24.2%
expm1-log1p24.9%
associate-*l*25.0%
associate-*l/25.0%
Simplified25.0%
Final simplification63.4%
NOTE: M should be positive before calling this function NOTE: D should be positive before calling this function NOTE: d should be positive before calling this function NOTE: M and D should be sorted in increasing order before calling this function. (FPCore (w0 M D h l d) :precision binary64 w0)
M = abs(M);
D = abs(D);
d = abs(d);
assert(M < D);
double code(double w0, double M, double D, double h, double l, double d) {
return w0;
}
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: d should be positive before calling this function
NOTE: M 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
code = w0
end function
M = Math.abs(M);
D = Math.abs(D);
d = Math.abs(d);
assert M < D;
public static double code(double w0, double M, double D, double h, double l, double d) {
return w0;
}
M = abs(M) D = abs(D) d = abs(d) [M, D] = sort([M, D]) def code(w0, M, D, h, l, d): return w0
M = abs(M) D = abs(D) d = abs(d) M, D = sort([M, D]) function code(w0, M, D, h, l, d) return w0 end
M = abs(M)
D = abs(D)
d = abs(d)
M, D = num2cell(sort([M, D])){:}
function tmp = code(w0, M, D, h, l, d)
tmp = w0;
end
NOTE: M should be positive before calling this function NOTE: D should be positive before calling this function NOTE: d should be positive before calling this function NOTE: M and D should be sorted in increasing order before calling this function. code[w0_, M_, D_, h_, l_, d_] := w0
\begin{array}{l}
M = |M|\\
D = |D|\\
d = |d|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
w0
\end{array}
Initial program 80.2%
Simplified80.5%
Taylor expanded in D around 0 66.6%
Final simplification66.6%
herbie shell --seed 2024024
(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))))))