
(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 10 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}
M_m = (fabs.f64 M)
NOTE: d, h, l, M_m, and D should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D)
:precision binary64
(let* ((t_0 (+ 1.0 (* (/ h l) (* (pow (* D (/ (/ M_m 2.0) d)) 2.0) -0.5)))))
(if (<= d -5e-310)
(* (/ 1.0 (sqrt (/ l d))) (* (/ (sqrt (- d)) (sqrt (- h))) t_0))
(if (<= d 1.4e-207)
(* (sqrt (/ d l)) (* t_0 (/ (sqrt d) (sqrt h))))
(*
(fma h (* -0.5 (/ (pow (* 0.5 (* D (/ M_m d))) 2.0) l)) 1.0)
(/ (/ d (sqrt h)) (sqrt l)))))))M_m = fabs(M);
assert(d < h && h < l && l < M_m && M_m < D);
double code(double d, double h, double l, double M_m, double D) {
double t_0 = 1.0 + ((h / l) * (pow((D * ((M_m / 2.0) / d)), 2.0) * -0.5));
double tmp;
if (d <= -5e-310) {
tmp = (1.0 / sqrt((l / d))) * ((sqrt(-d) / sqrt(-h)) * t_0);
} else if (d <= 1.4e-207) {
tmp = sqrt((d / l)) * (t_0 * (sqrt(d) / sqrt(h)));
} else {
tmp = fma(h, (-0.5 * (pow((0.5 * (D * (M_m / d))), 2.0) / l)), 1.0) * ((d / sqrt(h)) / sqrt(l));
}
return tmp;
}
M_m = abs(M) d, h, l, M_m, D = sort([d, h, l, M_m, D]) function code(d, h, l, M_m, D) t_0 = Float64(1.0 + Float64(Float64(h / l) * Float64((Float64(D * Float64(Float64(M_m / 2.0) / d)) ^ 2.0) * -0.5))) tmp = 0.0 if (d <= -5e-310) tmp = Float64(Float64(1.0 / sqrt(Float64(l / d))) * Float64(Float64(sqrt(Float64(-d)) / sqrt(Float64(-h))) * t_0)); elseif (d <= 1.4e-207) tmp = Float64(sqrt(Float64(d / l)) * Float64(t_0 * Float64(sqrt(d) / sqrt(h)))); else tmp = Float64(fma(h, Float64(-0.5 * Float64((Float64(0.5 * Float64(D * Float64(M_m / d))) ^ 2.0) / l)), 1.0) * Float64(Float64(d / sqrt(h)) / sqrt(l))); end return tmp end
M_m = N[Abs[M], $MachinePrecision]
NOTE: d, h, l, M_m, and D should be sorted in increasing order before calling this function.
code[d_, h_, l_, M$95$m_, D_] := Block[{t$95$0 = N[(1.0 + N[(N[(h / l), $MachinePrecision] * N[(N[Power[N[(D * N[(N[(M$95$m / 2.0), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -5e-310], N[(N[(1.0 / N[Sqrt[N[(l / d), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(N[(N[Sqrt[(-d)], $MachinePrecision] / N[Sqrt[(-h)], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.4e-207], N[(N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision] * N[(t$95$0 * N[(N[Sqrt[d], $MachinePrecision] / N[Sqrt[h], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(h * N[(-0.5 * N[(N[Power[N[(0.5 * N[(D * N[(M$95$m / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision] * N[(N[(d / N[Sqrt[h], $MachinePrecision]), $MachinePrecision] / N[Sqrt[l], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
M_m = \left|M\right|
\\
[d, h, l, M_m, D] = \mathsf{sort}([d, h, l, M_m, D])\\
\\
\begin{array}{l}
t_0 := 1 + \frac{h}{\ell} \cdot \left({\left(D \cdot \frac{\frac{M\_m}{2}}{d}\right)}^{2} \cdot -0.5\right)\\
\mathbf{if}\;d \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{1}{\sqrt{\frac{\ell}{d}}} \cdot \left(\frac{\sqrt{-d}}{\sqrt{-h}} \cdot t\_0\right)\\
\mathbf{elif}\;d \leq 1.4 \cdot 10^{-207}:\\
\;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \left(t\_0 \cdot \frac{\sqrt{d}}{\sqrt{h}}\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(h, -0.5 \cdot \frac{{\left(0.5 \cdot \left(D \cdot \frac{M\_m}{d}\right)\right)}^{2}}{\ell}, 1\right) \cdot \frac{\frac{d}{\sqrt{h}}}{\sqrt{\ell}}\\
\end{array}
\end{array}
if d < -4.999999999999985e-310Initial program 67.2%
Simplified67.2%
clear-num67.1%
sqrt-div67.9%
metadata-eval67.9%
Applied egg-rr67.9%
frac-2neg67.9%
sqrt-div77.7%
Applied egg-rr77.7%
if -4.999999999999985e-310 < d < 1.39999999999999996e-207Initial program 51.8%
Simplified51.8%
sqrt-div75.0%
div-inv75.1%
Applied egg-rr75.1%
associate-*r/75.0%
*-rgt-identity75.0%
Simplified75.0%
if 1.39999999999999996e-207 < d Initial program 69.0%
Simplified69.7%
sub-neg69.7%
distribute-rgt-in55.7%
*-un-lft-identity55.7%
sqrt-div56.2%
sqrt-div59.7%
frac-times59.6%
add-sqr-sqrt59.8%
Applied egg-rr77.3%
distribute-rgt1-in89.5%
Simplified90.7%
Final simplification83.7%
M_m = (fabs.f64 M)
NOTE: d, h, l, M_m, and D should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D)
:precision binary64
(let* ((t_0 (+ 1.0 (* (/ h l) (* (pow (* D (/ (/ M_m 2.0) d)) 2.0) -0.5))))
(t_1 (sqrt (/ d l))))
(if (<= d -5e-310)
(* (* (/ (sqrt (- d)) (sqrt (- h))) t_0) t_1)
(if (<= d 5e-209)
(* t_1 (* t_0 (/ (sqrt d) (sqrt h))))
(*
(fma h (* -0.5 (/ (pow (* 0.5 (* D (/ M_m d))) 2.0) l)) 1.0)
(/ (/ d (sqrt h)) (sqrt l)))))))M_m = fabs(M);
assert(d < h && h < l && l < M_m && M_m < D);
double code(double d, double h, double l, double M_m, double D) {
double t_0 = 1.0 + ((h / l) * (pow((D * ((M_m / 2.0) / d)), 2.0) * -0.5));
double t_1 = sqrt((d / l));
double tmp;
if (d <= -5e-310) {
tmp = ((sqrt(-d) / sqrt(-h)) * t_0) * t_1;
} else if (d <= 5e-209) {
tmp = t_1 * (t_0 * (sqrt(d) / sqrt(h)));
} else {
tmp = fma(h, (-0.5 * (pow((0.5 * (D * (M_m / d))), 2.0) / l)), 1.0) * ((d / sqrt(h)) / sqrt(l));
}
return tmp;
}
M_m = abs(M) d, h, l, M_m, D = sort([d, h, l, M_m, D]) function code(d, h, l, M_m, D) t_0 = Float64(1.0 + Float64(Float64(h / l) * Float64((Float64(D * Float64(Float64(M_m / 2.0) / d)) ^ 2.0) * -0.5))) t_1 = sqrt(Float64(d / l)) tmp = 0.0 if (d <= -5e-310) tmp = Float64(Float64(Float64(sqrt(Float64(-d)) / sqrt(Float64(-h))) * t_0) * t_1); elseif (d <= 5e-209) tmp = Float64(t_1 * Float64(t_0 * Float64(sqrt(d) / sqrt(h)))); else tmp = Float64(fma(h, Float64(-0.5 * Float64((Float64(0.5 * Float64(D * Float64(M_m / d))) ^ 2.0) / l)), 1.0) * Float64(Float64(d / sqrt(h)) / sqrt(l))); end return tmp end
M_m = N[Abs[M], $MachinePrecision]
NOTE: d, h, l, M_m, and D should be sorted in increasing order before calling this function.
code[d_, h_, l_, M$95$m_, D_] := Block[{t$95$0 = N[(1.0 + N[(N[(h / l), $MachinePrecision] * N[(N[Power[N[(D * N[(N[(M$95$m / 2.0), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[d, -5e-310], N[(N[(N[(N[Sqrt[(-d)], $MachinePrecision] / N[Sqrt[(-h)], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision] * t$95$1), $MachinePrecision], If[LessEqual[d, 5e-209], N[(t$95$1 * N[(t$95$0 * N[(N[Sqrt[d], $MachinePrecision] / N[Sqrt[h], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(h * N[(-0.5 * N[(N[Power[N[(0.5 * N[(D * N[(M$95$m / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision] * N[(N[(d / N[Sqrt[h], $MachinePrecision]), $MachinePrecision] / N[Sqrt[l], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
M_m = \left|M\right|
\\
[d, h, l, M_m, D] = \mathsf{sort}([d, h, l, M_m, D])\\
\\
\begin{array}{l}
t_0 := 1 + \frac{h}{\ell} \cdot \left({\left(D \cdot \frac{\frac{M\_m}{2}}{d}\right)}^{2} \cdot -0.5\right)\\
t_1 := \sqrt{\frac{d}{\ell}}\\
\mathbf{if}\;d \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\left(\frac{\sqrt{-d}}{\sqrt{-h}} \cdot t\_0\right) \cdot t\_1\\
\mathbf{elif}\;d \leq 5 \cdot 10^{-209}:\\
\;\;\;\;t\_1 \cdot \left(t\_0 \cdot \frac{\sqrt{d}}{\sqrt{h}}\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(h, -0.5 \cdot \frac{{\left(0.5 \cdot \left(D \cdot \frac{M\_m}{d}\right)\right)}^{2}}{\ell}, 1\right) \cdot \frac{\frac{d}{\sqrt{h}}}{\sqrt{\ell}}\\
\end{array}
\end{array}
if d < -4.999999999999985e-310Initial program 67.2%
Simplified67.2%
frac-2neg67.9%
sqrt-div77.7%
Applied egg-rr76.9%
if -4.999999999999985e-310 < d < 5.0000000000000005e-209Initial program 51.8%
Simplified51.8%
sqrt-div75.0%
div-inv75.1%
Applied egg-rr75.1%
associate-*r/75.0%
*-rgt-identity75.0%
Simplified75.0%
if 5.0000000000000005e-209 < d Initial program 69.0%
Simplified69.7%
sub-neg69.7%
distribute-rgt-in55.7%
*-un-lft-identity55.7%
sqrt-div56.2%
sqrt-div59.7%
frac-times59.6%
add-sqr-sqrt59.8%
Applied egg-rr77.3%
distribute-rgt1-in89.5%
Simplified90.7%
Final simplification83.3%
M_m = (fabs.f64 M)
NOTE: d, h, l, M_m, and D should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D)
:precision binary64
(if (<= l -3.5e-126)
(* (- d) (sqrt (/ 1.0 (* l h))))
(if (<= l 4.6e-281)
(* -0.125 (* (pow (* D M_m) 2.0) (/ (sqrt (/ h (pow l 3.0))) (- d))))
(*
(+ 1.0 (* (* (/ h l) -0.5) (pow (* D (/ M_m (* d 2.0))) 2.0)))
(/ d (* (sqrt h) (sqrt l)))))))M_m = fabs(M);
assert(d < h && h < l && l < M_m && M_m < D);
double code(double d, double h, double l, double M_m, double D) {
double tmp;
if (l <= -3.5e-126) {
tmp = -d * sqrt((1.0 / (l * h)));
} else if (l <= 4.6e-281) {
tmp = -0.125 * (pow((D * M_m), 2.0) * (sqrt((h / pow(l, 3.0))) / -d));
} else {
tmp = (1.0 + (((h / l) * -0.5) * pow((D * (M_m / (d * 2.0))), 2.0))) * (d / (sqrt(h) * sqrt(l)));
}
return tmp;
}
M_m = abs(m)
NOTE: d, h, l, M_m, and D should be sorted in increasing order before calling this function.
real(8) function code(d, h, l, m_m, d_1)
real(8), intent (in) :: d
real(8), intent (in) :: h
real(8), intent (in) :: l
real(8), intent (in) :: m_m
real(8), intent (in) :: d_1
real(8) :: tmp
if (l <= (-3.5d-126)) then
tmp = -d * sqrt((1.0d0 / (l * h)))
else if (l <= 4.6d-281) then
tmp = (-0.125d0) * (((d_1 * m_m) ** 2.0d0) * (sqrt((h / (l ** 3.0d0))) / -d))
else
tmp = (1.0d0 + (((h / l) * (-0.5d0)) * ((d_1 * (m_m / (d * 2.0d0))) ** 2.0d0))) * (d / (sqrt(h) * sqrt(l)))
end if
code = tmp
end function
M_m = Math.abs(M);
assert d < h && h < l && l < M_m && M_m < D;
public static double code(double d, double h, double l, double M_m, double D) {
double tmp;
if (l <= -3.5e-126) {
tmp = -d * Math.sqrt((1.0 / (l * h)));
} else if (l <= 4.6e-281) {
tmp = -0.125 * (Math.pow((D * M_m), 2.0) * (Math.sqrt((h / Math.pow(l, 3.0))) / -d));
} else {
tmp = (1.0 + (((h / l) * -0.5) * Math.pow((D * (M_m / (d * 2.0))), 2.0))) * (d / (Math.sqrt(h) * Math.sqrt(l)));
}
return tmp;
}
M_m = math.fabs(M) [d, h, l, M_m, D] = sort([d, h, l, M_m, D]) def code(d, h, l, M_m, D): tmp = 0 if l <= -3.5e-126: tmp = -d * math.sqrt((1.0 / (l * h))) elif l <= 4.6e-281: tmp = -0.125 * (math.pow((D * M_m), 2.0) * (math.sqrt((h / math.pow(l, 3.0))) / -d)) else: tmp = (1.0 + (((h / l) * -0.5) * math.pow((D * (M_m / (d * 2.0))), 2.0))) * (d / (math.sqrt(h) * math.sqrt(l))) return tmp
M_m = abs(M) d, h, l, M_m, D = sort([d, h, l, M_m, D]) function code(d, h, l, M_m, D) tmp = 0.0 if (l <= -3.5e-126) tmp = Float64(Float64(-d) * sqrt(Float64(1.0 / Float64(l * h)))); elseif (l <= 4.6e-281) tmp = Float64(-0.125 * Float64((Float64(D * M_m) ^ 2.0) * Float64(sqrt(Float64(h / (l ^ 3.0))) / Float64(-d)))); else tmp = Float64(Float64(1.0 + Float64(Float64(Float64(h / l) * -0.5) * (Float64(D * Float64(M_m / Float64(d * 2.0))) ^ 2.0))) * Float64(d / Float64(sqrt(h) * sqrt(l)))); end return tmp end
M_m = abs(M);
d, h, l, M_m, D = num2cell(sort([d, h, l, M_m, D])){:}
function tmp_2 = code(d, h, l, M_m, D)
tmp = 0.0;
if (l <= -3.5e-126)
tmp = -d * sqrt((1.0 / (l * h)));
elseif (l <= 4.6e-281)
tmp = -0.125 * (((D * M_m) ^ 2.0) * (sqrt((h / (l ^ 3.0))) / -d));
else
tmp = (1.0 + (((h / l) * -0.5) * ((D * (M_m / (d * 2.0))) ^ 2.0))) * (d / (sqrt(h) * sqrt(l)));
end
tmp_2 = tmp;
end
M_m = N[Abs[M], $MachinePrecision] NOTE: d, h, l, M_m, and D should be sorted in increasing order before calling this function. code[d_, h_, l_, M$95$m_, D_] := If[LessEqual[l, -3.5e-126], N[((-d) * N[Sqrt[N[(1.0 / N[(l * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 4.6e-281], N[(-0.125 * N[(N[Power[N[(D * M$95$m), $MachinePrecision], 2.0], $MachinePrecision] * N[(N[Sqrt[N[(h / N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / (-d)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 + N[(N[(N[(h / l), $MachinePrecision] * -0.5), $MachinePrecision] * N[Power[N[(D * N[(M$95$m / N[(d * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(d / N[(N[Sqrt[h], $MachinePrecision] * N[Sqrt[l], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
M_m = \left|M\right|
\\
[d, h, l, M_m, D] = \mathsf{sort}([d, h, l, M_m, D])\\
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -3.5 \cdot 10^{-126}:\\
\;\;\;\;\left(-d\right) \cdot \sqrt{\frac{1}{\ell \cdot h}}\\
\mathbf{elif}\;\ell \leq 4.6 \cdot 10^{-281}:\\
\;\;\;\;-0.125 \cdot \left({\left(D \cdot M\_m\right)}^{2} \cdot \frac{\sqrt{\frac{h}{{\ell}^{3}}}}{-d}\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 + \left(\frac{h}{\ell} \cdot -0.5\right) \cdot {\left(D \cdot \frac{M\_m}{d \cdot 2}\right)}^{2}\right) \cdot \frac{d}{\sqrt{h} \cdot \sqrt{\ell}}\\
\end{array}
\end{array}
if l < -3.5e-126Initial program 65.4%
Simplified65.5%
Taylor expanded in l around -inf 0.0%
*-commutative0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt56.0%
neg-mul-156.0%
Simplified56.0%
if -3.5e-126 < l < 4.59999999999999978e-281Initial program 69.6%
Simplified69.6%
add-sqr-sqrt19.4%
sqrt-unprod16.5%
*-commutative16.5%
*-commutative16.5%
swap-sqr16.5%
Applied egg-rr16.5%
associate-*r*16.5%
times-frac16.5%
*-commutative16.5%
associate-/l*16.5%
Simplified16.5%
Taylor expanded in h around -inf 0.0%
associate-*l/0.0%
associate-/l*0.0%
associate-*r*0.0%
unpow20.0%
rem-square-sqrt50.2%
*-commutative50.2%
mul-1-neg50.2%
unpow250.2%
unpow250.2%
swap-sqr53.5%
unpow253.5%
Simplified53.5%
if 4.59999999999999978e-281 < l Initial program 67.0%
Simplified67.6%
sub-neg67.6%
distribute-rgt-in55.5%
*-un-lft-identity55.5%
sqrt-div55.9%
sqrt-div58.9%
frac-times58.9%
add-sqr-sqrt59.0%
Applied egg-rr75.4%
distribute-rgt1-in86.1%
+-commutative86.1%
associate-*r*86.1%
times-frac85.8%
*-commutative85.8%
associate-/l*86.1%
Simplified86.1%
Final simplification72.3%
M_m = (fabs.f64 M)
NOTE: d, h, l, M_m, and D should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D)
:precision binary64
(if (<= l -7.8e-126)
(* (- d) (sqrt (/ 1.0 (* l h))))
(if (<= l 4.6e-281)
(* -0.125 (* (pow (* D M_m) 2.0) (/ (sqrt (/ h (pow l 3.0))) (- d))))
(/
(* d (fma -0.5 (* (/ h l) (pow (/ (* D M_m) (* d 2.0)) 2.0)) 1.0))
(sqrt (* l h))))))M_m = fabs(M);
assert(d < h && h < l && l < M_m && M_m < D);
double code(double d, double h, double l, double M_m, double D) {
double tmp;
if (l <= -7.8e-126) {
tmp = -d * sqrt((1.0 / (l * h)));
} else if (l <= 4.6e-281) {
tmp = -0.125 * (pow((D * M_m), 2.0) * (sqrt((h / pow(l, 3.0))) / -d));
} else {
tmp = (d * fma(-0.5, ((h / l) * pow(((D * M_m) / (d * 2.0)), 2.0)), 1.0)) / sqrt((l * h));
}
return tmp;
}
M_m = abs(M) d, h, l, M_m, D = sort([d, h, l, M_m, D]) function code(d, h, l, M_m, D) tmp = 0.0 if (l <= -7.8e-126) tmp = Float64(Float64(-d) * sqrt(Float64(1.0 / Float64(l * h)))); elseif (l <= 4.6e-281) tmp = Float64(-0.125 * Float64((Float64(D * M_m) ^ 2.0) * Float64(sqrt(Float64(h / (l ^ 3.0))) / Float64(-d)))); else tmp = Float64(Float64(d * fma(-0.5, Float64(Float64(h / l) * (Float64(Float64(D * M_m) / Float64(d * 2.0)) ^ 2.0)), 1.0)) / sqrt(Float64(l * h))); end return tmp end
M_m = N[Abs[M], $MachinePrecision] NOTE: d, h, l, M_m, and D should be sorted in increasing order before calling this function. code[d_, h_, l_, M$95$m_, D_] := If[LessEqual[l, -7.8e-126], N[((-d) * N[Sqrt[N[(1.0 / N[(l * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 4.6e-281], N[(-0.125 * N[(N[Power[N[(D * M$95$m), $MachinePrecision], 2.0], $MachinePrecision] * N[(N[Sqrt[N[(h / N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / (-d)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(d * N[(-0.5 * N[(N[(h / l), $MachinePrecision] * N[Power[N[(N[(D * M$95$m), $MachinePrecision] / N[(d * 2.0), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / N[Sqrt[N[(l * h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
M_m = \left|M\right|
\\
[d, h, l, M_m, D] = \mathsf{sort}([d, h, l, M_m, D])\\
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -7.8 \cdot 10^{-126}:\\
\;\;\;\;\left(-d\right) \cdot \sqrt{\frac{1}{\ell \cdot h}}\\
\mathbf{elif}\;\ell \leq 4.6 \cdot 10^{-281}:\\
\;\;\;\;-0.125 \cdot \left({\left(D \cdot M\_m\right)}^{2} \cdot \frac{\sqrt{\frac{h}{{\ell}^{3}}}}{-d}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{d \cdot \mathsf{fma}\left(-0.5, \frac{h}{\ell} \cdot {\left(\frac{D \cdot M\_m}{d \cdot 2}\right)}^{2}, 1\right)}{\sqrt{\ell \cdot h}}\\
\end{array}
\end{array}
if l < -7.7999999999999996e-126Initial program 65.4%
Simplified65.5%
Taylor expanded in l around -inf 0.0%
*-commutative0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt56.0%
neg-mul-156.0%
Simplified56.0%
if -7.7999999999999996e-126 < l < 4.59999999999999978e-281Initial program 69.6%
Simplified69.6%
add-sqr-sqrt19.4%
sqrt-unprod16.5%
*-commutative16.5%
*-commutative16.5%
swap-sqr16.5%
Applied egg-rr16.5%
associate-*r*16.5%
times-frac16.5%
*-commutative16.5%
associate-/l*16.5%
Simplified16.5%
Taylor expanded in h around -inf 0.0%
associate-*l/0.0%
associate-/l*0.0%
associate-*r*0.0%
unpow20.0%
rem-square-sqrt50.2%
*-commutative50.2%
mul-1-neg50.2%
unpow250.2%
unpow250.2%
swap-sqr53.5%
unpow253.5%
Simplified53.5%
if 4.59999999999999978e-281 < l Initial program 67.0%
Simplified67.6%
sub-neg67.6%
distribute-rgt-in55.5%
*-un-lft-identity55.5%
sqrt-div55.9%
sqrt-div58.9%
frac-times58.9%
add-sqr-sqrt59.0%
Applied egg-rr75.4%
distribute-rgt1-in86.1%
+-commutative86.1%
associate-*r*86.1%
times-frac85.8%
*-commutative85.8%
associate-/l*86.1%
Simplified86.1%
associate-*r/89.6%
+-commutative89.6%
associate-*l*89.6%
fma-define89.6%
associate-*r/89.3%
sqrt-unprod77.1%
*-commutative77.1%
Applied egg-rr77.1%
Final simplification67.3%
M_m = (fabs.f64 M)
NOTE: d, h, l, M_m, and D should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D)
:precision binary64
(if (<= h 3e-300)
(*
(* (sqrt (/ d l)) (sqrt (/ d h)))
(- 1.0 (* 0.5 (* h (/ (pow (* 0.5 (* D (/ M_m d))) 2.0) l)))))
(*
(+ 1.0 (* (* (/ h l) -0.5) (pow (* D (/ M_m (* d 2.0))) 2.0)))
(/ d (* (sqrt h) (sqrt l))))))M_m = fabs(M);
assert(d < h && h < l && l < M_m && M_m < D);
double code(double d, double h, double l, double M_m, double D) {
double tmp;
if (h <= 3e-300) {
tmp = (sqrt((d / l)) * sqrt((d / h))) * (1.0 - (0.5 * (h * (pow((0.5 * (D * (M_m / d))), 2.0) / l))));
} else {
tmp = (1.0 + (((h / l) * -0.5) * pow((D * (M_m / (d * 2.0))), 2.0))) * (d / (sqrt(h) * sqrt(l)));
}
return tmp;
}
M_m = abs(m)
NOTE: d, h, l, M_m, and D should be sorted in increasing order before calling this function.
real(8) function code(d, h, l, m_m, d_1)
real(8), intent (in) :: d
real(8), intent (in) :: h
real(8), intent (in) :: l
real(8), intent (in) :: m_m
real(8), intent (in) :: d_1
real(8) :: tmp
if (h <= 3d-300) then
tmp = (sqrt((d / l)) * sqrt((d / h))) * (1.0d0 - (0.5d0 * (h * (((0.5d0 * (d_1 * (m_m / d))) ** 2.0d0) / l))))
else
tmp = (1.0d0 + (((h / l) * (-0.5d0)) * ((d_1 * (m_m / (d * 2.0d0))) ** 2.0d0))) * (d / (sqrt(h) * sqrt(l)))
end if
code = tmp
end function
M_m = Math.abs(M);
assert d < h && h < l && l < M_m && M_m < D;
public static double code(double d, double h, double l, double M_m, double D) {
double tmp;
if (h <= 3e-300) {
tmp = (Math.sqrt((d / l)) * Math.sqrt((d / h))) * (1.0 - (0.5 * (h * (Math.pow((0.5 * (D * (M_m / d))), 2.0) / l))));
} else {
tmp = (1.0 + (((h / l) * -0.5) * Math.pow((D * (M_m / (d * 2.0))), 2.0))) * (d / (Math.sqrt(h) * Math.sqrt(l)));
}
return tmp;
}
M_m = math.fabs(M) [d, h, l, M_m, D] = sort([d, h, l, M_m, D]) def code(d, h, l, M_m, D): tmp = 0 if h <= 3e-300: tmp = (math.sqrt((d / l)) * math.sqrt((d / h))) * (1.0 - (0.5 * (h * (math.pow((0.5 * (D * (M_m / d))), 2.0) / l)))) else: tmp = (1.0 + (((h / l) * -0.5) * math.pow((D * (M_m / (d * 2.0))), 2.0))) * (d / (math.sqrt(h) * math.sqrt(l))) return tmp
M_m = abs(M) d, h, l, M_m, D = sort([d, h, l, M_m, D]) function code(d, h, l, M_m, D) tmp = 0.0 if (h <= 3e-300) tmp = Float64(Float64(sqrt(Float64(d / l)) * sqrt(Float64(d / h))) * Float64(1.0 - Float64(0.5 * Float64(h * Float64((Float64(0.5 * Float64(D * Float64(M_m / d))) ^ 2.0) / l))))); else tmp = Float64(Float64(1.0 + Float64(Float64(Float64(h / l) * -0.5) * (Float64(D * Float64(M_m / Float64(d * 2.0))) ^ 2.0))) * Float64(d / Float64(sqrt(h) * sqrt(l)))); end return tmp end
M_m = abs(M);
d, h, l, M_m, D = num2cell(sort([d, h, l, M_m, D])){:}
function tmp_2 = code(d, h, l, M_m, D)
tmp = 0.0;
if (h <= 3e-300)
tmp = (sqrt((d / l)) * sqrt((d / h))) * (1.0 - (0.5 * (h * (((0.5 * (D * (M_m / d))) ^ 2.0) / l))));
else
tmp = (1.0 + (((h / l) * -0.5) * ((D * (M_m / (d * 2.0))) ^ 2.0))) * (d / (sqrt(h) * sqrt(l)));
end
tmp_2 = tmp;
end
M_m = N[Abs[M], $MachinePrecision] NOTE: d, h, l, M_m, and D should be sorted in increasing order before calling this function. code[d_, h_, l_, M$95$m_, D_] := If[LessEqual[h, 3e-300], N[(N[(N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(1.0 - N[(0.5 * N[(h * N[(N[Power[N[(0.5 * N[(D * N[(M$95$m / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 + N[(N[(N[(h / l), $MachinePrecision] * -0.5), $MachinePrecision] * N[Power[N[(D * N[(M$95$m / N[(d * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(d / N[(N[Sqrt[h], $MachinePrecision] * N[Sqrt[l], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
M_m = \left|M\right|
\\
[d, h, l, M_m, D] = \mathsf{sort}([d, h, l, M_m, D])\\
\\
\begin{array}{l}
\mathbf{if}\;h \leq 3 \cdot 10^{-300}:\\
\;\;\;\;\left(\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}\right) \cdot \left(1 - 0.5 \cdot \left(h \cdot \frac{{\left(0.5 \cdot \left(D \cdot \frac{M\_m}{d}\right)\right)}^{2}}{\ell}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 + \left(\frac{h}{\ell} \cdot -0.5\right) \cdot {\left(D \cdot \frac{M\_m}{d \cdot 2}\right)}^{2}\right) \cdot \frac{d}{\sqrt{h} \cdot \sqrt{\ell}}\\
\end{array}
\end{array}
if h < 3.00000000000000024e-300Initial program 67.4%
Simplified67.5%
clear-num67.5%
un-div-inv67.9%
frac-times67.9%
*-commutative67.9%
times-frac67.9%
Applied egg-rr67.9%
associate-/r/70.9%
*-commutative70.9%
*-rgt-identity70.9%
associate-/l*70.9%
metadata-eval70.9%
*-commutative70.9%
associate-*r*70.9%
Simplified70.9%
if 3.00000000000000024e-300 < h Initial program 66.3%
Simplified66.9%
sub-neg66.9%
distribute-rgt-in55.2%
*-un-lft-identity55.2%
sqrt-div55.7%
sqrt-div58.7%
frac-times58.8%
add-sqr-sqrt58.9%
Applied egg-rr75.6%
distribute-rgt1-in85.8%
+-commutative85.8%
associate-*r*85.8%
times-frac85.5%
*-commutative85.5%
associate-/l*85.8%
Simplified85.8%
Final simplification78.9%
M_m = (fabs.f64 M)
NOTE: d, h, l, M_m, and D should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D)
:precision binary64
(if (<= h 3e-300)
(*
(sqrt (/ d l))
(*
(+ 1.0 (* (/ h l) (* (pow (* D (/ (/ M_m 2.0) d)) 2.0) -0.5)))
(sqrt (/ d h))))
(*
(+ 1.0 (* (* (/ h l) -0.5) (pow (* D (/ M_m (* d 2.0))) 2.0)))
(/ d (* (sqrt h) (sqrt l))))))M_m = fabs(M);
assert(d < h && h < l && l < M_m && M_m < D);
double code(double d, double h, double l, double M_m, double D) {
double tmp;
if (h <= 3e-300) {
tmp = sqrt((d / l)) * ((1.0 + ((h / l) * (pow((D * ((M_m / 2.0) / d)), 2.0) * -0.5))) * sqrt((d / h)));
} else {
tmp = (1.0 + (((h / l) * -0.5) * pow((D * (M_m / (d * 2.0))), 2.0))) * (d / (sqrt(h) * sqrt(l)));
}
return tmp;
}
M_m = abs(m)
NOTE: d, h, l, M_m, and D should be sorted in increasing order before calling this function.
real(8) function code(d, h, l, m_m, d_1)
real(8), intent (in) :: d
real(8), intent (in) :: h
real(8), intent (in) :: l
real(8), intent (in) :: m_m
real(8), intent (in) :: d_1
real(8) :: tmp
if (h <= 3d-300) then
tmp = sqrt((d / l)) * ((1.0d0 + ((h / l) * (((d_1 * ((m_m / 2.0d0) / d)) ** 2.0d0) * (-0.5d0)))) * sqrt((d / h)))
else
tmp = (1.0d0 + (((h / l) * (-0.5d0)) * ((d_1 * (m_m / (d * 2.0d0))) ** 2.0d0))) * (d / (sqrt(h) * sqrt(l)))
end if
code = tmp
end function
M_m = Math.abs(M);
assert d < h && h < l && l < M_m && M_m < D;
public static double code(double d, double h, double l, double M_m, double D) {
double tmp;
if (h <= 3e-300) {
tmp = Math.sqrt((d / l)) * ((1.0 + ((h / l) * (Math.pow((D * ((M_m / 2.0) / d)), 2.0) * -0.5))) * Math.sqrt((d / h)));
} else {
tmp = (1.0 + (((h / l) * -0.5) * Math.pow((D * (M_m / (d * 2.0))), 2.0))) * (d / (Math.sqrt(h) * Math.sqrt(l)));
}
return tmp;
}
M_m = math.fabs(M) [d, h, l, M_m, D] = sort([d, h, l, M_m, D]) def code(d, h, l, M_m, D): tmp = 0 if h <= 3e-300: tmp = math.sqrt((d / l)) * ((1.0 + ((h / l) * (math.pow((D * ((M_m / 2.0) / d)), 2.0) * -0.5))) * math.sqrt((d / h))) else: tmp = (1.0 + (((h / l) * -0.5) * math.pow((D * (M_m / (d * 2.0))), 2.0))) * (d / (math.sqrt(h) * math.sqrt(l))) return tmp
M_m = abs(M) d, h, l, M_m, D = sort([d, h, l, M_m, D]) function code(d, h, l, M_m, D) tmp = 0.0 if (h <= 3e-300) tmp = Float64(sqrt(Float64(d / l)) * Float64(Float64(1.0 + Float64(Float64(h / l) * Float64((Float64(D * Float64(Float64(M_m / 2.0) / d)) ^ 2.0) * -0.5))) * sqrt(Float64(d / h)))); else tmp = Float64(Float64(1.0 + Float64(Float64(Float64(h / l) * -0.5) * (Float64(D * Float64(M_m / Float64(d * 2.0))) ^ 2.0))) * Float64(d / Float64(sqrt(h) * sqrt(l)))); end return tmp end
M_m = abs(M);
d, h, l, M_m, D = num2cell(sort([d, h, l, M_m, D])){:}
function tmp_2 = code(d, h, l, M_m, D)
tmp = 0.0;
if (h <= 3e-300)
tmp = sqrt((d / l)) * ((1.0 + ((h / l) * (((D * ((M_m / 2.0) / d)) ^ 2.0) * -0.5))) * sqrt((d / h)));
else
tmp = (1.0 + (((h / l) * -0.5) * ((D * (M_m / (d * 2.0))) ^ 2.0))) * (d / (sqrt(h) * sqrt(l)));
end
tmp_2 = tmp;
end
M_m = N[Abs[M], $MachinePrecision] NOTE: d, h, l, M_m, and D should be sorted in increasing order before calling this function. code[d_, h_, l_, M$95$m_, D_] := If[LessEqual[h, 3e-300], N[(N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision] * N[(N[(1.0 + N[(N[(h / l), $MachinePrecision] * N[(N[Power[N[(D * N[(N[(M$95$m / 2.0), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 + N[(N[(N[(h / l), $MachinePrecision] * -0.5), $MachinePrecision] * N[Power[N[(D * N[(M$95$m / N[(d * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(d / N[(N[Sqrt[h], $MachinePrecision] * N[Sqrt[l], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
M_m = \left|M\right|
\\
[d, h, l, M_m, D] = \mathsf{sort}([d, h, l, M_m, D])\\
\\
\begin{array}{l}
\mathbf{if}\;h \leq 3 \cdot 10^{-300}:\\
\;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \left(\left(1 + \frac{h}{\ell} \cdot \left({\left(D \cdot \frac{\frac{M\_m}{2}}{d}\right)}^{2} \cdot -0.5\right)\right) \cdot \sqrt{\frac{d}{h}}\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 + \left(\frac{h}{\ell} \cdot -0.5\right) \cdot {\left(D \cdot \frac{M\_m}{d \cdot 2}\right)}^{2}\right) \cdot \frac{d}{\sqrt{h} \cdot \sqrt{\ell}}\\
\end{array}
\end{array}
if h < 3.00000000000000024e-300Initial program 67.4%
Simplified67.4%
if 3.00000000000000024e-300 < h Initial program 66.3%
Simplified66.9%
sub-neg66.9%
distribute-rgt-in55.2%
*-un-lft-identity55.2%
sqrt-div55.7%
sqrt-div58.7%
frac-times58.8%
add-sqr-sqrt58.9%
Applied egg-rr75.6%
distribute-rgt1-in85.8%
+-commutative85.8%
associate-*r*85.8%
times-frac85.5%
*-commutative85.5%
associate-/l*85.8%
Simplified85.8%
Final simplification77.3%
M_m = (fabs.f64 M)
NOTE: d, h, l, M_m, and D should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D)
:precision binary64
(if (<= l -2.4e-130)
(* (- d) (sqrt (/ 1.0 (* l h))))
(if (<= l 4.6e-281)
(* -0.125 (* (pow (* D M_m) 2.0) (/ (sqrt (/ h (pow l 3.0))) (- d))))
(*
(+ 1.0 (* (* (/ h l) -0.5) (pow (* D (/ M_m (* d 2.0))) 2.0)))
(/ d (sqrt (* l h)))))))M_m = fabs(M);
assert(d < h && h < l && l < M_m && M_m < D);
double code(double d, double h, double l, double M_m, double D) {
double tmp;
if (l <= -2.4e-130) {
tmp = -d * sqrt((1.0 / (l * h)));
} else if (l <= 4.6e-281) {
tmp = -0.125 * (pow((D * M_m), 2.0) * (sqrt((h / pow(l, 3.0))) / -d));
} else {
tmp = (1.0 + (((h / l) * -0.5) * pow((D * (M_m / (d * 2.0))), 2.0))) * (d / sqrt((l * h)));
}
return tmp;
}
M_m = abs(m)
NOTE: d, h, l, M_m, and D should be sorted in increasing order before calling this function.
real(8) function code(d, h, l, m_m, d_1)
real(8), intent (in) :: d
real(8), intent (in) :: h
real(8), intent (in) :: l
real(8), intent (in) :: m_m
real(8), intent (in) :: d_1
real(8) :: tmp
if (l <= (-2.4d-130)) then
tmp = -d * sqrt((1.0d0 / (l * h)))
else if (l <= 4.6d-281) then
tmp = (-0.125d0) * (((d_1 * m_m) ** 2.0d0) * (sqrt((h / (l ** 3.0d0))) / -d))
else
tmp = (1.0d0 + (((h / l) * (-0.5d0)) * ((d_1 * (m_m / (d * 2.0d0))) ** 2.0d0))) * (d / sqrt((l * h)))
end if
code = tmp
end function
M_m = Math.abs(M);
assert d < h && h < l && l < M_m && M_m < D;
public static double code(double d, double h, double l, double M_m, double D) {
double tmp;
if (l <= -2.4e-130) {
tmp = -d * Math.sqrt((1.0 / (l * h)));
} else if (l <= 4.6e-281) {
tmp = -0.125 * (Math.pow((D * M_m), 2.0) * (Math.sqrt((h / Math.pow(l, 3.0))) / -d));
} else {
tmp = (1.0 + (((h / l) * -0.5) * Math.pow((D * (M_m / (d * 2.0))), 2.0))) * (d / Math.sqrt((l * h)));
}
return tmp;
}
M_m = math.fabs(M) [d, h, l, M_m, D] = sort([d, h, l, M_m, D]) def code(d, h, l, M_m, D): tmp = 0 if l <= -2.4e-130: tmp = -d * math.sqrt((1.0 / (l * h))) elif l <= 4.6e-281: tmp = -0.125 * (math.pow((D * M_m), 2.0) * (math.sqrt((h / math.pow(l, 3.0))) / -d)) else: tmp = (1.0 + (((h / l) * -0.5) * math.pow((D * (M_m / (d * 2.0))), 2.0))) * (d / math.sqrt((l * h))) return tmp
M_m = abs(M) d, h, l, M_m, D = sort([d, h, l, M_m, D]) function code(d, h, l, M_m, D) tmp = 0.0 if (l <= -2.4e-130) tmp = Float64(Float64(-d) * sqrt(Float64(1.0 / Float64(l * h)))); elseif (l <= 4.6e-281) tmp = Float64(-0.125 * Float64((Float64(D * M_m) ^ 2.0) * Float64(sqrt(Float64(h / (l ^ 3.0))) / Float64(-d)))); else tmp = Float64(Float64(1.0 + Float64(Float64(Float64(h / l) * -0.5) * (Float64(D * Float64(M_m / Float64(d * 2.0))) ^ 2.0))) * Float64(d / sqrt(Float64(l * h)))); end return tmp end
M_m = abs(M);
d, h, l, M_m, D = num2cell(sort([d, h, l, M_m, D])){:}
function tmp_2 = code(d, h, l, M_m, D)
tmp = 0.0;
if (l <= -2.4e-130)
tmp = -d * sqrt((1.0 / (l * h)));
elseif (l <= 4.6e-281)
tmp = -0.125 * (((D * M_m) ^ 2.0) * (sqrt((h / (l ^ 3.0))) / -d));
else
tmp = (1.0 + (((h / l) * -0.5) * ((D * (M_m / (d * 2.0))) ^ 2.0))) * (d / sqrt((l * h)));
end
tmp_2 = tmp;
end
M_m = N[Abs[M], $MachinePrecision] NOTE: d, h, l, M_m, and D should be sorted in increasing order before calling this function. code[d_, h_, l_, M$95$m_, D_] := If[LessEqual[l, -2.4e-130], N[((-d) * N[Sqrt[N[(1.0 / N[(l * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 4.6e-281], N[(-0.125 * N[(N[Power[N[(D * M$95$m), $MachinePrecision], 2.0], $MachinePrecision] * N[(N[Sqrt[N[(h / N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / (-d)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 + N[(N[(N[(h / l), $MachinePrecision] * -0.5), $MachinePrecision] * N[Power[N[(D * N[(M$95$m / N[(d * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(d / N[Sqrt[N[(l * h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
M_m = \left|M\right|
\\
[d, h, l, M_m, D] = \mathsf{sort}([d, h, l, M_m, D])\\
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -2.4 \cdot 10^{-130}:\\
\;\;\;\;\left(-d\right) \cdot \sqrt{\frac{1}{\ell \cdot h}}\\
\mathbf{elif}\;\ell \leq 4.6 \cdot 10^{-281}:\\
\;\;\;\;-0.125 \cdot \left({\left(D \cdot M\_m\right)}^{2} \cdot \frac{\sqrt{\frac{h}{{\ell}^{3}}}}{-d}\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 + \left(\frac{h}{\ell} \cdot -0.5\right) \cdot {\left(D \cdot \frac{M\_m}{d \cdot 2}\right)}^{2}\right) \cdot \frac{d}{\sqrt{\ell \cdot h}}\\
\end{array}
\end{array}
if l < -2.39999999999999997e-130Initial program 65.4%
Simplified65.5%
Taylor expanded in l around -inf 0.0%
*-commutative0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt56.0%
neg-mul-156.0%
Simplified56.0%
if -2.39999999999999997e-130 < l < 4.59999999999999978e-281Initial program 69.6%
Simplified69.6%
add-sqr-sqrt19.4%
sqrt-unprod16.5%
*-commutative16.5%
*-commutative16.5%
swap-sqr16.5%
Applied egg-rr16.5%
associate-*r*16.5%
times-frac16.5%
*-commutative16.5%
associate-/l*16.5%
Simplified16.5%
Taylor expanded in h around -inf 0.0%
associate-*l/0.0%
associate-/l*0.0%
associate-*r*0.0%
unpow20.0%
rem-square-sqrt50.2%
*-commutative50.2%
mul-1-neg50.2%
unpow250.2%
unpow250.2%
swap-sqr53.5%
unpow253.5%
Simplified53.5%
if 4.59999999999999978e-281 < l Initial program 67.0%
Simplified67.6%
sub-neg67.6%
distribute-rgt-in55.5%
*-un-lft-identity55.5%
sqrt-div55.9%
sqrt-div58.9%
frac-times58.9%
add-sqr-sqrt59.0%
Applied egg-rr75.4%
distribute-rgt1-in86.1%
+-commutative86.1%
associate-*r*86.1%
times-frac85.8%
*-commutative85.8%
associate-/l*86.1%
Simplified86.1%
Taylor expanded in h around 0 74.0%
*-commutative74.0%
Simplified74.0%
Final simplification65.6%
M_m = (fabs.f64 M)
NOTE: d, h, l, M_m, and D should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D)
:precision binary64
(if (<= d 4e-262)
(* (- d) (sqrt (/ 1.0 (* l h))))
(*
(+ 1.0 (* (* (/ h l) -0.5) (pow (* D (/ M_m (* d 2.0))) 2.0)))
(/ d (sqrt (* l h))))))M_m = fabs(M);
assert(d < h && h < l && l < M_m && M_m < D);
double code(double d, double h, double l, double M_m, double D) {
double tmp;
if (d <= 4e-262) {
tmp = -d * sqrt((1.0 / (l * h)));
} else {
tmp = (1.0 + (((h / l) * -0.5) * pow((D * (M_m / (d * 2.0))), 2.0))) * (d / sqrt((l * h)));
}
return tmp;
}
M_m = abs(m)
NOTE: d, h, l, M_m, and D should be sorted in increasing order before calling this function.
real(8) function code(d, h, l, m_m, d_1)
real(8), intent (in) :: d
real(8), intent (in) :: h
real(8), intent (in) :: l
real(8), intent (in) :: m_m
real(8), intent (in) :: d_1
real(8) :: tmp
if (d <= 4d-262) then
tmp = -d * sqrt((1.0d0 / (l * h)))
else
tmp = (1.0d0 + (((h / l) * (-0.5d0)) * ((d_1 * (m_m / (d * 2.0d0))) ** 2.0d0))) * (d / sqrt((l * h)))
end if
code = tmp
end function
M_m = Math.abs(M);
assert d < h && h < l && l < M_m && M_m < D;
public static double code(double d, double h, double l, double M_m, double D) {
double tmp;
if (d <= 4e-262) {
tmp = -d * Math.sqrt((1.0 / (l * h)));
} else {
tmp = (1.0 + (((h / l) * -0.5) * Math.pow((D * (M_m / (d * 2.0))), 2.0))) * (d / Math.sqrt((l * h)));
}
return tmp;
}
M_m = math.fabs(M) [d, h, l, M_m, D] = sort([d, h, l, M_m, D]) def code(d, h, l, M_m, D): tmp = 0 if d <= 4e-262: tmp = -d * math.sqrt((1.0 / (l * h))) else: tmp = (1.0 + (((h / l) * -0.5) * math.pow((D * (M_m / (d * 2.0))), 2.0))) * (d / math.sqrt((l * h))) return tmp
M_m = abs(M) d, h, l, M_m, D = sort([d, h, l, M_m, D]) function code(d, h, l, M_m, D) tmp = 0.0 if (d <= 4e-262) tmp = Float64(Float64(-d) * sqrt(Float64(1.0 / Float64(l * h)))); else tmp = Float64(Float64(1.0 + Float64(Float64(Float64(h / l) * -0.5) * (Float64(D * Float64(M_m / Float64(d * 2.0))) ^ 2.0))) * Float64(d / sqrt(Float64(l * h)))); end return tmp end
M_m = abs(M);
d, h, l, M_m, D = num2cell(sort([d, h, l, M_m, D])){:}
function tmp_2 = code(d, h, l, M_m, D)
tmp = 0.0;
if (d <= 4e-262)
tmp = -d * sqrt((1.0 / (l * h)));
else
tmp = (1.0 + (((h / l) * -0.5) * ((D * (M_m / (d * 2.0))) ^ 2.0))) * (d / sqrt((l * h)));
end
tmp_2 = tmp;
end
M_m = N[Abs[M], $MachinePrecision] NOTE: d, h, l, M_m, and D should be sorted in increasing order before calling this function. code[d_, h_, l_, M$95$m_, D_] := If[LessEqual[d, 4e-262], N[((-d) * N[Sqrt[N[(1.0 / N[(l * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(1.0 + N[(N[(N[(h / l), $MachinePrecision] * -0.5), $MachinePrecision] * N[Power[N[(D * N[(M$95$m / N[(d * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(d / N[Sqrt[N[(l * h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
M_m = \left|M\right|
\\
[d, h, l, M_m, D] = \mathsf{sort}([d, h, l, M_m, D])\\
\\
\begin{array}{l}
\mathbf{if}\;d \leq 4 \cdot 10^{-262}:\\
\;\;\;\;\left(-d\right) \cdot \sqrt{\frac{1}{\ell \cdot h}}\\
\mathbf{else}:\\
\;\;\;\;\left(1 + \left(\frac{h}{\ell} \cdot -0.5\right) \cdot {\left(D \cdot \frac{M\_m}{d \cdot 2}\right)}^{2}\right) \cdot \frac{d}{\sqrt{\ell \cdot h}}\\
\end{array}
\end{array}
if d < 4.00000000000000005e-262Initial program 66.3%
Simplified66.4%
Taylor expanded in l around -inf 0.0%
*-commutative0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt48.7%
neg-mul-148.7%
Simplified48.7%
if 4.00000000000000005e-262 < d Initial program 67.3%
Simplified68.0%
sub-neg68.0%
distribute-rgt-in54.8%
*-un-lft-identity54.8%
sqrt-div55.2%
sqrt-div58.5%
frac-times58.5%
add-sqr-sqrt58.6%
Applied egg-rr76.4%
distribute-rgt1-in88.0%
+-commutative88.0%
associate-*r*88.0%
times-frac87.7%
*-commutative87.7%
associate-/l*88.0%
Simplified88.0%
Taylor expanded in h around 0 76.4%
*-commutative76.4%
Simplified76.4%
Final simplification62.8%
M_m = (fabs.f64 M) NOTE: d, h, l, M_m, and D should be sorted in increasing order before calling this function. (FPCore (d h l M_m D) :precision binary64 (let* ((t_0 (sqrt (/ 1.0 (* l h))))) (if (<= d 3e-174) (* (- d) t_0) (* d t_0))))
M_m = fabs(M);
assert(d < h && h < l && l < M_m && M_m < D);
double code(double d, double h, double l, double M_m, double D) {
double t_0 = sqrt((1.0 / (l * h)));
double tmp;
if (d <= 3e-174) {
tmp = -d * t_0;
} else {
tmp = d * t_0;
}
return tmp;
}
M_m = abs(m)
NOTE: d, h, l, M_m, and D should be sorted in increasing order before calling this function.
real(8) function code(d, h, l, m_m, d_1)
real(8), intent (in) :: d
real(8), intent (in) :: h
real(8), intent (in) :: l
real(8), intent (in) :: m_m
real(8), intent (in) :: d_1
real(8) :: t_0
real(8) :: tmp
t_0 = sqrt((1.0d0 / (l * h)))
if (d <= 3d-174) then
tmp = -d * t_0
else
tmp = d * t_0
end if
code = tmp
end function
M_m = Math.abs(M);
assert d < h && h < l && l < M_m && M_m < D;
public static double code(double d, double h, double l, double M_m, double D) {
double t_0 = Math.sqrt((1.0 / (l * h)));
double tmp;
if (d <= 3e-174) {
tmp = -d * t_0;
} else {
tmp = d * t_0;
}
return tmp;
}
M_m = math.fabs(M) [d, h, l, M_m, D] = sort([d, h, l, M_m, D]) def code(d, h, l, M_m, D): t_0 = math.sqrt((1.0 / (l * h))) tmp = 0 if d <= 3e-174: tmp = -d * t_0 else: tmp = d * t_0 return tmp
M_m = abs(M) d, h, l, M_m, D = sort([d, h, l, M_m, D]) function code(d, h, l, M_m, D) t_0 = sqrt(Float64(1.0 / Float64(l * h))) tmp = 0.0 if (d <= 3e-174) tmp = Float64(Float64(-d) * t_0); else tmp = Float64(d * t_0); end return tmp end
M_m = abs(M);
d, h, l, M_m, D = num2cell(sort([d, h, l, M_m, D])){:}
function tmp_2 = code(d, h, l, M_m, D)
t_0 = sqrt((1.0 / (l * h)));
tmp = 0.0;
if (d <= 3e-174)
tmp = -d * t_0;
else
tmp = d * t_0;
end
tmp_2 = tmp;
end
M_m = N[Abs[M], $MachinePrecision]
NOTE: d, h, l, M_m, and D should be sorted in increasing order before calling this function.
code[d_, h_, l_, M$95$m_, D_] := Block[{t$95$0 = N[Sqrt[N[(1.0 / N[(l * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[d, 3e-174], N[((-d) * t$95$0), $MachinePrecision], N[(d * t$95$0), $MachinePrecision]]]
\begin{array}{l}
M_m = \left|M\right|
\\
[d, h, l, M_m, D] = \mathsf{sort}([d, h, l, M_m, D])\\
\\
\begin{array}{l}
t_0 := \sqrt{\frac{1}{\ell \cdot h}}\\
\mathbf{if}\;d \leq 3 \cdot 10^{-174}:\\
\;\;\;\;\left(-d\right) \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;d \cdot t\_0\\
\end{array}
\end{array}
if d < 3.00000000000000021e-174Initial program 64.1%
Simplified64.1%
Taylor expanded in l around -inf 0.0%
*-commutative0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt45.4%
neg-mul-145.4%
Simplified45.4%
if 3.00000000000000021e-174 < d Initial program 70.4%
Simplified71.2%
Taylor expanded in d around inf 59.8%
Final simplification51.6%
M_m = (fabs.f64 M) NOTE: d, h, l, M_m, and D should be sorted in increasing order before calling this function. (FPCore (d h l M_m D) :precision binary64 (* d (sqrt (/ 1.0 (* l h)))))
M_m = fabs(M);
assert(d < h && h < l && l < M_m && M_m < D);
double code(double d, double h, double l, double M_m, double D) {
return d * sqrt((1.0 / (l * h)));
}
M_m = abs(m)
NOTE: d, h, l, M_m, and D should be sorted in increasing order before calling this function.
real(8) function code(d, h, l, m_m, d_1)
real(8), intent (in) :: d
real(8), intent (in) :: h
real(8), intent (in) :: l
real(8), intent (in) :: m_m
real(8), intent (in) :: d_1
code = d * sqrt((1.0d0 / (l * h)))
end function
M_m = Math.abs(M);
assert d < h && h < l && l < M_m && M_m < D;
public static double code(double d, double h, double l, double M_m, double D) {
return d * Math.sqrt((1.0 / (l * h)));
}
M_m = math.fabs(M) [d, h, l, M_m, D] = sort([d, h, l, M_m, D]) def code(d, h, l, M_m, D): return d * math.sqrt((1.0 / (l * h)))
M_m = abs(M) d, h, l, M_m, D = sort([d, h, l, M_m, D]) function code(d, h, l, M_m, D) return Float64(d * sqrt(Float64(1.0 / Float64(l * h)))) end
M_m = abs(M);
d, h, l, M_m, D = num2cell(sort([d, h, l, M_m, D])){:}
function tmp = code(d, h, l, M_m, D)
tmp = d * sqrt((1.0 / (l * h)));
end
M_m = N[Abs[M], $MachinePrecision] NOTE: d, h, l, M_m, and D should be sorted in increasing order before calling this function. code[d_, h_, l_, M$95$m_, D_] := N[(d * N[Sqrt[N[(1.0 / N[(l * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
M_m = \left|M\right|
\\
[d, h, l, M_m, D] = \mathsf{sort}([d, h, l, M_m, D])\\
\\
d \cdot \sqrt{\frac{1}{\ell \cdot h}}
\end{array}
Initial program 66.8%
Simplified67.2%
Taylor expanded in d around inf 32.6%
Final simplification32.6%
herbie shell --seed 2024103
(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)))))