?

Average Error: 18.2% → 99.9%
Time: 29.1s
Precision: binary64
Cost: 13824.00

?

\[\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{a}{-a} \cdot \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
 (* (/ a (- a)) (/ 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 (a / -a) * (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(a / Float64(-a)) * 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[(N[(a / (-a)), $MachinePrecision] * N[(c / N[(b + N[Sqrt[N[(a * N[(c * -3.0), $MachinePrecision] + N[(b * b), $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{a}{-a} \cdot \frac{c}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}

Error?

Derivation?

  1. Initial program 18.2

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

    \[\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]18.2

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

    remove-double-neg [<=]18.2

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

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

    div-sub [=>]18.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 [=>]18.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/ [<=]18.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 [=>]18.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 [=>]19.5

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

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

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

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

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

    \[ \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 [<=]18.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 [=>]18.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. Applied egg-rr18.7

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

    [Start]18.2

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

    *-commutative [=>]18.2

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

    clear-num [=>]18.2

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

    flip-- [=>]18.2

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

    frac-times [=>]18.2

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

    associate-/l* [=>]18.2

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

    div-inv [=>]18.2

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

    metadata-eval [=>]18.2

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

    add-sqr-sqrt [<=]18.7

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

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

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

    [Start]99.1

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

    expm1-log1p-u [=>]82.9

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

    expm1-udef [=>]20.4

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

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

    [Start]20.4

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

    expm1-def [=>]83.2

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

    expm1-log1p [=>]99.4

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

    times-frac [=>]99.9

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

    mul-1-neg [=>]99.9

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

    *-commutative [=>]99.9

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

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

Alternatives

Alternative 1
Error95.2%
Cost13696.00
\[\mathsf{fma}\left(-0.375, \frac{c \cdot c}{\frac{{b}^{3}}{a}}, -0.5 \cdot \frac{c}{b}\right) \]
Alternative 2
Error95.0%
Cost7232.00
\[\frac{b}{\frac{\mathsf{fma}\left(c, a \cdot 1.5, b \cdot \left(b \cdot -2\right)\right)}{c}} \]
Alternative 3
Error95.1%
Cost832.00
\[\frac{1}{-2 \cdot \frac{b}{c} + 1.5 \cdot \frac{a}{b}} \]
Alternative 4
Error89.8%
Cost320.00
\[c \cdot \frac{-0.5}{b} \]
Alternative 5
Error89.8%
Cost320.00
\[\frac{-0.5}{\frac{b}{c}} \]
Alternative 6
Error90.1%
Cost320.00
\[\frac{c \cdot -0.5}{b} \]

Error

Reproduce?

herbie shell --seed 2023121 
(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)))