Average Error: 59.3 → 15.4
Time: 29.5s
Precision: binary64
Cost: 33224
\[\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \]
\[\begin{array}{l} t_0 := M \cdot \frac{D}{d}\\ t_1 := \mathsf{fma}\left(0.25, \mathsf{fma}\left(t_0, h \cdot t_0, 0\right), 0\right)\\ t_2 := \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}\\ t_3 := \frac{c0}{2 \cdot w}\\ t_4 := \left(t_2 + \sqrt{t_2 \cdot t_2 - M \cdot M}\right) \cdot t_3\\ \mathbf{if}\;t_4 \leq 0:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_4 \leq \infty:\\ \;\;\;\;\frac{\left(2 \cdot t_3\right) \cdot \frac{d}{D}}{\frac{w}{\frac{c0}{h \cdot \frac{D}{d}}}}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
(FPCore (c0 w h D d M)
 :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))))))
(FPCore (c0 w h D d M)
 :precision binary64
 (let* ((t_0 (* M (/ D d)))
        (t_1 (fma 0.25 (fma t_0 (* h t_0) 0.0) 0.0))
        (t_2 (/ (* c0 (* d d)) (* (* w h) (* D D))))
        (t_3 (/ c0 (* 2.0 w)))
        (t_4 (* (+ t_2 (sqrt (- (* t_2 t_2) (* M M)))) t_3)))
   (if (<= t_4 0.0)
     t_1
     (if (<= t_4 INFINITY)
       (/ (* (* 2.0 t_3) (/ d D)) (/ w (/ c0 (* h (/ D d)))))
       t_1))))
double code(double c0, double w, double h, double D, double d, double M) {
	return (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))));
}
double code(double c0, double w, double h, double D, double d, double M) {
	double t_0 = M * (D / d);
	double t_1 = fma(0.25, fma(t_0, (h * t_0), 0.0), 0.0);
	double t_2 = (c0 * (d * d)) / ((w * h) * (D * D));
	double t_3 = c0 / (2.0 * w);
	double t_4 = (t_2 + sqrt(((t_2 * t_2) - (M * M)))) * t_3;
	double tmp;
	if (t_4 <= 0.0) {
		tmp = t_1;
	} else if (t_4 <= ((double) INFINITY)) {
		tmp = ((2.0 * t_3) * (d / D)) / (w / (c0 / (h * (D / d))));
	} else {
		tmp = t_1;
	}
	return tmp;
}
function code(c0, w, h, D, d, M)
	return Float64(Float64(c0 / Float64(2.0 * w)) * Float64(Float64(Float64(c0 * Float64(d * d)) / Float64(Float64(w * h) * Float64(D * D))) + sqrt(Float64(Float64(Float64(Float64(c0 * Float64(d * d)) / Float64(Float64(w * h) * Float64(D * D))) * Float64(Float64(c0 * Float64(d * d)) / Float64(Float64(w * h) * Float64(D * D)))) - Float64(M * M)))))
end
function code(c0, w, h, D, d, M)
	t_0 = Float64(M * Float64(D / d))
	t_1 = fma(0.25, fma(t_0, Float64(h * t_0), 0.0), 0.0)
	t_2 = Float64(Float64(c0 * Float64(d * d)) / Float64(Float64(w * h) * Float64(D * D)))
	t_3 = Float64(c0 / Float64(2.0 * w))
	t_4 = Float64(Float64(t_2 + sqrt(Float64(Float64(t_2 * t_2) - Float64(M * M)))) * t_3)
	tmp = 0.0
	if (t_4 <= 0.0)
		tmp = t_1;
	elseif (t_4 <= Inf)
		tmp = Float64(Float64(Float64(2.0 * t_3) * Float64(d / D)) / Float64(w / Float64(c0 / Float64(h * Float64(D / d)))));
	else
		tmp = t_1;
	end
	return tmp
end
code[c0_, w_, h_, D_, d_, M_] := N[(N[(c0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision] * N[(N[(N[(c0 * N[(d * d), $MachinePrecision]), $MachinePrecision] / N[(N[(w * h), $MachinePrecision] * N[(D * D), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[Sqrt[N[(N[(N[(N[(c0 * N[(d * d), $MachinePrecision]), $MachinePrecision] / N[(N[(w * h), $MachinePrecision] * N[(D * D), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[(c0 * N[(d * d), $MachinePrecision]), $MachinePrecision] / N[(N[(w * h), $MachinePrecision] * N[(D * D), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(M * M), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[c0_, w_, h_, D_, d_, M_] := Block[{t$95$0 = N[(M * N[(D / d), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(0.25 * N[(t$95$0 * N[(h * t$95$0), $MachinePrecision] + 0.0), $MachinePrecision] + 0.0), $MachinePrecision]}, Block[{t$95$2 = N[(N[(c0 * N[(d * d), $MachinePrecision]), $MachinePrecision] / N[(N[(w * h), $MachinePrecision] * N[(D * D), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(c0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[(N[(t$95$2 + N[Sqrt[N[(N[(t$95$2 * t$95$2), $MachinePrecision] - N[(M * M), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * t$95$3), $MachinePrecision]}, If[LessEqual[t$95$4, 0.0], t$95$1, If[LessEqual[t$95$4, Infinity], N[(N[(N[(2.0 * t$95$3), $MachinePrecision] * N[(d / D), $MachinePrecision]), $MachinePrecision] / N[(w / N[(c0 / N[(h * N[(D / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]]]
\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right)
\begin{array}{l}
t_0 := M \cdot \frac{D}{d}\\
t_1 := \mathsf{fma}\left(0.25, \mathsf{fma}\left(t_0, h \cdot t_0, 0\right), 0\right)\\
t_2 := \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}\\
t_3 := \frac{c0}{2 \cdot w}\\
t_4 := \left(t_2 + \sqrt{t_2 \cdot t_2 - M \cdot M}\right) \cdot t_3\\
\mathbf{if}\;t_4 \leq 0:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_4 \leq \infty:\\
\;\;\;\;\frac{\left(2 \cdot t_3\right) \cdot \frac{d}{D}}{\frac{w}{\frac{c0}{h \cdot \frac{D}{d}}}}\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}

Error

Derivation

  1. Split input into 2 regimes
  2. 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))))) < -0.0 or +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)))))

    1. Initial program 60.1

      \[\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \]
    2. Applied egg-rr55.5

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{\mathsf{fma}\left(1, \frac{\frac{c0}{h}}{w} \cdot \left(\frac{d}{D} \cdot \frac{d}{D}\right), \sqrt{{\left(\frac{\frac{c0}{h}}{w} \cdot \left(\frac{d}{D} \cdot \frac{d}{D}\right)\right)}^{2} - M \cdot M}\right)} \]
    3. Taylor expanded in c0 around -inf 60.5

      \[\leadsto \color{blue}{-0.5 \cdot \frac{\left(\frac{{d}^{2}}{{D}^{2} \cdot \left(w \cdot h\right)} + -1 \cdot \frac{{d}^{2}}{{D}^{2} \cdot \left(w \cdot h\right)}\right) \cdot {c0}^{2}}{w} + 0.25 \cdot \frac{{D}^{2} \cdot \left({M}^{2} \cdot h\right)}{{d}^{2}}} \]
    4. Simplified30.2

      \[\leadsto \color{blue}{\mathsf{fma}\left(0.25, \frac{D}{\frac{d \cdot d}{D}} \cdot \left(M \cdot \left(M \cdot h\right)\right), 0\right)} \]
      Proof
      (fma.f64 1/4 (*.f64 (/.f64 D (/.f64 (*.f64 d d) D)) (*.f64 M (*.f64 M h))) 0): 0 points increase in error, 0 points decrease in error
      (fma.f64 1/4 (*.f64 (/.f64 D (/.f64 (Rewrite<= unpow2_binary64 (pow.f64 d 2)) D)) (*.f64 M (*.f64 M h))) 0): 0 points increase in error, 0 points decrease in error
      (fma.f64 1/4 (*.f64 (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 D D) (pow.f64 d 2))) (*.f64 M (*.f64 M h))) 0): 31 points increase in error, 3 points decrease in error
      (fma.f64 1/4 (*.f64 (/.f64 (Rewrite<= unpow2_binary64 (pow.f64 D 2)) (pow.f64 d 2)) (*.f64 M (*.f64 M h))) 0): 0 points increase in error, 0 points decrease in error
      (fma.f64 1/4 (*.f64 (/.f64 (pow.f64 D 2) (pow.f64 d 2)) (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 M M) h))) 0): 15 points increase in error, 4 points decrease in error
      (fma.f64 1/4 (*.f64 (/.f64 (pow.f64 D 2) (pow.f64 d 2)) (*.f64 (Rewrite<= unpow2_binary64 (pow.f64 M 2)) h)) 0): 0 points increase in error, 0 points decrease in error
      (fma.f64 1/4 (Rewrite<= associate-/r/_binary64 (/.f64 (pow.f64 D 2) (/.f64 (pow.f64 d 2) (*.f64 (pow.f64 M 2) h)))) 0): 14 points increase in error, 5 points decrease in error
      (fma.f64 1/4 (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 (pow.f64 D 2) (*.f64 (pow.f64 M 2) h)) (pow.f64 d 2))) 0): 8 points increase in error, 15 points decrease in error
      (fma.f64 1/4 (/.f64 (*.f64 (pow.f64 D 2) (*.f64 (pow.f64 M 2) h)) (pow.f64 d 2)) (Rewrite<= div0_binary64 (/.f64 0 (/.f64 w (pow.f64 c0 2))))): 38 points increase in error, 0 points decrease in error
      (fma.f64 1/4 (/.f64 (*.f64 (pow.f64 D 2) (*.f64 (pow.f64 M 2) h)) (pow.f64 d 2)) (/.f64 (Rewrite<= metadata-eval (*.f64 -1/2 0)) (/.f64 w (pow.f64 c0 2)))): 0 points increase in error, 0 points decrease in error
      (fma.f64 1/4 (/.f64 (*.f64 (pow.f64 D 2) (*.f64 (pow.f64 M 2) h)) (pow.f64 d 2)) (/.f64 (*.f64 -1/2 (Rewrite<= mul0-lft_binary64 (*.f64 0 (/.f64 (pow.f64 d 2) (*.f64 (pow.f64 D 2) (*.f64 w h)))))) (/.f64 w (pow.f64 c0 2)))): 109 points increase in error, 0 points decrease in error
      (fma.f64 1/4 (/.f64 (*.f64 (pow.f64 D 2) (*.f64 (pow.f64 M 2) h)) (pow.f64 d 2)) (/.f64 (*.f64 -1/2 (*.f64 (Rewrite<= metadata-eval (+.f64 -1 1)) (/.f64 (pow.f64 d 2) (*.f64 (pow.f64 D 2) (*.f64 w h))))) (/.f64 w (pow.f64 c0 2)))): 0 points increase in error, 0 points decrease in error
      (fma.f64 1/4 (/.f64 (*.f64 (pow.f64 D 2) (*.f64 (pow.f64 M 2) h)) (pow.f64 d 2)) (/.f64 (*.f64 -1/2 (Rewrite<= distribute-rgt1-in_binary64 (+.f64 (/.f64 (pow.f64 d 2) (*.f64 (pow.f64 D 2) (*.f64 w h))) (*.f64 -1 (/.f64 (pow.f64 d 2) (*.f64 (pow.f64 D 2) (*.f64 w h))))))) (/.f64 w (pow.f64 c0 2)))): 0 points increase in error, 0 points decrease in error
      (fma.f64 1/4 (/.f64 (*.f64 (pow.f64 D 2) (*.f64 (pow.f64 M 2) h)) (pow.f64 d 2)) (Rewrite<= associate-*r/_binary64 (*.f64 -1/2 (/.f64 (+.f64 (/.f64 (pow.f64 d 2) (*.f64 (pow.f64 D 2) (*.f64 w h))) (*.f64 -1 (/.f64 (pow.f64 d 2) (*.f64 (pow.f64 D 2) (*.f64 w h))))) (/.f64 w (pow.f64 c0 2)))))): 0 points increase in error, 0 points decrease in error
      (fma.f64 1/4 (/.f64 (*.f64 (pow.f64 D 2) (*.f64 (pow.f64 M 2) h)) (pow.f64 d 2)) (*.f64 -1/2 (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 (+.f64 (/.f64 (pow.f64 d 2) (*.f64 (pow.f64 D 2) (*.f64 w h))) (*.f64 -1 (/.f64 (pow.f64 d 2) (*.f64 (pow.f64 D 2) (*.f64 w h))))) (pow.f64 c0 2)) w)))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= fma-def_binary64 (+.f64 (*.f64 1/4 (/.f64 (*.f64 (pow.f64 D 2) (*.f64 (pow.f64 M 2) h)) (pow.f64 d 2))) (*.f64 -1/2 (/.f64 (*.f64 (+.f64 (/.f64 (pow.f64 d 2) (*.f64 (pow.f64 D 2) (*.f64 w h))) (*.f64 -1 (/.f64 (pow.f64 d 2) (*.f64 (pow.f64 D 2) (*.f64 w h))))) (pow.f64 c0 2)) w)))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 -1/2 (/.f64 (*.f64 (+.f64 (/.f64 (pow.f64 d 2) (*.f64 (pow.f64 D 2) (*.f64 w h))) (*.f64 -1 (/.f64 (pow.f64 d 2) (*.f64 (pow.f64 D 2) (*.f64 w h))))) (pow.f64 c0 2)) w)) (*.f64 1/4 (/.f64 (*.f64 (pow.f64 D 2) (*.f64 (pow.f64 M 2) h)) (pow.f64 d 2))))): 0 points increase in error, 0 points decrease in error
    5. Applied egg-rr17.8

      \[\leadsto \mathsf{fma}\left(0.25, \color{blue}{0 + {\left(\frac{D}{d} \cdot M\right)}^{2} \cdot h}, 0\right) \]
    6. Applied egg-rr14.5

      \[\leadsto \mathsf{fma}\left(0.25, 0 + \color{blue}{\mathsf{fma}\left(\frac{D}{d} \cdot M, \left(\frac{D}{d} \cdot M\right) \cdot h, 0\right)}, 0\right) \]

    if -0.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))))) < +inf.0

    1. Initial program 47.3

      \[\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \]
    2. Simplified55.6

      \[\leadsto \color{blue}{\frac{\frac{c0}{2}}{w} \cdot \mathsf{fma}\left(d \cdot d, \frac{c0}{w \cdot \left(h \cdot \left(D \cdot D\right)\right)}, \sqrt{\mathsf{fma}\left(\frac{c0}{w \cdot h}, \frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{4}, M \cdot \left(-M\right)\right)}\right)} \]
      Proof
      (*.f64 (/.f64 (/.f64 c0 2) w) (fma.f64 (*.f64 d d) (/.f64 c0 (*.f64 w (*.f64 h (*.f64 D D)))) (sqrt.f64 (fma.f64 (/.f64 c0 (*.f64 w h)) (*.f64 (/.f64 c0 (*.f64 w h)) (pow.f64 (/.f64 d D) 4)) (*.f64 M (neg.f64 M)))))): 0 points increase in error, 0 points decrease in error
      (*.f64 (Rewrite<= associate-/r*_binary64 (/.f64 c0 (*.f64 2 w))) (fma.f64 (*.f64 d d) (/.f64 c0 (*.f64 w (*.f64 h (*.f64 D D)))) (sqrt.f64 (fma.f64 (/.f64 c0 (*.f64 w h)) (*.f64 (/.f64 c0 (*.f64 w h)) (pow.f64 (/.f64 d D) 4)) (*.f64 M (neg.f64 M)))))): 0 points increase in error, 0 points decrease in error
      (*.f64 (/.f64 c0 (*.f64 2 w)) (fma.f64 (*.f64 d d) (/.f64 c0 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 w h) (*.f64 D D)))) (sqrt.f64 (fma.f64 (/.f64 c0 (*.f64 w h)) (*.f64 (/.f64 c0 (*.f64 w h)) (pow.f64 (/.f64 d D) 4)) (*.f64 M (neg.f64 M)))))): 4 points increase in error, 4 points decrease in error
      (*.f64 (/.f64 c0 (*.f64 2 w)) (fma.f64 (*.f64 d d) (/.f64 c0 (*.f64 (*.f64 w h) (*.f64 D D))) (sqrt.f64 (fma.f64 (/.f64 c0 (*.f64 w h)) (*.f64 (/.f64 c0 (*.f64 w h)) (pow.f64 (/.f64 d D) (Rewrite<= metadata-eval (+.f64 3 1)))) (*.f64 M (neg.f64 M)))))): 0 points increase in error, 0 points decrease in error
      (*.f64 (/.f64 c0 (*.f64 2 w)) (fma.f64 (*.f64 d d) (/.f64 c0 (*.f64 (*.f64 w h) (*.f64 D D))) (sqrt.f64 (fma.f64 (/.f64 c0 (*.f64 w h)) (*.f64 (/.f64 c0 (*.f64 w h)) (Rewrite<= pow-plus_binary64 (*.f64 (pow.f64 (/.f64 d D) 3) (/.f64 d D)))) (*.f64 M (neg.f64 M)))))): 1 points increase in error, 0 points decrease in error
      (*.f64 (/.f64 c0 (*.f64 2 w)) (fma.f64 (*.f64 d d) (/.f64 c0 (*.f64 (*.f64 w h) (*.f64 D D))) (sqrt.f64 (fma.f64 (/.f64 c0 (*.f64 w h)) (*.f64 (/.f64 c0 (*.f64 w h)) (*.f64 (Rewrite=> unpow3_binary64 (*.f64 (*.f64 (/.f64 d D) (/.f64 d D)) (/.f64 d D))) (/.f64 d D))) (*.f64 M (neg.f64 M)))))): 0 points increase in error, 1 points decrease in error
      (*.f64 (/.f64 c0 (*.f64 2 w)) (fma.f64 (*.f64 d d) (/.f64 c0 (*.f64 (*.f64 w h) (*.f64 D D))) (sqrt.f64 (fma.f64 (/.f64 c0 (*.f64 w h)) (*.f64 (/.f64 c0 (*.f64 w h)) (*.f64 (*.f64 (Rewrite<= times-frac_binary64 (/.f64 (*.f64 d d) (*.f64 D D))) (/.f64 d D)) (/.f64 d D))) (*.f64 M (neg.f64 M)))))): 0 points increase in error, 2 points decrease in error
      (*.f64 (/.f64 c0 (*.f64 2 w)) (fma.f64 (*.f64 d d) (/.f64 c0 (*.f64 (*.f64 w h) (*.f64 D D))) (sqrt.f64 (fma.f64 (/.f64 c0 (*.f64 w h)) (*.f64 (/.f64 c0 (*.f64 w h)) (Rewrite<= associate-*r*_binary64 (*.f64 (/.f64 (*.f64 d d) (*.f64 D D)) (*.f64 (/.f64 d D) (/.f64 d D))))) (*.f64 M (neg.f64 M)))))): 1 points increase in error, 1 points decrease in error
      (*.f64 (/.f64 c0 (*.f64 2 w)) (fma.f64 (*.f64 d d) (/.f64 c0 (*.f64 (*.f64 w h) (*.f64 D D))) (sqrt.f64 (fma.f64 (/.f64 c0 (*.f64 w h)) (*.f64 (/.f64 c0 (*.f64 w h)) (*.f64 (/.f64 (*.f64 d d) (*.f64 D D)) (Rewrite<= times-frac_binary64 (/.f64 (*.f64 d d) (*.f64 D D))))) (*.f64 M (neg.f64 M)))))): 1 points increase in error, 4 points decrease in error
      (*.f64 (/.f64 c0 (*.f64 2 w)) (fma.f64 (*.f64 d d) (/.f64 c0 (*.f64 (*.f64 w h) (*.f64 D D))) (sqrt.f64 (fma.f64 (/.f64 c0 (*.f64 w h)) (*.f64 (/.f64 c0 (*.f64 w h)) (*.f64 (/.f64 (*.f64 d d) (*.f64 D D)) (/.f64 (*.f64 d d) (*.f64 D D)))) (Rewrite<= distribute-rgt-neg-in_binary64 (neg.f64 (*.f64 M M))))))): 0 points increase in error, 0 points decrease in error
      (*.f64 (/.f64 c0 (*.f64 2 w)) (fma.f64 (*.f64 d d) (/.f64 c0 (*.f64 (*.f64 w h) (*.f64 D D))) (sqrt.f64 (Rewrite<= fma-neg_binary64 (-.f64 (*.f64 (/.f64 c0 (*.f64 w h)) (*.f64 (/.f64 c0 (*.f64 w h)) (*.f64 (/.f64 (*.f64 d d) (*.f64 D D)) (/.f64 (*.f64 d d) (*.f64 D D))))) (*.f64 M M)))))): 0 points increase in error, 0 points decrease in error
      (*.f64 (/.f64 c0 (*.f64 2 w)) (fma.f64 (*.f64 d d) (/.f64 c0 (*.f64 (*.f64 w h) (*.f64 D D))) (sqrt.f64 (-.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 (/.f64 c0 (*.f64 w h)) (/.f64 c0 (*.f64 w h))) (*.f64 (/.f64 (*.f64 d d) (*.f64 D D)) (/.f64 (*.f64 d d) (*.f64 D D))))) (*.f64 M M))))): 6 points increase in error, 0 points decrease in error
      (*.f64 (/.f64 c0 (*.f64 2 w)) (fma.f64 (*.f64 d d) (/.f64 c0 (*.f64 (*.f64 w h) (*.f64 D D))) (sqrt.f64 (-.f64 (Rewrite<= swap-sqr_binary64 (*.f64 (*.f64 (/.f64 c0 (*.f64 w h)) (/.f64 (*.f64 d d) (*.f64 D D))) (*.f64 (/.f64 c0 (*.f64 w h)) (/.f64 (*.f64 d d) (*.f64 D D))))) (*.f64 M M))))): 2 points increase in error, 13 points decrease in error
      (*.f64 (/.f64 c0 (*.f64 2 w)) (fma.f64 (*.f64 d d) (/.f64 c0 (*.f64 (*.f64 w h) (*.f64 D D))) (sqrt.f64 (-.f64 (*.f64 (Rewrite<= times-frac_binary64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D)))) (*.f64 (/.f64 c0 (*.f64 w h)) (/.f64 (*.f64 d d) (*.f64 D D)))) (*.f64 M M))))): 4 points increase in error, 4 points decrease in error
      (*.f64 (/.f64 c0 (*.f64 2 w)) (fma.f64 (*.f64 d d) (/.f64 c0 (*.f64 (*.f64 w h) (*.f64 D D))) (sqrt.f64 (-.f64 (*.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (Rewrite<= times-frac_binary64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))))) (*.f64 M M))))): 3 points increase in error, 8 points decrease in error
      (*.f64 (/.f64 c0 (*.f64 2 w)) (Rewrite<= fma-def_binary64 (+.f64 (*.f64 (*.f64 d d) (/.f64 c0 (*.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)))))): 6 points increase in error, 5 points decrease in error
      (*.f64 (/.f64 c0 (*.f64 2 w)) (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 (/.f64 c0 (*.f64 (*.f64 w h) (*.f64 D D))) (*.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))))): 0 points increase in error, 0 points decrease in error
      (*.f64 (/.f64 c0 (*.f64 2 w)) (+.f64 (Rewrite=> associate-*l/_binary64 (/.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))))): 0 points increase in error, 8 points decrease in error
    3. Taylor expanded in d around inf 42.8

      \[\leadsto \frac{\frac{c0}{2}}{w} \cdot \color{blue}{\left(2 \cdot \frac{{d}^{2} \cdot c0}{{D}^{2} \cdot \left(w \cdot h\right)}\right)} \]
    4. Simplified41.4

      \[\leadsto \frac{\frac{c0}{2}}{w} \cdot \color{blue}{\left(2 \cdot \left(c0 \cdot \frac{\frac{d}{D} \cdot \frac{d}{D}}{w \cdot h}\right)\right)} \]
      Proof
      (*.f64 2 (*.f64 c0 (/.f64 (*.f64 (/.f64 d D) (/.f64 d D)) (*.f64 w h)))): 0 points increase in error, 0 points decrease in error
      (*.f64 2 (*.f64 c0 (/.f64 (Rewrite<= times-frac_binary64 (/.f64 (*.f64 d d) (*.f64 D D))) (*.f64 w h)))): 51 points increase in error, 12 points decrease in error
      (*.f64 2 (*.f64 c0 (/.f64 (/.f64 (Rewrite<= unpow2_binary64 (pow.f64 d 2)) (*.f64 D D)) (*.f64 w h)))): 0 points increase in error, 0 points decrease in error
      (*.f64 2 (*.f64 c0 (/.f64 (/.f64 (pow.f64 d 2) (Rewrite<= unpow2_binary64 (pow.f64 D 2))) (*.f64 w h)))): 0 points increase in error, 0 points decrease in error
      (*.f64 2 (*.f64 c0 (Rewrite<= associate-/r*_binary64 (/.f64 (pow.f64 d 2) (*.f64 (pow.f64 D 2) (*.f64 w h)))))): 8 points increase in error, 16 points decrease in error
      (*.f64 2 (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 c0 (pow.f64 d 2)) (*.f64 (pow.f64 D 2) (*.f64 w h))))): 9 points increase in error, 7 points decrease in error
      (*.f64 2 (/.f64 (Rewrite<= *-commutative_binary64 (*.f64 (pow.f64 d 2) c0)) (*.f64 (pow.f64 D 2) (*.f64 w h)))): 0 points increase in error, 0 points decrease in error
    5. Applied egg-rr29.3

      \[\leadsto \frac{\frac{c0}{2}}{w} \cdot \left(2 \cdot \color{blue}{\frac{\frac{d}{D} \cdot c0}{\left(w \cdot h\right) \cdot \frac{D}{d}}}\right) \]
    6. Applied egg-rr29.5

      \[\leadsto \color{blue}{\frac{\left(2 \cdot \frac{c0}{w \cdot 2}\right) \cdot \frac{d}{D}}{\frac{w}{\frac{c0}{h \cdot \frac{D}{d}}}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification15.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \cdot \frac{c0}{2 \cdot w} \leq 0:\\ \;\;\;\;\mathsf{fma}\left(0.25, \mathsf{fma}\left(M \cdot \frac{D}{d}, h \cdot \left(M \cdot \frac{D}{d}\right), 0\right), 0\right)\\ \mathbf{elif}\;\left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \cdot \frac{c0}{2 \cdot w} \leq \infty:\\ \;\;\;\;\frac{\left(2 \cdot \frac{c0}{2 \cdot w}\right) \cdot \frac{d}{D}}{\frac{w}{\frac{c0}{h \cdot \frac{D}{d}}}}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(0.25, \mathsf{fma}\left(M \cdot \frac{D}{d}, h \cdot \left(M \cdot \frac{D}{d}\right), 0\right), 0\right)\\ \end{array} \]

Alternatives

Alternative 1
Error18.5
Cost32904
\[\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}\\ t_2 := \left(t_0 + \sqrt{t_0 \cdot t_0 - M \cdot M}\right) \cdot t_1\\ \mathbf{if}\;t_2 \leq 0:\\ \;\;\;\;h \cdot \left(0.25 \cdot {\left(M \cdot \frac{D}{d}\right)}^{2}\right)\\ \mathbf{elif}\;t_2 \leq \infty:\\ \;\;\;\;\frac{\left(2 \cdot t_1\right) \cdot \frac{d}{D}}{\frac{w}{\frac{c0}{h \cdot \frac{D}{d}}}}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(0.25, h \cdot {\left(\frac{D \cdot M}{d}\right)}^{2}, 0\right)\\ \end{array} \]
Alternative 2
Error18.5
Cost26504
\[\begin{array}{l} t_0 := h \cdot \left(0.25 \cdot {\left(M \cdot \frac{D}{d}\right)}^{2}\right)\\ t_1 := \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}\\ t_2 := \frac{c0}{2 \cdot w}\\ t_3 := \left(t_1 + \sqrt{t_1 \cdot t_1 - M \cdot M}\right) \cdot t_2\\ \mathbf{if}\;t_3 \leq 0:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_3 \leq \infty:\\ \;\;\;\;\frac{\left(2 \cdot t_2\right) \cdot \frac{d}{D}}{\frac{w}{\frac{c0}{h \cdot \frac{D}{d}}}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error22.8
Cost1480
\[\begin{array}{l} \mathbf{if}\;d \cdot d \leq 5 \cdot 10^{-204}:\\ \;\;\;\;\frac{\frac{D}{d} \cdot \left(0.25 \cdot \left(h \cdot \left(M \cdot M\right)\right)\right)}{\frac{d}{D}}\\ \mathbf{elif}\;d \cdot d \leq 5 \cdot 10^{+285}:\\ \;\;\;\;\left(D \cdot \left(M \cdot \left(h \cdot \left(D \cdot M\right)\right)\right)\right) \cdot \frac{0.25}{d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;0.25 \cdot \left(D \cdot \frac{D}{\frac{d}{h \cdot \left(M \cdot \frac{M}{d}\right)}}\right)\\ \end{array} \]
Alternative 4
Error28.1
Cost1224
\[\begin{array}{l} \mathbf{if}\;M \leq -6.2 \cdot 10^{+151}:\\ \;\;\;\;0\\ \mathbf{elif}\;M \leq 6.5 \cdot 10^{+116}:\\ \;\;\;\;\frac{D \cdot \frac{D}{d}}{d} \cdot \left(\left(M \cdot M\right) \cdot \left(h \cdot 0.25\right)\right)\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
Alternative 5
Error25.3
Cost1224
\[\begin{array}{l} \mathbf{if}\;M \leq -6.2 \cdot 10^{+151}:\\ \;\;\;\;0\\ \mathbf{elif}\;M \leq 3.5 \cdot 10^{+143}:\\ \;\;\;\;\frac{\frac{D}{d} \cdot \left(0.25 \cdot \left(h \cdot \left(M \cdot M\right)\right)\right)}{\frac{d}{D}}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
Alternative 6
Error23.9
Cost1224
\[\begin{array}{l} t_0 := \left(D \cdot \left(M \cdot \left(h \cdot \left(D \cdot M\right)\right)\right)\right) \cdot \frac{0.25}{d \cdot d}\\ \mathbf{if}\;M \leq -6.2 \cdot 10^{+151}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;M \leq 3.5 \cdot 10^{+143}:\\ \;\;\;\;\frac{\frac{D}{d} \cdot \left(0.25 \cdot \left(h \cdot \left(M \cdot M\right)\right)\right)}{\frac{d}{D}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Error32.3
Cost64
\[0 \]

Error

Reproduce

herbie shell --seed 2022289 
(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))))))