?

Average Error: 52.8 → 0.1
Time: 15.6s
Precision: binary64
Cost: 13568

?

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

Error?

Derivation?

  1. Initial program 52.8

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

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

    remove-double-neg [<=]52.8

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

    \[ \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.0

    \[ \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.0

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

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

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

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

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

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

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

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

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

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

    \[ \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. Applied egg-rr52.5

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

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

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

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

    [Start]51.4

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

    expm1-def [=>]10.7

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

    expm1-log1p [=>]0.5

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

    rem-3cbrt-lft [<=]1.4

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

    unpow2 [<=]1.4

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

    associate-/r* [=>]1.4

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

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

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

    [Start]0.1

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

    distribute-lft1-in [=>]0.1

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

    metadata-eval [=>]0.1

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

    associate-*r/ [<=]0.1

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

    mul0-lft [=>]0.1

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

    metadata-eval [=>]0.1

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

    +-commutative [=>]0.1

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

    mul-1-neg [=>]0.1

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

    unsub-neg [=>]0.1

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

    neg-sub0 [<=]0.1

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

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

Alternatives

Alternative 1
Error0.5
Cost8256
\[\frac{a \cdot \left(c \cdot 3\right) + \left(b \cdot b - b \cdot b\right)}{\left(a \cdot -3\right) \cdot \left(b + \sqrt{b \cdot b + a \cdot \left(c \cdot -3\right)}\right)} \]
Alternative 2
Error0.4
Cost8256
\[\frac{\frac{a \cdot \left(c \cdot 3\right) + \left(b \cdot b - b \cdot b\right)}{a \cdot -3}}{b + \sqrt{b \cdot b + a \cdot \left(c \cdot -3\right)}} \]
Alternative 3
Error3.0
Cost960
\[\left(\frac{-0.375 \cdot \left(c \cdot a\right)}{b \cdot b} + -0.5\right) \cdot \frac{c}{b} \]
Alternative 4
Error3.0
Cost960
\[\frac{c}{\frac{b}{\frac{-0.375 \cdot \left(c \cdot a\right)}{b \cdot b} + -0.5}} \]
Alternative 5
Error3.0
Cost960
\[\frac{c \cdot \left(\frac{-0.375 \cdot \left(c \cdot a\right)}{b \cdot b} + -0.5\right)}{b} \]
Alternative 6
Error6.2
Cost320
\[c \cdot \frac{-0.5}{b} \]
Alternative 7
Error6.0
Cost320
\[\frac{c \cdot -0.5}{b} \]

Error

Reproduce?

herbie shell --seed 2023187 
(FPCore (a b c)
  :name "Cubic critical, wide range"
  :precision binary64
  :pre (and (and (and (< 4.930380657631324e-32 a) (< a 2.028240960365167e+31)) (and (< 4.930380657631324e-32 b) (< b 2.028240960365167e+31))) (and (< 4.930380657631324e-32 c) (< c 2.028240960365167e+31)))
  (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))