Average Error: 19.2 → 9.1
Time: 22.2s
Precision: 64
Internal Precision: 128
\[\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \end{array}\]
\[\begin{array}{l} \mathbf{if}\;b \le -1.5604433271538123 \cdot 10^{+100}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\left(-b\right) + \left(2 \cdot \frac{a \cdot c}{b} - b\right)}\\ \end{array}\\ \mathbf{elif}\;b \le 1.501809486178084 \cdot 10^{+23}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + \left(-b\right)}\\ \end{array}\\ \mathbf{elif}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot \frac{a \cdot c}{b} - 2 \cdot b}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + \left(-b\right)}\\ \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

Derivation

  1. Split input into 3 regimes
  2. if b < -1.5604433271538123e+100

    1. Initial program 29.7

      \[\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \end{array}\]
    2. Taylor expanded around -inf 6.8

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\color{blue}{\left(-b\right) + \left(2 \cdot \frac{a \cdot c}{b} - b\right)}}\\ \end{array}\]

    if -1.5604433271538123e+100 < b < 1.501809486178084e+23

    1. Initial program 9.3

      \[\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \end{array}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt9.4

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - \color{blue}{\sqrt{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \end{array}\]

    if 1.501809486178084e+23 < b

    1. Initial program 32.7

      \[\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \end{array}\]
    2. Taylor expanded around inf 10.6

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{\color{blue}{2 \cdot \frac{a \cdot c}{b} - 2 \cdot b}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \end{array}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification9.1

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

Reproduce

herbie shell --seed 2019022 
(FPCore (a b c)
  :name "jeff quadratic root 1"
  (if (>= b 0) (/ (- (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)) (/ (* 2 c) (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))))))

Details

Time bar (total: 21.2s)Debug log

sample86.0ms

Algorithm
intervals
Results
52.0ms281×body80valid
15.0ms96×body80nan

simplify150.0ms

Counts
1 → 1
Calls
1 calls:
Slowest
150.0ms
(if (>= b 0) (/ (- (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)) (/ (* 2 c) (+ (- b) (sqrt (- (* b b) (* (* 4 a) c))))))

prune26.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 18.0b

localize177.0ms

Local error

Found 4 expressions with local error:

22.4b
(sqrt (- (* b b) (* (* 4 a) c)))
22.4b
(sqrt (- (* b b) (* (* 4 a) c)))
2.0b
(+ (- b) (sqrt (- (* b b) (* (* 4 a) c))))
1.1b
(- (- b) (sqrt (- (* b b) (* (* 4 a) c))))

rewrite34.0ms

Algorithm
rewrite-expression-head
Rules
12×add-sqr-sqrt
10×*-un-lft-identity
add-log-exp
sqrt-prod
add-cube-cbrt
add-exp-log
sqrt-div
add-cbrt-cube
pow1
flip--
flip3--
difference-of-squares
pow1/2
rem-sqrt-square
neg-sub0
distribute-lft-out--
distribute-lft-out
flip-+
associate-+l-
diff-log
flip3-+
sub-neg
sum-log
+-commutative
associate--l-
Counts
4 → 57
Calls
4 calls:
Slowest
11.0ms
(- (- b) (sqrt (- (* b b) (* (* 4 a) c))))
11.0ms
(+ (- b) (sqrt (- (* b b) (* (* 4 a) c))))
7.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
4.0ms
(sqrt (- (* b b) (* (* 4 a) c)))

series235.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
76.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
60.0ms
(+ (- b) (sqrt (- (* b b) (* (* 4 a) c))))
50.0ms
(- (- b) (sqrt (- (* b b) (* (* 4 a) c))))
50.0ms
(sqrt (- (* b b) (* (* 4 a) c)))

simplify2.4s

Counts
32 → 69
Calls
32 calls:
Slowest
436.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
428.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
153.0ms
(- b (* 2 (/ (* a c) b)))
140.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* 4 a) c) (* (* 4 a) c))))
139.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* 4 a) c) (* (* 4 a) c))))

prune1.0s

Pruning

8 alts after pruning (8 fresh and 0 done)

Merged error: 7.5b

localize105.0ms

Local error

Found 4 expressions with local error:

22.4b
(sqrt (- (* b b) (* (* 4 a) c)))
22.4b
(sqrt (- (* b b) (* (* 4 a) c)))
22.4b
(sqrt (- (* b b) (* (* 4 a) c)))
12.8b
(- (- b) (* (sqrt (sqrt (- (* b b) (* (* 4 a) c)))) (sqrt (sqrt (- (* b b) (* (* 4 a) c))))))

rewrite18.0ms

Algorithm
rewrite-expression-head
Rules
11×add-sqr-sqrt
sqrt-prod
add-cube-cbrt
*-un-lft-identity
add-log-exp
sqrt-div
flip--
add-exp-log
add-cbrt-cube
flip3--
pow1
pow1/2
rem-sqrt-square
difference-of-squares
diff-log
sub-neg
neg-sub0
associate--l-
Counts
4 → 56
Calls
4 calls:
Slowest
6.0ms
(- (- b) (* (sqrt (sqrt (- (* b b) (* (* 4 a) c)))) (sqrt (sqrt (- (* b b) (* (* 4 a) c))))))
4.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
4.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
4.0ms
(sqrt (- (* b b) (* (* 4 a) c)))

series216.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
65.0ms
(- (- b) (* (sqrt (sqrt (- (* b b) (* (* 4 a) c)))) (sqrt (sqrt (- (* b b) (* (* 4 a) c))))))
54.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
50.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
46.0ms
(sqrt (- (* b b) (* (* 4 a) c)))

simplify2.6s

Counts
33 → 68
Calls
33 calls:
Slowest
398.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
374.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
370.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
156.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* 4 a) c) (* (* 4 a) c))))
130.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* 4 a) c) (* (* 4 a) c))))

prune1.3s

Pruning

8 alts after pruning (7 fresh and 1 done)

Merged error: 7.5b

localize126.0ms

Local error

Found 4 expressions with local error:

23.1b
(cbrt (- (* b b) (* (* 4 a) c)))
23.1b
(cbrt (- (* b b) (* (* 4 a) c)))
22.4b
(sqrt (- (* b b) (* (* 4 a) c)))
7.2b
(+ (- b) (* (fabs (cbrt (- (* b b) (* (* 4 a) c)))) (sqrt (cbrt (- (* b b) (* (* 4 a) c))))))

rewrite10.0ms

Algorithm
rewrite-expression-head
Rules
add-sqr-sqrt
add-cube-cbrt
*-un-lft-identity
add-log-exp
cbrt-prod
add-exp-log
add-cbrt-cube
cbrt-div
pow1
flip--
sqrt-prod
flip3--
sqrt-div
pow1/3
flip-+
associate-+l-
pow1/2
flip3-+
sum-log
rem-sqrt-square
+-commutative
neg-sub0
Counts
4 → 52
Calls
4 calls:
Slowest
4.0ms
(+ (- b) (* (fabs (cbrt (- (* b b) (* (* 4 a) c)))) (sqrt (cbrt (- (* b b) (* (* 4 a) c))))))
2.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
1.0ms
(cbrt (- (* b b) (* (* 4 a) c)))
1.0ms
(cbrt (- (* b b) (* (* 4 a) c)))

series343.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
112.0ms
(cbrt (- (* b b) (* (* 4 a) c)))
95.0ms
(cbrt (- (* b b) (* (* 4 a) c)))
86.0ms
(+ (- b) (* (fabs (cbrt (- (* b b) (* (* 4 a) c)))) (sqrt (cbrt (- (* b b) (* (* 4 a) c))))))
50.0ms
(sqrt (- (* b b) (* (* 4 a) c)))

simplify3.0s

Counts
29 → 64
Calls
29 calls:
Slowest
423.0ms
(cbrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
361.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
344.0ms
(cbrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
273.0ms
(- (exp (* 1/3 (+ (log -4) (+ (log a) (log c))))) (* 1/12 (* (exp (* 1/3 (- (log -4) (+ (* 2 (log a)) (* 2 (log c)))))) (pow b 2))))
264.0ms
(- (exp (* 1/3 (+ (log -4) (+ (log a) (log c))))) (* 1/12 (* (exp (* 1/3 (- (log -4) (+ (* 2 (log a)) (* 2 (log c)))))) (pow b 2))))

prune1.3s

Pruning

8 alts after pruning (6 fresh and 2 done)

Merged error: 7.5b

localize106.0ms

Local error

Found 4 expressions with local error:

23.1b
(cbrt (- (* b b) (* (* 4 a) c)))
23.1b
(cbrt (- (* b b) (* (* 4 a) c)))
22.4b
(sqrt (- (* b b) (* (* 4 a) c)))
9.1b
(- (- b) (* (fabs (cbrt (- (* b b) (* (* 4 a) c)))) (sqrt (cbrt (- (* b b) (* (* 4 a) c))))))

rewrite9.0ms

Algorithm
rewrite-expression-head
Rules
add-sqr-sqrt
add-cube-cbrt
*-un-lft-identity
add-log-exp
cbrt-prod
flip--
add-exp-log
add-cbrt-cube
flip3--
cbrt-div
pow1
sqrt-prod
sqrt-div
pow1/3
diff-log
pow1/2
sub-neg
rem-sqrt-square
neg-sub0
associate--l-
Counts
4 → 53
Calls
4 calls:
Slowest
4.0ms
(- (- b) (* (fabs (cbrt (- (* b b) (* (* 4 a) c)))) (sqrt (cbrt (- (* b b) (* (* 4 a) c))))))
2.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
1.0ms
(cbrt (- (* b b) (* (* 4 a) c)))
1.0ms
(cbrt (- (* b b) (* (* 4 a) c)))

series346.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
104.0ms
(cbrt (- (* b b) (* (* 4 a) c)))
102.0ms
(cbrt (- (* b b) (* (* 4 a) c)))
86.0ms
(- (- b) (* (fabs (cbrt (- (* b b) (* (* 4 a) c)))) (sqrt (cbrt (- (* b b) (* (* 4 a) c))))))
53.0ms
(sqrt (- (* b b) (* (* 4 a) c)))

simplify2.9s

Counts
29 → 65
Calls
29 calls:
Slowest
428.0ms
(cbrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
384.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
347.0ms
(cbrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
292.0ms
(- (exp (* 1/3 (+ (log -4) (+ (log a) (log c))))) (* 1/12 (* (exp (* 1/3 (- (log -4) (+ (* 2 (log a)) (* 2 (log c)))))) (pow b 2))))
283.0ms
(- (exp (* 1/3 (+ (log -4) (+ (log a) (log c))))) (* 1/12 (* (exp (* 1/3 (- (log -4) (+ (* 2 (log a)) (* 2 (log c)))))) (pow b 2))))

prune1.3s

Pruning

8 alts after pruning (5 fresh and 3 done)

Merged error: 7.5b

regimes285.0ms

Accuracy

87.3% (1.5b remaining)

Error of 9.1b against oracle of 7.6b and baseline of 19.3b

bsearch220.0ms

end0.0ms

sample2.8s

Algorithm
intervals
Results
1.9s8730×body80valid
527.0ms2975×body80nan