?

Average Error: 46.4% → 84.2%
Time: 27.3s
Precision: binary64
Cost: 13896.00

?

\[\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 -1.2 \cdot 10^{+86}:\\ \;\;\;\;\frac{b}{a \cdot -1.5}\\ \mathbf{elif}\;b \leq 3.6 \cdot 10^{-36}:\\ \;\;\;\;\frac{\frac{b - \sqrt{\mathsf{fma}\left(-3, a \cdot c, b \cdot b\right)}}{a}}{-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 -1.2e+86)
   (/ b (* a -1.5))
   (if (<= b 3.6e-36)
     (/ (/ (- b (sqrt (fma -3.0 (* a c) (* b 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 <= -1.2e+86) {
		tmp = b / (a * -1.5);
	} else if (b <= 3.6e-36) {
		tmp = ((b - sqrt(fma(-3.0, (a * c), (b * 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 <= -1.2e+86)
		tmp = Float64(b / Float64(a * -1.5));
	elseif (b <= 3.6e-36)
		tmp = Float64(Float64(Float64(b - sqrt(fma(-3.0, Float64(a * c), Float64(b * b)))) / 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, -1.2e+86], N[(b / N[(a * -1.5), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 3.6e-36], N[(N[(N[(b - N[Sqrt[N[(-3.0 * N[(a * c), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision] / -3.0), $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 -1.2 \cdot 10^{+86}:\\
\;\;\;\;\frac{b}{a \cdot -1.5}\\

\mathbf{elif}\;b \leq 3.6 \cdot 10^{-36}:\\
\;\;\;\;\frac{\frac{b - \sqrt{\mathsf{fma}\left(-3, a \cdot c, b \cdot b\right)}}{a}}{-3}\\

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


\end{array}

Error?

Derivation?

  1. Split input into 3 regimes
  2. if b < -1.2e86

    1. Initial program 27.4

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

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

      [Start]27.4

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

      *-lft-identity [<=]27.4

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

      metadata-eval [<=]27.4

      \[ \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 [<=]27.4

      \[ \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)}} \]

      neg-mul-1 [<=]27.4

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

      distribute-rgt-neg-in [=>]27.4

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

      times-frac [=>]27.3

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

      *-commutative [=>]27.3

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

      \[\leadsto \color{blue}{-0.6666666666666666 \cdot \frac{b}{a}} \]
    4. Simplified91.6

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

      [Start]91.6

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

      *-commutative [=>]91.6

      \[ \color{blue}{\frac{b}{a} \cdot -0.6666666666666666} \]
    5. Taylor expanded in b around 0 91.6

      \[\leadsto \color{blue}{-0.6666666666666666 \cdot \frac{b}{a}} \]
    6. Simplified91.8

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

      [Start]91.6

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

      *-commutative [<=]91.6

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

      /-rgt-identity [<=]91.6

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

      associate-/l* [=>]91.7

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

      associate-/r* [<=]91.8

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

      metadata-eval [=>]91.8

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

    if -1.2e86 < b < 3.60000000000000032e-36

    1. Initial program 77.9

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

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

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

      [Start]77.7

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

      associate-*l/ [=>]77.7

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

      associate-*r/ [=>]77.8

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

      *-rgt-identity [=>]77.8

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

      fma-def [<=]77.8

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

      +-commutative [=>]77.8

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

      fma-def [=>]77.8

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

      *-commutative [=>]77.8

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

    if 3.60000000000000032e-36 < b

    1. Initial program 14.5

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

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

      [Start]14.5

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

      *-lft-identity [<=]14.5

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

      metadata-eval [<=]14.5

      \[ \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 [<=]14.5

      \[ \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 [<=]14.5

      \[ \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 [=>]14.5

      \[ \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/ [=>]14.5

      \[ \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 89.2

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

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

      [Start]89.2

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

      associate-*r/ [=>]89.2

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

      *-commutative [=>]89.2

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1.2 \cdot 10^{+86}:\\ \;\;\;\;\frac{b}{a \cdot -1.5}\\ \mathbf{elif}\;b \leq 3.6 \cdot 10^{-36}:\\ \;\;\;\;\frac{\frac{b - \sqrt{\mathsf{fma}\left(-3, a \cdot c, b \cdot b\right)}}{a}}{-3}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b}\\ \end{array} \]

Alternatives

Alternative 1
Error84.3%
Cost7624.00
\[\begin{array}{l} \mathbf{if}\;b \leq -1.2 \cdot 10^{+86}:\\ \;\;\;\;\frac{b}{a \cdot -1.5}\\ \mathbf{elif}\;b \leq 4.7 \cdot 10^{-35}:\\ \;\;\;\;\frac{-0.3333333333333333}{a} \cdot \left(b - \sqrt{b \cdot b + \frac{c}{\frac{-0.3333333333333333}{a}}}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b}\\ \end{array} \]
Alternative 2
Error84.2%
Cost7624.00
\[\begin{array}{l} \mathbf{if}\;b \leq -6.2 \cdot 10^{+85}:\\ \;\;\;\;\frac{b}{a \cdot -1.5}\\ \mathbf{elif}\;b \leq 2.8 \cdot 10^{-32}:\\ \;\;\;\;-0.3333333333333333 \cdot \frac{b - \sqrt{b \cdot b + \frac{c}{\frac{-0.3333333333333333}{a}}}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b}\\ \end{array} \]
Alternative 3
Error78.8%
Cost7368.00
\[\begin{array}{l} \mathbf{if}\;b \leq -2.1 \cdot 10^{-32}:\\ \;\;\;\;-0.6666666666666666 \cdot \frac{b}{a} + 0.5 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \leq 2.5 \cdot 10^{-32}:\\ \;\;\;\;\frac{-0.3333333333333333}{a} \cdot \left(b - \sqrt{-3 \cdot \left(a \cdot c\right)}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b}\\ \end{array} \]
Alternative 4
Error78.8%
Cost7368.00
\[\begin{array}{l} \mathbf{if}\;b \leq -1.4 \cdot 10^{-32}:\\ \;\;\;\;-0.6666666666666666 \cdot \frac{b}{a} + 0.5 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \leq 1.32 \cdot 10^{-35}:\\ \;\;\;\;\frac{-0.3333333333333333}{a} \cdot \left(b - \sqrt{\frac{a \cdot c}{-0.3333333333333333}}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b}\\ \end{array} \]
Alternative 5
Error64.2%
Cost452.00
\[\begin{array}{l} \mathbf{if}\;b \leq 1.7 \cdot 10^{-232}:\\ \;\;\;\;b \cdot \frac{-0.6666666666666666}{a}\\ \mathbf{else}:\\ \;\;\;\;c \cdot \frac{-0.5}{b}\\ \end{array} \]
Alternative 6
Error64.2%
Cost452.00
\[\begin{array}{l} \mathbf{if}\;b \leq 2.3 \cdot 10^{-232}:\\ \;\;\;\;-0.6666666666666666 \cdot \frac{b}{a}\\ \mathbf{else}:\\ \;\;\;\;c \cdot \frac{-0.5}{b}\\ \end{array} \]
Alternative 7
Error64.2%
Cost452.00
\[\begin{array}{l} \mathbf{if}\;b \leq 3.9 \cdot 10^{-233}:\\ \;\;\;\;\frac{b}{a \cdot -1.5}\\ \mathbf{else}:\\ \;\;\;\;c \cdot \frac{-0.5}{b}\\ \end{array} \]
Alternative 8
Error64.3%
Cost452.00
\[\begin{array}{l} \mathbf{if}\;b \leq 2.4 \cdot 10^{-232}:\\ \;\;\;\;\frac{b}{a \cdot -1.5}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b}\\ \end{array} \]
Alternative 9
Error7.4%
Cost320.00
\[-0.3333333333333333 \cdot \frac{b}{a} \]
Alternative 10
Error28.7%
Cost320.00
\[b \cdot \frac{-0.6666666666666666}{a} \]

Error

Reproduce?

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