
(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}
(FPCore (c0 w h D d M)
:precision binary64
(let* ((t_0 (/ (* c0 (* d d)) (* (* w h) (* D D))))
(t_1 (* (/ c0 (* 2.0 w)) (+ t_0 (sqrt (- (* t_0 t_0) (* M M)))))))
(if (<= t_1 INFINITY) t_1 (/ 0.0 w))))
double code(double c0, double w, double h, double D, double d, double M) {
double t_0 = (c0 * (d * d)) / ((w * h) * (D * D));
double t_1 = (c0 / (2.0 * w)) * (t_0 + sqrt(((t_0 * t_0) - (M * M))));
double tmp;
if (t_1 <= ((double) INFINITY)) {
tmp = t_1;
} else {
tmp = 0.0 / w;
}
return tmp;
}
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));
double t_1 = (c0 / (2.0 * w)) * (t_0 + Math.sqrt(((t_0 * t_0) - (M * M))));
double tmp;
if (t_1 <= Double.POSITIVE_INFINITY) {
tmp = t_1;
} else {
tmp = 0.0 / w;
}
return tmp;
}
def code(c0, w, h, D, d, M): t_0 = (c0 * (d * d)) / ((w * h) * (D * D)) t_1 = (c0 / (2.0 * w)) * (t_0 + math.sqrt(((t_0 * t_0) - (M * M)))) tmp = 0 if t_1 <= math.inf: tmp = t_1 else: tmp = 0.0 / w return tmp
function code(c0, w, h, D, d, M) t_0 = Float64(Float64(c0 * Float64(d * d)) / Float64(Float64(w * h) * Float64(D * D))) t_1 = Float64(Float64(c0 / Float64(2.0 * w)) * Float64(t_0 + sqrt(Float64(Float64(t_0 * t_0) - Float64(M * M))))) tmp = 0.0 if (t_1 <= Inf) tmp = t_1; else tmp = Float64(0.0 / w); end return tmp end
function tmp_2 = code(c0, w, h, D, d, M) t_0 = (c0 * (d * d)) / ((w * h) * (D * D)); t_1 = (c0 / (2.0 * w)) * (t_0 + sqrt(((t_0 * t_0) - (M * M)))); tmp = 0.0; if (t_1 <= Inf) tmp = t_1; else tmp = 0.0 / w; end tmp_2 = tmp; 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]}, Block[{t$95$1 = 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]}, If[LessEqual[t$95$1, Infinity], t$95$1, N[(0.0 / w), $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)}\\
t_1 := \frac{c0}{2 \cdot w} \cdot \left(t\_0 + \sqrt{t\_0 \cdot t\_0 - M \cdot M}\right)\\
\mathbf{if}\;t\_1 \leq \infty:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;\frac{0}{w}\\
\end{array}
\end{array}
if (*.f64 (/.f64 c0 (*.f64 #s(literal 2 binary64) w)) (+.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (sqrt.f64 (-.f64 (*.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D)))) (*.f64 M M))))) < +inf.0Initial program 73.0%
if +inf.0 < (*.f64 (/.f64 c0 (*.f64 #s(literal 2 binary64) w)) (+.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (sqrt.f64 (-.f64 (*.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D)))) (*.f64 M M))))) Initial program 0.0%
Simplified22.8%
fma-undefine22.8%
associate-*r/17.5%
*-commutative17.5%
associate-*r*15.3%
associate-*r*12.6%
associate-/l*10.7%
frac-times11.3%
Applied egg-rr9.3%
*-lft-identity9.3%
Simplified9.3%
pow29.3%
frac-times2.5%
pow22.5%
pow22.5%
cancel-sign-sub-inv2.5%
pow22.5%
frac-times9.3%
pow29.3%
unpow-prod-down7.7%
pow-pow7.7%
metadata-eval7.7%
Applied egg-rr7.7%
Taylor expanded in c0 around -inf 0.1%
associate-*r/0.1%
distribute-lft1-in0.1%
metadata-eval0.1%
mul0-lft35.4%
mul0-rgt47.4%
metadata-eval47.4%
Simplified47.4%
(FPCore (c0 w h D d M)
:precision binary64
(let* ((t_0 (/ c0 (* w h))) (t_1 (* t_0 (/ (* d d) (* D D)))))
(if (or (<= (* D D) 1e+47) (not (<= (* D D) 5e+287)))
(/ 0.0 w)
(*
(/ c0 (* 2.0 w))
(+ (* t_0 (* (/ d D) (/ d D))) (sqrt (- (* t_1 t_1) (* M M))))))))
double code(double c0, double w, double h, double D, double d, double M) {
double t_0 = c0 / (w * h);
double t_1 = t_0 * ((d * d) / (D * D));
double tmp;
if (((D * D) <= 1e+47) || !((D * D) <= 5e+287)) {
tmp = 0.0 / w;
} else {
tmp = (c0 / (2.0 * w)) * ((t_0 * ((d / D) * (d / D))) + sqrt(((t_1 * t_1) - (M * M))));
}
return tmp;
}
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) :: t_1
real(8) :: tmp
t_0 = c0 / (w * h)
t_1 = t_0 * ((d_1 * d_1) / (d * d))
if (((d * d) <= 1d+47) .or. (.not. ((d * d) <= 5d+287))) then
tmp = 0.0d0 / w
else
tmp = (c0 / (2.0d0 * w)) * ((t_0 * ((d_1 / d) * (d_1 / d))) + sqrt(((t_1 * t_1) - (m * m))))
end if
code = tmp
end function
public static double code(double c0, double w, double h, double D, double d, double M) {
double t_0 = c0 / (w * h);
double t_1 = t_0 * ((d * d) / (D * D));
double tmp;
if (((D * D) <= 1e+47) || !((D * D) <= 5e+287)) {
tmp = 0.0 / w;
} else {
tmp = (c0 / (2.0 * w)) * ((t_0 * ((d / D) * (d / D))) + Math.sqrt(((t_1 * t_1) - (M * M))));
}
return tmp;
}
def code(c0, w, h, D, d, M): t_0 = c0 / (w * h) t_1 = t_0 * ((d * d) / (D * D)) tmp = 0 if ((D * D) <= 1e+47) or not ((D * D) <= 5e+287): tmp = 0.0 / w else: tmp = (c0 / (2.0 * w)) * ((t_0 * ((d / D) * (d / D))) + math.sqrt(((t_1 * t_1) - (M * M)))) return tmp
function code(c0, w, h, D, d, M) t_0 = Float64(c0 / Float64(w * h)) t_1 = Float64(t_0 * Float64(Float64(d * d) / Float64(D * D))) tmp = 0.0 if ((Float64(D * D) <= 1e+47) || !(Float64(D * D) <= 5e+287)) tmp = Float64(0.0 / w); else tmp = Float64(Float64(c0 / Float64(2.0 * w)) * Float64(Float64(t_0 * Float64(Float64(d / D) * Float64(d / D))) + sqrt(Float64(Float64(t_1 * t_1) - Float64(M * M))))); end return tmp end
function tmp_2 = code(c0, w, h, D, d, M) t_0 = c0 / (w * h); t_1 = t_0 * ((d * d) / (D * D)); tmp = 0.0; if (((D * D) <= 1e+47) || ~(((D * D) <= 5e+287))) tmp = 0.0 / w; else tmp = (c0 / (2.0 * w)) * ((t_0 * ((d / D) * (d / D))) + sqrt(((t_1 * t_1) - (M * M)))); end tmp_2 = tmp; end
code[c0_, w_, h_, D_, d_, M_] := Block[{t$95$0 = N[(c0 / N[(w * h), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 * N[(N[(d * d), $MachinePrecision] / N[(D * D), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[N[(D * D), $MachinePrecision], 1e+47], N[Not[LessEqual[N[(D * D), $MachinePrecision], 5e+287]], $MachinePrecision]], N[(0.0 / w), $MachinePrecision], N[(N[(c0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision] * N[(N[(t$95$0 * N[(N[(d / D), $MachinePrecision] * N[(d / D), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[Sqrt[N[(N[(t$95$1 * t$95$1), $MachinePrecision] - N[(M * M), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{c0}{w \cdot h}\\
t_1 := t\_0 \cdot \frac{d \cdot d}{D \cdot D}\\
\mathbf{if}\;D \cdot D \leq 10^{+47} \lor \neg \left(D \cdot D \leq 5 \cdot 10^{+287}\right):\\
\;\;\;\;\frac{0}{w}\\
\mathbf{else}:\\
\;\;\;\;\frac{c0}{2 \cdot w} \cdot \left(t\_0 \cdot \left(\frac{d}{D} \cdot \frac{d}{D}\right) + \sqrt{t\_1 \cdot t\_1 - M \cdot M}\right)\\
\end{array}
\end{array}
if (*.f64 D D) < 1e47 or 5e287 < (*.f64 D D) Initial program 21.1%
Simplified36.0%
fma-undefine36.0%
associate-*r/31.9%
*-commutative31.9%
associate-*r*30.2%
associate-*r*27.7%
associate-/l*26.3%
frac-times25.5%
Applied egg-rr25.7%
*-lft-identity25.7%
Simplified25.7%
pow225.7%
frac-times20.1%
pow220.1%
pow220.1%
cancel-sign-sub-inv20.1%
pow220.1%
frac-times25.7%
pow225.7%
unpow-prod-down23.6%
pow-pow23.6%
metadata-eval23.6%
Applied egg-rr23.6%
Taylor expanded in c0 around -inf 3.1%
associate-*r/3.1%
distribute-lft1-in3.1%
metadata-eval3.1%
mul0-lft30.5%
mul0-rgt40.2%
metadata-eval40.2%
Simplified40.2%
if 1e47 < (*.f64 D D) < 5e287Initial program 42.3%
Simplified45.2%
times-frac45.3%
Applied egg-rr45.3%
Final simplification40.8%
(FPCore (c0 w h D d M) :precision binary64 (/ 0.0 w))
double code(double c0, double w, double h, double D, double d, double M) {
return 0.0 / w;
}
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 = 0.0d0 / w
end function
public static double code(double c0, double w, double h, double D, double d, double M) {
return 0.0 / w;
}
def code(c0, w, h, D, d, M): return 0.0 / w
function code(c0, w, h, D, d, M) return Float64(0.0 / w) end
function tmp = code(c0, w, h, D, d, M) tmp = 0.0 / w; end
code[c0_, w_, h_, D_, d_, M_] := N[(0.0 / w), $MachinePrecision]
\begin{array}{l}
\\
\frac{0}{w}
\end{array}
Initial program 23.7%
Simplified38.4%
fma-undefine38.4%
associate-*r/34.4%
*-commutative34.4%
associate-*r*33.3%
associate-*r*31.1%
associate-/l*29.4%
frac-times29.1%
Applied egg-rr28.1%
*-lft-identity28.1%
Simplified28.1%
pow228.1%
frac-times23.2%
pow223.2%
pow223.2%
cancel-sign-sub-inv23.2%
pow223.2%
frac-times28.1%
pow228.1%
unpow-prod-down25.1%
pow-pow25.1%
metadata-eval25.1%
Applied egg-rr25.1%
Taylor expanded in c0 around -inf 2.8%
associate-*r/2.8%
distribute-lft1-in2.8%
metadata-eval2.8%
mul0-lft27.3%
mul0-rgt36.9%
metadata-eval36.9%
Simplified36.9%
herbie shell --seed 2024085
(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))))))