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

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

Reproduce

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

start222.0ms

Algorithm
intervals

setup437.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 30.7b

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

rewrite56.0ms

Algorithm
rewrite-expression-head
Counts
4 → 70
Calls

4 calls. Slowest were:

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

series242.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

71.0ms
(/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a))
71.0ms
(sqrt (- (* b b) (* 4 (* a c))))
63.0ms
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
36.0ms
(- (* b b) (* 4 (* a c)))

simplify2.7s

Counts
46 → 82
Calls

46 calls. Slowest were:

295.0ms
(sqrt (- (pow (* b b) 3) (pow (* 4 (* a c)) 3)))
286.0ms
(- (* (- b) (- b)) (* (sqrt (- (* b b) (* 4 (* a c)))) (sqrt (- (* b b) (* 4 (* a c))))))
283.0ms
(- (pow (- b) 3) (pow (sqrt (- (* b b) (* 4 (* a c)))) 3))

prune1.2s

Pruning

7 alts after pruning (7 fresh and 0 done)

Merged error: 4.1b

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

rewrite21.0ms

Algorithm
rewrite-expression-head
Counts
4 → 58
Calls

4 calls. Slowest were:

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

series343.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

177.0ms
(/ (* (* c 4) a) (* (* 2 a) (+ (- b) (sqrt (- (* b b) (* 4 (* a c)))))))
71.0ms
(+ (- b) (sqrt (- (* b b) (* 4 (* a c)))))
52.0ms
(sqrt (- (* b b) (* 4 (* a c))))
43.0ms
(- (* b b) (* 4 (* a c)))

simplify3.8s

Counts
31 → 70
Calls

31 calls. Slowest were:

893.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))))))))
847.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))))))))
347.0ms
(sqrt (- (pow (* b b) 3) (pow (* 4 (* a c)) 3)))

prune1.0s

Pruning

8 alts after pruning (7 fresh and 1 done)

Merged error: 4.1b

localize15.0ms

Local error

Found 4 expressions with local error:

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

rewrite20.0ms

Algorithm
rewrite-expression-head
Counts
4 → 51
Calls

4 calls. Slowest were:

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

series177.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

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

simplify1.9s

Counts
24 → 63
Calls

24 calls. Slowest were:

654.0ms
(- (log (* (* c 4) a)) (log (* 2 a)))
647.0ms
(/ (* (* (* (* c 4) a) (* (* c 4) a)) (* (* c 4) a)) (* (* (* 2 a) (* 2 a)) (* 2 a)))
240.0ms
(sqrt (+ (pow (* -4 (* a c)) 3) (pow (* b b) 3)))

prune702.0ms

Pruning

8 alts after pruning (6 fresh and 2 done)

Merged error: 4.1b

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

rewrite35.0ms

Algorithm
rewrite-expression-head
Counts
4 → 70
Calls

4 calls. Slowest were:

17.0ms
(/ (- (- b) (sqrt (- (pow b 2) (* 4 (* a c))))) (* 2 a))
6.0ms
(- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))
4.0ms
(sqrt (- (pow b 2) (* 4 (* a c))))

series184.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

58.0ms
(/ (- (- b) (sqrt (- (pow b 2) (* 4 (* a c))))) (* 2 a))
52.0ms
(- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))
47.0ms
(sqrt (- (pow b 2) (* 4 (* a c))))
27.0ms
(- (pow b 2) (* 4 (* a c)))

simplify3.3s

Counts
46 → 82
Calls

46 calls. Slowest were:

1.0s
(- (* (- b) (- b)) (* (sqrt (- (pow b 2) (* 4 (* a c)))) (sqrt (- (pow b 2) (* 4 (* a c))))))
359.0ms
(sqrt (- (pow (pow b 2) 3) (pow (* 4 (* a c)) 3)))
249.0ms
(- (pow (- b) 3) (pow (sqrt (- (pow b 2) (* 4 (* a c)))) 3))

prune1.1s

Pruning

7 alts after pruning (5 fresh and 2 done)

Merged error: 4.1b

regimes369.0ms

Accuracy

86.6% (3.5b remaining)

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

bsearch487.0ms