Average Error: 33.7 → 8.7
Time: 27.7s
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 -4799886.458194201:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le -2.0171640414531174 \cdot 10^{-134}:\\ \;\;\;\;\frac{a}{\sqrt{c \cdot \left(-4 \cdot a\right) + b \cdot b} - b} \cdot \frac{\frac{c}{\frac{1}{2}}}{a}\\ \mathbf{elif}\;b \le 6.207549349185736 \cdot 10^{+126}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a \cdot 2}\\ \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.7
Target20.3
Herbie8.7
\[\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 < -4799886.458194201

    1. Initial program 55.7

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

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

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

    if -4799886.458194201 < b < -2.0171640414531174e-134

    1. Initial program 35.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--35.2

      \[\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.4

      \[\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. Simplified23.6

      \[\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 times-frac19.2

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

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

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

    if -2.0171640414531174e-134 < b < 6.207549349185736e+126

    1. Initial program 11.1

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

    if 6.207549349185736e+126 < b

    1. Initial program 50.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--61.9

      \[\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/62.1

      \[\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. Simplified62.3

      \[\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 2.9

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -4799886.458194201:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le -2.0171640414531174 \cdot 10^{-134}:\\ \;\;\;\;\frac{a}{\sqrt{c \cdot \left(-4 \cdot a\right) + b \cdot b} - b} \cdot \frac{\frac{c}{\frac{1}{2}}}{a}\\ \mathbf{elif}\;b \le 6.207549349185736 \cdot 10^{+126}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;-\frac{b}{a}\\ \end{array}\]

Reproduce

herbie shell --seed 323378853 
(FPCore (a b c)
  :name "quadm (p42, negative)"

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

sample245.0ms

Algorithm
intervals
Results
61.0ms38×body2560valid
48.0ms37×body1280valid
43.0ms168×body80valid
21.0ms21×body640valid
19.0ms84×body80nan
5.0msbody320valid
4.0msbody5120valid
2.0msbody160valid

simplify166.0ms

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

prune17.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 35.4b

localize77.0ms

Local error

Found 4 expressions with local error:

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

rewrite67.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
40.0ms
(/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a))
15.0ms
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
5.0ms
(- (* b b) (* 4 (* a c)))
5.0ms
(sqrt (- (* b b) (* 4 (* a c))))

series356.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
112.0ms
(/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a))
96.0ms
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
92.0ms
(sqrt (- (* b b) (* 4 (* a c))))
56.0ms
(- (* b b) (* 4 (* a c)))

simplify3.9s

Counts
46 → 82
Calls
46 calls:
Slowest
443.0ms
(sqrt (- (pow (* b b) 3) (pow (* 4 (* a c)) 3)))
383.0ms
(- (* (- b) (- b)) (* (sqrt (- (* b b) (* 4 (* a c)))) (sqrt (- (* b b) (* 4 (* a c))))))
341.0ms
(- (pow (- b) 3) (pow (sqrt (- (* b b) (* 4 (* a c)))) 3))
239.0ms
(sqrt (- (* (* b b) (* b b)) (* (* 4 (* a c)) (* 4 (* a c)))))
185.0ms
(- b (* 2 (/ (* a c) b)))

prune1.5s

Pruning

8 alts after pruning (7 fresh and 1 done)

Merged error: 4.8b

localize37.0ms

Local error

Found 4 expressions with local error:

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

rewrite50.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
26.0ms
(/ (* (* c 4) a) (* (* 2 a) (+ (- b) (sqrt (- (* b b) (* 4 (* a c)))))))
13.0ms
(+ (- b) (sqrt (- (* b b) (* 4 (* a c)))))
5.0ms
(- (* b b) (* 4 (* a c)))
5.0ms
(sqrt (- (* b b) (* 4 (* a c))))

series458.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
234.0ms
(/ (* (* c 4) a) (* (* 2 a) (+ (- b) (sqrt (- (* b b) (* 4 (* a c)))))))
88.0ms
(+ (- b) (sqrt (- (* b b) (* 4 (* a c)))))
85.0ms
(sqrt (- (* b b) (* 4 (* a c))))
51.0ms
(- (* b b) (* 4 (* a c)))

simplify4.8s

Counts
31 → 70
Calls
31 calls:
Slowest
1.0s
(/ (* (* (* (* 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))))))))
1.0s
(/ (* (* (* (* 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))))))))
461.0ms
(+ (* (- b) (- b)) (- (* (sqrt (- (* b b) (* 4 (* a c)))) (sqrt (- (* b b) (* 4 (* a c))))) (* (- b) (sqrt (- (* b b) (* 4 (* a c)))))))
440.0ms
(sqrt (- (pow (* b b) 3) (pow (* 4 (* a c)) 3)))
238.0ms
(sqrt (- (* (* b b) (* b b)) (* (* 4 (* a c)) (* 4 (* a c)))))

prune1.3s

Pruning

7 alts after pruning (5 fresh and 2 done)

Merged error: 4.7b

localize49.0ms

Local error

Found 4 expressions with local error:

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

rewrite50.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
26.0ms
(- (sqrt (+ (* -4 (* a c)) (* b b))) b)
12.0ms
(/ (* (* c 4) a) (* 2 a))
7.0ms
(+ (* -4 (* a c)) (* b b))
5.0ms
(sqrt (+ (* -4 (* a c)) (* b b)))

series248.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
93.0ms
(- (sqrt (+ (* -4 (* a c)) (* b b))) b)
83.0ms
(sqrt (+ (* -4 (* a c)) (* b b)))
62.0ms
(+ (* -4 (* a c)) (* b b))
10.0ms
(/ (* (* c 4) a) (* 2 a))

simplify2.7s

Counts
24 → 63
Calls
24 calls:
Slowest
990.0ms
(/ (* (* (* (* c 4) a) (* (* c 4) a)) (* (* c 4) a)) (* (* (* 2 a) (* 2 a)) (* 2 a)))
900.0ms
(- (log (* (* c 4) a)) (log (* 2 a)))
316.0ms
(sqrt (- (* (* -4 (* a c)) (* -4 (* a c))) (* (* b b) (* b b))))
249.0ms
(sqrt (+ (pow (* -4 (* a c)) 3) (pow (* b b) 3)))
53.0ms
(- (pow b 2) (* 4 (* a c)))

prune1.2s

Pruning

7 alts after pruning (4 fresh and 3 done)

Merged error: 4.7b

localize13.0ms

Local error

Found 0 expressions with local error:

rewrite0.0ms

Algorithm
rewrite-expression-head
Rules
Counts
0 → 0
Calls
0 calls:
Slowest

series0.0ms

Counts
0 → 0
Calls
0 calls:
Slowest

simplify0.0ms

Counts
0 → 0
Calls
0 calls:
Slowest

prune1.0ms

Pruning

7 alts after pruning (3 fresh and 4 done)

Merged error: 4.7b

regimes566.0ms

Accuracy

87% (3.4b remaining)

Error of 8.7b against oracle of 5.2b and baseline of 31.5b

bsearch1.4s

end0.0ms

sample7.0s

Algorithm
intervals
Results
2.1s1078×body2560valid
1.5s5762×body80valid
1.3s927×body1280valid
700.0ms2974×body80nan
537.0ms483×body640valid
264.0ms117×body5120valid
177.0ms250×body320valid
58.0ms124×body160valid