?

Average Error: 34.2 → 10.0
Time: 24.6s
Precision: binary64
Cost: 14024

?

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

\mathbf{elif}\;b \leq 3.3 \cdot 10^{-74}:\\
\;\;\;\;\frac{\sqrt{0.1111111111111111 \cdot \mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)} + b \cdot -0.3333333333333333}{a}\\

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


\end{array}

Error?

Derivation?

  1. Split input into 3 regimes
  2. if b < -7.2000000000000001e114

    1. Initial program 50.4

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

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

      [Start]50.4

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

      *-lft-identity [<=]50.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 [<=]50.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 [<=]50.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 [<=]50.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 [=>]50.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 [=>]50.5

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

      *-commutative [=>]50.5

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

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

    if -7.2000000000000001e114 < b < 3.29999999999999996e-74

    1. Initial program 12.9

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

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

      [Start]12.9

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

      *-lft-identity [<=]12.9

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

      metadata-eval [<=]12.9

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

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

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

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

      \[ \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. Applied egg-rr37.4

      \[\leadsto \frac{\color{blue}{\left(e^{\mathsf{log1p}\left(\mathsf{hypot}\left(b, \sqrt{a \cdot \left(c \cdot -3\right)}\right)\right)} - 1\right)} - b}{3 \cdot a} \]
    4. Simplified19.0

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

      [Start]37.4

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

      expm1-def [=>]20.6

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

      expm1-log1p [=>]19.1

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

      associate-*r* [=>]19.1

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

      *-commutative [=>]19.1

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

      associate-*l* [=>]19.0

      \[ \frac{\mathsf{hypot}\left(b, \sqrt{\color{blue}{c \cdot \left(a \cdot -3\right)}}\right) - b}{3 \cdot a} \]
    5. Applied egg-rr19.3

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

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

      [Start]19.3

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

      associate-*l/ [=>]19.3

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

      associate-*r/ [=>]19.3

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

      rem-square-sqrt [=>]19.1

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

      \[\leadsto \frac{\color{blue}{\mathsf{hypot}\left(b, \sqrt{c \cdot \left(a \cdot -3\right)}\right) \cdot 0.3333333333333333 - b \cdot 0.3333333333333333}}{a} \]
    8. Applied egg-rr13.0

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

    if 3.29999999999999996e-74 < b

    1. Initial program 52.7

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

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

      [Start]52.7

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

      remove-double-neg [<=]52.7

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

      sub-neg [<=]52.7

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

      div-sub [=>]53.5

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

      neg-mul-1 [=>]53.5

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

      associate-*l/ [<=]54.2

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

      distribute-frac-neg [=>]54.2

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

      fma-neg [=>]56.9

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

      /-rgt-identity [<=]56.9

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

      metadata-eval [<=]56.9

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

      associate-/l* [<=]56.9

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

      *-commutative [<=]56.9

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

      neg-mul-1 [<=]56.9

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

      fma-neg [<=]54.2

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

      neg-mul-1 [=>]54.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -7.2 \cdot 10^{+114}:\\ \;\;\;\;\left(-1.5 \cdot \frac{c}{b} + 2 \cdot \frac{b}{a}\right) \cdot -0.3333333333333333\\ \mathbf{elif}\;b \leq 3.3 \cdot 10^{-74}:\\ \;\;\;\;\frac{\sqrt{0.1111111111111111 \cdot \mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)} + b \cdot -0.3333333333333333}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} \cdot -0.5\\ \end{array} \]

Alternatives

Alternative 1
Error10.0
Cost7624
\[\begin{array}{l} \mathbf{if}\;b \leq -3.4 \cdot 10^{+113}:\\ \;\;\;\;\left(-1.5 \cdot \frac{c}{b} + 2 \cdot \frac{b}{a}\right) \cdot -0.3333333333333333\\ \mathbf{elif}\;b \leq 10^{-75}:\\ \;\;\;\;\frac{\sqrt{b \cdot b + a \cdot \left(c \cdot -3\right)} - b}{a \cdot 3}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} \cdot -0.5\\ \end{array} \]
Alternative 2
Error10.0
Cost7624
\[\begin{array}{l} \mathbf{if}\;b \leq -5.2 \cdot 10^{+107}:\\ \;\;\;\;\left(-1.5 \cdot \frac{c}{b} + 2 \cdot \frac{b}{a}\right) \cdot -0.3333333333333333\\ \mathbf{elif}\;b \leq 5.6 \cdot 10^{-73}:\\ \;\;\;\;\frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -3\right)} - b}{a \cdot 3}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} \cdot -0.5\\ \end{array} \]
Alternative 3
Error13.2
Cost7368
\[\begin{array}{l} \mathbf{if}\;b \leq -9 \cdot 10^{-72}:\\ \;\;\;\;\left(-1.5 \cdot \frac{c}{b} + 2 \cdot \frac{b}{a}\right) \cdot -0.3333333333333333\\ \mathbf{elif}\;b \leq 3.2 \cdot 10^{-76}:\\ \;\;\;\;\frac{0.3333333333333333}{a} \cdot \left(\sqrt{a \cdot \left(c \cdot -3\right)} - b\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} \cdot -0.5\\ \end{array} \]
Alternative 4
Error13.2
Cost7368
\[\begin{array}{l} \mathbf{if}\;b \leq -3.2 \cdot 10^{-72}:\\ \;\;\;\;\left(-1.5 \cdot \frac{c}{b} + 2 \cdot \frac{b}{a}\right) \cdot -0.3333333333333333\\ \mathbf{elif}\;b \leq 8 \cdot 10^{-75}:\\ \;\;\;\;\frac{\sqrt{c \cdot \left(a \cdot -3\right)} - b}{a \cdot 3}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} \cdot -0.5\\ \end{array} \]
Alternative 5
Error22.4
Cost964
\[\begin{array}{l} \mathbf{if}\;b \leq -2 \cdot 10^{-280}:\\ \;\;\;\;\left(-1.5 \cdot \frac{c}{b} + 2 \cdot \frac{b}{a}\right) \cdot -0.3333333333333333\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} \cdot -0.5\\ \end{array} \]
Alternative 6
Error22.3
Cost836
\[\begin{array}{l} \mathbf{if}\;b \leq -2 \cdot 10^{-280}:\\ \;\;\;\;\frac{b}{a} \cdot -0.6666666666666666 + \frac{c}{b} \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} \cdot -0.5\\ \end{array} \]
Alternative 7
Error22.4
Cost580
\[\begin{array}{l} \mathbf{if}\;b \leq 3.2 \cdot 10^{-228}:\\ \;\;\;\;\frac{b \cdot -2}{a \cdot 3}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} \cdot -0.5\\ \end{array} \]
Alternative 8
Error36.2
Cost452
\[\begin{array}{l} \mathbf{if}\;b \leq 4.4 \cdot 10^{-226}:\\ \;\;\;\;b \cdot \frac{-0.3333333333333333}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} \cdot -0.5\\ \end{array} \]
Alternative 9
Error22.4
Cost452
\[\begin{array}{l} \mathbf{if}\;b \leq 1.45 \cdot 10^{-225}:\\ \;\;\;\;\frac{b}{a} \cdot -0.6666666666666666\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} \cdot -0.5\\ \end{array} \]
Alternative 10
Error22.4
Cost452
\[\begin{array}{l} \mathbf{if}\;b \leq 3.7 \cdot 10^{-227}:\\ \;\;\;\;\frac{-0.6666666666666666}{\frac{a}{b}}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} \cdot -0.5\\ \end{array} \]
Alternative 11
Error39.4
Cost320
\[\frac{c}{b} \cdot -0.5 \]

Error

Reproduce?

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