?

Average Error: 33.9 → 11.4
Time: 19.4s
Precision: binary64
Cost: 7624

?

\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
\[\begin{array}{l} \mathbf{if}\;b \leq -3.7 \cdot 10^{+32}:\\ \;\;\;\;\mathsf{fma}\left(0.5, \frac{c}{b}, \frac{1}{a} \cdot \left(b \cdot -0.6666666666666666\right)\right)\\ \mathbf{elif}\;b \leq 1850000:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b}{a \cdot 3}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b}\\ \end{array} \]
(FPCore (a b c)
 :precision binary64
 (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))
(FPCore (a b c)
 :precision binary64
 (if (<= b -3.7e+32)
   (fma 0.5 (/ c b) (* (/ 1.0 a) (* b -0.6666666666666666)))
   (if (<= b 1850000.0)
     (/ (- (sqrt (- (* b b) (* c (* a 3.0)))) b) (* a 3.0))
     (/ (* c -0.5) b))))
double code(double a, double b, double c) {
	return (-b + sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a);
}
double code(double a, double b, double c) {
	double tmp;
	if (b <= -3.7e+32) {
		tmp = fma(0.5, (c / b), ((1.0 / a) * (b * -0.6666666666666666)));
	} else if (b <= 1850000.0) {
		tmp = (sqrt(((b * b) - (c * (a * 3.0)))) - b) / (a * 3.0);
	} else {
		tmp = (c * -0.5) / b;
	}
	return tmp;
}
function code(a, b, c)
	return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(3.0 * a) * c)))) / Float64(3.0 * a))
end
function code(a, b, c)
	tmp = 0.0
	if (b <= -3.7e+32)
		tmp = fma(0.5, Float64(c / b), Float64(Float64(1.0 / a) * Float64(b * -0.6666666666666666)));
	elseif (b <= 1850000.0)
		tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 3.0)))) - b) / Float64(a * 3.0));
	else
		tmp = Float64(Float64(c * -0.5) / b);
	end
	return tmp
end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(3.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(3.0 * a), $MachinePrecision]), $MachinePrecision]
code[a_, b_, c_] := If[LessEqual[b, -3.7e+32], N[(0.5 * N[(c / b), $MachinePrecision] + N[(N[(1.0 / a), $MachinePrecision] * N[(b * -0.6666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1850000.0], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision], N[(N[(c * -0.5), $MachinePrecision] / b), $MachinePrecision]]]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\begin{array}{l}
\mathbf{if}\;b \leq -3.7 \cdot 10^{+32}:\\
\;\;\;\;\mathsf{fma}\left(0.5, \frac{c}{b}, \frac{1}{a} \cdot \left(b \cdot -0.6666666666666666\right)\right)\\

\mathbf{elif}\;b \leq 1850000:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b}{a \cdot 3}\\

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


\end{array}

Error?

Derivation?

  1. Split input into 3 regimes
  2. if b < -3.7e32

    1. Initial program 35.2

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

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

      [Start]35.2

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

      *-lft-identity [<=]35.2

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

      metadata-eval [<=]35.2

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

      times-frac [<=]35.2

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

      *-commutative [<=]35.2

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

      times-frac [=>]35.3

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

      associate-*r/ [=>]35.2

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

      \[\leadsto \color{blue}{-0.6666666666666666 \cdot \frac{b}{a} + 0.5 \cdot \frac{c}{b}} \]
    4. Simplified7.5

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

      [Start]7.5

      \[ -0.6666666666666666 \cdot \frac{b}{a} + 0.5 \cdot \frac{c}{b} \]

      +-commutative [=>]7.5

      \[ \color{blue}{0.5 \cdot \frac{c}{b} + -0.6666666666666666 \cdot \frac{b}{a}} \]

      fma-def [=>]7.5

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

      associate-*r/ [=>]7.4

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

      associate-/l* [=>]7.5

      \[ \mathsf{fma}\left(0.5, \frac{c}{b}, \color{blue}{\frac{-0.6666666666666666}{\frac{a}{b}}}\right) \]
    5. Applied egg-rr7.5

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

    if -3.7e32 < b < 1.85e6

    1. Initial program 17.5

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

    if 1.85e6 < b

    1. Initial program 55.6

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

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

      [Start]55.6

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

      *-lft-identity [<=]55.6

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

      metadata-eval [<=]55.6

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

      times-frac [<=]55.6

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

      *-commutative [<=]55.6

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

      times-frac [=>]55.6

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

      associate-*r/ [=>]55.6

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

      \[\leadsto \color{blue}{-0.5 \cdot \frac{c}{b}} \]
    4. Simplified5.5

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

      [Start]5.5

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

      associate-*r/ [=>]5.5

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

      *-commutative [=>]5.5

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -3.7 \cdot 10^{+32}:\\ \;\;\;\;\mathsf{fma}\left(0.5, \frac{c}{b}, \frac{1}{a} \cdot \left(b \cdot -0.6666666666666666\right)\right)\\ \mathbf{elif}\;b \leq 1850000:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b}{a \cdot 3}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b}\\ \end{array} \]

Alternatives

Alternative 1
Error11.4
Cost7624
\[\begin{array}{l} \mathbf{if}\;b \leq -3.7 \cdot 10^{+32}:\\ \;\;\;\;\mathsf{fma}\left(0.5, \frac{c}{b}, \frac{1}{a} \cdot \left(b \cdot -0.6666666666666666\right)\right)\\ \mathbf{elif}\;b \leq 1850000:\\ \;\;\;\;\frac{\sqrt{b \cdot b + a \cdot \left(c \cdot -3\right)} - b}{a \cdot 3}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b}\\ \end{array} \]
Alternative 2
Error14.4
Cost7368
\[\begin{array}{l} \mathbf{if}\;b \leq -4.05 \cdot 10^{-75}:\\ \;\;\;\;-0.6666666666666666 \cdot \frac{b}{a} + 0.5 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \leq 0.09:\\ \;\;\;\;\left(b - \sqrt{c \cdot \left(a \cdot -3\right)}\right) \cdot \frac{-0.3333333333333333}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b}\\ \end{array} \]
Alternative 3
Error14.4
Cost7368
\[\begin{array}{l} \mathbf{if}\;b \leq -4.8 \cdot 10^{-75}:\\ \;\;\;\;-0.6666666666666666 \cdot \frac{b}{a} + 0.5 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \leq 0.09:\\ \;\;\;\;\frac{\sqrt{a \cdot \left(c \cdot -3\right)} - b}{a \cdot 3}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b}\\ \end{array} \]
Alternative 4
Error14.4
Cost7368
\[\begin{array}{l} \mathbf{if}\;b \leq -1.38 \cdot 10^{-76}:\\ \;\;\;\;\mathsf{fma}\left(0.5, \frac{c}{b}, \frac{1}{a} \cdot \left(b \cdot -0.6666666666666666\right)\right)\\ \mathbf{elif}\;b \leq 0.145:\\ \;\;\;\;\frac{\sqrt{a \cdot \left(c \cdot -3\right)} - b}{a \cdot 3}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b}\\ \end{array} \]
Alternative 5
Error23.0
Cost452
\[\begin{array}{l} \mathbf{if}\;b \leq 2.3 \cdot 10^{-178}:\\ \;\;\;\;b \cdot \frac{-0.6666666666666666}{a}\\ \mathbf{else}:\\ \;\;\;\;c \cdot \frac{-0.5}{b}\\ \end{array} \]
Alternative 6
Error22.9
Cost452
\[\begin{array}{l} \mathbf{if}\;b \leq 2.3 \cdot 10^{-178}:\\ \;\;\;\;\frac{b}{a \cdot -1.5}\\ \mathbf{else}:\\ \;\;\;\;c \cdot \frac{-0.5}{b}\\ \end{array} \]
Alternative 7
Error22.9
Cost452
\[\begin{array}{l} \mathbf{if}\;b \leq 2.3 \cdot 10^{-178}:\\ \;\;\;\;\frac{b \cdot -0.6666666666666666}{a}\\ \mathbf{else}:\\ \;\;\;\;c \cdot \frac{-0.5}{b}\\ \end{array} \]
Alternative 8
Error22.9
Cost452
\[\begin{array}{l} \mathbf{if}\;b \leq 2.3 \cdot 10^{-178}:\\ \;\;\;\;\frac{b \cdot -0.6666666666666666}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b}\\ \end{array} \]
Alternative 9
Error45.5
Cost320
\[b \cdot \frac{-0.6666666666666666}{a} \]

Error

Reproduce?

herbie shell --seed 2023025 
(FPCore (a b c)
  :name "Cubic critical"
  :precision binary64
  (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))