Average Error: 33.7 → 7.3
Time: 41.4s
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.149882403051541 \cdot 10^{+52}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le -3.420898477294382 \cdot 10^{-305}:\\ \;\;\;\;\frac{\sqrt{{b}^{2} - \left(c \cdot a\right) \cdot 4} - b}{a \cdot 2}\\ \mathbf{elif}\;b \le 1.8709491320040642 \cdot 10^{+68}:\\ \;\;\;\;\frac{c \cdot -2}{b + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\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.7
Target20.8
Herbie7.3
\[\begin{array}{l} \mathbf{if}\;b \lt 0:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{a \cdot \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.149882403051541e+52

    1. Initial program 38.4

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

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

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

    if -2.149882403051541e+52 < b < -3.420898477294382e-305

    1. Initial program 10.1

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

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

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

    if -3.420898477294382e-305 < b < 1.8709491320040642e+68

    1. Initial program 30.3

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

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2 \cdot a}}\]
    3. Using strategy rm
    4. Applied div-inv30.3

      \[\leadsto \color{blue}{\left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b\right) \cdot \frac{1}{2 \cdot a}}\]
    5. Using strategy rm
    6. Applied flip--30.4

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

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

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

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

    if 1.8709491320040642e+68 < b

    1. Initial program 56.9

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -2.149882403051541 \cdot 10^{+52}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le -3.420898477294382 \cdot 10^{-305}:\\ \;\;\;\;\frac{\sqrt{{b}^{2} - \left(c \cdot a\right) \cdot 4} - b}{a \cdot 2}\\ \mathbf{elif}\;b \le 1.8709491320040642 \cdot 10^{+68}:\\ \;\;\;\;\frac{c \cdot -2}{b + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 1137770271 
(FPCore (a b c)
  :name "quadp (p42, positive)"

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

sample349.0ms

Algorithm
intervals
Results
39×93.0ms(body real 2560)
189×71.0ms(body real 80)
28×49.0ms(body real 1280)
93×32.0ms(body nan 80)
366×19.0ms(pre true 80)
11.0ms(body real 640)
9.0ms(body real 5120)
6.0ms(body real 320)
0.0ms(body real 160)

simplify205.0ms

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

prune40.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 33.7b

localize140.0ms

Local error

Found 4 expressions with local error:

23.3b
(sqrt (- (* b b) (* (* 4 a) c)))
0.6b
(- (sqrt (- (* b b) (* (* 4 a) c))) b)
0.4b
(- (* b b) (* (* 4 a) c))
0.1b
(/ (- (sqrt (- (* b b) (* (* 4 a) c))) b) (* 2 a))

rewrite125.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
54.0ms
(/ (- (sqrt (- (* b b) (* (* 4 a) c))) b) (* 2 a))
53.0ms
(- (sqrt (- (* b b) (* (* 4 a) c))) b)
11.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
6.0ms
(- (* b b) (* (* 4 a) c))

series433.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
157.0ms
(/ (- (sqrt (- (* b b) (* (* 4 a) c))) b) (* 2 a))
118.0ms
(- (sqrt (- (* b b) (* (* 4 a) c))) b)
86.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
72.0ms
(- (* b b) (* (* 4 a) c))

simplify4.4s

Counts
32 → 71
Calls
32 calls:
Slowest
761.0ms
(- (* (sqrt (- (* b b) (* (* 4 a) c))) (sqrt (- (* b b) (* (* 4 a) c)))) (* b b))
669.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
503.0ms
(- (pow (sqrt (- (* b b) (* (* 4 a) c))) 3) (pow b 3))
265.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* 4 a) c) (* (* 4 a) c))))
240.0ms
(- b (* 2 (/ (* a c) b)))

prune1.7s

Pruning

10 alts after pruning (10 fresh and 0 done)

Merged error: 6.7b

localize59.0ms

Local error

Found 4 expressions with local error:

23.3b
(sqrt (- (pow b 2) (* 4 (* a c))))
0.6b
(- (sqrt (- (pow b 2) (* 4 (* a c)))) b)
0.4b
(- (pow b 2) (* 4 (* a c)))
0.1b
(/ (- (sqrt (- (pow b 2) (* 4 (* a c)))) b) (* 2 a))

rewrite125.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
71.0ms
(/ (- (sqrt (- (pow b 2) (* 4 (* a c)))) b) (* 2 a))
37.0ms
(- (sqrt (- (pow b 2) (* 4 (* a c)))) b)
8.0ms
(- (pow b 2) (* 4 (* a c)))
7.0ms
(sqrt (- (pow b 2) (* 4 (* a c))))

series360.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
122.0ms
(/ (- (sqrt (- (pow b 2) (* 4 (* a c)))) b) (* 2 a))
93.0ms
(- (sqrt (- (pow b 2) (* 4 (* a c)))) b)
90.0ms
(sqrt (- (pow b 2) (* 4 (* a c))))
55.0ms
(- (pow b 2) (* 4 (* a c)))

simplify4.5s

Counts
32 → 71
Calls
32 calls:
Slowest
857.0ms
(sqrt (- (pow (pow b 2) 3) (pow (* 4 (* a c)) 3)))
754.0ms
(- (* (sqrt (- (pow b 2) (* 4 (* a c)))) (sqrt (- (pow b 2) (* 4 (* a c))))) (* b b))
533.0ms
(- (pow (sqrt (- (pow b 2) (* 4 (* a c)))) 3) (pow b 3))
293.0ms
(sqrt (- (* (pow b 2) (pow b 2)) (* (* 4 (* a c)) (* 4 (* a c)))))
224.0ms
(- b (* 2 (/ (* a c) b)))

prune1.5s

Pruning

9 alts after pruning (8 fresh and 1 done)

Merged error: 6.7b

localize19.0ms

Local error

Found 4 expressions with local error:

23.3b
(sqrt (- (* b b) (* (* 4 a) c)))
0.6b
(- (sqrt (- (* b b) (* (* 4 a) c))) b)
0.4b
(- (* b b) (* (* 4 a) c))
0.2b
(* (- (sqrt (- (* b b) (* (* 4 a) c))) b) (/ 1 (* 2 a)))

rewrite124.0ms

Algorithm
rewrite-expression-head
Rules
add-exp-log
add-sqr-sqrt
add-cube-cbrt
*-un-lft-identity
add-log-exp
add-cbrt-cube
pow1
flip--
flip3--
associate-*r*
sqrt-prod
associate-*l*
prod-exp
associate-*l/
sqrt-div
sub-neg
frac-times
div-inv
cbrt-unprod
*-commutative
un-div-inv
associate-*r/
pow-prod-down
diff-log
pow1/2
rec-exp
rem-sqrt-square
Counts
4 → 62
Calls
4 calls:
Slowest
69.0ms
(* (- (sqrt (- (* b b) (* (* 4 a) c))) b) (/ 1 (* 2 a)))
37.0ms
(- (sqrt (- (* b b) (* (* 4 a) c))) b)
10.0ms
(- (* b b) (* (* 4 a) c))
5.0ms
(sqrt (- (* b b) (* (* 4 a) c)))

series369.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
143.0ms
(* (- (sqrt (- (* b b) (* (* 4 a) c))) b) (/ 1 (* 2 a)))
91.0ms
(- (sqrt (- (* b b) (* (* 4 a) c))) b)
82.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
52.0ms
(- (* b b) (* (* 4 a) c))

simplify5.3s

Counts
37 → 74
Calls
37 calls:
Slowest
895.0ms
(* (- (* (sqrt (- (* b b) (* (* 4 a) c))) (sqrt (- (* b b) (* (* 4 a) c)))) (* b b)) 1)
574.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
484.0ms
(* (- (* (sqrt (- (* b b) (* (* 4 a) c))) (sqrt (- (* b b) (* (* 4 a) c)))) (* b b)) (/ 1 (* 2 a)))
362.0ms
(* (- (sqrt (- (* b b) (* (* 4 a) c))) b) (/ 1 (* 2 a)))
346.0ms
(* (- (pow (sqrt (- (* b b) (* (* 4 a) c))) 3) (pow b 3)) 1)

prune1.7s

Pruning

8 alts after pruning (6 fresh and 2 done)

Merged error: 6.7b

localize51.0ms

Local error

Found 4 expressions with local error:

23.3b
(sqrt (- (* b b) (* (* 4 a) c)))
15.1b
(/ (+ (* -4 (* a c)) 0) (/ a 1/2))
0.6b
(+ (sqrt (- (* b b) (* (* 4 a) c))) b)
0.4b
(- (* b b) (* (* 4 a) c))

rewrite59.0ms

Algorithm
rewrite-expression-head
Rules
15×add-sqr-sqrt
14×add-cube-cbrt
14×*-un-lft-identity
12×times-frac
add-log-exp
add-exp-log
add-cbrt-cube
div-inv
associate-/r*
pow1
associate-/l*
sqrt-prod
associate-/l/
flip--
flip-+
sqrt-div
flip3--
flip3-+
associate-/r/
div-exp
diff-log
pow1/2
frac-2neg
sub-neg
clear-num
rem-sqrt-square
+-commutative
cbrt-undiv
Counts
4 → 70
Calls
4 calls:
Slowest
23.0ms
(+ (sqrt (- (* b b) (* (* 4 a) c))) b)
21.0ms
(/ (+ (* -4 (* a c)) 0) (/ a 1/2))
7.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
5.0ms
(- (* b b) (* (* 4 a) c))

series244.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
92.0ms
(+ (sqrt (- (* b b) (* (* 4 a) c))) b)
85.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
53.0ms
(- (* b b) (* (* 4 a) c))
14.0ms
(/ (+ (* -4 (* a c)) 0) (/ a 1/2))

simplify6.1s

Counts
53 → 82
Calls
53 calls:
Slowest
1.2s
(/ (+ (* -4 (* a c)) 0) (/ a 1/2))
758.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
553.0ms
(- (log (+ (* -4 (* a c)) 0)) (log (/ a 1/2)))
548.0ms
(/ (+ (* -4 (* a c)) 0) (/ 1 1/2))
327.0ms
(- (* (* -4 (* a c)) (* -4 (* a c))) (* 0 0))

prune1.9s

Pruning

8 alts after pruning (6 fresh and 2 done)

Merged error: 6.7b

regimes527.0ms

Accuracy

93.9% (1.4b remaining)

Error of 7.3b against oracle of 5.8b and baseline of 28.9b

bsearch854.0ms

end0.0ms

sample8.1s

Algorithm
intervals
Results
1067×2.3s(body real 2560)
905×1.7s(body real 1280)
5865×1.6s(body real 80)
2946×711.0ms(body nan 80)
486×512.0ms(body real 640)
11702×419.0ms(pre true 80)
221×200.0ms(body real 320)
111×198.0ms(body real 5120)
101×50.0ms(body real 160)