Average Error: 33.0 → 7.2
Time: 39.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 -2.149882403051541 \cdot 10^{+52}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \le -5.3114917253015484 \cdot 10^{-256}:\\ \;\;\;\;\frac{2 \cdot c}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} + \left(-b\right)}\\ \mathbf{elif}\;b \le 1.628277854542934 \cdot 10^{+68}:\\ \;\;\;\;\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.0
Target20.8
Herbie7.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.149882403051541e+52

    1. Initial program 56.9

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

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

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

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

    if -2.149882403051541e+52 < b < -5.3114917253015484e-256

    1. Initial program 31.6

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

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

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

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

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

    if -5.3114917253015484e-256 < b < 1.628277854542934e+68

    1. Initial program 10.3

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

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

    if 1.628277854542934e+68 < b

    1. Initial program 37.5

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -2.149882403051541 \cdot 10^{+52}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \le -5.3114917253015484 \cdot 10^{-256}:\\ \;\;\;\;\frac{2 \cdot c}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} + \left(-b\right)}\\ \mathbf{elif}\;b \le 1.628277854542934 \cdot 10^{+68}:\\ \;\;\;\;\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 1137770271 
(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: 37.0s)Debug log

sample235.0ms

Algorithm
intervals
Results
192×46.0ms(body real 80)
30×44.0ms(body real 2560)
32×40.0ms(body real 1280)
98×21.0ms(body nan 80)
17×16.0ms(body real 640)
381×12.0ms(pre true 80)
10×7.0ms(body real 320)
2.0ms(body real 5120)
0.0ms(body real 160)

simplify162.0ms

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

prune17.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 33.0b

localize76.0ms

Local error

Found 4 expressions with local error:

22.2b
(sqrt (- (* b b) (* 4 (* a c))))
0.6b
(- (- 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))

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
41.0ms
(/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a))
14.0ms
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
5.0ms
(- (* b b) (* 4 (* a c)))
5.0ms
(sqrt (- (* b b) (* 4 (* a c))))

series341.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
107.0ms
(/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a))
92.0ms
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
88.0ms
(sqrt (- (* b b) (* 4 (* a c))))
54.0ms
(- (* b b) (* 4 (* a c)))

simplify4.1s

Counts
46 → 82
Calls
46 calls:
Slowest
453.0ms
(sqrt (- (pow (* b b) 3) (pow (* 4 (* a c)) 3)))
442.0ms
(- (* (- b) (- b)) (* (sqrt (- (* b b) (* 4 (* a c)))) (sqrt (- (* b b) (* 4 (* a c))))))
358.0ms
(- (pow (- b) 3) (pow (sqrt (- (* b b) (* 4 (* a c)))) 3))
250.0ms
(sqrt (- (* (* b b) (* b b)) (* (* 4 (* a c)) (* 4 (* a c)))))
191.0ms
(- b (* 2 (/ (* a c) b)))

prune1.8s

Pruning

11 alts after pruning (11 fresh and 0 done)

Merged error: 7.1b

localize40.0ms

Local error

Found 4 expressions with local error:

22.2b
(sqrt (- (pow b 2) (* 4 (* a c))))
0.6b
(- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))
0.4b
(- (pow b 2) (* 4 (* a c)))
0.1b
(/ (- (- b) (sqrt (- (pow b 2) (* 4 (* a c))))) (* 2 a))

rewrite87.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
52.0ms
(/ (- (- b) (sqrt (- (pow b 2) (* 4 (* a c))))) (* 2 a))
17.0ms
(- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))
8.0ms
(- (pow b 2) (* 4 (* a c)))
7.0ms
(sqrt (- (pow b 2) (* 4 (* a c))))

series351.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
113.0ms
(/ (- (- b) (sqrt (- (pow b 2) (* 4 (* a c))))) (* 2 a))
100.0ms
(- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))
82.0ms
(sqrt (- (pow b 2) (* 4 (* a c))))
56.0ms
(- (pow b 2) (* 4 (* a c)))

simplify5.5s

Counts
46 → 82
Calls
46 calls:
Slowest
1.5s
(- (* (- b) (- b)) (* (sqrt (- (pow b 2) (* 4 (* a c)))) (sqrt (- (pow b 2) (* 4 (* a c))))))
554.0ms
(sqrt (- (pow (pow b 2) 3) (pow (* 4 (* a c)) 3)))
390.0ms
(- (pow (- b) 3) (pow (sqrt (- (pow b 2) (* 4 (* a c)))) 3))
268.0ms
(sqrt (- (* (pow b 2) (pow b 2)) (* (* 4 (* a c)) (* 4 (* a c)))))
211.0ms
(- b (* 2 (/ (* a c) b)))

prune1.9s

Pruning

10 alts after pruning (9 fresh and 1 done)

Merged error: 7.1b

localize17.0ms

Local error

Found 4 expressions with local error:

22.2b
(sqrt (- (* b b) (* 4 (* a c))))
0.6b
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
0.4b
(- (* b b) (* 4 (* a c)))
0.2b
(* (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (/ 1 (* 2 a)))

rewrite66.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
35.0ms
(* (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (/ 1 (* 2 a)))
17.0ms
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
6.0ms
(sqrt (- (* b b) (* 4 (* a c))))
5.0ms
(- (* b b) (* 4 (* a c)))

series730.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
488.0ms
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
105.0ms
(* (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (/ 1 (* 2 a)))
81.0ms
(sqrt (- (* b b) (* 4 (* a c))))
56.0ms
(- (* b b) (* 4 (* a c)))

simplify6.6s

Counts
45 → 82
Calls
45 calls:
Slowest
822.0ms
(* (- (* (- b) (- b)) (* (sqrt (- (* b b) (* 4 (* a c)))) (sqrt (- (* b b) (* 4 (* a c)))))) 1)
793.0ms
(* (- (pow (- b) 3) (pow (sqrt (- (* b b) (* 4 (* a c)))) 3)) 1)
625.0ms
(* (- (* (- b) (- b)) (* (sqrt (- (* b b) (* 4 (* a c)))) (sqrt (- (* b b) (* 4 (* a c)))))) (/ 1 (* 2 a)))
496.0ms
(* (+ (* (- b) (- b)) (+ (* (sqrt (- (* b b) (* 4 (* a c)))) (sqrt (- (* b b) (* 4 (* a c))))) (* (- b) (sqrt (- (* b b) (* 4 (* a c))))))) (* 2 a))
483.0ms
(* (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (/ 1 (* 2 a)))

prune1.6s

Pruning

9 alts after pruning (8 fresh and 1 done)

Merged error: 7.1b

localize50.0ms

Local error

Found 4 expressions with local error:

22.2b
(sqrt (- (* b b) (* 4 (* a c))))
14.5b
(* (* (* 4 a) c) (/ 1/2 a))
0.7b
(+ (- b) (sqrt (- (* b b) (* 4 (* a c)))))
0.4b
(- (* b b) (* 4 (* a c)))

rewrite42.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
16.0ms
(* (* (* 4 a) c) (/ 1/2 a))
14.0ms
(+ (- b) (sqrt (- (* b b) (* 4 (* a c)))))
6.0ms
(sqrt (- (* b b) (* 4 (* a c))))
5.0ms
(- (* b b) (* 4 (* a c)))

series241.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
93.0ms
(+ (- b) (sqrt (- (* b b) (* 4 (* a c)))))
82.0ms
(sqrt (- (* b b) (* 4 (* a c))))
52.0ms
(- (* b b) (* 4 (* a c)))
14.0ms
(* (* (* 4 a) c) (/ 1/2 a))

simplify2.8s

Counts
29 → 68
Calls
29 calls:
Slowest
528.0ms
(+ (log (* (* 4 a) c)) (log (/ 1/2 a)))
477.0ms
(sqrt (- (pow (* b b) 3) (pow (* 4 (* a c)) 3)))
335.0ms
(* (* (* 4 a) c) (/ 1/2 a))
258.0ms
(sqrt (- (* (* b b) (* b b)) (* (* 4 (* a c)) (* 4 (* a c)))))
188.0ms
(- b (* 2 (/ (* a c) b)))

prune1.5s

Pruning

8 alts after pruning (6 fresh and 2 done)

Merged error: 7.1b

regimes461.0ms

Accuracy

94% (1.4b remaining)

Error of 7.2b against oracle of 5.8b and baseline of 29.8b

bsearch822.0ms

end0.0ms

sample7.3s

Algorithm
intervals
Results
1039×1.7s(body real 2560)
5903×1.6s(body real 80)
884×1.2s(body real 1280)
11629×807.0ms(pre true 80)
2927×670.0ms(body nan 80)
446×493.0ms(body real 640)
116×292.0ms(body real 5120)
214×156.0ms(body real 320)
100×48.0ms(body real 160)