Average Error: 34.6 → 12.0
Time: 16.8s
Precision: binary64
Cost: 13832
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
\[\begin{array}{l} \mathbf{if}\;b \leq -1.82 \cdot 10^{+40}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{elif}\;b \leq 5.4 \cdot 10^{-31}:\\ \;\;\;\;\frac{0.5}{\frac{a}{\mathsf{hypot}\left(b, \sqrt{a \cdot \left(c \cdot -4\right)}\right) - b}}\\ \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 -1.82e+40)
   (/ (- b) a)
   (if (<= b 5.4e-31)
     (/ 0.5 (/ a (- (hypot b (sqrt (* a (* c -4.0)))) b)))
     (/ (- 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 <= -1.82e+40) {
		tmp = -b / a;
	} else if (b <= 5.4e-31) {
		tmp = 0.5 / (a / (hypot(b, sqrt((a * (c * -4.0)))) - b));
	} else {
		tmp = -c / b;
	}
	return tmp;
}
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 <= -1.82e+40) {
		tmp = -b / a;
	} else if (b <= 5.4e-31) {
		tmp = 0.5 / (a / (Math.hypot(b, Math.sqrt((a * (c * -4.0)))) - b));
	} 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 <= -1.82e+40:
		tmp = -b / a
	elif b <= 5.4e-31:
		tmp = 0.5 / (a / (math.hypot(b, math.sqrt((a * (c * -4.0)))) - b))
	else:
		tmp = -c / b
	return tmp
function code(a, b, c)
	return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c)))) / Float64(2.0 * a))
end
function code(a, b, c)
	tmp = 0.0
	if (b <= -1.82e+40)
		tmp = Float64(Float64(-b) / a);
	elseif (b <= 5.4e-31)
		tmp = Float64(0.5 / Float64(a / Float64(hypot(b, sqrt(Float64(a * Float64(c * -4.0)))) - b)));
	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 <= -1.82e+40)
		tmp = -b / a;
	elseif (b <= 5.4e-31)
		tmp = 0.5 / (a / (hypot(b, sqrt((a * (c * -4.0)))) - b));
	else
		tmp = -c / b;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
code[a_, b_, c_] := If[LessEqual[b, -1.82e+40], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 5.4e-31], N[(0.5 / N[(a / N[(N[Sqrt[b ^ 2 + N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] ^ 2], $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\begin{array}{l}
\mathbf{if}\;b \leq -1.82 \cdot 10^{+40}:\\
\;\;\;\;\frac{-b}{a}\\

\mathbf{elif}\;b \leq 5.4 \cdot 10^{-31}:\\
\;\;\;\;\frac{0.5}{\frac{a}{\mathsf{hypot}\left(b, \sqrt{a \cdot \left(c \cdot -4\right)}\right) - b}}\\

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


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 3 regimes
  2. if b < -1.82e40

    1. Initial program 36.8

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

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

      [Start]36.8

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

      /-rgt-identity [<=]36.8

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

      metadata-eval [<=]36.8

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

      *-commutative [=>]36.8

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

      associate-/l* [=>]36.8

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

      associate-/l* [<=]36.8

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

      associate-*r/ [<=]36.9

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

      /-rgt-identity [<=]36.9

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

      metadata-eval [<=]36.9

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

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}} \]
    4. Simplified5.8

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

      [Start]5.8

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

      associate-*r/ [=>]5.8

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

      mul-1-neg [=>]5.8

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

    if -1.82e40 < b < 5.40000000000000027e-31

    1. Initial program 16.0

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

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

      [Start]16.0

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

      /-rgt-identity [<=]16.0

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

      metadata-eval [<=]16.0

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

      *-commutative [=>]16.0

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

      associate-/l* [=>]16.0

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

      associate-/l* [<=]16.0

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

      associate-*r/ [<=]16.1

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

      /-rgt-identity [<=]16.1

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

      metadata-eval [<=]16.1

      \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{--1}} \cdot \frac{\frac{--1}{2}}{a} \]
    3. Applied egg-rr19.7

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

    if 5.40000000000000027e-31 < b

    1. Initial program 55.4

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

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

      [Start]55.4

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

      *-commutative [=>]55.4

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

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

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

      [Start]6.3

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

      mul-1-neg [=>]6.3

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

      distribute-neg-frac [=>]6.3

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1.82 \cdot 10^{+40}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{elif}\;b \leq 5.4 \cdot 10^{-31}:\\ \;\;\;\;\frac{0.5}{\frac{a}{\mathsf{hypot}\left(b, \sqrt{a \cdot \left(c \cdot -4\right)}\right) - b}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array} \]

Alternatives

Alternative 1
Error10.5
Cost7624
\[\begin{array}{l} \mathbf{if}\;b \leq -4 \cdot 10^{+33}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{elif}\;b \leq 3.5 \cdot 10^{-34}:\\ \;\;\;\;\left(\sqrt{a \cdot \left(c \cdot -4\right) + b \cdot b} - b\right) \cdot \frac{0.5}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array} \]
Alternative 2
Error10.4
Cost7624
\[\begin{array}{l} \mathbf{if}\;b \leq -4.5 \cdot 10^{+42}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{elif}\;b \leq 1.9 \cdot 10^{-34}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array} \]
Alternative 3
Error13.6
Cost7368
\[\begin{array}{l} \mathbf{if}\;b \leq -2.9 \cdot 10^{-27}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{elif}\;b \leq 3.65 \cdot 10^{-31}:\\ \;\;\;\;\frac{0.5}{a} \cdot \left(\sqrt{c \cdot \left(a \cdot -4\right)} - b\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array} \]
Alternative 4
Error13.6
Cost7368
\[\begin{array}{l} \mathbf{if}\;b \leq -3.7 \cdot 10^{-25}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{elif}\;b \leq 1.18 \cdot 10^{-33}:\\ \;\;\;\;\frac{\frac{\sqrt{c \cdot \left(a \cdot -4\right)} - b}{a}}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array} \]
Alternative 5
Error22.2
Cost580
\[\begin{array}{l} \mathbf{if}\;b \leq -4.3 \cdot 10^{-305}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array} \]
Alternative 6
Error39.9
Cost388
\[\begin{array}{l} \mathbf{if}\;b \leq 1.22 \cdot 10^{+63}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b}\\ \end{array} \]
Alternative 7
Error22.2
Cost388
\[\begin{array}{l} \mathbf{if}\;b \leq 3.45 \cdot 10^{-276}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array} \]
Alternative 8
Error62.3
Cost192
\[\frac{b}{a} \]
Alternative 9
Error56.4
Cost192
\[\frac{c}{b} \]

Error

Reproduce

herbie shell --seed 2023016 
(FPCore (a b c)
  :name "Quadratic roots, full range"
  :precision binary64
  (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))