?

Average Accuracy: 47.7% → 87.0%
Time: 38.5s
Precision: binary64

?

\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a} \]
\[\begin{array}{l} t_0 := \frac{\frac{b}{a}}{-2}\\ \mathbf{if}\;b \leq -3.4 \cdot 10^{+103}:\\ \;\;\;\;-\frac{b}{a}\\ \mathbf{elif}\;b \leq -4.8 \cdot 10^{-157}:\\ \;\;\;\;\frac{{\left(\mathsf{fma}\left(c \cdot a, -4, {b}^{2}\right)\right)}^{0.5}}{a + a} + t_0\\ \mathbf{elif}\;b \leq 10600000:\\ \;\;\;\;\frac{\mathsf{hypot}\left(b, {\left(\sqrt[3]{-4 \cdot c} \cdot \sqrt[3]{a}\right)}^{1.5}\right)}{a + a} + t_0\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array} \]
(FPCore (a b c)
 :precision binary64
 (/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
(FPCore (a b c)
 :precision binary64
 (let* ((t_0 (/ (/ b a) -2.0)))
   (if (<= b -3.4e+103)
     (- (/ b a))
     (if (<= b -4.8e-157)
       (+ (/ (pow (fma (* c a) -4.0 (pow b 2.0)) 0.5) (+ a a)) t_0)
       (if (<= b 10600000.0)
         (+ (/ (hypot b (pow (* (cbrt (* -4.0 c)) (cbrt a)) 1.5)) (+ a a)) t_0)
         (- (/ c b)))))))
double code(double a, double b, double c) {
	return (-b + sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
double code(double a, double b, double c) {
	double t_0 = (b / a) / -2.0;
	double tmp;
	if (b <= -3.4e+103) {
		tmp = -(b / a);
	} else if (b <= -4.8e-157) {
		tmp = (pow(fma((c * a), -4.0, pow(b, 2.0)), 0.5) / (a + a)) + t_0;
	} else if (b <= 10600000.0) {
		tmp = (hypot(b, pow((cbrt((-4.0 * c)) * cbrt(a)), 1.5)) / (a + a)) + t_0;
	} else {
		tmp = -(c / b);
	}
	return tmp;
}
function code(a, b, c)
	return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c))))) / Float64(2.0 * a))
end
function code(a, b, c)
	t_0 = Float64(Float64(b / a) / -2.0)
	tmp = 0.0
	if (b <= -3.4e+103)
		tmp = Float64(-Float64(b / a));
	elseif (b <= -4.8e-157)
		tmp = Float64(Float64((fma(Float64(c * a), -4.0, (b ^ 2.0)) ^ 0.5) / Float64(a + a)) + t_0);
	elseif (b <= 10600000.0)
		tmp = Float64(Float64(hypot(b, (Float64(cbrt(Float64(-4.0 * c)) * cbrt(a)) ^ 1.5)) / Float64(a + a)) + t_0);
	else
		tmp = Float64(-Float64(c / b));
	end
	return tmp
end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(b / a), $MachinePrecision] / -2.0), $MachinePrecision]}, If[LessEqual[b, -3.4e+103], (-N[(b / a), $MachinePrecision]), If[LessEqual[b, -4.8e-157], N[(N[(N[Power[N[(N[(c * a), $MachinePrecision] * -4.0 + N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision], 0.5], $MachinePrecision] / N[(a + a), $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision], If[LessEqual[b, 10600000.0], N[(N[(N[Sqrt[b ^ 2 + N[Power[N[(N[Power[N[(-4.0 * c), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision], 1.5], $MachinePrecision] ^ 2], $MachinePrecision] / N[(a + a), $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision], (-N[(c / b), $MachinePrecision])]]]]
\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\begin{array}{l}
t_0 := \frac{\frac{b}{a}}{-2}\\
\mathbf{if}\;b \leq -3.4 \cdot 10^{+103}:\\
\;\;\;\;-\frac{b}{a}\\

\mathbf{elif}\;b \leq -4.8 \cdot 10^{-157}:\\
\;\;\;\;\frac{{\left(\mathsf{fma}\left(c \cdot a, -4, {b}^{2}\right)\right)}^{0.5}}{a + a} + t_0\\

\mathbf{elif}\;b \leq 10600000:\\
\;\;\;\;\frac{\mathsf{hypot}\left(b, {\left(\sqrt[3]{-4 \cdot c} \cdot \sqrt[3]{a}\right)}^{1.5}\right)}{a + a} + t_0\\

\mathbf{else}:\\
\;\;\;\;-\frac{c}{b}\\


\end{array}

Error?

Target

Original47.7%
Target68.0%
Herbie87.0%
\[\begin{array}{l} \mathbf{if}\;b < 0:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}}\\ \end{array} \]

Derivation?

  1. Split input into 4 regimes
  2. if b < -3.3999999999999998e103

    1. Initial program 28.6%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a} \]
    2. Simplified28.6%

      \[\leadsto \color{blue}{\frac{\sqrt{\mathsf{fma}\left(-4, a \cdot c, {b}^{2}\right)} - b}{a + a}} \]
      Proof
    3. Taylor expanded in b around -inf 93.6%

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}} \]
    4. Simplified93.6%

      \[\leadsto \color{blue}{-\frac{b}{a}} \]
      Proof

    if -3.3999999999999998e103 < b < -4.8e-157

    1. Initial program 90.4%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a} \]
    2. Simplified90.4%

      \[\leadsto \color{blue}{\frac{\sqrt{\mathsf{fma}\left(-4, a \cdot c, {b}^{2}\right)} - b}{a + a}} \]
      Proof
    3. Applied egg-rr67.7%

      \[\leadsto \color{blue}{\frac{\mathsf{hypot}\left(b, \sqrt{a \cdot \left(-4 \cdot c\right)}\right)}{a + a} + \frac{b}{a \cdot -2}} \]
    4. Simplified67.7%

      \[\leadsto \color{blue}{\frac{\mathsf{hypot}\left(b, \sqrt{a \cdot \left(-4 \cdot c\right)}\right)}{a + a} + \frac{\frac{b}{a}}{-2}} \]
      Proof
    5. Applied egg-rr67.3%

      \[\leadsto \frac{\mathsf{hypot}\left(b, \color{blue}{{\left(\sqrt[3]{c \cdot \left(-4 \cdot a\right)}\right)}^{\left(3 \cdot 0.5\right)}}\right)}{a + a} + \frac{\frac{b}{a}}{-2} \]
    6. Simplified67.3%

      \[\leadsto \frac{\mathsf{hypot}\left(b, \color{blue}{{\left(\sqrt[3]{c \cdot \left(-4 \cdot a\right)}\right)}^{1.5}}\right)}{a + a} + \frac{\frac{b}{a}}{-2} \]
      Proof
    7. Applied egg-rr90.4%

      \[\leadsto \color{blue}{\frac{{\left(\mathsf{fma}\left(c \cdot a, -4, {b}^{2}\right)\right)}^{\left(1 \cdot 0.5\right)}}{a + a}} + \frac{\frac{b}{a}}{-2} \]
    8. Simplified90.4%

      \[\leadsto \color{blue}{\frac{{\left(\mathsf{fma}\left(c \cdot a, -4, {b}^{2}\right)\right)}^{0.5}}{a + a}} + \frac{\frac{b}{a}}{-2} \]
      Proof

    if -4.8e-157 < b < 1.06e7

    1. Initial program 64.0%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a} \]
    2. Simplified64.0%

      \[\leadsto \color{blue}{\frac{\sqrt{\mathsf{fma}\left(-4, a \cdot c, {b}^{2}\right)} - b}{a + a}} \]
      Proof
    3. Applied egg-rr65.0%

      \[\leadsto \color{blue}{\frac{\mathsf{hypot}\left(b, \sqrt{a \cdot \left(-4 \cdot c\right)}\right)}{a + a} + \frac{b}{a \cdot -2}} \]
    4. Simplified65.0%

      \[\leadsto \color{blue}{\frac{\mathsf{hypot}\left(b, \sqrt{a \cdot \left(-4 \cdot c\right)}\right)}{a + a} + \frac{\frac{b}{a}}{-2}} \]
      Proof
    5. Applied egg-rr64.4%

      \[\leadsto \frac{\mathsf{hypot}\left(b, \color{blue}{{\left(\sqrt[3]{c \cdot \left(-4 \cdot a\right)}\right)}^{\left(3 \cdot 0.5\right)}}\right)}{a + a} + \frac{\frac{b}{a}}{-2} \]
    6. Simplified64.4%

      \[\leadsto \frac{\mathsf{hypot}\left(b, \color{blue}{{\left(\sqrt[3]{c \cdot \left(-4 \cdot a\right)}\right)}^{1.5}}\right)}{a + a} + \frac{\frac{b}{a}}{-2} \]
      Proof
    7. Applied egg-rr77.3%

      \[\leadsto \frac{\mathsf{hypot}\left(b, {\color{blue}{\left(\sqrt[3]{-4 \cdot c} \cdot \sqrt[3]{a}\right)}}^{1.5}\right)}{a + a} + \frac{\frac{b}{a}}{-2} \]

    if 1.06e7 < b

    1. Initial program 12.1%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a} \]
    2. Simplified12.1%

      \[\leadsto \color{blue}{\frac{\sqrt{\mathsf{fma}\left(-4, a \cdot c, {b}^{2}\right)} - b}{a + a}} \]
      Proof
    3. Taylor expanded in b around inf 91.4%

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}} \]
    4. Simplified91.4%

      \[\leadsto \color{blue}{-\frac{c}{b}} \]
      Proof
  3. Recombined 4 regimes into one program.

Reproduce?

herbie shell --seed 2023151 
(FPCore (a b c)
  :name "quadp (p42, positive)"
  :precision binary64

  :herbie-target
  (if (< b 0.0) (/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)) (/ c (* a (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))))

  (/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))