Average Error: 44.0 → 0.2
Time: 15.1s
Precision: binary64
Cost: 13568
\[\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 44.0

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

    \[\leadsto \color{blue}{\left(b - \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right) \cdot \frac{-0.3333333333333333}{a}} \]
    Proof
    (*.f64 (-.f64 b (sqrt.f64 (fma.f64 a (*.f64 c -3) (*.f64 b b)))) (/.f64 -1/3 a)): 0 points increase in error, 0 points decrease in error
    (*.f64 (-.f64 b (sqrt.f64 (fma.f64 a (*.f64 c (Rewrite<= metadata-eval (neg.f64 3))) (*.f64 b b)))) (/.f64 -1/3 a)): 31 points increase in error, 0 points decrease in error
    (*.f64 (-.f64 b (sqrt.f64 (Rewrite<= fma-def_binary64 (+.f64 (*.f64 a (*.f64 c (neg.f64 3))) (*.f64 b b))))) (/.f64 -1/3 a)): 31 points increase in error, 0 points decrease in error
    (*.f64 (-.f64 b (sqrt.f64 (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 (*.f64 c (neg.f64 3)) a)) (*.f64 b b)))) (/.f64 -1/3 a)): 0 points increase in error, 31 points decrease in error
    (*.f64 (-.f64 b (sqrt.f64 (+.f64 (Rewrite<= associate-*r*_binary64 (*.f64 c (*.f64 (neg.f64 3) a))) (*.f64 b b)))) (/.f64 -1/3 a)): 31 points increase in error, 0 points decrease in error
    (*.f64 (-.f64 b (sqrt.f64 (+.f64 (*.f64 c (Rewrite<= distribute-lft-neg-in_binary64 (neg.f64 (*.f64 3 a)))) (*.f64 b b)))) (/.f64 -1/3 a)): 31 points increase in error, 0 points decrease in error
    (*.f64 (-.f64 b (sqrt.f64 (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 (neg.f64 (*.f64 3 a)) c)) (*.f64 b b)))) (/.f64 -1/3 a)): 0 points increase in error, 31 points decrease in error
    (*.f64 (-.f64 b (sqrt.f64 (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 b b) (*.f64 (neg.f64 (*.f64 3 a)) c))))) (/.f64 -1/3 a)): 31 points increase in error, 0 points decrease in error
    (*.f64 (-.f64 b (sqrt.f64 (Rewrite<= cancel-sign-sub-inv_binary64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c))))) (/.f64 -1/3 a)): 0 points increase in error, 31 points decrease in error
    (*.f64 (Rewrite=> sub-neg_binary64 (+.f64 b (neg.f64 (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))))) (/.f64 -1/3 a)): 0 points increase in error, 31 points decrease in error
    (*.f64 (+.f64 (Rewrite<= /-rgt-identity_binary64 (/.f64 b 1)) (neg.f64 (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c))))) (/.f64 -1/3 a)): 0 points increase in error, 31 points decrease in error
    (*.f64 (+.f64 (/.f64 b (Rewrite<= metadata-eval (/.f64 -1 -1))) (neg.f64 (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c))))) (/.f64 -1/3 a)): 0 points increase in error, 31 points decrease in error
    (*.f64 (+.f64 (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 b -1) -1)) (neg.f64 (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c))))) (/.f64 -1/3 a)): 6 points increase in error, 25 points decrease in error
    (*.f64 (+.f64 (/.f64 (Rewrite<= *-commutative_binary64 (*.f64 -1 b)) -1) (neg.f64 (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c))))) (/.f64 -1/3 a)): 31 points increase in error, 0 points decrease in error
    (*.f64 (+.f64 (/.f64 (Rewrite<= neg-mul-1_binary64 (neg.f64 b)) -1) (neg.f64 (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c))))) (/.f64 -1/3 a)): 31 points increase in error, 0 points decrease in error
    (*.f64 (+.f64 (/.f64 (neg.f64 b) -1) (neg.f64 (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c))))) (/.f64 (Rewrite<= metadata-eval (/.f64 -1 3)) a)): 0 points increase in error, 31 points decrease in error
    (*.f64 (+.f64 (/.f64 (neg.f64 b) -1) (neg.f64 (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c))))) (Rewrite<= associate-/r*_binary64 (/.f64 -1 (*.f64 3 a)))): 31 points increase in error, 0 points decrease in error
    (Rewrite<= *-commutative_binary64 (*.f64 (/.f64 -1 (*.f64 3 a)) (+.f64 (/.f64 (neg.f64 b) -1) (neg.f64 (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c))))))): 31 points increase in error, 0 points decrease in error
    (Rewrite<= distribute-lft-out_binary64 (+.f64 (*.f64 (/.f64 -1 (*.f64 3 a)) (/.f64 (neg.f64 b) -1)) (*.f64 (/.f64 -1 (*.f64 3 a)) (neg.f64 (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c))))))): 0 points increase in error, 31 points decrease in error
    (+.f64 (*.f64 (/.f64 -1 (*.f64 3 a)) (/.f64 (Rewrite=> neg-mul-1_binary64 (*.f64 -1 b)) -1)) (*.f64 (/.f64 -1 (*.f64 3 a)) (neg.f64 (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))))): 31 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 (/.f64 -1 (*.f64 3 a)) (/.f64 (Rewrite=> *-commutative_binary64 (*.f64 b -1)) -1)) (*.f64 (/.f64 -1 (*.f64 3 a)) (neg.f64 (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))))): 0 points increase in error, 31 points decrease in error
    (+.f64 (*.f64 (/.f64 -1 (*.f64 3 a)) (Rewrite=> associate-/l*_binary64 (/.f64 b (/.f64 -1 -1)))) (*.f64 (/.f64 -1 (*.f64 3 a)) (neg.f64 (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))))): 31 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 (/.f64 -1 (*.f64 3 a)) (/.f64 b (Rewrite=> metadata-eval 1))) (*.f64 (/.f64 -1 (*.f64 3 a)) (neg.f64 (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))))): 31 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 (/.f64 -1 (*.f64 3 a)) (Rewrite=> /-rgt-identity_binary64 b)) (*.f64 (/.f64 -1 (*.f64 3 a)) (neg.f64 (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))))): 0 points increase in error, 31 points decrease in error
    (Rewrite<= distribute-lft-in_binary64 (*.f64 (/.f64 -1 (*.f64 3 a)) (+.f64 b (neg.f64 (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c))))))): 0 points increase in error, 31 points decrease in error
    (*.f64 (/.f64 -1 (*.f64 3 a)) (Rewrite<= sub-neg_binary64 (-.f64 b (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))))): 0 points increase in error, 31 points decrease in error
    (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 -1 (-.f64 b (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c))))) (*.f64 3 a))): 31 points increase in error, 0 points decrease in error
    (/.f64 (Rewrite<= neg-mul-1_binary64 (neg.f64 (-.f64 b (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))))) (*.f64 3 a)): 31 points increase in error, 0 points decrease in error
    (/.f64 (Rewrite<= sub0-neg_binary64 (-.f64 0 (-.f64 b (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))))) (*.f64 3 a)): 31 points increase in error, 0 points decrease in error
    (/.f64 (Rewrite<= associate-+l-_binary64 (+.f64 (-.f64 0 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c))))) (*.f64 3 a)): 31 points increase in error, 0 points decrease in error
    (/.f64 (+.f64 (Rewrite<= neg-sub0_binary64 (neg.f64 b)) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (*.f64 3 a)): 0 points increase in error, 31 points decrease in error
  3. Applied egg-rr43.4

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

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

    \[\leadsto \frac{-0.3333333333333333}{\color{blue}{\left(-\left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)\right) \cdot \frac{-0.3333333333333333}{c}}} \]
    Proof
    (/.f64 -1/3 (*.f64 (neg.f64 (+.f64 b (sqrt.f64 (fma.f64 a (*.f64 c -3) (*.f64 b b))))) (/.f64 -1/3 c))): 0 points increase in error, 0 points decrease in error
    (/.f64 -1/3 (*.f64 (neg.f64 (+.f64 b (sqrt.f64 (fma.f64 a (*.f64 c -3) (*.f64 b b))))) (/.f64 (Rewrite<= metadata-eval (/.f64 1 -3)) c))): 0 points increase in error, 18 points decrease in error
    (/.f64 -1/3 (*.f64 (neg.f64 (+.f64 b (sqrt.f64 (fma.f64 a (*.f64 c -3) (*.f64 b b))))) (Rewrite<= associate-/r*_binary64 (/.f64 1 (*.f64 -3 c))))): 3 points increase in error, 0 points decrease in error
    (/.f64 -1/3 (*.f64 (neg.f64 (+.f64 b (sqrt.f64 (fma.f64 a (*.f64 c -3) (*.f64 b b))))) (/.f64 (Rewrite<= *-inverses_binary64 (/.f64 a a)) (*.f64 -3 c)))): 0 points increase in error, 0 points decrease in error
    (/.f64 -1/3 (*.f64 (neg.f64 (+.f64 b (sqrt.f64 (fma.f64 a (*.f64 c -3) (*.f64 b b))))) (/.f64 (/.f64 a a) (Rewrite<= *-commutative_binary64 (*.f64 c -3))))): 2 points increase in error, 0 points decrease in error
    (/.f64 -1/3 (*.f64 (neg.f64 (+.f64 b (sqrt.f64 (fma.f64 a (*.f64 c -3) (*.f64 b b))))) (Rewrite<= associate-/r*_binary64 (/.f64 a (*.f64 a (*.f64 c -3)))))): 13 points increase in error, 0 points decrease in error
    (/.f64 -1/3 (Rewrite<= *-commutative_binary64 (*.f64 (/.f64 a (*.f64 a (*.f64 c -3))) (neg.f64 (+.f64 b (sqrt.f64 (fma.f64 a (*.f64 c -3) (*.f64 b b)))))))): 3 points increase in error, 13 points decrease in error
    (/.f64 -1/3 (Rewrite=> distribute-rgt-neg-out_binary64 (neg.f64 (*.f64 (/.f64 a (*.f64 a (*.f64 c -3))) (+.f64 b (sqrt.f64 (fma.f64 a (*.f64 c -3) (*.f64 b b)))))))): 13 points increase in error, 3 points decrease in error
    (/.f64 -1/3 (neg.f64 (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 a (+.f64 b (sqrt.f64 (fma.f64 a (*.f64 c -3) (*.f64 b b))))) (*.f64 a (*.f64 c -3)))))): 0 points increase in error, 18 points decrease in error
    (/.f64 -1/3 (Rewrite=> distribute-neg-frac_binary64 (/.f64 (neg.f64 (*.f64 a (+.f64 b (sqrt.f64 (fma.f64 a (*.f64 c -3) (*.f64 b b)))))) (*.f64 a (*.f64 c -3))))): 0 points increase in error, 0 points decrease in error
    (/.f64 -1/3 (/.f64 (neg.f64 (Rewrite=> *-commutative_binary64 (*.f64 (+.f64 b (sqrt.f64 (fma.f64 a (*.f64 c -3) (*.f64 b b)))) a))) (*.f64 a (*.f64 c -3)))): 16 points increase in error, 0 points decrease in error
    (/.f64 -1/3 (/.f64 (Rewrite<= distribute-rgt-neg-out_binary64 (*.f64 (+.f64 b (sqrt.f64 (fma.f64 a (*.f64 c -3) (*.f64 b b)))) (neg.f64 a))) (*.f64 a (*.f64 c -3)))): 2 points increase in error, 0 points decrease in error
    (/.f64 -1/3 (/.f64 (*.f64 (+.f64 b (sqrt.f64 (fma.f64 a (*.f64 c -3) (*.f64 b b)))) (neg.f64 a)) (Rewrite=> *-commutative_binary64 (*.f64 (*.f64 c -3) a)))): 0 points increase in error, 5 points decrease in error
    (/.f64 -1/3 (/.f64 (*.f64 (+.f64 b (sqrt.f64 (fma.f64 a (*.f64 c -3) (*.f64 b b)))) (neg.f64 a)) (*.f64 (*.f64 c -3) (Rewrite<= /-rgt-identity_binary64 (/.f64 a 1))))): 5 points increase in error, 0 points decrease in error
    (/.f64 -1/3 (/.f64 (*.f64 (+.f64 b (sqrt.f64 (fma.f64 a (*.f64 c -3) (*.f64 b b)))) (neg.f64 a)) (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 (*.f64 c -3) a) 1)))): 1 points increase in error, 17 points decrease in error
    (/.f64 -1/3 (/.f64 (*.f64 (+.f64 b (sqrt.f64 (fma.f64 a (*.f64 c -3) (*.f64 b b)))) (neg.f64 a)) (/.f64 (Rewrite<= *-commutative_binary64 (*.f64 a (*.f64 c -3))) 1))): 12 points increase in error, 0 points decrease in error
    (/.f64 -1/3 (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 (*.f64 (+.f64 b (sqrt.f64 (fma.f64 a (*.f64 c -3) (*.f64 b b)))) (neg.f64 a)) 1) (*.f64 a (*.f64 c -3))))): 0 points increase in error, 13 points decrease in error
    (/.f64 -1/3 (Rewrite<= associate-*r/_binary64 (*.f64 (*.f64 (+.f64 b (sqrt.f64 (fma.f64 a (*.f64 c -3) (*.f64 b b)))) (neg.f64 a)) (/.f64 1 (*.f64 a (*.f64 c -3)))))): 17 points increase in error, 0 points decrease in error
  7. Applied egg-rr0.2

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

    \[\leadsto \color{blue}{\frac{-c}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}} \]
    Proof
    (/.f64 (neg.f64 c) (+.f64 b (sqrt.f64 (fma.f64 a (*.f64 c -3) (*.f64 b b))))): 0 points increase in error, 0 points decrease in error
    (Rewrite=> distribute-frac-neg_binary64 (neg.f64 (/.f64 c (+.f64 b (sqrt.f64 (fma.f64 a (*.f64 c -3) (*.f64 b b))))))): 0 points increase in error, 3 points decrease in error
    (Rewrite<= mul-1-neg_binary64 (*.f64 -1 (/.f64 c (+.f64 b (sqrt.f64 (fma.f64 a (*.f64 c -3) (*.f64 b b))))))): 0 points increase in error, 0 points decrease in error
  9. Final simplification0.2

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

Alternatives

Alternative 1
Error5.9
Cost14788
\[\begin{array}{l} t_0 := \frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -3\right)} - b}{a \cdot 3}\\ \mathbf{if}\;t_0 \leq -300:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.3333333333333333}{\mathsf{fma}\left(-0.5, \frac{a}{b}, \frac{0.6666666666666666}{\frac{c}{b}}\right)}\\ \end{array} \]
Alternative 2
Error0.4
Cost7488
\[\frac{-0.3333333333333333}{\left(b + \sqrt{b \cdot b + a \cdot \left(c \cdot -3\right)}\right) \cdot \frac{0.3333333333333333}{c}} \]
Alternative 3
Error5.8
Cost7104
\[\frac{-0.3333333333333333}{\mathsf{fma}\left(-0.5, \frac{a}{b}, \frac{0.6666666666666666}{\frac{c}{b}}\right)} \]
Alternative 4
Error5.9
Cost832
\[\frac{-0.3333333333333333}{0.6666666666666666 \cdot \frac{b}{c} + -0.5 \cdot \frac{a}{b}} \]
Alternative 5
Error11.9
Cost320
\[-0.5 \cdot \frac{c}{b} \]

Error

Reproduce

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