Beckmann Sample, normalization factor

Percentage Accurate: 97.8% → 98.5%
Time: 4.0s
Alternatives: 11
Speedup: 1.2×

Specification

?
\[\left(0 < cosTheta \land cosTheta < 0.9999\right) \land \left(-1 < c \land c < 1\right)\]
\[\frac{1}{\left(1 + c\right) + \left(\frac{1}{\sqrt{\pi}} \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}\right) \cdot e^{\left(-cosTheta\right) \cdot cosTheta}} \]
(FPCore (cosTheta c)
  :precision binary32
  :pre (and (and (< 0.0 cosTheta) (< cosTheta 0.9999))
     (and (< -1.0 c) (< c 1.0)))
  (/
 1.0
 (+
  (+ 1.0 c)
  (*
   (*
    (/ 1.0 (sqrt PI))
    (/ (sqrt (- (- 1.0 cosTheta) cosTheta)) cosTheta))
   (exp (* (- cosTheta) cosTheta))))))
float code(float cosTheta, float c) {
	return 1.0f / ((1.0f + c) + (((1.0f / sqrtf(((float) M_PI))) * (sqrtf(((1.0f - cosTheta) - cosTheta)) / cosTheta)) * expf((-cosTheta * cosTheta))));
}
function code(cosTheta, c)
	return Float32(Float32(1.0) / Float32(Float32(Float32(1.0) + c) + Float32(Float32(Float32(Float32(1.0) / sqrt(Float32(pi))) * Float32(sqrt(Float32(Float32(Float32(1.0) - cosTheta) - cosTheta)) / cosTheta)) * exp(Float32(Float32(-cosTheta) * cosTheta)))))
end
function tmp = code(cosTheta, c)
	tmp = single(1.0) / ((single(1.0) + c) + (((single(1.0) / sqrt(single(pi))) * (sqrt(((single(1.0) - cosTheta) - cosTheta)) / cosTheta)) * exp((-cosTheta * cosTheta))));
end
\frac{1}{\left(1 + c\right) + \left(\frac{1}{\sqrt{\pi}} \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}\right) \cdot e^{\left(-cosTheta\right) \cdot cosTheta}}

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 11 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: 97.8% accurate, 1.0× speedup?

\[\left(0 < cosTheta \land cosTheta < 0.9999\right) \land \left(-1 < c \land c < 1\right)\]
\[\frac{1}{\left(1 + c\right) + \left(\frac{1}{\sqrt{\pi}} \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}\right) \cdot e^{\left(-cosTheta\right) \cdot cosTheta}} \]
(FPCore (cosTheta c)
  :precision binary32
  :pre (and (and (< 0.0 cosTheta) (< cosTheta 0.9999))
     (and (< -1.0 c) (< c 1.0)))
  (/
 1.0
 (+
  (+ 1.0 c)
  (*
   (*
    (/ 1.0 (sqrt PI))
    (/ (sqrt (- (- 1.0 cosTheta) cosTheta)) cosTheta))
   (exp (* (- cosTheta) cosTheta))))))
float code(float cosTheta, float c) {
	return 1.0f / ((1.0f + c) + (((1.0f / sqrtf(((float) M_PI))) * (sqrtf(((1.0f - cosTheta) - cosTheta)) / cosTheta)) * expf((-cosTheta * cosTheta))));
}
function code(cosTheta, c)
	return Float32(Float32(1.0) / Float32(Float32(Float32(1.0) + c) + Float32(Float32(Float32(Float32(1.0) / sqrt(Float32(pi))) * Float32(sqrt(Float32(Float32(Float32(1.0) - cosTheta) - cosTheta)) / cosTheta)) * exp(Float32(Float32(-cosTheta) * cosTheta)))))
end
function tmp = code(cosTheta, c)
	tmp = single(1.0) / ((single(1.0) + c) + (((single(1.0) / sqrt(single(pi))) * (sqrt(((single(1.0) - cosTheta) - cosTheta)) / cosTheta)) * exp((-cosTheta * cosTheta))));
end
\frac{1}{\left(1 + c\right) + \left(\frac{1}{\sqrt{\pi}} \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}\right) \cdot e^{\left(-cosTheta\right) \cdot cosTheta}}

Alternative 1: 98.5% accurate, 1.2× speedup?

\[\left(0 < cosTheta \land cosTheta < 0.9999\right) \land \left(-1 < c \land c < 1\right)\]
\[\frac{1.7724539041519165}{\mathsf{fma}\left(1.7724539041519165, c + 1, \frac{\sqrt{\mathsf{fma}\left(-2, cosTheta, 1\right)}}{e^{cosTheta \cdot cosTheta} \cdot cosTheta}\right)} \]
(FPCore (cosTheta c)
  :precision binary32
  :pre (and (and (< 0.0 cosTheta) (< cosTheta 0.9999))
     (and (< -1.0 c) (< c 1.0)))
  (/
 1.7724539041519165
 (fma
  1.7724539041519165
  (+ c 1.0)
  (/
   (sqrt (fma -2.0 cosTheta 1.0))
   (* (exp (* cosTheta cosTheta)) cosTheta)))))
float code(float cosTheta, float c) {
	return 1.7724539041519165f / fmaf(1.7724539041519165f, (c + 1.0f), (sqrtf(fmaf(-2.0f, cosTheta, 1.0f)) / (expf((cosTheta * cosTheta)) * cosTheta)));
}
function code(cosTheta, c)
	return Float32(Float32(1.7724539041519165) / fma(Float32(1.7724539041519165), Float32(c + Float32(1.0)), Float32(sqrt(fma(Float32(-2.0), cosTheta, Float32(1.0))) / Float32(exp(Float32(cosTheta * cosTheta)) * cosTheta))))
end
\frac{1.7724539041519165}{\mathsf{fma}\left(1.7724539041519165, c + 1, \frac{\sqrt{\mathsf{fma}\left(-2, cosTheta, 1\right)}}{e^{cosTheta \cdot cosTheta} \cdot cosTheta}\right)}
Derivation
  1. Initial program 97.8%

    \[\frac{1}{\left(1 + c\right) + \left(\frac{1}{\sqrt{\pi}} \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}\right) \cdot e^{\left(-cosTheta\right) \cdot cosTheta}} \]
  2. Step-by-step derivation
    1. Applied rewrites98.3%

      \[\leadsto \frac{1}{\left(1 + c\right) + \frac{\frac{\sqrt{\mathsf{fma}\left(-2, cosTheta, 1\right)}}{e^{cosTheta \cdot cosTheta} \cdot cosTheta}}{\sqrt{\pi}}} \]
    2. Step-by-step derivation
      1. Applied rewrites98.5%

        \[\leadsto \frac{\sqrt{\pi}}{\mathsf{fma}\left(\sqrt{\pi}, c + 1, \frac{\sqrt{\mathsf{fma}\left(-2, cosTheta, 1\right)}}{e^{cosTheta \cdot cosTheta} \cdot cosTheta}\right)} \]
      2. Evaluated real constant98.5%

        \[\leadsto \frac{1.7724539041519165}{\mathsf{fma}\left(1.7724539041519165, c + 1, \frac{\sqrt{\mathsf{fma}\left(-2, cosTheta, 1\right)}}{e^{cosTheta \cdot cosTheta} \cdot cosTheta}\right)} \]
      3. Add Preprocessing

      Alternative 2: 97.9% accurate, 1.2× speedup?

      \[\left(0 < cosTheta \land cosTheta < 0.9999\right) \land \left(-1 < c \land c < 1\right)\]
      \[\frac{1}{\mathsf{fma}\left(\frac{\sqrt{\mathsf{fma}\left(-2, cosTheta, 1\right)}}{e^{cosTheta \cdot cosTheta} \cdot cosTheta}, 0.564189612865448, 1\right) + c} \]
      (FPCore (cosTheta c)
        :precision binary32
        :pre (and (and (< 0.0 cosTheta) (< cosTheta 0.9999))
           (and (< -1.0 c) (< c 1.0)))
        (/
       1.0
       (+
        (fma
         (/
          (sqrt (fma -2.0 cosTheta 1.0))
          (* (exp (* cosTheta cosTheta)) cosTheta))
         0.564189612865448
         1.0)
        c)))
      float code(float cosTheta, float c) {
      	return 1.0f / (fmaf((sqrtf(fmaf(-2.0f, cosTheta, 1.0f)) / (expf((cosTheta * cosTheta)) * cosTheta)), 0.564189612865448f, 1.0f) + c);
      }
      
      function code(cosTheta, c)
      	return Float32(Float32(1.0) / Float32(fma(Float32(sqrt(fma(Float32(-2.0), cosTheta, Float32(1.0))) / Float32(exp(Float32(cosTheta * cosTheta)) * cosTheta)), Float32(0.564189612865448), Float32(1.0)) + c))
      end
      
      \frac{1}{\mathsf{fma}\left(\frac{\sqrt{\mathsf{fma}\left(-2, cosTheta, 1\right)}}{e^{cosTheta \cdot cosTheta} \cdot cosTheta}, 0.564189612865448, 1\right) + c}
      
      Derivation
      1. Initial program 97.8%

        \[\frac{1}{\left(1 + c\right) + \left(\frac{1}{\sqrt{\pi}} \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}\right) \cdot e^{\left(-cosTheta\right) \cdot cosTheta}} \]
      2. Evaluated real constant97.9%

        \[\leadsto \frac{1}{\left(1 + c\right) + \left(0.564189612865448 \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}\right) \cdot e^{\left(-cosTheta\right) \cdot cosTheta}} \]
      3. Step-by-step derivation
        1. Applied rewrites97.9%

          \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{\sqrt{\mathsf{fma}\left(-2, cosTheta, 1\right)}}{e^{cosTheta \cdot cosTheta} \cdot cosTheta}, 0.564189612865448, 1\right) + c} \]
        2. Add Preprocessing

        Alternative 3: 97.9% accurate, 1.2× speedup?

        \[\left(0 < cosTheta \land cosTheta < 0.9999\right) \land \left(-1 < c \land c < 1\right)\]
        \[\frac{1}{1 + \mathsf{fma}\left(\frac{\sqrt{\mathsf{fma}\left(-2, cosTheta, 1\right)}}{e^{cosTheta \cdot cosTheta} \cdot cosTheta}, 0.564189612865448, c\right)} \]
        (FPCore (cosTheta c)
          :precision binary32
          :pre (and (and (< 0.0 cosTheta) (< cosTheta 0.9999))
             (and (< -1.0 c) (< c 1.0)))
          (/
         1.0
         (+
          1.0
          (fma
           (/
            (sqrt (fma -2.0 cosTheta 1.0))
            (* (exp (* cosTheta cosTheta)) cosTheta))
           0.564189612865448
           c))))
        float code(float cosTheta, float c) {
        	return 1.0f / (1.0f + fmaf((sqrtf(fmaf(-2.0f, cosTheta, 1.0f)) / (expf((cosTheta * cosTheta)) * cosTheta)), 0.564189612865448f, c));
        }
        
        function code(cosTheta, c)
        	return Float32(Float32(1.0) / Float32(Float32(1.0) + fma(Float32(sqrt(fma(Float32(-2.0), cosTheta, Float32(1.0))) / Float32(exp(Float32(cosTheta * cosTheta)) * cosTheta)), Float32(0.564189612865448), c)))
        end
        
        \frac{1}{1 + \mathsf{fma}\left(\frac{\sqrt{\mathsf{fma}\left(-2, cosTheta, 1\right)}}{e^{cosTheta \cdot cosTheta} \cdot cosTheta}, 0.564189612865448, c\right)}
        
        Derivation
        1. Initial program 97.8%

          \[\frac{1}{\left(1 + c\right) + \left(\frac{1}{\sqrt{\pi}} \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}\right) \cdot e^{\left(-cosTheta\right) \cdot cosTheta}} \]
        2. Evaluated real constant97.9%

          \[\leadsto \frac{1}{\left(1 + c\right) + \left(0.564189612865448 \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}\right) \cdot e^{\left(-cosTheta\right) \cdot cosTheta}} \]
        3. Step-by-step derivation
          1. Applied rewrites97.9%

            \[\leadsto \frac{1}{1 + \mathsf{fma}\left(\frac{\sqrt{\mathsf{fma}\left(-2, cosTheta, 1\right)}}{e^{cosTheta \cdot cosTheta} \cdot cosTheta}, 0.564189612865448, c\right)} \]
          2. Add Preprocessing

          Alternative 4: 97.6% accurate, 1.4× speedup?

          \[\left(0 < cosTheta \land cosTheta < 0.9999\right) \land \left(-1 < c \land c < 1\right)\]
          \[\frac{1.7724539041519165}{\mathsf{fma}\left(1.7724539041519165, c + 1, \frac{1 + cosTheta \cdot \left(cosTheta \cdot \left(0.5 \cdot cosTheta - 1.5\right) - 1\right)}{cosTheta}\right)} \]
          (FPCore (cosTheta c)
            :precision binary32
            :pre (and (and (< 0.0 cosTheta) (< cosTheta 0.9999))
               (and (< -1.0 c) (< c 1.0)))
            (/
           1.7724539041519165
           (fma
            1.7724539041519165
            (+ c 1.0)
            (/
             (+ 1.0 (* cosTheta (- (* cosTheta (- (* 0.5 cosTheta) 1.5)) 1.0)))
             cosTheta))))
          float code(float cosTheta, float c) {
          	return 1.7724539041519165f / fmaf(1.7724539041519165f, (c + 1.0f), ((1.0f + (cosTheta * ((cosTheta * ((0.5f * cosTheta) - 1.5f)) - 1.0f))) / cosTheta));
          }
          
          function code(cosTheta, c)
          	return Float32(Float32(1.7724539041519165) / fma(Float32(1.7724539041519165), Float32(c + Float32(1.0)), Float32(Float32(Float32(1.0) + Float32(cosTheta * Float32(Float32(cosTheta * Float32(Float32(Float32(0.5) * cosTheta) - Float32(1.5))) - Float32(1.0)))) / cosTheta)))
          end
          
          \frac{1.7724539041519165}{\mathsf{fma}\left(1.7724539041519165, c + 1, \frac{1 + cosTheta \cdot \left(cosTheta \cdot \left(0.5 \cdot cosTheta - 1.5\right) - 1\right)}{cosTheta}\right)}
          
          Derivation
          1. Initial program 97.8%

            \[\frac{1}{\left(1 + c\right) + \left(\frac{1}{\sqrt{\pi}} \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}\right) \cdot e^{\left(-cosTheta\right) \cdot cosTheta}} \]
          2. Step-by-step derivation
            1. Applied rewrites98.3%

              \[\leadsto \frac{1}{\left(1 + c\right) + \frac{\frac{\sqrt{\mathsf{fma}\left(-2, cosTheta, 1\right)}}{e^{cosTheta \cdot cosTheta} \cdot cosTheta}}{\sqrt{\pi}}} \]
            2. Step-by-step derivation
              1. Applied rewrites98.5%

                \[\leadsto \frac{\sqrt{\pi}}{\mathsf{fma}\left(\sqrt{\pi}, c + 1, \frac{\sqrt{\mathsf{fma}\left(-2, cosTheta, 1\right)}}{e^{cosTheta \cdot cosTheta} \cdot cosTheta}\right)} \]
              2. Evaluated real constant98.5%

                \[\leadsto \frac{1.7724539041519165}{\mathsf{fma}\left(1.7724539041519165, c + 1, \frac{\sqrt{\mathsf{fma}\left(-2, cosTheta, 1\right)}}{e^{cosTheta \cdot cosTheta} \cdot cosTheta}\right)} \]
              3. Taylor expanded in cosTheta around 0

                \[\leadsto \frac{1.7724539041519165}{\mathsf{fma}\left(1.7724539041519165, c + 1, \frac{1 + cosTheta \cdot \left(cosTheta \cdot \left(\frac{1}{2} \cdot cosTheta - \frac{3}{2}\right) - 1\right)}{cosTheta}\right)} \]
              4. Step-by-step derivation
                1. Applied rewrites97.6%

                  \[\leadsto \frac{1.7724539041519165}{\mathsf{fma}\left(1.7724539041519165, c + 1, \frac{1 + cosTheta \cdot \left(cosTheta \cdot \left(0.5 \cdot cosTheta - 1.5\right) - 1\right)}{cosTheta}\right)} \]
                2. Add Preprocessing

                Alternative 5: 97.0% accurate, 2.0× speedup?

                \[\left(0 < cosTheta \land cosTheta < 0.9999\right) \land \left(-1 < c \land c < 1\right)\]
                \[\frac{1}{\mathsf{fma}\left(\mathsf{fma}\left(0.282094806432724, cosTheta, -0.846284419298172\right), cosTheta, 0.435810387134552 + c\right) + \frac{0.564189612865448}{cosTheta}} \]
                (FPCore (cosTheta c)
                  :precision binary32
                  :pre (and (and (< 0.0 cosTheta) (< cosTheta 0.9999))
                     (and (< -1.0 c) (< c 1.0)))
                  (/
                 1.0
                 (+
                  (fma
                   (fma 0.282094806432724 cosTheta -0.846284419298172)
                   cosTheta
                   (+ 0.435810387134552 c))
                  (/ 0.564189612865448 cosTheta))))
                float code(float cosTheta, float c) {
                	return 1.0f / (fmaf(fmaf(0.282094806432724f, cosTheta, -0.846284419298172f), cosTheta, (0.435810387134552f + c)) + (0.564189612865448f / cosTheta));
                }
                
                function code(cosTheta, c)
                	return Float32(Float32(1.0) / Float32(fma(fma(Float32(0.282094806432724), cosTheta, Float32(-0.846284419298172)), cosTheta, Float32(Float32(0.435810387134552) + c)) + Float32(Float32(0.564189612865448) / cosTheta)))
                end
                
                \frac{1}{\mathsf{fma}\left(\mathsf{fma}\left(0.282094806432724, cosTheta, -0.846284419298172\right), cosTheta, 0.435810387134552 + c\right) + \frac{0.564189612865448}{cosTheta}}
                
                Derivation
                1. Initial program 97.8%

                  \[\frac{1}{\left(1 + c\right) + \left(\frac{1}{\sqrt{\pi}} \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}\right) \cdot e^{\left(-cosTheta\right) \cdot cosTheta}} \]
                2. Evaluated real constant97.9%

                  \[\leadsto \frac{1}{\left(1 + c\right) + \left(0.564189612865448 \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}\right) \cdot e^{\left(-cosTheta\right) \cdot cosTheta}} \]
                3. Taylor expanded in cosTheta around 0

                  \[\leadsto \frac{1}{\frac{\frac{9465531}{16777216} + cosTheta \cdot \left(\frac{7311685}{16777216} + \left(c + cosTheta \cdot \left(\frac{9465531}{33554432} \cdot cosTheta - \frac{28396593}{33554432}\right)\right)\right)}{cosTheta}} \]
                4. Step-by-step derivation
                  1. Applied rewrites97.0%

                    \[\leadsto \frac{1}{\frac{0.564189612865448 + cosTheta \cdot \left(0.435810387134552 + \left(c + cosTheta \cdot \left(0.282094806432724 \cdot cosTheta - 0.846284419298172\right)\right)\right)}{cosTheta}} \]
                  2. Applied rewrites97.0%

                    \[\leadsto \frac{1}{\mathsf{fma}\left(\mathsf{fma}\left(0.282094806432724, cosTheta, -0.846284419298172\right), cosTheta, 0.435810387134552 + c\right) + \frac{0.564189612865448}{cosTheta}} \]
                  3. Add Preprocessing

                  Alternative 6: 96.7% accurate, 2.3× speedup?

                  \[\left(0 < cosTheta \land cosTheta < 0.9999\right) \land \left(-1 < c \land c < 1\right)\]
                  \[\frac{1}{\mathsf{fma}\left(\mathsf{fma}\left(0.282094806432724, cosTheta, -0.846284419298172\right), cosTheta, 0.435810387134552\right) + \frac{0.564189612865448}{cosTheta}} \]
                  (FPCore (cosTheta c)
                    :precision binary32
                    :pre (and (and (< 0.0 cosTheta) (< cosTheta 0.9999))
                       (and (< -1.0 c) (< c 1.0)))
                    (/
                   1.0
                   (+
                    (fma
                     (fma 0.282094806432724 cosTheta -0.846284419298172)
                     cosTheta
                     0.435810387134552)
                    (/ 0.564189612865448 cosTheta))))
                  float code(float cosTheta, float c) {
                  	return 1.0f / (fmaf(fmaf(0.282094806432724f, cosTheta, -0.846284419298172f), cosTheta, 0.435810387134552f) + (0.564189612865448f / cosTheta));
                  }
                  
                  function code(cosTheta, c)
                  	return Float32(Float32(1.0) / Float32(fma(fma(Float32(0.282094806432724), cosTheta, Float32(-0.846284419298172)), cosTheta, Float32(0.435810387134552)) + Float32(Float32(0.564189612865448) / cosTheta)))
                  end
                  
                  \frac{1}{\mathsf{fma}\left(\mathsf{fma}\left(0.282094806432724, cosTheta, -0.846284419298172\right), cosTheta, 0.435810387134552\right) + \frac{0.564189612865448}{cosTheta}}
                  
                  Derivation
                  1. Initial program 97.8%

                    \[\frac{1}{\left(1 + c\right) + \left(\frac{1}{\sqrt{\pi}} \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}\right) \cdot e^{\left(-cosTheta\right) \cdot cosTheta}} \]
                  2. Evaluated real constant97.9%

                    \[\leadsto \frac{1}{\left(1 + c\right) + \left(0.564189612865448 \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}\right) \cdot e^{\left(-cosTheta\right) \cdot cosTheta}} \]
                  3. Taylor expanded in cosTheta around 0

                    \[\leadsto \frac{1}{\frac{\frac{9465531}{16777216} + cosTheta \cdot \left(\frac{7311685}{16777216} + \left(c + cosTheta \cdot \left(\frac{9465531}{33554432} \cdot cosTheta - \frac{28396593}{33554432}\right)\right)\right)}{cosTheta}} \]
                  4. Step-by-step derivation
                    1. Applied rewrites97.0%

                      \[\leadsto \frac{1}{\frac{0.564189612865448 + cosTheta \cdot \left(0.435810387134552 + \left(c + cosTheta \cdot \left(0.282094806432724 \cdot cosTheta - 0.846284419298172\right)\right)\right)}{cosTheta}} \]
                    2. Taylor expanded in c around 0

                      \[\leadsto \frac{1}{\frac{0.564189612865448 + cosTheta \cdot \left(\frac{7311685}{16777216} + cosTheta \cdot \left(\frac{9465531}{33554432} \cdot cosTheta - \frac{28396593}{33554432}\right)\right)}{cosTheta}} \]
                    3. Step-by-step derivation
                      1. Applied rewrites96.7%

                        \[\leadsto \frac{1}{\frac{0.564189612865448 + cosTheta \cdot \left(0.435810387134552 + cosTheta \cdot \left(0.282094806432724 \cdot cosTheta - 0.846284419298172\right)\right)}{cosTheta}} \]
                      2. Applied rewrites96.7%

                        \[\leadsto \frac{1}{\mathsf{fma}\left(\mathsf{fma}\left(0.282094806432724, cosTheta, -0.846284419298172\right), cosTheta, 0.435810387134552\right) + \frac{0.564189612865448}{cosTheta}} \]
                      3. Add Preprocessing

                      Alternative 7: 96.4% accurate, 2.5× speedup?

                      \[\left(0 < cosTheta \land cosTheta < 0.9999\right) \land \left(-1 < c \land c < 1\right)\]
                      \[\frac{1}{\mathsf{fma}\left(-0.846284419298172, cosTheta, 0.435810387134552 + c\right) + \frac{0.564189612865448}{cosTheta}} \]
                      (FPCore (cosTheta c)
                        :precision binary32
                        :pre (and (and (< 0.0 cosTheta) (< cosTheta 0.9999))
                           (and (< -1.0 c) (< c 1.0)))
                        (/
                       1.0
                       (+
                        (fma -0.846284419298172 cosTheta (+ 0.435810387134552 c))
                        (/ 0.564189612865448 cosTheta))))
                      float code(float cosTheta, float c) {
                      	return 1.0f / (fmaf(-0.846284419298172f, cosTheta, (0.435810387134552f + c)) + (0.564189612865448f / cosTheta));
                      }
                      
                      function code(cosTheta, c)
                      	return Float32(Float32(1.0) / Float32(fma(Float32(-0.846284419298172), cosTheta, Float32(Float32(0.435810387134552) + c)) + Float32(Float32(0.564189612865448) / cosTheta)))
                      end
                      
                      \frac{1}{\mathsf{fma}\left(-0.846284419298172, cosTheta, 0.435810387134552 + c\right) + \frac{0.564189612865448}{cosTheta}}
                      
                      Derivation
                      1. Initial program 97.8%

                        \[\frac{1}{\left(1 + c\right) + \left(\frac{1}{\sqrt{\pi}} \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}\right) \cdot e^{\left(-cosTheta\right) \cdot cosTheta}} \]
                      2. Evaluated real constant97.9%

                        \[\leadsto \frac{1}{\left(1 + c\right) + \left(0.564189612865448 \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}\right) \cdot e^{\left(-cosTheta\right) \cdot cosTheta}} \]
                      3. Taylor expanded in cosTheta around 0

                        \[\leadsto \frac{1}{\frac{\frac{9465531}{16777216} + cosTheta \cdot \left(\frac{7311685}{16777216} + \left(c + \frac{-28396593}{33554432} \cdot cosTheta\right)\right)}{cosTheta}} \]
                      4. Step-by-step derivation
                        1. Applied rewrites96.4%

                          \[\leadsto \frac{1}{\frac{0.564189612865448 + cosTheta \cdot \left(0.435810387134552 + \left(c + -0.846284419298172 \cdot cosTheta\right)\right)}{cosTheta}} \]
                        2. Applied rewrites96.4%

                          \[\leadsto \frac{1}{\mathsf{fma}\left(-0.846284419298172, cosTheta, 0.435810387134552 + c\right) + \frac{0.564189612865448}{cosTheta}} \]
                        3. Add Preprocessing

                        Alternative 8: 96.2% accurate, 3.0× speedup?

                        \[\left(0 < cosTheta \land cosTheta < 0.9999\right) \land \left(-1 < c \land c < 1\right)\]
                        \[\frac{1}{\mathsf{fma}\left(-0.846284419298172, cosTheta, 0.435810387134552\right) + \frac{0.564189612865448}{cosTheta}} \]
                        (FPCore (cosTheta c)
                          :precision binary32
                          :pre (and (and (< 0.0 cosTheta) (< cosTheta 0.9999))
                             (and (< -1.0 c) (< c 1.0)))
                          (/
                         1.0
                         (+
                          (fma -0.846284419298172 cosTheta 0.435810387134552)
                          (/ 0.564189612865448 cosTheta))))
                        float code(float cosTheta, float c) {
                        	return 1.0f / (fmaf(-0.846284419298172f, cosTheta, 0.435810387134552f) + (0.564189612865448f / cosTheta));
                        }
                        
                        function code(cosTheta, c)
                        	return Float32(Float32(1.0) / Float32(fma(Float32(-0.846284419298172), cosTheta, Float32(0.435810387134552)) + Float32(Float32(0.564189612865448) / cosTheta)))
                        end
                        
                        \frac{1}{\mathsf{fma}\left(-0.846284419298172, cosTheta, 0.435810387134552\right) + \frac{0.564189612865448}{cosTheta}}
                        
                        Derivation
                        1. Initial program 97.8%

                          \[\frac{1}{\left(1 + c\right) + \left(\frac{1}{\sqrt{\pi}} \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}\right) \cdot e^{\left(-cosTheta\right) \cdot cosTheta}} \]
                        2. Evaluated real constant97.9%

                          \[\leadsto \frac{1}{\left(1 + c\right) + \left(0.564189612865448 \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}\right) \cdot e^{\left(-cosTheta\right) \cdot cosTheta}} \]
                        3. Taylor expanded in cosTheta around 0

                          \[\leadsto \frac{1}{\frac{\frac{9465531}{16777216} + cosTheta \cdot \left(\frac{7311685}{16777216} + \left(c + \frac{-28396593}{33554432} \cdot cosTheta\right)\right)}{cosTheta}} \]
                        4. Step-by-step derivation
                          1. Applied rewrites96.4%

                            \[\leadsto \frac{1}{\frac{0.564189612865448 + cosTheta \cdot \left(0.435810387134552 + \left(c + -0.846284419298172 \cdot cosTheta\right)\right)}{cosTheta}} \]
                          2. Taylor expanded in c around 0

                            \[\leadsto \frac{1}{\frac{0.564189612865448 + cosTheta \cdot \left(\frac{7311685}{16777216} + \frac{-28396593}{33554432} \cdot cosTheta\right)}{cosTheta}} \]
                          3. Step-by-step derivation
                            1. Applied rewrites96.2%

                              \[\leadsto \frac{1}{\frac{0.564189612865448 + cosTheta \cdot \left(0.435810387134552 + -0.846284419298172 \cdot cosTheta\right)}{cosTheta}} \]
                            2. Applied rewrites96.2%

                              \[\leadsto \frac{1}{\mathsf{fma}\left(-0.846284419298172, cosTheta, 0.435810387134552\right) + \frac{0.564189612865448}{cosTheta}} \]
                            3. Add Preprocessing

                            Alternative 9: 95.4% accurate, 3.1× speedup?

                            \[\left(0 < cosTheta \land cosTheta < 0.9999\right) \land \left(-1 < c \land c < 1\right)\]
                            \[cosTheta \cdot \left(1.7724537588012759 + -3.141592327088772 \cdot \left(cosTheta \cdot \left(0.435810387134552 + c\right)\right)\right) \]
                            (FPCore (cosTheta c)
                              :precision binary32
                              :pre (and (and (< 0.0 cosTheta) (< cosTheta 0.9999))
                                 (and (< -1.0 c) (< c 1.0)))
                              (*
                             cosTheta
                             (+
                              1.7724537588012759
                              (* -3.141592327088772 (* cosTheta (+ 0.435810387134552 c))))))
                            float code(float cosTheta, float c) {
                            	return cosTheta * (1.7724537588012759f + (-3.141592327088772f * (cosTheta * (0.435810387134552f + c))));
                            }
                            
                            real(4) function code(costheta, c)
                            use fmin_fmax_functions
                                real(4), intent (in) :: costheta
                                real(4), intent (in) :: c
                                code = costheta * (1.7724537588012759e0 + ((-3.141592327088772e0) * (costheta * (0.435810387134552e0 + c))))
                            end function
                            
                            function code(cosTheta, c)
                            	return Float32(cosTheta * Float32(Float32(1.7724537588012759) + Float32(Float32(-3.141592327088772) * Float32(cosTheta * Float32(Float32(0.435810387134552) + c)))))
                            end
                            
                            function tmp = code(cosTheta, c)
                            	tmp = cosTheta * (single(1.7724537588012759) + (single(-3.141592327088772) * (cosTheta * (single(0.435810387134552) + c))));
                            end
                            
                            cosTheta \cdot \left(1.7724537588012759 + -3.141592327088772 \cdot \left(cosTheta \cdot \left(0.435810387134552 + c\right)\right)\right)
                            
                            Derivation
                            1. Initial program 97.8%

                              \[\frac{1}{\left(1 + c\right) + \left(\frac{1}{\sqrt{\pi}} \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}\right) \cdot e^{\left(-cosTheta\right) \cdot cosTheta}} \]
                            2. Evaluated real constant97.9%

                              \[\leadsto \frac{1}{\left(1 + c\right) + \left(0.564189612865448 \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}\right) \cdot e^{\left(-cosTheta\right) \cdot cosTheta}} \]
                            3. Taylor expanded in cosTheta around 0

                              \[\leadsto cosTheta \cdot \left(\frac{16777216}{9465531} + \frac{-281474976710656}{89596277111961} \cdot \left(cosTheta \cdot \left(\frac{7311685}{16777216} + c\right)\right)\right) \]
                            4. Step-by-step derivation
                              1. Applied rewrites95.4%

                                \[\leadsto cosTheta \cdot \left(1.7724537588012759 + -3.141592327088772 \cdot \left(cosTheta \cdot \left(0.435810387134552 + c\right)\right)\right) \]
                              2. Add Preprocessing

                              Alternative 10: 95.3% accurate, 5.0× speedup?

                              \[\left(0 < cosTheta \land cosTheta < 0.9999\right) \land \left(-1 < c \land c < 1\right)\]
                              \[cosTheta \cdot \left(1.7724537588012759 + -1.3691385682874957 \cdot cosTheta\right) \]
                              (FPCore (cosTheta c)
                                :precision binary32
                                :pre (and (and (< 0.0 cosTheta) (< cosTheta 0.9999))
                                   (and (< -1.0 c) (< c 1.0)))
                                (* cosTheta (+ 1.7724537588012759 (* -1.3691385682874957 cosTheta))))
                              float code(float cosTheta, float c) {
                              	return cosTheta * (1.7724537588012759f + (-1.3691385682874957f * cosTheta));
                              }
                              
                              real(4) function code(costheta, c)
                              use fmin_fmax_functions
                                  real(4), intent (in) :: costheta
                                  real(4), intent (in) :: c
                                  code = costheta * (1.7724537588012759e0 + ((-1.3691385682874957e0) * costheta))
                              end function
                              
                              function code(cosTheta, c)
                              	return Float32(cosTheta * Float32(Float32(1.7724537588012759) + Float32(Float32(-1.3691385682874957) * cosTheta)))
                              end
                              
                              function tmp = code(cosTheta, c)
                              	tmp = cosTheta * (single(1.7724537588012759) + (single(-1.3691385682874957) * cosTheta));
                              end
                              
                              cosTheta \cdot \left(1.7724537588012759 + -1.3691385682874957 \cdot cosTheta\right)
                              
                              Derivation
                              1. Initial program 97.8%

                                \[\frac{1}{\left(1 + c\right) + \left(\frac{1}{\sqrt{\pi}} \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}\right) \cdot e^{\left(-cosTheta\right) \cdot cosTheta}} \]
                              2. Evaluated real constant97.9%

                                \[\leadsto \frac{1}{\left(1 + c\right) + \left(0.564189612865448 \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}\right) \cdot e^{\left(-cosTheta\right) \cdot cosTheta}} \]
                              3. Taylor expanded in cosTheta around 0

                                \[\leadsto cosTheta \cdot \left(\frac{16777216}{9465531} + \frac{-281474976710656}{89596277111961} \cdot \left(cosTheta \cdot \left(\frac{7311685}{16777216} + c\right)\right)\right) \]
                              4. Step-by-step derivation
                                1. Applied rewrites95.4%

                                  \[\leadsto cosTheta \cdot \left(1.7724537588012759 + -3.141592327088772 \cdot \left(cosTheta \cdot \left(0.435810387134552 + c\right)\right)\right) \]
                                2. Taylor expanded in c around 0

                                  \[\leadsto cosTheta \cdot \left(1.7724537588012759 + \frac{-122669718568960}{89596277111961} \cdot cosTheta\right) \]
                                3. Step-by-step derivation
                                  1. Applied rewrites95.3%

                                    \[\leadsto cosTheta \cdot \left(1.7724537588012759 + -1.3691385682874957 \cdot cosTheta\right) \]
                                  2. Add Preprocessing

                                  Alternative 11: 92.7% accurate, 11.9× speedup?

                                  \[\left(0 < cosTheta \land cosTheta < 0.9999\right) \land \left(-1 < c \land c < 1\right)\]
                                  \[1.7724537588012759 \cdot cosTheta \]
                                  (FPCore (cosTheta c)
                                    :precision binary32
                                    :pre (and (and (< 0.0 cosTheta) (< cosTheta 0.9999))
                                       (and (< -1.0 c) (< c 1.0)))
                                    (* 1.7724537588012759 cosTheta))
                                  float code(float cosTheta, float c) {
                                  	return 1.7724537588012759f * cosTheta;
                                  }
                                  
                                  real(4) function code(costheta, c)
                                  use fmin_fmax_functions
                                      real(4), intent (in) :: costheta
                                      real(4), intent (in) :: c
                                      code = 1.7724537588012759e0 * costheta
                                  end function
                                  
                                  function code(cosTheta, c)
                                  	return Float32(Float32(1.7724537588012759) * cosTheta)
                                  end
                                  
                                  function tmp = code(cosTheta, c)
                                  	tmp = single(1.7724537588012759) * cosTheta;
                                  end
                                  
                                  1.7724537588012759 \cdot cosTheta
                                  
                                  Derivation
                                  1. Initial program 97.8%

                                    \[\frac{1}{\left(1 + c\right) + \left(\frac{1}{\sqrt{\pi}} \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}\right) \cdot e^{\left(-cosTheta\right) \cdot cosTheta}} \]
                                  2. Evaluated real constant97.9%

                                    \[\leadsto \frac{1}{\left(1 + c\right) + \left(0.564189612865448 \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}\right) \cdot e^{\left(-cosTheta\right) \cdot cosTheta}} \]
                                  3. Taylor expanded in cosTheta around 0

                                    \[\leadsto \frac{16777216}{9465531} \cdot cosTheta \]
                                  4. Step-by-step derivation
                                    1. Applied rewrites92.7%

                                      \[\leadsto 1.7724537588012759 \cdot cosTheta \]
                                    2. Add Preprocessing

                                    Reproduce

                                    ?
                                    herbie shell --seed 2026086 
                                    (FPCore (cosTheta c)
                                      :name "Beckmann Sample, normalization factor"
                                      :precision binary32
                                      :pre (and (and (< 0.0 cosTheta) (< cosTheta 0.9999)) (and (< -1.0 c) (< c 1.0)))
                                      (/ 1.0 (+ (+ 1.0 c) (* (* (/ 1.0 (sqrt PI)) (/ (sqrt (- (- 1.0 cosTheta) cosTheta)) cosTheta)) (exp (* (- cosTheta) cosTheta))))))