Average Error: 33.2 → 6.7
Time: 22.9s
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.1146996886759634 \cdot 10^{+123}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le -5.4415579011733295 \cdot 10^{-244}:\\ \;\;\;\;\frac{\sqrt{{b}^{2} - \left(c \cdot a\right) \cdot 4} - b}{a \cdot 2}\\ \mathbf{elif}\;b \le 2.653900512555386 \cdot 10^{+58}:\\ \;\;\;\;\frac{c \cdot -2}{b + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \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.2
Target20.6
Herbie6.7
\[\begin{array}{l} \mathbf{if}\;b \lt 0:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{a \cdot \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.1146996886759634e+123

    1. Initial program 49.1

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

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

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

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

    if -4.1146996886759634e+123 < b < -5.4415579011733295e-244

    1. Initial program 8.3

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

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

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

    if -5.4415579011733295e-244 < b < 2.653900512555386e+58

    1. Initial program 27.6

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Simplified27.6

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

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

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

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

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

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

    if 2.653900512555386e+58 < b

    1. Initial program 56.4

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

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

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

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

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

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

Reproduce

herbie shell --seed 2019010 
(FPCore (a b c)
  :name "quadp (p42, positive)"

  :herbie-target
  (if (< b 0) (/ (+ (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)) (/ c (* a (/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))))

  (/ (+ (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))

Details

Time bar (total: 22.1s)Debug log

sample139.0ms

Algorithm
intervals

simplify74.0ms

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

prune10.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 32.9b

localize32.0ms

Local error

Found 4 expressions with local error:

22.0b
(sqrt (- (* b b) (* (* 4 a) c)))
1.7b
(- (sqrt (- (* b b) (* (* 4 a) c))) b)
0.2b
(- (* b b) (* (* 4 a) c))
0.1b
(/ (- (sqrt (- (* b b) (* (* 4 a) c))) b) (* 2 a))

rewrite43.0ms

Algorithm
rewrite-expression-head
Rules
add-sqr-sqrt
add-cube-cbrt
*-un-lft-identity
add-log-exp
add-exp-log
add-cbrt-cube
flip--
flip3--
pow1
associate-/l*
sqrt-prod
times-frac
associate-/l/
sqrt-div
sub-neg
div-inv
div-exp
div-sub
diff-log
pow1/2
frac-2neg
associate-/r*
clear-num
rem-sqrt-square
cbrt-undiv
Counts
4 → 59
Calls
4 calls:
Slowest
24.0ms
(/ (- (sqrt (- (* b b) (* (* 4 a) c))) b) (* 2 a))
13.0ms
(- (sqrt (- (* b b) (* (* 4 a) c))) b)
4.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
2.0ms
(- (* b b) (* (* 4 a) c))

series240.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
83.0ms
(/ (- (sqrt (- (* b b) (* (* 4 a) c))) b) (* 2 a))
59.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
52.0ms
(- (sqrt (- (* b b) (* (* 4 a) c))) b)
45.0ms
(- (* b b) (* (* 4 a) c))

simplify2.1s

Counts
32 → 71
Calls
32 calls:
Slowest
352.0ms
(- (* (sqrt (- (* b b) (* (* 4 a) c))) (sqrt (- (* b b) (* (* 4 a) c)))) (* b b))
340.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
192.0ms
(- (pow (sqrt (- (* b b) (* (* 4 a) c))) 3) (pow b 3))
110.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* 4 a) c) (* (* 4 a) c))))
100.0ms
(- (log (- (sqrt (- (* b b) (* (* 4 a) c))) b)) (log (* 2 a)))

prune746.0ms

Pruning

7 alts after pruning (7 fresh and 0 done)

Merged error: 6.3b

localize32.0ms

Local error

Found 4 expressions with local error:

22.0b
(sqrt (- (pow b 2) (* 4 (* a c))))
1.7b
(- (sqrt (- (pow b 2) (* 4 (* a c)))) b)
0.2b
(- (pow b 2) (* 4 (* a c)))
0.1b
(/ (- (sqrt (- (pow b 2) (* 4 (* a c)))) b) (* 2 a))

rewrite72.0ms

Algorithm
rewrite-expression-head
Rules
add-sqr-sqrt
add-cube-cbrt
*-un-lft-identity
add-log-exp
add-exp-log
add-cbrt-cube
flip--
flip3--
pow1
associate-/l*
sqrt-prod
times-frac
associate-/l/
sqrt-div
sub-neg
div-inv
div-exp
div-sub
diff-log
pow1/2
frac-2neg
associate-/r*
clear-num
rem-sqrt-square
cbrt-undiv
Counts
4 → 59
Calls
4 calls:
Slowest
50.0ms
(/ (- (sqrt (- (pow b 2) (* 4 (* a c)))) b) (* 2 a))
15.0ms
(- (sqrt (- (pow b 2) (* 4 (* a c)))) b)
3.0ms
(- (pow b 2) (* 4 (* a c)))
3.0ms
(sqrt (- (pow b 2) (* 4 (* a c))))

series190.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
58.0ms
(/ (- (sqrt (- (pow b 2) (* 4 (* a c)))) b) (* 2 a))
53.0ms
(- (sqrt (- (pow b 2) (* 4 (* a c)))) b)
47.0ms
(sqrt (- (pow b 2) (* 4 (* a c))))
32.0ms
(- (pow b 2) (* 4 (* a c)))

simplify2.3s

Counts
32 → 71
Calls
32 calls:
Slowest
440.0ms
(- (* (sqrt (- (pow b 2) (* 4 (* a c)))) (sqrt (- (pow b 2) (* 4 (* a c))))) (* b b))
304.0ms
(sqrt (- (pow (pow b 2) 3) (pow (* 4 (* a c)) 3)))
230.0ms
(sqrt (- (* (pow b 2) (pow b 2)) (* (* 4 (* a c)) (* 4 (* a c)))))
227.0ms
(- (pow (sqrt (- (pow b 2) (* 4 (* a c)))) 3) (pow b 3))
129.0ms
(/ (* (* (- (sqrt (- (pow b 2) (* 4 (* a c)))) b) (- (sqrt (- (pow b 2) (* 4 (* a c)))) b)) (- (sqrt (- (pow b 2) (* 4 (* a c)))) b)) (* (* (* 2 a) (* 2 a)) (* 2 a)))

prune703.0ms

Pruning

6 alts after pruning (5 fresh and 1 done)

Merged error: 6.3b

localize11.0ms

Local error

Found 4 expressions with local error:

22.0b
(sqrt (- (* b b) (* (* 4 a) c)))
1.7b
(- (sqrt (- (* b b) (* (* 4 a) c))) b)
0.2b
(* (- (sqrt (- (* b b) (* (* 4 a) c))) b) (/ 1 (* 2 a)))
0.2b
(- (* b b) (* (* 4 a) c))

rewrite52.0ms

Algorithm
rewrite-expression-head
Rules
add-exp-log
add-sqr-sqrt
add-cube-cbrt
*-un-lft-identity
add-log-exp
add-cbrt-cube
pow1
flip--
flip3--
associate-*r*
sqrt-prod
associate-*l*
prod-exp
associate-*l/
sqrt-div
sub-neg
frac-times
div-inv
cbrt-unprod
*-commutative
un-div-inv
associate-*r/
pow-prod-down
diff-log
pow1/2
rec-exp
rem-sqrt-square
Counts
4 → 62
Calls
4 calls:
Slowest
37.0ms
(* (- (sqrt (- (* b b) (* (* 4 a) c))) b) (/ 1 (* 2 a)))
10.0ms
(- (sqrt (- (* b b) (* (* 4 a) c))) b)
3.0ms
(- (* b b) (* (* 4 a) c))
2.0ms
(sqrt (- (* b b) (* (* 4 a) c)))

series221.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
80.0ms
(* (- (sqrt (- (* b b) (* (* 4 a) c))) b) (/ 1 (* 2 a)))
55.0ms
(- (sqrt (- (* b b) (* (* 4 a) c))) b)
43.0ms
(- (* b b) (* (* 4 a) c))
42.0ms
(sqrt (- (* b b) (* (* 4 a) c)))

simplify3.3s

Counts
37 → 74
Calls
37 calls:
Slowest
584.0ms
(* (- (* (sqrt (- (* b b) (* (* 4 a) c))) (sqrt (- (* b b) (* (* 4 a) c)))) (* b b)) 1)
376.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
261.0ms
(* (- (* (sqrt (- (* b b) (* (* 4 a) c))) (sqrt (- (* b b) (* (* 4 a) c)))) (* b b)) (/ 1 (* 2 a)))
249.0ms
(* (- (sqrt (- (* b b) (* (* 4 a) c))) b) (/ 1 (* 2 a)))
239.0ms
(* (- (pow (sqrt (- (* b b) (* (* 4 a) c))) 3) (pow b 3)) 1)

prune634.0ms

Pruning

6 alts after pruning (4 fresh and 2 done)

Merged error: 6.2b

localize19.0ms

Local error

Found 4 expressions with local error:

22.0b
(sqrt (- (* b b) (* (* 4 a) c)))
14.2b
(/ (+ (* -4 (* a c)) 0) (/ a 1/2))
0.3b
(+ (sqrt (- (* b b) (* (* 4 a) c))) b)
0.2b
(- (* b b) (* (* 4 a) c))

rewrite18.0ms

Algorithm
rewrite-expression-head
Rules
15×add-sqr-sqrt
14×add-cube-cbrt
14×*-un-lft-identity
12×times-frac
add-log-exp
add-exp-log
add-cbrt-cube
div-inv
associate-/r*
pow1
associate-/l*
sqrt-prod
associate-/l/
flip--
flip-+
sqrt-div
flip3--
flip3-+
associate-/r/
div-exp
diff-log
pow1/2
frac-2neg
sub-neg
clear-num
rem-sqrt-square
+-commutative
cbrt-undiv
Counts
4 → 70
Calls
4 calls:
Slowest
7.0ms
(+ (sqrt (- (* b b) (* (* 4 a) c))) b)
6.0ms
(/ (+ (* -4 (* a c)) 0) (/ a 1/2))
2.0ms
(- (* b b) (* (* 4 a) c))
2.0ms
(sqrt (- (* b b) (* (* 4 a) c)))

series173.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
62.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
58.0ms
(+ (sqrt (- (* b b) (* (* 4 a) c))) b)
43.0ms
(- (* b b) (* (* 4 a) c))
10.0ms
(/ (+ (* -4 (* a c)) 0) (/ a 1/2))

simplify3.5s

Counts
53 → 82
Calls
53 calls:
Slowest
763.0ms
(/ (+ (* -4 (* a c)) 0) (/ a 1/2))
425.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
377.0ms
(/ (+ (* -4 (* a c)) 0) (/ 1 1/2))
244.0ms
(- (log (+ (* -4 (* a c)) 0)) (log (/ a 1/2)))
206.0ms
(- (* (* -4 (* a c)) (* -4 (* a c))) (* 0 0))

prune1.1s

Pruning

6 alts after pruning (4 fresh and 2 done)

Merged error: 6.2b

regimes335.0ms

Accuracy

94.8% (1.2b remaining)

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

bsearch630.0ms

end0.0ms

sample5.3s

Algorithm
intervals