
(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
(if (or (<= c0 -1.4e+265)
(not
(or (<= c0 -1.35e+193)
(and (not (<= c0 -6.4e-169)) (<= c0 3.1e+37)))))
(* c0 (* (pow (/ d D) 2.0) (/ (/ (/ c0 w) h) w)))
(* c0 (/ 0.0 (* 2.0 w)))))
double code(double c0, double w, double h, double D, double d, double M) {
double tmp;
if ((c0 <= -1.4e+265) || !((c0 <= -1.35e+193) || (!(c0 <= -6.4e-169) && (c0 <= 3.1e+37)))) {
tmp = c0 * (pow((d / D), 2.0) * (((c0 / w) / h) / w));
} else {
tmp = c0 * (0.0 / (2.0 * w));
}
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 ((c0 <= (-1.4d+265)) .or. (.not. (c0 <= (-1.35d+193)) .or. (.not. (c0 <= (-6.4d-169))) .and. (c0 <= 3.1d+37))) then
tmp = c0 * (((d_1 / d) ** 2.0d0) * (((c0 / w) / h) / w))
else
tmp = c0 * (0.0d0 / (2.0d0 * w))
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 ((c0 <= -1.4e+265) || !((c0 <= -1.35e+193) || (!(c0 <= -6.4e-169) && (c0 <= 3.1e+37)))) {
tmp = c0 * (Math.pow((d / D), 2.0) * (((c0 / w) / h) / w));
} else {
tmp = c0 * (0.0 / (2.0 * w));
}
return tmp;
}
def code(c0, w, h, D, d, M): tmp = 0 if (c0 <= -1.4e+265) or not ((c0 <= -1.35e+193) or (not (c0 <= -6.4e-169) and (c0 <= 3.1e+37))): tmp = c0 * (math.pow((d / D), 2.0) * (((c0 / w) / h) / w)) else: tmp = c0 * (0.0 / (2.0 * w)) return tmp
function code(c0, w, h, D, d, M) tmp = 0.0 if ((c0 <= -1.4e+265) || !((c0 <= -1.35e+193) || (!(c0 <= -6.4e-169) && (c0 <= 3.1e+37)))) tmp = Float64(c0 * Float64((Float64(d / D) ^ 2.0) * Float64(Float64(Float64(c0 / w) / h) / w))); else tmp = Float64(c0 * Float64(0.0 / Float64(2.0 * w))); end return tmp end
function tmp_2 = code(c0, w, h, D, d, M) tmp = 0.0; if ((c0 <= -1.4e+265) || ~(((c0 <= -1.35e+193) || (~((c0 <= -6.4e-169)) && (c0 <= 3.1e+37))))) tmp = c0 * (((d / D) ^ 2.0) * (((c0 / w) / h) / w)); else tmp = c0 * (0.0 / (2.0 * w)); end tmp_2 = tmp; end
code[c0_, w_, h_, D_, d_, M_] := If[Or[LessEqual[c0, -1.4e+265], N[Not[Or[LessEqual[c0, -1.35e+193], And[N[Not[LessEqual[c0, -6.4e-169]], $MachinePrecision], LessEqual[c0, 3.1e+37]]]], $MachinePrecision]], N[(c0 * N[(N[Power[N[(d / D), $MachinePrecision], 2.0], $MachinePrecision] * N[(N[(N[(c0 / w), $MachinePrecision] / h), $MachinePrecision] / w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(c0 * N[(0.0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c0 \leq -1.4 \cdot 10^{+265} \lor \neg \left(c0 \leq -1.35 \cdot 10^{+193} \lor \neg \left(c0 \leq -6.4 \cdot 10^{-169}\right) \land c0 \leq 3.1 \cdot 10^{+37}\right):\\
\;\;\;\;c0 \cdot \left({\left(\frac{d}{D}\right)}^{2} \cdot \frac{\frac{\frac{c0}{w}}{h}}{w}\right)\\
\mathbf{else}:\\
\;\;\;\;c0 \cdot \frac{0}{2 \cdot w}\\
\end{array}
\end{array}
if c0 < -1.39999999999999995e265 or -1.35e193 < c0 < -6.39999999999999989e-169 or 3.1000000000000002e37 < c0 Initial program 29.0%
Simplified47.0%
Taylor expanded in c0 around -inf 4.7%
mul-1-neg4.7%
associate-/l*5.6%
distribute-rgt-neg-in5.6%
*-commutative5.6%
*-commutative5.6%
distribute-neg-frac25.6%
*-commutative5.6%
*-commutative5.6%
distribute-rgt-neg-in5.6%
*-commutative5.6%
distribute-rgt-neg-in5.6%
Simplified5.6%
associate-*r/4.7%
*-commutative4.7%
times-frac4.7%
add-sqr-sqrt2.0%
sqrt-unprod17.0%
sqr-neg17.0%
sqrt-unprod20.5%
add-sqr-sqrt36.7%
*-commutative36.7%
unpow236.7%
unpow236.7%
frac-times44.2%
unpow244.2%
add-sqr-sqrt42.6%
pow242.6%
Applied egg-rr48.4%
Taylor expanded in h around -inf 0.0%
mul-1-neg0.0%
distribute-neg-frac20.0%
Simplified49.6%
associate-*r/49.6%
distribute-frac-neg49.6%
*-commutative49.6%
Applied egg-rr49.6%
Simplified48.0%
if -1.39999999999999995e265 < c0 < -1.35e193 or -6.39999999999999989e-169 < c0 < 3.1000000000000002e37Initial program 8.6%
Simplified15.7%
Taylor expanded in c0 around -inf 1.1%
distribute-lft-in1.1%
mul-1-neg1.1%
distribute-rgt-neg-in1.1%
associate-/l*0.2%
mul-1-neg0.2%
associate-/l*2.2%
distribute-lft1-in2.2%
metadata-eval2.2%
mul0-lft52.6%
metadata-eval52.6%
Simplified52.6%
Final simplification49.8%
(FPCore (c0 w h D d M)
:precision binary64
(let* ((t_0 (/ (* c0 (* d d)) (* (* w h) (* D D)))))
(if (<=
(* (/ c0 (* 2.0 w)) (+ t_0 (sqrt (- (* t_0 t_0) (* M M)))))
INFINITY)
(* -0.5 (* (/ c0 h) (/ (* c0 (* (/ (pow (/ d D) 2.0) w) -2.0)) w)))
(* c0 (/ 0.0 (* 2.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 tmp;
if (((c0 / (2.0 * w)) * (t_0 + sqrt(((t_0 * t_0) - (M * M))))) <= ((double) INFINITY)) {
tmp = -0.5 * ((c0 / h) * ((c0 * ((pow((d / D), 2.0) / w) * -2.0)) / w));
} else {
tmp = c0 * (0.0 / (2.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 tmp;
if (((c0 / (2.0 * w)) * (t_0 + Math.sqrt(((t_0 * t_0) - (M * M))))) <= Double.POSITIVE_INFINITY) {
tmp = -0.5 * ((c0 / h) * ((c0 * ((Math.pow((d / D), 2.0) / w) * -2.0)) / w));
} else {
tmp = c0 * (0.0 / (2.0 * w));
}
return tmp;
}
def code(c0, w, h, D, d, M): t_0 = (c0 * (d * d)) / ((w * h) * (D * D)) tmp = 0 if ((c0 / (2.0 * w)) * (t_0 + math.sqrt(((t_0 * t_0) - (M * M))))) <= math.inf: tmp = -0.5 * ((c0 / h) * ((c0 * ((math.pow((d / D), 2.0) / w) * -2.0)) / w)) else: tmp = c0 * (0.0 / (2.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))) tmp = 0.0 if (Float64(Float64(c0 / Float64(2.0 * w)) * Float64(t_0 + sqrt(Float64(Float64(t_0 * t_0) - Float64(M * M))))) <= Inf) tmp = Float64(-0.5 * Float64(Float64(c0 / h) * Float64(Float64(c0 * Float64(Float64((Float64(d / D) ^ 2.0) / w) * -2.0)) / w))); else tmp = Float64(c0 * Float64(0.0 / Float64(2.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)); tmp = 0.0; if (((c0 / (2.0 * w)) * (t_0 + sqrt(((t_0 * t_0) - (M * M))))) <= Inf) tmp = -0.5 * ((c0 / h) * ((c0 * ((((d / D) ^ 2.0) / w) * -2.0)) / w)); else tmp = c0 * (0.0 / (2.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]}, If[LessEqual[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], Infinity], N[(-0.5 * N[(N[(c0 / h), $MachinePrecision] * N[(N[(c0 * N[(N[(N[Power[N[(d / D), $MachinePrecision], 2.0], $MachinePrecision] / w), $MachinePrecision] * -2.0), $MachinePrecision]), $MachinePrecision] / w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(c0 * N[(0.0 / N[(2.0 * w), $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)}\\
\mathbf{if}\;\frac{c0}{2 \cdot w} \cdot \left(t\_0 + \sqrt{t\_0 \cdot t\_0 - M \cdot M}\right) \leq \infty:\\
\;\;\;\;-0.5 \cdot \left(\frac{c0}{h} \cdot \frac{c0 \cdot \left(\frac{{\left(\frac{d}{D}\right)}^{2}}{w} \cdot -2\right)}{w}\right)\\
\mathbf{else}:\\
\;\;\;\;c0 \cdot \frac{0}{2 \cdot 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 75.0%
Simplified72.2%
Taylor expanded in c0 around -inf 4.9%
mul-1-neg4.9%
associate-/l*4.9%
distribute-rgt-neg-in4.9%
*-commutative4.9%
*-commutative4.9%
distribute-neg-frac24.9%
*-commutative4.9%
*-commutative4.9%
distribute-rgt-neg-in4.9%
*-commutative4.9%
distribute-rgt-neg-in4.9%
Simplified4.9%
associate-*r/4.9%
*-commutative4.9%
times-frac7.3%
add-sqr-sqrt4.1%
sqrt-unprod28.3%
sqr-neg28.3%
sqrt-unprod36.2%
add-sqr-sqrt71.0%
*-commutative71.0%
unpow271.0%
unpow271.0%
frac-times72.3%
unpow272.3%
add-sqr-sqrt71.9%
pow271.9%
Applied egg-rr72.1%
Taylor expanded in h around -inf 0.0%
mul-1-neg0.0%
distribute-neg-frac20.0%
Simplified72.4%
Taylor expanded in D around 0 71.2%
Simplified76.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%
Simplified20.5%
Taylor expanded in c0 around -inf 0.7%
distribute-lft-in0.1%
mul-1-neg0.1%
distribute-rgt-neg-in0.1%
associate-/l*0.1%
mul-1-neg0.1%
associate-/l*0.1%
distribute-lft1-in0.1%
metadata-eval0.1%
mul0-lft38.9%
metadata-eval38.9%
Simplified38.9%
Final simplification49.5%
(FPCore (c0 w h D d M) :precision binary64 (* c0 (/ 0.0 (* 2.0 w))))
double code(double c0, double w, double h, double D, double d, double M) {
return c0 * (0.0 / (2.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 = c0 * (0.0d0 / (2.0d0 * w))
end function
public static double code(double c0, double w, double h, double D, double d, double M) {
return c0 * (0.0 / (2.0 * w));
}
def code(c0, w, h, D, d, M): return c0 * (0.0 / (2.0 * w))
function code(c0, w, h, D, d, M) return Float64(c0 * Float64(0.0 / Float64(2.0 * w))) end
function tmp = code(c0, w, h, D, d, M) tmp = c0 * (0.0 / (2.0 * w)); end
code[c0_, w_, h_, D_, d_, M_] := N[(c0 * N[(0.0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
c0 \cdot \frac{0}{2 \cdot w}
\end{array}
Initial program 21.4%
Simplified35.3%
Taylor expanded in c0 around -inf 2.2%
distribute-lft-in1.8%
mul-1-neg1.8%
distribute-rgt-neg-in1.8%
associate-/l*1.5%
mul-1-neg1.5%
associate-/l*2.1%
distribute-lft1-in2.1%
metadata-eval2.1%
mul0-lft30.2%
metadata-eval30.2%
Simplified30.2%
Final simplification30.2%
herbie shell --seed 2024112
(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))))))