quad2p (problem 3.2.1, positive)

?

Percentage Accurate: 52.1% → 85.4%
Time: 17.2s
Precision: binary64
Cost: 7368

?

\[\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
\[\begin{array}{l} \mathbf{if}\;b_2 \leq -1 \cdot 10^{+156}:\\ \;\;\;\;\frac{b_2 \cdot -2}{a}\\ \mathbf{elif}\;b_2 \leq 7.4 \cdot 10^{-144}:\\ \;\;\;\;\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b_2}\\ \end{array} \]
(FPCore (a b_2 c)
 :precision binary64
 (/ (+ (- b_2) (sqrt (- (* b_2 b_2) (* a c)))) a))
(FPCore (a b_2 c)
 :precision binary64
 (if (<= b_2 -1e+156)
   (/ (* b_2 -2.0) a)
   (if (<= b_2 7.4e-144)
     (/ (- (sqrt (- (* b_2 b_2) (* a c))) b_2) a)
     (/ (* c -0.5) b_2))))
double code(double a, double b_2, double c) {
	return (-b_2 + sqrt(((b_2 * b_2) - (a * c)))) / a;
}
double code(double a, double b_2, double c) {
	double tmp;
	if (b_2 <= -1e+156) {
		tmp = (b_2 * -2.0) / a;
	} else if (b_2 <= 7.4e-144) {
		tmp = (sqrt(((b_2 * b_2) - (a * c))) - b_2) / a;
	} else {
		tmp = (c * -0.5) / 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
    code = (-b_2 + sqrt(((b_2 * b_2) - (a * c)))) / a
end function
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 <= (-1d+156)) then
        tmp = (b_2 * (-2.0d0)) / a
    else if (b_2 <= 7.4d-144) then
        tmp = (sqrt(((b_2 * b_2) - (a * c))) - b_2) / a
    else
        tmp = (c * (-0.5d0)) / b_2
    end if
    code = tmp
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;
}
public static double code(double a, double b_2, double c) {
	double tmp;
	if (b_2 <= -1e+156) {
		tmp = (b_2 * -2.0) / a;
	} else if (b_2 <= 7.4e-144) {
		tmp = (Math.sqrt(((b_2 * b_2) - (a * c))) - b_2) / a;
	} else {
		tmp = (c * -0.5) / b_2;
	}
	return tmp;
}
def code(a, b_2, c):
	return (-b_2 + math.sqrt(((b_2 * b_2) - (a * c)))) / a
def code(a, b_2, c):
	tmp = 0
	if b_2 <= -1e+156:
		tmp = (b_2 * -2.0) / a
	elif b_2 <= 7.4e-144:
		tmp = (math.sqrt(((b_2 * b_2) - (a * c))) - b_2) / a
	else:
		tmp = (c * -0.5) / b_2
	return tmp
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 code(a, b_2, c)
	tmp = 0.0
	if (b_2 <= -1e+156)
		tmp = Float64(Float64(b_2 * -2.0) / a);
	elseif (b_2 <= 7.4e-144)
		tmp = Float64(Float64(sqrt(Float64(Float64(b_2 * b_2) - Float64(a * c))) - b_2) / a);
	else
		tmp = Float64(Float64(c * -0.5) / b_2);
	end
	return tmp
end
function tmp = code(a, b_2, c)
	tmp = (-b_2 + sqrt(((b_2 * b_2) - (a * c)))) / a;
end
function tmp_2 = code(a, b_2, c)
	tmp = 0.0;
	if (b_2 <= -1e+156)
		tmp = (b_2 * -2.0) / a;
	elseif (b_2 <= 7.4e-144)
		tmp = (sqrt(((b_2 * b_2) - (a * c))) - b_2) / a;
	else
		tmp = (c * -0.5) / b_2;
	end
	tmp_2 = tmp;
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]
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -1e+156], N[(N[(b$95$2 * -2.0), $MachinePrecision] / a), $MachinePrecision], If[LessEqual[b$95$2, 7.4e-144], 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[(N[(c * -0.5), $MachinePrecision] / b$95$2), $MachinePrecision]]]
\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}
\begin{array}{l}
\mathbf{if}\;b_2 \leq -1 \cdot 10^{+156}:\\
\;\;\;\;\frac{b_2 \cdot -2}{a}\\

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

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


\end{array}

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.

Herbie found 7 alternatives:

AlternativeAccuracySpeedup

Accuracy vs Speed

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.

Bogosity?

Bogosity

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Split input into 3 regimes
  2. if b_2 < -9.9999999999999998e155

    1. Initial program 52.5%

      \[\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
    2. Simplified52.5%

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}} \]
      Step-by-step derivation

      [Start]52.5%

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

      +-commutative [=>]52.5%

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

      unsub-neg [=>]52.5%

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

      \[\leadsto \frac{\color{blue}{-2 \cdot b_2}}{a} \]
    4. Simplified100.0%

      \[\leadsto \frac{\color{blue}{b_2 \cdot -2}}{a} \]
      Step-by-step derivation

      [Start]100.0%

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

      *-commutative [=>]100.0%

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

    if -9.9999999999999998e155 < b_2 < 7.4000000000000005e-144

    1. Initial program 85.6%

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

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}} \]
      Step-by-step derivation

      [Start]85.6%

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

      +-commutative [=>]85.6%

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

      unsub-neg [=>]85.6%

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

    if 7.4000000000000005e-144 < b_2

    1. Initial program 16.9%

      \[\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
    2. Simplified16.9%

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}} \]
      Step-by-step derivation

      [Start]16.9%

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

      +-commutative [=>]16.9%

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

      unsub-neg [=>]16.9%

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

      \[\leadsto \color{blue}{-0.5 \cdot \frac{c}{b_2}} \]
    4. Applied egg-rr78.0%

      \[\leadsto \color{blue}{\frac{-0.5 \cdot c}{b_2}} \]
      Step-by-step derivation

      [Start]78.0%

      \[ -0.5 \cdot \frac{c}{b_2} \]

      associate-*r/ [=>]78.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b_2 \leq -1 \cdot 10^{+156}:\\ \;\;\;\;\frac{b_2 \cdot -2}{a}\\ \mathbf{elif}\;b_2 \leq 7.4 \cdot 10^{-144}:\\ \;\;\;\;\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b_2}\\ \end{array} \]

Alternatives

Alternative 1
Accuracy85.4%
Cost7368
\[\begin{array}{l} \mathbf{if}\;b_2 \leq -1 \cdot 10^{+156}:\\ \;\;\;\;\frac{b_2 \cdot -2}{a}\\ \mathbf{elif}\;b_2 \leq 7.4 \cdot 10^{-144}:\\ \;\;\;\;\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b_2}\\ \end{array} \]
Alternative 2
Accuracy80.8%
Cost7176
\[\begin{array}{l} \mathbf{if}\;b_2 \leq -3.8 \cdot 10^{-47}:\\ \;\;\;\;-2 \cdot \frac{b_2}{a} + 0.5 \cdot \frac{c}{b_2}\\ \mathbf{elif}\;b_2 \leq 7.4 \cdot 10^{-144}:\\ \;\;\;\;\frac{\sqrt{a \cdot \left(-c\right)} - b_2}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b_2}\\ \end{array} \]
Alternative 3
Accuracy80.4%
Cost7048
\[\begin{array}{l} \mathbf{if}\;b_2 \leq -9.2 \cdot 10^{-58}:\\ \;\;\;\;-2 \cdot \frac{b_2}{a} + 0.5 \cdot \frac{c}{b_2}\\ \mathbf{elif}\;b_2 \leq 3.1 \cdot 10^{-144}:\\ \;\;\;\;\frac{\sqrt{a \cdot \left(-c\right)}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b_2}\\ \end{array} \]
Alternative 4
Accuracy68.1%
Cost836
\[\begin{array}{l} \mathbf{if}\;b_2 \leq -5 \cdot 10^{-310}:\\ \;\;\;\;-2 \cdot \frac{b_2}{a} + 0.5 \cdot \frac{c}{b_2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b_2}\\ \end{array} \]
Alternative 5
Accuracy68.0%
Cost452
\[\begin{array}{l} \mathbf{if}\;b_2 \leq -5 \cdot 10^{-310}:\\ \;\;\;\;\frac{b_2 \cdot -2}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b_2}\\ \end{array} \]
Alternative 6
Accuracy35.2%
Cost320
\[-0.5 \cdot \frac{c}{b_2} \]
Alternative 7
Accuracy35.2%
Cost320
\[\frac{c \cdot -0.5}{b_2} \]

Reproduce?

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