Average Error: 33.5 → 7.1
Time: 24.8s
Precision: 64
Internal Precision: 128
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \le -4.209504678355017 \cdot 10^{+65}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le -5.15631482418829 \cdot 10^{-230}:\\ \;\;\;\;\frac{\sqrt{{b}^{2} - \left(c \cdot a\right) \cdot 4} - b}{a \cdot 2}\\ \mathbf{elif}\;b \le 1.0547782469042754 \cdot 10^{+108}:\\ \;\;\;\;\frac{-2}{\frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + b}{c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \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.8
Herbie7.1
\[\begin{array}{l} \mathbf{if}\;b \lt 0:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}}\\ \end{array}\]

Derivation

  1. Split input into 4 regimes
  2. if b < -4.209504678355017e+65

    1. Initial program 39.8

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

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

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

    if -4.209504678355017e+65 < b < -5.15631482418829e-230

    1. Initial program 8.7

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

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

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

    if -5.15631482418829e-230 < b < 1.0547782469042754e+108

    1. Initial program 29.7

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

      \[\leadsto \frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b}{2 \cdot a}\]
    3. Using strategy rm
    4. Applied flip--29.9

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

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

      \[\leadsto \frac{\color{blue}{\left(c \cdot -4\right) \cdot a}}{\left(2 \cdot a\right) \cdot \left(\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + b\right)}\]
    7. Using strategy rm
    8. Applied associate-/r*15.9

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

      \[\leadsto \frac{\color{blue}{-2 \cdot c}}{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + b}\]
    10. Using strategy rm
    11. Applied associate-/l*10.1

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

    if 1.0547782469042754e+108 < b

    1. Initial program 59.1

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -4.209504678355017 \cdot 10^{+65}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le -5.15631482418829 \cdot 10^{-230}:\\ \;\;\;\;\frac{\sqrt{{b}^{2} - \left(c \cdot a\right) \cdot 4} - b}{a \cdot 2}\\ \mathbf{elif}\;b \le 1.0547782469042754 \cdot 10^{+108}:\\ \;\;\;\;\frac{-2}{\frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + b}{c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array}\]

Reproduce

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

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

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

Details

Time bar (total: 17.1s)Debug log

start202.0ms

Algorithm
intervals

setup122.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 35.7b

localize21.0ms

Local error

Found 4 expressions with local error:

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

rewrite74.0ms

Algorithm
rewrite-expression-head
Counts
4 → 59
Calls

4 calls. Slowest were:

47.0ms
(/ (- (sqrt (- (* b b) (* (* c a) 4))) b) (* 2 a))
19.0ms
(- (sqrt (- (* b b) (* (* c a) 4))) b)
4.0ms
(- (* b b) (* (* c a) 4))

series236.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

72.0ms
(/ (- (sqrt (- (* b b) (* (* c a) 4))) b) (* 2 a))
64.0ms
(sqrt (- (* b b) (* (* c a) 4)))
57.0ms
(- (sqrt (- (* b b) (* (* c a) 4))) b)
42.0ms
(- (* b b) (* (* c a) 4))

simplify2.2s

Counts
32 → 71
Calls

32 calls. Slowest were:

406.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* c a) 4) 3)))
333.0ms
(- (* (sqrt (- (* b b) (* (* c a) 4))) (sqrt (- (* b b) (* (* c a) 4)))) (* b b))
225.0ms
(- (pow (sqrt (- (* b b) (* (* c a) 4))) 3) (pow b 3))

prune961.0ms

Pruning

6 alts after pruning (6 fresh and 0 done)

Merged error: 5.9b

localize13.0ms

Local error

Found 4 expressions with local error:

25.1b
(sqrt (- (* b b) (* (* c a) 4)))
17.5b
(/ (* (* c -4) a) (* (* 2 a) (+ (sqrt (- (* b b) (* (* c a) 4))) b)))
1.2b
(+ (sqrt (- (* b b) (* (* c a) 4))) b)
0.8b
(- (* b b) (* (* c a) 4))

rewrite27.0ms

Algorithm
rewrite-expression-head
Counts
4 → 55
Calls

4 calls. Slowest were:

11.0ms
(/ (* (* c -4) a) (* (* 2 a) (+ (sqrt (- (* b b) (* (* c a) 4))) b)))
8.0ms
(+ (sqrt (- (* b b) (* (* c a) 4))) b)
4.0ms
(- (* b b) (* (* c a) 4))

series295.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

135.0ms
(/ (* (* c -4) a) (* (* 2 a) (+ (sqrt (- (* b b) (* (* c a) 4))) b)))
59.0ms
(+ (sqrt (- (* b b) (* (* c a) 4))) b)
58.0ms
(sqrt (- (* b b) (* (* c a) 4)))
44.0ms
(- (* b b) (* (* c a) 4))

simplify3.7s

Counts
29 → 67
Calls

29 calls. Slowest were:

898.0ms
(/ (* (* (* (* c -4) a) (* (* c -4) a)) (* (* c -4) a)) (* (* (* (* 2 a) (* 2 a)) (* 2 a)) (* (* (+ (sqrt (- (* b b) (* (* c a) 4))) b) (+ (sqrt (- (* b b) (* (* c a) 4))) b)) (+ (sqrt (- (* b b) (* (* c a) 4))) b))))
859.0ms
(/ (* (* (* (* c -4) a) (* (* c -4) a)) (* (* c -4) a)) (* (* (* (* 2 a) (+ (sqrt (- (* b b) (* (* c a) 4))) b)) (* (* 2 a) (+ (sqrt (- (* b b) (* (* c a) 4))) b))) (* (* 2 a) (+ (sqrt (- (* b b) (* (* c a) 4))) b))))
446.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* c a) 4) 3)))

prune1.2s

Pruning

6 alts after pruning (6 fresh and 0 done)

Merged error: 5.9b

localize10.0ms

Local error

Found 4 expressions with local error:

25.1b
(sqrt (- (* b b) (* (* c a) 4)))
14.6b
(/ (* (* c -4) a) (* 2 a))
1.2b
(+ (sqrt (- (* b b) (* (* c a) 4))) b)
0.8b
(- (* b b) (* (* c a) 4))

rewrite19.0ms

Algorithm
rewrite-expression-head
Counts
4 → 51
Calls

4 calls. Slowest were:

10.0ms
(+ (sqrt (- (* b b) (* (* c a) 4))) b)
5.0ms
(/ (* (* c -4) a) (* 2 a))
2.0ms
(- (* b b) (* (* c a) 4))

series153.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

57.0ms
(sqrt (- (* b b) (* (* c a) 4)))
48.0ms
(+ (sqrt (- (* b b) (* (* c a) 4))) b)
40.0ms
(- (* b b) (* (* c a) 4))
9.0ms
(/ (* (* c -4) a) (* 2 a))

simplify2.5s

Counts
24 → 63
Calls

24 calls. Slowest were:

668.0ms
(- (log (* (* c -4) a)) (log (* 2 a)))
536.0ms
(/ (* (* (* (* c -4) a) (* (* c -4) a)) (* (* c -4) a)) (* (* (* 2 a) (* 2 a)) (* 2 a)))
465.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* c a) 4) 3)))

prune1.0s

Pruning

6 alts after pruning (5 fresh and 1 done)

Merged error: 5.9b

localize8.0ms

Local error

Found 4 expressions with local error:

25.1b
(sqrt (- (* b b) (* (* c a) 4)))
1.2b
(+ (sqrt (- (* b b) (* (* c a) 4))) b)
0.8b
(- (* b b) (* (* c a) 4))
0.4b
(/ (* -2 c) (+ (sqrt (- (* b b) (* (* c a) 4))) b))

rewrite37.0ms

Algorithm
rewrite-expression-head
Counts
4 → 57
Calls

4 calls. Slowest were:

15.0ms
(+ (sqrt (- (* b b) (* (* c a) 4))) b)
14.0ms
(/ (* -2 c) (+ (sqrt (- (* b b) (* (* c a) 4))) b))
4.0ms
(sqrt (- (* b b) (* (* c a) 4)))

series328.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

157.0ms
(/ (* -2 c) (+ (sqrt (- (* b b) (* (* c a) 4))) b))
72.0ms
(+ (sqrt (- (* b b) (* (* c a) 4))) b)
58.0ms
(sqrt (- (* b b) (* (* c a) 4)))
41.0ms
(- (* b b) (* (* c a) 4))

simplify2.3s

Counts
32 → 69
Calls

32 calls. Slowest were:

644.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* c a) 4) 3)))
267.0ms
(+ (* (sqrt (- (* b b) (* (* c a) 4))) (sqrt (- (* b b) (* (* c a) 4)))) (- (* b b) (* (sqrt (- (* b b) (* (* c a) 4))) b)))
203.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* c a) 4) (* (* c a) 4))))

prune878.0ms

Pruning

5 alts after pruning (4 fresh and 1 done)

Merged error: 5.9b

regimes228.0ms

Accuracy

94.1% (1.4b remaining)

Error of 7.1b against oracle of 5.7b and baseline of 29.2b

bsearch588.0ms