Average Error: 33.4 → 7.9
Time: 32.5s
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 -3.9662470494954583 \cdot 10^{+148}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 2.2500462861079674 \cdot 10^{-93}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b}{a \cdot 2}\\ \mathbf{elif}\;b \le 1.6889965443539738 \cdot 10^{+108}:\\ \;\;\;\;\frac{c \cdot -4}{\frac{\left(\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} + b\right) \cdot \left(a \cdot 2\right)}{a}}\\ \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.4
Herbie7.9
\[\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 < -3.9662470494954583e+148

    1. Initial program 58.7

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

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

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

    if -3.9662470494954583e+148 < b < 2.2500462861079674e-93

    1. Initial program 11.4

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

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

    if 2.2500462861079674e-93 < b < 1.6889965443539738e+108

    1. Initial program 42.7

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

      \[\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 flip--42.7

      \[\leadsto \frac{\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}}}{2 \cdot a}\]
    5. Applied associate-/l/45.2

      \[\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}{\left(2 \cdot a\right) \cdot \left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + b\right)}}\]
    6. Simplified16.7

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

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

    if 1.6889965443539738e+108 < b

    1. Initial program 59.4

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Simplified59.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 2.3

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -3.9662470494954583 \cdot 10^{+148}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 2.2500462861079674 \cdot 10^{-93}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b}{a \cdot 2}\\ \mathbf{elif}\;b \le 1.6889965443539738 \cdot 10^{+108}:\\ \;\;\;\;\frac{c \cdot -4}{\frac{\left(\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} + b\right) \cdot \left(a \cdot 2\right)}{a}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Reproduce

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

sample192.0ms

Algorithm
intervals
Results
46.0ms199×body80valid
42.0ms30×body2560valid
29.0ms25×body1280valid
18.0ms84×body80nan
12.0ms13×body640valid
5.0msbody320valid
3.0msbody5120valid
3.0msbody160valid

simplify119.0ms

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

prune23.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 34.1b

localize66.0ms

Local error

Found 4 expressions with local error:

24.4b
(sqrt (- (* b b) (* (* 4 a) c)))
1.8b
(- (sqrt (- (* b b) (* (* 4 a) c))) b)
1.4b
(- (* b b) (* (* 4 a) c))
0.1b
(/ (- (sqrt (- (* b b) (* (* 4 a) c))) b) (* 2 a))

rewrite85.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
49.0ms
(/ (- (sqrt (- (* b b) (* (* 4 a) c))) b) (* 2 a))
25.0ms
(- (sqrt (- (* b b) (* (* 4 a) c))) b)
5.0ms
(- (* b b) (* (* 4 a) c))
5.0ms
(sqrt (- (* b b) (* (* 4 a) c)))

series339.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
116.0ms
(/ (- (sqrt (- (* b b) (* (* 4 a) c))) b) (* 2 a))
89.0ms
(- (sqrt (- (* b b) (* (* 4 a) c))) b)
83.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
51.0ms
(- (* b b) (* (* 4 a) c))

simplify3.2s

Counts
32 → 71
Calls
32 calls:
Slowest
549.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
486.0ms
(- (* (sqrt (- (* b b) (* (* 4 a) c))) (sqrt (- (* b b) (* (* 4 a) c)))) (* b b))
276.0ms
(- (pow (sqrt (- (* b b) (* (* 4 a) c))) 3) (pow b 3))
220.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* 4 a) c) (* (* 4 a) c))))
180.0ms
(- b (* 2 (/ (* a c) b)))

prune1.2s

Pruning

7 alts after pruning (6 fresh and 1 done)

Merged error: 4.7b

localize24.0ms

Local error

Found 4 expressions with local error:

24.4b
(sqrt (- (* b b) (* (* 4 a) c)))
24.4b
(sqrt (- (* b b) (* (* 4 a) c)))
1.8b
(- (sqrt (- (* b b) (* (* 4 a) c))) b)
1.8b
(- (sqrt (- (* b b) (* (* 4 a) c))) b)

rewrite64.0ms

Algorithm
rewrite-expression-head
Rules
add-sqr-sqrt
sqrt-prod
add-cube-cbrt
*-un-lft-identity
add-log-exp
flip--
add-exp-log
sqrt-div
add-cbrt-cube
flip3--
pow1
pow1/2
sub-neg
rem-sqrt-square
Counts
4 → 50
Calls
4 calls:
Slowest
28.0ms
(- (sqrt (- (* b b) (* (* 4 a) c))) b)
25.0ms
(- (sqrt (- (* b b) (* (* 4 a) c))) b)
5.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
5.0ms
(sqrt (- (* b b) (* (* 4 a) c)))

series339.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
89.0ms
(- (sqrt (- (* b b) (* (* 4 a) c))) b)
89.0ms
(- (sqrt (- (* b b) (* (* 4 a) c))) b)
81.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
80.0ms
(sqrt (- (* b b) (* (* 4 a) c)))

simplify2.8s

Counts
24 → 62
Calls
24 calls:
Slowest
551.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
551.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
217.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* 4 a) c) (* (* 4 a) c))))
212.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* 4 a) c) (* (* 4 a) c))))
181.0ms
(- b (* 2 (/ (* a c) b)))

prune1.3s

Pruning

7 alts after pruning (5 fresh and 2 done)

Merged error: 4.7b

localize44.0ms

Local error

Found 4 expressions with local error:

25.2b
(cbrt (- (* b b) (* (* 4 a) c)))
25.2b
(cbrt (- (* b b) (* (* 4 a) c)))
10.8b
(- (* (fabs (cbrt (- (* b b) (* (* 4 a) c)))) (sqrt (cbrt (- (* b b) (* (* 4 a) c))))) b)
1.4b
(- (* b b) (* (* 4 a) c))

rewrite31.0ms

Algorithm
rewrite-expression-head
Rules
add-log-exp
add-cube-cbrt
*-un-lft-identity
add-sqr-sqrt
cbrt-prod
flip--
add-exp-log
add-cbrt-cube
flip3--
cbrt-div
pow1
pow1/3
sub-neg
diff-log
Counts
4 → 49
Calls
4 calls:
Slowest
18.0ms
(- (* (fabs (cbrt (- (* b b) (* (* 4 a) c)))) (sqrt (cbrt (- (* b b) (* (* 4 a) c))))) b)
5.0ms
(- (* b b) (* (* 4 a) c))
3.0ms
(cbrt (- (* b b) (* (* 4 a) c)))
3.0ms
(cbrt (- (* b b) (* (* 4 a) c)))

series504.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
164.0ms
(cbrt (- (* b b) (* (* 4 a) c)))
157.0ms
(cbrt (- (* b b) (* (* 4 a) c)))
131.0ms
(- (* (fabs (cbrt (- (* b b) (* (* 4 a) c)))) (sqrt (cbrt (- (* b b) (* (* 4 a) c))))) b)
52.0ms
(- (* b b) (* (* 4 a) c))

simplify3.8s

Counts
23 → 61
Calls
23 calls:
Slowest
949.0ms
(cbrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
572.0ms
(cbrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
439.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))))
393.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))))
323.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)))))))))))

prune1.4s

Pruning

7 alts after pruning (4 fresh and 3 done)

Merged error: 4.7b

localize37.0ms

Local error

Found 4 expressions with local error:

24.4b
(sqrt (- (* b b) (* (* 4 a) c)))
15.7b
(/ (* (* -4 c) a) (* (* 2 a) (+ (sqrt (- (* b b) (* (* 4 a) c))) b)))
1.4b
(- (* b b) (* (* 4 a) c))
0.6b
(+ (sqrt (- (* b b) (* (* 4 a) c))) b)

rewrite62.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
33.0ms
(/ (* (* -4 c) a) (* (* 2 a) (+ (sqrt (- (* b b) (* (* 4 a) c))) b)))
18.0ms
(+ (sqrt (- (* b b) (* (* 4 a) c))) b)
5.0ms
(- (* b b) (* (* 4 a) c))
5.0ms
(sqrt (- (* b b) (* (* 4 a) c)))

series450.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
221.0ms
(/ (* (* -4 c) a) (* (* 2 a) (+ (sqrt (- (* b b) (* (* 4 a) c))) b)))
95.0ms
(+ (sqrt (- (* b b) (* (* 4 a) c))) b)
81.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
53.0ms
(- (* b b) (* (* 4 a) c))

simplify5.1s

Counts
29 → 67
Calls
29 calls:
Slowest
1.2s
(/ (* (* (* (* -4 c) a) (* (* -4 c) a)) (* (* -4 c) a)) (* (* (* (* 2 a) (* 2 a)) (* 2 a)) (* (* (+ (sqrt (- (* b b) (* (* 4 a) c))) b) (+ (sqrt (- (* b b) (* (* 4 a) c))) b)) (+ (sqrt (- (* b b) (* (* 4 a) c))) b))))
1.1s
(/ (* (* (* (* -4 c) a) (* (* -4 c) a)) (* (* -4 c) a)) (* (* (* (* 2 a) (+ (sqrt (- (* b b) (* (* 4 a) c))) b)) (* (* 2 a) (+ (sqrt (- (* b b) (* (* 4 a) c))) b))) (* (* 2 a) (+ (sqrt (- (* b b) (* (* 4 a) c))) b))))
552.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
420.0ms
(+ (* (sqrt (- (* b b) (* (* 4 a) c))) (sqrt (- (* b b) (* (* 4 a) c)))) (- (* b b) (* (sqrt (- (* b b) (* (* 4 a) c))) b)))
230.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* 4 a) c) (* (* 4 a) c))))

prune1.2s

Pruning

8 alts after pruning (4 fresh and 4 done)

Merged error: 4.7b

regimes439.0ms

Accuracy

90.7% (2.6b remaining)

Error of 7.9b against oracle of 5.2b and baseline of 33.4b

bsearch885.0ms

end0.0ms

sample6.8s

Algorithm
intervals
Results
2.0s5854×body80valid
1.7s1062×body2560valid
1.2s906×body1280valid
699.0ms2978×body80nan
446.0ms451×body640valid
271.0ms262×body320valid
182.0ms94×body5120valid
56.0ms122×body160valid