
(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 (* 2.0 w))) (t_1 (/ (* c0 (* d d)) (* (* w h) (* D D)))))
(if (<= (* t_0 (+ t_1 (sqrt (- (* t_1 t_1) (* M M))))) INFINITY)
(* t_0 (* 2.0 (/ d (/ (/ (* D D) (/ (/ c0 w) h)) d))))
0.0)))
double code(double c0, double w, double h, double D, double d, double M) {
double t_0 = c0 / (2.0 * w);
double t_1 = (c0 * (d * d)) / ((w * h) * (D * D));
double tmp;
if ((t_0 * (t_1 + sqrt(((t_1 * t_1) - (M * M))))) <= ((double) INFINITY)) {
tmp = t_0 * (2.0 * (d / (((D * D) / ((c0 / w) / h)) / d)));
} else {
tmp = 0.0;
}
return tmp;
}
public static double code(double c0, double w, double h, double D, double d, double M) {
double t_0 = c0 / (2.0 * w);
double t_1 = (c0 * (d * d)) / ((w * h) * (D * D));
double tmp;
if ((t_0 * (t_1 + Math.sqrt(((t_1 * t_1) - (M * M))))) <= Double.POSITIVE_INFINITY) {
tmp = t_0 * (2.0 * (d / (((D * D) / ((c0 / w) / h)) / d)));
} else {
tmp = 0.0;
}
return tmp;
}
def code(c0, w, h, D, d, M): t_0 = c0 / (2.0 * w) t_1 = (c0 * (d * d)) / ((w * h) * (D * D)) tmp = 0 if (t_0 * (t_1 + math.sqrt(((t_1 * t_1) - (M * M))))) <= math.inf: tmp = t_0 * (2.0 * (d / (((D * D) / ((c0 / w) / h)) / d))) else: tmp = 0.0 return tmp
function code(c0, w, h, D, d, M) t_0 = Float64(c0 / Float64(2.0 * w)) t_1 = Float64(Float64(c0 * Float64(d * d)) / Float64(Float64(w * h) * Float64(D * D))) tmp = 0.0 if (Float64(t_0 * Float64(t_1 + sqrt(Float64(Float64(t_1 * t_1) - Float64(M * M))))) <= Inf) tmp = Float64(t_0 * Float64(2.0 * Float64(d / Float64(Float64(Float64(D * D) / Float64(Float64(c0 / w) / h)) / d)))); else tmp = 0.0; end return tmp end
function tmp_2 = code(c0, w, h, D, d, M) t_0 = c0 / (2.0 * w); t_1 = (c0 * (d * d)) / ((w * h) * (D * D)); tmp = 0.0; if ((t_0 * (t_1 + sqrt(((t_1 * t_1) - (M * M))))) <= Inf) tmp = t_0 * (2.0 * (d / (((D * D) / ((c0 / w) / h)) / d))); else tmp = 0.0; end tmp_2 = tmp; end
code[c0_, w_, h_, D_, d_, M_] := Block[{t$95$0 = N[(c0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(c0 * N[(d * d), $MachinePrecision]), $MachinePrecision] / N[(N[(w * h), $MachinePrecision] * N[(D * D), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(t$95$0 * N[(t$95$1 + N[Sqrt[N[(N[(t$95$1 * t$95$1), $MachinePrecision] - N[(M * M), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], Infinity], N[(t$95$0 * N[(2.0 * N[(d / N[(N[(N[(D * D), $MachinePrecision] / N[(N[(c0 / w), $MachinePrecision] / h), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{c0}{2 \cdot w}\\
t_1 := \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}\\
\mathbf{if}\;t_0 \cdot \left(t_1 + \sqrt{t_1 \cdot t_1 - M \cdot M}\right) \leq \infty:\\
\;\;\;\;t_0 \cdot \left(2 \cdot \frac{d}{\frac{\frac{D \cdot D}{\frac{\frac{c0}{w}}{h}}}{d}}\right)\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if (*.f64 (/.f64 c0 (*.f64 2 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 72.7%
times-frac68.0%
fma-def65.7%
associate-/r*65.9%
difference-of-squares65.9%
Simplified67.7%
fma-udef71.1%
associate-/l/70.2%
frac-times70.0%
pow270.0%
fma-udef70.0%
associate-/l/69.1%
times-frac68.2%
associate-/l/68.2%
times-frac67.1%
Applied egg-rr71.1%
fma-def67.7%
associate-*l/67.7%
times-frac65.3%
Simplified65.3%
Taylor expanded in c0 around inf 71.3%
times-frac69.9%
associate-/r/73.3%
unpow273.3%
unpow273.3%
associate-/l*75.6%
associate-/r*77.7%
Simplified77.7%
if +inf.0 < (*.f64 (/.f64 c0 (*.f64 2 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%
times-frac0.0%
fma-def0.0%
associate-/r*0.0%
difference-of-squares12.5%
Simplified17.5%
Taylor expanded in c0 around -inf 1.4%
associate-*r*1.4%
distribute-rgt1-in1.4%
metadata-eval1.4%
mul0-lft40.3%
metadata-eval40.3%
mul0-lft1.4%
metadata-eval1.4%
distribute-lft1-in1.4%
*-commutative1.4%
distribute-lft1-in1.4%
metadata-eval1.4%
mul0-lft40.3%
Simplified40.3%
Taylor expanded in c0 around 0 43.5%
Final simplification55.2%
(FPCore (c0 w h D d M)
:precision binary64
(if (<= (* D D) 3.3e-292)
0.0
(if (<= (* D D) 4.3e+225)
(* (/ c0 (* 2.0 w)) (/ d (/ (/ (* D D) (/ (/ c0 w) h)) d)))
0.0)))
double code(double c0, double w, double h, double D, double d, double M) {
double tmp;
if ((D * D) <= 3.3e-292) {
tmp = 0.0;
} else if ((D * D) <= 4.3e+225) {
tmp = (c0 / (2.0 * w)) * (d / (((D * D) / ((c0 / w) / h)) / d));
} else {
tmp = 0.0;
}
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) :: tmp
if ((d * d) <= 3.3d-292) then
tmp = 0.0d0
else if ((d * d) <= 4.3d+225) then
tmp = (c0 / (2.0d0 * w)) * (d_1 / (((d * d) / ((c0 / w) / h)) / d_1))
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double c0, double w, double h, double D, double d, double M) {
double tmp;
if ((D * D) <= 3.3e-292) {
tmp = 0.0;
} else if ((D * D) <= 4.3e+225) {
tmp = (c0 / (2.0 * w)) * (d / (((D * D) / ((c0 / w) / h)) / d));
} else {
tmp = 0.0;
}
return tmp;
}
def code(c0, w, h, D, d, M): tmp = 0 if (D * D) <= 3.3e-292: tmp = 0.0 elif (D * D) <= 4.3e+225: tmp = (c0 / (2.0 * w)) * (d / (((D * D) / ((c0 / w) / h)) / d)) else: tmp = 0.0 return tmp
function code(c0, w, h, D, d, M) tmp = 0.0 if (Float64(D * D) <= 3.3e-292) tmp = 0.0; elseif (Float64(D * D) <= 4.3e+225) tmp = Float64(Float64(c0 / Float64(2.0 * w)) * Float64(d / Float64(Float64(Float64(D * D) / Float64(Float64(c0 / w) / h)) / d))); else tmp = 0.0; end return tmp end
function tmp_2 = code(c0, w, h, D, d, M) tmp = 0.0; if ((D * D) <= 3.3e-292) tmp = 0.0; elseif ((D * D) <= 4.3e+225) tmp = (c0 / (2.0 * w)) * (d / (((D * D) / ((c0 / w) / h)) / d)); else tmp = 0.0; end tmp_2 = tmp; end
code[c0_, w_, h_, D_, d_, M_] := If[LessEqual[N[(D * D), $MachinePrecision], 3.3e-292], 0.0, If[LessEqual[N[(D * D), $MachinePrecision], 4.3e+225], N[(N[(c0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision] * N[(d / N[(N[(N[(D * D), $MachinePrecision] / N[(N[(c0 / w), $MachinePrecision] / h), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;D \cdot D \leq 3.3 \cdot 10^{-292}:\\
\;\;\;\;0\\
\mathbf{elif}\;D \cdot D \leq 4.3 \cdot 10^{+225}:\\
\;\;\;\;\frac{c0}{2 \cdot w} \cdot \frac{d}{\frac{\frac{D \cdot D}{\frac{\frac{c0}{w}}{h}}}{d}}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if (*.f64 D D) < 3.29999999999999995e-292 or 4.3000000000000001e225 < (*.f64 D D) Initial program 15.1%
times-frac15.1%
fma-def15.1%
associate-/r*15.2%
difference-of-squares23.0%
Simplified28.1%
Taylor expanded in c0 around -inf 1.0%
associate-*r*1.0%
distribute-rgt1-in1.0%
metadata-eval1.0%
mul0-lft36.8%
metadata-eval36.8%
mul0-lft1.0%
metadata-eval1.0%
distribute-lft1-in1.0%
*-commutative1.0%
distribute-lft1-in1.0%
metadata-eval1.0%
mul0-lft36.8%
Simplified36.8%
Taylor expanded in c0 around 0 40.4%
if 3.29999999999999995e-292 < (*.f64 D D) < 4.3000000000000001e225Initial program 36.5%
times-frac33.0%
fma-def31.3%
associate-/r*31.3%
difference-of-squares40.0%
Simplified42.5%
Taylor expanded in c0 around 0 27.0%
Taylor expanded in c0 around inf 41.3%
times-frac40.7%
associate-/r/42.7%
unpow242.7%
unpow242.7%
associate-/l*47.6%
associate-/r*47.9%
Simplified47.9%
Final simplification43.8%
(FPCore (c0 w h D d M) :precision binary64 0.0)
double code(double c0, double w, double h, double D, double d, double M) {
return 0.0;
}
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
end function
public static double code(double c0, double w, double h, double D, double d, double M) {
return 0.0;
}
def code(c0, w, h, D, d, M): return 0.0
function code(c0, w, h, D, d, M) return 0.0 end
function tmp = code(c0, w, h, D, d, M) tmp = 0.0; end
code[c0_, w_, h_, D_, d_, M_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 24.7%
times-frac23.1%
fma-def22.4%
associate-/r*22.4%
difference-of-squares30.6%
Simplified34.5%
Taylor expanded in c0 around -inf 2.5%
associate-*r*2.5%
distribute-rgt1-in2.5%
metadata-eval2.5%
mul0-lft29.3%
metadata-eval29.3%
mul0-lft2.8%
metadata-eval2.8%
distribute-lft1-in2.8%
*-commutative2.8%
distribute-lft1-in2.8%
metadata-eval2.8%
mul0-lft29.3%
Simplified29.3%
Taylor expanded in c0 around 0 31.5%
Final simplification31.5%
herbie shell --seed 2023207
(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))))))