Average Error: 19.5 → 13.8
Time: 22.1s
Precision: 64
Internal Precision: 128
\[\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \end{array}\]
\[\begin{array}{l} \mathbf{if}\;b \le 2.863205149176435 \cdot 10^{+62}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{\sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)}} \cdot \sqrt{\sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)}}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)} - b}\\ \end{array}\\ \mathbf{elif}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - b}{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

Derivation

  1. Split input into 2 regimes
  2. if b < 2.863205149176435e+62

    1. Initial program 15.6

      \[\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \end{array}\]
    2. Simplified15.6

      \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{\left(-4 \cdot a\right) \cdot c + b \cdot b}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\sqrt{\left(-4 \cdot a\right) \cdot c + b \cdot b} - b}\\ \end{array}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt15.7

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - \color{blue}{\sqrt{\sqrt{\left(-4 \cdot a\right) \cdot c + b \cdot b}} \cdot \sqrt{\sqrt{\left(-4 \cdot a\right) \cdot c + b \cdot b}}}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\sqrt{\left(-4 \cdot a\right) \cdot c + b \cdot b} - b}\\ \end{array}\]

    if 2.863205149176435e+62 < b

    1. Initial program 37.0

      \[\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \end{array}\]
    2. Simplified37.0

      \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{\left(-4 \cdot a\right) \cdot c + b \cdot b}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\sqrt{\left(-4 \cdot a\right) \cdot c + b \cdot b} - b}\\ \end{array}}\]
    3. Taylor expanded around 0 5.3

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - \color{blue}{b}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\sqrt{\left(-4 \cdot a\right) \cdot c + b \cdot b} - b}\\ \end{array}\]
    4. Taylor expanded around 0 5.3

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - b}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{b}{a}\\ \end{array}\]
    5. Simplified5.3

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - b}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a}\\ \end{array}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification13.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le 2.863205149176435 \cdot 10^{+62}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{\sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)}} \cdot \sqrt{\sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)}}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)} - b}\\ \end{array}\\ \mathbf{elif}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - b}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a}\\ \end{array}\]

Reproduce

herbie shell --seed 2019016 
(FPCore (a b c)
  :name "jeff quadratic root 1"
  (if (>= b 0) (/ (- (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)) (/ (* 2 c) (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))))))

Details

Time bar (total: 20.6s)Debug log

sample141.0ms

Algorithm
intervals
Results
368×(pre true 80)
277×(body real 80)
91×(body nan 80)

simplify125.0ms

Counts
1 → 1
Calls
1 calls:
Slowest
125.0ms
(if (>= b 0) (/ (- (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)) (/ (* 2 c) (+ (- b) (sqrt (- (* b b) (* (* 4 a) c))))))

prune13.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 20.6b

localize168.0ms

Local error

Found 4 expressions with local error:

24.0b
(sqrt (+ (* (* -4 a) c) (* b b)))
24.0b
(sqrt (+ (* (* -4 a) c) (* b b)))
2.2b
(- (sqrt (+ (* (* -4 a) c) (* b b))) b)
1.2b
(- (- b) (sqrt (+ (* (* -4 a) c) (* b b))))

rewrite61.0ms

Algorithm
rewrite-expression-head
Rules
12×add-sqr-sqrt
*-un-lft-identity
sqrt-prod
add-log-exp
add-cube-cbrt
add-exp-log
sqrt-div
add-cbrt-cube
pow1
difference-of-squares
flip--
flip-+
pow1/2
flip3--
flip3-+
sub-neg
rem-sqrt-square
distribute-lft-out--
diff-log
neg-sub0
associate--l-
Counts
4 → 55
Calls
4 calls:
Slowest
29.0ms
(- (sqrt (+ (* (* -4 a) c) (* b b))) b)
19.0ms
(- (- b) (sqrt (+ (* (* -4 a) c) (* b b))))
6.0ms
(sqrt (+ (* (* -4 a) c) (* b b)))
6.0ms
(sqrt (+ (* (* -4 a) c) (* b b)))

series230.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
75.0ms
(- (- b) (sqrt (+ (* (* -4 a) c) (* b b))))
55.0ms
(sqrt (+ (* (* -4 a) c) (* b b)))
52.0ms
(- (sqrt (+ (* (* -4 a) c) (* b b))) b)
47.0ms
(sqrt (+ (* (* -4 a) c) (* b b)))

simplify1.5s

Counts
30 → 67
Calls
30 calls:
Slowest
569.0ms
(sqrt (- (* (* (* -4 a) c) (* (* -4 a) c)) (* (* b b) (* b b))))
232.0ms
(sqrt (+ (pow (* (* -4 a) c) 3) (pow (* b b) 3)))
205.0ms
(sqrt (- (* (* (* -4 a) c) (* (* -4 a) c)) (* (* b b) (* b b))))
195.0ms
(sqrt (+ (pow (* (* -4 a) c) 3) (pow (* b b) 3)))
58.0ms
(- (* 2 (/ (* a c) b)) (* 2 b))

prune973.0ms

Pruning

11 alts after pruning (11 fresh and 0 done)

Merged error: 12.1b

localize132.0ms

Local error

Found 4 expressions with local error:

24.0b
(sqrt (+ (* (* -4 a) c) (* b b)))
2.2b
(- (sqrt (+ (* (* -4 a) c) (* b b))) b)
1.2b
(+ (* (* -4 a) c) (* b b))
0.1b
(/ (* 2 c) (- (sqrt (+ (* (* -4 a) c) (* b b))) b))

rewrite81.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
pow1/2
frac-2neg
sub-neg
sum-log
clear-num
rem-sqrt-square
+-commutative
cbrt-undiv
Counts
4 → 57
Calls
4 calls:
Slowest
36.0ms
(/ (* 2 c) (- (sqrt (+ (* (* -4 a) c) (* b b))) b))
30.0ms
(- (sqrt (+ (* (* -4 a) c) (* b b))) b)
8.0ms
(+ (* (* -4 a) c) (* b b))
6.0ms
(sqrt (+ (* (* -4 a) c) (* b b)))

series267.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
121.0ms
(/ (* 2 c) (- (sqrt (+ (* (* -4 a) c) (* b b))) b))
70.0ms
(- (sqrt (+ (* (* -4 a) c) (* b b))) b)
45.0ms
(sqrt (+ (* (* -4 a) c) (* b b)))
31.0ms
(+ (* (* -4 a) c) (* b b))

simplify1.4s

Counts
32 → 69
Calls
32 calls:
Slowest
490.0ms
(/ (* (* (* 2 c) (* 2 c)) (* 2 c)) (* (* (- (sqrt (+ (* (* -4 a) c) (* b b))) b) (- (sqrt (+ (* (* -4 a) c) (* b b))) b)) (- (sqrt (+ (* (* -4 a) c) (* b b))) b)))
241.0ms
(sqrt (+ (pow (* (* -4 a) c) 3) (pow (* b b) 3)))
216.0ms
(sqrt (- (* (* (* -4 a) c) (* (* -4 a) c)) (* (* b b) (* b b))))
53.0ms
(- (log (* 2 c)) (log (- (sqrt (+ (* (* -4 a) c) (* b b))) b)))
36.0ms
(+ (* (sqrt (+ (* (* -4 a) c) (* b b))) (sqrt (+ (* (* -4 a) c) (* b b)))) (+ (* b b) (* (sqrt (+ (* (* -4 a) c) (* b b))) b)))

prune978.0ms

Pruning

12 alts after pruning (12 fresh and 0 done)

Merged error: 12.1b

localize127.0ms

Local error

Found 4 expressions with local error:

24.7b
(cbrt (+ (* (* -4 a) c) (* b b)))
24.7b
(cbrt (+ (* b b) (* (* c a) -4)))
8.0b
(- (* (fabs (cbrt (+ (* b b) (* (* c a) -4)))) (sqrt (cbrt (+ (* (* -4 a) c) (* b b))))) b)
1.2b
(+ (* b b) (* (* c a) -4))

rewrite33.0ms

Algorithm
rewrite-expression-head
Rules
add-log-exp
add-cube-cbrt
*-un-lft-identity
add-sqr-sqrt
cbrt-prod
add-exp-log
add-cbrt-cube
cbrt-div
pow1
flip-+
flip3-+
pow1/3
flip--
flip3--
sub-neg
sum-log
+-commutative
Counts
4 → 48
Calls
4 calls:
Slowest
20.0ms
(- (* (fabs (cbrt (+ (* b b) (* (* c a) -4)))) (sqrt (cbrt (+ (* (* -4 a) c) (* b b))))) b)
5.0ms
(+ (* b b) (* (* c a) -4))
4.0ms
(cbrt (+ (* (* -4 a) c) (* b b)))
2.0ms
(cbrt (+ (* b b) (* (* c a) -4)))

series443.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
213.0ms
(cbrt (+ (* (* -4 a) c) (* b b)))
124.0ms
(cbrt (+ (* b b) (* (* c a) -4)))
80.0ms
(- (* (fabs (cbrt (+ (* b b) (* (* c a) -4)))) (sqrt (cbrt (+ (* (* -4 a) c) (* b b))))) b)
25.0ms
(+ (* b b) (* (* c a) -4))

simplify2.4s

Counts
23 → 60
Calls
23 calls:
Slowest
411.0ms
(exp (* 1/3 (- (log -4) (+ (log (/ 1 a)) (log (/ 1 c))))))
325.0ms
(- (exp (* 1/3 (+ (log -4) (+ (log a) (log c))))) (* 1/12 (* (exp (* 1/3 (- (log -4) (+ (* 2 (log a)) (* 2 (log c)))))) (pow b 2))))
267.0ms
(cbrt (- (* (* (* -4 a) c) (* (* -4 a) c)) (* (* b b) (* b b))))
228.0ms
(- (* (fabs (pow (- (pow b 2) (* 4 (* a c))) 1/3)) (exp (* 1/6 (+ (log -4) (+ (log a) (log c)))))) (+ b (* 1/24 (* (pow b 2) (* (fabs (pow (- (pow b 2) (* 4 (* a c))) 1/3)) (exp (* 1/6 (- (log -4) (+ (* 5 (log a)) (* 5 (log c)))))))))))
225.0ms
(cbrt (+ (pow (* (* -4 a) c) 3) (pow (* b b) 3)))

prune1.3s

Pruning

12 alts after pruning (11 fresh and 1 done)

Merged error: 12.0b

localize109.0ms

Local error

Found 4 expressions with local error:

24.7b
(cbrt (+ (* (* -4 a) c) (* b b)))
24.7b
(cbrt (* (sqrt (+ (* b b) (* (* c a) -4))) (sqrt (+ (* b b) (* (* c a) -4)))))
24.0b
(sqrt (+ (* b b) (* (* c a) -4)))
24.0b
(sqrt (+ (* b b) (* (* c a) -4)))

rewrite31.0ms

Algorithm
rewrite-expression-head
Rules
16×sqrt-div
10×cbrt-div
flip-+
flip3-+
add-sqr-sqrt
add-cube-cbrt
*-un-lft-identity
sqrt-prod
add-log-exp
add-exp-log
add-cbrt-cube
pow1
frac-times
cbrt-prod
associate-*r/
associate-*l/
pow1/3
pow1/2
rem-sqrt-square
Counts
4 → 58
Calls
4 calls:
Slowest
17.0ms
(cbrt (* (sqrt (+ (* b b) (* (* c a) -4))) (sqrt (+ (* b b) (* (* c a) -4)))))
4.0ms
(sqrt (+ (* b b) (* (* c a) -4)))
4.0ms
(cbrt (+ (* (* -4 a) c) (* b b)))
4.0ms
(sqrt (+ (* b b) (* (* c a) -4)))

series391.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
191.0ms
(cbrt (+ (* (* -4 a) c) (* b b)))
89.0ms
(cbrt (* (sqrt (+ (* b b) (* (* c a) -4))) (sqrt (+ (* b b) (* (* c a) -4)))))
57.0ms
(sqrt (+ (* b b) (* (* c a) -4)))
53.0ms
(sqrt (+ (* b b) (* (* c a) -4)))

simplify4.1s

Counts
38 → 70
Calls
38 calls:
Slowest
329.0ms
(exp (* 1/3 (- (log -4) (+ (log (/ 1 a)) (log (/ 1 c))))))
305.0ms
(cbrt (* (sqrt (- (* (* b b) (* b b)) (* (* (* c a) -4) (* (* c a) -4)))) (sqrt (+ (pow (* b b) 3) (pow (* (* c a) -4) 3)))))
265.0ms
(cbrt (* (sqrt (+ (pow (* b b) 3) (pow (* (* c a) -4) 3))) (sqrt (- (* (* b b) (* b b)) (* (* (* c a) -4) (* (* c a) -4))))))
246.0ms
(- (exp (* 1/3 (+ (log -4) (+ (log a) (log c))))) (* 1/12 (* (exp (* 1/3 (- (log -4) (+ (* 2 (log a)) (* 2 (log c)))))) (pow b 2))))
232.0ms
(cbrt (- (* (* (* -4 a) c) (* (* -4 a) c)) (* (* b b) (* b b))))

prune1.7s

Pruning

12 alts after pruning (10 fresh and 2 done)

Merged error: 12.0b

regimes464.0ms

Accuracy

90.5% (0.8b remaining)

Error of 13.8b against oracle of 13.0b and baseline of 21.7b

bsearch200.0ms

end0.0ms

sample3.3s

Algorithm
intervals
Results
11455×(pre true 80)
8717×(body real 80)
2738×(body nan 80)