quad2m (problem 3.2.1, negative)

?

Percentage Accurate: 51.2% → 84.7%
Time: 17.4s
Precision: binary64
Cost: 13904

?

\[\frac{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
\[\begin{array}{l} t_0 := \frac{-0.5 \cdot c}{b_2}\\ t_1 := \frac{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - c \cdot a}}{a}\\ \mathbf{if}\;b_2 \leq -9 \cdot 10^{-24}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;b_2 \leq -8 \cdot 10^{-50}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b_2 \leq -1.6 \cdot 10^{-77}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;b_2 \leq -1.15 \cdot 10^{-134}:\\ \;\;\;\;\frac{\left(-b_2\right) - \sqrt{-a} \cdot \sqrt{c}}{a}\\ \mathbf{elif}\;b_2 \leq 1.9 \cdot 10^{+101}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \frac{b_2}{a} + 0.5 \cdot \frac{c}{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
 (let* ((t_0 (/ (* -0.5 c) b_2))
        (t_1 (/ (- (- b_2) (sqrt (- (* b_2 b_2) (* c a)))) a)))
   (if (<= b_2 -9e-24)
     t_0
     (if (<= b_2 -8e-50)
       t_1
       (if (<= b_2 -1.6e-77)
         t_0
         (if (<= b_2 -1.15e-134)
           (/ (- (- b_2) (* (sqrt (- a)) (sqrt c))) a)
           (if (<= b_2 1.9e+101)
             t_1
             (+ (* -2.0 (/ b_2 a)) (* 0.5 (/ c 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 t_0 = (-0.5 * c) / b_2;
	double t_1 = (-b_2 - sqrt(((b_2 * b_2) - (c * a)))) / a;
	double tmp;
	if (b_2 <= -9e-24) {
		tmp = t_0;
	} else if (b_2 <= -8e-50) {
		tmp = t_1;
	} else if (b_2 <= -1.6e-77) {
		tmp = t_0;
	} else if (b_2 <= -1.15e-134) {
		tmp = (-b_2 - (sqrt(-a) * sqrt(c))) / a;
	} else if (b_2 <= 1.9e+101) {
		tmp = t_1;
	} else {
		tmp = (-2.0 * (b_2 / a)) + (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
    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) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = ((-0.5d0) * c) / b_2
    t_1 = (-b_2 - sqrt(((b_2 * b_2) - (c * a)))) / a
    if (b_2 <= (-9d-24)) then
        tmp = t_0
    else if (b_2 <= (-8d-50)) then
        tmp = t_1
    else if (b_2 <= (-1.6d-77)) then
        tmp = t_0
    else if (b_2 <= (-1.15d-134)) then
        tmp = (-b_2 - (sqrt(-a) * sqrt(c))) / a
    else if (b_2 <= 1.9d+101) then
        tmp = t_1
    else
        tmp = ((-2.0d0) * (b_2 / a)) + (0.5d0 * (c / 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 t_0 = (-0.5 * c) / b_2;
	double t_1 = (-b_2 - Math.sqrt(((b_2 * b_2) - (c * a)))) / a;
	double tmp;
	if (b_2 <= -9e-24) {
		tmp = t_0;
	} else if (b_2 <= -8e-50) {
		tmp = t_1;
	} else if (b_2 <= -1.6e-77) {
		tmp = t_0;
	} else if (b_2 <= -1.15e-134) {
		tmp = (-b_2 - (Math.sqrt(-a) * Math.sqrt(c))) / a;
	} else if (b_2 <= 1.9e+101) {
		tmp = t_1;
	} else {
		tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / 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):
	t_0 = (-0.5 * c) / b_2
	t_1 = (-b_2 - math.sqrt(((b_2 * b_2) - (c * a)))) / a
	tmp = 0
	if b_2 <= -9e-24:
		tmp = t_0
	elif b_2 <= -8e-50:
		tmp = t_1
	elif b_2 <= -1.6e-77:
		tmp = t_0
	elif b_2 <= -1.15e-134:
		tmp = (-b_2 - (math.sqrt(-a) * math.sqrt(c))) / a
	elif b_2 <= 1.9e+101:
		tmp = t_1
	else:
		tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / 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)
	t_0 = Float64(Float64(-0.5 * c) / b_2)
	t_1 = Float64(Float64(Float64(-b_2) - sqrt(Float64(Float64(b_2 * b_2) - Float64(c * a)))) / a)
	tmp = 0.0
	if (b_2 <= -9e-24)
		tmp = t_0;
	elseif (b_2 <= -8e-50)
		tmp = t_1;
	elseif (b_2 <= -1.6e-77)
		tmp = t_0;
	elseif (b_2 <= -1.15e-134)
		tmp = Float64(Float64(Float64(-b_2) - Float64(sqrt(Float64(-a)) * sqrt(c))) / a);
	elseif (b_2 <= 1.9e+101)
		tmp = t_1;
	else
		tmp = Float64(Float64(-2.0 * Float64(b_2 / a)) + Float64(0.5 * Float64(c / 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)
	t_0 = (-0.5 * c) / b_2;
	t_1 = (-b_2 - sqrt(((b_2 * b_2) - (c * a)))) / a;
	tmp = 0.0;
	if (b_2 <= -9e-24)
		tmp = t_0;
	elseif (b_2 <= -8e-50)
		tmp = t_1;
	elseif (b_2 <= -1.6e-77)
		tmp = t_0;
	elseif (b_2 <= -1.15e-134)
		tmp = (-b_2 - (sqrt(-a) * sqrt(c))) / a;
	elseif (b_2 <= 1.9e+101)
		tmp = t_1;
	else
		tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / 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_] := Block[{t$95$0 = N[(N[(-0.5 * c), $MachinePrecision] / b$95$2), $MachinePrecision]}, Block[{t$95$1 = N[(N[((-b$95$2) - N[Sqrt[N[(N[(b$95$2 * b$95$2), $MachinePrecision] - N[(c * a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]}, If[LessEqual[b$95$2, -9e-24], t$95$0, If[LessEqual[b$95$2, -8e-50], t$95$1, If[LessEqual[b$95$2, -1.6e-77], t$95$0, If[LessEqual[b$95$2, -1.15e-134], N[(N[((-b$95$2) - N[(N[Sqrt[(-a)], $MachinePrecision] * N[Sqrt[c], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision], If[LessEqual[b$95$2, 1.9e+101], t$95$1, N[(N[(-2.0 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]]
\frac{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}
\begin{array}{l}
t_0 := \frac{-0.5 \cdot c}{b_2}\\
t_1 := \frac{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - c \cdot a}}{a}\\
\mathbf{if}\;b_2 \leq -9 \cdot 10^{-24}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;b_2 \leq -8 \cdot 10^{-50}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;b_2 \leq -1.6 \cdot 10^{-77}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;b_2 \leq 1.9 \cdot 10^{+101}:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;-2 \cdot \frac{b_2}{a} + 0.5 \cdot \frac{c}{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 9 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 4 regimes
  2. if b_2 < -8.9999999999999995e-24 or -8.00000000000000006e-50 < b_2 < -1.6e-77

    1. Initial program 17.7%

      \[\frac{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
    2. Taylor expanded in b_2 around -inf 86.4%

      \[\leadsto \color{blue}{-0.5 \cdot \frac{c}{b_2}} \]
    3. Simplified86.4%

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

      [Start]86.4%

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

      associate-*r/ [=>]86.4%

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

    if -8.9999999999999995e-24 < b_2 < -8.00000000000000006e-50 or -1.15e-134 < b_2 < 1.8999999999999999e101

    1. Initial program 81.2%

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

    if -1.6e-77 < b_2 < -1.15e-134

    1. Initial program 46.5%

      \[\frac{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
    2. Taylor expanded in b_2 around 0 43.6%

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

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

      [Start]43.6%

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

      mul-1-neg [=>]43.6%

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

      distribute-rgt-neg-out [<=]43.6%

      \[ \frac{\left(-b_2\right) - \sqrt{\color{blue}{c \cdot \left(-a\right)}}}{a} \]
    4. Applied egg-rr75.1%

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

      [Start]43.6%

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

      *-commutative [=>]43.6%

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

      sqrt-prod [=>]75.1%

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

    if 1.8999999999999999e101 < b_2

    1. Initial program 54.5%

      \[\frac{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
    2. Taylor expanded in b_2 around inf 94.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b_2 \leq -9 \cdot 10^{-24}:\\ \;\;\;\;\frac{-0.5 \cdot c}{b_2}\\ \mathbf{elif}\;b_2 \leq -8 \cdot 10^{-50}:\\ \;\;\;\;\frac{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - c \cdot a}}{a}\\ \mathbf{elif}\;b_2 \leq -1.6 \cdot 10^{-77}:\\ \;\;\;\;\frac{-0.5 \cdot c}{b_2}\\ \mathbf{elif}\;b_2 \leq -1.15 \cdot 10^{-134}:\\ \;\;\;\;\frac{\left(-b_2\right) - \sqrt{-a} \cdot \sqrt{c}}{a}\\ \mathbf{elif}\;b_2 \leq 1.9 \cdot 10^{+101}:\\ \;\;\;\;\frac{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - c \cdot a}}{a}\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \frac{b_2}{a} + 0.5 \cdot \frac{c}{b_2}\\ \end{array} \]

Alternatives

Alternative 1
Accuracy84.7%
Cost13904
\[\begin{array}{l} t_0 := \frac{-0.5 \cdot c}{b_2}\\ t_1 := \frac{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - c \cdot a}}{a}\\ \mathbf{if}\;b_2 \leq -9 \cdot 10^{-24}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;b_2 \leq -8 \cdot 10^{-50}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b_2 \leq -1.6 \cdot 10^{-77}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;b_2 \leq -1.15 \cdot 10^{-134}:\\ \;\;\;\;\frac{\left(-b_2\right) - \sqrt{-a} \cdot \sqrt{c}}{a}\\ \mathbf{elif}\;b_2 \leq 1.9 \cdot 10^{+101}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \frac{b_2}{a} + 0.5 \cdot \frac{c}{b_2}\\ \end{array} \]
Alternative 2
Accuracy85.5%
Cost14088
\[\begin{array}{l} t_0 := \frac{-0.5 \cdot c}{b_2}\\ \mathbf{if}\;b_2 \leq -1.05 \cdot 10^{-22}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;b_2 \leq -4.2 \cdot 10^{-61}:\\ \;\;\;\;\frac{c \cdot a}{b_2 - \mathsf{hypot}\left(b_2, \sqrt{c \cdot \left(-a\right)}\right)} \cdot \frac{1}{-a}\\ \mathbf{elif}\;b_2 \leq -9 \cdot 10^{-118}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;b_2 \leq 1.25 \cdot 10^{+101}:\\ \;\;\;\;\frac{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - c \cdot a}}{a}\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \frac{b_2}{a} + 0.5 \cdot \frac{c}{b_2}\\ \end{array} \]
Alternative 3
Accuracy80.8%
Cost7504
\[\begin{array}{l} t_0 := \frac{-0.5 \cdot c}{b_2}\\ t_1 := \frac{\left(-b_2\right) - \sqrt{c \cdot \left(-a\right)}}{a}\\ \mathbf{if}\;b_2 \leq -1.05 \cdot 10^{-23}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;b_2 \leq -2.1 \cdot 10^{-49}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b_2 \leq -3.2 \cdot 10^{-121}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;b_2 \leq 9.4 \cdot 10^{-91}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \frac{b_2}{a} + 0.5 \cdot \frac{c}{b_2}\\ \end{array} \]
Alternative 4
Accuracy85.4%
Cost7432
\[\begin{array}{l} \mathbf{if}\;b_2 \leq -1.2 \cdot 10^{-23}:\\ \;\;\;\;\frac{-0.5 \cdot c}{b_2}\\ \mathbf{elif}\;b_2 \leq 1.4 \cdot 10^{+99}:\\ \;\;\;\;\frac{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - c \cdot a}}{a}\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \frac{b_2}{a} + 0.5 \cdot \frac{c}{b_2}\\ \end{array} \]
Alternative 5
Accuracy68.7%
Cost836
\[\begin{array}{l} \mathbf{if}\;b_2 \leq -1 \cdot 10^{-310}:\\ \;\;\;\;\frac{-0.5 \cdot c}{b_2}\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \frac{b_2}{a} + 0.5 \cdot \frac{c}{b_2}\\ \end{array} \]
Alternative 6
Accuracy44.1%
Cost452
\[\begin{array}{l} \mathbf{if}\;b_2 \leq 5.6 \cdot 10^{-305}:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \frac{b_2}{a}\\ \end{array} \]
Alternative 7
Accuracy68.4%
Cost452
\[\begin{array}{l} \mathbf{if}\;b_2 \leq -2.6 \cdot 10^{-266}:\\ \;\;\;\;\frac{-0.5 \cdot c}{b_2}\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \frac{b_2}{a}\\ \end{array} \]
Alternative 8
Accuracy23.7%
Cost388
\[\begin{array}{l} \mathbf{if}\;b_2 \leq 2 \cdot 10^{-305}:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;\frac{-b_2}{a}\\ \end{array} \]
Alternative 9
Accuracy11.4%
Cost64
\[0 \]

Reproduce?

herbie shell --seed 2023263 
(FPCore (a b_2 c)
  :name "quad2m (problem 3.2.1, negative)"
  :precision binary64
  (/ (- (- b_2) (sqrt (- (* b_2 b_2) (* a c)))) a))