Migdal et al, Equation (51)

Percentage Accurate: 99.4% → 99.4%
Time: 8.6s
Alternatives: 9
Speedup: 1.1×

Specification

?
\[\begin{array}{l} \\ \frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \end{array} \]
(FPCore (k n)
 :precision binary64
 (* (/ 1.0 (sqrt k)) (pow (* (* 2.0 (PI)) n) (/ (- 1.0 k) 2.0))))
\begin{array}{l}

\\
\frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)}
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 9 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 99.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \end{array} \]
(FPCore (k n)
 :precision binary64
 (* (/ 1.0 (sqrt k)) (pow (* (* 2.0 (PI)) n) (/ (- 1.0 k) 2.0))))
\begin{array}{l}

\\
\frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)}
\end{array}

Alternative 1: 99.4% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \frac{{\left(\left(2 \cdot n\right) \cdot \mathsf{PI}\left(\right)\right)}^{\left(\mathsf{fma}\left(k, -0.5, 0.5\right)\right)}}{\sqrt{k}} \end{array} \]
(FPCore (k n)
 :precision binary64
 (/ (pow (* (* 2.0 n) (PI)) (fma k -0.5 0.5)) (sqrt k)))
\begin{array}{l}

\\
\frac{{\left(\left(2 \cdot n\right) \cdot \mathsf{PI}\left(\right)\right)}^{\left(\mathsf{fma}\left(k, -0.5, 0.5\right)\right)}}{\sqrt{k}}
\end{array}
Derivation
  1. Initial program 99.6%

    \[\frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \]
  2. Add Preprocessing
  3. Taylor expanded in k around inf

    \[\leadsto \color{blue}{\sqrt{\frac{1}{k}} \cdot e^{\frac{1}{2} \cdot \left(\log \left(2 \cdot \left(n \cdot \mathsf{PI}\left(\right)\right)\right) \cdot \left(1 - k\right)\right)}} \]
  4. Step-by-step derivation
    1. *-commutativeN/A

      \[\leadsto \color{blue}{e^{\frac{1}{2} \cdot \left(\log \left(2 \cdot \left(n \cdot \mathsf{PI}\left(\right)\right)\right) \cdot \left(1 - k\right)\right)} \cdot \sqrt{\frac{1}{k}}} \]
    2. lower-*.f64N/A

      \[\leadsto \color{blue}{e^{\frac{1}{2} \cdot \left(\log \left(2 \cdot \left(n \cdot \mathsf{PI}\left(\right)\right)\right) \cdot \left(1 - k\right)\right)} \cdot \sqrt{\frac{1}{k}}} \]
  5. Applied rewrites99.6%

    \[\leadsto \color{blue}{{\left(\left(2 \cdot n\right) \cdot \mathsf{PI}\left(\right)\right)}^{\left(\mathsf{fma}\left(-0.5, k, 0.5\right)\right)} \cdot \sqrt{\frac{1}{k}}} \]
  6. Step-by-step derivation
    1. Applied rewrites99.6%

      \[\leadsto \frac{{\left(\mathsf{PI}\left(\right) \cdot \left(n \cdot 2\right)\right)}^{\left(\mathsf{fma}\left(-0.5, k, 0.5\right)\right)} \cdot 1}{\color{blue}{\sqrt{k}}} \]
    2. Step-by-step derivation
      1. Applied rewrites99.6%

        \[\leadsto \frac{{\left(\left(2 \cdot n\right) \cdot \mathsf{PI}\left(\right)\right)}^{\left(\mathsf{fma}\left(k, -0.5, 0.5\right)\right)}}{\sqrt{\color{blue}{k}}} \]
      2. Add Preprocessing

      Alternative 2: 97.4% accurate, 0.2× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} t_0 := {\left(\sqrt{k}\right)}^{-1} \cdot {\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)}\\ \mathbf{if}\;t\_0 \leq 0:\\ \;\;\;\;\frac{0}{\sqrt{k}}\\ \mathbf{elif}\;t\_0 \leq 4 \cdot 10^{+277}:\\ \;\;\;\;\sqrt{\frac{\mathsf{PI}\left(\right)}{k}} \cdot \sqrt{2 \cdot n}\\ \mathbf{else}:\\ \;\;\;\;\frac{{0}^{\left(\mathsf{fma}\left(k, -0.5, 0.5\right)\right)}}{\sqrt{k}}\\ \end{array} \end{array} \]
      (FPCore (k n)
       :precision binary64
       (let* ((t_0
               (* (pow (sqrt k) -1.0) (pow (* (* 2.0 (PI)) n) (/ (- 1.0 k) 2.0)))))
         (if (<= t_0 0.0)
           (/ 0.0 (sqrt k))
           (if (<= t_0 4e+277)
             (* (sqrt (/ (PI) k)) (sqrt (* 2.0 n)))
             (/ (pow 0.0 (fma k -0.5 0.5)) (sqrt k))))))
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      t_0 := {\left(\sqrt{k}\right)}^{-1} \cdot {\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)}\\
      \mathbf{if}\;t\_0 \leq 0:\\
      \;\;\;\;\frac{0}{\sqrt{k}}\\
      
      \mathbf{elif}\;t\_0 \leq 4 \cdot 10^{+277}:\\
      \;\;\;\;\sqrt{\frac{\mathsf{PI}\left(\right)}{k}} \cdot \sqrt{2 \cdot n}\\
      
      \mathbf{else}:\\
      \;\;\;\;\frac{{0}^{\left(\mathsf{fma}\left(k, -0.5, 0.5\right)\right)}}{\sqrt{k}}\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 3 regimes
      2. if (*.f64 (/.f64 #s(literal 1 binary64) (sqrt.f64 k)) (pow.f64 (*.f64 (*.f64 #s(literal 2 binary64) (PI.f64)) n) (/.f64 (-.f64 #s(literal 1 binary64) k) #s(literal 2 binary64)))) < 0.0

        1. Initial program 100.0%

          \[\frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \]
        2. Add Preprocessing
        3. Taylor expanded in k around 0

          \[\leadsto \frac{1}{\sqrt{k}} \cdot \color{blue}{\left(\sqrt{n \cdot \mathsf{PI}\left(\right)} \cdot \sqrt{2}\right)} \]
        4. Step-by-step derivation
          1. lower-*.f64N/A

            \[\leadsto \frac{1}{\sqrt{k}} \cdot \color{blue}{\left(\sqrt{n \cdot \mathsf{PI}\left(\right)} \cdot \sqrt{2}\right)} \]
          2. lower-sqrt.f64N/A

            \[\leadsto \frac{1}{\sqrt{k}} \cdot \left(\color{blue}{\sqrt{n \cdot \mathsf{PI}\left(\right)}} \cdot \sqrt{2}\right) \]
          3. *-commutativeN/A

            \[\leadsto \frac{1}{\sqrt{k}} \cdot \left(\sqrt{\color{blue}{\mathsf{PI}\left(\right) \cdot n}} \cdot \sqrt{2}\right) \]
          4. lower-*.f64N/A

            \[\leadsto \frac{1}{\sqrt{k}} \cdot \left(\sqrt{\color{blue}{\mathsf{PI}\left(\right) \cdot n}} \cdot \sqrt{2}\right) \]
          5. lower-PI.f64N/A

            \[\leadsto \frac{1}{\sqrt{k}} \cdot \left(\sqrt{\color{blue}{\mathsf{PI}\left(\right)} \cdot n} \cdot \sqrt{2}\right) \]
          6. lower-sqrt.f643.2

            \[\leadsto \frac{1}{\sqrt{k}} \cdot \left(\sqrt{\mathsf{PI}\left(\right) \cdot n} \cdot \color{blue}{\sqrt{2}}\right) \]
        5. Applied rewrites3.2%

          \[\leadsto \frac{1}{\sqrt{k}} \cdot \color{blue}{\left(\sqrt{\mathsf{PI}\left(\right) \cdot n} \cdot \sqrt{2}\right)} \]
        6. Step-by-step derivation
          1. Applied rewrites3.2%

            \[\leadsto \frac{1}{\sqrt{k}} \cdot \left(\sqrt{\left(\sqrt{\mathsf{PI}\left(\right)} \cdot \sqrt{\mathsf{PI}\left(\right)}\right) \cdot n} \cdot \sqrt{2}\right) \]
          2. Applied rewrites100.0%

            \[\leadsto \color{blue}{\frac{0}{\sqrt{k}}} \]

          if 0.0 < (*.f64 (/.f64 #s(literal 1 binary64) (sqrt.f64 k)) (pow.f64 (*.f64 (*.f64 #s(literal 2 binary64) (PI.f64)) n) (/.f64 (-.f64 #s(literal 1 binary64) k) #s(literal 2 binary64)))) < 4.00000000000000001e277

          1. Initial program 99.1%

            \[\frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \]
          2. Add Preprocessing
          3. Taylor expanded in k around 0

            \[\leadsto \color{blue}{\sqrt{\frac{n \cdot \mathsf{PI}\left(\right)}{k}} \cdot \sqrt{2}} \]
          4. Step-by-step derivation
            1. *-commutativeN/A

              \[\leadsto \color{blue}{\sqrt{2} \cdot \sqrt{\frac{n \cdot \mathsf{PI}\left(\right)}{k}}} \]
            2. lower-*.f64N/A

              \[\leadsto \color{blue}{\sqrt{2} \cdot \sqrt{\frac{n \cdot \mathsf{PI}\left(\right)}{k}}} \]
            3. lower-sqrt.f64N/A

              \[\leadsto \color{blue}{\sqrt{2}} \cdot \sqrt{\frac{n \cdot \mathsf{PI}\left(\right)}{k}} \]
            4. lower-sqrt.f64N/A

              \[\leadsto \sqrt{2} \cdot \color{blue}{\sqrt{\frac{n \cdot \mathsf{PI}\left(\right)}{k}}} \]
            5. lower-/.f64N/A

              \[\leadsto \sqrt{2} \cdot \sqrt{\color{blue}{\frac{n \cdot \mathsf{PI}\left(\right)}{k}}} \]
            6. *-commutativeN/A

              \[\leadsto \sqrt{2} \cdot \sqrt{\frac{\color{blue}{\mathsf{PI}\left(\right) \cdot n}}{k}} \]
            7. lower-*.f64N/A

              \[\leadsto \sqrt{2} \cdot \sqrt{\frac{\color{blue}{\mathsf{PI}\left(\right) \cdot n}}{k}} \]
            8. lower-PI.f6473.2

              \[\leadsto \sqrt{2} \cdot \sqrt{\frac{\color{blue}{\mathsf{PI}\left(\right)} \cdot n}{k}} \]
          5. Applied rewrites73.2%

            \[\leadsto \color{blue}{\sqrt{2} \cdot \sqrt{\frac{\mathsf{PI}\left(\right) \cdot n}{k}}} \]
          6. Step-by-step derivation
            1. Applied rewrites73.3%

              \[\leadsto \color{blue}{\sqrt{\frac{\mathsf{PI}\left(\right) \cdot n}{k} \cdot 2}} \]
            2. Step-by-step derivation
              1. Applied rewrites97.2%

                \[\leadsto \sqrt{\frac{\mathsf{PI}\left(\right)}{k}} \cdot \color{blue}{\sqrt{2 \cdot n}} \]

              if 4.00000000000000001e277 < (*.f64 (/.f64 #s(literal 1 binary64) (sqrt.f64 k)) (pow.f64 (*.f64 (*.f64 #s(literal 2 binary64) (PI.f64)) n) (/.f64 (-.f64 #s(literal 1 binary64) k) #s(literal 2 binary64))))

              1. Initial program 100.0%

                \[\frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \]
              2. Add Preprocessing
              3. Taylor expanded in k around inf

                \[\leadsto \color{blue}{\sqrt{\frac{1}{k}} \cdot e^{\frac{1}{2} \cdot \left(\log \left(2 \cdot \left(n \cdot \mathsf{PI}\left(\right)\right)\right) \cdot \left(1 - k\right)\right)}} \]
              4. Step-by-step derivation
                1. *-commutativeN/A

                  \[\leadsto \color{blue}{e^{\frac{1}{2} \cdot \left(\log \left(2 \cdot \left(n \cdot \mathsf{PI}\left(\right)\right)\right) \cdot \left(1 - k\right)\right)} \cdot \sqrt{\frac{1}{k}}} \]
                2. lower-*.f64N/A

                  \[\leadsto \color{blue}{e^{\frac{1}{2} \cdot \left(\log \left(2 \cdot \left(n \cdot \mathsf{PI}\left(\right)\right)\right) \cdot \left(1 - k\right)\right)} \cdot \sqrt{\frac{1}{k}}} \]
              5. Applied rewrites100.0%

                \[\leadsto \color{blue}{{\left(\left(2 \cdot n\right) \cdot \mathsf{PI}\left(\right)\right)}^{\left(\mathsf{fma}\left(-0.5, k, 0.5\right)\right)} \cdot \sqrt{\frac{1}{k}}} \]
              6. Step-by-step derivation
                1. Applied rewrites100.0%

                  \[\leadsto \frac{{\left(\mathsf{PI}\left(\right) \cdot \left(n \cdot 2\right)\right)}^{\left(\mathsf{fma}\left(-0.5, k, 0.5\right)\right)} \cdot 1}{\color{blue}{\sqrt{k}}} \]
                2. Step-by-step derivation
                  1. Applied rewrites100.0%

                    \[\leadsto \frac{{\left(\left(2 \cdot n\right) \cdot \mathsf{PI}\left(\right)\right)}^{\left(\mathsf{fma}\left(k, -0.5, 0.5\right)\right)}}{\sqrt{\color{blue}{k}}} \]
                  2. Step-by-step derivation
                    1. Applied rewrites100.0%

                      \[\leadsto \frac{{0}^{\left(\mathsf{fma}\left(k, -0.5, 0.5\right)\right)}}{\sqrt{k}} \]
                  3. Recombined 3 regimes into one program.
                  4. Final simplification98.5%

                    \[\leadsto \begin{array}{l} \mathbf{if}\;{\left(\sqrt{k}\right)}^{-1} \cdot {\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \leq 0:\\ \;\;\;\;\frac{0}{\sqrt{k}}\\ \mathbf{elif}\;{\left(\sqrt{k}\right)}^{-1} \cdot {\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \leq 4 \cdot 10^{+277}:\\ \;\;\;\;\sqrt{\frac{\mathsf{PI}\left(\right)}{k}} \cdot \sqrt{2 \cdot n}\\ \mathbf{else}:\\ \;\;\;\;\frac{{0}^{\left(\mathsf{fma}\left(k, -0.5, 0.5\right)\right)}}{\sqrt{k}}\\ \end{array} \]
                  5. Add Preprocessing

                  Alternative 3: 73.9% accurate, 0.5× speedup?

                  \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;{\left(\sqrt{k}\right)}^{-1} \cdot {\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \leq 0:\\ \;\;\;\;\frac{0}{\sqrt{k}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\frac{\mathsf{PI}\left(\right)}{k}} \cdot \sqrt{2 \cdot n}\\ \end{array} \end{array} \]
                  (FPCore (k n)
                   :precision binary64
                   (if (<=
                        (* (pow (sqrt k) -1.0) (pow (* (* 2.0 (PI)) n) (/ (- 1.0 k) 2.0)))
                        0.0)
                     (/ 0.0 (sqrt k))
                     (* (sqrt (/ (PI) k)) (sqrt (* 2.0 n)))))
                  \begin{array}{l}
                  
                  \\
                  \begin{array}{l}
                  \mathbf{if}\;{\left(\sqrt{k}\right)}^{-1} \cdot {\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \leq 0:\\
                  \;\;\;\;\frac{0}{\sqrt{k}}\\
                  
                  \mathbf{else}:\\
                  \;\;\;\;\sqrt{\frac{\mathsf{PI}\left(\right)}{k}} \cdot \sqrt{2 \cdot n}\\
                  
                  
                  \end{array}
                  \end{array}
                  
                  Derivation
                  1. Split input into 2 regimes
                  2. if (*.f64 (/.f64 #s(literal 1 binary64) (sqrt.f64 k)) (pow.f64 (*.f64 (*.f64 #s(literal 2 binary64) (PI.f64)) n) (/.f64 (-.f64 #s(literal 1 binary64) k) #s(literal 2 binary64)))) < 0.0

                    1. Initial program 100.0%

                      \[\frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \]
                    2. Add Preprocessing
                    3. Taylor expanded in k around 0

                      \[\leadsto \frac{1}{\sqrt{k}} \cdot \color{blue}{\left(\sqrt{n \cdot \mathsf{PI}\left(\right)} \cdot \sqrt{2}\right)} \]
                    4. Step-by-step derivation
                      1. lower-*.f64N/A

                        \[\leadsto \frac{1}{\sqrt{k}} \cdot \color{blue}{\left(\sqrt{n \cdot \mathsf{PI}\left(\right)} \cdot \sqrt{2}\right)} \]
                      2. lower-sqrt.f64N/A

                        \[\leadsto \frac{1}{\sqrt{k}} \cdot \left(\color{blue}{\sqrt{n \cdot \mathsf{PI}\left(\right)}} \cdot \sqrt{2}\right) \]
                      3. *-commutativeN/A

                        \[\leadsto \frac{1}{\sqrt{k}} \cdot \left(\sqrt{\color{blue}{\mathsf{PI}\left(\right) \cdot n}} \cdot \sqrt{2}\right) \]
                      4. lower-*.f64N/A

                        \[\leadsto \frac{1}{\sqrt{k}} \cdot \left(\sqrt{\color{blue}{\mathsf{PI}\left(\right) \cdot n}} \cdot \sqrt{2}\right) \]
                      5. lower-PI.f64N/A

                        \[\leadsto \frac{1}{\sqrt{k}} \cdot \left(\sqrt{\color{blue}{\mathsf{PI}\left(\right)} \cdot n} \cdot \sqrt{2}\right) \]
                      6. lower-sqrt.f643.2

                        \[\leadsto \frac{1}{\sqrt{k}} \cdot \left(\sqrt{\mathsf{PI}\left(\right) \cdot n} \cdot \color{blue}{\sqrt{2}}\right) \]
                    5. Applied rewrites3.2%

                      \[\leadsto \frac{1}{\sqrt{k}} \cdot \color{blue}{\left(\sqrt{\mathsf{PI}\left(\right) \cdot n} \cdot \sqrt{2}\right)} \]
                    6. Step-by-step derivation
                      1. Applied rewrites3.2%

                        \[\leadsto \frac{1}{\sqrt{k}} \cdot \left(\sqrt{\left(\sqrt{\mathsf{PI}\left(\right)} \cdot \sqrt{\mathsf{PI}\left(\right)}\right) \cdot n} \cdot \sqrt{2}\right) \]
                      2. Applied rewrites100.0%

                        \[\leadsto \color{blue}{\frac{0}{\sqrt{k}}} \]

                      if 0.0 < (*.f64 (/.f64 #s(literal 1 binary64) (sqrt.f64 k)) (pow.f64 (*.f64 (*.f64 #s(literal 2 binary64) (PI.f64)) n) (/.f64 (-.f64 #s(literal 1 binary64) k) #s(literal 2 binary64))))

                      1. Initial program 99.4%

                        \[\frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \]
                      2. Add Preprocessing
                      3. Taylor expanded in k around 0

                        \[\leadsto \color{blue}{\sqrt{\frac{n \cdot \mathsf{PI}\left(\right)}{k}} \cdot \sqrt{2}} \]
                      4. Step-by-step derivation
                        1. *-commutativeN/A

                          \[\leadsto \color{blue}{\sqrt{2} \cdot \sqrt{\frac{n \cdot \mathsf{PI}\left(\right)}{k}}} \]
                        2. lower-*.f64N/A

                          \[\leadsto \color{blue}{\sqrt{2} \cdot \sqrt{\frac{n \cdot \mathsf{PI}\left(\right)}{k}}} \]
                        3. lower-sqrt.f64N/A

                          \[\leadsto \color{blue}{\sqrt{2}} \cdot \sqrt{\frac{n \cdot \mathsf{PI}\left(\right)}{k}} \]
                        4. lower-sqrt.f64N/A

                          \[\leadsto \sqrt{2} \cdot \color{blue}{\sqrt{\frac{n \cdot \mathsf{PI}\left(\right)}{k}}} \]
                        5. lower-/.f64N/A

                          \[\leadsto \sqrt{2} \cdot \sqrt{\color{blue}{\frac{n \cdot \mathsf{PI}\left(\right)}{k}}} \]
                        6. *-commutativeN/A

                          \[\leadsto \sqrt{2} \cdot \sqrt{\frac{\color{blue}{\mathsf{PI}\left(\right) \cdot n}}{k}} \]
                        7. lower-*.f64N/A

                          \[\leadsto \sqrt{2} \cdot \sqrt{\frac{\color{blue}{\mathsf{PI}\left(\right) \cdot n}}{k}} \]
                        8. lower-PI.f6451.1

                          \[\leadsto \sqrt{2} \cdot \sqrt{\frac{\color{blue}{\mathsf{PI}\left(\right)} \cdot n}{k}} \]
                      5. Applied rewrites51.1%

                        \[\leadsto \color{blue}{\sqrt{2} \cdot \sqrt{\frac{\mathsf{PI}\left(\right) \cdot n}{k}}} \]
                      6. Step-by-step derivation
                        1. Applied rewrites51.2%

                          \[\leadsto \color{blue}{\sqrt{\frac{\mathsf{PI}\left(\right) \cdot n}{k} \cdot 2}} \]
                        2. Step-by-step derivation
                          1. Applied rewrites67.7%

                            \[\leadsto \sqrt{\frac{\mathsf{PI}\left(\right)}{k}} \cdot \color{blue}{\sqrt{2 \cdot n}} \]
                        3. Recombined 2 regimes into one program.
                        4. Final simplification75.6%

                          \[\leadsto \begin{array}{l} \mathbf{if}\;{\left(\sqrt{k}\right)}^{-1} \cdot {\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \leq 0:\\ \;\;\;\;\frac{0}{\sqrt{k}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\frac{\mathsf{PI}\left(\right)}{k}} \cdot \sqrt{2 \cdot n}\\ \end{array} \]
                        5. Add Preprocessing

                        Alternative 4: 73.8% accurate, 0.5× speedup?

                        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;{\left(\sqrt{k}\right)}^{-1} \cdot {\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \leq 0:\\ \;\;\;\;\frac{0}{\sqrt{k}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{n \cdot \mathsf{PI}\left(\right)} \cdot \sqrt{\frac{2}{k}}\\ \end{array} \end{array} \]
                        (FPCore (k n)
                         :precision binary64
                         (if (<=
                              (* (pow (sqrt k) -1.0) (pow (* (* 2.0 (PI)) n) (/ (- 1.0 k) 2.0)))
                              0.0)
                           (/ 0.0 (sqrt k))
                           (* (sqrt (* n (PI))) (sqrt (/ 2.0 k)))))
                        \begin{array}{l}
                        
                        \\
                        \begin{array}{l}
                        \mathbf{if}\;{\left(\sqrt{k}\right)}^{-1} \cdot {\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \leq 0:\\
                        \;\;\;\;\frac{0}{\sqrt{k}}\\
                        
                        \mathbf{else}:\\
                        \;\;\;\;\sqrt{n \cdot \mathsf{PI}\left(\right)} \cdot \sqrt{\frac{2}{k}}\\
                        
                        
                        \end{array}
                        \end{array}
                        
                        Derivation
                        1. Split input into 2 regimes
                        2. if (*.f64 (/.f64 #s(literal 1 binary64) (sqrt.f64 k)) (pow.f64 (*.f64 (*.f64 #s(literal 2 binary64) (PI.f64)) n) (/.f64 (-.f64 #s(literal 1 binary64) k) #s(literal 2 binary64)))) < 0.0

                          1. Initial program 100.0%

                            \[\frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \]
                          2. Add Preprocessing
                          3. Taylor expanded in k around 0

                            \[\leadsto \frac{1}{\sqrt{k}} \cdot \color{blue}{\left(\sqrt{n \cdot \mathsf{PI}\left(\right)} \cdot \sqrt{2}\right)} \]
                          4. Step-by-step derivation
                            1. lower-*.f64N/A

                              \[\leadsto \frac{1}{\sqrt{k}} \cdot \color{blue}{\left(\sqrt{n \cdot \mathsf{PI}\left(\right)} \cdot \sqrt{2}\right)} \]
                            2. lower-sqrt.f64N/A

                              \[\leadsto \frac{1}{\sqrt{k}} \cdot \left(\color{blue}{\sqrt{n \cdot \mathsf{PI}\left(\right)}} \cdot \sqrt{2}\right) \]
                            3. *-commutativeN/A

                              \[\leadsto \frac{1}{\sqrt{k}} \cdot \left(\sqrt{\color{blue}{\mathsf{PI}\left(\right) \cdot n}} \cdot \sqrt{2}\right) \]
                            4. lower-*.f64N/A

                              \[\leadsto \frac{1}{\sqrt{k}} \cdot \left(\sqrt{\color{blue}{\mathsf{PI}\left(\right) \cdot n}} \cdot \sqrt{2}\right) \]
                            5. lower-PI.f64N/A

                              \[\leadsto \frac{1}{\sqrt{k}} \cdot \left(\sqrt{\color{blue}{\mathsf{PI}\left(\right)} \cdot n} \cdot \sqrt{2}\right) \]
                            6. lower-sqrt.f643.2

                              \[\leadsto \frac{1}{\sqrt{k}} \cdot \left(\sqrt{\mathsf{PI}\left(\right) \cdot n} \cdot \color{blue}{\sqrt{2}}\right) \]
                          5. Applied rewrites3.2%

                            \[\leadsto \frac{1}{\sqrt{k}} \cdot \color{blue}{\left(\sqrt{\mathsf{PI}\left(\right) \cdot n} \cdot \sqrt{2}\right)} \]
                          6. Step-by-step derivation
                            1. Applied rewrites3.2%

                              \[\leadsto \frac{1}{\sqrt{k}} \cdot \left(\sqrt{\left(\sqrt{\mathsf{PI}\left(\right)} \cdot \sqrt{\mathsf{PI}\left(\right)}\right) \cdot n} \cdot \sqrt{2}\right) \]
                            2. Applied rewrites100.0%

                              \[\leadsto \color{blue}{\frac{0}{\sqrt{k}}} \]

                            if 0.0 < (*.f64 (/.f64 #s(literal 1 binary64) (sqrt.f64 k)) (pow.f64 (*.f64 (*.f64 #s(literal 2 binary64) (PI.f64)) n) (/.f64 (-.f64 #s(literal 1 binary64) k) #s(literal 2 binary64))))

                            1. Initial program 99.4%

                              \[\frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \]
                            2. Add Preprocessing
                            3. Taylor expanded in k around 0

                              \[\leadsto \color{blue}{\sqrt{\frac{n \cdot \mathsf{PI}\left(\right)}{k}} \cdot \sqrt{2}} \]
                            4. Step-by-step derivation
                              1. *-commutativeN/A

                                \[\leadsto \color{blue}{\sqrt{2} \cdot \sqrt{\frac{n \cdot \mathsf{PI}\left(\right)}{k}}} \]
                              2. lower-*.f64N/A

                                \[\leadsto \color{blue}{\sqrt{2} \cdot \sqrt{\frac{n \cdot \mathsf{PI}\left(\right)}{k}}} \]
                              3. lower-sqrt.f64N/A

                                \[\leadsto \color{blue}{\sqrt{2}} \cdot \sqrt{\frac{n \cdot \mathsf{PI}\left(\right)}{k}} \]
                              4. lower-sqrt.f64N/A

                                \[\leadsto \sqrt{2} \cdot \color{blue}{\sqrt{\frac{n \cdot \mathsf{PI}\left(\right)}{k}}} \]
                              5. lower-/.f64N/A

                                \[\leadsto \sqrt{2} \cdot \sqrt{\color{blue}{\frac{n \cdot \mathsf{PI}\left(\right)}{k}}} \]
                              6. *-commutativeN/A

                                \[\leadsto \sqrt{2} \cdot \sqrt{\frac{\color{blue}{\mathsf{PI}\left(\right) \cdot n}}{k}} \]
                              7. lower-*.f64N/A

                                \[\leadsto \sqrt{2} \cdot \sqrt{\frac{\color{blue}{\mathsf{PI}\left(\right) \cdot n}}{k}} \]
                              8. lower-PI.f6451.1

                                \[\leadsto \sqrt{2} \cdot \sqrt{\frac{\color{blue}{\mathsf{PI}\left(\right)} \cdot n}{k}} \]
                            5. Applied rewrites51.1%

                              \[\leadsto \color{blue}{\sqrt{2} \cdot \sqrt{\frac{\mathsf{PI}\left(\right) \cdot n}{k}}} \]
                            6. Step-by-step derivation
                              1. Applied rewrites51.2%

                                \[\leadsto \color{blue}{\sqrt{\frac{\mathsf{PI}\left(\right) \cdot n}{k} \cdot 2}} \]
                              2. Step-by-step derivation
                                1. Applied rewrites67.6%

                                  \[\leadsto \sqrt{n \cdot \mathsf{PI}\left(\right)} \cdot \color{blue}{\sqrt{\frac{2}{k}}} \]
                              3. Recombined 2 regimes into one program.
                              4. Final simplification75.6%

                                \[\leadsto \begin{array}{l} \mathbf{if}\;{\left(\sqrt{k}\right)}^{-1} \cdot {\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \leq 0:\\ \;\;\;\;\frac{0}{\sqrt{k}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{n \cdot \mathsf{PI}\left(\right)} \cdot \sqrt{\frac{2}{k}}\\ \end{array} \]
                              5. Add Preprocessing

                              Alternative 5: 73.9% accurate, 0.5× speedup?

                              \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;{\left(\sqrt{k}\right)}^{-1} \cdot {\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \leq 0:\\ \;\;\;\;\frac{0}{\sqrt{k}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{2 \cdot \frac{\mathsf{PI}\left(\right)}{k}} \cdot \sqrt{n}\\ \end{array} \end{array} \]
                              (FPCore (k n)
                               :precision binary64
                               (if (<=
                                    (* (pow (sqrt k) -1.0) (pow (* (* 2.0 (PI)) n) (/ (- 1.0 k) 2.0)))
                                    0.0)
                                 (/ 0.0 (sqrt k))
                                 (* (sqrt (* 2.0 (/ (PI) k))) (sqrt n))))
                              \begin{array}{l}
                              
                              \\
                              \begin{array}{l}
                              \mathbf{if}\;{\left(\sqrt{k}\right)}^{-1} \cdot {\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \leq 0:\\
                              \;\;\;\;\frac{0}{\sqrt{k}}\\
                              
                              \mathbf{else}:\\
                              \;\;\;\;\sqrt{2 \cdot \frac{\mathsf{PI}\left(\right)}{k}} \cdot \sqrt{n}\\
                              
                              
                              \end{array}
                              \end{array}
                              
                              Derivation
                              1. Split input into 2 regimes
                              2. if (*.f64 (/.f64 #s(literal 1 binary64) (sqrt.f64 k)) (pow.f64 (*.f64 (*.f64 #s(literal 2 binary64) (PI.f64)) n) (/.f64 (-.f64 #s(literal 1 binary64) k) #s(literal 2 binary64)))) < 0.0

                                1. Initial program 100.0%

                                  \[\frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \]
                                2. Add Preprocessing
                                3. Taylor expanded in k around 0

                                  \[\leadsto \frac{1}{\sqrt{k}} \cdot \color{blue}{\left(\sqrt{n \cdot \mathsf{PI}\left(\right)} \cdot \sqrt{2}\right)} \]
                                4. Step-by-step derivation
                                  1. lower-*.f64N/A

                                    \[\leadsto \frac{1}{\sqrt{k}} \cdot \color{blue}{\left(\sqrt{n \cdot \mathsf{PI}\left(\right)} \cdot \sqrt{2}\right)} \]
                                  2. lower-sqrt.f64N/A

                                    \[\leadsto \frac{1}{\sqrt{k}} \cdot \left(\color{blue}{\sqrt{n \cdot \mathsf{PI}\left(\right)}} \cdot \sqrt{2}\right) \]
                                  3. *-commutativeN/A

                                    \[\leadsto \frac{1}{\sqrt{k}} \cdot \left(\sqrt{\color{blue}{\mathsf{PI}\left(\right) \cdot n}} \cdot \sqrt{2}\right) \]
                                  4. lower-*.f64N/A

                                    \[\leadsto \frac{1}{\sqrt{k}} \cdot \left(\sqrt{\color{blue}{\mathsf{PI}\left(\right) \cdot n}} \cdot \sqrt{2}\right) \]
                                  5. lower-PI.f64N/A

                                    \[\leadsto \frac{1}{\sqrt{k}} \cdot \left(\sqrt{\color{blue}{\mathsf{PI}\left(\right)} \cdot n} \cdot \sqrt{2}\right) \]
                                  6. lower-sqrt.f643.2

                                    \[\leadsto \frac{1}{\sqrt{k}} \cdot \left(\sqrt{\mathsf{PI}\left(\right) \cdot n} \cdot \color{blue}{\sqrt{2}}\right) \]
                                5. Applied rewrites3.2%

                                  \[\leadsto \frac{1}{\sqrt{k}} \cdot \color{blue}{\left(\sqrt{\mathsf{PI}\left(\right) \cdot n} \cdot \sqrt{2}\right)} \]
                                6. Step-by-step derivation
                                  1. Applied rewrites3.2%

                                    \[\leadsto \frac{1}{\sqrt{k}} \cdot \left(\sqrt{\left(\sqrt{\mathsf{PI}\left(\right)} \cdot \sqrt{\mathsf{PI}\left(\right)}\right) \cdot n} \cdot \sqrt{2}\right) \]
                                  2. Applied rewrites100.0%

                                    \[\leadsto \color{blue}{\frac{0}{\sqrt{k}}} \]

                                  if 0.0 < (*.f64 (/.f64 #s(literal 1 binary64) (sqrt.f64 k)) (pow.f64 (*.f64 (*.f64 #s(literal 2 binary64) (PI.f64)) n) (/.f64 (-.f64 #s(literal 1 binary64) k) #s(literal 2 binary64))))

                                  1. Initial program 99.4%

                                    \[\frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \]
                                  2. Add Preprocessing
                                  3. Taylor expanded in k around 0

                                    \[\leadsto \color{blue}{\sqrt{\frac{n \cdot \mathsf{PI}\left(\right)}{k}} \cdot \sqrt{2}} \]
                                  4. Step-by-step derivation
                                    1. *-commutativeN/A

                                      \[\leadsto \color{blue}{\sqrt{2} \cdot \sqrt{\frac{n \cdot \mathsf{PI}\left(\right)}{k}}} \]
                                    2. lower-*.f64N/A

                                      \[\leadsto \color{blue}{\sqrt{2} \cdot \sqrt{\frac{n \cdot \mathsf{PI}\left(\right)}{k}}} \]
                                    3. lower-sqrt.f64N/A

                                      \[\leadsto \color{blue}{\sqrt{2}} \cdot \sqrt{\frac{n \cdot \mathsf{PI}\left(\right)}{k}} \]
                                    4. lower-sqrt.f64N/A

                                      \[\leadsto \sqrt{2} \cdot \color{blue}{\sqrt{\frac{n \cdot \mathsf{PI}\left(\right)}{k}}} \]
                                    5. lower-/.f64N/A

                                      \[\leadsto \sqrt{2} \cdot \sqrt{\color{blue}{\frac{n \cdot \mathsf{PI}\left(\right)}{k}}} \]
                                    6. *-commutativeN/A

                                      \[\leadsto \sqrt{2} \cdot \sqrt{\frac{\color{blue}{\mathsf{PI}\left(\right) \cdot n}}{k}} \]
                                    7. lower-*.f64N/A

                                      \[\leadsto \sqrt{2} \cdot \sqrt{\frac{\color{blue}{\mathsf{PI}\left(\right) \cdot n}}{k}} \]
                                    8. lower-PI.f6451.1

                                      \[\leadsto \sqrt{2} \cdot \sqrt{\frac{\color{blue}{\mathsf{PI}\left(\right)} \cdot n}{k}} \]
                                  5. Applied rewrites51.1%

                                    \[\leadsto \color{blue}{\sqrt{2} \cdot \sqrt{\frac{\mathsf{PI}\left(\right) \cdot n}{k}}} \]
                                  6. Step-by-step derivation
                                    1. Applied rewrites51.2%

                                      \[\leadsto \color{blue}{\sqrt{\frac{\mathsf{PI}\left(\right) \cdot n}{k} \cdot 2}} \]
                                    2. Step-by-step derivation
                                      1. Applied rewrites67.2%

                                        \[\leadsto \sqrt{2 \cdot \frac{\mathsf{PI}\left(\right)}{k}} \cdot \color{blue}{\sqrt{n}} \]
                                    3. Recombined 2 regimes into one program.
                                    4. Final simplification75.3%

                                      \[\leadsto \begin{array}{l} \mathbf{if}\;{\left(\sqrt{k}\right)}^{-1} \cdot {\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \leq 0:\\ \;\;\;\;\frac{0}{\sqrt{k}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{2 \cdot \frac{\mathsf{PI}\left(\right)}{k}} \cdot \sqrt{n}\\ \end{array} \]
                                    5. Add Preprocessing

                                    Alternative 6: 62.3% accurate, 0.5× speedup?

                                    \[\begin{array}{l} \\ \begin{array}{l} t_0 := 2 \cdot \mathsf{PI}\left(\right)\\ \mathbf{if}\;{\left(\sqrt{k}\right)}^{-1} \cdot {\left(t\_0 \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \leq 0:\\ \;\;\;\;\frac{0}{\sqrt{k}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\frac{n}{k} \cdot t\_0}\\ \end{array} \end{array} \]
                                    (FPCore (k n)
                                     :precision binary64
                                     (let* ((t_0 (* 2.0 (PI))))
                                       (if (<= (* (pow (sqrt k) -1.0) (pow (* t_0 n) (/ (- 1.0 k) 2.0))) 0.0)
                                         (/ 0.0 (sqrt k))
                                         (sqrt (* (/ n k) t_0)))))
                                    \begin{array}{l}
                                    
                                    \\
                                    \begin{array}{l}
                                    t_0 := 2 \cdot \mathsf{PI}\left(\right)\\
                                    \mathbf{if}\;{\left(\sqrt{k}\right)}^{-1} \cdot {\left(t\_0 \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \leq 0:\\
                                    \;\;\;\;\frac{0}{\sqrt{k}}\\
                                    
                                    \mathbf{else}:\\
                                    \;\;\;\;\sqrt{\frac{n}{k} \cdot t\_0}\\
                                    
                                    
                                    \end{array}
                                    \end{array}
                                    
                                    Derivation
                                    1. Split input into 2 regimes
                                    2. if (*.f64 (/.f64 #s(literal 1 binary64) (sqrt.f64 k)) (pow.f64 (*.f64 (*.f64 #s(literal 2 binary64) (PI.f64)) n) (/.f64 (-.f64 #s(literal 1 binary64) k) #s(literal 2 binary64)))) < 0.0

                                      1. Initial program 100.0%

                                        \[\frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \]
                                      2. Add Preprocessing
                                      3. Taylor expanded in k around 0

                                        \[\leadsto \frac{1}{\sqrt{k}} \cdot \color{blue}{\left(\sqrt{n \cdot \mathsf{PI}\left(\right)} \cdot \sqrt{2}\right)} \]
                                      4. Step-by-step derivation
                                        1. lower-*.f64N/A

                                          \[\leadsto \frac{1}{\sqrt{k}} \cdot \color{blue}{\left(\sqrt{n \cdot \mathsf{PI}\left(\right)} \cdot \sqrt{2}\right)} \]
                                        2. lower-sqrt.f64N/A

                                          \[\leadsto \frac{1}{\sqrt{k}} \cdot \left(\color{blue}{\sqrt{n \cdot \mathsf{PI}\left(\right)}} \cdot \sqrt{2}\right) \]
                                        3. *-commutativeN/A

                                          \[\leadsto \frac{1}{\sqrt{k}} \cdot \left(\sqrt{\color{blue}{\mathsf{PI}\left(\right) \cdot n}} \cdot \sqrt{2}\right) \]
                                        4. lower-*.f64N/A

                                          \[\leadsto \frac{1}{\sqrt{k}} \cdot \left(\sqrt{\color{blue}{\mathsf{PI}\left(\right) \cdot n}} \cdot \sqrt{2}\right) \]
                                        5. lower-PI.f64N/A

                                          \[\leadsto \frac{1}{\sqrt{k}} \cdot \left(\sqrt{\color{blue}{\mathsf{PI}\left(\right)} \cdot n} \cdot \sqrt{2}\right) \]
                                        6. lower-sqrt.f643.2

                                          \[\leadsto \frac{1}{\sqrt{k}} \cdot \left(\sqrt{\mathsf{PI}\left(\right) \cdot n} \cdot \color{blue}{\sqrt{2}}\right) \]
                                      5. Applied rewrites3.2%

                                        \[\leadsto \frac{1}{\sqrt{k}} \cdot \color{blue}{\left(\sqrt{\mathsf{PI}\left(\right) \cdot n} \cdot \sqrt{2}\right)} \]
                                      6. Step-by-step derivation
                                        1. Applied rewrites3.2%

                                          \[\leadsto \frac{1}{\sqrt{k}} \cdot \left(\sqrt{\left(\sqrt{\mathsf{PI}\left(\right)} \cdot \sqrt{\mathsf{PI}\left(\right)}\right) \cdot n} \cdot \sqrt{2}\right) \]
                                        2. Applied rewrites100.0%

                                          \[\leadsto \color{blue}{\frac{0}{\sqrt{k}}} \]

                                        if 0.0 < (*.f64 (/.f64 #s(literal 1 binary64) (sqrt.f64 k)) (pow.f64 (*.f64 (*.f64 #s(literal 2 binary64) (PI.f64)) n) (/.f64 (-.f64 #s(literal 1 binary64) k) #s(literal 2 binary64))))

                                        1. Initial program 99.4%

                                          \[\frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \]
                                        2. Add Preprocessing
                                        3. Taylor expanded in k around 0

                                          \[\leadsto \color{blue}{\sqrt{\frac{n \cdot \mathsf{PI}\left(\right)}{k}} \cdot \sqrt{2}} \]
                                        4. Step-by-step derivation
                                          1. *-commutativeN/A

                                            \[\leadsto \color{blue}{\sqrt{2} \cdot \sqrt{\frac{n \cdot \mathsf{PI}\left(\right)}{k}}} \]
                                          2. lower-*.f64N/A

                                            \[\leadsto \color{blue}{\sqrt{2} \cdot \sqrt{\frac{n \cdot \mathsf{PI}\left(\right)}{k}}} \]
                                          3. lower-sqrt.f64N/A

                                            \[\leadsto \color{blue}{\sqrt{2}} \cdot \sqrt{\frac{n \cdot \mathsf{PI}\left(\right)}{k}} \]
                                          4. lower-sqrt.f64N/A

                                            \[\leadsto \sqrt{2} \cdot \color{blue}{\sqrt{\frac{n \cdot \mathsf{PI}\left(\right)}{k}}} \]
                                          5. lower-/.f64N/A

                                            \[\leadsto \sqrt{2} \cdot \sqrt{\color{blue}{\frac{n \cdot \mathsf{PI}\left(\right)}{k}}} \]
                                          6. *-commutativeN/A

                                            \[\leadsto \sqrt{2} \cdot \sqrt{\frac{\color{blue}{\mathsf{PI}\left(\right) \cdot n}}{k}} \]
                                          7. lower-*.f64N/A

                                            \[\leadsto \sqrt{2} \cdot \sqrt{\frac{\color{blue}{\mathsf{PI}\left(\right) \cdot n}}{k}} \]
                                          8. lower-PI.f6451.1

                                            \[\leadsto \sqrt{2} \cdot \sqrt{\frac{\color{blue}{\mathsf{PI}\left(\right)} \cdot n}{k}} \]
                                        5. Applied rewrites51.1%

                                          \[\leadsto \color{blue}{\sqrt{2} \cdot \sqrt{\frac{\mathsf{PI}\left(\right) \cdot n}{k}}} \]
                                        6. Step-by-step derivation
                                          1. Applied rewrites51.2%

                                            \[\leadsto \color{blue}{\sqrt{\frac{\mathsf{PI}\left(\right) \cdot n}{k} \cdot 2}} \]
                                          2. Step-by-step derivation
                                            1. Applied rewrites51.3%

                                              \[\leadsto \sqrt{\frac{n}{k} \cdot \left(2 \cdot \mathsf{PI}\left(\right)\right)} \]
                                          3. Recombined 2 regimes into one program.
                                          4. Final simplification63.3%

                                            \[\leadsto \begin{array}{l} \mathbf{if}\;{\left(\sqrt{k}\right)}^{-1} \cdot {\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \leq 0:\\ \;\;\;\;\frac{0}{\sqrt{k}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\frac{n}{k} \cdot \left(2 \cdot \mathsf{PI}\left(\right)\right)}\\ \end{array} \]
                                          5. Add Preprocessing

                                          Alternative 7: 62.2% accurate, 0.5× speedup?

                                          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;{\left(\sqrt{k}\right)}^{-1} \cdot {\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \leq 0:\\ \;\;\;\;\frac{0}{\sqrt{k}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\left(n \cdot \mathsf{PI}\left(\right)\right) \cdot \frac{2}{k}}\\ \end{array} \end{array} \]
                                          (FPCore (k n)
                                           :precision binary64
                                           (if (<=
                                                (* (pow (sqrt k) -1.0) (pow (* (* 2.0 (PI)) n) (/ (- 1.0 k) 2.0)))
                                                0.0)
                                             (/ 0.0 (sqrt k))
                                             (sqrt (* (* n (PI)) (/ 2.0 k)))))
                                          \begin{array}{l}
                                          
                                          \\
                                          \begin{array}{l}
                                          \mathbf{if}\;{\left(\sqrt{k}\right)}^{-1} \cdot {\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \leq 0:\\
                                          \;\;\;\;\frac{0}{\sqrt{k}}\\
                                          
                                          \mathbf{else}:\\
                                          \;\;\;\;\sqrt{\left(n \cdot \mathsf{PI}\left(\right)\right) \cdot \frac{2}{k}}\\
                                          
                                          
                                          \end{array}
                                          \end{array}
                                          
                                          Derivation
                                          1. Split input into 2 regimes
                                          2. if (*.f64 (/.f64 #s(literal 1 binary64) (sqrt.f64 k)) (pow.f64 (*.f64 (*.f64 #s(literal 2 binary64) (PI.f64)) n) (/.f64 (-.f64 #s(literal 1 binary64) k) #s(literal 2 binary64)))) < 0.0

                                            1. Initial program 100.0%

                                              \[\frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \]
                                            2. Add Preprocessing
                                            3. Taylor expanded in k around 0

                                              \[\leadsto \frac{1}{\sqrt{k}} \cdot \color{blue}{\left(\sqrt{n \cdot \mathsf{PI}\left(\right)} \cdot \sqrt{2}\right)} \]
                                            4. Step-by-step derivation
                                              1. lower-*.f64N/A

                                                \[\leadsto \frac{1}{\sqrt{k}} \cdot \color{blue}{\left(\sqrt{n \cdot \mathsf{PI}\left(\right)} \cdot \sqrt{2}\right)} \]
                                              2. lower-sqrt.f64N/A

                                                \[\leadsto \frac{1}{\sqrt{k}} \cdot \left(\color{blue}{\sqrt{n \cdot \mathsf{PI}\left(\right)}} \cdot \sqrt{2}\right) \]
                                              3. *-commutativeN/A

                                                \[\leadsto \frac{1}{\sqrt{k}} \cdot \left(\sqrt{\color{blue}{\mathsf{PI}\left(\right) \cdot n}} \cdot \sqrt{2}\right) \]
                                              4. lower-*.f64N/A

                                                \[\leadsto \frac{1}{\sqrt{k}} \cdot \left(\sqrt{\color{blue}{\mathsf{PI}\left(\right) \cdot n}} \cdot \sqrt{2}\right) \]
                                              5. lower-PI.f64N/A

                                                \[\leadsto \frac{1}{\sqrt{k}} \cdot \left(\sqrt{\color{blue}{\mathsf{PI}\left(\right)} \cdot n} \cdot \sqrt{2}\right) \]
                                              6. lower-sqrt.f643.2

                                                \[\leadsto \frac{1}{\sqrt{k}} \cdot \left(\sqrt{\mathsf{PI}\left(\right) \cdot n} \cdot \color{blue}{\sqrt{2}}\right) \]
                                            5. Applied rewrites3.2%

                                              \[\leadsto \frac{1}{\sqrt{k}} \cdot \color{blue}{\left(\sqrt{\mathsf{PI}\left(\right) \cdot n} \cdot \sqrt{2}\right)} \]
                                            6. Step-by-step derivation
                                              1. Applied rewrites3.2%

                                                \[\leadsto \frac{1}{\sqrt{k}} \cdot \left(\sqrt{\left(\sqrt{\mathsf{PI}\left(\right)} \cdot \sqrt{\mathsf{PI}\left(\right)}\right) \cdot n} \cdot \sqrt{2}\right) \]
                                              2. Applied rewrites100.0%

                                                \[\leadsto \color{blue}{\frac{0}{\sqrt{k}}} \]

                                              if 0.0 < (*.f64 (/.f64 #s(literal 1 binary64) (sqrt.f64 k)) (pow.f64 (*.f64 (*.f64 #s(literal 2 binary64) (PI.f64)) n) (/.f64 (-.f64 #s(literal 1 binary64) k) #s(literal 2 binary64))))

                                              1. Initial program 99.4%

                                                \[\frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \]
                                              2. Add Preprocessing
                                              3. Taylor expanded in k around 0

                                                \[\leadsto \color{blue}{\sqrt{\frac{n \cdot \mathsf{PI}\left(\right)}{k}} \cdot \sqrt{2}} \]
                                              4. Step-by-step derivation
                                                1. *-commutativeN/A

                                                  \[\leadsto \color{blue}{\sqrt{2} \cdot \sqrt{\frac{n \cdot \mathsf{PI}\left(\right)}{k}}} \]
                                                2. lower-*.f64N/A

                                                  \[\leadsto \color{blue}{\sqrt{2} \cdot \sqrt{\frac{n \cdot \mathsf{PI}\left(\right)}{k}}} \]
                                                3. lower-sqrt.f64N/A

                                                  \[\leadsto \color{blue}{\sqrt{2}} \cdot \sqrt{\frac{n \cdot \mathsf{PI}\left(\right)}{k}} \]
                                                4. lower-sqrt.f64N/A

                                                  \[\leadsto \sqrt{2} \cdot \color{blue}{\sqrt{\frac{n \cdot \mathsf{PI}\left(\right)}{k}}} \]
                                                5. lower-/.f64N/A

                                                  \[\leadsto \sqrt{2} \cdot \sqrt{\color{blue}{\frac{n \cdot \mathsf{PI}\left(\right)}{k}}} \]
                                                6. *-commutativeN/A

                                                  \[\leadsto \sqrt{2} \cdot \sqrt{\frac{\color{blue}{\mathsf{PI}\left(\right) \cdot n}}{k}} \]
                                                7. lower-*.f64N/A

                                                  \[\leadsto \sqrt{2} \cdot \sqrt{\frac{\color{blue}{\mathsf{PI}\left(\right) \cdot n}}{k}} \]
                                                8. lower-PI.f6451.1

                                                  \[\leadsto \sqrt{2} \cdot \sqrt{\frac{\color{blue}{\mathsf{PI}\left(\right)} \cdot n}{k}} \]
                                              5. Applied rewrites51.1%

                                                \[\leadsto \color{blue}{\sqrt{2} \cdot \sqrt{\frac{\mathsf{PI}\left(\right) \cdot n}{k}}} \]
                                              6. Step-by-step derivation
                                                1. Applied rewrites51.2%

                                                  \[\leadsto \color{blue}{\sqrt{\frac{\mathsf{PI}\left(\right) \cdot n}{k} \cdot 2}} \]
                                                2. Step-by-step derivation
                                                  1. Applied rewrites51.1%

                                                    \[\leadsto \sqrt{\left(n \cdot \mathsf{PI}\left(\right)\right) \cdot \frac{2}{k}} \]
                                                3. Recombined 2 regimes into one program.
                                                4. Final simplification63.1%

                                                  \[\leadsto \begin{array}{l} \mathbf{if}\;{\left(\sqrt{k}\right)}^{-1} \cdot {\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \leq 0:\\ \;\;\;\;\frac{0}{\sqrt{k}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\left(n \cdot \mathsf{PI}\left(\right)\right) \cdot \frac{2}{k}}\\ \end{array} \]
                                                5. Add Preprocessing

                                                Alternative 8: 29.0% accurate, 0.6× speedup?

                                                \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;{\left(\sqrt{k}\right)}^{-1} \cdot {\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \leq 0:\\ \;\;\;\;\frac{0}{\sqrt{k}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\frac{2}{k} \cdot \mathsf{PI}\left(\right)}\\ \end{array} \end{array} \]
                                                (FPCore (k n)
                                                 :precision binary64
                                                 (if (<=
                                                      (* (pow (sqrt k) -1.0) (pow (* (* 2.0 (PI)) n) (/ (- 1.0 k) 2.0)))
                                                      0.0)
                                                   (/ 0.0 (sqrt k))
                                                   (sqrt (* (/ 2.0 k) (PI)))))
                                                \begin{array}{l}
                                                
                                                \\
                                                \begin{array}{l}
                                                \mathbf{if}\;{\left(\sqrt{k}\right)}^{-1} \cdot {\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \leq 0:\\
                                                \;\;\;\;\frac{0}{\sqrt{k}}\\
                                                
                                                \mathbf{else}:\\
                                                \;\;\;\;\sqrt{\frac{2}{k} \cdot \mathsf{PI}\left(\right)}\\
                                                
                                                
                                                \end{array}
                                                \end{array}
                                                
                                                Derivation
                                                1. Split input into 2 regimes
                                                2. if (*.f64 (/.f64 #s(literal 1 binary64) (sqrt.f64 k)) (pow.f64 (*.f64 (*.f64 #s(literal 2 binary64) (PI.f64)) n) (/.f64 (-.f64 #s(literal 1 binary64) k) #s(literal 2 binary64)))) < 0.0

                                                  1. Initial program 100.0%

                                                    \[\frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \]
                                                  2. Add Preprocessing
                                                  3. Taylor expanded in k around 0

                                                    \[\leadsto \frac{1}{\sqrt{k}} \cdot \color{blue}{\left(\sqrt{n \cdot \mathsf{PI}\left(\right)} \cdot \sqrt{2}\right)} \]
                                                  4. Step-by-step derivation
                                                    1. lower-*.f64N/A

                                                      \[\leadsto \frac{1}{\sqrt{k}} \cdot \color{blue}{\left(\sqrt{n \cdot \mathsf{PI}\left(\right)} \cdot \sqrt{2}\right)} \]
                                                    2. lower-sqrt.f64N/A

                                                      \[\leadsto \frac{1}{\sqrt{k}} \cdot \left(\color{blue}{\sqrt{n \cdot \mathsf{PI}\left(\right)}} \cdot \sqrt{2}\right) \]
                                                    3. *-commutativeN/A

                                                      \[\leadsto \frac{1}{\sqrt{k}} \cdot \left(\sqrt{\color{blue}{\mathsf{PI}\left(\right) \cdot n}} \cdot \sqrt{2}\right) \]
                                                    4. lower-*.f64N/A

                                                      \[\leadsto \frac{1}{\sqrt{k}} \cdot \left(\sqrt{\color{blue}{\mathsf{PI}\left(\right) \cdot n}} \cdot \sqrt{2}\right) \]
                                                    5. lower-PI.f64N/A

                                                      \[\leadsto \frac{1}{\sqrt{k}} \cdot \left(\sqrt{\color{blue}{\mathsf{PI}\left(\right)} \cdot n} \cdot \sqrt{2}\right) \]
                                                    6. lower-sqrt.f643.2

                                                      \[\leadsto \frac{1}{\sqrt{k}} \cdot \left(\sqrt{\mathsf{PI}\left(\right) \cdot n} \cdot \color{blue}{\sqrt{2}}\right) \]
                                                  5. Applied rewrites3.2%

                                                    \[\leadsto \frac{1}{\sqrt{k}} \cdot \color{blue}{\left(\sqrt{\mathsf{PI}\left(\right) \cdot n} \cdot \sqrt{2}\right)} \]
                                                  6. Step-by-step derivation
                                                    1. Applied rewrites3.2%

                                                      \[\leadsto \frac{1}{\sqrt{k}} \cdot \left(\sqrt{\left(\sqrt{\mathsf{PI}\left(\right)} \cdot \sqrt{\mathsf{PI}\left(\right)}\right) \cdot n} \cdot \sqrt{2}\right) \]
                                                    2. Applied rewrites100.0%

                                                      \[\leadsto \color{blue}{\frac{0}{\sqrt{k}}} \]

                                                    if 0.0 < (*.f64 (/.f64 #s(literal 1 binary64) (sqrt.f64 k)) (pow.f64 (*.f64 (*.f64 #s(literal 2 binary64) (PI.f64)) n) (/.f64 (-.f64 #s(literal 1 binary64) k) #s(literal 2 binary64))))

                                                    1. Initial program 99.4%

                                                      \[\frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \]
                                                    2. Add Preprocessing
                                                    3. Taylor expanded in k around 0

                                                      \[\leadsto \color{blue}{\sqrt{\frac{n \cdot \mathsf{PI}\left(\right)}{k}} \cdot \sqrt{2}} \]
                                                    4. Step-by-step derivation
                                                      1. *-commutativeN/A

                                                        \[\leadsto \color{blue}{\sqrt{2} \cdot \sqrt{\frac{n \cdot \mathsf{PI}\left(\right)}{k}}} \]
                                                      2. lower-*.f64N/A

                                                        \[\leadsto \color{blue}{\sqrt{2} \cdot \sqrt{\frac{n \cdot \mathsf{PI}\left(\right)}{k}}} \]
                                                      3. lower-sqrt.f64N/A

                                                        \[\leadsto \color{blue}{\sqrt{2}} \cdot \sqrt{\frac{n \cdot \mathsf{PI}\left(\right)}{k}} \]
                                                      4. lower-sqrt.f64N/A

                                                        \[\leadsto \sqrt{2} \cdot \color{blue}{\sqrt{\frac{n \cdot \mathsf{PI}\left(\right)}{k}}} \]
                                                      5. lower-/.f64N/A

                                                        \[\leadsto \sqrt{2} \cdot \sqrt{\color{blue}{\frac{n \cdot \mathsf{PI}\left(\right)}{k}}} \]
                                                      6. *-commutativeN/A

                                                        \[\leadsto \sqrt{2} \cdot \sqrt{\frac{\color{blue}{\mathsf{PI}\left(\right) \cdot n}}{k}} \]
                                                      7. lower-*.f64N/A

                                                        \[\leadsto \sqrt{2} \cdot \sqrt{\frac{\color{blue}{\mathsf{PI}\left(\right) \cdot n}}{k}} \]
                                                      8. lower-PI.f6451.1

                                                        \[\leadsto \sqrt{2} \cdot \sqrt{\frac{\color{blue}{\mathsf{PI}\left(\right)} \cdot n}{k}} \]
                                                    5. Applied rewrites51.1%

                                                      \[\leadsto \color{blue}{\sqrt{2} \cdot \sqrt{\frac{\mathsf{PI}\left(\right) \cdot n}{k}}} \]
                                                    6. Step-by-step derivation
                                                      1. Applied rewrites51.2%

                                                        \[\leadsto \color{blue}{\sqrt{\frac{\mathsf{PI}\left(\right) \cdot n}{k} \cdot 2}} \]
                                                      2. Step-by-step derivation
                                                        1. Applied rewrites51.1%

                                                          \[\leadsto \sqrt{\left(n \cdot \mathsf{PI}\left(\right)\right) \cdot \frac{2}{k}} \]
                                                        2. Applied rewrites5.6%

                                                          \[\leadsto \sqrt{\frac{2}{k} \cdot \mathsf{PI}\left(\right)} \]
                                                      3. Recombined 2 regimes into one program.
                                                      4. Final simplification28.9%

                                                        \[\leadsto \begin{array}{l} \mathbf{if}\;{\left(\sqrt{k}\right)}^{-1} \cdot {\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \leq 0:\\ \;\;\;\;\frac{0}{\sqrt{k}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\frac{2}{k} \cdot \mathsf{PI}\left(\right)}\\ \end{array} \]
                                                      5. Add Preprocessing

                                                      Alternative 9: 26.7% accurate, 6.9× speedup?

                                                      \[\begin{array}{l} \\ \frac{0}{\sqrt{k}} \end{array} \]
                                                      (FPCore (k n) :precision binary64 (/ 0.0 (sqrt k)))
                                                      double code(double k, double n) {
                                                      	return 0.0 / sqrt(k);
                                                      }
                                                      
                                                      real(8) function code(k, n)
                                                          real(8), intent (in) :: k
                                                          real(8), intent (in) :: n
                                                          code = 0.0d0 / sqrt(k)
                                                      end function
                                                      
                                                      public static double code(double k, double n) {
                                                      	return 0.0 / Math.sqrt(k);
                                                      }
                                                      
                                                      def code(k, n):
                                                      	return 0.0 / math.sqrt(k)
                                                      
                                                      function code(k, n)
                                                      	return Float64(0.0 / sqrt(k))
                                                      end
                                                      
                                                      function tmp = code(k, n)
                                                      	tmp = 0.0 / sqrt(k);
                                                      end
                                                      
                                                      code[k_, n_] := N[(0.0 / N[Sqrt[k], $MachinePrecision]), $MachinePrecision]
                                                      
                                                      \begin{array}{l}
                                                      
                                                      \\
                                                      \frac{0}{\sqrt{k}}
                                                      \end{array}
                                                      
                                                      Derivation
                                                      1. Initial program 99.6%

                                                        \[\frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \]
                                                      2. Add Preprocessing
                                                      3. Taylor expanded in k around 0

                                                        \[\leadsto \frac{1}{\sqrt{k}} \cdot \color{blue}{\left(\sqrt{n \cdot \mathsf{PI}\left(\right)} \cdot \sqrt{2}\right)} \]
                                                      4. Step-by-step derivation
                                                        1. lower-*.f64N/A

                                                          \[\leadsto \frac{1}{\sqrt{k}} \cdot \color{blue}{\left(\sqrt{n \cdot \mathsf{PI}\left(\right)} \cdot \sqrt{2}\right)} \]
                                                        2. lower-sqrt.f64N/A

                                                          \[\leadsto \frac{1}{\sqrt{k}} \cdot \left(\color{blue}{\sqrt{n \cdot \mathsf{PI}\left(\right)}} \cdot \sqrt{2}\right) \]
                                                        3. *-commutativeN/A

                                                          \[\leadsto \frac{1}{\sqrt{k}} \cdot \left(\sqrt{\color{blue}{\mathsf{PI}\left(\right) \cdot n}} \cdot \sqrt{2}\right) \]
                                                        4. lower-*.f64N/A

                                                          \[\leadsto \frac{1}{\sqrt{k}} \cdot \left(\sqrt{\color{blue}{\mathsf{PI}\left(\right) \cdot n}} \cdot \sqrt{2}\right) \]
                                                        5. lower-PI.f64N/A

                                                          \[\leadsto \frac{1}{\sqrt{k}} \cdot \left(\sqrt{\color{blue}{\mathsf{PI}\left(\right)} \cdot n} \cdot \sqrt{2}\right) \]
                                                        6. lower-sqrt.f6451.7

                                                          \[\leadsto \frac{1}{\sqrt{k}} \cdot \left(\sqrt{\mathsf{PI}\left(\right) \cdot n} \cdot \color{blue}{\sqrt{2}}\right) \]
                                                      5. Applied rewrites51.7%

                                                        \[\leadsto \frac{1}{\sqrt{k}} \cdot \color{blue}{\left(\sqrt{\mathsf{PI}\left(\right) \cdot n} \cdot \sqrt{2}\right)} \]
                                                      6. Step-by-step derivation
                                                        1. Applied rewrites51.7%

                                                          \[\leadsto \frac{1}{\sqrt{k}} \cdot \left(\sqrt{\left(\sqrt{\mathsf{PI}\left(\right)} \cdot \sqrt{\mathsf{PI}\left(\right)}\right) \cdot n} \cdot \sqrt{2}\right) \]
                                                        2. Applied rewrites26.4%

                                                          \[\leadsto \color{blue}{\frac{0}{\sqrt{k}}} \]
                                                        3. Add Preprocessing

                                                        Reproduce

                                                        ?
                                                        herbie shell --seed 2024326 
                                                        (FPCore (k n)
                                                          :name "Migdal et al, Equation (51)"
                                                          :precision binary64
                                                          (* (/ 1.0 (sqrt k)) (pow (* (* 2.0 (PI)) n) (/ (- 1.0 k) 2.0))))