Average Error: 33.5 → 7.9
Time: 37.6s
Precision: 64
Internal Precision: 128
\[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \le -1.8990148416878514 \cdot 10^{+29}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \le -7.496249327445511 \cdot 10^{-189}:\\ \;\;\;\;\frac{\sqrt[3]{\frac{\frac{1}{2}}{a}}}{\sqrt{b \cdot b + -4 \cdot \left(a \cdot c\right)} - b} \cdot \left(\left(\sqrt[3]{-a} \cdot c\right) \cdot \left(-4 \cdot \left(\sqrt[3]{\frac{-1}{2}} \cdot \sqrt[3]{\frac{-1}{2}}\right)\right)\right)\\ \mathbf{elif}\;b \le 1.0994587633517505 \cdot 10^{+108}:\\ \;\;\;\;\frac{1}{\frac{2 \cdot a}{\left(-b\right) - \sqrt{b \cdot b + -4 \cdot \left(a \cdot c\right)}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original33.5
Target20.9
Herbie7.9
\[\begin{array}{l} \mathbf{if}\;b \lt 0:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \end{array}\]

Derivation

  1. Split input into 4 regimes
  2. if b < -1.8990148416878514e+29

    1. Initial program 56.5

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Initial simplification56.5

      \[\leadsto \frac{\left(-b\right) - \sqrt{b \cdot b + -4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    3. Taylor expanded around -inf 4.6

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
    4. Simplified4.6

      \[\leadsto \color{blue}{\frac{-c}{b}}\]

    if -1.8990148416878514e+29 < b < -7.496249327445511e-189

    1. Initial program 32.6

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Initial simplification32.6

      \[\leadsto \frac{\left(-b\right) - \sqrt{b \cdot b + -4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    3. Using strategy rm
    4. Applied *-un-lft-identity32.6

      \[\leadsto \frac{\left(-b\right) - \color{blue}{1 \cdot \sqrt{b \cdot b + -4 \cdot \left(a \cdot c\right)}}}{2 \cdot a}\]
    5. Applied *-un-lft-identity32.6

      \[\leadsto \frac{\color{blue}{1 \cdot \left(-b\right)} - 1 \cdot \sqrt{b \cdot b + -4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    6. Applied distribute-lft-out--32.6

      \[\leadsto \frac{\color{blue}{1 \cdot \left(\left(-b\right) - \sqrt{b \cdot b + -4 \cdot \left(a \cdot c\right)}\right)}}{2 \cdot a}\]
    7. Applied associate-/l*32.6

      \[\leadsto \color{blue}{\frac{1}{\frac{2 \cdot a}{\left(-b\right) - \sqrt{b \cdot b + -4 \cdot \left(a \cdot c\right)}}}}\]
    8. Using strategy rm
    9. Applied div-inv32.7

      \[\leadsto \frac{1}{\color{blue}{\left(2 \cdot a\right) \cdot \frac{1}{\left(-b\right) - \sqrt{b \cdot b + -4 \cdot \left(a \cdot c\right)}}}}\]
    10. Applied associate-/r*32.7

      \[\leadsto \color{blue}{\frac{\frac{1}{2 \cdot a}}{\frac{1}{\left(-b\right) - \sqrt{b \cdot b + -4 \cdot \left(a \cdot c\right)}}}}\]
    11. Using strategy rm
    12. Applied flip--32.8

      \[\leadsto \frac{\frac{1}{2 \cdot a}}{\frac{1}{\color{blue}{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b + -4 \cdot \left(a \cdot c\right)} \cdot \sqrt{b \cdot b + -4 \cdot \left(a \cdot c\right)}}{\left(-b\right) + \sqrt{b \cdot b + -4 \cdot \left(a \cdot c\right)}}}}}\]
    13. Applied associate-/r/32.8

      \[\leadsto \frac{\frac{1}{2 \cdot a}}{\color{blue}{\frac{1}{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b + -4 \cdot \left(a \cdot c\right)} \cdot \sqrt{b \cdot b + -4 \cdot \left(a \cdot c\right)}} \cdot \left(\left(-b\right) + \sqrt{b \cdot b + -4 \cdot \left(a \cdot c\right)}\right)}}\]
    14. Applied add-cube-cbrt33.2

      \[\leadsto \frac{\color{blue}{\left(\sqrt[3]{\frac{1}{2 \cdot a}} \cdot \sqrt[3]{\frac{1}{2 \cdot a}}\right) \cdot \sqrt[3]{\frac{1}{2 \cdot a}}}}{\frac{1}{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b + -4 \cdot \left(a \cdot c\right)} \cdot \sqrt{b \cdot b + -4 \cdot \left(a \cdot c\right)}} \cdot \left(\left(-b\right) + \sqrt{b \cdot b + -4 \cdot \left(a \cdot c\right)}\right)}\]
    15. Applied times-frac33.2

      \[\leadsto \color{blue}{\frac{\sqrt[3]{\frac{1}{2 \cdot a}} \cdot \sqrt[3]{\frac{1}{2 \cdot a}}}{\frac{1}{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b + -4 \cdot \left(a \cdot c\right)} \cdot \sqrt{b \cdot b + -4 \cdot \left(a \cdot c\right)}}} \cdot \frac{\sqrt[3]{\frac{1}{2 \cdot a}}}{\left(-b\right) + \sqrt{b \cdot b + -4 \cdot \left(a \cdot c\right)}}}\]
    16. Simplified17.7

      \[\leadsto \color{blue}{\left(\left(c \cdot \left(a \cdot 4\right)\right) \cdot \left(\sqrt[3]{\frac{\frac{1}{2}}{a}} \cdot \sqrt[3]{\frac{\frac{1}{2}}{a}}\right)\right)} \cdot \frac{\sqrt[3]{\frac{1}{2 \cdot a}}}{\left(-b\right) + \sqrt{b \cdot b + -4 \cdot \left(a \cdot c\right)}}\]
    17. Simplified17.7

      \[\leadsto \left(\left(c \cdot \left(a \cdot 4\right)\right) \cdot \left(\sqrt[3]{\frac{\frac{1}{2}}{a}} \cdot \sqrt[3]{\frac{\frac{1}{2}}{a}}\right)\right) \cdot \color{blue}{\frac{\sqrt[3]{\frac{\frac{1}{2}}{a}}}{\sqrt{\left(a \cdot c\right) \cdot -4 + b \cdot b} - b}}\]
    18. Taylor expanded around -inf 38.4

      \[\leadsto \color{blue}{\left(-4 \cdot \left({\left(a \cdot -1\right)}^{\frac{1}{3}} \cdot \left({\left(\sqrt[3]{\frac{-1}{2}}\right)}^{2} \cdot c\right)\right)\right)} \cdot \frac{\sqrt[3]{\frac{\frac{1}{2}}{a}}}{\sqrt{\left(a \cdot c\right) \cdot -4 + b \cdot b} - b}\]
    19. Simplified10.7

      \[\leadsto \color{blue}{\left(\left(\sqrt[3]{-a} \cdot c\right) \cdot \left(\left(\sqrt[3]{\frac{-1}{2}} \cdot \sqrt[3]{\frac{-1}{2}}\right) \cdot -4\right)\right)} \cdot \frac{\sqrt[3]{\frac{\frac{1}{2}}{a}}}{\sqrt{\left(a \cdot c\right) \cdot -4 + b \cdot b} - b}\]

    if -7.496249327445511e-189 < b < 1.0994587633517505e+108

    1. Initial program 10.8

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Initial simplification10.8

      \[\leadsto \frac{\left(-b\right) - \sqrt{b \cdot b + -4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    3. Using strategy rm
    4. Applied *-un-lft-identity10.8

      \[\leadsto \frac{\left(-b\right) - \color{blue}{1 \cdot \sqrt{b \cdot b + -4 \cdot \left(a \cdot c\right)}}}{2 \cdot a}\]
    5. Applied *-un-lft-identity10.8

      \[\leadsto \frac{\color{blue}{1 \cdot \left(-b\right)} - 1 \cdot \sqrt{b \cdot b + -4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    6. Applied distribute-lft-out--10.8

      \[\leadsto \frac{\color{blue}{1 \cdot \left(\left(-b\right) - \sqrt{b \cdot b + -4 \cdot \left(a \cdot c\right)}\right)}}{2 \cdot a}\]
    7. Applied associate-/l*10.9

      \[\leadsto \color{blue}{\frac{1}{\frac{2 \cdot a}{\left(-b\right) - \sqrt{b \cdot b + -4 \cdot \left(a \cdot c\right)}}}}\]

    if 1.0994587633517505e+108 < b

    1. Initial program 46.2

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Initial simplification46.2

      \[\leadsto \frac{\left(-b\right) - \sqrt{b \cdot b + -4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    3. Taylor expanded around inf 3.5

      \[\leadsto \color{blue}{\frac{c}{b} - \frac{b}{a}}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification7.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.8990148416878514 \cdot 10^{+29}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \le -7.496249327445511 \cdot 10^{-189}:\\ \;\;\;\;\frac{\sqrt[3]{\frac{\frac{1}{2}}{a}}}{\sqrt{b \cdot b + -4 \cdot \left(a \cdot c\right)} - b} \cdot \left(\left(\sqrt[3]{-a} \cdot c\right) \cdot \left(-4 \cdot \left(\sqrt[3]{\frac{-1}{2}} \cdot \sqrt[3]{\frac{-1}{2}}\right)\right)\right)\\ \mathbf{elif}\;b \le 1.0994587633517505 \cdot 10^{+108}:\\ \;\;\;\;\frac{1}{\frac{2 \cdot a}{\left(-b\right) - \sqrt{b \cdot b + -4 \cdot \left(a \cdot c\right)}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\]

Reproduce

herbie shell --seed 2018365 
(FPCore (a b c)
  :name "The quadratic formula (r2)"

  :herbie-target
  (if (< b 0) (/ c (* a (/ (+ (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))) (/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))

  (/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))

Details

Time bar (total: 28.6s)Debug log

start165.0ms

Algorithm
intervals

setup135.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 34.4b

localize57.0ms

Local error

Found 4 expressions with local error:

24.1b
(sqrt (+ (* b b) (* -4 (* a c))))
1.2b
(- (- b) (sqrt (+ (* b b) (* -4 (* a c)))))
0.8b
(+ (* b b) (* -4 (* a c)))
0.1b
(/ (- (- b) (sqrt (+ (* b b) (* -4 (* a c))))) (* 2 a))

rewrite28.0ms

Algorithm
rewrite-expression-head
Counts
4 → 69
Calls

4 calls. Slowest were:

15.0ms
(/ (- (- b) (sqrt (+ (* b b) (* -4 (* a c))))) (* 2 a))
6.0ms
(- (- b) (sqrt (+ (* b b) (* -4 (* a c)))))
3.0ms
(sqrt (+ (* b b) (* -4 (* a c))))

series246.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

88.0ms
(/ (- (- b) (sqrt (+ (* b b) (* -4 (* a c))))) (* 2 a))
69.0ms
(sqrt (+ (* b b) (* -4 (* a c))))
63.0ms
(- (- b) (sqrt (+ (* b b) (* -4 (* a c)))))
26.0ms
(+ (* b b) (* -4 (* a c)))

simplify2.0s

Counts
46 → 81
Calls

46 calls. Slowest were:

298.0ms
(- (pow (- b) 3) (pow (sqrt (+ (* b b) (* -4 (* a c)))) 3))
191.0ms
(sqrt (- (* (* b b) (* b b)) (* (* -4 (* a c)) (* -4 (* a c)))))
174.0ms
(- (* (- b) (- b)) (* (sqrt (+ (* b b) (* -4 (* a c)))) (sqrt (+ (* b b) (* -4 (* a c))))))

prune1.2s

Pruning

7 alts after pruning (7 fresh and 0 done)

Merged error: 5.9b

localize7.0ms

Local error

Found 4 expressions with local error:

24.1b
(sqrt (+ (* b b) (* -4 (* a c))))
1.2b
(- (- b) (sqrt (+ (* b b) (* -4 (* a c)))))
0.8b
(+ (* b b) (* -4 (* a c)))
0.2b
(/ 1 (/ (* 2 a) (- (- b) (sqrt (+ (* b b) (* -4 (* a c)))))))

rewrite20.0ms

Algorithm
rewrite-expression-head
Counts
4 → 68
Calls

4 calls. Slowest were:

8.0ms
(/ 1 (/ (* 2 a) (- (- b) (sqrt (+ (* b b) (* -4 (* a c)))))))
6.0ms
(- (- b) (sqrt (+ (* b b) (* -4 (* a c)))))
3.0ms
(+ (* b b) (* -4 (* a c)))

series248.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

109.0ms
(/ 1 (/ (* 2 a) (- (- b) (sqrt (+ (* b b) (* -4 (* a c)))))))
58.0ms
(- (- b) (sqrt (+ (* b b) (* -4 (* a c)))))
50.0ms
(sqrt (+ (* b b) (* -4 (* a c))))
31.0ms
(+ (* b b) (* -4 (* a c)))

simplify1.5s

Counts
39 → 80
Calls

39 calls. Slowest were:

265.0ms
(+ (* (- b) (- b)) (+ (* (sqrt (+ (* b b) (* -4 (* a c)))) (sqrt (+ (* b b) (* -4 (* a c))))) (* (- b) (sqrt (+ (* b b) (* -4 (* a c)))))))
148.0ms
(sqrt (+ (pow (* b b) 3) (pow (* -4 (* a c)) 3)))
146.0ms
(sqrt (- (* (* b b) (* b b)) (* (* -4 (* a c)) (* -4 (* a c)))))

prune1.4s

Pruning

7 alts after pruning (6 fresh and 1 done)

Merged error: 5.9b

localize16.0ms

Local error

Found 4 expressions with local error:

24.1b
(sqrt (+ (* b b) (* -4 (* a c))))
1.2b
(- (- b) (sqrt (+ (* b b) (* -4 (* a c)))))
0.8b
(+ (* b b) (* -4 (* a c)))
0.3b
(/ (/ 1 (* 2 a)) (/ 1 (- (- b) (sqrt (+ (* b b) (* -4 (* a c)))))))

rewrite17.0ms

Algorithm
rewrite-expression-head
Counts
4 → 92
Calls

4 calls. Slowest were:

6.0ms
(- (- b) (sqrt (+ (* b b) (* -4 (* a c)))))
5.0ms
(/ (/ 1 (* 2 a)) (/ 1 (- (- b) (sqrt (+ (* b b) (* -4 (* a c)))))))
3.0ms
(+ (* b b) (* -4 (* a c)))

series244.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

93.0ms
(/ (/ 1 (* 2 a)) (/ 1 (- (- b) (sqrt (+ (* b b) (* -4 (* a c)))))))
65.0ms
(- (- b) (sqrt (+ (* b b) (* -4 (* a c)))))
44.0ms
(+ (* b b) (* -4 (* a c)))
42.0ms
(sqrt (+ (* b b) (* -4 (* a c))))

simplify8.4s

Counts
87 → 104
Calls

87 calls. Slowest were:

664.0ms
(/ (sqrt (/ 1 (* 2 a))) (/ 1 (- (pow (- b) 3) (pow (sqrt (+ (* b b) (* -4 (* a c)))) 3))))
487.0ms
(/ 1 (/ 1 (- (* (- b) (- b)) (* (sqrt (+ (* b b) (* -4 (* a c)))) (sqrt (+ (* b b) (* -4 (* a c))))))))
470.0ms
(/ 1 (/ 1 (- (* (- b) (- b)) (* (sqrt (+ (* b b) (* -4 (* a c)))) (sqrt (+ (* b b) (* -4 (* a c))))))))

prune1.8s

Pruning

9 alts after pruning (7 fresh and 2 done)

Merged error: 5.9b

localize50.0ms

Local error

Found 4 expressions with local error:

24.1b
(sqrt (+ (* (* a c) -4) (* b b)))
11.6b
(* (* c (* a 4)) (* (cbrt (/ 1/2 a)) (cbrt (/ 1/2 a))))
3.3b
(* (* (* c (* a 4)) (* (cbrt (/ 1/2 a)) (cbrt (/ 1/2 a)))) (/ (cbrt (/ 1/2 a)) (- (sqrt (+ (* (* a c) -4) (* b b))) b)))
1.2b
(- (sqrt (+ (* (* a c) -4) (* b b))) b)

rewrite75.0ms

Algorithm
rewrite-expression-head
Counts
4 → 102
Calls

4 calls. Slowest were:

43.0ms
(* (* (* c (* a 4)) (* (cbrt (/ 1/2 a)) (cbrt (/ 1/2 a)))) (/ (cbrt (/ 1/2 a)) (- (sqrt (+ (* (* a c) -4) (* b b))) b)))
16.0ms
(- (sqrt (+ (* (* a c) -4) (* b b))) b)
11.0ms
(* (* c (* a 4)) (* (cbrt (/ 1/2 a)) (cbrt (/ 1/2 a))))

series510.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

247.0ms
(* (* (* c (* a 4)) (* (cbrt (/ 1/2 a)) (cbrt (/ 1/2 a)))) (/ (cbrt (/ 1/2 a)) (- (sqrt (+ (* (* a c) -4) (* b b))) b)))
156.0ms
(* (* c (* a 4)) (* (cbrt (/ 1/2 a)) (cbrt (/ 1/2 a))))
63.0ms
(- (sqrt (+ (* (* a c) -4) (* b b))) b)
43.0ms
(sqrt (+ (* (* a c) -4) (* b b)))

simplify7.3s

Counts
81 → 114
Calls

81 calls. Slowest were:

450.0ms
(* (* (* c (* a 4)) (* (cbrt (/ 1/2 a)) (cbrt 1/2))) (/ (cbrt (/ 1/2 a)) (- (sqrt (+ (* (* a c) -4) (* b b))) b)))
364.0ms
(* (* (* c (* a 4)) (* (cbrt 1/2) (cbrt (/ 1/2 a)))) (/ (cbrt (/ 1/2 a)) (- (sqrt (+ (* (* a c) -4) (* b b))) b)))
320.0ms
(* (* (* (* (* c (* a 4)) (* c (* a 4))) (* c (* a 4))) (* (* (* (cbrt (/ 1/2 a)) (cbrt (/ 1/2 a))) (* (cbrt (/ 1/2 a)) (cbrt (/ 1/2 a)))) (* (cbrt (/ 1/2 a)) (cbrt (/ 1/2 a))))) (/ (/ 1/2 a) (* (* (- (sqrt (+ (* (* a c) -4) (* b b))) b) (- (sqrt (+ (* (* a c) -4) (* b b))) b)) (- (sqrt (+ (* (* a c) -4) (* b b))) b))))

prune2.2s

Pruning

8 alts after pruning (6 fresh and 2 done)

Merged error: 5.9b

regimes392.0ms

Accuracy

91% (2.2b remaining)

Error of 7.9b against oracle of 5.6b and baseline of 30.2b

bsearch752.0ms