Average Error: 32.7 → 8.2
Time: 16.0s
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 -7.0744040414122835 \cdot 10^{+130}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 4.270340906482378 \cdot 10^{-114}:\\ \;\;\;\;\frac{\sqrt{{b}^{2} - 4 \cdot \left(c \cdot a\right)} - b}{a \cdot 2}\\ \mathbf{elif}\;b \le 2.205823585814744 \cdot 10^{+105}:\\ \;\;\;\;\frac{c \cdot -4}{\frac{\left(b + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}\right) \cdot \left(a \cdot 2\right)}{a}}\\ \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

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

    1. Initial program 53.0

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

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

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

    if -7.0744040414122835e+130 < b < 4.270340906482378e-114

    1. Initial program 11.4

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

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

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

    if 4.270340906482378e-114 < b < 2.205823585814744e+105

    1. Initial program 39.9

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

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b}{2 \cdot a}}\]
    3. Using strategy rm
    4. Applied flip--39.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/42.6

      \[\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. Simplified16.4

      \[\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-/l*10.8

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

    if 2.205823585814744e+105 < b

    1. Initial program 58.9

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

      \[\leadsto \color{blue}{\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 simplification8.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -7.0744040414122835 \cdot 10^{+130}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 4.270340906482378 \cdot 10^{-114}:\\ \;\;\;\;\frac{\sqrt{{b}^{2} - 4 \cdot \left(c \cdot a\right)} - b}{a \cdot 2}\\ \mathbf{elif}\;b \le 2.205823585814744 \cdot 10^{+105}:\\ \;\;\;\;\frac{c \cdot -4}{\frac{\left(b + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}\right) \cdot \left(a \cdot 2\right)}{a}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Reproduce

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

sample209.0ms

Algorithm
intervals

simplify54.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

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

prune20.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 37.0b

localize32.0ms

Local error

Found 4 expressions with local error:

23.6b
(sqrt (- (* b b) (* (* c a) 4)))
1.3b
(- (sqrt (- (* b b) (* (* c a) 4))) b)
0.6b
(- (* b b) (* (* c a) 4))
0.1b
(/ (- (sqrt (- (* b b) (* (* c a) 4))) b) (* 2 a))

rewrite59.0ms

Algorithm
rewrite-expression-head
Counts
4 → 59
Calls

4 calls. Slowest were:

42.0ms
(/ (- (sqrt (- (* b b) (* (* c a) 4))) b) (* 2 a))
11.0ms
(- (sqrt (- (* b b) (* (* c a) 4))) b)
2.0ms
(- (* b b) (* (* c a) 4))

series235.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

73.0ms
(sqrt (- (* b b) (* (* c a) 4)))
69.0ms
(/ (- (sqrt (- (* b b) (* (* c a) 4))) b) (* 2 a))
65.0ms
(- (sqrt (- (* b b) (* (* c a) 4))) b)
28.0ms
(- (* b b) (* (* c a) 4))

simplify1.9s

Counts
32 → 71
Calls

32 calls. Slowest were:

349.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* c a) 4) 3)))
296.0ms
(- (* (sqrt (- (* b b) (* (* c a) 4))) (sqrt (- (* b b) (* (* c a) 4)))) (* b b))
161.0ms
(- (pow (sqrt (- (* b b) (* (* c a) 4))) 3) (pow b 3))

prune701.0ms

Pruning

6 alts after pruning (6 fresh and 0 done)

Merged error: 4.5b

localize15.0ms

Local error

Found 4 expressions with local error:

23.6b
(sqrt (- (* b b) (* (* c a) 4)))
14.2b
(/ (* (* c -4) a) (* (* 2 a) (+ (sqrt (- (* b b) (* (* c a) 4))) b)))
1.7b
(+ (sqrt (- (* b b) (* (* c a) 4))) b)
0.6b
(- (* b b) (* (* c a) 4))

rewrite36.0ms

Algorithm
rewrite-expression-head
Counts
4 → 55
Calls

4 calls. Slowest were:

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

series271.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

144.0ms
(/ (* (* c -4) a) (* (* 2 a) (+ (sqrt (- (* b b) (* (* c a) 4))) b)))
48.0ms
(sqrt (- (* b b) (* (* c a) 4)))
47.0ms
(+ (sqrt (- (* b b) (* (* c a) 4))) b)
31.0ms
(- (* b b) (* (* c a) 4))

simplify3.3s

Counts
29 → 67
Calls

29 calls. Slowest were:

852.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))))
731.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))))
321.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* c a) 4) 3)))

prune717.0ms

Pruning

7 alts after pruning (6 fresh and 1 done)

Merged error: 4.5b

localize7.0ms

Local error

Found 4 expressions with local error:

23.6b
(sqrt (- (* b b) (* (* c a) 4)))
10.5b
(/ (* (* 2 a) (+ (sqrt (- (* b b) (* (* c a) 4))) b)) a)
1.7b
(+ (sqrt (- (* b b) (* (* c a) 4))) b)
0.6b
(- (* b b) (* (* c a) 4))

rewrite34.0ms

Algorithm
rewrite-expression-head
Counts
4 → 49
Calls

4 calls. Slowest were:

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

series194.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

61.0ms
(/ (* (* 2 a) (+ (sqrt (- (* b b) (* (* c a) 4))) b)) a)
52.0ms
(sqrt (- (* b b) (* (* c a) 4)))
49.0ms
(+ (sqrt (- (* b b) (* (* c a) 4))) b)
32.0ms
(- (* b b) (* (* c a) 4))

simplify1.3s

Counts
22 → 61
Calls

22 calls. Slowest were:

315.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* c a) 4) 3)))
174.0ms
(* (* 2 a) (- (* (sqrt (- (* b b) (* (* c a) 4))) (sqrt (- (* b b) (* (* c a) 4)))) (* b b)))
138.0ms
(- (* 2 b) (* 2 (/ (* a c) b)))

prune684.0ms

Pruning

7 alts after pruning (5 fresh and 2 done)

Merged error: 4.5b

localize5.0ms

Local error

Found 0 expressions with local error:

rewrite0.0ms

Algorithm
rewrite-expression-head
Counts
0 → 0
Calls

0 calls. Slowest were:

series0.0ms

Counts
0 → 0
Calls

0 calls. Slowest were:

simplify0.0ms

Counts
0 → 0
Calls

0 calls. Slowest were:

prune0.0ms

Pruning

7 alts after pruning (4 fresh and 3 done)

Merged error: 4.5b

regimes288.0ms

Accuracy

90.7% (2.6b remaining)

Error of 8.2b against oracle of 5.6b and baseline of 33.1b

bsearch454.0ms

end0.0ms

sample4.7s

Algorithm
intervals