Average Error: 33.5 → 9.2
Time: 21.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 -2.1404970644413445 \cdot 10^{+42}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le -4.645504089248097 \cdot 10^{-163}:\\ \;\;\;\;\frac{\frac{\left(4 \cdot c\right) \cdot a}{2 \cdot a}}{\sqrt{\sqrt{-4 \cdot \left(a \cdot c\right) + b \cdot b}} \cdot \sqrt{\sqrt{-4 \cdot \left(a \cdot c\right) + b \cdot b}} - b}\\ \mathbf{elif}\;b \le 1.501809486178084 \cdot 10^{+23}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{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

Target

Original33.5
Target20.3
Herbie9.2
\[\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 < -2.1404970644413445e+42

    1. Initial program 56.5

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

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

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

    if -2.1404970644413445e+42 < b < -4.645504089248097e-163

    1. Initial program 36.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--36.3

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

      \[\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. Simplified21.5

      \[\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 associate-/r*16.7

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

      \[\leadsto \frac{\frac{\left(c \cdot 4\right) \cdot a}{2 \cdot a}}{\color{blue}{\sqrt{-4 \cdot \left(a \cdot c\right) + b \cdot b} - b}}\]
    9. Using strategy rm
    10. Applied add-sqr-sqrt16.8

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

    if -4.645504089248097e-163 < b < 1.501809486178084e+23

    1. Initial program 11.9

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

    if 1.501809486178084e+23 < b

    1. Initial program 32.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--59.1

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

      \[\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. Simplified60.1

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -2.1404970644413445 \cdot 10^{+42}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le -4.645504089248097 \cdot 10^{-163}:\\ \;\;\;\;\frac{\frac{\left(4 \cdot c\right) \cdot a}{2 \cdot a}}{\sqrt{\sqrt{-4 \cdot \left(a \cdot c\right) + b \cdot b}} \cdot \sqrt{\sqrt{-4 \cdot \left(a \cdot c\right) + b \cdot b}} - b}\\ \mathbf{elif}\;b \le 1.501809486178084 \cdot 10^{+23}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a}\\ \end{array}\]

Reproduce

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

sample122.0ms

Algorithm
intervals
Results
27.0ms32×body2560valid
25.0ms188×body80valid
16.0ms24×body1280valid
15.0ms96×body80nan
9.0ms17×body640valid
5.0msbody5120valid
4.0msbody320valid
2.0msbody160valid

simplify123.0ms

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

prune7.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 33.7b

localize450.0ms

Local error

Found 4 expressions with local error:

22.4b
(sqrt (- (* b b) (* 4 (* a c))))
1.1b
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
0.4b
(- (* b b) (* 4 (* a c)))
0.1b
(/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a))

rewrite37.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
16.0ms
(/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a))
13.0ms
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
4.0ms
(- (* b b) (* 4 (* a c)))
2.0ms
(sqrt (- (* b b) (* 4 (* a c))))

series229.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
73.0ms
(/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a))
68.0ms
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
45.0ms
(sqrt (- (* b b) (* 4 (* a c))))
43.0ms
(- (* b b) (* 4 (* a c)))

simplify2.6s

Counts
46 → 82
Calls
46 calls:
Slowest
299.0ms
(- (* (- b) (- b)) (* (sqrt (- (* b b) (* 4 (* a c)))) (sqrt (- (* b b) (* 4 (* a c))))))
276.0ms
(sqrt (- (pow (* b b) 3) (pow (* 4 (* a c)) 3)))
228.0ms
(- (pow (- b) 3) (pow (sqrt (- (* b b) (* 4 (* a c)))) 3))
177.0ms
(sqrt (- (* (* b b) (* b b)) (* (* 4 (* a c)) (* 4 (* a c)))))
122.0ms
(- b (* 2 (/ (* a c) b)))

prune1.0s

Pruning

9 alts after pruning (8 fresh and 1 done)

Merged error: 5.5b

localize25.0ms

Local error

Found 4 expressions with local error:

22.4b
(sqrt (- (* b b) (* 4 (* a c))))
14.0b
(/ (* (* c 4) a) (* (* 2 a) (+ (- b) (sqrt (- (* b b) (* 4 (* a c)))))))
2.0b
(+ (- b) (sqrt (- (* b b) (* 4 (* a c)))))
0.4b
(- (* b b) (* 4 (* a c)))

rewrite24.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
12.0ms
(/ (* (* c 4) a) (* (* 2 a) (+ (- b) (sqrt (- (* b b) (* 4 (* a c)))))))
5.0ms
(+ (- b) (sqrt (- (* b b) (* 4 (* a c)))))
4.0ms
(sqrt (- (* b b) (* 4 (* a c))))
2.0ms
(- (* b b) (* 4 (* a c)))

series290.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
139.0ms
(/ (* (* c 4) a) (* (* 2 a) (+ (- b) (sqrt (- (* b b) (* 4 (* a c)))))))
56.0ms
(+ (- b) (sqrt (- (* b b) (* 4 (* a c)))))
54.0ms
(sqrt (- (* b b) (* 4 (* a c))))
41.0ms
(- (* b b) (* 4 (* a c)))

simplify3.4s

Counts
31 → 70
Calls
31 calls:
Slowest
815.0ms
(/ (* (* (* (* 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))))))))
716.0ms
(/ (* (* (* (* 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))))))))
353.0ms
(+ (* (- b) (- b)) (- (* (sqrt (- (* b b) (* 4 (* a c)))) (sqrt (- (* b b) (* 4 (* a c))))) (* (- b) (sqrt (- (* b b) (* 4 (* a c)))))))
279.0ms
(sqrt (- (pow (* b b) 3) (pow (* 4 (* a c)) 3)))
148.0ms
(- (log (* (* c 4) a)) (+ (log (* 2 a)) (log (+ (- b) (sqrt (- (* b b) (* 4 (* a c))))))))

prune676.0ms

Pruning

9 alts after pruning (7 fresh and 2 done)

Merged error: 5.5b

localize17.0ms

Local error

Found 4 expressions with local error:

22.4b
(sqrt (+ (* -4 (* a c)) (* b b)))
13.0b
(/ (* (* c 4) a) (* 2 a))
2.0b
(- (sqrt (+ (* -4 (* a c)) (* b b))) b)
0.4b
(+ (* -4 (* a c)) (* b b))

rewrite38.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
20.0ms
(- (sqrt (+ (* -4 (* a c)) (* b b))) b)
10.0ms
(/ (* (* c 4) a) (* 2 a))
5.0ms
(+ (* -4 (* a c)) (* b b))
2.0ms
(sqrt (+ (* -4 (* a c)) (* b b)))

series192.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
75.0ms
(- (sqrt (+ (* -4 (* a c)) (* b b))) b)
66.0ms
(sqrt (+ (* -4 (* a c)) (* b b)))
43.0ms
(+ (* -4 (* a c)) (* b b))
8.0ms
(/ (* (* c 4) a) (* 2 a))

simplify1.7s

Counts
24 → 63
Calls
24 calls:
Slowest
666.0ms
(/ (* (* (* (* c 4) a) (* (* c 4) a)) (* (* c 4) a)) (* (* (* 2 a) (* 2 a)) (* 2 a)))
569.0ms
(- (log (* (* c 4) a)) (log (* 2 a)))
181.0ms
(sqrt (- (* (* -4 (* a c)) (* -4 (* a c))) (* (* b b) (* b b))))
129.0ms
(sqrt (+ (pow (* -4 (* a c)) 3) (pow (* b b) 3)))
33.0ms
(- (pow b 2) (* 4 (* a c)))

prune733.0ms

Pruning

8 alts after pruning (6 fresh and 2 done)

Merged error: 5.5b

localize14.0ms

Local error

Found 4 expressions with local error:

22.4b
(sqrt (+ (* -4 (* a c)) (* b b)))
22.4b
(sqrt (+ (* -4 (* a c)) (* b b)))
13.0b
(/ (* (* c 4) a) (* 2 a))
9.4b
(- (* (sqrt (sqrt (+ (* -4 (* a c)) (* b b)))) (sqrt (sqrt (+ (* -4 (* a c)) (* b b))))) b)

rewrite24.0ms

Algorithm
rewrite-expression-head
Rules
add-sqr-sqrt
sqrt-prod
add-cube-cbrt
add-exp-log
add-cbrt-cube
*-un-lft-identity
add-log-exp
sqrt-div
pow1
flip-+
pow1/2
flip3-+
rem-sqrt-square
associate-/l*
flip--
div-inv
div-exp
flip3--
times-frac
frac-2neg
sub-neg
associate-/r*
clear-num
cbrt-undiv
Counts
4 → 54
Calls
4 calls:
Slowest
14.0ms
(- (* (sqrt (sqrt (+ (* -4 (* a c)) (* b b)))) (sqrt (sqrt (+ (* -4 (* a c)) (* b b))))) b)
5.0ms
(/ (* (* c 4) a) (* 2 a))
2.0ms
(sqrt (+ (* -4 (* a c)) (* b b)))
2.0ms
(sqrt (+ (* -4 (* a c)) (* b b)))

series171.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
61.0ms
(sqrt (+ (* -4 (* a c)) (* b b)))
52.0ms
(sqrt (+ (* -4 (* a c)) (* b b)))
50.0ms
(- (* (sqrt (sqrt (+ (* -4 (* a c)) (* b b)))) (sqrt (sqrt (+ (* -4 (* a c)) (* b b))))) b)
7.0ms
(/ (* (* c 4) a) (* 2 a))

simplify2.1s

Counts
29 → 66
Calls
29 calls:
Slowest
719.0ms
(/ (* (* (* (* c 4) a) (* (* c 4) a)) (* (* c 4) a)) (* (* (* 2 a) (* 2 a)) (* 2 a)))
593.0ms
(- (log (* (* c 4) a)) (log (* 2 a)))
197.0ms
(sqrt (- (* (* -4 (* a c)) (* -4 (* a c))) (* (* b b) (* b b))))
179.0ms
(sqrt (- (* (* -4 (* a c)) (* -4 (* a c))) (* (* b b) (* b b))))
137.0ms
(sqrt (+ (pow (* -4 (* a c)) 3) (pow (* b b) 3)))

prune937.0ms

Pruning

8 alts after pruning (5 fresh and 3 done)

Merged error: 5.5b

regimes469.0ms

Accuracy

86% (3.6b remaining)

Error of 9.2b against oracle of 5.5b and baseline of 31.6b

bsearch314.0ms

end0.0ms

sample5.0s

Algorithm
intervals
Results
1.9s1063×body2560valid
897.0ms5849×body80valid
854.0ms937×body1280valid
483.0ms2975×body80nan
295.0ms444×body640valid
123.0ms123×body5120valid
88.0ms203×body320valid
31.0ms111×body160valid