
(FPCore (d h l M D) :precision binary64 (* (* (pow (/ d h) (/ 1.0 2.0)) (pow (/ d l) (/ 1.0 2.0))) (- 1.0 (* (* (/ 1.0 2.0) (pow (/ (* M D) (* 2.0 d)) 2.0)) (/ h l)))))
double code(double d, double h, double l, double M, double D) {
return (pow((d / h), (1.0 / 2.0)) * pow((d / l), (1.0 / 2.0))) * (1.0 - (((1.0 / 2.0) * pow(((M * D) / (2.0 * d)), 2.0)) * (h / l)));
}
real(8) function code(d, h, l, m, d_1)
real(8), intent (in) :: d
real(8), intent (in) :: h
real(8), intent (in) :: l
real(8), intent (in) :: m
real(8), intent (in) :: d_1
code = (((d / h) ** (1.0d0 / 2.0d0)) * ((d / l) ** (1.0d0 / 2.0d0))) * (1.0d0 - (((1.0d0 / 2.0d0) * (((m * d_1) / (2.0d0 * d)) ** 2.0d0)) * (h / l)))
end function
public static double code(double d, double h, double l, double M, double D) {
return (Math.pow((d / h), (1.0 / 2.0)) * Math.pow((d / l), (1.0 / 2.0))) * (1.0 - (((1.0 / 2.0) * Math.pow(((M * D) / (2.0 * d)), 2.0)) * (h / l)));
}
def code(d, h, l, M, D): return (math.pow((d / h), (1.0 / 2.0)) * math.pow((d / l), (1.0 / 2.0))) * (1.0 - (((1.0 / 2.0) * math.pow(((M * D) / (2.0 * d)), 2.0)) * (h / l)))
function code(d, h, l, M, D) return Float64(Float64((Float64(d / h) ^ Float64(1.0 / 2.0)) * (Float64(d / l) ^ Float64(1.0 / 2.0))) * Float64(1.0 - Float64(Float64(Float64(1.0 / 2.0) * (Float64(Float64(M * D) / Float64(2.0 * d)) ^ 2.0)) * Float64(h / l)))) end
function tmp = code(d, h, l, M, D) tmp = (((d / h) ^ (1.0 / 2.0)) * ((d / l) ^ (1.0 / 2.0))) * (1.0 - (((1.0 / 2.0) * (((M * D) / (2.0 * d)) ^ 2.0)) * (h / l))); end
code[d_, h_, l_, M_, D_] := N[(N[(N[Power[N[(d / h), $MachinePrecision], N[(1.0 / 2.0), $MachinePrecision]], $MachinePrecision] * N[Power[N[(d / l), $MachinePrecision], N[(1.0 / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(1.0 - N[(N[(N[(1.0 / 2.0), $MachinePrecision] * N[Power[N[(N[(M * D), $MachinePrecision] / N[(2.0 * d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (d h l M D) :precision binary64 (* (* (pow (/ d h) (/ 1.0 2.0)) (pow (/ d l) (/ 1.0 2.0))) (- 1.0 (* (* (/ 1.0 2.0) (pow (/ (* M D) (* 2.0 d)) 2.0)) (/ h l)))))
double code(double d, double h, double l, double M, double D) {
return (pow((d / h), (1.0 / 2.0)) * pow((d / l), (1.0 / 2.0))) * (1.0 - (((1.0 / 2.0) * pow(((M * D) / (2.0 * d)), 2.0)) * (h / l)));
}
real(8) function code(d, h, l, m, d_1)
real(8), intent (in) :: d
real(8), intent (in) :: h
real(8), intent (in) :: l
real(8), intent (in) :: m
real(8), intent (in) :: d_1
code = (((d / h) ** (1.0d0 / 2.0d0)) * ((d / l) ** (1.0d0 / 2.0d0))) * (1.0d0 - (((1.0d0 / 2.0d0) * (((m * d_1) / (2.0d0 * d)) ** 2.0d0)) * (h / l)))
end function
public static double code(double d, double h, double l, double M, double D) {
return (Math.pow((d / h), (1.0 / 2.0)) * Math.pow((d / l), (1.0 / 2.0))) * (1.0 - (((1.0 / 2.0) * Math.pow(((M * D) / (2.0 * d)), 2.0)) * (h / l)));
}
def code(d, h, l, M, D): return (math.pow((d / h), (1.0 / 2.0)) * math.pow((d / l), (1.0 / 2.0))) * (1.0 - (((1.0 / 2.0) * math.pow(((M * D) / (2.0 * d)), 2.0)) * (h / l)))
function code(d, h, l, M, D) return Float64(Float64((Float64(d / h) ^ Float64(1.0 / 2.0)) * (Float64(d / l) ^ Float64(1.0 / 2.0))) * Float64(1.0 - Float64(Float64(Float64(1.0 / 2.0) * (Float64(Float64(M * D) / Float64(2.0 * d)) ^ 2.0)) * Float64(h / l)))) end
function tmp = code(d, h, l, M, D) tmp = (((d / h) ^ (1.0 / 2.0)) * ((d / l) ^ (1.0 / 2.0))) * (1.0 - (((1.0 / 2.0) * (((M * D) / (2.0 * d)) ^ 2.0)) * (h / l))); end
code[d_, h_, l_, M_, D_] := N[(N[(N[Power[N[(d / h), $MachinePrecision], N[(1.0 / 2.0), $MachinePrecision]], $MachinePrecision] * N[Power[N[(d / l), $MachinePrecision], N[(1.0 / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(1.0 - N[(N[(N[(1.0 / 2.0), $MachinePrecision] * N[Power[N[(N[(M * D), $MachinePrecision] / N[(2.0 * d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right)
\end{array}
NOTE: d, h, l, M, and D should be sorted in increasing order before calling this function.
(FPCore (d h l M D)
:precision binary64
(let* ((t_0 (sqrt (/ d l))))
(if (<= l -5e-310)
(*
(/ (sqrt (- d)) (sqrt (- h)))
(* t_0 (+ 1.0 (* h (/ (pow (* M (/ (/ D 2.0) d)) 2.0) (/ l -0.5))))))
(*
(/ (sqrt d) (sqrt h))
(* t_0 (+ 1.0 (* (/ h l) (* -0.5 (pow (* (/ M 2.0) (/ D d)) 2.0)))))))))assert(d < h && h < l && l < M && M < D);
double code(double d, double h, double l, double M, double D) {
double t_0 = sqrt((d / l));
double tmp;
if (l <= -5e-310) {
tmp = (sqrt(-d) / sqrt(-h)) * (t_0 * (1.0 + (h * (pow((M * ((D / 2.0) / d)), 2.0) / (l / -0.5)))));
} else {
tmp = (sqrt(d) / sqrt(h)) * (t_0 * (1.0 + ((h / l) * (-0.5 * pow(((M / 2.0) * (D / d)), 2.0)))));
}
return tmp;
}
NOTE: d, h, l, M, and D should be sorted in increasing order before calling this function.
real(8) function code(d, h, l, m, d_1)
real(8), intent (in) :: d
real(8), intent (in) :: h
real(8), intent (in) :: l
real(8), intent (in) :: m
real(8), intent (in) :: d_1
real(8) :: t_0
real(8) :: tmp
t_0 = sqrt((d / l))
if (l <= (-5d-310)) then
tmp = (sqrt(-d) / sqrt(-h)) * (t_0 * (1.0d0 + (h * (((m * ((d_1 / 2.0d0) / d)) ** 2.0d0) / (l / (-0.5d0))))))
else
tmp = (sqrt(d) / sqrt(h)) * (t_0 * (1.0d0 + ((h / l) * ((-0.5d0) * (((m / 2.0d0) * (d_1 / d)) ** 2.0d0)))))
end if
code = tmp
end function
assert d < h && h < l && l < M && M < D;
public static double code(double d, double h, double l, double M, double D) {
double t_0 = Math.sqrt((d / l));
double tmp;
if (l <= -5e-310) {
tmp = (Math.sqrt(-d) / Math.sqrt(-h)) * (t_0 * (1.0 + (h * (Math.pow((M * ((D / 2.0) / d)), 2.0) / (l / -0.5)))));
} else {
tmp = (Math.sqrt(d) / Math.sqrt(h)) * (t_0 * (1.0 + ((h / l) * (-0.5 * Math.pow(((M / 2.0) * (D / d)), 2.0)))));
}
return tmp;
}
[d, h, l, M, D] = sort([d, h, l, M, D]) def code(d, h, l, M, D): t_0 = math.sqrt((d / l)) tmp = 0 if l <= -5e-310: tmp = (math.sqrt(-d) / math.sqrt(-h)) * (t_0 * (1.0 + (h * (math.pow((M * ((D / 2.0) / d)), 2.0) / (l / -0.5))))) else: tmp = (math.sqrt(d) / math.sqrt(h)) * (t_0 * (1.0 + ((h / l) * (-0.5 * math.pow(((M / 2.0) * (D / d)), 2.0))))) return tmp
d, h, l, M, D = sort([d, h, l, M, D]) function code(d, h, l, M, D) t_0 = sqrt(Float64(d / l)) tmp = 0.0 if (l <= -5e-310) tmp = Float64(Float64(sqrt(Float64(-d)) / sqrt(Float64(-h))) * Float64(t_0 * Float64(1.0 + Float64(h * Float64((Float64(M * Float64(Float64(D / 2.0) / d)) ^ 2.0) / Float64(l / -0.5)))))); else tmp = Float64(Float64(sqrt(d) / sqrt(h)) * Float64(t_0 * Float64(1.0 + Float64(Float64(h / l) * Float64(-0.5 * (Float64(Float64(M / 2.0) * Float64(D / d)) ^ 2.0)))))); end return tmp end
d, h, l, M, D = num2cell(sort([d, h, l, M, D])){:}
function tmp_2 = code(d, h, l, M, D)
t_0 = sqrt((d / l));
tmp = 0.0;
if (l <= -5e-310)
tmp = (sqrt(-d) / sqrt(-h)) * (t_0 * (1.0 + (h * (((M * ((D / 2.0) / d)) ^ 2.0) / (l / -0.5)))));
else
tmp = (sqrt(d) / sqrt(h)) * (t_0 * (1.0 + ((h / l) * (-0.5 * (((M / 2.0) * (D / d)) ^ 2.0)))));
end
tmp_2 = tmp;
end
NOTE: d, h, l, M, and D should be sorted in increasing order before calling this function.
code[d_, h_, l_, M_, D_] := Block[{t$95$0 = N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[l, -5e-310], N[(N[(N[Sqrt[(-d)], $MachinePrecision] / N[Sqrt[(-h)], $MachinePrecision]), $MachinePrecision] * N[(t$95$0 * N[(1.0 + N[(h * N[(N[Power[N[(M * N[(N[(D / 2.0), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] / N[(l / -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Sqrt[d], $MachinePrecision] / N[Sqrt[h], $MachinePrecision]), $MachinePrecision] * N[(t$95$0 * N[(1.0 + N[(N[(h / l), $MachinePrecision] * N[(-0.5 * N[Power[N[(N[(M / 2.0), $MachinePrecision] * N[(D / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[d, h, l, M, D] = \mathsf{sort}([d, h, l, M, D])\\
\\
\begin{array}{l}
t_0 := \sqrt{\frac{d}{\ell}}\\
\mathbf{if}\;\ell \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{\sqrt{-d}}{\sqrt{-h}} \cdot \left(t_0 \cdot \left(1 + h \cdot \frac{{\left(M \cdot \frac{\frac{D}{2}}{d}\right)}^{2}}{\frac{\ell}{-0.5}}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{d}}{\sqrt{h}} \cdot \left(t_0 \cdot \left(1 + \frac{h}{\ell} \cdot \left(-0.5 \cdot {\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2}\right)\right)\right)\\
\end{array}
\end{array}
if l < -4.999999999999985e-310Initial program 60.5%
Simplified59.8%
expm1-log1p-u34.9%
expm1-udef34.9%
*-commutative34.9%
associate-*l*34.9%
div-inv34.9%
metadata-eval34.9%
Applied egg-rr34.9%
expm1-def34.9%
expm1-log1p59.8%
associate-*r*59.8%
*-commutative59.8%
associate-*r/61.5%
associate-*l/62.8%
*-commutative62.8%
*-commutative62.8%
associate-/l*62.8%
Simplified62.8%
frac-2neg62.8%
sqrt-div80.9%
Applied egg-rr80.9%
if -4.999999999999985e-310 < l Initial program 71.1%
Simplified71.0%
sqrt-div81.0%
div-inv81.0%
Applied egg-rr81.0%
associate-*r/81.0%
*-rgt-identity81.0%
Simplified81.0%
Final simplification81.0%
NOTE: d, h, l, M, and D should be sorted in increasing order before calling this function.
(FPCore (d h l M D)
:precision binary64
(if (<= l -5e-310)
(*
(sqrt (/ d h))
(*
(+ 1.0 (* h (/ (pow (* M (/ (/ D 2.0) d)) 2.0) (/ l -0.5))))
(/ (sqrt (- d)) (sqrt (- l)))))
(*
(/ (sqrt d) (sqrt h))
(*
(sqrt (/ d l))
(+ 1.0 (* (/ h l) (* -0.5 (pow (* (/ M 2.0) (/ D d)) 2.0))))))))assert(d < h && h < l && l < M && M < D);
double code(double d, double h, double l, double M, double D) {
double tmp;
if (l <= -5e-310) {
tmp = sqrt((d / h)) * ((1.0 + (h * (pow((M * ((D / 2.0) / d)), 2.0) / (l / -0.5)))) * (sqrt(-d) / sqrt(-l)));
} else {
tmp = (sqrt(d) / sqrt(h)) * (sqrt((d / l)) * (1.0 + ((h / l) * (-0.5 * pow(((M / 2.0) * (D / d)), 2.0)))));
}
return tmp;
}
NOTE: d, h, l, M, and D should be sorted in increasing order before calling this function.
real(8) function code(d, h, l, m, d_1)
real(8), intent (in) :: d
real(8), intent (in) :: h
real(8), intent (in) :: l
real(8), intent (in) :: m
real(8), intent (in) :: d_1
real(8) :: tmp
if (l <= (-5d-310)) then
tmp = sqrt((d / h)) * ((1.0d0 + (h * (((m * ((d_1 / 2.0d0) / d)) ** 2.0d0) / (l / (-0.5d0))))) * (sqrt(-d) / sqrt(-l)))
else
tmp = (sqrt(d) / sqrt(h)) * (sqrt((d / l)) * (1.0d0 + ((h / l) * ((-0.5d0) * (((m / 2.0d0) * (d_1 / d)) ** 2.0d0)))))
end if
code = tmp
end function
assert d < h && h < l && l < M && M < D;
public static double code(double d, double h, double l, double M, double D) {
double tmp;
if (l <= -5e-310) {
tmp = Math.sqrt((d / h)) * ((1.0 + (h * (Math.pow((M * ((D / 2.0) / d)), 2.0) / (l / -0.5)))) * (Math.sqrt(-d) / Math.sqrt(-l)));
} else {
tmp = (Math.sqrt(d) / Math.sqrt(h)) * (Math.sqrt((d / l)) * (1.0 + ((h / l) * (-0.5 * Math.pow(((M / 2.0) * (D / d)), 2.0)))));
}
return tmp;
}
[d, h, l, M, D] = sort([d, h, l, M, D]) def code(d, h, l, M, D): tmp = 0 if l <= -5e-310: tmp = math.sqrt((d / h)) * ((1.0 + (h * (math.pow((M * ((D / 2.0) / d)), 2.0) / (l / -0.5)))) * (math.sqrt(-d) / math.sqrt(-l))) else: tmp = (math.sqrt(d) / math.sqrt(h)) * (math.sqrt((d / l)) * (1.0 + ((h / l) * (-0.5 * math.pow(((M / 2.0) * (D / d)), 2.0))))) return tmp
d, h, l, M, D = sort([d, h, l, M, D]) function code(d, h, l, M, D) tmp = 0.0 if (l <= -5e-310) tmp = Float64(sqrt(Float64(d / h)) * Float64(Float64(1.0 + Float64(h * Float64((Float64(M * Float64(Float64(D / 2.0) / d)) ^ 2.0) / Float64(l / -0.5)))) * Float64(sqrt(Float64(-d)) / sqrt(Float64(-l))))); else tmp = Float64(Float64(sqrt(d) / sqrt(h)) * Float64(sqrt(Float64(d / l)) * Float64(1.0 + Float64(Float64(h / l) * Float64(-0.5 * (Float64(Float64(M / 2.0) * Float64(D / d)) ^ 2.0)))))); end return tmp end
d, h, l, M, D = num2cell(sort([d, h, l, M, D])){:}
function tmp_2 = code(d, h, l, M, D)
tmp = 0.0;
if (l <= -5e-310)
tmp = sqrt((d / h)) * ((1.0 + (h * (((M * ((D / 2.0) / d)) ^ 2.0) / (l / -0.5)))) * (sqrt(-d) / sqrt(-l)));
else
tmp = (sqrt(d) / sqrt(h)) * (sqrt((d / l)) * (1.0 + ((h / l) * (-0.5 * (((M / 2.0) * (D / d)) ^ 2.0)))));
end
tmp_2 = tmp;
end
NOTE: d, h, l, M, and D should be sorted in increasing order before calling this function. code[d_, h_, l_, M_, D_] := If[LessEqual[l, -5e-310], N[(N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision] * N[(N[(1.0 + N[(h * N[(N[Power[N[(M * N[(N[(D / 2.0), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] / N[(l / -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[Sqrt[(-d)], $MachinePrecision] / N[Sqrt[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Sqrt[d], $MachinePrecision] / N[Sqrt[h], $MachinePrecision]), $MachinePrecision] * N[(N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision] * N[(1.0 + N[(N[(h / l), $MachinePrecision] * N[(-0.5 * N[Power[N[(N[(M / 2.0), $MachinePrecision] * N[(D / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[d, h, l, M, D] = \mathsf{sort}([d, h, l, M, D])\\
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\sqrt{\frac{d}{h}} \cdot \left(\left(1 + h \cdot \frac{{\left(M \cdot \frac{\frac{D}{2}}{d}\right)}^{2}}{\frac{\ell}{-0.5}}\right) \cdot \frac{\sqrt{-d}}{\sqrt{-\ell}}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{d}}{\sqrt{h}} \cdot \left(\sqrt{\frac{d}{\ell}} \cdot \left(1 + \frac{h}{\ell} \cdot \left(-0.5 \cdot {\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2}\right)\right)\right)\\
\end{array}
\end{array}
if l < -4.999999999999985e-310Initial program 60.5%
Simplified59.8%
expm1-log1p-u34.9%
expm1-udef34.9%
*-commutative34.9%
associate-*l*34.9%
div-inv34.9%
metadata-eval34.9%
Applied egg-rr34.9%
expm1-def34.9%
expm1-log1p59.8%
associate-*r*59.8%
*-commutative59.8%
associate-*r/61.5%
associate-*l/62.8%
*-commutative62.8%
*-commutative62.8%
associate-/l*62.8%
Simplified62.8%
frac-2neg62.8%
sqrt-div68.2%
Applied egg-rr68.2%
if -4.999999999999985e-310 < l Initial program 71.1%
Simplified71.0%
sqrt-div81.0%
div-inv81.0%
Applied egg-rr81.0%
associate-*r/81.0%
*-rgt-identity81.0%
Simplified81.0%
Final simplification74.0%
NOTE: d, h, l, M, and D should be sorted in increasing order before calling this function.
(FPCore (d h l M D)
:precision binary64
(let* ((t_0 (* (* D (/ M d)) 0.5)) (t_1 (sqrt (/ d h))))
(if (<= h 7.2e-182)
(* t_1 (* (sqrt (/ d l)) (+ 1.0 (* h (* (/ t_0 l) (/ t_0 -2.0))))))
(*
t_1
(*
(+ 1.0 (* h (/ (pow (* M (/ (/ D 2.0) d)) 2.0) (/ l -0.5))))
(/ (sqrt d) (sqrt l)))))))assert(d < h && h < l && l < M && M < D);
double code(double d, double h, double l, double M, double D) {
double t_0 = (D * (M / d)) * 0.5;
double t_1 = sqrt((d / h));
double tmp;
if (h <= 7.2e-182) {
tmp = t_1 * (sqrt((d / l)) * (1.0 + (h * ((t_0 / l) * (t_0 / -2.0)))));
} else {
tmp = t_1 * ((1.0 + (h * (pow((M * ((D / 2.0) / d)), 2.0) / (l / -0.5)))) * (sqrt(d) / sqrt(l)));
}
return tmp;
}
NOTE: d, h, l, M, and D should be sorted in increasing order before calling this function.
real(8) function code(d, h, l, m, d_1)
real(8), intent (in) :: d
real(8), intent (in) :: h
real(8), intent (in) :: l
real(8), intent (in) :: m
real(8), intent (in) :: d_1
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = (d_1 * (m / d)) * 0.5d0
t_1 = sqrt((d / h))
if (h <= 7.2d-182) then
tmp = t_1 * (sqrt((d / l)) * (1.0d0 + (h * ((t_0 / l) * (t_0 / (-2.0d0))))))
else
tmp = t_1 * ((1.0d0 + (h * (((m * ((d_1 / 2.0d0) / d)) ** 2.0d0) / (l / (-0.5d0))))) * (sqrt(d) / sqrt(l)))
end if
code = tmp
end function
assert d < h && h < l && l < M && M < D;
public static double code(double d, double h, double l, double M, double D) {
double t_0 = (D * (M / d)) * 0.5;
double t_1 = Math.sqrt((d / h));
double tmp;
if (h <= 7.2e-182) {
tmp = t_1 * (Math.sqrt((d / l)) * (1.0 + (h * ((t_0 / l) * (t_0 / -2.0)))));
} else {
tmp = t_1 * ((1.0 + (h * (Math.pow((M * ((D / 2.0) / d)), 2.0) / (l / -0.5)))) * (Math.sqrt(d) / Math.sqrt(l)));
}
return tmp;
}
[d, h, l, M, D] = sort([d, h, l, M, D]) def code(d, h, l, M, D): t_0 = (D * (M / d)) * 0.5 t_1 = math.sqrt((d / h)) tmp = 0 if h <= 7.2e-182: tmp = t_1 * (math.sqrt((d / l)) * (1.0 + (h * ((t_0 / l) * (t_0 / -2.0))))) else: tmp = t_1 * ((1.0 + (h * (math.pow((M * ((D / 2.0) / d)), 2.0) / (l / -0.5)))) * (math.sqrt(d) / math.sqrt(l))) return tmp
d, h, l, M, D = sort([d, h, l, M, D]) function code(d, h, l, M, D) t_0 = Float64(Float64(D * Float64(M / d)) * 0.5) t_1 = sqrt(Float64(d / h)) tmp = 0.0 if (h <= 7.2e-182) tmp = Float64(t_1 * Float64(sqrt(Float64(d / l)) * Float64(1.0 + Float64(h * Float64(Float64(t_0 / l) * Float64(t_0 / -2.0)))))); else tmp = Float64(t_1 * Float64(Float64(1.0 + Float64(h * Float64((Float64(M * Float64(Float64(D / 2.0) / d)) ^ 2.0) / Float64(l / -0.5)))) * Float64(sqrt(d) / sqrt(l)))); end return tmp end
d, h, l, M, D = num2cell(sort([d, h, l, M, D])){:}
function tmp_2 = code(d, h, l, M, D)
t_0 = (D * (M / d)) * 0.5;
t_1 = sqrt((d / h));
tmp = 0.0;
if (h <= 7.2e-182)
tmp = t_1 * (sqrt((d / l)) * (1.0 + (h * ((t_0 / l) * (t_0 / -2.0)))));
else
tmp = t_1 * ((1.0 + (h * (((M * ((D / 2.0) / d)) ^ 2.0) / (l / -0.5)))) * (sqrt(d) / sqrt(l)));
end
tmp_2 = tmp;
end
NOTE: d, h, l, M, and D should be sorted in increasing order before calling this function.
code[d_, h_, l_, M_, D_] := Block[{t$95$0 = N[(N[(D * N[(M / d), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[h, 7.2e-182], N[(t$95$1 * N[(N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision] * N[(1.0 + N[(h * N[(N[(t$95$0 / l), $MachinePrecision] * N[(t$95$0 / -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$1 * N[(N[(1.0 + N[(h * N[(N[Power[N[(M * N[(N[(D / 2.0), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] / N[(l / -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[Sqrt[d], $MachinePrecision] / N[Sqrt[l], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
[d, h, l, M, D] = \mathsf{sort}([d, h, l, M, D])\\
\\
\begin{array}{l}
t_0 := \left(D \cdot \frac{M}{d}\right) \cdot 0.5\\
t_1 := \sqrt{\frac{d}{h}}\\
\mathbf{if}\;h \leq 7.2 \cdot 10^{-182}:\\
\;\;\;\;t_1 \cdot \left(\sqrt{\frac{d}{\ell}} \cdot \left(1 + h \cdot \left(\frac{t_0}{\ell} \cdot \frac{t_0}{-2}\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t_1 \cdot \left(\left(1 + h \cdot \frac{{\left(M \cdot \frac{\frac{D}{2}}{d}\right)}^{2}}{\frac{\ell}{-0.5}}\right) \cdot \frac{\sqrt{d}}{\sqrt{\ell}}\right)\\
\end{array}
\end{array}
if h < 7.19999999999999954e-182Initial program 60.2%
Simplified59.6%
expm1-log1p-u34.5%
expm1-udef34.5%
*-commutative34.5%
associate-*l*34.5%
div-inv34.5%
metadata-eval34.5%
Applied egg-rr34.5%
expm1-def34.5%
expm1-log1p59.6%
associate-*r*59.6%
*-commutative59.6%
associate-*r/61.1%
associate-*l/62.2%
*-commutative62.2%
*-commutative62.2%
associate-/l*62.2%
Simplified62.2%
unpow262.2%
div-inv62.2%
metadata-eval62.2%
metadata-eval62.2%
times-frac65.3%
associate-*r/65.2%
associate-*l/64.1%
div-inv64.1%
metadata-eval64.1%
associate-*r*64.1%
*-commutative64.1%
associate-*r/65.3%
associate-*l/65.4%
div-inv65.4%
metadata-eval65.4%
associate-*r*65.4%
*-commutative65.4%
metadata-eval65.4%
Applied egg-rr65.4%
if 7.19999999999999954e-182 < h Initial program 74.2%
Simplified74.2%
expm1-log1p-u24.9%
expm1-udef24.9%
*-commutative24.9%
associate-*l*24.9%
div-inv24.9%
metadata-eval24.9%
Applied egg-rr24.9%
expm1-def24.9%
expm1-log1p74.2%
associate-*r*74.2%
*-commutative74.2%
associate-*r/72.2%
associate-*l/75.3%
*-commutative75.3%
*-commutative75.3%
associate-/l*75.3%
Simplified75.3%
sqrt-div81.7%
div-inv81.7%
Applied egg-rr81.7%
associate-*r/81.7%
*-rgt-identity81.7%
Simplified81.7%
Final simplification71.2%
NOTE: d, h, l, M, and D should be sorted in increasing order before calling this function.
(FPCore (d h l M D)
:precision binary64
(let* ((t_0 (* (* D (/ M d)) 0.5)) (t_1 (sqrt (/ d l))))
(if (<= l 3.1e-305)
(* (sqrt (/ d h)) (* t_1 (+ 1.0 (* h (* (/ t_0 l) (/ t_0 -2.0))))))
(*
(/ (sqrt d) (sqrt h))
(* t_1 (+ 1.0 (* (/ h l) (* -0.5 (pow (* (/ M 2.0) (/ D d)) 2.0)))))))))assert(d < h && h < l && l < M && M < D);
double code(double d, double h, double l, double M, double D) {
double t_0 = (D * (M / d)) * 0.5;
double t_1 = sqrt((d / l));
double tmp;
if (l <= 3.1e-305) {
tmp = sqrt((d / h)) * (t_1 * (1.0 + (h * ((t_0 / l) * (t_0 / -2.0)))));
} else {
tmp = (sqrt(d) / sqrt(h)) * (t_1 * (1.0 + ((h / l) * (-0.5 * pow(((M / 2.0) * (D / d)), 2.0)))));
}
return tmp;
}
NOTE: d, h, l, M, and D should be sorted in increasing order before calling this function.
real(8) function code(d, h, l, m, d_1)
real(8), intent (in) :: d
real(8), intent (in) :: h
real(8), intent (in) :: l
real(8), intent (in) :: m
real(8), intent (in) :: d_1
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = (d_1 * (m / d)) * 0.5d0
t_1 = sqrt((d / l))
if (l <= 3.1d-305) then
tmp = sqrt((d / h)) * (t_1 * (1.0d0 + (h * ((t_0 / l) * (t_0 / (-2.0d0))))))
else
tmp = (sqrt(d) / sqrt(h)) * (t_1 * (1.0d0 + ((h / l) * ((-0.5d0) * (((m / 2.0d0) * (d_1 / d)) ** 2.0d0)))))
end if
code = tmp
end function
assert d < h && h < l && l < M && M < D;
public static double code(double d, double h, double l, double M, double D) {
double t_0 = (D * (M / d)) * 0.5;
double t_1 = Math.sqrt((d / l));
double tmp;
if (l <= 3.1e-305) {
tmp = Math.sqrt((d / h)) * (t_1 * (1.0 + (h * ((t_0 / l) * (t_0 / -2.0)))));
} else {
tmp = (Math.sqrt(d) / Math.sqrt(h)) * (t_1 * (1.0 + ((h / l) * (-0.5 * Math.pow(((M / 2.0) * (D / d)), 2.0)))));
}
return tmp;
}
[d, h, l, M, D] = sort([d, h, l, M, D]) def code(d, h, l, M, D): t_0 = (D * (M / d)) * 0.5 t_1 = math.sqrt((d / l)) tmp = 0 if l <= 3.1e-305: tmp = math.sqrt((d / h)) * (t_1 * (1.0 + (h * ((t_0 / l) * (t_0 / -2.0))))) else: tmp = (math.sqrt(d) / math.sqrt(h)) * (t_1 * (1.0 + ((h / l) * (-0.5 * math.pow(((M / 2.0) * (D / d)), 2.0))))) return tmp
d, h, l, M, D = sort([d, h, l, M, D]) function code(d, h, l, M, D) t_0 = Float64(Float64(D * Float64(M / d)) * 0.5) t_1 = sqrt(Float64(d / l)) tmp = 0.0 if (l <= 3.1e-305) tmp = Float64(sqrt(Float64(d / h)) * Float64(t_1 * Float64(1.0 + Float64(h * Float64(Float64(t_0 / l) * Float64(t_0 / -2.0)))))); else tmp = Float64(Float64(sqrt(d) / sqrt(h)) * Float64(t_1 * Float64(1.0 + Float64(Float64(h / l) * Float64(-0.5 * (Float64(Float64(M / 2.0) * Float64(D / d)) ^ 2.0)))))); end return tmp end
d, h, l, M, D = num2cell(sort([d, h, l, M, D])){:}
function tmp_2 = code(d, h, l, M, D)
t_0 = (D * (M / d)) * 0.5;
t_1 = sqrt((d / l));
tmp = 0.0;
if (l <= 3.1e-305)
tmp = sqrt((d / h)) * (t_1 * (1.0 + (h * ((t_0 / l) * (t_0 / -2.0)))));
else
tmp = (sqrt(d) / sqrt(h)) * (t_1 * (1.0 + ((h / l) * (-0.5 * (((M / 2.0) * (D / d)) ^ 2.0)))));
end
tmp_2 = tmp;
end
NOTE: d, h, l, M, and D should be sorted in increasing order before calling this function.
code[d_, h_, l_, M_, D_] := Block[{t$95$0 = N[(N[(D * N[(M / d), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[l, 3.1e-305], N[(N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision] * N[(t$95$1 * N[(1.0 + N[(h * N[(N[(t$95$0 / l), $MachinePrecision] * N[(t$95$0 / -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Sqrt[d], $MachinePrecision] / N[Sqrt[h], $MachinePrecision]), $MachinePrecision] * N[(t$95$1 * N[(1.0 + N[(N[(h / l), $MachinePrecision] * N[(-0.5 * N[Power[N[(N[(M / 2.0), $MachinePrecision] * N[(D / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
[d, h, l, M, D] = \mathsf{sort}([d, h, l, M, D])\\
\\
\begin{array}{l}
t_0 := \left(D \cdot \frac{M}{d}\right) \cdot 0.5\\
t_1 := \sqrt{\frac{d}{\ell}}\\
\mathbf{if}\;\ell \leq 3.1 \cdot 10^{-305}:\\
\;\;\;\;\sqrt{\frac{d}{h}} \cdot \left(t_1 \cdot \left(1 + h \cdot \left(\frac{t_0}{\ell} \cdot \frac{t_0}{-2}\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{d}}{\sqrt{h}} \cdot \left(t_1 \cdot \left(1 + \frac{h}{\ell} \cdot \left(-0.5 \cdot {\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2}\right)\right)\right)\\
\end{array}
\end{array}
if l < 3.0999999999999998e-305Initial program 60.0%
Simplified59.3%
expm1-log1p-u34.6%
expm1-udef34.6%
*-commutative34.6%
associate-*l*34.6%
div-inv34.6%
metadata-eval34.6%
Applied egg-rr34.6%
expm1-def34.6%
expm1-log1p59.3%
associate-*r*59.3%
*-commutative59.3%
associate-*r/61.8%
associate-*l/63.1%
*-commutative63.1%
*-commutative63.1%
associate-/l*63.1%
Simplified63.1%
unpow263.1%
div-inv63.1%
metadata-eval63.1%
metadata-eval63.1%
times-frac65.2%
associate-*r/65.2%
associate-*l/63.9%
div-inv63.9%
metadata-eval63.9%
associate-*r*63.9%
*-commutative63.9%
associate-*r/65.3%
associate-*l/65.3%
div-inv65.3%
metadata-eval65.3%
associate-*r*65.3%
*-commutative65.3%
metadata-eval65.3%
Applied egg-rr65.3%
if 3.0999999999999998e-305 < l Initial program 71.7%
Simplified71.7%
sqrt-div81.8%
div-inv81.7%
Applied egg-rr81.7%
associate-*r/81.8%
*-rgt-identity81.8%
Simplified81.8%
Final simplification72.6%
NOTE: d, h, l, M, and D should be sorted in increasing order before calling this function.
(FPCore (d h l M D)
:precision binary64
(let* ((t_0 (* (* D (/ M d)) 0.5)))
(*
(sqrt (/ d h))
(* (sqrt (/ d l)) (+ 1.0 (* h (* (/ t_0 l) (/ t_0 -2.0))))))))assert(d < h && h < l && l < M && M < D);
double code(double d, double h, double l, double M, double D) {
double t_0 = (D * (M / d)) * 0.5;
return sqrt((d / h)) * (sqrt((d / l)) * (1.0 + (h * ((t_0 / l) * (t_0 / -2.0)))));
}
NOTE: d, h, l, M, and D should be sorted in increasing order before calling this function.
real(8) function code(d, h, l, m, d_1)
real(8), intent (in) :: d
real(8), intent (in) :: h
real(8), intent (in) :: l
real(8), intent (in) :: m
real(8), intent (in) :: d_1
real(8) :: t_0
t_0 = (d_1 * (m / d)) * 0.5d0
code = sqrt((d / h)) * (sqrt((d / l)) * (1.0d0 + (h * ((t_0 / l) * (t_0 / (-2.0d0))))))
end function
assert d < h && h < l && l < M && M < D;
public static double code(double d, double h, double l, double M, double D) {
double t_0 = (D * (M / d)) * 0.5;
return Math.sqrt((d / h)) * (Math.sqrt((d / l)) * (1.0 + (h * ((t_0 / l) * (t_0 / -2.0)))));
}
[d, h, l, M, D] = sort([d, h, l, M, D]) def code(d, h, l, M, D): t_0 = (D * (M / d)) * 0.5 return math.sqrt((d / h)) * (math.sqrt((d / l)) * (1.0 + (h * ((t_0 / l) * (t_0 / -2.0)))))
d, h, l, M, D = sort([d, h, l, M, D]) function code(d, h, l, M, D) t_0 = Float64(Float64(D * Float64(M / d)) * 0.5) return Float64(sqrt(Float64(d / h)) * Float64(sqrt(Float64(d / l)) * Float64(1.0 + Float64(h * Float64(Float64(t_0 / l) * Float64(t_0 / -2.0)))))) end
d, h, l, M, D = num2cell(sort([d, h, l, M, D])){:}
function tmp = code(d, h, l, M, D)
t_0 = (D * (M / d)) * 0.5;
tmp = sqrt((d / h)) * (sqrt((d / l)) * (1.0 + (h * ((t_0 / l) * (t_0 / -2.0)))));
end
NOTE: d, h, l, M, and D should be sorted in increasing order before calling this function.
code[d_, h_, l_, M_, D_] := Block[{t$95$0 = N[(N[(D * N[(M / d), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]}, N[(N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision] * N[(N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision] * N[(1.0 + N[(h * N[(N[(t$95$0 / l), $MachinePrecision] * N[(t$95$0 / -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[d, h, l, M, D] = \mathsf{sort}([d, h, l, M, D])\\
\\
\begin{array}{l}
t_0 := \left(D \cdot \frac{M}{d}\right) \cdot 0.5\\
\sqrt{\frac{d}{h}} \cdot \left(\sqrt{\frac{d}{\ell}} \cdot \left(1 + h \cdot \left(\frac{t_0}{\ell} \cdot \frac{t_0}{-2}\right)\right)\right)
\end{array}
\end{array}
Initial program 65.2%
Simplified64.8%
expm1-log1p-u31.0%
expm1-udef31.0%
*-commutative31.0%
associate-*l*31.0%
div-inv31.0%
metadata-eval31.0%
Applied egg-rr31.0%
expm1-def31.0%
expm1-log1p64.8%
associate-*r*64.8%
*-commutative64.8%
associate-*r/65.1%
associate-*l/66.9%
*-commutative66.9%
*-commutative66.9%
associate-/l*66.9%
Simplified66.9%
unpow266.9%
div-inv66.9%
metadata-eval66.9%
metadata-eval66.9%
times-frac69.3%
associate-*r/69.2%
associate-*l/68.5%
div-inv68.5%
metadata-eval68.5%
associate-*r*68.5%
*-commutative68.5%
associate-*r/69.3%
associate-*l/69.3%
div-inv69.3%
metadata-eval69.3%
associate-*r*69.3%
*-commutative69.3%
metadata-eval69.3%
Applied egg-rr69.3%
Final simplification69.3%
herbie shell --seed 2023321
(FPCore (d h l M D)
:name "Henrywood and Agarwal, Equation (12)"
:precision binary64
(* (* (pow (/ d h) (/ 1.0 2.0)) (pow (/ d l) (/ 1.0 2.0))) (- 1.0 (* (* (/ 1.0 2.0) (pow (/ (* M D) (* 2.0 d)) 2.0)) (/ h l)))))