Average Error: 33.4 → 7.4
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 -2.1317624771383882 \cdot 10^{+58}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 1.080192248888389 \cdot 10^{-171}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4}}{2 \cdot a} - \frac{b}{2 \cdot a}\\ \mathbf{elif}\;b \le 1.3660877782595927 \cdot 10^{+23}:\\ \;\;\;\;\left(c \cdot -2\right) \cdot \frac{1}{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + b}\\ \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.4
Target20.6
Herbie7.4
\[\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 < -2.1317624771383882e+58

    1. Initial program 37.4

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

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

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

    if -2.1317624771383882e+58 < b < 1.080192248888389e-171

    1. Initial program 11.7

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

      \[\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-sub11.7

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

    if 1.080192248888389e-171 < b < 1.3660877782595927e+23

    1. Initial program 32.3

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

      \[\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 flip--32.4

      \[\leadsto \frac{\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}}}{2 \cdot a}\]
    5. Applied associate-/l/37.4

      \[\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}{\left(2 \cdot a\right) \cdot \left(\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + b\right)}}\]
    6. Simplified20.4

      \[\leadsto \frac{\color{blue}{\left(c \cdot -4\right) \cdot a}}{\left(2 \cdot a\right) \cdot \left(\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + b\right)}\]
    7. Using strategy rm
    8. Applied associate-/r*14.6

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

      \[\leadsto \frac{\color{blue}{-2 \cdot c}}{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + b}\]
    10. Using strategy rm
    11. Applied div-inv5.9

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

    if 1.3660877782595927e+23 < b

    1. Initial program 55.5

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -2.1317624771383882 \cdot 10^{+58}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 1.080192248888389 \cdot 10^{-171}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4}}{2 \cdot a} - \frac{b}{2 \cdot a}\\ \mathbf{elif}\;b \le 1.3660877782595927 \cdot 10^{+23}:\\ \;\;\;\;\left(c \cdot -2\right) \cdot \frac{1}{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + b}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2019022 
(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.1s)Debug log

sample134.0ms

Algorithm
intervals
Results
40.0ms40×body2560valid
27.0ms185×body80valid
19.0ms27×body1280valid
13.0ms97×body80nan
8.0ms15×body640valid
3.0msbody5120valid
3.0msbody320valid
2.0msbody160valid

simplify84.0ms

Counts
1 → 1
Calls
1 calls:
Slowest
84.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.5b

localize36.0ms

Local error

Found 4 expressions with local error:

21.7b
(sqrt (- (* b b) (* (* c a) 4)))
2.0b
(- (sqrt (- (* b b) (* (* c a) 4))) b)
0.4b
(- (* b b) (* (* c a) 4))
0.1b
(/ (- (sqrt (- (* b b) (* (* c a) 4))) b) (* 2 a))

rewrite57.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
28.0ms
(- (sqrt (- (* b b) (* (* c a) 4))) b)
21.0ms
(/ (- (sqrt (- (* b b) (* (* c a) 4))) b) (* 2 a))
4.0ms
(- (* b b) (* (* c a) 4))
4.0ms
(sqrt (- (* b b) (* (* c a) 4)))

series249.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
74.0ms
(- (sqrt (- (* b b) (* (* c a) 4))) b)
71.0ms
(/ (- (sqrt (- (* b b) (* (* c a) 4))) b) (* 2 a))
63.0ms
(sqrt (- (* b b) (* (* c a) 4)))
42.0ms
(- (* b b) (* (* c a) 4))

simplify1.9s

Counts
32 → 71
Calls
32 calls:
Slowest
330.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* c a) 4) 3)))
247.0ms
(- (* (sqrt (- (* b b) (* (* c a) 4))) (sqrt (- (* b b) (* (* c a) 4)))) (* b b))
173.0ms
(- (pow (sqrt (- (* b b) (* (* c a) 4))) 3) (pow b 3))
113.0ms
(- b (* 2 (/ (* a c) b)))
113.0ms
(/ (* (* (- (sqrt (- (* b b) (* (* c a) 4))) b) (- (sqrt (- (* b b) (* (* c a) 4))) b)) (- (sqrt (- (* b b) (* (* c a) 4))) b)) (* (* (* 2 a) (* 2 a)) (* 2 a)))

prune660.0ms

Pruning

10 alts after pruning (10 fresh and 0 done)

Merged error: 5.5b

localize12.0ms

Local error

Found 4 expressions with local error:

21.7b
(sqrt (- (* b b) (* (* c a) 4)))
13.5b
(/ (* (* c -4) a) (* (* 2 a) (+ (sqrt (- (* b b) (* (* c a) 4))) b)))
1.3b
(+ (sqrt (- (* b b) (* (* c a) 4))) b)
0.4b
(- (* b b) (* (* c a) 4))

rewrite45.0ms

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

series289.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
158.0ms
(/ (* (* c -4) a) (* (* 2 a) (+ (sqrt (- (* b b) (* (* c a) 4))) b)))
54.0ms
(+ (sqrt (- (* b b) (* (* c a) 4))) b)
49.0ms
(sqrt (- (* b b) (* (* c a) 4)))
27.0ms
(- (* b b) (* (* c a) 4))

simplify3.5s

Counts
29 → 67
Calls
29 calls:
Slowest
925.0ms
(/ (* (* (* (* c -4) a) (* (* c -4) a)) (* (* c -4) a)) (* (* (* (* 2 a) (+ (sqrt (- (* b b) (* (* c a) 4))) b)) (* (* 2 a) (+ (sqrt (- (* b b) (* (* c a) 4))) b))) (* (* 2 a) (+ (sqrt (- (* b b) (* (* c a) 4))) b))))
862.0ms
(/ (* (* (* (* c -4) a) (* (* c -4) a)) (* (* c -4) a)) (* (* (* (* 2 a) (* 2 a)) (* 2 a)) (* (* (+ (sqrt (- (* b b) (* (* c a) 4))) b) (+ (sqrt (- (* b b) (* (* c a) 4))) b)) (+ (sqrt (- (* b b) (* (* c a) 4))) b))))
289.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* c a) 4) 3)))
269.0ms
(+ (* (sqrt (- (* b b) (* (* c a) 4))) (sqrt (- (* b b) (* (* c a) 4)))) (- (* b b) (* (sqrt (- (* b b) (* (* c a) 4))) b)))
150.0ms
(- (* 2 b) (* 2 (/ (* a c) b)))

prune802.0ms

Pruning

8 alts after pruning (8 fresh and 0 done)

Merged error: 5.5b

localize12.0ms

Local error

Found 4 expressions with local error:

21.7b
(sqrt (- (* b b) (* (* c a) 4)))
12.1b
(/ (* (* c -4) a) (* 2 a))
1.3b
(+ (sqrt (- (* b b) (* (* c a) 4))) b)
0.4b
(- (* b b) (* (* c a) 4))

rewrite35.0ms

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

series178.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
68.0ms
(+ (sqrt (- (* b b) (* (* c a) 4))) b)
63.0ms
(sqrt (- (* b b) (* (* c a) 4)))
36.0ms
(- (* b b) (* (* c a) 4))
11.0ms
(/ (* (* c -4) a) (* 2 a))

simplify2.1s

Counts
24 → 63
Calls
24 calls:
Slowest
630.0ms
(- (log (* (* c -4) a)) (log (* 2 a)))
445.0ms
(/ (* (* (* (* c -4) a) (* (* c -4) a)) (* (* c -4) a)) (* (* (* 2 a) (* 2 a)) (* 2 a)))
312.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* c a) 4) 3)))
141.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* c a) 4) (* (* c a) 4))))
100.0ms
(- (* 2 b) (* 2 (/ (* a c) b)))

prune689.0ms

Pruning

8 alts after pruning (7 fresh and 1 done)

Merged error: 5.5b

localize6.0ms

Local error

Found 4 expressions with local error:

21.7b
(sqrt (- (* b b) (* (* c a) 4)))
1.3b
(+ (sqrt (- (* b b) (* (* c a) 4))) b)
0.4b
(- (* b b) (* (* c a) 4))
0.1b
(/ (* -2 c) (+ (sqrt (- (* b b) (* (* c a) 4))) b))

rewrite24.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
times-frac
associate-/r*
flip--
flip-+
associate-/r/
sqrt-div
flip3--
flip3-+
associate-/l*
div-inv
div-exp
diff-log
pow1/2
frac-2neg
sub-neg
clear-num
rem-sqrt-square
+-commutative
cbrt-undiv
Counts
4 → 57
Calls
4 calls:
Slowest
12.0ms
(/ (* -2 c) (+ (sqrt (- (* b b) (* (* c a) 4))) b))
8.0ms
(+ (sqrt (- (* b b) (* (* c a) 4))) b)
2.0ms
(- (* b b) (* (* c a) 4))
2.0ms
(sqrt (- (* b b) (* (* c a) 4)))

series267.0ms

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

simplify1.9s

Counts
32 → 69
Calls
32 calls:
Slowest
354.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* c a) 4) 3)))
283.0ms
(+ (* (sqrt (- (* b b) (* (* c a) 4))) (sqrt (- (* b b) (* (* c a) 4)))) (- (* b b) (* (sqrt (- (* b b) (* (* c a) 4))) b)))
138.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* c a) 4) (* (* c a) 4))))
122.0ms
(- (* 2 b) (* 2 (/ (* a c) b)))
116.0ms
(- b (* 2 (/ (* a c) b)))

prune642.0ms

Pruning

7 alts after pruning (6 fresh and 1 done)

Merged error: 5.5b

regimes314.0ms

Accuracy

92.1% (1.9b remaining)

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

bsearch369.0ms

end0.0ms

sample4.8s

Algorithm
intervals
Results
1.5s1063×body2560valid
995.0ms924×body1280valid
969.0ms5847×body80valid
580.0ms2979×body80nan
294.0ms435×body640valid
129.0ms102×body5120valid
89.0ms222×body320valid
37.0ms145×body160valid