Average Error: 33.3 → 6.7
Time: 24.5s
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 -1.0041518941750358 \cdot 10^{+133}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \le 3.9279776760338723 \cdot 10^{-290}:\\ \;\;\;\;\frac{2 \cdot c}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} + \left(-b\right)}\\ \mathbf{elif}\;b \le 2.653900512555386 \cdot 10^{+58}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{{b}^{2} - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\ \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

Original33.3
Target20.7
Herbie6.7
\[\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 < -1.0041518941750358e+133

    1. Initial program 60.5

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Taylor expanded around -inf 1.9

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

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

    if -1.0041518941750358e+133 < b < 3.9279776760338723e-290

    1. Initial program 32.8

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied div-inv32.8

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

      \[\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(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}} \cdot \frac{1}{2 \cdot a}\]
    6. Applied associate-*l/33.0

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

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

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

    if 3.9279776760338723e-290 < b < 2.653900512555386e+58

    1. Initial program 8.9

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Taylor expanded around -inf 8.9

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

    if 2.653900512555386e+58 < b

    1. Initial program 37.0

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Taylor expanded around -inf 37.0

      \[\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 4.8

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.0041518941750358 \cdot 10^{+133}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \le 3.9279776760338723 \cdot 10^{-290}:\\ \;\;\;\;\frac{2 \cdot c}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} + \left(-b\right)}\\ \mathbf{elif}\;b \le 2.653900512555386 \cdot 10^{+58}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{{b}^{2} - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\]

Reproduce

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

sample200.0ms

Algorithm
intervals

simplify85.0ms

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

prune7.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 34.1b

localize55.0ms

Local error

Found 4 expressions with local error:

23.4b
(sqrt (- (* b b) (* 4 (* a c))))
0.3b
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
0.2b
(- (* b b) (* 4 (* a c)))
0.1b
(/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a))

rewrite50.0ms

Algorithm
rewrite-expression-head
Rules
20×add-sqr-sqrt
13×*-un-lft-identity
add-log-exp
add-cube-cbrt
difference-of-squares
associate-/l*
sqrt-prod
add-exp-log
add-cbrt-cube
times-frac
flip--
flip3--
pow1
distribute-lft-out--
associate-/l/
diff-log
sqrt-div
sub-neg
div-inv
div-exp
div-sub
pow1/2
frac-2neg
associate-/r*
clear-num
rem-sqrt-square
cbrt-undiv
neg-sub0
associate--l-
Counts
4 → 70
Calls
4 calls:
Slowest
30.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)))
4.0ms
(sqrt (- (* b b) (* 4 (* a c))))

series245.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
81.0ms
(/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a))
67.0ms
(sqrt (- (* b b) (* 4 (* a c))))
63.0ms
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
33.0ms
(- (* b b) (* 4 (* a c)))

simplify2.6s

Counts
46 → 82
Calls
46 calls:
Slowest
319.0ms
(sqrt (- (pow (* b b) 3) (pow (* 4 (* a c)) 3)))
292.0ms
(- (* (- b) (- b)) (* (sqrt (- (* b b) (* 4 (* a c)))) (sqrt (- (* b b) (* 4 (* a c))))))
201.0ms
(- (pow (- b) 3) (pow (sqrt (- (* b b) (* 4 (* a c)))) 3))
174.0ms
(sqrt (- (* (* b b) (* b b)) (* (* 4 (* a c)) (* 4 (* a c)))))
133.0ms
(/ (* (* (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (- (- b) (sqrt (- (* b b) (* 4 (* a c)))))) (- (- b) (sqrt (- (* b b) (* 4 (* a c)))))) (* (* (* 2 a) (* 2 a)) (* 2 a)))

prune944.0ms

Pruning

10 alts after pruning (10 fresh and 0 done)

Merged error: 6.2b

localize23.0ms

Local error

Found 4 expressions with local error:

23.4b
(sqrt (- (pow b 2) (* 4 (* a c))))
0.3b
(- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))
0.2b
(- (pow b 2) (* 4 (* a c)))
0.1b
(/ (- (- b) (sqrt (- (pow b 2) (* 4 (* a c))))) (* 2 a))

rewrite63.0ms

Algorithm
rewrite-expression-head
Rules
20×add-sqr-sqrt
13×*-un-lft-identity
add-log-exp
add-cube-cbrt
difference-of-squares
associate-/l*
sqrt-prod
add-exp-log
add-cbrt-cube
times-frac
flip--
flip3--
pow1
distribute-lft-out--
associate-/l/
diff-log
sqrt-div
sub-neg
div-inv
div-exp
div-sub
pow1/2
frac-2neg
associate-/r*
clear-num
rem-sqrt-square
cbrt-undiv
neg-sub0
associate--l-
Counts
4 → 70
Calls
4 calls:
Slowest
36.0ms
(/ (- (- b) (sqrt (- (pow b 2) (* 4 (* a c))))) (* 2 a))
13.0ms
(- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))
6.0ms
(- (pow b 2) (* 4 (* a c)))
5.0ms
(sqrt (- (pow b 2) (* 4 (* a c))))

series257.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
88.0ms
(/ (- (- b) (sqrt (- (pow b 2) (* 4 (* a c))))) (* 2 a))
71.0ms
(sqrt (- (pow b 2) (* 4 (* a c))))
70.0ms
(- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))
28.0ms
(- (pow b 2) (* 4 (* a c)))

simplify3.2s

Counts
46 → 82
Calls
46 calls:
Slowest
843.0ms
(- (* (- b) (- b)) (* (sqrt (- (pow b 2) (* 4 (* a c)))) (sqrt (- (pow b 2) (* 4 (* a c))))))
401.0ms
(sqrt (- (pow (pow b 2) 3) (pow (* 4 (* a c)) 3)))
180.0ms
(sqrt (- (* (pow b 2) (pow b 2)) (* (* 4 (* a c)) (* 4 (* a c)))))
170.0ms
(- (pow (- b) 3) (pow (sqrt (- (pow b 2) (* 4 (* a c)))) 3))
125.0ms
(- b (* 2 (/ (* a c) b)))

prune953.0ms

Pruning

10 alts after pruning (9 fresh and 1 done)

Merged error: 6.2b

localize7.0ms

Local error

Found 4 expressions with local error:

23.4b
(sqrt (- (* b b) (* 4 (* a c))))
0.3b
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
0.2b
(* (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (/ 1 (* 2 a)))
0.2b
(- (* b b) (* 4 (* a c)))

rewrite33.0ms

Algorithm
rewrite-expression-head
Rules
16×add-sqr-sqrt
11×*-un-lft-identity
add-log-exp
add-exp-log
add-cube-cbrt
associate-*l*
add-cbrt-cube
pow1
flip--
sqrt-prod
flip3--
difference-of-squares
associate-*r*
distribute-lft-out--
prod-exp
associate-*l/
diff-log
sqrt-div
sub-neg
frac-times
div-inv
cbrt-unprod
*-commutative
un-div-inv
associate-*r/
pow-prod-down
pow1/2
rec-exp
rem-sqrt-square
neg-sub0
associate--l-
Counts
4 → 70
Calls
4 calls:
Slowest
19.0ms
(* (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (/ 1 (* 2 a)))
5.0ms
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
5.0ms
(- (* b b) (* 4 (* a c)))
2.0ms
(sqrt (- (* b b) (* 4 (* a c))))

series244.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
90.0ms
(* (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (/ 1 (* 2 a)))
77.0ms
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
48.0ms
(sqrt (- (* b b) (* 4 (* a c))))
27.0ms
(- (* b b) (* 4 (* a c)))

simplify4.7s

Counts
45 → 82
Calls
45 calls:
Slowest
958.0ms
(* (- (pow (- b) 3) (pow (sqrt (- (* b b) (* 4 (* a c)))) 3)) 1)
436.0ms
(* (- (* (- b) (- b)) (* (sqrt (- (* b b) (* 4 (* a c)))) (sqrt (- (* b b) (* 4 (* a c)))))) (/ 1 (* 2 a)))
414.0ms
(* (- (* (- b) (- b)) (* (sqrt (- (* b b) (* 4 (* a c)))) (sqrt (- (* b b) (* 4 (* a c)))))) 1)
414.0ms
(sqrt (- (pow (* b b) 3) (pow (* 4 (* a c)) 3)))
337.0ms
(* (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (/ 1 (* 2 a)))

prune852.0ms

Pruning

8 alts after pruning (6 fresh and 2 done)

Merged error: 6.2b

localize33.0ms

Local error

Found 4 expressions with local error:

23.4b
(sqrt (- (* b b) (* 4 (* a c))))
15.3b
(* (* (* 4 a) c) (/ 1/2 a))
1.7b
(+ (- b) (sqrt (- (* b b) (* 4 (* a c)))))
0.2b
(- (* b b) (* 4 (* a c)))

rewrite27.0ms

Algorithm
rewrite-expression-head
Rules
add-log-exp
*-un-lft-identity
add-sqr-sqrt
add-cube-cbrt
add-exp-log
add-cbrt-cube
pow1
associate-*r*
sqrt-prod
flip--
sqrt-div
flip3--
distribute-lft-out
div-inv
flip-+
cbrt-unprod
associate-+l-
*-commutative
associate-*r/
prod-exp
pow-prod-down
associate-*l*
diff-log
pow1/2
flip3-+
sub-neg
sum-log
rem-sqrt-square
+-commutative
neg-sub0
Counts
4 → 56
Calls
4 calls:
Slowest
15.0ms
(* (* (* 4 a) c) (/ 1/2 a))
5.0ms
(+ (- b) (sqrt (- (* b b) (* 4 (* a c)))))
4.0ms
(sqrt (- (* b b) (* 4 (* a c))))
2.0ms
(- (* b b) (* 4 (* a c)))

series145.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
53.0ms
(+ (- b) (sqrt (- (* b b) (* 4 (* a c)))))
48.0ms
(sqrt (- (* b b) (* 4 (* a c))))
38.0ms
(- (* b b) (* 4 (* a c)))
7.0ms
(* (* (* 4 a) c) (/ 1/2 a))

simplify1.9s

Counts
29 → 68
Calls
29 calls:
Slowest
368.0ms
(+ (log (* (* 4 a) c)) (log (/ 1/2 a)))
366.0ms
(sqrt (- (pow (* b b) 3) (pow (* 4 (* a c)) 3)))
199.0ms
(* (* (* 4 a) c) (/ 1/2 a))
189.0ms
(sqrt (- (* (* b b) (* b b)) (* (* 4 (* a c)) (* 4 (* a c)))))
125.0ms
(- b (* 2 (/ (* a c) b)))

prune773.0ms

Pruning

9 alts after pruning (7 fresh and 2 done)

Merged error: 6.2b

regimes367.0ms

Accuracy

95.1% (1.2b remaining)

Error of 6.7b against oracle of 5.5b and baseline of 29.6b

bsearch571.0ms

end0.0ms

sample4.7s

Algorithm
intervals