Average Error: 33.5 → 9.2
Time: 20.3s
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 -2.1404970644413445 \cdot 10^{+42}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le -4.645504089248097 \cdot 10^{-163}:\\ \;\;\;\;\frac{\frac{\left(4 \cdot c\right) \cdot a}{2 \cdot a}}{\sqrt{\sqrt{-4 \cdot \left(a \cdot c\right) + b \cdot b}} \cdot \sqrt{\sqrt{-4 \cdot \left(a \cdot c\right) + b \cdot b}} - b}\\ \mathbf{elif}\;b \le 1.501809486178084 \cdot 10^{+23}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\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.5
Target20.3
Herbie9.2
\[\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 4 regimes
  2. if b < -2.1404970644413445e+42

    1. Initial program 56.5

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

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

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

    if -2.1404970644413445e+42 < b < -4.645504089248097e-163

    1. Initial program 36.1

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

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

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

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

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

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

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

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

    if -4.645504089248097e-163 < b < 1.501809486178084e+23

    1. Initial program 11.9

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

    if 1.501809486178084e+23 < b

    1. Initial program 32.7

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}}\]
    7. Simplified6.3

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -2.1404970644413445 \cdot 10^{+42}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le -4.645504089248097 \cdot 10^{-163}:\\ \;\;\;\;\frac{\frac{\left(4 \cdot c\right) \cdot a}{2 \cdot a}}{\sqrt{\sqrt{-4 \cdot \left(a \cdot c\right) + b \cdot b}} \cdot \sqrt{\sqrt{-4 \cdot \left(a \cdot c\right) + b \cdot b}} - b}\\ \mathbf{elif}\;b \le 1.501809486178084 \cdot 10^{+23}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a}\\ \end{array}\]

Reproduce

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

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

sample109.0ms

Algorithm
intervals
Results
30.0ms24×body1280valid
21.0ms32×body2560valid
19.0ms188×body80valid
9.0ms96×body80nan
7.0ms17×body640valid
6.0msbody5120valid
2.0msbody320valid
1.0msbody160valid

simplify89.0ms

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

prune7.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 33.7b

localize32.0ms

Local error

Found 4 expressions with local error:

22.4b
(sqrt (- (* b b) (* 4 (* a c))))
1.1b
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
0.4b
(- (* b b) (* 4 (* a c)))
0.1b
(/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a))

rewrite57.0ms

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

series237.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
86.0ms
(/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a))
65.0ms
(sqrt (- (* b b) (* 4 (* a c))))
50.0ms
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
36.0ms
(- (* b b) (* 4 (* a c)))

simplify2.7s

Counts
46 → 82
Calls
46 calls:
Slowest
313.0ms
(sqrt (- (pow (* b b) 3) (pow (* 4 (* a c)) 3)))
297.0ms
(- (pow (- b) 3) (pow (sqrt (- (* b b) (* 4 (* a c)))) 3))
247.0ms
(- (* (- b) (- b)) (* (sqrt (- (* b b) (* 4 (* a c)))) (sqrt (- (* b b) (* 4 (* a c))))))
180.0ms
(sqrt (- (* (* b b) (* b b)) (* (* 4 (* a c)) (* 4 (* a c)))))
116.0ms
(- b (* 2 (/ (* a c) b)))

prune902.0ms

Pruning

9 alts after pruning (8 fresh and 1 done)

Merged error: 5.5b

localize20.0ms

Local error

Found 4 expressions with local error:

22.4b
(sqrt (- (* b b) (* 4 (* a c))))
14.0b
(/ (* (* c 4) a) (* (* 2 a) (+ (- b) (sqrt (- (* b b) (* 4 (* a c)))))))
2.0b
(+ (- b) (sqrt (- (* b b) (* 4 (* a c)))))
0.4b
(- (* b b) (* 4 (* a c)))

rewrite24.0ms

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

series257.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
122.0ms
(/ (* (* c 4) a) (* (* 2 a) (+ (- b) (sqrt (- (* b b) (* 4 (* a c)))))))
57.0ms
(+ (- b) (sqrt (- (* b b) (* 4 (* a c)))))
44.0ms
(sqrt (- (* b b) (* 4 (* a c))))
34.0ms
(- (* b b) (* 4 (* a c)))

simplify3.0s

Counts
31 → 70
Calls
31 calls:
Slowest
713.0ms
(/ (* (* (* (* c 4) a) (* (* c 4) a)) (* (* c 4) a)) (* (* (* (* 2 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))))))))
652.0ms
(/ (* (* (* (* c 4) a) (* (* c 4) a)) (* (* c 4) a)) (* (* (* (* 2 a) (* 2 a)) (* 2 a)) (* (* (+ (- b) (sqrt (- (* b b) (* 4 (* a c))))) (+ (- b) (sqrt (- (* b b) (* 4 (* a c)))))) (+ (- b) (sqrt (- (* b b) (* 4 (* a c))))))))
277.0ms
(+ (* (- b) (- b)) (- (* (sqrt (- (* b b) (* 4 (* a c)))) (sqrt (- (* b b) (* 4 (* a c))))) (* (- b) (sqrt (- (* b b) (* 4 (* a c)))))))
251.0ms
(sqrt (- (pow (* b b) 3) (pow (* 4 (* a c)) 3)))
151.0ms
(- (log (* (* c 4) a)) (log (* (* 2 a) (+ (- b) (sqrt (- (* b b) (* 4 (* a c))))))))

prune717.0ms

Pruning

9 alts after pruning (7 fresh and 2 done)

Merged error: 5.5b

localize15.0ms

Local error

Found 4 expressions with local error:

22.4b
(sqrt (+ (* -4 (* a c)) (* b b)))
13.0b
(/ (* (* c 4) a) (* 2 a))
2.0b
(- (sqrt (+ (* -4 (* a c)) (* b b))) b)
0.4b
(+ (* -4 (* a c)) (* b b))

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

series199.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
73.0ms
(- (sqrt (+ (* -4 (* a c)) (* b b))) b)
71.0ms
(sqrt (+ (* -4 (* a c)) (* b b)))
48.0ms
(+ (* -4 (* a c)) (* b b))
8.0ms
(/ (* (* c 4) a) (* 2 a))

simplify1.7s

Counts
24 → 63
Calls
24 calls:
Slowest
625.0ms
(/ (* (* (* (* c 4) a) (* (* c 4) a)) (* (* c 4) a)) (* (* (* 2 a) (* 2 a)) (* 2 a)))
554.0ms
(- (log (* (* c 4) a)) (log (* 2 a)))
188.0ms
(sqrt (- (* (* -4 (* a c)) (* -4 (* a c))) (* (* b b) (* b b))))
142.0ms
(sqrt (+ (pow (* -4 (* a c)) 3) (pow (* b b) 3)))
38.0ms
(- (pow b 2) (* 4 (* a c)))

prune615.0ms

Pruning

8 alts after pruning (6 fresh and 2 done)

Merged error: 5.5b

localize22.0ms

Local error

Found 4 expressions with local error:

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

rewrite39.0ms

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

series196.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
69.0ms
(- (* (sqrt (sqrt (+ (* -4 (* a c)) (* b b)))) (sqrt (sqrt (+ (* -4 (* a c)) (* b b))))) b)
67.0ms
(sqrt (+ (* -4 (* a c)) (* b b)))
55.0ms
(sqrt (+ (* -4 (* a c)) (* b b)))
5.0ms
(/ (* (* c 4) a) (* 2 a))

simplify2.5s

Counts
29 → 66
Calls
29 calls:
Slowest
810.0ms
(/ (* (* (* (* c 4) a) (* (* c 4) a)) (* (* c 4) a)) (* (* (* 2 a) (* 2 a)) (* 2 a)))
516.0ms
(- (log (* (* c 4) a)) (log (* 2 a)))
471.0ms
(sqrt (+ (pow (* -4 (* a c)) 3) (pow (* b b) 3)))
248.0ms
(sqrt (- (* (* -4 (* a c)) (* -4 (* a c))) (* (* b b) (* b b))))
169.0ms
(sqrt (- (* (* -4 (* a c)) (* -4 (* a c))) (* (* b b) (* b b))))

prune885.0ms

Pruning

8 alts after pruning (5 fresh and 3 done)

Merged error: 5.5b

regimes486.0ms

Accuracy

86% (3.6b remaining)

Error of 9.2b against oracle of 5.5b and baseline of 31.6b

bsearch311.0ms

end0.0ms

sample4.3s

Algorithm
intervals
Results
1.5s1063×body2560valid
845.0ms5849×body80valid
819.0ms937×body1280valid
416.0ms2975×body80nan
251.0ms444×body640valid
111.0ms123×body5120valid
77.0ms203×body320valid
29.0ms111×body160valid