Average Error: 33.3 → 10.1
Time: 20.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 -3.4363098102745 \cdot 10^{-82}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \le 5.825682153804059 \cdot 10^{+126}:\\ \;\;\;\;\frac{-b}{2 \cdot a} - \frac{1}{2 \cdot a} \cdot \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\\ \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.6
Herbie10.1
\[\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 3 regimes
  2. if b < -3.4363098102745e-82

    1. Initial program 51.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 *-commutative51.8

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
    5. Simplified9.8

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

    if -3.4363098102745e-82 < b < 5.825682153804059e+126

    1. Initial program 12.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 *-commutative12.3

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

      \[\leadsto \color{blue}{\frac{-b}{2 \cdot a} - \frac{\sqrt{b \cdot b - \left(a \cdot c\right) \cdot 4}}{2 \cdot a}}\]
    6. Using strategy rm
    7. Applied div-inv12.4

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

    if 5.825682153804059e+126 < b

    1. Initial program 51.6

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -3.4363098102745 \cdot 10^{-82}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \le 5.825682153804059 \cdot 10^{+126}:\\ \;\;\;\;\frac{-b}{2 \cdot a} - \frac{1}{2 \cdot a} \cdot \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\]

Reproduce

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

sample93.0ms

Algorithm
intervals
Results
27.0ms31×body2560valid
17.0ms188×body80valid
12.0ms27×body1280valid
9.0ms103×body80nan
6.0ms17×body640valid
2.0msbody320valid
1.0msbody5120valid
1.0msbody160valid

simplify91.0ms

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

prune13.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 32.3b

localize49.0ms

Local error

Found 4 expressions with local error:

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

rewrite58.0ms

Algorithm
rewrite-expression-head
Rules
20×add-sqr-sqrt
13×*-un-lft-identity
add-cube-cbrt
difference-of-squares
add-log-exp
associate-/l*
sqrt-prod
add-exp-log
add-cbrt-cube
times-frac
pow1
distribute-lft-out--
flip--
flip3--
associate-/l/
sqrt-div
div-inv
*-commutative
associate-*r*
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 → 67
Calls
4 calls:
Slowest
30.0ms
(/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a))
20.0ms
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
4.0ms
(sqrt (- (* b b) (* 4 (* a c))))
2.0ms
(* 4 (* a c))

series227.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
87.0ms
(/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a))
64.0ms
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
57.0ms
(sqrt (- (* b b) (* 4 (* a c))))
19.0ms
(* 4 (* a c))

simplify2.5s

Counts
45 → 79
Calls
45 calls:
Slowest
364.0ms
(sqrt (- (pow (* b b) 3) (pow (* 4 (* a c)) 3)))
249.0ms
(- (* (- b) (- b)) (* (sqrt (- (* b b) (* 4 (* a c)))) (sqrt (- (* b b) (* 4 (* a c))))))
236.0ms
(- (pow (- b) 3) (pow (sqrt (- (* b b) (* 4 (* a c)))) 3))
188.0ms
(sqrt (- (* (* b b) (* b b)) (* (* 4 (* a c)) (* 4 (* a c)))))
90.0ms
(- b (* 2 (/ (* a c) b)))

prune966.0ms

Pruning

11 alts after pruning (11 fresh and 0 done)

Merged error: 5.9b

localize29.0ms

Local error

Found 4 expressions with local error:

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

rewrite39.0ms

Algorithm
rewrite-expression-head
Rules
20×add-sqr-sqrt
13×*-un-lft-identity
add-cube-cbrt
difference-of-squares
add-log-exp
associate-/l*
sqrt-prod
add-exp-log
add-cbrt-cube
times-frac
pow1
distribute-lft-out--
flip--
flip3--
associate-/l/
sqrt-div
div-inv
*-commutative
associate-*l*
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 → 67
Calls
4 calls:
Slowest
21.0ms
(/ (- (- b) (sqrt (- (* b b) (* (* a c) 4)))) (* 2 a))
11.0ms
(- (- b) (sqrt (- (* b b) (* (* a c) 4))))
4.0ms
(sqrt (- (* b b) (* (* a c) 4)))
2.0ms
(* (* a c) 4)

series184.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
60.0ms
(- (- b) (sqrt (- (* b b) (* (* a c) 4))))
56.0ms
(sqrt (- (* b b) (* (* a c) 4)))
56.0ms
(/ (- (- b) (sqrt (- (* b b) (* (* a c) 4)))) (* 2 a))
12.0ms
(* (* a c) 4)

simplify2.5s

Counts
45 → 79
Calls
45 calls:
Slowest
359.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* a c) 4) 3)))
302.0ms
(- (pow (- b) 3) (pow (sqrt (- (* b b) (* (* a c) 4))) 3))
248.0ms
(- (* (- b) (- b)) (* (sqrt (- (* b b) (* (* a c) 4))) (sqrt (- (* b b) (* (* a c) 4)))))
169.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* a c) 4) (* (* a c) 4))))
86.0ms
(- b (* 2 (/ (* a c) b)))

prune780.0ms

Pruning

9 alts after pruning (9 fresh and 0 done)

Merged error: 5.9b

localize10.0ms

Local error

Found 4 expressions with local error:

19.5b
(sqrt (- (* b b) (* (* a c) 4)))
6.5b
(- (/ (- b) (* 2 a)) (/ (sqrt (- (* b b) (* (* a c) 4))) (* 2 a)))
0.1b
(/ (sqrt (- (* b b) (* (* a c) 4))) (* 2 a))
0.0b
(* (* a c) 4)

rewrite25.0ms

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

series220.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
81.0ms
(/ (sqrt (- (* b b) (* (* a c) 4))) (* 2 a))
79.0ms
(- (/ (- b) (* 2 a)) (/ (sqrt (- (* b b) (* (* a c) 4))) (* 2 a)))
43.0ms
(sqrt (- (* b b) (* (* a c) 4)))
17.0ms
(* (* a c) 4)

simplify2.3s

Counts
52 → 81
Calls
52 calls:
Slowest
332.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* a c) 4) 3)))
320.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* a c) 4) 3)))
154.0ms
(- (* (- b) (* 2 a)) (* (* 2 a) (sqrt (- (* b b) (* (* a c) 4)))))
116.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* a c) 4) (* (* a c) 4))))
111.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* a c) 4) (* (* a c) 4))))

prune1.0s

Pruning

10 alts after pruning (10 fresh and 0 done)

Merged error: 5.9b

localize19.0ms

Local error

Found 4 expressions with local error:

19.5b
(sqrt (- (* b b) (* (* (cbrt (* (* a c) 4)) (cbrt (* (* a c) 4))) (cbrt (* (* a c) 4)))))
14.0b
(cbrt (* (* a c) 4))
14.0b
(cbrt (* (* a c) 4))
14.0b
(cbrt (* (* a c) 4))

rewrite13.0ms

Algorithm
rewrite-expression-head
Rules
add-sqr-sqrt
add-cube-cbrt
*-un-lft-identity
add-log-exp
add-exp-log
add-cbrt-cube
pow1
sqrt-prod
pow1/3
cbrt-prod
sqrt-div
flip--
pow1/2
flip3--
rem-sqrt-square
Counts
4 → 41
Calls
4 calls:
Slowest
2.0ms
(cbrt (* (* a c) 4))
2.0ms
(cbrt (* (* a c) 4))
2.0ms
(cbrt (* (* a c) 4))
2.0ms
(sqrt (- (* b b) (* (* (cbrt (* (* a c) 4)) (cbrt (* (* a c) 4))) (cbrt (* (* a c) 4)))))

series485.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
137.0ms
(cbrt (* (* a c) 4))
131.0ms
(cbrt (* (* a c) 4))
117.0ms
(cbrt (* (* a c) 4))
100.0ms
(sqrt (- (* b b) (* (* (cbrt (* (* a c) 4)) (cbrt (* (* a c) 4))) (cbrt (* (* a c) 4)))))

simplify1.8s

Counts
21 → 53
Calls
21 calls:
Slowest
357.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* (cbrt (* (* a c) 4)) (cbrt (* (* a c) 4))) (cbrt (* (* a c) 4))) 3)))
211.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* (cbrt (* (* a c) 4)) (cbrt (* (* a c) 4))) (cbrt (* (* a c) 4))) (* (* (cbrt (* (* a c) 4)) (cbrt (* (* a c) 4))) (cbrt (* (* a c) 4))))))
180.0ms
(* (exp (* -1/3 (+ (log (/ 1 a)) (log (/ 1 c))))) (cbrt 4))
141.0ms
(* (exp (* -1/3 (+ (log (/ -1 c)) (log (/ -1 a))))) (cbrt 4))
138.0ms
(* (exp (* -1/3 (+ (log (/ -1 c)) (log (/ -1 a))))) (cbrt 4))

prune832.0ms

Pruning

9 alts after pruning (9 fresh and 0 done)

Merged error: 5.9b

regimes305.0ms

Accuracy

84% (4.5b remaining)

Error of 10.1b against oracle of 5.6b and baseline of 33.7b

bsearch588.0ms

end0.0ms

sample4.4s

Algorithm
intervals
Results
1.4s5895×body80valid
1.2s1083×body2560valid
674.0ms862×body1280valid
422.0ms2784×body80nan
308.0ms465×body640valid
117.0ms110×body5120valid
114.0ms202×body320valid
30.0ms112×body160valid