Average Error: 33.2 → 8.7
Time: 24.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.8021396801207425 \cdot 10^{+125}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 1.13066952980576 \cdot 10^{-152}:\\ \;\;\;\;\frac{\sqrt{{b}^{2} - \left(c \cdot a\right) \cdot 4} + \left(-b\right)}{a \cdot 2}\\ \mathbf{elif}\;b \le 3.0304262084228798 \cdot 10^{+63}:\\ \;\;\;\;\frac{\frac{\left(c \cdot a\right) \cdot 4}{a \cdot 2}}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(a \cdot 4\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.7
Herbie8.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.8021396801207425e+125

    1. Initial program 50.9

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

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

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

    if -4.8021396801207425e+125 < b < 1.13066952980576e-152

    1. Initial program 10.9

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

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

    if 1.13066952980576e-152 < b < 3.0304262084228798e+63

    1. Initial program 37.3

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

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

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

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

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

    if 3.0304262084228798e+63 < b

    1. Initial program 56.5

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -4.8021396801207425 \cdot 10^{+125}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 1.13066952980576 \cdot 10^{-152}:\\ \;\;\;\;\frac{\sqrt{{b}^{2} - \left(c \cdot a\right) \cdot 4} + \left(-b\right)}{a \cdot 2}\\ \mathbf{elif}\;b \le 3.0304262084228798 \cdot 10^{+63}:\\ \;\;\;\;\frac{\frac{\left(c \cdot a\right) \cdot 4}{a \cdot 2}}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2019016 
(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: 24.1s)Debug log

sample176.0ms

Algorithm
intervals
Results
378×(pre true 80)
187×(body real 80)
93×(body nan 80)
36×(body real 2560)
30×(body real 1280)
16×(body real 640)
(body real 160)
(body real 320)
(body real 5120)

simplify67.0ms

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

prune11.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 35.0b

localize34.0ms

Local error

Found 4 expressions with local error:

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

rewrite57.0ms

Algorithm
rewrite-expression-head
Rules
13×*-un-lft-identity
add-log-exp
add-sqr-sqrt
add-cube-cbrt
add-exp-log
add-cbrt-cube
associate-/l*
times-frac
pow1
distribute-lft-out
sqrt-prod
associate-/l/
flip--
flip-+
associate-+l-
sqrt-div
flip3--
flip3-+
neg-sub0
div-inv
div-exp
div-sub
diff-log
pow1/2
frac-2neg
sub-neg
sum-log
associate-/r*
clear-num
rem-sqrt-square
+-commutative
cbrt-undiv
Counts
4 → 63
Calls
4 calls:
Slowest
36.0ms
(/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a))
12.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
78.0ms
(/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a))
72.0ms
(+ (- b) (sqrt (- (* b b) (* (* 4 a) c))))
45.0ms
(- (* b b) (* (* 4 a) c))
42.0ms
(sqrt (- (* b b) (* (* 4 a) c)))

simplify2.6s

Counts
36 → 75
Calls
36 calls:
Slowest
452.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
289.0ms
(- (* (- b) (- b)) (* (sqrt (- (* b b) (* (* 4 a) c))) (sqrt (- (* b b) (* (* 4 a) c)))))
244.0ms
(+ (pow (- b) 3) (pow (sqrt (- (* b b) (* (* 4 a) c))) 3))
204.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* 4 a) c) (* (* 4 a) c))))
173.0ms
(/ (* (* (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (+ (- b) (sqrt (- (* b b) (* (* 4 a) c))))) (+ (- b) (sqrt (- (* b b) (* (* 4 a) c))))) (* (* (* 2 a) (* 2 a)) (* 2 a)))

prune843.0ms

Pruning

8 alts after pruning (8 fresh and 0 done)

Merged error: 5.2b

localize28.0ms

Local error

Found 4 expressions with local error:

23.2b
(sqrt (- (* b b) (* (* 4 a) c)))
16.3b
(/ (* 4 (* c a)) (* (* 2 a) (- (- b) (sqrt (- (* b b) (* (* 4 a) c))))))
1.2b
(- (- b) (sqrt (- (* b b) (* (* 4 a) c))))
1.2b
(- (* b b) (* (* 4 a) c))

rewrite45.0ms

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

series310.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
157.0ms
(/ (* 4 (* c a)) (* (* 2 a) (- (- b) (sqrt (- (* b b) (* (* 4 a) c))))))
66.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
59.0ms
(- (- b) (sqrt (- (* b b) (* (* 4 a) c))))
27.0ms
(- (* b b) (* (* 4 a) c))

simplify4.4s

Counts
34 → 73
Calls
34 calls:
Slowest
1.2s
(/ (* (* (* 4 (* c a)) (* 4 (* c a))) (* 4 (* c 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)))))))
784.0ms
(/ (* (* (* 4 (* c a)) (* 4 (* c a))) (* 4 (* c 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)))))))
506.0ms
(+ (* (- b) (- b)) (+ (* (sqrt (- (* b b) (* (* 4 a) c))) (sqrt (- (* b b) (* (* 4 a) c)))) (* (- b) (sqrt (- (* b b) (* (* 4 a) c))))))
402.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
177.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* 4 a) c) (* (* 4 a) c))))

prune877.0ms

Pruning

7 alts after pruning (7 fresh and 0 done)

Merged error: 5.2b

localize14.0ms

Local error

Found 4 expressions with local error:

23.2b
(sqrt (- (* b b) (* (* 4 a) c)))
13.9b
(/ (* 4 (* c a)) (* 2 a))
1.2b
(- (- b) (sqrt (- (* b b) (* (* 4 a) c))))
1.2b
(- (* b b) (* (* 4 a) c))

rewrite33.0ms

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

series179.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
69.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
61.0ms
(- (- b) (sqrt (- (* b b) (* (* 4 a) c))))
41.0ms
(- (* b b) (* (* 4 a) c))
8.0ms
(/ (* 4 (* c a)) (* 2 a))

simplify2.8s

Counts
29 → 69
Calls
29 calls:
Slowest
828.0ms
(/ (* (* (* 4 (* c a)) (* 4 (* c a))) (* 4 (* c a))) (* (* (* 2 a) (* 2 a)) (* 2 a)))
450.0ms
(- (log (* 4 (* c a))) (log (* 2 a)))
423.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
189.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* 4 a) c) (* (* 4 a) c))))
137.0ms
(- b (* 2 (/ (* a c) b)))

prune746.0ms

Pruning

7 alts after pruning (6 fresh and 1 done)

Merged error: 5.2b

localize20.0ms

Local error

Found 4 expressions with local error:

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

rewrite50.0ms

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

series215.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
80.0ms
(/ (+ (- b) (sqrt (- (pow b 2) (* 4 (* a c))))) (* 2 a))
68.0ms
(+ (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))
41.0ms
(sqrt (- (pow b 2) (* 4 (* a c))))
26.0ms
(- (pow b 2) (* 4 (* a c)))

simplify3.8s

Counts
36 → 75
Calls
36 calls:
Slowest
1.1s
(- (* (- b) (- b)) (* (sqrt (- (pow b 2) (* 4 (* a c)))) (sqrt (- (pow b 2) (* 4 (* a c))))))
674.0ms
(+ (pow (- b) 3) (pow (sqrt (- (pow b 2) (* 4 (* a c)))) 3))
439.0ms
(sqrt (- (pow (pow b 2) 3) (pow (* 4 (* a c)) 3)))
174.0ms
(sqrt (- (* (pow b 2) (pow b 2)) (* (* 4 (* a c)) (* 4 (* a c)))))
128.0ms
(/ (* (* (+ (- b) (sqrt (- (pow b 2) (* 4 (* a c))))) (+ (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))) (+ (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))) (* (* (* 2 a) (* 2 a)) (* 2 a)))

prune945.0ms

Pruning

7 alts after pruning (5 fresh and 2 done)

Merged error: 5.2b

regimes345.0ms

Accuracy

88.4% (3.0b remaining)

Error of 8.7b against oracle of 5.7b and baseline of 31.9b

bsearch646.0ms

end0.0ms

sample4.6s

Algorithm
intervals
Results
11500×(pre true 80)
5932×(body real 80)
2746×(body nan 80)
1013×(body real 2560)
888×(body real 1280)
455×(body real 640)
223×(body real 320)
126×(body real 160)
117×(body real 5120)