Average Error: 33.0 → 6.7
Time: 35.4s
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 -3.113715444889159 \cdot 10^{+97}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le 3.743477545150262 \cdot 10^{-272}:\\ \;\;\;\;\frac{2 \cdot c}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} + \left(-b\right)}\\ \mathbf{elif}\;b \le 1.2614257711811345 \cdot 10^{+67}:\\ \;\;\;\;\frac{1}{a \cdot 2} \cdot \left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}\right)\\ \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.2
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 < -3.113715444889159e+97

    1. Initial program 58.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-inv58.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 2.5

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

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

    if -3.113715444889159e+97 < b < 3.743477545150262e-272

    1. Initial program 30.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-inv30.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. Using strategy rm
    5. Applied flip--30.7

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

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

      \[\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 inf 9.1

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

    if 3.743477545150262e-272 < b < 1.2614257711811345e+67

    1. Initial program 8.3

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

      \[\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}}\]

    if 1.2614257711811345e+67 < b

    1. Initial program 38.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-inv38.6

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

      \[\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 -3.113715444889159 \cdot 10^{+97}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le 3.743477545150262 \cdot 10^{-272}:\\ \;\;\;\;\frac{2 \cdot c}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} + \left(-b\right)}\\ \mathbf{elif}\;b \le 1.2614257711811345 \cdot 10^{+67}:\\ \;\;\;\;\frac{1}{a \cdot 2} \cdot \left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\]

Reproduce

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

sample236.0ms

Algorithm
intervals
Results
359×(pre true 80)
200×(body real 80)
85×(body nan 80)
34×(body real 2560)
20×(body real 1280)
13×(body real 640)
(body real 5120)
(body real 320)
(body real 160)

simplify159.0ms

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

prune16.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 30.2b

localize66.0ms

Local error

Found 4 expressions with local error:

22.7b
(sqrt (- (* b b) (* 4 (* a c))))
0.8b
(- (* b b) (* 4 (* a c)))
0.5b
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
0.1b
(/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a))

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

series328.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
104.0ms
(/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a))
89.0ms
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
81.0ms
(sqrt (- (* b b) (* 4 (* a c))))
54.0ms
(- (* b b) (* 4 (* a c)))

simplify4.1s

Counts
46 → 82
Calls
46 calls:
Slowest
464.0ms
(sqrt (- (pow (* b b) 3) (pow (* 4 (* a c)) 3)))
403.0ms
(- (* (- b) (- b)) (* (sqrt (- (* b b) (* 4 (* a c)))) (sqrt (- (* b b) (* 4 (* a c))))))
346.0ms
(- (pow (- b) 3) (pow (sqrt (- (* b b) (* 4 (* a c)))) 3))
244.0ms
(sqrt (- (* (* b b) (* b b)) (* (* 4 (* a c)) (* 4 (* a c)))))
189.0ms
(- b (* 2 (/ (* a c) b)))

prune1.9s

Pruning

9 alts after pruning (9 fresh and 0 done)

Merged error: 5.4b

localize20.0ms

Local error

Found 4 expressions with local error:

22.7b
(sqrt (- (* b b) (* 4 (* a c))))
0.8b
(- (* b b) (* 4 (* a c)))
0.5b
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
0.3b
(* (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (/ 1 (* 2 a)))

rewrite55.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
31.0ms
(* (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (/ 1 (* 2 a)))
13.0ms
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
5.0ms
(- (* b b) (* 4 (* a c)))
5.0ms
(sqrt (- (* b b) (* 4 (* a c))))

series332.0ms

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

simplify6.2s

Counts
45 → 82
Calls
45 calls:
Slowest
753.0ms
(* (- (pow (- b) 3) (pow (sqrt (- (* b b) (* 4 (* a c)))) 3)) 1)
665.0ms
(* (- (* (- b) (- b)) (* (sqrt (- (* b b) (* 4 (* a c)))) (sqrt (- (* b b) (* 4 (* a c)))))) 1)
568.0ms
(* (- (* (- b) (- b)) (* (sqrt (- (* b b) (* 4 (* a c)))) (sqrt (- (* b b) (* 4 (* a c)))))) (/ 1 (* 2 a)))
490.0ms
(* (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (/ 1 (* 2 a)))
456.0ms
(sqrt (- (pow (* b b) 3) (pow (* 4 (* a c)) 3)))

prune1.5s

Pruning

8 alts after pruning (7 fresh and 1 done)

Merged error: 5.4b

localize16.0ms

Local error

Found 4 expressions with local error:

22.7b
(sqrt (- (* b b) (* 4 (* a c))))
0.8b
(- (* b b) (* 4 (* a c)))
0.5b
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
0.2b
(/ 1 (/ (* 2 a) (- (- b) (sqrt (- (* b b) (* 4 (* a c)))))))

rewrite40.0ms

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

series354.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
132.0ms
(/ 1 (/ (* 2 a) (- (- b) (sqrt (- (* b b) (* 4 (* a c)))))))
90.0ms
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
80.0ms
(sqrt (- (* b b) (* 4 (* a c))))
51.0ms
(- (* b b) (* 4 (* a c)))

simplify3.6s

Counts
39 → 81
Calls
39 calls:
Slowest
591.0ms
(+ (* (- b) (- b)) (+ (* (sqrt (- (* b b) (* 4 (* a c)))) (sqrt (- (* b b) (* 4 (* a c))))) (* (- b) (sqrt (- (* b b) (* 4 (* a c)))))))
457.0ms
(sqrt (- (pow (* b b) 3) (pow (* 4 (* a c)) 3)))
245.0ms
(sqrt (- (* (* b b) (* b b)) (* (* 4 (* a c)) (* 4 (* a c)))))
188.0ms
(- b (* 2 (/ (* a c) b)))
120.0ms
(sqrt (/ (* 2 a) (- (- b) (sqrt (- (* b b) (* 4 (* a c)))))))

prune1.5s

Pruning

9 alts after pruning (7 fresh and 2 done)

Merged error: 5.4b

localize49.0ms

Local error

Found 4 expressions with local error:

22.7b
(sqrt (- (* b b) (* 4 (* a c))))
13.1b
(* (* (* 4 a) c) (/ 1/2 a))
0.8b
(+ (- b) (sqrt (- (* b b) (* 4 (* a c)))))
0.8b
(- (* b b) (* 4 (* a c)))

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

series236.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
91.0ms
(+ (- b) (sqrt (- (* b b) (* 4 (* a c)))))
81.0ms
(sqrt (- (* b b) (* 4 (* a c))))
51.0ms
(- (* b b) (* 4 (* a c)))
13.0ms
(* (* (* 4 a) c) (/ 1/2 a))

simplify2.9s

Counts
29 → 68
Calls
29 calls:
Slowest
522.0ms
(+ (log (* (* 4 a) c)) (log (/ 1/2 a)))
451.0ms
(sqrt (- (pow (* b b) 3) (pow (* 4 (* a c)) 3)))
338.0ms
(* (* (* 4 a) c) (/ 1/2 a))
247.0ms
(sqrt (- (* (* b b) (* b b)) (* (* 4 (* a c)) (* 4 (* a c)))))
190.0ms
(- b (* 2 (/ (* a c) b)))

prune1.3s

Pruning

8 alts after pruning (7 fresh and 1 done)

Merged error: 5.4b

regimes444.0ms

Accuracy

95.9% (1.1b remaining)

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

bsearch833.0ms

end0.0ms

sample7.7s

Algorithm
intervals
Results
11661×(pre true 80)
5921×(body real 80)
2918×(body nan 80)
1021×(body real 2560)
880×(body real 1280)
469×(body real 640)
230×(body real 320)
117×(body real 5120)
105×(body real 160)