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

    1. Initial program 53.0

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

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - 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 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Simplified11.4

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - 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 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Simplified39.9

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

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

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

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

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

    if 2.205823585814744e+105 < b

    1. Initial program 58.9

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

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - 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} - \left(c \cdot a\right) \cdot 4} - b}{a \cdot 2}\\ \mathbf{elif}\;b \le 2.205823585814744 \cdot 10^{+105}:\\ \;\;\;\;\frac{c \cdot -4}{\frac{\left(b + \sqrt{b \cdot b - c \cdot \left(4 \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 "quadp (p42, positive)"

  :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: 16.1s)Debug log

sample181.0ms

Algorithm
intervals

simplify50.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

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

prune17.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 37.0b

localize23.0ms

Local error

Found 4 expressions with local error:

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

rewrite79.0ms

Algorithm
rewrite-expression-head
Counts
4 → 59
Calls

4 calls. Slowest were:

50.0ms
(/ (- (sqrt (- (* b b) (* (* 4 a) c))) b) (* 2 a))
21.0ms
(- (sqrt (- (* b b) (* (* 4 a) c))) b)
4.0ms
(- (* b b) (* (* 4 a) c))

series214.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

69.0ms
(- (sqrt (- (* b b) (* (* 4 a) c))) b)
67.0ms
(/ (- (sqrt (- (* b b) (* (* 4 a) c))) b) (* 2 a))
45.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
34.0ms
(- (* b b) (* (* 4 a) c))

simplify2.3s

Counts
32 → 71
Calls

32 calls. Slowest were:

414.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
342.0ms
(- (* (sqrt (- (* b b) (* (* 4 a) c))) (sqrt (- (* b b) (* (* 4 a) c)))) (* b b))
191.0ms
(- (pow (sqrt (- (* b b) (* (* 4 a) c))) 3) (pow b 3))

prune857.0ms

Pruning

6 alts after pruning (6 fresh and 0 done)

Merged error: 4.5b

localize27.0ms

Local error

Found 4 expressions with local error:

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

rewrite37.0ms

Algorithm
rewrite-expression-head
Counts
4 → 55
Calls

4 calls. Slowest were:

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

series285.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

134.0ms
(/ (* (* -4 c) a) (* (* 2 a) (+ (sqrt (- (* b b) (* (* 4 a) c))) b)))
59.0ms
(+ (sqrt (- (* b b) (* (* 4 a) c))) b)
51.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
40.0ms
(- (* b b) (* (* 4 a) c))

simplify3.8s

Counts
29 → 67
Calls

29 calls. Slowest were:

1.0s
(/ (* (* (* (* -4 c) a) (* (* -4 c) a)) (* (* -4 c) a)) (* (* (* (* 2 a) (* 2 a)) (* 2 a)) (* (* (+ (sqrt (- (* b b) (* (* 4 a) c))) b) (+ (sqrt (- (* b b) (* (* 4 a) c))) b)) (+ (sqrt (- (* b b) (* (* 4 a) c))) b))))
887.0ms
(/ (* (* (* (* -4 c) a) (* (* -4 c) a)) (* (* -4 c) a)) (* (* (* (* 2 a) (+ (sqrt (- (* b b) (* (* 4 a) c))) b)) (* (* 2 a) (+ (sqrt (- (* b b) (* (* 4 a) c))) b))) (* (* 2 a) (+ (sqrt (- (* b b) (* (* 4 a) c))) b))))
430.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))

prune878.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) (* (* 4 a) c)))
10.5b
(/ (* (* 2 a) (+ (sqrt (- (* b b) (* (* 4 a) c))) b)) a)
1.7b
(+ (sqrt (- (* b b) (* (* 4 a) c))) b)
0.6b
(- (* b b) (* (* 4 a) c))

rewrite31.0ms

Algorithm
rewrite-expression-head
Counts
4 → 49
Calls

4 calls. Slowest were:

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

series229.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

85.0ms
(/ (* (* 2 a) (+ (sqrt (- (* b b) (* (* 4 a) c))) b)) a)
55.0ms
(+ (sqrt (- (* b b) (* (* 4 a) c))) b)
49.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
41.0ms
(- (* b b) (* (* 4 a) c))

simplify1.7s

Counts
22 → 61
Calls

22 calls. Slowest were:

472.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
213.0ms
(* (* 2 a) (- (* (sqrt (- (* b b) (* (* 4 a) c))) (sqrt (- (* b b) (* (* 4 a) c)))) (* b b)))
181.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* 4 a) c) (* (* 4 a) c))))

prune741.0ms

Pruning

7 alts after pruning (5 fresh and 2 done)

Merged error: 4.5b

localize10.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:

prune1.0ms

Pruning

7 alts after pruning (4 fresh and 3 done)

Merged error: 4.5b

regimes309.0ms

Accuracy

90.7% (2.6b remaining)

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

bsearch453.0ms

end0.0ms

sample3.9s

Algorithm
intervals