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

Error

Bits error versus a

Bits error versus b

Bits error versus c

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. Taylor expanded around inf 60.8

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
    5. 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. Using strategy rm
    3. 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}\]
    4. 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)}}\]
    5. Simplified16.8

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

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

      \[\leadsto \frac{\frac{\left(c \cdot 4\right) \cdot a}{2 \cdot a}}{\color{blue}{\sqrt{(-4 \cdot \left(a \cdot c\right) + \left(b \cdot b\right))_*} - 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. Taylor expanded around inf 11.5

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

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

      \[\leadsto \color{blue}{\frac{-b}{2 \cdot a} - \frac{\sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\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. Taylor expanded around inf 40.4

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

      \[\leadsto \frac{\left(-b\right) - \sqrt{\color{blue}{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*}}}{2 \cdot a}\]
    4. 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{\left(4 \cdot c\right) \cdot a}{2 \cdot a}}{\sqrt{(-4 \cdot \left(a \cdot c\right) + \left(b \cdot b\right))_*} - b}\\ \mathbf{elif}\;b \le 4.62148638684652 \cdot 10^{+78}:\\ \;\;\;\;\frac{-b}{2 \cdot a} - \frac{\sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\]

Reproduce

herbie shell --seed 2018362 +o rules:numerics
(FPCore (a b c)
  :name "quadm (p42, negative)"

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

start211.0ms

Algorithm
intervals

setup139.0ms

Pruning

2 alts after pruning (2 fresh and 0 done)

Merged error: 30.7b

localize55.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))

rewrite60.0ms

Algorithm
rewrite-expression-head
Counts
4 → 108
Calls

4 calls. Slowest were:

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

series201.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

69.0ms
(sqrt (- (* b b) (* 4 (* a c))))
60.0ms
(/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a))
44.0ms
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
28.0ms
(- (* b b) (* 4 (* a c)))

simplify6.5s

Counts
98 → 120
Calls

98 calls. Slowest were:

457.0ms
(sqrt (- (pow (* b b) 3) (pow (* 4 (* a c)) 3)))
411.0ms
(- (* (- b) (- b)) (* (sqrt (- (* b b) (* 4 (* a c)))) (sqrt (- (* b b) (* 4 (* a c))))))
382.0ms
(- (pow (- b) 3) (pow (sqrt (- (* b b) (* 4 (* a c)))) 3))

prune1.7s

Pruning

9 alts after pruning (9 fresh and 0 done)

Merged error: 4.1b

localize28.0ms

Local error

Found 4 expressions with local error:

21.0b
(sqrt (- (* b b) (* 4 (* a c))))
13.2b
(/ (* (* c 4) a) (* (* 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)))

rewrite50.0ms

Algorithm
rewrite-expression-head
Counts
4 → 72
Calls

4 calls. Slowest were:

22.0ms
(/ (* (* c 4) a) (* (* 2 a) (+ (- b) (sqrt (- (* b b) (* 4 (* a c)))))))
16.0ms
(+ (- b) (sqrt (- (* b b) (* 4 (* a c)))))
6.0ms
(sqrt (- (* b b) (* 4 (* a c))))

series341.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

192.0ms
(/ (* (* c 4) a) (* (* 2 a) (+ (- b) (sqrt (- (* b b) (* 4 (* a c)))))))
63.0ms
(sqrt (- (* b b) (* 4 (* a c))))
56.0ms
(+ (- b) (sqrt (- (* b b) (* 4 (* a c)))))
29.0ms
(- (* b b) (* 4 (* a c)))

simplify3.8s

Counts
35 → 84
Calls

35 calls. Slowest were:

841.0ms
(/ (* (* (* (* c 4) a) (* (* c 4) a)) (* (* c 4) a)) (* (* (* (* 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))))))))
815.0ms
(/ (* (* (* (* c 4) a) (* (* c 4) a)) (* (* c 4) a)) (* (* (* (* 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))))))))
363.0ms
(sqrt (- (pow (* b b) 3) (pow (* 4 (* a c)) 3)))

prune1.3s

Pruning

8 alts after pruning (7 fresh and 1 done)

Merged error: 4.1b

localize29.0ms

Local error

Found 4 expressions with local error:

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

rewrite22.0ms

Algorithm
rewrite-expression-head
Counts
4 → 60
Calls

4 calls. Slowest were:

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

series155.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

56.0ms
(sqrt (fma -4 (* a c) (* b b)))
49.0ms
(fma -4 (* a c) (* b b))
45.0ms
(- (sqrt (fma -4 (* a c) (* b b))) b)
5.0ms
(/ (* (* c 4) a) (* 2 a))

simplify1.7s

Counts
26 → 72
Calls

26 calls. Slowest were:

755.0ms
(/ (* (* (* (* c 4) a) (* (* c 4) a)) (* (* c 4) a)) (* (* (* 2 a) (* 2 a)) (* 2 a)))
723.0ms
(- (log (* (* c 4) a)) (log (* 2 a)))
41.0ms
(- (pow b 2) (* 4 (* a c)))

prune1.3s

Pruning

8 alts after pruning (6 fresh and 2 done)

Merged error: 4.1b

localize17.0ms

Local error

Found 4 expressions with local error:

21.0b
(sqrt (fma (* a -4) c (* b b)))
0.9b
(- (- b) (sqrt (fma (* a -4) c (* b b))))
0.1b
(/ (- (- b) (sqrt (fma (* a -4) c (* b b)))) (* 2 a))
0.0b
(fma (* a -4) c (* b b))

rewrite31.0ms

Algorithm
rewrite-expression-head
Counts
4 → 100
Calls

4 calls. Slowest were:

18.0ms
(/ (- (- b) (sqrt (fma (* a -4) c (* b b)))) (* 2 a))
9.0ms
(- (- b) (sqrt (fma (* a -4) c (* b b))))
2.0ms
(sqrt (fma (* a -4) c (* b b)))

series223.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

62.0ms
(/ (- (- b) (sqrt (fma (* a -4) c (* b b)))) (* 2 a))
58.0ms
(- (- b) (sqrt (fma (* a -4) c (* b b))))
58.0ms
(sqrt (fma (* a -4) c (* b b)))
45.0ms
(fma (* a -4) c (* b b))

simplify3.8s

Counts
93 → 112
Calls

93 calls. Slowest were:

347.0ms
(- (* (- b) (- b)) (* (sqrt (fma (* a -4) c (* b b))) (sqrt (fma (* a -4) c (* b b)))))
184.0ms
(- (pow (- b) 3) (pow (sqrt (fma (* a -4) c (* b b))) 3))
119.0ms
(/ (* (* (- (- b) (sqrt (fma (* a -4) c (* b b)))) (- (- b) (sqrt (fma (* a -4) c (* b b))))) (- (- b) (sqrt (fma (* a -4) c (* b b))))) (* (* (* 2 a) (* 2 a)) (* 2 a)))

prune1.5s

Pruning

7 alts after pruning (5 fresh and 2 done)

Merged error: 4.1b

regimes380.0ms

Accuracy

86.6% (3.5b remaining)

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

bsearch557.0ms