Average Error: 33.3 → 6.7
Time: 24.0s
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 -1.0041518941750358 \cdot 10^{+133}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \le 3.9279776760338723 \cdot 10^{-290}:\\ \;\;\;\;\frac{2 \cdot c}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} + \left(-b\right)}\\ \mathbf{elif}\;b \le 2.653900512555386 \cdot 10^{+58}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{{b}^{2} - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\ \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.3
Target20.7
Herbie6.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 < -1.0041518941750358e+133

    1. Initial program 60.5

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
    5. Simplified1.9

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

    if -1.0041518941750358e+133 < b < 3.9279776760338723e-290

    1. Initial program 32.8

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

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

      \[\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(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}} \cdot \frac{1}{2 \cdot a}\]
    6. Applied associate-*l/33.0

      \[\leadsto \color{blue}{\frac{\left(\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)}\right) \cdot \frac{1}{2 \cdot a}}{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}\]
    7. Simplified14.9

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

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

    if 3.9279776760338723e-290 < b < 2.653900512555386e+58

    1. Initial program 8.9

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

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

    if 2.653900512555386e+58 < b

    1. Initial program 37.0

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.0041518941750358 \cdot 10^{+133}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \le 3.9279776760338723 \cdot 10^{-290}:\\ \;\;\;\;\frac{2 \cdot c}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} + \left(-b\right)}\\ \mathbf{elif}\;b \le 2.653900512555386 \cdot 10^{+58}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{{b}^{2} - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\]

Reproduce

herbie shell --seed 2019010 
(FPCore (a b c)
  :name "The quadratic formula (r2)"

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

sample184.0ms

Algorithm
intervals

simplify137.0ms

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

prune13.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 34.1b

localize36.0ms

Local error

Found 4 expressions with local error:

23.4b
(sqrt (- (* b b) (* 4 (* a c))))
0.3b
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
0.2b
(- (* b b) (* 4 (* a c)))
0.1b
(/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a))

rewrite34.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
19.0ms
(/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a))
8.0ms
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
4.0ms
(- (* b b) (* 4 (* a c)))
2.0ms
(sqrt (- (* b b) (* 4 (* a c))))

series199.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
82.0ms
(/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a))
51.0ms
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
40.0ms
(sqrt (- (* b b) (* 4 (* a c))))
26.0ms
(- (* b b) (* 4 (* a c)))

simplify2.7s

Counts
46 → 82
Calls
46 calls:
Slowest
315.0ms
(sqrt (- (pow (* b b) 3) (pow (* 4 (* a c)) 3)))
256.0ms
(- (* (- b) (- b)) (* (sqrt (- (* b b) (* 4 (* a c)))) (sqrt (- (* b b) (* 4 (* a c))))))
224.0ms
(sqrt (- (* (* b b) (* b b)) (* (* 4 (* a c)) (* 4 (* a c)))))
204.0ms
(- (pow (- b) 3) (pow (sqrt (- (* b b) (* 4 (* a c)))) 3))
140.0ms
(- b (* 2 (/ (* a c) b)))

prune990.0ms

Pruning

10 alts after pruning (10 fresh and 0 done)

Merged error: 6.2b

localize30.0ms

Local error

Found 4 expressions with local error:

23.4b
(sqrt (- (pow b 2) (* 4 (* a c))))
0.3b
(- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))
0.2b
(- (pow b 2) (* 4 (* a c)))
0.1b
(/ (- (- b) (sqrt (- (pow b 2) (* 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
19.0ms
(/ (- (- b) (sqrt (- (pow b 2) (* 4 (* a c))))) (* 2 a))
7.0ms
(- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))
6.0ms
(sqrt (- (pow b 2) (* 4 (* a c))))
3.0ms
(- (pow b 2) (* 4 (* a c)))

series208.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
71.0ms
(/ (- (- b) (sqrt (- (pow b 2) (* 4 (* a c))))) (* 2 a))
55.0ms
(- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))
48.0ms
(sqrt (- (pow b 2) (* 4 (* a c))))
34.0ms
(- (pow b 2) (* 4 (* a c)))

simplify3.3s

Counts
46 → 82
Calls
46 calls:
Slowest
917.0ms
(- (* (- b) (- b)) (* (sqrt (- (pow b 2) (* 4 (* a c)))) (sqrt (- (pow b 2) (* 4 (* a c))))))
310.0ms
(sqrt (- (pow (pow b 2) 3) (pow (* 4 (* a c)) 3)))
210.0ms
(- (pow (- b) 3) (pow (sqrt (- (pow b 2) (* 4 (* a c)))) 3))
161.0ms
(sqrt (- (* (pow b 2) (pow b 2)) (* (* 4 (* a c)) (* 4 (* a c)))))
104.0ms
(/ (* (* (- (- b) (sqrt (- (pow b 2) (* 4 (* a c))))) (- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))) (- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))) (* (* (* 2 a) (* 2 a)) (* 2 a)))

prune934.0ms

Pruning

10 alts after pruning (9 fresh and 1 done)

Merged error: 6.2b

localize13.0ms

Local error

Found 4 expressions with local error:

23.4b
(sqrt (- (* b b) (* 4 (* a c))))
0.3b
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
0.2b
(* (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (/ 1 (* 2 a)))
0.2b
(- (* b b) (* 4 (* a c)))

rewrite50.0ms

Algorithm
rewrite-expression-head
Rules
16×add-sqr-sqrt
11×*-un-lft-identity
add-log-exp
add-exp-log
add-cube-cbrt
associate-*l*
add-cbrt-cube
pow1
flip--
sqrt-prod
flip3--
difference-of-squares
associate-*r*
distribute-lft-out--
prod-exp
associate-*l/
diff-log
sqrt-div
sub-neg
frac-times
div-inv
cbrt-unprod
*-commutative
un-div-inv
associate-*r/
pow-prod-down
pow1/2
rec-exp
rem-sqrt-square
neg-sub0
associate--l-
Counts
4 → 70
Calls
4 calls:
Slowest
30.0ms
(* (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (/ 1 (* 2 a)))
11.0ms
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
4.0ms
(- (* b b) (* 4 (* a c)))
4.0ms
(sqrt (- (* b b) (* 4 (* a c))))

series227.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
84.0ms
(* (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (/ 1 (* 2 a)))
53.0ms
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
50.0ms
(sqrt (- (* b b) (* 4 (* a c))))
39.0ms
(- (* b b) (* 4 (* a c)))

simplify4.1s

Counts
45 → 82
Calls
45 calls:
Slowest
502.0ms
(* (- (* (- b) (- b)) (* (sqrt (- (* b b) (* 4 (* a c)))) (sqrt (- (* b b) (* 4 (* a c)))))) 1)
471.0ms
(* (- (pow (- b) 3) (pow (sqrt (- (* b b) (* 4 (* a c)))) 3)) 1)
382.0ms
(sqrt (- (pow (* b b) 3) (pow (* 4 (* a c)) 3)))
366.0ms
(* (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (/ 1 (* 2 a)))
314.0ms
(* (- (* (- b) (- b)) (* (sqrt (- (* b b) (* 4 (* a c)))) (sqrt (- (* b b) (* 4 (* a c)))))) (/ 1 (* 2 a)))

prune859.0ms

Pruning

8 alts after pruning (6 fresh and 2 done)

Merged error: 6.2b

localize32.0ms

Local error

Found 4 expressions with local error:

23.4b
(sqrt (- (* b b) (* 4 (* a c))))
15.3b
(* (* (* 4 a) c) (/ 1/2 a))
1.7b
(+ (- b) (sqrt (- (* b b) (* 4 (* a c)))))
0.2b
(- (* b b) (* 4 (* a c)))

rewrite30.0ms

Algorithm
rewrite-expression-head
Rules
add-log-exp
*-un-lft-identity
add-sqr-sqrt
add-cube-cbrt
add-exp-log
add-cbrt-cube
pow1
associate-*r*
sqrt-prod
flip--
sqrt-div
flip3--
distribute-lft-out
div-inv
flip-+
cbrt-unprod
associate-+l-
*-commutative
associate-*r/
prod-exp
pow-prod-down
associate-*l*
diff-log
pow1/2
flip3-+
sub-neg
sum-log
rem-sqrt-square
+-commutative
neg-sub0
Counts
4 → 56
Calls
4 calls:
Slowest
13.0ms
(* (* (* 4 a) c) (/ 1/2 a))
10.0ms
(+ (- b) (sqrt (- (* b b) (* 4 (* a c)))))
4.0ms
(sqrt (- (* b b) (* 4 (* a c))))
2.0ms
(- (* b b) (* 4 (* a c)))

series119.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
46.0ms
(+ (- b) (sqrt (- (* b b) (* 4 (* a c)))))
40.0ms
(sqrt (- (* b b) (* 4 (* a c))))
27.0ms
(- (* b b) (* 4 (* a c)))
6.0ms
(* (* (* 4 a) c) (/ 1/2 a))

simplify1.9s

Counts
29 → 68
Calls
29 calls:
Slowest
368.0ms
(+ (log (* (* 4 a) c)) (log (/ 1/2 a)))
282.0ms
(sqrt (- (pow (* b b) 3) (pow (* 4 (* a c)) 3)))
202.0ms
(* (* (* 4 a) c) (/ 1/2 a))
193.0ms
(sqrt (- (* (* b b) (* b b)) (* (* 4 (* a c)) (* 4 (* a c)))))
103.0ms
(* (* (* (* (* 4 a) c) (* (* 4 a) c)) (* (* 4 a) c)) (* (* (/ 1/2 a) (/ 1/2 a)) (/ 1/2 a)))

prune774.0ms

Pruning

9 alts after pruning (7 fresh and 2 done)

Merged error: 6.2b

regimes280.0ms

Accuracy

95.1% (1.2b remaining)

Error of 6.7b against oracle of 5.5b and baseline of 29.6b

bsearch477.0ms

end0.0ms

sample5.3s

Algorithm
intervals