?

Average Error: 28.4 → 0.3
Time: 21.2s
Precision: binary64
Cost: 13760

?

\[\left(\left(1.0536712127723509 \cdot 10^{-8} < a \land a < 94906265.62425156\right) \land \left(1.0536712127723509 \cdot 10^{-8} < b \land b < 94906265.62425156\right)\right) \land \left(1.0536712127723509 \cdot 10^{-8} < c \land c < 94906265.62425156\right)\]
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
\[\frac{\frac{-3}{\frac{3}{c}}}{b + \sqrt{\mathsf{fma}\left(b, b, a \cdot \left(-3 \cdot c\right)\right)}} \]
(FPCore (a b c)
 :precision binary64
 (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))
(FPCore (a b c)
 :precision binary64
 (/ (/ -3.0 (/ 3.0 c)) (+ b (sqrt (fma b b (* a (* -3.0 c)))))))
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) {
	return (-3.0 / (3.0 / c)) / (b + sqrt(fma(b, b, (a * (-3.0 * c)))));
}
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)
	return Float64(Float64(-3.0 / Float64(3.0 / c)) / Float64(b + sqrt(fma(b, b, Float64(a * Float64(-3.0 * c))))))
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_] := N[(N[(-3.0 / N[(3.0 / c), $MachinePrecision]), $MachinePrecision] / N[(b + N[Sqrt[N[(b * b + N[(a * N[(-3.0 * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\frac{\frac{-3}{\frac{3}{c}}}{b + \sqrt{\mathsf{fma}\left(b, b, a \cdot \left(-3 \cdot c\right)\right)}}

Error?

Derivation?

  1. Initial program 28.4

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

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

    [Start]28.4

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

    *-lft-identity [<=]28.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 [<=]28.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 [<=]28.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)}} \]

    *-commutative [<=]28.4

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

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

    \[ \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-rr27.8

    \[\leadsto \frac{\color{blue}{\frac{{\left(\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)\right)}^{2} - \left(b \cdot b\right) \cdot \left(b \cdot b\right)}{\left(b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)}\right) \cdot \left(\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right) + b \cdot b\right)}}}{3 \cdot a} \]
  4. Simplified27.3

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

    [Start]27.8

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

    *-commutative [=>]27.8

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

    associate-/r* [=>]27.8

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

    unpow2 [<=]27.8

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

    unpow2 [<=]27.8

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

    pow-sqr [=>]27.3

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

    metadata-eval [=>]27.3

    \[ \frac{\frac{\frac{{\left(\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)\right)}^{2} - {b}^{\color{blue}{4}}}{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right) + b \cdot b}}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)}}}{3 \cdot a} \]
  5. Taylor expanded in b around 0 0.6

    \[\leadsto \frac{\frac{\color{blue}{-3 \cdot \left(c \cdot a\right)}}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)}}}{3 \cdot a} \]
  6. Simplified0.4

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

    [Start]0.6

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

    *-commutative [=>]0.6

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

    associate-*r* [<=]0.4

    \[ \frac{\frac{\color{blue}{c \cdot \left(a \cdot -3\right)}}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)}}}{3 \cdot a} \]
  7. Applied egg-rr0.4

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

    \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{\frac{a \cdot -3}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)}} \cdot c}{3 \cdot a}\right)} - 1} \]
  9. Simplified0.3

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

    [Start]24.3

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

    expm1-def [=>]9.3

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

    expm1-log1p [=>]0.4

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

    associate-/l* [=>]0.4

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

    associate-*l/ [<=]0.6

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

    *-rgt-identity [<=]0.6

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

    associate-*l/ [=>]0.6

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

    associate-*r/ [<=]0.6

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

    associate-*l/ [<=]0.6

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

    associate-*r/ [=>]0.5

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

    associate-*l/ [=>]0.5

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

    associate-*l* [=>]0.5

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

    metadata-eval [=>]0.5

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

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

Alternatives

Alternative 1
Error9.6
Cost15684
\[\begin{array}{l} t_0 := a \cdot \left(-3 \cdot c\right) + b \cdot b\\ \mathbf{if}\;\frac{\sqrt{b \cdot b - c \cdot \left(3 \cdot a\right)} - b}{3 \cdot a} \leq -1:\\ \;\;\;\;-0.3333333333333333 \cdot \frac{\frac{b \cdot b - t_0}{b + \sqrt{t_0}}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{c \cdot \left(-3 \cdot a\right)}{-1.5 \cdot \frac{c \cdot a}{b} + b \cdot 2}}{3 \cdot a}\\ \end{array} \]
Alternative 2
Error9.6
Cost15684
\[\begin{array}{l} t_0 := a \cdot \left(-3 \cdot c\right) + b \cdot b\\ \mathbf{if}\;\frac{\sqrt{b \cdot b - c \cdot \left(3 \cdot a\right)} - b}{3 \cdot a} \leq -1:\\ \;\;\;\;\frac{\frac{-0.3333333333333333}{\frac{a}{b \cdot b - t_0}}}{b + \sqrt{t_0}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{c \cdot \left(-3 \cdot a\right)}{-1.5 \cdot \frac{c \cdot a}{b} + b \cdot 2}}{3 \cdot a}\\ \end{array} \]
Alternative 3
Error9.7
Cost14788
\[\begin{array}{l} \mathbf{if}\;\frac{\sqrt{b \cdot b - c \cdot \left(3 \cdot a\right)} - b}{3 \cdot a} \leq -1:\\ \;\;\;\;-0.3333333333333333 \cdot \frac{b - \sqrt{b \cdot b + -3 \cdot \left(c \cdot a\right)}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{c \cdot \left(-3 \cdot a\right)}{-1.5 \cdot \frac{c \cdot a}{b} + b \cdot 2}}{3 \cdot a}\\ \end{array} \]
Alternative 4
Error0.4
Cost13632
\[c \cdot \frac{-1}{b + \sqrt{\mathsf{fma}\left(b, b, a \cdot \left(-3 \cdot c\right)\right)}} \]
Alternative 5
Error9.4
Cost7492
\[\begin{array}{l} \mathbf{if}\;b \leq 23:\\ \;\;\;\;\left(b - \sqrt{a \cdot \left(-3 \cdot c\right) + b \cdot b}\right) \cdot \frac{-0.3333333333333333}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{c \cdot \left(-3 \cdot a\right)}{-1.5 \cdot \frac{c \cdot a}{b} + b \cdot 2}}{3 \cdot a}\\ \end{array} \]
Alternative 6
Error11.6
Cost1344
\[\frac{\frac{c \cdot \left(-3 \cdot a\right)}{-1.5 \cdot \frac{c \cdot a}{b} + b \cdot 2}}{3 \cdot a} \]
Alternative 7
Error11.6
Cost832
\[\frac{1}{-2 \cdot \frac{b}{c} + 1.5 \cdot \frac{a}{b}} \]
Alternative 8
Error22.9
Cost320
\[-0.5 \cdot \frac{c}{b} \]
Alternative 9
Error62.0
Cost64
\[0 \]

Error

Reproduce?

herbie shell --seed 2023187 
(FPCore (a b c)
  :name "Cubic critical, narrow range"
  :precision binary64
  :pre (and (and (and (< 1.0536712127723509e-8 a) (< a 94906265.62425156)) (and (< 1.0536712127723509e-8 b) (< b 94906265.62425156))) (and (< 1.0536712127723509e-8 c) (< c 94906265.62425156)))
  (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))