?

Average Error: 52.6 → 0.1
Time: 14.1s
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}{\left(-\sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right) - b} \]
(FPCore (a b c)
 :precision binary64
 (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))
(FPCore (a b c)
 :precision binary64
 (/ c (- (- (sqrt (fma a (* c -3.0) (* b 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 / (-sqrt(fma(a, (c * -3.0), (b * 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(c / Float64(Float64(-sqrt(fma(a, Float64(c * -3.0), Float64(b * 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[((-N[Sqrt[N[(a * N[(c * -3.0), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) - b), $MachinePrecision]), $MachinePrecision]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\frac{c}{\left(-\sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right) - b}

Error?

Derivation?

  1. Initial program 52.6

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

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

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

    remove-double-neg [<=]52.6

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

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

    div-sub [=>]52.7

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{-0.3333333333333333}{\frac{a \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)}}} \]
  4. Taylor expanded in b around 0 0.6

    \[\leadsto \frac{-0.3333333333333333}{\frac{a \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-rr51.2

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

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

    [Start]51.2

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

    expm1-def [=>]10.3

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

    expm1-log1p [=>]0.4

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

    times-frac [=>]0.4

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

    metadata-eval [<=]0.4

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

    associate-*r/ [<=]0.6

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

    associate-*r/ [=>]0.5

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

    associate-*l/ [<=]0.6

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

    associate-*r* [=>]0.6

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

    associate-/r/ [<=]0.6

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

    *-commutative [=>]0.6

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

    associate-*r/ [=>]0.5

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

    metadata-eval [=>]0.5

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

    associate-/l/ [=>]0.4

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

    *-commutative [<=]0.4

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

    associate-*r/ [=>]0.4

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

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

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

    [Start]51.2

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

    expm1-def [=>]10.1

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

    expm1-log1p [=>]0.1

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

    neg-sub0 [=>]0.1

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

    +-commutative [=>]0.1

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

    associate--r+ [=>]0.1

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

    neg-sub0 [<=]0.1

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

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

Alternatives

Alternative 1
Error0.3
Cost7360
\[c \cdot \frac{-1}{b + \sqrt{b \cdot b + a \cdot \left(c \cdot -3\right)}} \]
Alternative 2
Error3.2
Cost960
\[c \cdot \frac{-1}{-1.5 \cdot \frac{c \cdot a}{b} + b \cdot 2} \]
Alternative 3
Error3.3
Cost832
\[\frac{-0.3333333333333333}{0.6666666666666666 \cdot \frac{b}{c} + -0.5 \cdot \frac{a}{b}} \]
Alternative 4
Error6.4
Cost320
\[c \cdot \frac{-0.5}{b} \]
Alternative 5
Error6.4
Cost320
\[\frac{-0.5}{\frac{b}{c}} \]
Alternative 6
Error6.2
Cost320
\[\frac{c \cdot -0.5}{b} \]

Error

Reproduce?

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