?

Average Error: 32.3% → 99.7%
Time: 15.7s
Precision: binary64
Cost: 13568.00

?

\[\left(\left(1.1102230246251565 \cdot 10^{-16} < a \land a < 9007199254740992\right) \land \left(1.1102230246251565 \cdot 10^{-16} < b \land b < 9007199254740992\right)\right) \land \left(1.1102230246251565 \cdot 10^{-16} < c \land c < 9007199254740992\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 32.3

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

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

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

    remove-double-neg [<=]32.3

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

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

    div-sub [=>]31.8

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

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

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

    \[ \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 [=>]33.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 [<=]33.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 [<=]33.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* [<=]33.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 [<=]33.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 [<=]33.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 [<=]32.1

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

    \[ \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-rr33.2

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

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

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

    [Start]99.1

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

    *-commutative [=>]99.1

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

    associate-*l* [=>]99.3

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

    *-commutative [=>]99.3

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

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

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

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

    [Start]52.2

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

    expm1-def [=>]98.9

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

    expm1-log1p [=>]99.2

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

    associate-*l* [=>]99.1

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

    *-commutative [<=]99.1

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

    associate-*l/ [=>]99.1

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

    associate-*l/ [=>]99.3

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

    associate-*r/ [=>]99.3

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

    associate-*l* [<=]99.2

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

    associate-/l/ [=>]99.1

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

    times-frac [=>]99.1

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

    associate-*l/ [=>]99.2

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

    associate-/l* [=>]99.4

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

    *-inverses [=>]99.4

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

    metadata-eval [=>]99.4

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

    associate-*l* [=>]99.7

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

    metadata-eval [=>]99.7

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

    *-rgt-identity [=>]99.7

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

    remove-double-neg [<=]99.7

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

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

Alternatives

Alternative 1
Error99.4%
Cost7744.00
\[\frac{c}{a \cdot 3} \cdot \frac{a \cdot -3}{b + \sqrt{b \cdot b + a \cdot \left(c \cdot -3\right)}} \]
Alternative 2
Error90.3%
Cost1088.00
\[\frac{\frac{-0.3333333333333333}{a}}{\frac{\frac{0.6666666666666666}{\frac{c}{b}}}{a} + 0.5 \cdot \frac{-1}{b}} \]
Alternative 3
Error90.2%
Cost960.00
\[\frac{0.3333333333333333}{a \cdot \left(\frac{0.5}{b} + \frac{b}{c \cdot a} \cdot -0.6666666666666666\right)} \]
Alternative 4
Error90.2%
Cost960.00
\[\frac{\frac{-0.3333333333333333}{a}}{\frac{b \cdot 0.6666666666666666}{c \cdot a} + \frac{-0.5}{b}} \]
Alternative 5
Error80.6%
Cost320.00
\[\frac{c}{b} \cdot -0.5 \]

Error

Reproduce?

herbie shell --seed 2023098 
(FPCore (a b c)
  :name "Cubic critical, medium range"
  :precision binary64
  :pre (and (and (and (< 1.1102230246251565e-16 a) (< a 9007199254740992.0)) (and (< 1.1102230246251565e-16 b) (< b 9007199254740992.0))) (and (< 1.1102230246251565e-16 c) (< c 9007199254740992.0)))
  (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))