Average Error: 33.2 → 6.7
Time: 19.9s
Precision: 64
Internal Precision: 128
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{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} - 4 \cdot \left(c \cdot a\right)} - b}{a \cdot 2}\\ \mathbf{elif}\;b \le 2.653900512555386 \cdot 10^{+58}:\\ \;\;\;\;\frac{c \cdot -2}{b + \sqrt{b \cdot b - 4 \cdot \left(c \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 - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{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 - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Simplified49.1

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

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

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

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

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

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

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

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

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

    if 2.653900512555386e+58 < b

    1. Initial program 56.4

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
    6. 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} - 4 \cdot \left(c \cdot a\right)} - b}{a \cdot 2}\\ \mathbf{elif}\;b \le 2.653900512555386 \cdot 10^{+58}:\\ \;\;\;\;\frac{c \cdot -2}{b + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2019010 
(FPCore (a b c)
  :name "The quadratic formula (r1)"

  :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: 19.3s)Debug log

sample184.0ms

Algorithm
intervals

simplify87.0ms

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

prune20.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 32.9b

localize48.0ms

Local error

Found 4 expressions with local error:

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

rewrite44.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
21.0ms
(/ (- (sqrt (- (* b b) (* (* c a) 4))) b) (* 2 a))
11.0ms
(- (sqrt (- (* b b) (* (* c a) 4))) b)
9.0ms
(sqrt (- (* b b) (* (* c a) 4)))
2.0ms
(- (* b b) (* (* c a) 4))

series258.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
78.0ms
(/ (- (sqrt (- (* b b) (* (* c a) 4))) b) (* 2 a))
73.0ms
(- (sqrt (- (* b b) (* (* c a) 4))) b)
63.0ms
(sqrt (- (* b b) (* (* c a) 4)))
43.0ms
(- (* b b) (* (* c a) 4))

simplify1.8s

Counts
32 → 71
Calls
32 calls:
Slowest
368.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* c a) 4) 3)))
243.0ms
(- (* (sqrt (- (* b b) (* (* c a) 4))) (sqrt (- (* b b) (* (* c a) 4)))) (* b b))
149.0ms
(- (pow (sqrt (- (* b b) (* (* c a) 4))) 3) (pow b 3))
145.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* c a) 4) (* (* c a) 4))))
82.0ms
(- b (* 2 (/ (* a c) b)))

prune765.0ms

Pruning

7 alts after pruning (7 fresh and 0 done)

Merged error: 6.3b

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

rewrite73.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
36.0ms
(/ (- (sqrt (- (pow b 2) (* 4 (* a c)))) b) (* 2 a))
24.0ms
(- (sqrt (- (pow b 2) (* 4 (* a c)))) b)
7.0ms
(- (pow b 2) (* 4 (* a c)))
6.0ms
(sqrt (- (pow b 2) (* 4 (* a c))))

series227.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
97.0ms
(/ (- (sqrt (- (pow b 2) (* 4 (* a c)))) b) (* 2 a))
44.0ms
(- (sqrt (- (pow b 2) (* 4 (* a c)))) b)
43.0ms
(sqrt (- (pow b 2) (* 4 (* a c))))
43.0ms
(- (pow b 2) (* 4 (* a c)))

simplify1.9s

Counts
32 → 71
Calls
32 calls:
Slowest
370.0ms
(- (* (sqrt (- (pow b 2) (* 4 (* a c)))) (sqrt (- (pow b 2) (* 4 (* a c))))) (* b b))
293.0ms
(sqrt (- (pow (pow b 2) 3) (pow (* 4 (* a c)) 3)))
210.0ms
(sqrt (- (* (pow b 2) (pow b 2)) (* (* 4 (* a c)) (* 4 (* a c)))))
163.0ms
(- (pow (sqrt (- (pow b 2) (* 4 (* a c)))) 3) (pow b 3))
98.0ms
(- b (* 2 (/ (* a c) b)))

prune650.0ms

Pruning

6 alts after pruning (5 fresh and 1 done)

Merged error: 6.3b

localize6.0ms

Local error

Found 4 expressions with local error:

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

rewrite43.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
25.0ms
(* (- (sqrt (- (* b b) (* (* c a) 4))) b) (/ 1 (* 2 a)))
13.0ms
(- (sqrt (- (* b b) (* (* c a) 4))) b)
2.0ms
(- (* b b) (* (* c a) 4))
2.0ms
(sqrt (- (* b b) (* (* c a) 4)))

series186.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
68.0ms
(* (- (sqrt (- (* b b) (* (* c a) 4))) b) (/ 1 (* 2 a)))
47.0ms
(- (sqrt (- (* b b) (* (* c a) 4))) b)
42.0ms
(sqrt (- (* b b) (* (* c a) 4)))
29.0ms
(- (* b b) (* (* c a) 4))

simplify2.8s

Counts
37 → 74
Calls
37 calls:
Slowest
505.0ms
(* (- (* (sqrt (- (* b b) (* (* c a) 4))) (sqrt (- (* b b) (* (* c a) 4)))) (* b b)) 1)
275.0ms
(* (- (* (sqrt (- (* b b) (* (* c a) 4))) (sqrt (- (* b b) (* (* c a) 4)))) (* b b)) (/ 1 (* 2 a)))
257.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* c a) 4) 3)))
186.0ms
(* (+ (* (sqrt (- (* b b) (* (* c a) 4))) (sqrt (- (* b b) (* (* c a) 4)))) (+ (* b b) (* (sqrt (- (* b b) (* (* c a) 4))) b))) (* 2 a))
180.0ms
(* (- (sqrt (- (* b b) (* (* c a) 4))) b) (/ 1 (* 2 a)))

prune722.0ms

Pruning

6 alts after pruning (4 fresh and 2 done)

Merged error: 6.2b

localize29.0ms

Local error

Found 4 expressions with local error:

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

rewrite20.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
8.0ms
(+ (sqrt (- (* b b) (* (* c a) 4))) b)
7.0ms
(/ (+ (* -4 (* c a)) 0) (/ a 1/2))
2.0ms
(- (* b b) (* (* c a) 4))
2.0ms
(sqrt (- (* b b) (* (* c a) 4)))

series145.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
55.0ms
(+ (sqrt (- (* b b) (* (* c a) 4))) b)
50.0ms
(sqrt (- (* b b) (* (* c a) 4)))
36.0ms
(- (* b b) (* (* c a) 4))
5.0ms
(/ (+ (* -4 (* c a)) 0) (/ a 1/2))

simplify2.9s

Counts
53 → 82
Calls
53 calls:
Slowest
642.0ms
(/ (+ (* -4 (* c a)) 0) (/ a 1/2))
377.0ms
(/ (+ (* -4 (* c a)) 0) (/ 1 1/2))
338.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* c a) 4) 3)))
180.0ms
(- (* (* -4 (* c a)) (* -4 (* c a))) (* 0 0))
175.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* c a) 4) (* (* c a) 4))))

prune883.0ms

Pruning

6 alts after pruning (4 fresh and 2 done)

Merged error: 6.2b

regimes281.0ms

Accuracy

94.9% (1.2b remaining)

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

bsearch662.0ms

end0.0ms

sample4.4s

Algorithm
intervals