quad2p (problem 3.2.1, positive)

Percentage Accurate: 51.7% → 85.1%
Time: 9.3s
Alternatives: 6
Speedup: 15.9×

Specification

?
\[\begin{array}{l} \\ \frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \end{array} \]
(FPCore (a b_2 c)
 :precision binary64
 (/ (+ (- b_2) (sqrt (- (* b_2 b_2) (* a c)))) a))
double code(double a, double b_2, double c) {
	return (-b_2 + sqrt(((b_2 * b_2) - (a * c)))) / a;
}
real(8) function code(a, b_2, c)
    real(8), intent (in) :: a
    real(8), intent (in) :: b_2
    real(8), intent (in) :: c
    code = (-b_2 + sqrt(((b_2 * b_2) - (a * c)))) / a
end function
public static double code(double a, double b_2, double c) {
	return (-b_2 + Math.sqrt(((b_2 * b_2) - (a * c)))) / a;
}
def code(a, b_2, c):
	return (-b_2 + math.sqrt(((b_2 * b_2) - (a * c)))) / a
function code(a, b_2, c)
	return Float64(Float64(Float64(-b_2) + sqrt(Float64(Float64(b_2 * b_2) - Float64(a * c)))) / a)
end
function tmp = code(a, b_2, c)
	tmp = (-b_2 + sqrt(((b_2 * b_2) - (a * c)))) / a;
end
code[a_, b$95$2_, c_] := N[(N[((-b$95$2) + N[Sqrt[N[(N[(b$95$2 * b$95$2), $MachinePrecision] - N[(a * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]
\begin{array}{l}

\\
\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 6 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 51.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \end{array} \]
(FPCore (a b_2 c)
 :precision binary64
 (/ (+ (- b_2) (sqrt (- (* b_2 b_2) (* a c)))) a))
double code(double a, double b_2, double c) {
	return (-b_2 + sqrt(((b_2 * b_2) - (a * c)))) / a;
}
real(8) function code(a, b_2, c)
    real(8), intent (in) :: a
    real(8), intent (in) :: b_2
    real(8), intent (in) :: c
    code = (-b_2 + sqrt(((b_2 * b_2) - (a * c)))) / a
end function
public static double code(double a, double b_2, double c) {
	return (-b_2 + Math.sqrt(((b_2 * b_2) - (a * c)))) / a;
}
def code(a, b_2, c):
	return (-b_2 + math.sqrt(((b_2 * b_2) - (a * c)))) / a
function code(a, b_2, c)
	return Float64(Float64(Float64(-b_2) + sqrt(Float64(Float64(b_2 * b_2) - Float64(a * c)))) / a)
end
function tmp = code(a, b_2, c)
	tmp = (-b_2 + sqrt(((b_2 * b_2) - (a * c)))) / a;
end
code[a_, b$95$2_, c_] := N[(N[((-b$95$2) + N[Sqrt[N[(N[(b$95$2 * b$95$2), $MachinePrecision] - N[(a * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]
\begin{array}{l}

\\
\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}
\end{array}

Alternative 1: 85.1% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b_2 \leq -5 \cdot 10^{+150}:\\ \;\;\;\;-2 \cdot \frac{b_2}{a}\\ \mathbf{elif}\;b_2 \leq 1.22 \cdot 10^{-11}:\\ \;\;\;\;\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b_2}\\ \end{array} \end{array} \]
(FPCore (a b_2 c)
 :precision binary64
 (if (<= b_2 -5e+150)
   (* -2.0 (/ b_2 a))
   (if (<= b_2 1.22e-11)
     (/ (- (sqrt (- (* b_2 b_2) (* a c))) b_2) a)
     (* -0.5 (/ c b_2)))))
double code(double a, double b_2, double c) {
	double tmp;
	if (b_2 <= -5e+150) {
		tmp = -2.0 * (b_2 / a);
	} else if (b_2 <= 1.22e-11) {
		tmp = (sqrt(((b_2 * b_2) - (a * c))) - b_2) / a;
	} else {
		tmp = -0.5 * (c / b_2);
	}
	return tmp;
}
real(8) function code(a, b_2, c)
    real(8), intent (in) :: a
    real(8), intent (in) :: b_2
    real(8), intent (in) :: c
    real(8) :: tmp
    if (b_2 <= (-5d+150)) then
        tmp = (-2.0d0) * (b_2 / a)
    else if (b_2 <= 1.22d-11) then
        tmp = (sqrt(((b_2 * b_2) - (a * c))) - b_2) / a
    else
        tmp = (-0.5d0) * (c / b_2)
    end if
    code = tmp
end function
public static double code(double a, double b_2, double c) {
	double tmp;
	if (b_2 <= -5e+150) {
		tmp = -2.0 * (b_2 / a);
	} else if (b_2 <= 1.22e-11) {
		tmp = (Math.sqrt(((b_2 * b_2) - (a * c))) - b_2) / a;
	} else {
		tmp = -0.5 * (c / b_2);
	}
	return tmp;
}
def code(a, b_2, c):
	tmp = 0
	if b_2 <= -5e+150:
		tmp = -2.0 * (b_2 / a)
	elif b_2 <= 1.22e-11:
		tmp = (math.sqrt(((b_2 * b_2) - (a * c))) - b_2) / a
	else:
		tmp = -0.5 * (c / b_2)
	return tmp
function code(a, b_2, c)
	tmp = 0.0
	if (b_2 <= -5e+150)
		tmp = Float64(-2.0 * Float64(b_2 / a));
	elseif (b_2 <= 1.22e-11)
		tmp = Float64(Float64(sqrt(Float64(Float64(b_2 * b_2) - Float64(a * c))) - b_2) / a);
	else
		tmp = Float64(-0.5 * Float64(c / b_2));
	end
	return tmp
end
function tmp_2 = code(a, b_2, c)
	tmp = 0.0;
	if (b_2 <= -5e+150)
		tmp = -2.0 * (b_2 / a);
	elseif (b_2 <= 1.22e-11)
		tmp = (sqrt(((b_2 * b_2) - (a * c))) - b_2) / a;
	else
		tmp = -0.5 * (c / b_2);
	end
	tmp_2 = tmp;
end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -5e+150], N[(-2.0 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b$95$2, 1.22e-11], N[(N[(N[Sqrt[N[(N[(b$95$2 * b$95$2), $MachinePrecision] - N[(a * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b$95$2), $MachinePrecision] / a), $MachinePrecision], N[(-0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b_2 \leq -5 \cdot 10^{+150}:\\
\;\;\;\;-2 \cdot \frac{b_2}{a}\\

\mathbf{elif}\;b_2 \leq 1.22 \cdot 10^{-11}:\\
\;\;\;\;\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}\\

\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{c}{b_2}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if b_2 < -5.00000000000000009e150

    1. Initial program 32.3%

      \[\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
    2. Step-by-step derivation
      1. +-commutative32.3%

        \[\leadsto \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} + \left(-b_2\right)}}{a} \]
      2. unsub-neg32.3%

        \[\leadsto \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}}{a} \]
    3. Simplified32.3%

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}} \]
    4. Taylor expanded in b_2 around -inf 97.8%

      \[\leadsto \color{blue}{-2 \cdot \frac{b_2}{a}} \]

    if -5.00000000000000009e150 < b_2 < 1.2200000000000001e-11

    1. Initial program 75.8%

      \[\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
    2. Step-by-step derivation
      1. +-commutative75.8%

        \[\leadsto \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} + \left(-b_2\right)}}{a} \]
      2. unsub-neg75.8%

        \[\leadsto \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}}{a} \]
    3. Simplified75.8%

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}} \]

    if 1.2200000000000001e-11 < b_2

    1. Initial program 14.8%

      \[\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
    2. Step-by-step derivation
      1. +-commutative14.8%

        \[\leadsto \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} + \left(-b_2\right)}}{a} \]
      2. unsub-neg14.8%

        \[\leadsto \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}}{a} \]
    3. Simplified14.8%

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}} \]
    4. Taylor expanded in b_2 around inf 89.6%

      \[\leadsto \color{blue}{-0.5 \cdot \frac{c}{b_2}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification83.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;b_2 \leq -5 \cdot 10^{+150}:\\ \;\;\;\;-2 \cdot \frac{b_2}{a}\\ \mathbf{elif}\;b_2 \leq 1.22 \cdot 10^{-11}:\\ \;\;\;\;\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b_2}\\ \end{array} \]

Alternative 2: 80.1% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b_2 \leq -2.85 \cdot 10^{-42}:\\ \;\;\;\;-2 \cdot \frac{b_2}{a} + \frac{c}{b_2} \cdot 0.5\\ \mathbf{elif}\;b_2 \leq 1.22 \cdot 10^{-11}:\\ \;\;\;\;\frac{\sqrt{a \cdot \left(-c\right)} - b_2}{a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b_2}\\ \end{array} \end{array} \]
(FPCore (a b_2 c)
 :precision binary64
 (if (<= b_2 -2.85e-42)
   (+ (* -2.0 (/ b_2 a)) (* (/ c b_2) 0.5))
   (if (<= b_2 1.22e-11) (/ (- (sqrt (* a (- c))) b_2) a) (* -0.5 (/ c b_2)))))
double code(double a, double b_2, double c) {
	double tmp;
	if (b_2 <= -2.85e-42) {
		tmp = (-2.0 * (b_2 / a)) + ((c / b_2) * 0.5);
	} else if (b_2 <= 1.22e-11) {
		tmp = (sqrt((a * -c)) - b_2) / a;
	} else {
		tmp = -0.5 * (c / b_2);
	}
	return tmp;
}
real(8) function code(a, b_2, c)
    real(8), intent (in) :: a
    real(8), intent (in) :: b_2
    real(8), intent (in) :: c
    real(8) :: tmp
    if (b_2 <= (-2.85d-42)) then
        tmp = ((-2.0d0) * (b_2 / a)) + ((c / b_2) * 0.5d0)
    else if (b_2 <= 1.22d-11) then
        tmp = (sqrt((a * -c)) - b_2) / a
    else
        tmp = (-0.5d0) * (c / b_2)
    end if
    code = tmp
end function
public static double code(double a, double b_2, double c) {
	double tmp;
	if (b_2 <= -2.85e-42) {
		tmp = (-2.0 * (b_2 / a)) + ((c / b_2) * 0.5);
	} else if (b_2 <= 1.22e-11) {
		tmp = (Math.sqrt((a * -c)) - b_2) / a;
	} else {
		tmp = -0.5 * (c / b_2);
	}
	return tmp;
}
def code(a, b_2, c):
	tmp = 0
	if b_2 <= -2.85e-42:
		tmp = (-2.0 * (b_2 / a)) + ((c / b_2) * 0.5)
	elif b_2 <= 1.22e-11:
		tmp = (math.sqrt((a * -c)) - b_2) / a
	else:
		tmp = -0.5 * (c / b_2)
	return tmp
function code(a, b_2, c)
	tmp = 0.0
	if (b_2 <= -2.85e-42)
		tmp = Float64(Float64(-2.0 * Float64(b_2 / a)) + Float64(Float64(c / b_2) * 0.5));
	elseif (b_2 <= 1.22e-11)
		tmp = Float64(Float64(sqrt(Float64(a * Float64(-c))) - b_2) / a);
	else
		tmp = Float64(-0.5 * Float64(c / b_2));
	end
	return tmp
end
function tmp_2 = code(a, b_2, c)
	tmp = 0.0;
	if (b_2 <= -2.85e-42)
		tmp = (-2.0 * (b_2 / a)) + ((c / b_2) * 0.5);
	elseif (b_2 <= 1.22e-11)
		tmp = (sqrt((a * -c)) - b_2) / a;
	else
		tmp = -0.5 * (c / b_2);
	end
	tmp_2 = tmp;
end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -2.85e-42], N[(N[(-2.0 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision] + N[(N[(c / b$95$2), $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision], If[LessEqual[b$95$2, 1.22e-11], N[(N[(N[Sqrt[N[(a * (-c)), $MachinePrecision]], $MachinePrecision] - b$95$2), $MachinePrecision] / a), $MachinePrecision], N[(-0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b_2 \leq -2.85 \cdot 10^{-42}:\\
\;\;\;\;-2 \cdot \frac{b_2}{a} + \frac{c}{b_2} \cdot 0.5\\

\mathbf{elif}\;b_2 \leq 1.22 \cdot 10^{-11}:\\
\;\;\;\;\frac{\sqrt{a \cdot \left(-c\right)} - b_2}{a}\\

\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{c}{b_2}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if b_2 < -2.85e-42

    1. Initial program 63.8%

      \[\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
    2. Step-by-step derivation
      1. +-commutative63.8%

        \[\leadsto \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} + \left(-b_2\right)}}{a} \]
      2. unsub-neg63.8%

        \[\leadsto \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}}{a} \]
    3. Simplified63.8%

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}} \]
    4. Taylor expanded in b_2 around -inf 91.1%

      \[\leadsto \color{blue}{-2 \cdot \frac{b_2}{a} + 0.5 \cdot \frac{c}{b_2}} \]

    if -2.85e-42 < b_2 < 1.2200000000000001e-11

    1. Initial program 66.7%

      \[\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
    2. Step-by-step derivation
      1. +-commutative66.7%

        \[\leadsto \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} + \left(-b_2\right)}}{a} \]
      2. unsub-neg66.7%

        \[\leadsto \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}}{a} \]
    3. Simplified66.7%

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}} \]
    4. Taylor expanded in b_2 around 0 60.9%

      \[\leadsto \frac{\sqrt{\color{blue}{-1 \cdot \left(a \cdot c\right)}} - b_2}{a} \]
    5. Step-by-step derivation
      1. associate-*r*60.9%

        \[\leadsto \frac{\sqrt{\color{blue}{\left(-1 \cdot a\right) \cdot c}} - b_2}{a} \]
      2. neg-mul-160.9%

        \[\leadsto \frac{\sqrt{\color{blue}{\left(-a\right)} \cdot c} - b_2}{a} \]
      3. *-commutative60.9%

        \[\leadsto \frac{\sqrt{\color{blue}{c \cdot \left(-a\right)}} - b_2}{a} \]
    6. Simplified60.9%

      \[\leadsto \frac{\sqrt{\color{blue}{c \cdot \left(-a\right)}} - b_2}{a} \]

    if 1.2200000000000001e-11 < b_2

    1. Initial program 14.8%

      \[\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
    2. Step-by-step derivation
      1. +-commutative14.8%

        \[\leadsto \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} + \left(-b_2\right)}}{a} \]
      2. unsub-neg14.8%

        \[\leadsto \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}}{a} \]
    3. Simplified14.8%

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}} \]
    4. Taylor expanded in b_2 around inf 89.6%

      \[\leadsto \color{blue}{-0.5 \cdot \frac{c}{b_2}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification80.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;b_2 \leq -2.85 \cdot 10^{-42}:\\ \;\;\;\;-2 \cdot \frac{b_2}{a} + \frac{c}{b_2} \cdot 0.5\\ \mathbf{elif}\;b_2 \leq 1.22 \cdot 10^{-11}:\\ \;\;\;\;\frac{\sqrt{a \cdot \left(-c\right)} - b_2}{a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b_2}\\ \end{array} \]

Alternative 3: 79.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b_2 \leq -4.7 \cdot 10^{-70}:\\ \;\;\;\;-2 \cdot \frac{b_2}{a} + \frac{c}{b_2} \cdot 0.5\\ \mathbf{elif}\;b_2 \leq 1.75 \cdot 10^{-11}:\\ \;\;\;\;\frac{\sqrt{a \cdot \left(-c\right)}}{a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b_2}\\ \end{array} \end{array} \]
(FPCore (a b_2 c)
 :precision binary64
 (if (<= b_2 -4.7e-70)
   (+ (* -2.0 (/ b_2 a)) (* (/ c b_2) 0.5))
   (if (<= b_2 1.75e-11) (/ (sqrt (* a (- c))) a) (* -0.5 (/ c b_2)))))
double code(double a, double b_2, double c) {
	double tmp;
	if (b_2 <= -4.7e-70) {
		tmp = (-2.0 * (b_2 / a)) + ((c / b_2) * 0.5);
	} else if (b_2 <= 1.75e-11) {
		tmp = sqrt((a * -c)) / a;
	} else {
		tmp = -0.5 * (c / b_2);
	}
	return tmp;
}
real(8) function code(a, b_2, c)
    real(8), intent (in) :: a
    real(8), intent (in) :: b_2
    real(8), intent (in) :: c
    real(8) :: tmp
    if (b_2 <= (-4.7d-70)) then
        tmp = ((-2.0d0) * (b_2 / a)) + ((c / b_2) * 0.5d0)
    else if (b_2 <= 1.75d-11) then
        tmp = sqrt((a * -c)) / a
    else
        tmp = (-0.5d0) * (c / b_2)
    end if
    code = tmp
end function
public static double code(double a, double b_2, double c) {
	double tmp;
	if (b_2 <= -4.7e-70) {
		tmp = (-2.0 * (b_2 / a)) + ((c / b_2) * 0.5);
	} else if (b_2 <= 1.75e-11) {
		tmp = Math.sqrt((a * -c)) / a;
	} else {
		tmp = -0.5 * (c / b_2);
	}
	return tmp;
}
def code(a, b_2, c):
	tmp = 0
	if b_2 <= -4.7e-70:
		tmp = (-2.0 * (b_2 / a)) + ((c / b_2) * 0.5)
	elif b_2 <= 1.75e-11:
		tmp = math.sqrt((a * -c)) / a
	else:
		tmp = -0.5 * (c / b_2)
	return tmp
function code(a, b_2, c)
	tmp = 0.0
	if (b_2 <= -4.7e-70)
		tmp = Float64(Float64(-2.0 * Float64(b_2 / a)) + Float64(Float64(c / b_2) * 0.5));
	elseif (b_2 <= 1.75e-11)
		tmp = Float64(sqrt(Float64(a * Float64(-c))) / a);
	else
		tmp = Float64(-0.5 * Float64(c / b_2));
	end
	return tmp
end
function tmp_2 = code(a, b_2, c)
	tmp = 0.0;
	if (b_2 <= -4.7e-70)
		tmp = (-2.0 * (b_2 / a)) + ((c / b_2) * 0.5);
	elseif (b_2 <= 1.75e-11)
		tmp = sqrt((a * -c)) / a;
	else
		tmp = -0.5 * (c / b_2);
	end
	tmp_2 = tmp;
end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -4.7e-70], N[(N[(-2.0 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision] + N[(N[(c / b$95$2), $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision], If[LessEqual[b$95$2, 1.75e-11], N[(N[Sqrt[N[(a * (-c)), $MachinePrecision]], $MachinePrecision] / a), $MachinePrecision], N[(-0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b_2 \leq -4.7 \cdot 10^{-70}:\\
\;\;\;\;-2 \cdot \frac{b_2}{a} + \frac{c}{b_2} \cdot 0.5\\

\mathbf{elif}\;b_2 \leq 1.75 \cdot 10^{-11}:\\
\;\;\;\;\frac{\sqrt{a \cdot \left(-c\right)}}{a}\\

\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{c}{b_2}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if b_2 < -4.6999999999999998e-70

    1. Initial program 63.9%

      \[\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
    2. Step-by-step derivation
      1. +-commutative63.9%

        \[\leadsto \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} + \left(-b_2\right)}}{a} \]
      2. unsub-neg63.9%

        \[\leadsto \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}}{a} \]
    3. Simplified63.9%

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}} \]
    4. Taylor expanded in b_2 around -inf 89.2%

      \[\leadsto \color{blue}{-2 \cdot \frac{b_2}{a} + 0.5 \cdot \frac{c}{b_2}} \]

    if -4.6999999999999998e-70 < b_2 < 1.7500000000000001e-11

    1. Initial program 66.7%

      \[\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
    2. Step-by-step derivation
      1. +-commutative66.7%

        \[\leadsto \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} + \left(-b_2\right)}}{a} \]
      2. unsub-neg66.7%

        \[\leadsto \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}}{a} \]
    3. Simplified66.7%

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}} \]
    4. Step-by-step derivation
      1. prod-diff66.1%

        \[\leadsto \frac{\sqrt{\color{blue}{\mathsf{fma}\left(b_2, b_2, -c \cdot a\right) + \mathsf{fma}\left(-c, a, c \cdot a\right)}} - b_2}{a} \]
      2. *-commutative66.1%

        \[\leadsto \frac{\sqrt{\mathsf{fma}\left(b_2, b_2, -\color{blue}{a \cdot c}\right) + \mathsf{fma}\left(-c, a, c \cdot a\right)} - b_2}{a} \]
      3. fma-def66.1%

        \[\leadsto \frac{\sqrt{\color{blue}{\left(b_2 \cdot b_2 + \left(-a \cdot c\right)\right)} + \mathsf{fma}\left(-c, a, c \cdot a\right)} - b_2}{a} \]
      4. associate-+l+66.1%

        \[\leadsto \frac{\sqrt{\color{blue}{b_2 \cdot b_2 + \left(\left(-a \cdot c\right) + \mathsf{fma}\left(-c, a, c \cdot a\right)\right)}} - b_2}{a} \]
      5. distribute-rgt-neg-in66.1%

        \[\leadsto \frac{\sqrt{b_2 \cdot b_2 + \left(\color{blue}{a \cdot \left(-c\right)} + \mathsf{fma}\left(-c, a, c \cdot a\right)\right)} - b_2}{a} \]
      6. fma-def66.2%

        \[\leadsto \frac{\sqrt{b_2 \cdot b_2 + \color{blue}{\mathsf{fma}\left(a, -c, \mathsf{fma}\left(-c, a, c \cdot a\right)\right)}} - b_2}{a} \]
      7. *-commutative66.2%

        \[\leadsto \frac{\sqrt{b_2 \cdot b_2 + \mathsf{fma}\left(a, -c, \mathsf{fma}\left(-c, a, \color{blue}{a \cdot c}\right)\right)} - b_2}{a} \]
      8. fma-udef66.1%

        \[\leadsto \frac{\sqrt{b_2 \cdot b_2 + \mathsf{fma}\left(a, -c, \color{blue}{\left(-c\right) \cdot a + a \cdot c}\right)} - b_2}{a} \]
      9. distribute-lft-neg-in66.1%

        \[\leadsto \frac{\sqrt{b_2 \cdot b_2 + \mathsf{fma}\left(a, -c, \color{blue}{\left(-c \cdot a\right)} + a \cdot c\right)} - b_2}{a} \]
      10. *-commutative66.1%

        \[\leadsto \frac{\sqrt{b_2 \cdot b_2 + \mathsf{fma}\left(a, -c, \left(-\color{blue}{a \cdot c}\right) + a \cdot c\right)} - b_2}{a} \]
      11. distribute-rgt-neg-in66.1%

        \[\leadsto \frac{\sqrt{b_2 \cdot b_2 + \mathsf{fma}\left(a, -c, \color{blue}{a \cdot \left(-c\right)} + a \cdot c\right)} - b_2}{a} \]
      12. fma-def66.2%

        \[\leadsto \frac{\sqrt{b_2 \cdot b_2 + \mathsf{fma}\left(a, -c, \color{blue}{\mathsf{fma}\left(a, -c, a \cdot c\right)}\right)} - b_2}{a} \]
    5. Applied egg-rr66.2%

      \[\leadsto \frac{\sqrt{\color{blue}{b_2 \cdot b_2 + \mathsf{fma}\left(a, -c, \mathsf{fma}\left(a, -c, a \cdot c\right)\right)}} - b_2}{a} \]
    6. Taylor expanded in b_2 around 0 60.5%

      \[\leadsto \color{blue}{\frac{1}{a} \cdot \sqrt{-2 \cdot \left(a \cdot c\right) + a \cdot c}} \]
    7. Step-by-step derivation
      1. *-commutative60.5%

        \[\leadsto \color{blue}{\sqrt{-2 \cdot \left(a \cdot c\right) + a \cdot c} \cdot \frac{1}{a}} \]
      2. associate-*r/60.4%

        \[\leadsto \color{blue}{\frac{\sqrt{-2 \cdot \left(a \cdot c\right) + a \cdot c} \cdot 1}{a}} \]
      3. *-rgt-identity60.4%

        \[\leadsto \frac{\color{blue}{\sqrt{-2 \cdot \left(a \cdot c\right) + a \cdot c}}}{a} \]
      4. distribute-lft1-in60.9%

        \[\leadsto \frac{\sqrt{\color{blue}{\left(-2 + 1\right) \cdot \left(a \cdot c\right)}}}{a} \]
      5. metadata-eval60.9%

        \[\leadsto \frac{\sqrt{\color{blue}{-1} \cdot \left(a \cdot c\right)}}{a} \]
      6. neg-mul-160.9%

        \[\leadsto \frac{\sqrt{\color{blue}{-a \cdot c}}}{a} \]
      7. *-commutative60.9%

        \[\leadsto \frac{\sqrt{-\color{blue}{c \cdot a}}}{a} \]
      8. distribute-rgt-neg-out60.9%

        \[\leadsto \frac{\sqrt{\color{blue}{c \cdot \left(-a\right)}}}{a} \]
    8. Simplified60.9%

      \[\leadsto \color{blue}{\frac{\sqrt{c \cdot \left(-a\right)}}{a}} \]

    if 1.7500000000000001e-11 < b_2

    1. Initial program 14.8%

      \[\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
    2. Step-by-step derivation
      1. +-commutative14.8%

        \[\leadsto \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} + \left(-b_2\right)}}{a} \]
      2. unsub-neg14.8%

        \[\leadsto \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}}{a} \]
    3. Simplified14.8%

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}} \]
    4. Taylor expanded in b_2 around inf 89.6%

      \[\leadsto \color{blue}{-0.5 \cdot \frac{c}{b_2}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification79.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;b_2 \leq -4.7 \cdot 10^{-70}:\\ \;\;\;\;-2 \cdot \frac{b_2}{a} + \frac{c}{b_2} \cdot 0.5\\ \mathbf{elif}\;b_2 \leq 1.75 \cdot 10^{-11}:\\ \;\;\;\;\frac{\sqrt{a \cdot \left(-c\right)}}{a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b_2}\\ \end{array} \]

Alternative 4: 67.2% accurate, 8.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b_2 \leq -4 \cdot 10^{-310}:\\ \;\;\;\;-2 \cdot \frac{b_2}{a} + \frac{c}{b_2} \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b_2}\\ \end{array} \end{array} \]
(FPCore (a b_2 c)
 :precision binary64
 (if (<= b_2 -4e-310)
   (+ (* -2.0 (/ b_2 a)) (* (/ c b_2) 0.5))
   (* -0.5 (/ c b_2))))
double code(double a, double b_2, double c) {
	double tmp;
	if (b_2 <= -4e-310) {
		tmp = (-2.0 * (b_2 / a)) + ((c / b_2) * 0.5);
	} else {
		tmp = -0.5 * (c / b_2);
	}
	return tmp;
}
real(8) function code(a, b_2, c)
    real(8), intent (in) :: a
    real(8), intent (in) :: b_2
    real(8), intent (in) :: c
    real(8) :: tmp
    if (b_2 <= (-4d-310)) then
        tmp = ((-2.0d0) * (b_2 / a)) + ((c / b_2) * 0.5d0)
    else
        tmp = (-0.5d0) * (c / b_2)
    end if
    code = tmp
end function
public static double code(double a, double b_2, double c) {
	double tmp;
	if (b_2 <= -4e-310) {
		tmp = (-2.0 * (b_2 / a)) + ((c / b_2) * 0.5);
	} else {
		tmp = -0.5 * (c / b_2);
	}
	return tmp;
}
def code(a, b_2, c):
	tmp = 0
	if b_2 <= -4e-310:
		tmp = (-2.0 * (b_2 / a)) + ((c / b_2) * 0.5)
	else:
		tmp = -0.5 * (c / b_2)
	return tmp
function code(a, b_2, c)
	tmp = 0.0
	if (b_2 <= -4e-310)
		tmp = Float64(Float64(-2.0 * Float64(b_2 / a)) + Float64(Float64(c / b_2) * 0.5));
	else
		tmp = Float64(-0.5 * Float64(c / b_2));
	end
	return tmp
end
function tmp_2 = code(a, b_2, c)
	tmp = 0.0;
	if (b_2 <= -4e-310)
		tmp = (-2.0 * (b_2 / a)) + ((c / b_2) * 0.5);
	else
		tmp = -0.5 * (c / b_2);
	end
	tmp_2 = tmp;
end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -4e-310], N[(N[(-2.0 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision] + N[(N[(c / b$95$2), $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision], N[(-0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b_2 \leq -4 \cdot 10^{-310}:\\
\;\;\;\;-2 \cdot \frac{b_2}{a} + \frac{c}{b_2} \cdot 0.5\\

\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{c}{b_2}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if b_2 < -3.999999999999988e-310

    1. Initial program 68.5%

      \[\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
    2. Step-by-step derivation
      1. +-commutative68.5%

        \[\leadsto \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} + \left(-b_2\right)}}{a} \]
      2. unsub-neg68.5%

        \[\leadsto \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}}{a} \]
    3. Simplified68.5%

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}} \]
    4. Taylor expanded in b_2 around -inf 70.5%

      \[\leadsto \color{blue}{-2 \cdot \frac{b_2}{a} + 0.5 \cdot \frac{c}{b_2}} \]

    if -3.999999999999988e-310 < b_2

    1. Initial program 32.3%

      \[\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
    2. Step-by-step derivation
      1. +-commutative32.3%

        \[\leadsto \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} + \left(-b_2\right)}}{a} \]
      2. unsub-neg32.3%

        \[\leadsto \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}}{a} \]
    3. Simplified32.3%

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}} \]
    4. Taylor expanded in b_2 around inf 63.2%

      \[\leadsto \color{blue}{-0.5 \cdot \frac{c}{b_2}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification66.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;b_2 \leq -4 \cdot 10^{-310}:\\ \;\;\;\;-2 \cdot \frac{b_2}{a} + \frac{c}{b_2} \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b_2}\\ \end{array} \]

Alternative 5: 67.0% accurate, 15.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b_2 \leq 2.9 \cdot 10^{-289}:\\ \;\;\;\;-2 \cdot \frac{b_2}{a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b_2}\\ \end{array} \end{array} \]
(FPCore (a b_2 c)
 :precision binary64
 (if (<= b_2 2.9e-289) (* -2.0 (/ b_2 a)) (* -0.5 (/ c b_2))))
double code(double a, double b_2, double c) {
	double tmp;
	if (b_2 <= 2.9e-289) {
		tmp = -2.0 * (b_2 / a);
	} else {
		tmp = -0.5 * (c / b_2);
	}
	return tmp;
}
real(8) function code(a, b_2, c)
    real(8), intent (in) :: a
    real(8), intent (in) :: b_2
    real(8), intent (in) :: c
    real(8) :: tmp
    if (b_2 <= 2.9d-289) then
        tmp = (-2.0d0) * (b_2 / a)
    else
        tmp = (-0.5d0) * (c / b_2)
    end if
    code = tmp
end function
public static double code(double a, double b_2, double c) {
	double tmp;
	if (b_2 <= 2.9e-289) {
		tmp = -2.0 * (b_2 / a);
	} else {
		tmp = -0.5 * (c / b_2);
	}
	return tmp;
}
def code(a, b_2, c):
	tmp = 0
	if b_2 <= 2.9e-289:
		tmp = -2.0 * (b_2 / a)
	else:
		tmp = -0.5 * (c / b_2)
	return tmp
function code(a, b_2, c)
	tmp = 0.0
	if (b_2 <= 2.9e-289)
		tmp = Float64(-2.0 * Float64(b_2 / a));
	else
		tmp = Float64(-0.5 * Float64(c / b_2));
	end
	return tmp
end
function tmp_2 = code(a, b_2, c)
	tmp = 0.0;
	if (b_2 <= 2.9e-289)
		tmp = -2.0 * (b_2 / a);
	else
		tmp = -0.5 * (c / b_2);
	end
	tmp_2 = tmp;
end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, 2.9e-289], N[(-2.0 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision], N[(-0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b_2 \leq 2.9 \cdot 10^{-289}:\\
\;\;\;\;-2 \cdot \frac{b_2}{a}\\

\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{c}{b_2}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if b_2 < 2.90000000000000006e-289

    1. Initial program 68.5%

      \[\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
    2. Step-by-step derivation
      1. +-commutative68.5%

        \[\leadsto \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} + \left(-b_2\right)}}{a} \]
      2. unsub-neg68.5%

        \[\leadsto \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}}{a} \]
    3. Simplified68.5%

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}} \]
    4. Taylor expanded in b_2 around -inf 68.7%

      \[\leadsto \color{blue}{-2 \cdot \frac{b_2}{a}} \]

    if 2.90000000000000006e-289 < b_2

    1. Initial program 31.5%

      \[\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
    2. Step-by-step derivation
      1. +-commutative31.5%

        \[\leadsto \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} + \left(-b_2\right)}}{a} \]
      2. unsub-neg31.5%

        \[\leadsto \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}}{a} \]
    3. Simplified31.5%

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}} \]
    4. Taylor expanded in b_2 around inf 64.5%

      \[\leadsto \color{blue}{-0.5 \cdot \frac{c}{b_2}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification66.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;b_2 \leq 2.9 \cdot 10^{-289}:\\ \;\;\;\;-2 \cdot \frac{b_2}{a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b_2}\\ \end{array} \]

Alternative 6: 34.3% accurate, 22.4× speedup?

\[\begin{array}{l} \\ -2 \cdot \frac{b_2}{a} \end{array} \]
(FPCore (a b_2 c) :precision binary64 (* -2.0 (/ b_2 a)))
double code(double a, double b_2, double c) {
	return -2.0 * (b_2 / a);
}
real(8) function code(a, b_2, c)
    real(8), intent (in) :: a
    real(8), intent (in) :: b_2
    real(8), intent (in) :: c
    code = (-2.0d0) * (b_2 / a)
end function
public static double code(double a, double b_2, double c) {
	return -2.0 * (b_2 / a);
}
def code(a, b_2, c):
	return -2.0 * (b_2 / a)
function code(a, b_2, c)
	return Float64(-2.0 * Float64(b_2 / a))
end
function tmp = code(a, b_2, c)
	tmp = -2.0 * (b_2 / a);
end
code[a_, b$95$2_, c_] := N[(-2.0 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
-2 \cdot \frac{b_2}{a}
\end{array}
Derivation
  1. Initial program 49.1%

    \[\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
  2. Step-by-step derivation
    1. +-commutative49.1%

      \[\leadsto \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} + \left(-b_2\right)}}{a} \]
    2. unsub-neg49.1%

      \[\leadsto \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}}{a} \]
  3. Simplified49.1%

    \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}} \]
  4. Taylor expanded in b_2 around -inf 33.9%

    \[\leadsto \color{blue}{-2 \cdot \frac{b_2}{a}} \]
  5. Final simplification33.9%

    \[\leadsto -2 \cdot \frac{b_2}{a} \]

Reproduce

?
herbie shell --seed 2023287 
(FPCore (a b_2 c)
  :name "quad2p (problem 3.2.1, positive)"
  :precision binary64
  (/ (+ (- b_2) (sqrt (- (* b_2 b_2) (* a c)))) a))