Average Error: 39.5 → 20.7
Time: 53.0s
Precision: 64
Internal Precision: 1344
\[\frac{\left(1 - a\right) - \sqrt{\left(\left(1 - 2 \cdot a\right) + \left(4 \cdot K\right) \cdot a\right) + {a}^{2}}}{2 \cdot \sqrt{\left(\left(1 - 2 \cdot a\right) + \left(4 \cdot K\right) \cdot a\right) + {a}^{2}}}\]
\[\begin{array}{l} \mathbf{if}\;a \le -0.0029571681252933773:\\ \;\;\;\;\frac{2 \cdot \left(\frac{\frac{K}{a}}{a} + \left(\frac{K}{a} + K\right)\right)}{\sqrt{1 - a \cdot \left(\left(2 - a\right) - K \cdot 4\right)} \cdot 2}\\ \mathbf{elif}\;a \le 5.177159287427985 \cdot 10^{-16}:\\ \;\;\;\;\left(a \cdot 3 + 2\right) \cdot \left(\left(a \cdot a\right) \cdot \left(-K\right)\right) - K \cdot a\\ \mathbf{else}:\\ \;\;\;\;\frac{1 - \left(\sqrt{1 - a \cdot \left(\left(2 - a\right) - K \cdot 4\right)} + a\right)}{\sqrt{1 - a \cdot \left(\left(2 - a\right) - K \cdot 4\right)} \cdot 2}\\ \end{array}\]

Error

Bits error versus a

Bits error versus K

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 3 regimes
  2. if a < -0.0029571681252933773

    1. Initial program 53.8

      \[\frac{\left(1 - a\right) - \sqrt{\left(\left(1 - 2 \cdot a\right) + \left(4 \cdot K\right) \cdot a\right) + {a}^{2}}}{2 \cdot \sqrt{\left(\left(1 - 2 \cdot a\right) + \left(4 \cdot K\right) \cdot a\right) + {a}^{2}}}\]
    2. Initial simplification53.8

      \[\leadsto \frac{\left(1 - a\right) - \sqrt{1 - a \cdot \left(\left(2 - a\right) - 4 \cdot K\right)}}{2 \cdot \sqrt{1 - a \cdot \left(\left(2 - a\right) - 4 \cdot K\right)}}\]
    3. Taylor expanded around -inf 25.6

      \[\leadsto \frac{\color{blue}{2 \cdot \frac{K}{a} + \left(2 \cdot \frac{K}{{a}^{2}} + 2 \cdot K\right)}}{2 \cdot \sqrt{1 - a \cdot \left(\left(2 - a\right) - 4 \cdot K\right)}}\]
    4. Simplified25.6

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

    if -0.0029571681252933773 < a < 5.177159287427985e-16

    1. Initial program 33.4

      \[\frac{\left(1 - a\right) - \sqrt{\left(\left(1 - 2 \cdot a\right) + \left(4 \cdot K\right) \cdot a\right) + {a}^{2}}}{2 \cdot \sqrt{\left(\left(1 - 2 \cdot a\right) + \left(4 \cdot K\right) \cdot a\right) + {a}^{2}}}\]
    2. Initial simplification33.4

      \[\leadsto \frac{\left(1 - a\right) - \sqrt{1 - a \cdot \left(\left(2 - a\right) - 4 \cdot K\right)}}{2 \cdot \sqrt{1 - a \cdot \left(\left(2 - a\right) - 4 \cdot K\right)}}\]
    3. Taylor expanded around 0 9.3

      \[\leadsto \frac{\color{blue}{-\left(2 \cdot \left(a \cdot K\right) + \left(2 \cdot \left({a}^{3} \cdot K\right) + 2 \cdot \left({a}^{2} \cdot K\right)\right)\right)}}{2 \cdot \sqrt{1 - a \cdot \left(\left(2 - a\right) - 4 \cdot K\right)}}\]
    4. Simplified9.3

      \[\leadsto \frac{\color{blue}{\left(\left(a \cdot K\right) \cdot a\right) \cdot \left(\left(-2\right) - 2 \cdot a\right) + \left(-2\right) \cdot \left(a \cdot K\right)}}{2 \cdot \sqrt{1 - a \cdot \left(\left(2 - a\right) - 4 \cdot K\right)}}\]
    5. Taylor expanded around 0 9.5

      \[\leadsto \color{blue}{-\left(a \cdot K + \left(3 \cdot \left({a}^{3} \cdot K\right) + 2 \cdot \left({a}^{2} \cdot K\right)\right)\right)}\]
    6. Simplified9.5

      \[\leadsto \color{blue}{\left(\left(a \cdot a\right) \cdot \left(-K\right)\right) \cdot \left(3 \cdot a + 2\right) - a \cdot K}\]

    if 5.177159287427985e-16 < a

    1. Initial program 36.7

      \[\frac{\left(1 - a\right) - \sqrt{\left(\left(1 - 2 \cdot a\right) + \left(4 \cdot K\right) \cdot a\right) + {a}^{2}}}{2 \cdot \sqrt{\left(\left(1 - 2 \cdot a\right) + \left(4 \cdot K\right) \cdot a\right) + {a}^{2}}}\]
    2. Initial simplification36.7

      \[\leadsto \frac{\left(1 - a\right) - \sqrt{1 - a \cdot \left(\left(2 - a\right) - 4 \cdot K\right)}}{2 \cdot \sqrt{1 - a \cdot \left(\left(2 - a\right) - 4 \cdot K\right)}}\]
    3. Using strategy rm
    4. Applied associate--l-36.7

      \[\leadsto \frac{\color{blue}{1 - \left(a + \sqrt{1 - a \cdot \left(\left(2 - a\right) - 4 \cdot K\right)}\right)}}{2 \cdot \sqrt{1 - a \cdot \left(\left(2 - a\right) - 4 \cdot K\right)}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification20.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \le -0.0029571681252933773:\\ \;\;\;\;\frac{2 \cdot \left(\frac{\frac{K}{a}}{a} + \left(\frac{K}{a} + K\right)\right)}{\sqrt{1 - a \cdot \left(\left(2 - a\right) - K \cdot 4\right)} \cdot 2}\\ \mathbf{elif}\;a \le 5.177159287427985 \cdot 10^{-16}:\\ \;\;\;\;\left(a \cdot 3 + 2\right) \cdot \left(\left(a \cdot a\right) \cdot \left(-K\right)\right) - K \cdot a\\ \mathbf{else}:\\ \;\;\;\;\frac{1 - \left(\sqrt{1 - a \cdot \left(\left(2 - a\right) - K \cdot 4\right)} + a\right)}{\sqrt{1 - a \cdot \left(\left(2 - a\right) - K \cdot 4\right)} \cdot 2}\\ \end{array}\]

Runtime

Time bar (total: 53.0s)Debug log

herbie shell --seed '#(2775764126 3555076145 3898259844 1891440260 2599947619 1948460636)' 
(FPCore (a K)
  :name "(1 - a - sqrt(1-2*a+4*K*a+a^2))/(2*sqrt(1-2*a+4*K*a+a^2))"
  (/ (- (- 1 a) (sqrt (+ (+ (- 1 (* 2 a)) (* (* 4 K) a)) (pow a 2)))) (* 2 (sqrt (+ (+ (- 1 (* 2 a)) (* (* 4 K) a)) (pow a 2))))))