
(FPCore (c0 w h D d M) :precision binary64 (let* ((t_0 (/ (* c0 (* d d)) (* (* w h) (* D D))))) (* (/ c0 (* 2.0 w)) (+ t_0 (sqrt (- (* t_0 t_0) (* M M)))))))
double code(double c0, double w, double h, double D, double d, double M) {
double t_0 = (c0 * (d * d)) / ((w * h) * (D * D));
return (c0 / (2.0 * w)) * (t_0 + sqrt(((t_0 * t_0) - (M * M))));
}
real(8) function code(c0, w, h, d, d_1, m)
real(8), intent (in) :: c0
real(8), intent (in) :: w
real(8), intent (in) :: h
real(8), intent (in) :: d
real(8), intent (in) :: d_1
real(8), intent (in) :: m
real(8) :: t_0
t_0 = (c0 * (d_1 * d_1)) / ((w * h) * (d * d))
code = (c0 / (2.0d0 * w)) * (t_0 + sqrt(((t_0 * t_0) - (m * m))))
end function
public static double code(double c0, double w, double h, double D, double d, double M) {
double t_0 = (c0 * (d * d)) / ((w * h) * (D * D));
return (c0 / (2.0 * w)) * (t_0 + Math.sqrt(((t_0 * t_0) - (M * M))));
}
def code(c0, w, h, D, d, M): t_0 = (c0 * (d * d)) / ((w * h) * (D * D)) return (c0 / (2.0 * w)) * (t_0 + math.sqrt(((t_0 * t_0) - (M * M))))
function code(c0, w, h, D, d, M) t_0 = Float64(Float64(c0 * Float64(d * d)) / Float64(Float64(w * h) * Float64(D * D))) return Float64(Float64(c0 / Float64(2.0 * w)) * Float64(t_0 + sqrt(Float64(Float64(t_0 * t_0) - Float64(M * M))))) end
function tmp = code(c0, w, h, D, d, M) t_0 = (c0 * (d * d)) / ((w * h) * (D * D)); tmp = (c0 / (2.0 * w)) * (t_0 + sqrt(((t_0 * t_0) - (M * M)))); end
code[c0_, w_, h_, D_, d_, M_] := Block[{t$95$0 = N[(N[(c0 * N[(d * d), $MachinePrecision]), $MachinePrecision] / N[(N[(w * h), $MachinePrecision] * N[(D * D), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(N[(c0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision] * N[(t$95$0 + N[Sqrt[N[(N[(t$95$0 * t$95$0), $MachinePrecision] - N[(M * M), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}\\
\frac{c0}{2 \cdot w} \cdot \left(t_0 + \sqrt{t_0 \cdot t_0 - M \cdot M}\right)
\end{array}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (c0 w h D d M) :precision binary64 (let* ((t_0 (/ (* c0 (* d d)) (* (* w h) (* D D))))) (* (/ c0 (* 2.0 w)) (+ t_0 (sqrt (- (* t_0 t_0) (* M M)))))))
double code(double c0, double w, double h, double D, double d, double M) {
double t_0 = (c0 * (d * d)) / ((w * h) * (D * D));
return (c0 / (2.0 * w)) * (t_0 + sqrt(((t_0 * t_0) - (M * M))));
}
real(8) function code(c0, w, h, d, d_1, m)
real(8), intent (in) :: c0
real(8), intent (in) :: w
real(8), intent (in) :: h
real(8), intent (in) :: d
real(8), intent (in) :: d_1
real(8), intent (in) :: m
real(8) :: t_0
t_0 = (c0 * (d_1 * d_1)) / ((w * h) * (d * d))
code = (c0 / (2.0d0 * w)) * (t_0 + sqrt(((t_0 * t_0) - (m * m))))
end function
public static double code(double c0, double w, double h, double D, double d, double M) {
double t_0 = (c0 * (d * d)) / ((w * h) * (D * D));
return (c0 / (2.0 * w)) * (t_0 + Math.sqrt(((t_0 * t_0) - (M * M))));
}
def code(c0, w, h, D, d, M): t_0 = (c0 * (d * d)) / ((w * h) * (D * D)) return (c0 / (2.0 * w)) * (t_0 + math.sqrt(((t_0 * t_0) - (M * M))))
function code(c0, w, h, D, d, M) t_0 = Float64(Float64(c0 * Float64(d * d)) / Float64(Float64(w * h) * Float64(D * D))) return Float64(Float64(c0 / Float64(2.0 * w)) * Float64(t_0 + sqrt(Float64(Float64(t_0 * t_0) - Float64(M * M))))) end
function tmp = code(c0, w, h, D, d, M) t_0 = (c0 * (d * d)) / ((w * h) * (D * D)); tmp = (c0 / (2.0 * w)) * (t_0 + sqrt(((t_0 * t_0) - (M * M)))); end
code[c0_, w_, h_, D_, d_, M_] := Block[{t$95$0 = N[(N[(c0 * N[(d * d), $MachinePrecision]), $MachinePrecision] / N[(N[(w * h), $MachinePrecision] * N[(D * D), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(N[(c0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision] * N[(t$95$0 + N[Sqrt[N[(N[(t$95$0 * t$95$0), $MachinePrecision] - N[(M * M), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}\\
\frac{c0}{2 \cdot w} \cdot \left(t_0 + \sqrt{t_0 \cdot t_0 - M \cdot M}\right)
\end{array}
\end{array}
NOTE: M should be positive before calling this function
(FPCore (c0 w h D d M)
:precision binary64
(let* ((t_0 (/ c0 (* 2.0 w))))
(if (<= M 2.7e-156)
(* t_0 0.0)
(* t_0 (* 2.0 (* (/ c0 (* w h)) (pow (/ d D) 2.0)))))))M = abs(M);
double code(double c0, double w, double h, double D, double d, double M) {
double t_0 = c0 / (2.0 * w);
double tmp;
if (M <= 2.7e-156) {
tmp = t_0 * 0.0;
} else {
tmp = t_0 * (2.0 * ((c0 / (w * h)) * pow((d / D), 2.0)));
}
return tmp;
}
NOTE: M should be positive before calling this function
real(8) function code(c0, w, h, d, d_1, m)
real(8), intent (in) :: c0
real(8), intent (in) :: w
real(8), intent (in) :: h
real(8), intent (in) :: d
real(8), intent (in) :: d_1
real(8), intent (in) :: m
real(8) :: t_0
real(8) :: tmp
t_0 = c0 / (2.0d0 * w)
if (m <= 2.7d-156) then
tmp = t_0 * 0.0d0
else
tmp = t_0 * (2.0d0 * ((c0 / (w * h)) * ((d_1 / d) ** 2.0d0)))
end if
code = tmp
end function
M = Math.abs(M);
public static double code(double c0, double w, double h, double D, double d, double M) {
double t_0 = c0 / (2.0 * w);
double tmp;
if (M <= 2.7e-156) {
tmp = t_0 * 0.0;
} else {
tmp = t_0 * (2.0 * ((c0 / (w * h)) * Math.pow((d / D), 2.0)));
}
return tmp;
}
M = abs(M) def code(c0, w, h, D, d, M): t_0 = c0 / (2.0 * w) tmp = 0 if M <= 2.7e-156: tmp = t_0 * 0.0 else: tmp = t_0 * (2.0 * ((c0 / (w * h)) * math.pow((d / D), 2.0))) return tmp
M = abs(M) function code(c0, w, h, D, d, M) t_0 = Float64(c0 / Float64(2.0 * w)) tmp = 0.0 if (M <= 2.7e-156) tmp = Float64(t_0 * 0.0); else tmp = Float64(t_0 * Float64(2.0 * Float64(Float64(c0 / Float64(w * h)) * (Float64(d / D) ^ 2.0)))); end return tmp end
M = abs(M) function tmp_2 = code(c0, w, h, D, d, M) t_0 = c0 / (2.0 * w); tmp = 0.0; if (M <= 2.7e-156) tmp = t_0 * 0.0; else tmp = t_0 * (2.0 * ((c0 / (w * h)) * ((d / D) ^ 2.0))); end tmp_2 = tmp; end
NOTE: M should be positive before calling this function
code[c0_, w_, h_, D_, d_, M_] := Block[{t$95$0 = N[(c0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[M, 2.7e-156], N[(t$95$0 * 0.0), $MachinePrecision], N[(t$95$0 * N[(2.0 * N[(N[(c0 / N[(w * h), $MachinePrecision]), $MachinePrecision] * N[Power[N[(d / D), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
M = |M|\\
\\
\begin{array}{l}
t_0 := \frac{c0}{2 \cdot w}\\
\mathbf{if}\;M \leq 2.7 \cdot 10^{-156}:\\
\;\;\;\;t_0 \cdot 0\\
\mathbf{else}:\\
\;\;\;\;t_0 \cdot \left(2 \cdot \left(\frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2}\right)\right)\\
\end{array}
\end{array}
if M < 2.70000000000000012e-156Initial program 22.3%
Simplified23.0%
Taylor expanded in c0 around -inf 4.9%
mul-1-neg4.9%
distribute-rgt-in4.2%
Simplified35.2%
if 2.70000000000000012e-156 < M Initial program 17.2%
Simplified18.4%
Taylor expanded in c0 around inf 28.6%
associate-*r/28.6%
associate-*r*29.7%
*-commutative29.7%
unpow229.7%
*-commutative29.7%
associate-*r/29.7%
times-frac30.9%
unpow230.9%
*-commutative30.9%
associate-/r*30.1%
unpow230.1%
associate-/r*36.3%
unpow236.3%
associate-*l/43.0%
associate-*r/44.0%
unpow244.0%
times-frac40.9%
Simplified42.9%
Final simplification38.2%
NOTE: M should be positive before calling this function
(FPCore (c0 w h D d M)
:precision binary64
(let* ((t_0 (/ c0 (* 2.0 w))))
(if (or (<= M 1.26e-102) (and (not (<= M 2.15e-10)) (<= M 1.4e+24)))
(* t_0 0.0)
(* t_0 (* 2.0 (* (/ (/ c0 (* D D)) (* w h)) (* d d)))))))M = abs(M);
double code(double c0, double w, double h, double D, double d, double M) {
double t_0 = c0 / (2.0 * w);
double tmp;
if ((M <= 1.26e-102) || (!(M <= 2.15e-10) && (M <= 1.4e+24))) {
tmp = t_0 * 0.0;
} else {
tmp = t_0 * (2.0 * (((c0 / (D * D)) / (w * h)) * (d * d)));
}
return tmp;
}
NOTE: M should be positive before calling this function
real(8) function code(c0, w, h, d, d_1, m)
real(8), intent (in) :: c0
real(8), intent (in) :: w
real(8), intent (in) :: h
real(8), intent (in) :: d
real(8), intent (in) :: d_1
real(8), intent (in) :: m
real(8) :: t_0
real(8) :: tmp
t_0 = c0 / (2.0d0 * w)
if ((m <= 1.26d-102) .or. (.not. (m <= 2.15d-10)) .and. (m <= 1.4d+24)) then
tmp = t_0 * 0.0d0
else
tmp = t_0 * (2.0d0 * (((c0 / (d * d)) / (w * h)) * (d_1 * d_1)))
end if
code = tmp
end function
M = Math.abs(M);
public static double code(double c0, double w, double h, double D, double d, double M) {
double t_0 = c0 / (2.0 * w);
double tmp;
if ((M <= 1.26e-102) || (!(M <= 2.15e-10) && (M <= 1.4e+24))) {
tmp = t_0 * 0.0;
} else {
tmp = t_0 * (2.0 * (((c0 / (D * D)) / (w * h)) * (d * d)));
}
return tmp;
}
M = abs(M) def code(c0, w, h, D, d, M): t_0 = c0 / (2.0 * w) tmp = 0 if (M <= 1.26e-102) or (not (M <= 2.15e-10) and (M <= 1.4e+24)): tmp = t_0 * 0.0 else: tmp = t_0 * (2.0 * (((c0 / (D * D)) / (w * h)) * (d * d))) return tmp
M = abs(M) function code(c0, w, h, D, d, M) t_0 = Float64(c0 / Float64(2.0 * w)) tmp = 0.0 if ((M <= 1.26e-102) || (!(M <= 2.15e-10) && (M <= 1.4e+24))) tmp = Float64(t_0 * 0.0); else tmp = Float64(t_0 * Float64(2.0 * Float64(Float64(Float64(c0 / Float64(D * D)) / Float64(w * h)) * Float64(d * d)))); end return tmp end
M = abs(M) function tmp_2 = code(c0, w, h, D, d, M) t_0 = c0 / (2.0 * w); tmp = 0.0; if ((M <= 1.26e-102) || (~((M <= 2.15e-10)) && (M <= 1.4e+24))) tmp = t_0 * 0.0; else tmp = t_0 * (2.0 * (((c0 / (D * D)) / (w * h)) * (d * d))); end tmp_2 = tmp; end
NOTE: M should be positive before calling this function
code[c0_, w_, h_, D_, d_, M_] := Block[{t$95$0 = N[(c0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[M, 1.26e-102], And[N[Not[LessEqual[M, 2.15e-10]], $MachinePrecision], LessEqual[M, 1.4e+24]]], N[(t$95$0 * 0.0), $MachinePrecision], N[(t$95$0 * N[(2.0 * N[(N[(N[(c0 / N[(D * D), $MachinePrecision]), $MachinePrecision] / N[(w * h), $MachinePrecision]), $MachinePrecision] * N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
M = |M|\\
\\
\begin{array}{l}
t_0 := \frac{c0}{2 \cdot w}\\
\mathbf{if}\;M \leq 1.26 \cdot 10^{-102} \lor \neg \left(M \leq 2.15 \cdot 10^{-10}\right) \land M \leq 1.4 \cdot 10^{+24}:\\
\;\;\;\;t_0 \cdot 0\\
\mathbf{else}:\\
\;\;\;\;t_0 \cdot \left(2 \cdot \left(\frac{\frac{c0}{D \cdot D}}{w \cdot h} \cdot \left(d \cdot d\right)\right)\right)\\
\end{array}
\end{array}
if M < 1.2600000000000001e-102 or 2.15000000000000007e-10 < M < 1.4000000000000001e24Initial program 20.1%
Simplified20.7%
Taylor expanded in c0 around -inf 4.6%
mul-1-neg4.6%
distribute-rgt-in3.5%
Simplified33.2%
if 1.2600000000000001e-102 < M < 2.15000000000000007e-10 or 1.4000000000000001e24 < M Initial program 20.8%
Simplified22.4%
Taylor expanded in c0 around inf 37.1%
associate-*r/37.1%
associate-*r*37.2%
*-commutative37.2%
unpow237.2%
*-commutative37.2%
associate-*r/37.2%
associate-*l/37.1%
*-commutative37.1%
unpow237.1%
*-commutative37.1%
associate-*r*37.0%
associate-/r*35.6%
unpow235.6%
unpow235.6%
Simplified35.6%
Final simplification33.8%
NOTE: M should be positive before calling this function (FPCore (c0 w h D d M) :precision binary64 (* (/ c0 (* 2.0 w)) 0.0))
M = abs(M);
double code(double c0, double w, double h, double D, double d, double M) {
return (c0 / (2.0 * w)) * 0.0;
}
NOTE: M should be positive before calling this function
real(8) function code(c0, w, h, d, d_1, m)
real(8), intent (in) :: c0
real(8), intent (in) :: w
real(8), intent (in) :: h
real(8), intent (in) :: d
real(8), intent (in) :: d_1
real(8), intent (in) :: m
code = (c0 / (2.0d0 * w)) * 0.0d0
end function
M = Math.abs(M);
public static double code(double c0, double w, double h, double D, double d, double M) {
return (c0 / (2.0 * w)) * 0.0;
}
M = abs(M) def code(c0, w, h, D, d, M): return (c0 / (2.0 * w)) * 0.0
M = abs(M) function code(c0, w, h, D, d, M) return Float64(Float64(c0 / Float64(2.0 * w)) * 0.0) end
M = abs(M) function tmp = code(c0, w, h, D, d, M) tmp = (c0 / (2.0 * w)) * 0.0; end
NOTE: M should be positive before calling this function code[c0_, w_, h_, D_, d_, M_] := N[(N[(c0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision] * 0.0), $MachinePrecision]
\begin{array}{l}
M = |M|\\
\\
\frac{c0}{2 \cdot w} \cdot 0
\end{array}
Initial program 20.3%
Simplified21.2%
Taylor expanded in c0 around -inf 3.4%
mul-1-neg3.4%
distribute-rgt-in2.6%
Simplified28.1%
Final simplification28.1%
herbie shell --seed 2023285
(FPCore (c0 w h D d M)
:name "Henrywood and Agarwal, Equation (13)"
:precision binary64
(* (/ c0 (* 2.0 w)) (+ (/ (* c0 (* d d)) (* (* w h) (* D D))) (sqrt (- (* (/ (* c0 (* d d)) (* (* w h) (* D D))) (/ (* c0 (* d d)) (* (* w h) (* D D)))) (* M M))))))