Average Error: 33.5 → 7.5
Time: 21.0s
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 -2.8918891030401806 \cdot 10^{+33}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le -1.882722696756613 \cdot 10^{-300}:\\ \;\;\;\;\frac{c}{2} \cdot \frac{4}{\sqrt{(\left(-4 \cdot a\right) \cdot c + \left(b \cdot b\right))_*} - b}\\ \mathbf{elif}\;b \le 1.501809486178084 \cdot 10^{+23}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{(\left(-4 \cdot a\right) \cdot c + \left(b \cdot b\right))_*}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;-\frac{b}{a}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.5
Target20.3
Herbie7.5
\[\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 < -2.8918891030401806e+33

    1. Initial program 56.3

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

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

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

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

    if -2.8918891030401806e+33 < b < -1.882722696756613e-300

    1. Initial program 29.1

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

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

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

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

      \[\leadsto \frac{\color{blue}{\left(c \cdot a\right) \cdot 4}}{\left(2 \cdot a\right) \cdot \left(\left(-b\right) + \sqrt{(\left(-4 \cdot a\right) \cdot c + \left(b \cdot b\right))_*}\right)}\]
    7. Using strategy rm
    8. Applied times-frac17.3

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

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

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

    if -1.882722696756613e-300 < b < 1.501809486178084e+23

    1. Initial program 9.9

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

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

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

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

    if 1.501809486178084e+23 < b

    1. Initial program 32.7

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

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

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

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

      \[\leadsto \frac{\color{blue}{\left(c \cdot a\right) \cdot 4}}{\left(2 \cdot a\right) \cdot \left(\left(-b\right) + \sqrt{(\left(-4 \cdot a\right) \cdot c + \left(b \cdot b\right))_*}\right)}\]
    7. Using strategy rm
    8. Applied times-frac59.3

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}}\]
    12. Simplified6.3

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -2.8918891030401806 \cdot 10^{+33}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le -1.882722696756613 \cdot 10^{-300}:\\ \;\;\;\;\frac{c}{2} \cdot \frac{4}{\sqrt{(\left(-4 \cdot a\right) \cdot c + \left(b \cdot b\right))_*} - b}\\ \mathbf{elif}\;b \le 1.501809486178084 \cdot 10^{+23}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{(\left(-4 \cdot a\right) \cdot c + \left(b \cdot b\right))_*}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;-\frac{b}{a}\\ \end{array}\]

Reproduce

herbie shell --seed 2019022 +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: 20.3s)Debug log

sample114.0ms

Algorithm
intervals
Results
29.0ms188×body80valid
24.0ms32×body2560valid
14.0ms24×body1280valid
12.0ms96×body80nan
9.0ms17×body640valid
5.0msbody5120valid
4.0msbody320valid
1.0msbody160valid

simplify139.0ms

Counts
1 → 1
Calls
1 calls:
Slowest
139.0ms
(/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a))

prune20.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 33.7b

localize50.0ms

Local error

Found 4 expressions with local error:

22.4b
(sqrt (fma (* -4 a) c (* b b)))
1.1b
(- (- b) (sqrt (fma (* -4 a) c (* b b))))
0.1b
(/ (- (- b) (sqrt (fma (* -4 a) c (* b b)))) (* 2 a))
0.0b
(fma (* -4 a) c (* b b))

rewrite24.0ms

Algorithm
rewrite-expression-head
Rules
35×add-sqr-sqrt
28×*-un-lft-identity
24×prod-diff
22×add-cube-cbrt
18×sqrt-prod
neg-mul-1
difference-of-squares
add-log-exp
associate-/l*
add-exp-log
add-cbrt-cube
times-frac
log1p-expm1-u
fma-neg
pow1
expm1-log1p-u
distribute-lft-out--
associate-/l/
flip--
flip3--
div-inv
fma-udef
div-exp
div-sub
diff-log
pow1/2
frac-2neg
sub-neg
associate-/r*
clear-num
rem-sqrt-square
cbrt-undiv
neg-sub0
associate--l-
Counts
4 → 100
Calls
4 calls:
Slowest
12.0ms
(/ (- (- b) (sqrt (fma (* -4 a) c (* b b)))) (* 2 a))
9.0ms
(- (- b) (sqrt (fma (* -4 a) c (* b b))))
2.0ms
(sqrt (fma (* -4 a) c (* b b)))
0.0ms
(fma (* -4 a) c (* b b))

series208.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
72.0ms
(/ (- (- b) (sqrt (fma (* -4 a) c (* b b)))) (* 2 a))
55.0ms
(- (- b) (sqrt (fma (* -4 a) c (* b b))))
52.0ms
(sqrt (fma (* -4 a) c (* b b)))
29.0ms
(fma (* -4 a) c (* b b))

simplify3.2s

Counts
93 → 112
Calls
93 calls:
Slowest
258.0ms
(- (* (- b) (- b)) (* (sqrt (fma (* -4 a) c (* b b))) (sqrt (fma (* -4 a) c (* b b)))))
175.0ms
(- (pow (- b) 3) (pow (sqrt (fma (* -4 a) c (* b b))) 3))
77.0ms
(/ (* (* (- (- b) (sqrt (fma (* -4 a) c (* b b)))) (- (- b) (sqrt (fma (* -4 a) c (* b b))))) (- (- b) (sqrt (fma (* -4 a) c (* b b))))) (* (* (* 2 a) (* 2 a)) (* 2 a)))
73.0ms
(fma 1 (- b) (- (* (sqrt (cbrt (fma (* -4 a) c (* b b)))) (sqrt (* (cbrt (fma (* -4 a) c (* b b))) (cbrt (fma (* -4 a) c (* b b))))))))
67.0ms
(fma 1 (- b) (- (* (sqrt (fma (* -4 a) c (* b b))) 1)))

prune1.2s

Pruning

9 alts after pruning (9 fresh and 0 done)

Merged error: 5.5b

localize13.0ms

Local error

Found 4 expressions with local error:

22.4b
(sqrt (fma (* -4 a) c (* b b)))
14.0b
(/ (* (* c a) 4) (* (* 2 a) (+ (- b) (sqrt (fma (* -4 a) c (* b b))))))
2.0b
(+ (- b) (sqrt (fma (* -4 a) c (* b b))))
0.1b
(* (* 2 a) (+ (- b) (sqrt (fma (* -4 a) c (* b b)))))

rewrite44.0ms

Algorithm
rewrite-expression-head
Rules
11×add-exp-log
11×add-cbrt-cube
11×*-un-lft-identity
add-sqr-sqrt
add-cube-cbrt
add-log-exp
pow1
log1p-expm1-u
associate-*r/
associate-*r*
fma-def
expm1-log1p-u
flip-+
sqrt-prod
flip3-+
distribute-lft-out
cbrt-unprod
associate-/r/
prod-exp
div-exp
cbrt-undiv
associate-/l*
div-inv
associate-+l-
*-commutative
pow-prod-down
associate-*l*
pow1/2
times-frac
distribute-lft-in
frac-2neg
sum-log
neg-mul-1
associate-/r*
clear-num
rem-sqrt-square
+-commutative
distribute-rgt-in
neg-sub0
Counts
4 → 76
Calls
4 calls:
Slowest
18.0ms
(/ (* (* c a) 4) (* (* 2 a) (+ (- b) (sqrt (fma (* -4 a) c (* b b))))))
15.0ms
(* (* 2 a) (+ (- b) (sqrt (fma (* -4 a) c (* b b)))))
8.0ms
(+ (- b) (sqrt (fma (* -4 a) c (* b b))))
2.0ms
(sqrt (fma (* -4 a) c (* b b)))

series358.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
160.0ms
(/ (* (* c a) 4) (* (* 2 a) (+ (- b) (sqrt (fma (* -4 a) c (* b b))))))
73.0ms
(sqrt (fma (* -4 a) c (* b b)))
67.0ms
(* (* 2 a) (+ (- b) (sqrt (fma (* -4 a) c (* b b)))))
58.0ms
(+ (- b) (sqrt (fma (* -4 a) c (* b b))))

simplify4.4s

Counts
41 → 88
Calls
41 calls:
Slowest
828.0ms
(/ (* (* (* (* c a) 4) (* (* c a) 4)) (* (* c a) 4)) (* (* (* (* 2 a) (* 2 a)) (* 2 a)) (* (* (+ (- b) (sqrt (fma (* -4 a) c (* b b)))) (+ (- b) (sqrt (fma (* -4 a) c (* b b))))) (+ (- b) (sqrt (fma (* -4 a) c (* b b)))))))
715.0ms
(- (log (* (* c a) 4)) (+ (log (* 2 a)) (log (+ (- b) (sqrt (fma (* -4 a) c (* b b)))))))
671.0ms
(/ (* (* (* (* c a) 4) (* (* c a) 4)) (* (* c a) 4)) (* (* (* (* 2 a) (+ (- b) (sqrt (fma (* -4 a) c (* b b))))) (* (* 2 a) (+ (- b) (sqrt (fma (* -4 a) c (* b b)))))) (* (* 2 a) (+ (- b) (sqrt (fma (* -4 a) c (* b b)))))))
503.0ms
(+ (* (- b) (- b)) (- (* (sqrt (fma (* -4 a) c (* b b))) (sqrt (fma (* -4 a) c (* b b)))) (* (- b) (sqrt (fma (* -4 a) c (* b b))))))
425.0ms
(- (log (* (* c a) 4)) (log (* (* 2 a) (+ (- b) (sqrt (fma (* -4 a) c (* b b)))))))

prune1.1s

Pruning

7 alts after pruning (7 fresh and 0 done)

Merged error: 5.5b

localize15.0ms

Local error

Found 4 expressions with local error:

22.4b
(sqrt (fma (* -4 a) c (* b b)))
2.0b
(- (sqrt (fma (* -4 a) c (* b b))) b)
0.2b
(* (/ c 2) (/ 4 (- (sqrt (fma (* -4 a) c (* b b))) b)))
0.1b
(/ 4 (- (sqrt (fma (* -4 a) c (* b b))) b))

rewrite20.0ms

Algorithm
rewrite-expression-head
Rules
11×add-sqr-sqrt
10×add-cube-cbrt
10×*-un-lft-identity
sqrt-prod
add-exp-log
associate-*r*
fma-neg
add-cbrt-cube
pow1
add-log-exp
log1p-expm1-u
associate-/r/
associate-*l*
expm1-log1p-u
flip--
div-inv
flip3--
associate-/r*
cbrt-unprod
*-commutative
associate-*r/
prod-exp
associate-*l/
pow-prod-down
pow1/2
frac-2neg
sub-neg
clear-num
rem-sqrt-square
frac-times
Counts
4 → 76
Calls
4 calls:
Slowest
10.0ms
(* (/ c 2) (/ 4 (- (sqrt (fma (* -4 a) c (* b b))) b)))
5.0ms
(- (sqrt (fma (* -4 a) c (* b b))) b)
4.0ms
(/ 4 (- (sqrt (fma (* -4 a) c (* b b))) b))
1.0ms
(sqrt (fma (* -4 a) c (* b b)))

series359.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
143.0ms
(* (/ c 2) (/ 4 (- (sqrt (fma (* -4 a) c (* b b))) b)))
114.0ms
(/ 4 (- (sqrt (fma (* -4 a) c (* b b))) b))
56.0ms
(- (sqrt (fma (* -4 a) c (* b b))) b)
46.0ms
(sqrt (fma (* -4 a) c (* b b)))

simplify1.1s

Counts
41 → 88
Calls
41 calls:
Slowest
319.0ms
(* (* (* (/ c 2) (/ c 2)) (/ c 2)) (* (* (/ 4 (- (sqrt (fma (* -4 a) c (* b b))) b)) (/ 4 (- (sqrt (fma (* -4 a) c (* b b))) b))) (/ 4 (- (sqrt (fma (* -4 a) c (* b b))) b))))
142.0ms
(+ (log (/ c 2)) (log (/ 4 (- (sqrt (fma (* -4 a) c (* b b))) b))))
79.0ms
(* (/ c 2) (/ 4 (- (sqrt (fma (* -4 a) c (* b b))) b)))
78.0ms
(+ (* (sqrt (fma (* -4 a) c (* b b))) (sqrt (fma (* -4 a) c (* b b)))) (+ (* b b) (* (sqrt (fma (* -4 a) c (* b b))) b)))
66.0ms
(+ (* (sqrt (fma (* -4 a) c (* b b))) (sqrt (fma (* -4 a) c (* b b)))) (+ (* b b) (* (sqrt (fma (* -4 a) c (* b b))) b)))

prune841.0ms

Pruning

7 alts after pruning (6 fresh and 1 done)

Merged error: 5.5b

localize27.0ms

Local error

Found 4 expressions with local error:

22.4b
(sqrt (fma -4 (* a c) (* b b)))
13.0b
(/ (* (* c a) 4) (* 2 a))
2.0b
(- (sqrt (fma -4 (* a c) (* b b))) b)
0.4b
(fma -4 (* a c) (* b b))

rewrite14.0ms

Algorithm
rewrite-expression-head
Rules
add-sqr-sqrt
add-cube-cbrt
*-un-lft-identity
sqrt-prod
add-exp-log
fma-neg
add-cbrt-cube
add-log-exp
log1p-expm1-u
pow1
expm1-log1p-u
associate-/l*
flip--
div-inv
fma-udef
div-exp
pow1/2
flip3--
times-frac
frac-2neg
sub-neg
associate-/r*
clear-num
rem-sqrt-square
cbrt-undiv
Counts
4 → 60
Calls
4 calls:
Slowest
7.0ms
(/ (* (* c a) 4) (* 2 a))
5.0ms
(- (sqrt (fma -4 (* a c) (* b b))) b)
1.0ms
(sqrt (fma -4 (* a c) (* b b)))
0.0ms
(fma -4 (* a c) (* b b))

series149.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
60.0ms
(- (sqrt (fma -4 (* a c) (* b b))) b)
48.0ms
(sqrt (fma -4 (* a c) (* b b)))
35.0ms
(fma -4 (* a c) (* b b))
6.0ms
(/ (* (* c a) 4) (* 2 a))

simplify766.0ms

Counts
26 → 72
Calls
26 calls:
Slowest
330.0ms
(- (log (* (* c a) 4)) (log (* 2 a)))
242.0ms
(/ (* (* (* (* c a) 4) (* (* c a) 4)) (* (* c a) 4)) (* (* (* 2 a) (* 2 a)) (* 2 a)))
39.0ms
(- (pow b 2) (* 4 (* a c)))
28.0ms
(- (pow b 2) (* 4 (* a c)))
26.0ms
(- (pow b 2) (* 4 (* a c)))

prune844.0ms

Pruning

7 alts after pruning (5 fresh and 2 done)

Merged error: 5.5b

regimes372.0ms

Accuracy

91.6% (2.0b remaining)

Error of 7.5b against oracle of 5.5b and baseline of 29.3b

bsearch353.0ms

end0.0ms

sample4.6s

Algorithm
intervals
Results
1.4s1063×body2560valid
1.3s5849×body80valid
761.0ms937×body1280valid
409.0ms2975×body80nan
225.0ms444×body640valid
134.0ms123×body5120valid
116.0ms203×body320valid
29.0ms111×body160valid