Average Error: 33.1 → 9.1
Time: 20.3s
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.3325982788258776 \cdot 10^{+49}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le -3.0055774135002642 \cdot 10^{-136}:\\ \;\;\;\;\frac{\frac{c}{\frac{1}{2}}}{a} \cdot \frac{a}{\sqrt[3]{\sqrt{c \cdot \left(-4 \cdot a\right) + b \cdot b} - b} \cdot \left(\sqrt[3]{\sqrt{c \cdot \left(-4 \cdot a\right) + b \cdot b} - b} \cdot \sqrt[3]{\sqrt{c \cdot \left(-4 \cdot a\right) + b \cdot b} - b}\right)}\\ \mathbf{elif}\;b \le 1.3845698652006538 \cdot 10^{+96}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \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.1
Target20.4
Herbie9.1
\[\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.3325982788258776e+49

    1. Initial program 56.2

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

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

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

    if -2.3325982788258776e+49 < b < -3.0055774135002642e-136

    1. Initial program 37.0

      \[\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--37.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/40.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. Simplified19.9

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

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

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

      \[\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}}\]
    10. Using strategy rm
    11. Applied add-cube-cbrt19.0

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

    if -3.0055774135002642e-136 < b < 1.3845698652006538e+96

    1. Initial program 11.4

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

    if 1.3845698652006538e+96 < b

    1. Initial program 44.3

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -2.3325982788258776 \cdot 10^{+49}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le -3.0055774135002642 \cdot 10^{-136}:\\ \;\;\;\;\frac{\frac{c}{\frac{1}{2}}}{a} \cdot \frac{a}{\sqrt[3]{\sqrt{c \cdot \left(-4 \cdot a\right) + b \cdot b} - b} \cdot \left(\sqrt[3]{\sqrt{c \cdot \left(-4 \cdot a\right) + b \cdot b} - b} \cdot \sqrt[3]{\sqrt{c \cdot \left(-4 \cdot a\right) + b \cdot b} - b}\right)}\\ \mathbf{elif}\;b \le 1.3845698652006538 \cdot 10^{+96}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\]

Reproduce

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

sample150.0ms

Algorithm
intervals
Results
28.0ms13×body640valid
26.0ms33×body2560valid
26.0ms189×body80valid
24.0ms33×body1280valid
10.0ms76×body80nan
5.0msbody5120valid
3.0msbody320valid
1.0msbody160valid

simplify110.0ms

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

prune381.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 34.6b

localize48.0ms

Local error

Found 4 expressions with local error:

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

rewrite43.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
24.0ms
(/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a))
10.0ms
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
4.0ms
(- (* b b) (* 4 (* a c)))
4.0ms
(sqrt (- (* b b) (* 4 (* a c))))

series215.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
77.0ms
(/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a))
49.0ms
(sqrt (- (* b b) (* 4 (* a c))))
48.0ms
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
41.0ms
(- (* b b) (* 4 (* a c)))

simplify2.4s

Counts
46 → 82
Calls
46 calls:
Slowest
293.0ms
(sqrt (- (pow (* b b) 3) (pow (* 4 (* a c)) 3)))
290.0ms
(- (* (- b) (- b)) (* (sqrt (- (* b b) (* 4 (* a c)))) (sqrt (- (* b b) (* 4 (* a c))))))
198.0ms
(- (pow (- b) 3) (pow (sqrt (- (* b b) (* 4 (* a c)))) 3))
171.0ms
(sqrt (- (* (* b b) (* b b)) (* (* 4 (* a c)) (* 4 (* a c)))))
112.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)))

prune877.0ms

Pruning

10 alts after pruning (9 fresh and 1 done)

Merged error: 5.9b

localize12.0ms

Local error

Found 4 expressions with local error:

22.9b
(sqrt (- (* b b) (* 4 (* a c))))
17.4b
(/ (* (* c 4) a) (* (* 2 a) (+ (- b) (sqrt (- (* b b) (* 4 (* a c)))))))
1.1b
(+ (- b) (sqrt (- (* b b) (* 4 (* a c)))))
0.6b
(- (* b b) (* 4 (* a c)))

rewrite32.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
15.0ms
(/ (* (* c 4) a) (* (* 2 a) (+ (- b) (sqrt (- (* b b) (* 4 (* a c)))))))
10.0ms
(+ (- b) (sqrt (- (* b b) (* 4 (* a c)))))
4.0ms
(- (* b b) (* 4 (* a c)))
2.0ms
(sqrt (- (* b b) (* 4 (* a c))))

series312.0ms

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

simplify3.1s

Counts
31 → 70
Calls
31 calls:
Slowest
681.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))))))))
677.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))))))))
334.0ms
(+ (* (- b) (- b)) (- (* (sqrt (- (* b b) (* 4 (* a c)))) (sqrt (- (* b b) (* 4 (* a c))))) (* (- b) (sqrt (- (* b b) (* 4 (* a c)))))))
269.0ms
(sqrt (- (pow (* b b) 3) (pow (* 4 (* a c)) 3)))
132.0ms
(sqrt (- (* (* b b) (* b b)) (* (* 4 (* a c)) (* 4 (* a c)))))

prune800.0ms

Pruning

8 alts after pruning (6 fresh and 2 done)

Merged error: 5.8b

localize22.0ms

Local error

Found 4 expressions with local error:

22.9b
(sqrt (+ (* -4 (* a c)) (* b b)))
17.6b
(/ (* (* c 4) a) (* 2 a))
1.1b
(- (sqrt (+ (* -4 (* a c)) (* b b))) b)
0.6b
(+ (* -4 (* a c)) (* b b))

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

series170.0ms

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

simplify1.8s

Counts
24 → 63
Calls
24 calls:
Slowest
753.0ms
(/ (* (* (* (* c 4) a) (* (* c 4) a)) (* (* c 4) a)) (* (* (* 2 a) (* 2 a)) (* 2 a)))
541.0ms
(- (log (* (* c 4) a)) (log (* 2 a)))
163.0ms
(sqrt (- (* (* -4 (* a c)) (* -4 (* a c))) (* (* b b) (* b b))))
114.0ms
(sqrt (+ (pow (* -4 (* a c)) 3) (pow (* b b) 3)))
47.0ms
(- (pow b 2) (* 4 (* a c)))

prune620.0ms

Pruning

8 alts after pruning (5 fresh and 3 done)

Merged error: 5.8b

localize36.0ms

Local error

Found 4 expressions with local error:

22.9b
(sqrt (+ (* c (* -4 a)) (* b b)))
11.7b
(* (/ (/ c 1/2) a) (/ a (- (sqrt (+ (* c (* -4 a)) (* b b))) b)))
1.1b
(- (sqrt (+ (* c (* -4 a)) (* b b))) b)
0.6b
(+ (* c (* -4 a)) (* b b))

rewrite41.0ms

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

series354.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
175.0ms
(* (/ (/ c 1/2) a) (/ a (- (sqrt (+ (* c (* -4 a)) (* b b))) b)))
66.0ms
(- (sqrt (+ (* c (* -4 a)) (* b b))) b)
64.0ms
(sqrt (+ (* c (* -4 a)) (* b b)))
49.0ms
(+ (* c (* -4 a)) (* b b))

simplify1.2s

Counts
35 → 72
Calls
35 calls:
Slowest
192.0ms
(sqrt (+ (pow (* c (* -4 a)) 3) (pow (* b b) 3)))
188.0ms
(sqrt (- (* (* c (* -4 a)) (* c (* -4 a))) (* (* b b) (* b b))))
168.0ms
(* (/ (/ c 1/2) a) (/ a (- (sqrt (+ (* c (* -4 a)) (* b b))) b)))
161.0ms
(+ (log (/ (/ c 1/2) a)) (log (/ a (- (sqrt (+ (* c (* -4 a)) (* b b))) b))))
103.0ms
(* (* (* (/ (/ c 1/2) a) (/ (/ c 1/2) a)) (/ (/ c 1/2) a)) (* (* (/ a (- (sqrt (+ (* c (* -4 a)) (* b b))) b)) (/ a (- (sqrt (+ (* c (* -4 a)) (* b b))) b))) (/ a (- (sqrt (+ (* c (* -4 a)) (* b b))) b))))

prune756.0ms

Pruning

8 alts after pruning (5 fresh and 3 done)

Merged error: 5.8b

regimes549.0ms

Accuracy

85.9% (3.7b remaining)

Error of 9.1b against oracle of 5.4b and baseline of 31.5b

bsearch608.0ms

end0.0ms

sample4.7s

Algorithm
intervals
Results
1.8s1098×body2560valid
959.0ms5905×body80valid
799.0ms866×body1280valid
380.0ms2861×body80nan
258.0ms445×body640valid
133.0ms117×body5120valid
85.0ms223×body320valid
29.0ms102×body160valid