Average Error: 29.9 → 7.6
Time: 18.0s
Precision: 64
\[\sqrt{1 - \cos x \cdot \cos x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.01582460057993370985962577890404645586386:\\ \;\;\;\;\sqrt{\frac{{\left(1 - \frac{1}{2}\right)}^{3} - {\left(\frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right)}^{3}}{\left(1 - \frac{1}{2}\right) \cdot \left(1 - \frac{1}{2}\right) + \left(\frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right) \cdot \left(\left(1 - \frac{1}{2}\right) + \frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right)}}\\ \mathbf{elif}\;x \le 6.006836929901048229584203904238188713098 \cdot 10^{-310}:\\ \;\;\;\;\sqrt{\left({x}^{2} + \frac{2}{45} \cdot {x}^{6}\right) - \frac{1}{3} \cdot {x}^{4}}\\ \mathbf{elif}\;x \le 0.01918014872001604781415196043781179469079:\\ \;\;\;\;\left(x + \frac{1}{120} \cdot {x}^{5}\right) - \frac{1}{6} \cdot {x}^{3}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\frac{{\left(1 - \frac{1}{2}\right)}^{3} - {\left(\frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right)}^{3}}{\left(1 - \frac{1}{2}\right) \cdot \left(1 - \frac{1}{2}\right) + \left(\frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right) \cdot \left(\left(1 - \frac{1}{2}\right) + \frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right)}}\\ \end{array}\]
\sqrt{1 - \cos x \cdot \cos x}
\begin{array}{l}
\mathbf{if}\;x \le -0.01582460057993370985962577890404645586386:\\
\;\;\;\;\sqrt{\frac{{\left(1 - \frac{1}{2}\right)}^{3} - {\left(\frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right)}^{3}}{\left(1 - \frac{1}{2}\right) \cdot \left(1 - \frac{1}{2}\right) + \left(\frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right) \cdot \left(\left(1 - \frac{1}{2}\right) + \frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right)}}\\

\mathbf{elif}\;x \le 6.006836929901048229584203904238188713098 \cdot 10^{-310}:\\
\;\;\;\;\sqrt{\left({x}^{2} + \frac{2}{45} \cdot {x}^{6}\right) - \frac{1}{3} \cdot {x}^{4}}\\

\mathbf{elif}\;x \le 0.01918014872001604781415196043781179469079:\\
\;\;\;\;\left(x + \frac{1}{120} \cdot {x}^{5}\right) - \frac{1}{6} \cdot {x}^{3}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{{\left(1 - \frac{1}{2}\right)}^{3} - {\left(\frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right)}^{3}}{\left(1 - \frac{1}{2}\right) \cdot \left(1 - \frac{1}{2}\right) + \left(\frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right) \cdot \left(\left(1 - \frac{1}{2}\right) + \frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right)}}\\

\end{array}
double f(double x) {
        double r3409101 = 1.0;
        double r3409102 = x;
        double r3409103 = cos(r3409102);
        double r3409104 = r3409103 * r3409103;
        double r3409105 = r3409101 - r3409104;
        double r3409106 = sqrt(r3409105);
        return r3409106;
}

double f(double x) {
        double r3409107 = x;
        double r3409108 = -0.01582460057993371;
        bool r3409109 = r3409107 <= r3409108;
        double r3409110 = 1.0;
        double r3409111 = 0.5;
        double r3409112 = r3409110 - r3409111;
        double r3409113 = 3.0;
        double r3409114 = pow(r3409112, r3409113);
        double r3409115 = 2.0;
        double r3409116 = r3409115 * r3409107;
        double r3409117 = cos(r3409116);
        double r3409118 = r3409111 * r3409117;
        double r3409119 = pow(r3409118, r3409113);
        double r3409120 = r3409114 - r3409119;
        double r3409121 = r3409112 * r3409112;
        double r3409122 = r3409112 + r3409118;
        double r3409123 = r3409118 * r3409122;
        double r3409124 = r3409121 + r3409123;
        double r3409125 = r3409120 / r3409124;
        double r3409126 = sqrt(r3409125);
        double r3409127 = 6.00683692990105e-310;
        bool r3409128 = r3409107 <= r3409127;
        double r3409129 = pow(r3409107, r3409115);
        double r3409130 = 0.044444444444444446;
        double r3409131 = 6.0;
        double r3409132 = pow(r3409107, r3409131);
        double r3409133 = r3409130 * r3409132;
        double r3409134 = r3409129 + r3409133;
        double r3409135 = 0.3333333333333333;
        double r3409136 = 4.0;
        double r3409137 = pow(r3409107, r3409136);
        double r3409138 = r3409135 * r3409137;
        double r3409139 = r3409134 - r3409138;
        double r3409140 = sqrt(r3409139);
        double r3409141 = 0.019180148720016048;
        bool r3409142 = r3409107 <= r3409141;
        double r3409143 = 0.008333333333333333;
        double r3409144 = 5.0;
        double r3409145 = pow(r3409107, r3409144);
        double r3409146 = r3409143 * r3409145;
        double r3409147 = r3409107 + r3409146;
        double r3409148 = 0.16666666666666666;
        double r3409149 = pow(r3409107, r3409113);
        double r3409150 = r3409148 * r3409149;
        double r3409151 = r3409147 - r3409150;
        double r3409152 = r3409142 ? r3409151 : r3409126;
        double r3409153 = r3409128 ? r3409140 : r3409152;
        double r3409154 = r3409109 ? r3409126 : r3409153;
        return r3409154;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 3 regimes
  2. if x < -0.01582460057993371 or 0.019180148720016048 < x

    1. Initial program 1.1

      \[\sqrt{1 - \cos x \cdot \cos x}\]
    2. Using strategy rm
    3. Applied sqr-cos1.0

      \[\leadsto \sqrt{1 - \color{blue}{\left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right)}}\]
    4. Applied associate--r+0.7

      \[\leadsto \sqrt{\color{blue}{\left(1 - \frac{1}{2}\right) - \frac{1}{2} \cdot \cos \left(2 \cdot x\right)}}\]
    5. Using strategy rm
    6. Applied flip3--0.8

      \[\leadsto \sqrt{\color{blue}{\frac{{\left(1 - \frac{1}{2}\right)}^{3} - {\left(\frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right)}^{3}}{\left(1 - \frac{1}{2}\right) \cdot \left(1 - \frac{1}{2}\right) + \left(\left(\frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right) \cdot \left(\frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right) + \left(1 - \frac{1}{2}\right) \cdot \left(\frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right)\right)}}}\]
    7. Simplified0.8

      \[\leadsto \sqrt{\frac{{\left(1 - \frac{1}{2}\right)}^{3} - {\left(\frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right)}^{3}}{\color{blue}{\left(1 - \frac{1}{2}\right) \cdot \left(1 - \frac{1}{2}\right) + \left(\frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right) \cdot \left(\left(1 - \frac{1}{2}\right) + \frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right)}}}\]

    if -0.01582460057993371 < x < 6.00683692990105e-310

    1. Initial program 59.8

      \[\sqrt{1 - \cos x \cdot \cos x}\]
    2. Taylor expanded around 0 29.2

      \[\leadsto \sqrt{\color{blue}{\left({x}^{2} + \frac{2}{45} \cdot {x}^{6}\right) - \frac{1}{3} \cdot {x}^{4}}}\]

    if 6.00683692990105e-310 < x < 0.019180148720016048

    1. Initial program 59.7

      \[\sqrt{1 - \cos x \cdot \cos x}\]
    2. Taylor expanded around 0 0.0

      \[\leadsto \color{blue}{\left(x + \frac{1}{120} \cdot {x}^{5}\right) - \frac{1}{6} \cdot {x}^{3}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification7.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -0.01582460057993370985962577890404645586386:\\ \;\;\;\;\sqrt{\frac{{\left(1 - \frac{1}{2}\right)}^{3} - {\left(\frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right)}^{3}}{\left(1 - \frac{1}{2}\right) \cdot \left(1 - \frac{1}{2}\right) + \left(\frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right) \cdot \left(\left(1 - \frac{1}{2}\right) + \frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right)}}\\ \mathbf{elif}\;x \le 6.006836929901048229584203904238188713098 \cdot 10^{-310}:\\ \;\;\;\;\sqrt{\left({x}^{2} + \frac{2}{45} \cdot {x}^{6}\right) - \frac{1}{3} \cdot {x}^{4}}\\ \mathbf{elif}\;x \le 0.01918014872001604781415196043781179469079:\\ \;\;\;\;\left(x + \frac{1}{120} \cdot {x}^{5}\right) - \frac{1}{6} \cdot {x}^{3}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\frac{{\left(1 - \frac{1}{2}\right)}^{3} - {\left(\frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right)}^{3}}{\left(1 - \frac{1}{2}\right) \cdot \left(1 - \frac{1}{2}\right) + \left(\frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right) \cdot \left(\left(1 - \frac{1}{2}\right) + \frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right)}}\\ \end{array}\]

Reproduce

herbie shell --seed 1 
(FPCore (x)
  :name "sqrt(1-cos(x)*cos(x))"
  :precision binary64
  (sqrt (- 1 (* (cos x) (cos x)))))