Average Error: 33.4 → 7.4
Time: 15.4s
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 0 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: 14.9s)Debug log

sample122.0ms

Algorithm
intervals
Results
30.0ms40×body2560valid
25.0ms185×body80valid
22.0ms27×body1280valid
12.0ms97×body80nan
7.0ms15×body640valid
4.0msbody5120valid
3.0msbody320valid
2.0msbody160valid

simplify88.0ms

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

prune16.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 32.5b

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

rewrite79.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
40.0ms
(/ (- (sqrt (- (* b b) (* (* c a) 4))) b) (* 2 a))
30.0ms
(- (sqrt (- (* b b) (* (* c a) 4))) b)
4.0ms
(- (* b b) (* (* c a) 4))
4.0ms
(sqrt (- (* b b) (* (* c a) 4)))

series202.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
64.0ms
(- (sqrt (- (* b b) (* (* c a) 4))) b)
58.0ms
(/ (- (sqrt (- (* b b) (* (* c a) 4))) b) (* 2 a))
54.0ms
(sqrt (- (* b b) (* (* c a) 4)))
26.0ms
(- (* b b) (* (* c a) 4))

simplify1.9s

Counts
32 → 71
Calls
32 calls:
Slowest
347.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* c a) 4) 3)))
270.0ms
(- (* (sqrt (- (* b b) (* (* c a) 4))) (sqrt (- (* b b) (* (* c a) 4)))) (* b b))
179.0ms
(- (pow (sqrt (- (* b b) (* (* c a) 4))) 3) (pow b 3))
131.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* c a) 4) (* (* c a) 4))))
91.0ms
(- b (* 2 (/ (* a c) b)))

prune853.0ms

Pruning

10 alts after pruning (10 fresh and 0 done)

Merged error: 5.5b

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

rewrite43.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
26.0ms
(/ (* (* c -4) a) (* (* 2 a) (+ (sqrt (- (* b b) (* (* c a) 4))) b)))
10.0ms
(+ (sqrt (- (* b b) (* (* c a) 4))) b)
4.0ms
(sqrt (- (* b b) (* (* c a) 4)))
2.0ms
(- (* b b) (* (* c a) 4))

series274.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
128.0ms
(/ (* (* c -4) a) (* (* 2 a) (+ (sqrt (- (* b b) (* (* c a) 4))) b)))
64.0ms
(+ (sqrt (- (* b b) (* (* c a) 4))) b)
55.0ms
(sqrt (- (* b b) (* (* c a) 4)))
27.0ms
(- (* b b) (* (* c a) 4))

simplify3.0s

Counts
29 → 67
Calls
29 calls:
Slowest
750.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))))
707.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))))
338.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* c a) 4) 3)))
234.0ms
(+ (* (sqrt (- (* b b) (* (* c a) 4))) (sqrt (- (* b b) (* (* c a) 4)))) (- (* b b) (* (sqrt (- (* b b) (* (* c a) 4))) b)))
128.0ms
(- (* 2 b) (* 2 (/ (* a c) b)))

prune616.0ms

Pruning

8 alts after pruning (8 fresh and 0 done)

Merged error: 5.5b

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

rewrite16.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
7.0ms
(+ (sqrt (- (* b b) (* (* c a) 4))) b)
5.0ms
(/ (* (* c -4) a) (* 2 a))
2.0ms
(- (* b b) (* (* c a) 4))
2.0ms
(sqrt (- (* b b) (* (* c a) 4)))

series115.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
46.0ms
(+ (sqrt (- (* b b) (* (* c a) 4))) b)
39.0ms
(sqrt (- (* b b) (* (* c a) 4)))
24.0ms
(- (* b b) (* (* c a) 4))
5.0ms
(/ (* (* c -4) a) (* 2 a))

simplify1.5s

Counts
24 → 63
Calls
24 calls:
Slowest
434.0ms
(- (log (* (* c -4) a)) (log (* 2 a)))
315.0ms
(/ (* (* (* (* c -4) a) (* (* c -4) a)) (* (* c -4) a)) (* (* (* 2 a) (* 2 a)) (* 2 a)))
231.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* c a) 4) 3)))
97.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* c a) 4) (* (* c a) 4))))
82.0ms
(- (* 2 b) (* 2 (/ (* a c) b)))

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

rewrite23.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
10.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)))

series209.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
99.0ms
(/ (* -2 c) (+ (sqrt (- (* b b) (* (* c a) 4))) b))
45.0ms
(+ (sqrt (- (* b b) (* (* c a) 4))) b)
39.0ms
(sqrt (- (* b b) (* (* c a) 4)))
25.0ms
(- (* b b) (* (* c a) 4))

simplify1.2s

Counts
32 → 69
Calls
32 calls:
Slowest
227.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* c a) 4) 3)))
177.0ms
(+ (* (sqrt (- (* b b) (* (* c a) 4))) (sqrt (- (* b b) (* (* c a) 4)))) (- (* b b) (* (sqrt (- (* b b) (* (* c a) 4))) b)))
96.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* c a) 4) (* (* c a) 4))))
77.0ms
(- (* 2 b) (* 2 (/ (* a c) b)))
76.0ms
(- b (* 2 (/ (* a c) b)))

prune438.0ms

Pruning

7 alts after pruning (6 fresh and 1 done)

Merged error: 5.5b

regimes185.0ms

Accuracy

92.1% (1.9b remaining)

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

bsearch228.0ms

end0.0ms

sample3.2s

Algorithm
intervals
Results
937.0ms5847×body80valid
907.0ms1063×body2560valid
462.0ms924×body1280valid
291.0ms2979×body80nan
277.0ms435×body640valid
77.0ms222×body320valid
63.0ms102×body5120valid
24.0ms145×body160valid