Average Error: 32.8 → 8.8
Time: 26.4s
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 -4.2485149476691936 \cdot 10^{+130}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le -9.532534227544595 \cdot 10^{-103}:\\ \;\;\;\;\frac{\frac{4 \cdot \left(c \cdot a\right)}{a \cdot 2}}{\sqrt{a \cdot \left(-4 \cdot c\right) + b \cdot b} - b}\\ \mathbf{elif}\;b \le 4.62148638684652 \cdot 10^{+78}:\\ \;\;\;\;\frac{-b}{a \cdot 2} - \frac{\sqrt{{b}^{2} - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\ \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

Original32.8
Target20.2
Herbie8.8
\[\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 < -4.2485149476691936e+130

    1. Initial program 60.8

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

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

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

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

    if -4.2485149476691936e+130 < b < -9.532534227544595e-103

    1. Initial program 42.3

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

      \[\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 flip--42.3

      \[\leadsto \frac{\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)}}}}{2 \cdot a}\]
    5. Applied associate-/l/44.3

      \[\leadsto \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(2 \cdot a\right) \cdot \left(\left(-b\right) + \sqrt{b \cdot b + -4 \cdot \left(a \cdot c\right)}\right)}}\]
    6. Simplified16.8

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

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

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

    if -9.532534227544595e-103 < b < 4.62148638684652e+78

    1. Initial program 11.5

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

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

      \[\leadsto \frac{\left(-b\right) - \sqrt{\color{blue}{{b}^{2} - 4 \cdot \left(a \cdot c\right)}}}{2 \cdot a}\]
    4. Using strategy rm
    5. Applied div-sub11.5

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

    if 4.62148638684652e+78 < b

    1. Initial program 40.4

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -4.2485149476691936 \cdot 10^{+130}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le -9.532534227544595 \cdot 10^{-103}:\\ \;\;\;\;\frac{\frac{4 \cdot \left(c \cdot a\right)}{a \cdot 2}}{\sqrt{a \cdot \left(-4 \cdot c\right) + b \cdot b} - b}\\ \mathbf{elif}\;b \le 4.62148638684652 \cdot 10^{+78}:\\ \;\;\;\;\frac{-b}{a \cdot 2} - \frac{\sqrt{{b}^{2} - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\]

Reproduce

herbie shell --seed 2018362 
(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: 18.4s)Debug log

start196.0ms

Algorithm
intervals

setup119.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 30.7b

localize38.0ms

Local error

Found 4 expressions with local error:

21.0b
(sqrt (+ (* b b) (* -4 (* a c))))
0.9b
(- (- b) (sqrt (+ (* b b) (* -4 (* a c)))))
0.4b
(+ (* b b) (* -4 (* a c)))
0.1b
(/ (- (- b) (sqrt (+ (* b b) (* -4 (* a c))))) (* 2 a))

rewrite35.0ms

Algorithm
rewrite-expression-head
Counts
4 → 69
Calls

4 calls. Slowest were:

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

series235.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

76.0ms
(- (- b) (sqrt (+ (* b b) (* -4 (* a c)))))
64.0ms
(sqrt (+ (* b b) (* -4 (* a c))))
60.0ms
(/ (- (- b) (sqrt (+ (* b b) (* -4 (* a c))))) (* 2 a))
35.0ms
(+ (* b b) (* -4 (* a c)))

simplify2.1s

Counts
46 → 81
Calls

46 calls. Slowest were:

406.0ms
(- (pow (- b) 3) (pow (sqrt (+ (* b b) (* -4 (* a c)))) 3))
190.0ms
(- (* (- b) (- b)) (* (sqrt (+ (* b b) (* -4 (* a c)))) (sqrt (+ (* b b) (* -4 (* a c))))))
179.0ms
(sqrt (+ (pow (* b b) 3) (pow (* -4 (* a c)) 3)))

prune1.2s

Pruning

7 alts after pruning (7 fresh and 0 done)

Merged error: 4.1b

localize24.0ms

Local error

Found 4 expressions with local error:

21.0b
(sqrt (+ (* b b) (* -4 (* a c))))
13.2b
(/ (* 4 (* a c)) (* (* 2 a) (+ (- b) (sqrt (+ (* b b) (* -4 (* a c)))))))
1.8b
(+ (- b) (sqrt (+ (* b b) (* -4 (* a c)))))
0.4b
(+ (* b b) (* -4 (* a c)))

rewrite43.0ms

Algorithm
rewrite-expression-head
Counts
4 → 57
Calls

4 calls. Slowest were:

18.0ms
(/ (* 4 (* a c)) (* (* 2 a) (+ (- b) (sqrt (+ (* b b) (* -4 (* a c)))))))
11.0ms
(+ (- b) (sqrt (+ (* b b) (* -4 (* a c)))))
7.0ms
(sqrt (+ (* b b) (* -4 (* a c))))

series308.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

145.0ms
(/ (* 4 (* a c)) (* (* 2 a) (+ (- b) (sqrt (+ (* b b) (* -4 (* a c)))))))
67.0ms
(sqrt (+ (* b b) (* -4 (* a c))))
53.0ms
(+ (- b) (sqrt (+ (* b b) (* -4 (* a c)))))
44.0ms
(+ (* b b) (* -4 (* a c)))

simplify4.5s

Counts
30 → 69
Calls

30 calls. Slowest were:

916.0ms
(/ (* (* (* 4 (* a c)) (* 4 (* a c))) (* 4 (* a c))) (* (* (* (* 2 a) (* 2 a)) (* 2 a)) (* (* (+ (- b) (sqrt (+ (* b b) (* -4 (* a c))))) (+ (- b) (sqrt (+ (* b b) (* -4 (* a c)))))) (+ (- b) (sqrt (+ (* b b) (* -4 (* a c))))))))
740.0ms
(/ (* (* (* 4 (* a c)) (* 4 (* a c))) (* 4 (* a c))) (* (* (* (* 2 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))))))))
593.0ms
(- (log (* 4 (* a c))) (+ (log (* 2 a)) (log (+ (- b) (sqrt (+ (* b b) (* -4 (* a c))))))))

prune1.2s

Pruning

8 alts after pruning (7 fresh and 1 done)

Merged error: 4.1b

localize39.0ms

Local error

Found 4 expressions with local error:

21.0b
(sqrt (+ (* a (* -4 c)) (* b b)))
10.4b
(/ (* 4 (* a c)) (* 2 a))
1.8b
(- (sqrt (+ (* a (* -4 c)) (* b b))) b)
0.4b
(+ (* a (* -4 c)) (* b b))

rewrite38.0ms

Algorithm
rewrite-expression-head
Counts
4 → 51
Calls

4 calls. Slowest were:

21.0ms
(- (sqrt (+ (* a (* -4 c)) (* b b))) b)
7.0ms
(/ (* 4 (* a c)) (* 2 a))
5.0ms
(+ (* a (* -4 c)) (* b b))

series149.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

49.0ms
(sqrt (+ (* a (* -4 c)) (* b b)))
49.0ms
(- (sqrt (+ (* a (* -4 c)) (* b b))) b)
38.0ms
(+ (* a (* -4 c)) (* b b))
14.0ms
(/ (* 4 (* a c)) (* 2 a))

simplify1.4s

Counts
23 → 63
Calls

23 calls. Slowest were:

466.0ms
(/ (* (* (* 4 (* a c)) (* 4 (* a c))) (* 4 (* a c))) (* (* (* 2 a) (* 2 a)) (* 2 a)))
361.0ms
(- (log (* 4 (* a c))) (log (* 2 a)))
233.0ms
(sqrt (- (* (* a (* -4 c)) (* a (* -4 c))) (* (* b b) (* b b))))

prune960.0ms

Pruning

8 alts after pruning (6 fresh and 2 done)

Merged error: 4.1b

localize24.0ms

Local error

Found 4 expressions with local error:

21.0b
(sqrt (- (pow b 2) (* 4 (* a c))))
0.9b
(- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))
0.4b
(- (pow b 2) (* 4 (* a c)))
0.1b
(/ (- (- b) (sqrt (- (pow b 2) (* 4 (* a c))))) (* 2 a))

rewrite44.0ms

Algorithm
rewrite-expression-head
Counts
4 → 70
Calls

4 calls. Slowest were:

18.0ms
(/ (- (- b) (sqrt (- (pow b 2) (* 4 (* a c))))) (* 2 a))
14.0ms
(- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))
5.0ms
(sqrt (- (pow b 2) (* 4 (* a c))))

series222.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

71.0ms
(/ (- (- b) (sqrt (- (pow b 2) (* 4 (* a c))))) (* 2 a))
59.0ms
(- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))
55.0ms
(sqrt (- (pow b 2) (* 4 (* a c))))
36.0ms
(- (pow b 2) (* 4 (* a c)))

simplify3.5s

Counts
46 → 82
Calls

46 calls. Slowest were:

984.0ms
(- (* (- b) (- b)) (* (sqrt (- (pow b 2) (* 4 (* a c)))) (sqrt (- (pow b 2) (* 4 (* a c))))))
339.0ms
(sqrt (- (pow (pow b 2) 3) (pow (* 4 (* a c)) 3)))
247.0ms
(- (pow (- b) 3) (pow (sqrt (- (pow b 2) (* 4 (* a c)))) 3))

prune1.2s

Pruning

7 alts after pruning (5 fresh and 2 done)

Merged error: 4.1b

regimes342.0ms

Accuracy

86.6% (3.5b remaining)

Error of 8.8b against oracle of 5.3b and baseline of 31.3b

bsearch533.0ms