Beckmann Sample, normalization factor

Percentage Accurate: 97.9% → 98.5%
Time: 4.0s
Alternatives: 9
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 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: 97.9% 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}{\mathsf{fma}\left(\sqrt{\mathsf{fma}\left(-2, cosTheta, 1\right)}, \frac{e^{\left(-cosTheta\right) \cdot cosTheta}}{cosTheta \cdot 1.7724539041519165}, c + 1\right)} \]
(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 1.7724539041519165))
  (+ c 1.0))))
float code(float cosTheta, float c) {
	return 1.0f / fmaf(sqrtf(fmaf(-2.0f, cosTheta, 1.0f)), (expf((-cosTheta * cosTheta)) / (cosTheta * 1.7724539041519165f)), (c + 1.0f));
}
function code(cosTheta, c)
	return Float32(Float32(1.0) / fma(sqrt(fma(Float32(-2.0), cosTheta, Float32(1.0))), Float32(exp(Float32(Float32(-cosTheta) * cosTheta)) / Float32(cosTheta * Float32(1.7724539041519165))), Float32(c + Float32(1.0))))
end
\frac{1}{\mathsf{fma}\left(\sqrt{\mathsf{fma}\left(-2, cosTheta, 1\right)}, \frac{e^{\left(-cosTheta\right) \cdot cosTheta}}{cosTheta \cdot 1.7724539041519165}, c + 1\right)}
Derivation
  1. Initial program 97.9%

    \[\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.5%

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

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

    Alternative 2: 97.1% accurate, 1.5× speedup?

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

      \[\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. Taylor expanded in cosTheta around 0

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

        \[\leadsto \frac{1}{\frac{\mathsf{fma}\left(cosTheta, \left(1 + \left(c + -1.5 \cdot \frac{cosTheta}{\sqrt{\pi}}\right)\right) - \frac{1}{\sqrt{\pi}}, \frac{1}{\sqrt{\pi}}\right)}{cosTheta}} \]
      2. Applied rewrites97.0%

        \[\leadsto \frac{1}{\left(\left(c + 1\right) + \frac{-1.5 \cdot cosTheta - 1}{\sqrt{\pi}}\right) + \frac{1}{cosTheta \cdot \sqrt{\pi}}} \]
      3. Add Preprocessing

      Alternative 3: 97.1% accurate, 1.8× speedup?

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

        \[\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.1%

          \[\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. Step-by-step derivation
          1. Applied rewrites97.1%

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

          Alternative 4: 97.0% accurate, 2.0× speedup?

          \[\left(0 < cosTheta \land cosTheta < 0.9999\right) \land \left(-1 < c \land c < 1\right)\]
          \[\frac{1}{\left(\mathsf{fma}\left(\mathsf{fma}\left(0.282094806432724, cosTheta, -0.846284419298172\right), cosTheta, c\right) + 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
              c)
             0.435810387134552)
            (/ 0.564189612865448 cosTheta))))
          float code(float cosTheta, float c) {
          	return 1.0f / ((fmaf(fmaf(0.282094806432724f, cosTheta, -0.846284419298172f), cosTheta, c) + 0.435810387134552f) + (0.564189612865448f / cosTheta));
          }
          
          function code(cosTheta, c)
          	return Float32(Float32(1.0) / Float32(Float32(fma(fma(Float32(0.282094806432724), cosTheta, Float32(-0.846284419298172)), cosTheta, c) + Float32(0.435810387134552)) + Float32(Float32(0.564189612865448) / cosTheta)))
          end
          
          \frac{1}{\left(\mathsf{fma}\left(\mathsf{fma}\left(0.282094806432724, cosTheta, -0.846284419298172\right), cosTheta, c\right) + 0.435810387134552\right) + \frac{0.564189612865448}{cosTheta}}
          
          Derivation
          1. Initial program 97.9%

            \[\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.1%

              \[\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.1%

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

            Alternative 5: 96.7% accurate, 3.1× speedup?

            \[\left(0 < cosTheta \land cosTheta < 0.9999\right) \land \left(-1 < c \land c < 1\right)\]
            \[cosTheta \cdot \left(1.7724539041519165 + cosTheta \cdot \left(3.7162775743602734 \cdot cosTheta - 1.3691389381914547\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.7724539041519165
              (*
               cosTheta
               (- (* 3.7162775743602734 cosTheta) 1.3691389381914547)))))
            float code(float cosTheta, float c) {
            	return cosTheta * (1.7724539041519165f + (cosTheta * ((3.7162775743602734f * cosTheta) - 1.3691389381914547f)));
            }
            
            real(4) function code(costheta, c)
            use fmin_fmax_functions
                real(4), intent (in) :: costheta
                real(4), intent (in) :: c
                code = costheta * (1.7724539041519165e0 + (costheta * ((3.7162775743602734e0 * costheta) - 1.3691389381914547e0)))
            end function
            
            function code(cosTheta, c)
            	return Float32(cosTheta * Float32(Float32(1.7724539041519165) + Float32(cosTheta * Float32(Float32(Float32(3.7162775743602734) * cosTheta) - Float32(1.3691389381914547)))))
            end
            
            function tmp = code(cosTheta, c)
            	tmp = cosTheta * (single(1.7724539041519165) + (cosTheta * ((single(3.7162775743602734) * cosTheta) - single(1.3691389381914547))));
            end
            
            cosTheta \cdot \left(1.7724539041519165 + cosTheta \cdot \left(3.7162775743602734 \cdot cosTheta - 1.3691389381914547\right)\right)
            
            Derivation
            1. Initial program 97.9%

              \[\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.5%

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

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

                \[\leadsto cosTheta \cdot \left(\frac{14868421}{8388608} + cosTheta \cdot \left(cosTheta \cdot \left(\frac{44605263}{16777216} - \frac{-3286960983464244182461}{590295810358705651712} \cdot {\left(\frac{6479813}{14868421} + c\right)}^{2}\right) - \frac{221069943033241}{70368744177664} \cdot \left(\frac{6479813}{14868421} + c\right)\right)\right) \]
              4. Step-by-step derivation
                1. Applied rewrites96.9%

                  \[\leadsto cosTheta \cdot \left(1.7724539041519165 + cosTheta \cdot \left(cosTheta \cdot \left(2.6586808562278748 - -5.568328498667225 \cdot {\left(0.4358104334010989 + c\right)}^{2}\right) - 3.141592842343371 \cdot \left(0.4358104334010989 + c\right)\right)\right) \]
                2. Taylor expanded in c around 0

                  \[\leadsto cosTheta \cdot \left(1.7724539041519165 + cosTheta \cdot \left(\frac{2193703082274882616765}{590295810358705651712} \cdot cosTheta - \frac{96344587685273}{70368744177664}\right)\right) \]
                3. Step-by-step derivation
                  1. Applied rewrites96.7%

                    \[\leadsto cosTheta \cdot \left(1.7724539041519165 + cosTheta \cdot \left(3.7162775743602734 \cdot cosTheta - 1.3691389381914547\right)\right) \]
                  2. Add Preprocessing

                  Alternative 6: 95.8% accurate, 3.3× speedup?

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

                    \[\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.5%

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

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

                      \[\leadsto cosTheta \cdot \left(\frac{14868421}{8388608} + \frac{-221069943033241}{70368744177664} \cdot \left(cosTheta \cdot \left(\frac{6479813}{14868421} + c\right)\right)\right) \]
                    4. Step-by-step derivation
                      1. Applied rewrites95.8%

                        \[\leadsto cosTheta \cdot \left(1.7724539041519165 + -3.141592842343371 \cdot \left(cosTheta \cdot \left(0.4358104334010989 + c\right)\right)\right) \]
                      2. Step-by-step derivation
                        1. Applied rewrites95.8%

                          \[\leadsto \mathsf{fma}\left(-3.141592842343371, \left(0.4358104334010989 + c\right) \cdot cosTheta, 1.7724539041519165\right) \cdot cosTheta \]
                        2. Add Preprocessing

                        Alternative 7: 95.7% accurate, 5.0× speedup?

                        \[\left(0 < cosTheta \land cosTheta < 0.9999\right) \land \left(-1 < c \land c < 1\right)\]
                        \[cosTheta \cdot \left(1.7724539041519165 + -1.3691389381914547 \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.7724539041519165 (* -1.3691389381914547 cosTheta))))
                        float code(float cosTheta, float c) {
                        	return cosTheta * (1.7724539041519165f + (-1.3691389381914547f * cosTheta));
                        }
                        
                        real(4) function code(costheta, c)
                        use fmin_fmax_functions
                            real(4), intent (in) :: costheta
                            real(4), intent (in) :: c
                            code = costheta * (1.7724539041519165e0 + ((-1.3691389381914547e0) * costheta))
                        end function
                        
                        function code(cosTheta, c)
                        	return Float32(cosTheta * Float32(Float32(1.7724539041519165) + Float32(Float32(-1.3691389381914547) * cosTheta)))
                        end
                        
                        function tmp = code(cosTheta, c)
                        	tmp = cosTheta * (single(1.7724539041519165) + (single(-1.3691389381914547) * cosTheta));
                        end
                        
                        cosTheta \cdot \left(1.7724539041519165 + -1.3691389381914547 \cdot cosTheta\right)
                        
                        Derivation
                        1. Initial program 97.9%

                          \[\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.5%

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

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

                            \[\leadsto cosTheta \cdot \left(\frac{14868421}{8388608} + \frac{-221069943033241}{70368744177664} \cdot \left(cosTheta \cdot \left(\frac{6479813}{14868421} + c\right)\right)\right) \]
                          4. Step-by-step derivation
                            1. Applied rewrites95.8%

                              \[\leadsto cosTheta \cdot \left(1.7724539041519165 + -3.141592842343371 \cdot \left(cosTheta \cdot \left(0.4358104334010989 + c\right)\right)\right) \]
                            2. Taylor expanded in c around 0

                              \[\leadsto cosTheta \cdot \left(1.7724539041519165 + \frac{-96344587685273}{70368744177664} \cdot cosTheta\right) \]
                            3. Step-by-step derivation
                              1. Applied rewrites95.7%

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

                              Alternative 8: 93.0% accurate, 11.9× speedup?

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

                                \[\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. Taylor expanded in cosTheta around 0

                                \[\leadsto cosTheta \cdot \sqrt{\pi} \]
                              3. Step-by-step derivation
                                1. Applied rewrites93.0%

                                  \[\leadsto cosTheta \cdot \sqrt{\pi} \]
                                2. Evaluated real constant93.0%

                                  \[\leadsto cosTheta \cdot 1.7724539041519165 \]
                                3. Add Preprocessing

                                Alternative 9: 92.9% 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.9%

                                  \[\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.9%

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

                                  Reproduce

                                  ?
                                  herbie shell --seed 2026070 
                                  (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))))))