?

Average Accuracy: 46.3% → 84.1%
Time: 18.5s
Precision: binary64
Cost: 7624

?

\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a} \]
\[\begin{array}{l} \mathbf{if}\;b \leq -5 \cdot 10^{+154}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{elif}\;b \leq 1.26 \cdot 10^{-80}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}{a \cdot 2}\\ \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
 (if (<= b -5e+154)
   (/ (- b) a)
   (if (<= b 1.26e-80)
     (/ (- (sqrt (- (* b b) (* 4.0 (* a c)))) b) (* a 2.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 tmp;
	if (b <= -5e+154) {
		tmp = -b / a;
	} else if (b <= 1.26e-80) {
		tmp = (sqrt(((b * b) - (4.0 * (a * c)))) - b) / (a * 2.0);
	} else {
		tmp = -c / b;
	}
	return tmp;
}
real(8) function code(a, b, c)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    code = (-b + sqrt(((b * b) - (4.0d0 * (a * c))))) / (2.0d0 * a)
end function
real(8) function code(a, b, c)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8) :: tmp
    if (b <= (-5d+154)) then
        tmp = -b / a
    else if (b <= 1.26d-80) then
        tmp = (sqrt(((b * b) - (4.0d0 * (a * c)))) - b) / (a * 2.0d0)
    else
        tmp = -c / b
    end if
    code = tmp
end function
public static double code(double a, double b, double c) {
	return (-b + Math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
public static double code(double a, double b, double c) {
	double tmp;
	if (b <= -5e+154) {
		tmp = -b / a;
	} else if (b <= 1.26e-80) {
		tmp = (Math.sqrt(((b * b) - (4.0 * (a * c)))) - b) / (a * 2.0);
	} else {
		tmp = -c / b;
	}
	return tmp;
}
def code(a, b, c):
	return (-b + math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a)
def code(a, b, c):
	tmp = 0
	if b <= -5e+154:
		tmp = -b / a
	elif b <= 1.26e-80:
		tmp = (math.sqrt(((b * b) - (4.0 * (a * c)))) - b) / (a * 2.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)
	tmp = 0.0
	if (b <= -5e+154)
		tmp = Float64(Float64(-b) / a);
	elseif (b <= 1.26e-80)
		tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c)))) - b) / Float64(a * 2.0));
	else
		tmp = Float64(Float64(-c) / b);
	end
	return tmp
end
function tmp = code(a, b, c)
	tmp = (-b + sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
end
function tmp_2 = code(a, b, c)
	tmp = 0.0;
	if (b <= -5e+154)
		tmp = -b / a;
	elseif (b <= 1.26e-80)
		tmp = (sqrt(((b * b) - (4.0 * (a * c)))) - b) / (a * 2.0);
	else
		tmp = -c / b;
	end
	tmp_2 = 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_] := If[LessEqual[b, -5e+154], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 1.26e-80], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $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}
\mathbf{if}\;b \leq -5 \cdot 10^{+154}:\\
\;\;\;\;\frac{-b}{a}\\

\mathbf{elif}\;b \leq 1.26 \cdot 10^{-80}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}{a \cdot 2}\\

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


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original46.3%
Target67.3%
Herbie84.1%
\[\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 3 regimes
  2. if b < -5.00000000000000004e154

    1. Initial program 0.0%

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

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

      [Start]0.0

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

      /-rgt-identity [<=]0.0

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

      metadata-eval [<=]0.0

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

      *-commutative [=>]0.0

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

      associate-/l* [=>]0.0

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

      associate-/l* [<=]0.0

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

      associate-*r/ [<=]0.0

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

      /-rgt-identity [<=]0.0

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

      metadata-eval [<=]0.0

      \[ \frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{\color{blue}{--1}} \cdot \frac{\frac{--1}{2}}{a} \]
    3. Taylor expanded in b around -inf 97.0%

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

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

      [Start]97.0

      \[ -1 \cdot \frac{b}{a} \]

      associate-*r/ [=>]97.0

      \[ \color{blue}{\frac{-1 \cdot b}{a}} \]

      mul-1-neg [=>]97.0

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

    if -5.00000000000000004e154 < b < 1.26000000000000005e-80

    1. Initial program 80.2%

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

    if 1.26000000000000005e-80 < b

    1. Initial program 17.1%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a} \]
    2. Taylor expanded in b around inf 85.3%

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

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

      [Start]85.3

      \[ -1 \cdot \frac{c}{b} \]

      associate-*r/ [=>]85.3

      \[ \color{blue}{\frac{-1 \cdot c}{b}} \]

      neg-mul-1 [<=]85.3

      \[ \frac{\color{blue}{-c}}{b} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification84.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -5 \cdot 10^{+154}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{elif}\;b \leq 1.26 \cdot 10^{-80}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array} \]

Alternatives

Alternative 1
Accuracy84.0%
Cost7624
\[\begin{array}{l} \mathbf{if}\;b \leq -1.15 \cdot 10^{+112}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq 4.8 \cdot 10^{-81}:\\ \;\;\;\;\left(\sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)} - b\right) \cdot \frac{0.5}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array} \]
Alternative 2
Accuracy78.2%
Cost7368
\[\begin{array}{l} \mathbf{if}\;b \leq -1.65 \cdot 10^{-126}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq 3.6 \cdot 10^{-81}:\\ \;\;\;\;\frac{0.5}{a} \cdot \left(\sqrt{a \cdot \left(c \cdot -4\right)} - b\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array} \]
Alternative 3
Accuracy78.6%
Cost7368
\[\begin{array}{l} \mathbf{if}\;b \leq -1.4 \cdot 10^{-84}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq 6.2 \cdot 10^{-84}:\\ \;\;\;\;\frac{\frac{\sqrt{a \cdot \left(c \cdot -4\right)} - b}{a}}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array} \]
Alternative 4
Accuracy37.5%
Cost388
\[\begin{array}{l} \mathbf{if}\;b \leq 2.5 \cdot 10^{+24}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b}\\ \end{array} \]
Alternative 5
Accuracy64.4%
Cost388
\[\begin{array}{l} \mathbf{if}\;b \leq 7.2 \cdot 10^{-215}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array} \]
Alternative 6
Accuracy2.7%
Cost192
\[\frac{b}{a} \]
Alternative 7
Accuracy11.4%
Cost192
\[\frac{c}{b} \]

Error

Reproduce?

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