Beckmann Sample, normalization factor

Percentage Accurate: 97.8% → 98.6%
Time: 13.3s
Alternatives: 13
Speedup: 2.2×

Specification

?
\[\left(0 < cosTheta \land cosTheta < 0.9999\right) \land \left(-1 < c \land c < 1\right)\]
\[\begin{array}{l} \\ \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}} \end{array} \]
(FPCore (cosTheta c)
 :precision binary32
 (/
  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
\begin{array}{l}

\\
\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}}
\end{array}

Sampling outcomes in binary32 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 13 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?

\[\begin{array}{l} \\ \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}} \end{array} \]
(FPCore (cosTheta c)
 :precision binary32
 (/
  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
\begin{array}{l}

\\
\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}}
\end{array}

Alternative 1: 98.6% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \frac{1}{\frac{e^{cosTheta \cdot \left(-cosTheta\right)}}{cosTheta \cdot \sqrt{\frac{\pi}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}} + \left(1 + c\right)} \end{array} \]
(FPCore (cosTheta c)
 :precision binary32
 (/
  1.0
  (+
   (/
    (exp (* cosTheta (- cosTheta)))
    (* cosTheta (sqrt (/ PI (fma cosTheta -2.0 1.0)))))
   (+ 1.0 c))))
float code(float cosTheta, float c) {
	return 1.0f / ((expf((cosTheta * -cosTheta)) / (cosTheta * sqrtf((((float) M_PI) / fmaf(cosTheta, -2.0f, 1.0f))))) + (1.0f + c));
}
function code(cosTheta, c)
	return Float32(Float32(1.0) / Float32(Float32(exp(Float32(cosTheta * Float32(-cosTheta))) / Float32(cosTheta * sqrt(Float32(Float32(pi) / fma(cosTheta, Float32(-2.0), Float32(1.0)))))) + Float32(Float32(1.0) + c)))
end
\begin{array}{l}

\\
\frac{1}{\frac{e^{cosTheta \cdot \left(-cosTheta\right)}}{cosTheta \cdot \sqrt{\frac{\pi}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}} + \left(1 + c\right)}
\end{array}
Derivation
  1. Initial program 98.1%

    \[\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. Add Preprocessing
  3. Taylor expanded in c around 0

    \[\leadsto \frac{1}{\color{blue}{1 + \left(c + \frac{e^{-1 \cdot {cosTheta}^{2}}}{cosTheta} \cdot \sqrt{\frac{1 - 2 \cdot cosTheta}{\mathsf{PI}\left(\right)}}\right)}} \]
  4. Step-by-step derivation
    1. associate-+r+N/A

      \[\leadsto \frac{1}{\color{blue}{\left(1 + c\right) + \frac{e^{-1 \cdot {cosTheta}^{2}}}{cosTheta} \cdot \sqrt{\frac{1 - 2 \cdot cosTheta}{\mathsf{PI}\left(\right)}}}} \]
    2. +-commutativeN/A

      \[\leadsto \frac{1}{\color{blue}{\frac{e^{-1 \cdot {cosTheta}^{2}}}{cosTheta} \cdot \sqrt{\frac{1 - 2 \cdot cosTheta}{\mathsf{PI}\left(\right)}} + \left(1 + c\right)}} \]
    3. lower-fma.f32N/A

      \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(\frac{e^{-1 \cdot {cosTheta}^{2}}}{cosTheta}, \sqrt{\frac{1 - 2 \cdot cosTheta}{\mathsf{PI}\left(\right)}}, 1 + c\right)}} \]
  5. Applied rewrites98.2%

    \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(\frac{e^{cosTheta \cdot \left(-cosTheta\right)}}{cosTheta}, \sqrt{\frac{\mathsf{fma}\left(cosTheta, -2, 1\right)}{\pi}}, 1 + c\right)}} \]
  6. Step-by-step derivation
    1. lift-fma.f32N/A

      \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{e^{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}{cosTheta}, \sqrt{\frac{\color{blue}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}{\mathsf{PI}\left(\right)}}, 1 + c\right)} \]
    2. lift-PI.f32N/A

      \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{e^{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}{cosTheta}, \sqrt{\frac{\mathsf{fma}\left(cosTheta, -2, 1\right)}{\color{blue}{\mathsf{PI}\left(\right)}}}, 1 + c\right)} \]
    3. clear-numN/A

      \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{e^{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}{cosTheta}, \sqrt{\color{blue}{\frac{1}{\frac{\mathsf{PI}\left(\right)}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}}}, 1 + c\right)} \]
    4. sqrt-divN/A

      \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{e^{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}{cosTheta}, \color{blue}{\frac{\sqrt{1}}{\sqrt{\frac{\mathsf{PI}\left(\right)}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}}}, 1 + c\right)} \]
    5. metadata-evalN/A

      \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{e^{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}{cosTheta}, \frac{\color{blue}{1}}{\sqrt{\frac{\mathsf{PI}\left(\right)}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}}, 1 + c\right)} \]
    6. lower-/.f32N/A

      \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{e^{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}{cosTheta}, \color{blue}{\frac{1}{\sqrt{\frac{\mathsf{PI}\left(\right)}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}}}, 1 + c\right)} \]
    7. lower-sqrt.f32N/A

      \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{e^{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}{cosTheta}, \frac{1}{\color{blue}{\sqrt{\frac{\mathsf{PI}\left(\right)}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}}}, 1 + c\right)} \]
    8. lower-/.f3298.2

      \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{e^{cosTheta \cdot \left(-cosTheta\right)}}{cosTheta}, \frac{1}{\sqrt{\color{blue}{\frac{\pi}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}}}, 1 + c\right)} \]
  7. Applied rewrites98.2%

    \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{e^{cosTheta \cdot \left(-cosTheta\right)}}{cosTheta}, \color{blue}{\frac{1}{\sqrt{\frac{\pi}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}}}, 1 + c\right)} \]
  8. Step-by-step derivation
    1. lift-neg.f32N/A

      \[\leadsto \frac{1}{\frac{e^{cosTheta \cdot \color{blue}{\left(\mathsf{neg}\left(cosTheta\right)\right)}}}{cosTheta} \cdot \frac{1}{\sqrt{\frac{\mathsf{PI}\left(\right)}{cosTheta \cdot -2 + 1}}} + \left(1 + c\right)} \]
    2. lift-*.f32N/A

      \[\leadsto \frac{1}{\frac{e^{\color{blue}{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}}{cosTheta} \cdot \frac{1}{\sqrt{\frac{\mathsf{PI}\left(\right)}{cosTheta \cdot -2 + 1}}} + \left(1 + c\right)} \]
    3. lift-exp.f32N/A

      \[\leadsto \frac{1}{\frac{\color{blue}{e^{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}}{cosTheta} \cdot \frac{1}{\sqrt{\frac{\mathsf{PI}\left(\right)}{cosTheta \cdot -2 + 1}}} + \left(1 + c\right)} \]
    4. lift-/.f32N/A

      \[\leadsto \frac{1}{\color{blue}{\frac{e^{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}{cosTheta}} \cdot \frac{1}{\sqrt{\frac{\mathsf{PI}\left(\right)}{cosTheta \cdot -2 + 1}}} + \left(1 + c\right)} \]
    5. lift-PI.f32N/A

      \[\leadsto \frac{1}{\frac{e^{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}{cosTheta} \cdot \frac{1}{\sqrt{\frac{\color{blue}{\mathsf{PI}\left(\right)}}{cosTheta \cdot -2 + 1}}} + \left(1 + c\right)} \]
    6. lift-fma.f32N/A

      \[\leadsto \frac{1}{\frac{e^{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}{cosTheta} \cdot \frac{1}{\sqrt{\frac{\mathsf{PI}\left(\right)}{\color{blue}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}}} + \left(1 + c\right)} \]
    7. lift-/.f32N/A

      \[\leadsto \frac{1}{\frac{e^{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}{cosTheta} \cdot \frac{1}{\sqrt{\color{blue}{\frac{\mathsf{PI}\left(\right)}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}}} + \left(1 + c\right)} \]
    8. lift-sqrt.f32N/A

      \[\leadsto \frac{1}{\frac{e^{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}{cosTheta} \cdot \frac{1}{\color{blue}{\sqrt{\frac{\mathsf{PI}\left(\right)}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}}} + \left(1 + c\right)} \]
    9. lift-/.f32N/A

      \[\leadsto \frac{1}{\frac{e^{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}{cosTheta} \cdot \color{blue}{\frac{1}{\sqrt{\frac{\mathsf{PI}\left(\right)}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}}} + \left(1 + c\right)} \]
    10. lift-+.f32N/A

      \[\leadsto \frac{1}{\frac{e^{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}{cosTheta} \cdot \frac{1}{\sqrt{\frac{\mathsf{PI}\left(\right)}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}} + \color{blue}{\left(1 + c\right)}} \]
    11. lower-+.f32N/A

      \[\leadsto \frac{1}{\color{blue}{\frac{e^{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}{cosTheta} \cdot \frac{1}{\sqrt{\frac{\mathsf{PI}\left(\right)}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}} + \left(1 + c\right)}} \]
  9. Applied rewrites98.6%

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

Alternative 2: 98.0% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \frac{1}{\mathsf{fma}\left(e^{cosTheta \cdot \left(-cosTheta\right)}, \frac{\sqrt{\frac{\mathsf{fma}\left(cosTheta, -2, 1\right)}{\pi}}}{cosTheta}, 1 + c\right)} \end{array} \]
(FPCore (cosTheta c)
 :precision binary32
 (/
  1.0
  (fma
   (exp (* cosTheta (- cosTheta)))
   (/ (sqrt (/ (fma cosTheta -2.0 1.0) PI)) cosTheta)
   (+ 1.0 c))))
float code(float cosTheta, float c) {
	return 1.0f / fmaf(expf((cosTheta * -cosTheta)), (sqrtf((fmaf(cosTheta, -2.0f, 1.0f) / ((float) M_PI))) / cosTheta), (1.0f + c));
}
function code(cosTheta, c)
	return Float32(Float32(1.0) / fma(exp(Float32(cosTheta * Float32(-cosTheta))), Float32(sqrt(Float32(fma(cosTheta, Float32(-2.0), Float32(1.0)) / Float32(pi))) / cosTheta), Float32(Float32(1.0) + c)))
end
\begin{array}{l}

\\
\frac{1}{\mathsf{fma}\left(e^{cosTheta \cdot \left(-cosTheta\right)}, \frac{\sqrt{\frac{\mathsf{fma}\left(cosTheta, -2, 1\right)}{\pi}}}{cosTheta}, 1 + c\right)}
\end{array}
Derivation
  1. Initial program 98.1%

    \[\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. Add Preprocessing
  3. Taylor expanded in c around 0

    \[\leadsto \frac{1}{\color{blue}{1 + \left(c + \frac{e^{-1 \cdot {cosTheta}^{2}}}{cosTheta} \cdot \sqrt{\frac{1 - 2 \cdot cosTheta}{\mathsf{PI}\left(\right)}}\right)}} \]
  4. Step-by-step derivation
    1. associate-+r+N/A

      \[\leadsto \frac{1}{\color{blue}{\left(1 + c\right) + \frac{e^{-1 \cdot {cosTheta}^{2}}}{cosTheta} \cdot \sqrt{\frac{1 - 2 \cdot cosTheta}{\mathsf{PI}\left(\right)}}}} \]
    2. +-commutativeN/A

      \[\leadsto \frac{1}{\color{blue}{\frac{e^{-1 \cdot {cosTheta}^{2}}}{cosTheta} \cdot \sqrt{\frac{1 - 2 \cdot cosTheta}{\mathsf{PI}\left(\right)}} + \left(1 + c\right)}} \]
    3. lower-fma.f32N/A

      \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(\frac{e^{-1 \cdot {cosTheta}^{2}}}{cosTheta}, \sqrt{\frac{1 - 2 \cdot cosTheta}{\mathsf{PI}\left(\right)}}, 1 + c\right)}} \]
  5. Applied rewrites98.2%

    \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(\frac{e^{cosTheta \cdot \left(-cosTheta\right)}}{cosTheta}, \sqrt{\frac{\mathsf{fma}\left(cosTheta, -2, 1\right)}{\pi}}, 1 + c\right)}} \]
  6. Step-by-step derivation
    1. lift-neg.f32N/A

      \[\leadsto \frac{1}{\frac{e^{cosTheta \cdot \color{blue}{\left(\mathsf{neg}\left(cosTheta\right)\right)}}}{cosTheta} \cdot \sqrt{\frac{cosTheta \cdot -2 + 1}{\mathsf{PI}\left(\right)}} + \left(1 + c\right)} \]
    2. lift-*.f32N/A

      \[\leadsto \frac{1}{\frac{e^{\color{blue}{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}}{cosTheta} \cdot \sqrt{\frac{cosTheta \cdot -2 + 1}{\mathsf{PI}\left(\right)}} + \left(1 + c\right)} \]
    3. lift-exp.f32N/A

      \[\leadsto \frac{1}{\frac{\color{blue}{e^{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}}{cosTheta} \cdot \sqrt{\frac{cosTheta \cdot -2 + 1}{\mathsf{PI}\left(\right)}} + \left(1 + c\right)} \]
    4. lift-/.f32N/A

      \[\leadsto \frac{1}{\color{blue}{\frac{e^{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}{cosTheta}} \cdot \sqrt{\frac{cosTheta \cdot -2 + 1}{\mathsf{PI}\left(\right)}} + \left(1 + c\right)} \]
    5. lift-fma.f32N/A

      \[\leadsto \frac{1}{\frac{e^{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}{cosTheta} \cdot \sqrt{\frac{\color{blue}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}{\mathsf{PI}\left(\right)}} + \left(1 + c\right)} \]
    6. lift-PI.f32N/A

      \[\leadsto \frac{1}{\frac{e^{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}{cosTheta} \cdot \sqrt{\frac{\mathsf{fma}\left(cosTheta, -2, 1\right)}{\color{blue}{\mathsf{PI}\left(\right)}}} + \left(1 + c\right)} \]
    7. lift-/.f32N/A

      \[\leadsto \frac{1}{\frac{e^{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}{cosTheta} \cdot \sqrt{\color{blue}{\frac{\mathsf{fma}\left(cosTheta, -2, 1\right)}{\mathsf{PI}\left(\right)}}} + \left(1 + c\right)} \]
    8. lift-sqrt.f32N/A

      \[\leadsto \frac{1}{\frac{e^{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}{cosTheta} \cdot \color{blue}{\sqrt{\frac{\mathsf{fma}\left(cosTheta, -2, 1\right)}{\mathsf{PI}\left(\right)}}} + \left(1 + c\right)} \]
    9. lift-+.f32N/A

      \[\leadsto \frac{1}{\frac{e^{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}{cosTheta} \cdot \sqrt{\frac{\mathsf{fma}\left(cosTheta, -2, 1\right)}{\mathsf{PI}\left(\right)}} + \color{blue}{\left(1 + c\right)}} \]
  7. Applied rewrites98.2%

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

Alternative 3: 98.2% accurate, 2.2× speedup?

\[\begin{array}{l} \\ \frac{1}{\left(1 + c\right) + \frac{\mathsf{fma}\left(cosTheta \cdot cosTheta, \mathsf{fma}\left(cosTheta \cdot cosTheta, 0.5, -1\right), 1\right)}{cosTheta \cdot \sqrt{\frac{\pi}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}}} \end{array} \]
(FPCore (cosTheta c)
 :precision binary32
 (/
  1.0
  (+
   (+ 1.0 c)
   (/
    (fma (* cosTheta cosTheta) (fma (* cosTheta cosTheta) 0.5 -1.0) 1.0)
    (* cosTheta (sqrt (/ PI (fma cosTheta -2.0 1.0))))))))
float code(float cosTheta, float c) {
	return 1.0f / ((1.0f + c) + (fmaf((cosTheta * cosTheta), fmaf((cosTheta * cosTheta), 0.5f, -1.0f), 1.0f) / (cosTheta * sqrtf((((float) M_PI) / fmaf(cosTheta, -2.0f, 1.0f))))));
}
function code(cosTheta, c)
	return Float32(Float32(1.0) / Float32(Float32(Float32(1.0) + c) + Float32(fma(Float32(cosTheta * cosTheta), fma(Float32(cosTheta * cosTheta), Float32(0.5), Float32(-1.0)), Float32(1.0)) / Float32(cosTheta * sqrt(Float32(Float32(pi) / fma(cosTheta, Float32(-2.0), Float32(1.0))))))))
end
\begin{array}{l}

\\
\frac{1}{\left(1 + c\right) + \frac{\mathsf{fma}\left(cosTheta \cdot cosTheta, \mathsf{fma}\left(cosTheta \cdot cosTheta, 0.5, -1\right), 1\right)}{cosTheta \cdot \sqrt{\frac{\pi}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}}}
\end{array}
Derivation
  1. Initial program 98.1%

    \[\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. Add Preprocessing
  3. Taylor expanded in c around 0

    \[\leadsto \frac{1}{\color{blue}{1 + \left(c + \frac{e^{-1 \cdot {cosTheta}^{2}}}{cosTheta} \cdot \sqrt{\frac{1 - 2 \cdot cosTheta}{\mathsf{PI}\left(\right)}}\right)}} \]
  4. Step-by-step derivation
    1. associate-+r+N/A

      \[\leadsto \frac{1}{\color{blue}{\left(1 + c\right) + \frac{e^{-1 \cdot {cosTheta}^{2}}}{cosTheta} \cdot \sqrt{\frac{1 - 2 \cdot cosTheta}{\mathsf{PI}\left(\right)}}}} \]
    2. +-commutativeN/A

      \[\leadsto \frac{1}{\color{blue}{\frac{e^{-1 \cdot {cosTheta}^{2}}}{cosTheta} \cdot \sqrt{\frac{1 - 2 \cdot cosTheta}{\mathsf{PI}\left(\right)}} + \left(1 + c\right)}} \]
    3. lower-fma.f32N/A

      \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(\frac{e^{-1 \cdot {cosTheta}^{2}}}{cosTheta}, \sqrt{\frac{1 - 2 \cdot cosTheta}{\mathsf{PI}\left(\right)}}, 1 + c\right)}} \]
  5. Applied rewrites98.2%

    \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(\frac{e^{cosTheta \cdot \left(-cosTheta\right)}}{cosTheta}, \sqrt{\frac{\mathsf{fma}\left(cosTheta, -2, 1\right)}{\pi}}, 1 + c\right)}} \]
  6. Step-by-step derivation
    1. lift-fma.f32N/A

      \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{e^{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}{cosTheta}, \sqrt{\frac{\color{blue}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}{\mathsf{PI}\left(\right)}}, 1 + c\right)} \]
    2. lift-PI.f32N/A

      \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{e^{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}{cosTheta}, \sqrt{\frac{\mathsf{fma}\left(cosTheta, -2, 1\right)}{\color{blue}{\mathsf{PI}\left(\right)}}}, 1 + c\right)} \]
    3. clear-numN/A

      \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{e^{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}{cosTheta}, \sqrt{\color{blue}{\frac{1}{\frac{\mathsf{PI}\left(\right)}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}}}, 1 + c\right)} \]
    4. sqrt-divN/A

      \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{e^{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}{cosTheta}, \color{blue}{\frac{\sqrt{1}}{\sqrt{\frac{\mathsf{PI}\left(\right)}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}}}, 1 + c\right)} \]
    5. metadata-evalN/A

      \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{e^{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}{cosTheta}, \frac{\color{blue}{1}}{\sqrt{\frac{\mathsf{PI}\left(\right)}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}}, 1 + c\right)} \]
    6. lower-/.f32N/A

      \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{e^{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}{cosTheta}, \color{blue}{\frac{1}{\sqrt{\frac{\mathsf{PI}\left(\right)}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}}}, 1 + c\right)} \]
    7. lower-sqrt.f32N/A

      \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{e^{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}{cosTheta}, \frac{1}{\color{blue}{\sqrt{\frac{\mathsf{PI}\left(\right)}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}}}, 1 + c\right)} \]
    8. lower-/.f3298.2

      \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{e^{cosTheta \cdot \left(-cosTheta\right)}}{cosTheta}, \frac{1}{\sqrt{\color{blue}{\frac{\pi}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}}}, 1 + c\right)} \]
  7. Applied rewrites98.2%

    \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{e^{cosTheta \cdot \left(-cosTheta\right)}}{cosTheta}, \color{blue}{\frac{1}{\sqrt{\frac{\pi}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}}}, 1 + c\right)} \]
  8. Step-by-step derivation
    1. lift-neg.f32N/A

      \[\leadsto \frac{1}{\frac{e^{cosTheta \cdot \color{blue}{\left(\mathsf{neg}\left(cosTheta\right)\right)}}}{cosTheta} \cdot \frac{1}{\sqrt{\frac{\mathsf{PI}\left(\right)}{cosTheta \cdot -2 + 1}}} + \left(1 + c\right)} \]
    2. lift-*.f32N/A

      \[\leadsto \frac{1}{\frac{e^{\color{blue}{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}}{cosTheta} \cdot \frac{1}{\sqrt{\frac{\mathsf{PI}\left(\right)}{cosTheta \cdot -2 + 1}}} + \left(1 + c\right)} \]
    3. lift-exp.f32N/A

      \[\leadsto \frac{1}{\frac{\color{blue}{e^{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}}{cosTheta} \cdot \frac{1}{\sqrt{\frac{\mathsf{PI}\left(\right)}{cosTheta \cdot -2 + 1}}} + \left(1 + c\right)} \]
    4. lift-/.f32N/A

      \[\leadsto \frac{1}{\color{blue}{\frac{e^{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}{cosTheta}} \cdot \frac{1}{\sqrt{\frac{\mathsf{PI}\left(\right)}{cosTheta \cdot -2 + 1}}} + \left(1 + c\right)} \]
    5. lift-PI.f32N/A

      \[\leadsto \frac{1}{\frac{e^{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}{cosTheta} \cdot \frac{1}{\sqrt{\frac{\color{blue}{\mathsf{PI}\left(\right)}}{cosTheta \cdot -2 + 1}}} + \left(1 + c\right)} \]
    6. lift-fma.f32N/A

      \[\leadsto \frac{1}{\frac{e^{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}{cosTheta} \cdot \frac{1}{\sqrt{\frac{\mathsf{PI}\left(\right)}{\color{blue}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}}} + \left(1 + c\right)} \]
    7. lift-/.f32N/A

      \[\leadsto \frac{1}{\frac{e^{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}{cosTheta} \cdot \frac{1}{\sqrt{\color{blue}{\frac{\mathsf{PI}\left(\right)}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}}} + \left(1 + c\right)} \]
    8. lift-sqrt.f32N/A

      \[\leadsto \frac{1}{\frac{e^{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}{cosTheta} \cdot \frac{1}{\color{blue}{\sqrt{\frac{\mathsf{PI}\left(\right)}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}}} + \left(1 + c\right)} \]
    9. lift-/.f32N/A

      \[\leadsto \frac{1}{\frac{e^{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}{cosTheta} \cdot \color{blue}{\frac{1}{\sqrt{\frac{\mathsf{PI}\left(\right)}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}}} + \left(1 + c\right)} \]
    10. lift-+.f32N/A

      \[\leadsto \frac{1}{\frac{e^{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}{cosTheta} \cdot \frac{1}{\sqrt{\frac{\mathsf{PI}\left(\right)}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}} + \color{blue}{\left(1 + c\right)}} \]
    11. lower-+.f32N/A

      \[\leadsto \frac{1}{\color{blue}{\frac{e^{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}{cosTheta} \cdot \frac{1}{\sqrt{\frac{\mathsf{PI}\left(\right)}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}} + \left(1 + c\right)}} \]
  9. Applied rewrites98.6%

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

    \[\leadsto \frac{1}{\frac{\color{blue}{1 + {cosTheta}^{2} \cdot \left(\frac{1}{2} \cdot {cosTheta}^{2} - 1\right)}}{cosTheta \cdot \sqrt{\frac{\mathsf{PI}\left(\right)}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}} + \left(1 + c\right)} \]
  11. Step-by-step derivation
    1. +-commutativeN/A

      \[\leadsto \frac{1}{\frac{\color{blue}{{cosTheta}^{2} \cdot \left(\frac{1}{2} \cdot {cosTheta}^{2} - 1\right) + 1}}{cosTheta \cdot \sqrt{\frac{\mathsf{PI}\left(\right)}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}} + \left(1 + c\right)} \]
    2. lower-fma.f32N/A

      \[\leadsto \frac{1}{\frac{\color{blue}{\mathsf{fma}\left({cosTheta}^{2}, \frac{1}{2} \cdot {cosTheta}^{2} - 1, 1\right)}}{cosTheta \cdot \sqrt{\frac{\mathsf{PI}\left(\right)}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}} + \left(1 + c\right)} \]
    3. unpow2N/A

      \[\leadsto \frac{1}{\frac{\mathsf{fma}\left(\color{blue}{cosTheta \cdot cosTheta}, \frac{1}{2} \cdot {cosTheta}^{2} - 1, 1\right)}{cosTheta \cdot \sqrt{\frac{\mathsf{PI}\left(\right)}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}} + \left(1 + c\right)} \]
    4. lower-*.f32N/A

      \[\leadsto \frac{1}{\frac{\mathsf{fma}\left(\color{blue}{cosTheta \cdot cosTheta}, \frac{1}{2} \cdot {cosTheta}^{2} - 1, 1\right)}{cosTheta \cdot \sqrt{\frac{\mathsf{PI}\left(\right)}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}} + \left(1 + c\right)} \]
    5. sub-negN/A

      \[\leadsto \frac{1}{\frac{\mathsf{fma}\left(cosTheta \cdot cosTheta, \color{blue}{\frac{1}{2} \cdot {cosTheta}^{2} + \left(\mathsf{neg}\left(1\right)\right)}, 1\right)}{cosTheta \cdot \sqrt{\frac{\mathsf{PI}\left(\right)}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}} + \left(1 + c\right)} \]
    6. *-commutativeN/A

      \[\leadsto \frac{1}{\frac{\mathsf{fma}\left(cosTheta \cdot cosTheta, \color{blue}{{cosTheta}^{2} \cdot \frac{1}{2}} + \left(\mathsf{neg}\left(1\right)\right), 1\right)}{cosTheta \cdot \sqrt{\frac{\mathsf{PI}\left(\right)}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}} + \left(1 + c\right)} \]
    7. metadata-evalN/A

      \[\leadsto \frac{1}{\frac{\mathsf{fma}\left(cosTheta \cdot cosTheta, {cosTheta}^{2} \cdot \frac{1}{2} + \color{blue}{-1}, 1\right)}{cosTheta \cdot \sqrt{\frac{\mathsf{PI}\left(\right)}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}} + \left(1 + c\right)} \]
    8. lower-fma.f32N/A

      \[\leadsto \frac{1}{\frac{\mathsf{fma}\left(cosTheta \cdot cosTheta, \color{blue}{\mathsf{fma}\left({cosTheta}^{2}, \frac{1}{2}, -1\right)}, 1\right)}{cosTheta \cdot \sqrt{\frac{\mathsf{PI}\left(\right)}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}} + \left(1 + c\right)} \]
    9. unpow2N/A

      \[\leadsto \frac{1}{\frac{\mathsf{fma}\left(cosTheta \cdot cosTheta, \mathsf{fma}\left(\color{blue}{cosTheta \cdot cosTheta}, \frac{1}{2}, -1\right), 1\right)}{cosTheta \cdot \sqrt{\frac{\mathsf{PI}\left(\right)}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}} + \left(1 + c\right)} \]
    10. lower-*.f3298.1

      \[\leadsto \frac{1}{\frac{\mathsf{fma}\left(cosTheta \cdot cosTheta, \mathsf{fma}\left(\color{blue}{cosTheta \cdot cosTheta}, 0.5, -1\right), 1\right)}{cosTheta \cdot \sqrt{\frac{\pi}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}} + \left(1 + c\right)} \]
  12. Applied rewrites98.1%

    \[\leadsto \frac{1}{\frac{\color{blue}{\mathsf{fma}\left(cosTheta \cdot cosTheta, \mathsf{fma}\left(cosTheta \cdot cosTheta, 0.5, -1\right), 1\right)}}{cosTheta \cdot \sqrt{\frac{\pi}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}} + \left(1 + c\right)} \]
  13. Final simplification98.1%

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

Alternative 4: 97.5% accurate, 2.3× speedup?

\[\begin{array}{l} \\ \frac{1}{\mathsf{fma}\left(\frac{\mathsf{fma}\left(cosTheta, cosTheta \cdot \mathsf{fma}\left(cosTheta \cdot cosTheta, 0.5, -1\right), 1\right)}{cosTheta}, \sqrt{\frac{\mathsf{fma}\left(cosTheta, -2, 1\right)}{\pi}}, 1 + c\right)} \end{array} \]
(FPCore (cosTheta c)
 :precision binary32
 (/
  1.0
  (fma
   (/
    (fma cosTheta (* cosTheta (fma (* cosTheta cosTheta) 0.5 -1.0)) 1.0)
    cosTheta)
   (sqrt (/ (fma cosTheta -2.0 1.0) PI))
   (+ 1.0 c))))
float code(float cosTheta, float c) {
	return 1.0f / fmaf((fmaf(cosTheta, (cosTheta * fmaf((cosTheta * cosTheta), 0.5f, -1.0f)), 1.0f) / cosTheta), sqrtf((fmaf(cosTheta, -2.0f, 1.0f) / ((float) M_PI))), (1.0f + c));
}
function code(cosTheta, c)
	return Float32(Float32(1.0) / fma(Float32(fma(cosTheta, Float32(cosTheta * fma(Float32(cosTheta * cosTheta), Float32(0.5), Float32(-1.0))), Float32(1.0)) / cosTheta), sqrt(Float32(fma(cosTheta, Float32(-2.0), Float32(1.0)) / Float32(pi))), Float32(Float32(1.0) + c)))
end
\begin{array}{l}

\\
\frac{1}{\mathsf{fma}\left(\frac{\mathsf{fma}\left(cosTheta, cosTheta \cdot \mathsf{fma}\left(cosTheta \cdot cosTheta, 0.5, -1\right), 1\right)}{cosTheta}, \sqrt{\frac{\mathsf{fma}\left(cosTheta, -2, 1\right)}{\pi}}, 1 + c\right)}
\end{array}
Derivation
  1. Initial program 98.1%

    \[\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. Add Preprocessing
  3. Taylor expanded in c around 0

    \[\leadsto \frac{1}{\color{blue}{1 + \left(c + \frac{e^{-1 \cdot {cosTheta}^{2}}}{cosTheta} \cdot \sqrt{\frac{1 - 2 \cdot cosTheta}{\mathsf{PI}\left(\right)}}\right)}} \]
  4. Step-by-step derivation
    1. associate-+r+N/A

      \[\leadsto \frac{1}{\color{blue}{\left(1 + c\right) + \frac{e^{-1 \cdot {cosTheta}^{2}}}{cosTheta} \cdot \sqrt{\frac{1 - 2 \cdot cosTheta}{\mathsf{PI}\left(\right)}}}} \]
    2. +-commutativeN/A

      \[\leadsto \frac{1}{\color{blue}{\frac{e^{-1 \cdot {cosTheta}^{2}}}{cosTheta} \cdot \sqrt{\frac{1 - 2 \cdot cosTheta}{\mathsf{PI}\left(\right)}} + \left(1 + c\right)}} \]
    3. lower-fma.f32N/A

      \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(\frac{e^{-1 \cdot {cosTheta}^{2}}}{cosTheta}, \sqrt{\frac{1 - 2 \cdot cosTheta}{\mathsf{PI}\left(\right)}}, 1 + c\right)}} \]
  5. Applied rewrites98.2%

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

    \[\leadsto \frac{1}{\mathsf{fma}\left(\color{blue}{\frac{1 + {cosTheta}^{2} \cdot \left(\frac{1}{2} \cdot {cosTheta}^{2} - 1\right)}{cosTheta}}, \sqrt{\frac{\mathsf{fma}\left(cosTheta, -2, 1\right)}{\mathsf{PI}\left(\right)}}, 1 + c\right)} \]
  7. Step-by-step derivation
    1. lower-/.f32N/A

      \[\leadsto \frac{1}{\mathsf{fma}\left(\color{blue}{\frac{1 + {cosTheta}^{2} \cdot \left(\frac{1}{2} \cdot {cosTheta}^{2} - 1\right)}{cosTheta}}, \sqrt{\frac{\mathsf{fma}\left(cosTheta, -2, 1\right)}{\mathsf{PI}\left(\right)}}, 1 + c\right)} \]
    2. +-commutativeN/A

      \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{\color{blue}{{cosTheta}^{2} \cdot \left(\frac{1}{2} \cdot {cosTheta}^{2} - 1\right) + 1}}{cosTheta}, \sqrt{\frac{\mathsf{fma}\left(cosTheta, -2, 1\right)}{\mathsf{PI}\left(\right)}}, 1 + c\right)} \]
    3. unpow2N/A

      \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{\color{blue}{\left(cosTheta \cdot cosTheta\right)} \cdot \left(\frac{1}{2} \cdot {cosTheta}^{2} - 1\right) + 1}{cosTheta}, \sqrt{\frac{\mathsf{fma}\left(cosTheta, -2, 1\right)}{\mathsf{PI}\left(\right)}}, 1 + c\right)} \]
    4. associate-*l*N/A

      \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{\color{blue}{cosTheta \cdot \left(cosTheta \cdot \left(\frac{1}{2} \cdot {cosTheta}^{2} - 1\right)\right)} + 1}{cosTheta}, \sqrt{\frac{\mathsf{fma}\left(cosTheta, -2, 1\right)}{\mathsf{PI}\left(\right)}}, 1 + c\right)} \]
    5. lower-fma.f32N/A

      \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{\color{blue}{\mathsf{fma}\left(cosTheta, cosTheta \cdot \left(\frac{1}{2} \cdot {cosTheta}^{2} - 1\right), 1\right)}}{cosTheta}, \sqrt{\frac{\mathsf{fma}\left(cosTheta, -2, 1\right)}{\mathsf{PI}\left(\right)}}, 1 + c\right)} \]
    6. lower-*.f32N/A

      \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{\mathsf{fma}\left(cosTheta, \color{blue}{cosTheta \cdot \left(\frac{1}{2} \cdot {cosTheta}^{2} - 1\right)}, 1\right)}{cosTheta}, \sqrt{\frac{\mathsf{fma}\left(cosTheta, -2, 1\right)}{\mathsf{PI}\left(\right)}}, 1 + c\right)} \]
    7. sub-negN/A

      \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{\mathsf{fma}\left(cosTheta, cosTheta \cdot \color{blue}{\left(\frac{1}{2} \cdot {cosTheta}^{2} + \left(\mathsf{neg}\left(1\right)\right)\right)}, 1\right)}{cosTheta}, \sqrt{\frac{\mathsf{fma}\left(cosTheta, -2, 1\right)}{\mathsf{PI}\left(\right)}}, 1 + c\right)} \]
    8. *-commutativeN/A

      \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{\mathsf{fma}\left(cosTheta, cosTheta \cdot \left(\color{blue}{{cosTheta}^{2} \cdot \frac{1}{2}} + \left(\mathsf{neg}\left(1\right)\right)\right), 1\right)}{cosTheta}, \sqrt{\frac{\mathsf{fma}\left(cosTheta, -2, 1\right)}{\mathsf{PI}\left(\right)}}, 1 + c\right)} \]
    9. metadata-evalN/A

      \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{\mathsf{fma}\left(cosTheta, cosTheta \cdot \left({cosTheta}^{2} \cdot \frac{1}{2} + \color{blue}{-1}\right), 1\right)}{cosTheta}, \sqrt{\frac{\mathsf{fma}\left(cosTheta, -2, 1\right)}{\mathsf{PI}\left(\right)}}, 1 + c\right)} \]
    10. lower-fma.f32N/A

      \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{\mathsf{fma}\left(cosTheta, cosTheta \cdot \color{blue}{\mathsf{fma}\left({cosTheta}^{2}, \frac{1}{2}, -1\right)}, 1\right)}{cosTheta}, \sqrt{\frac{\mathsf{fma}\left(cosTheta, -2, 1\right)}{\mathsf{PI}\left(\right)}}, 1 + c\right)} \]
    11. unpow2N/A

      \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{\mathsf{fma}\left(cosTheta, cosTheta \cdot \mathsf{fma}\left(\color{blue}{cosTheta \cdot cosTheta}, \frac{1}{2}, -1\right), 1\right)}{cosTheta}, \sqrt{\frac{\mathsf{fma}\left(cosTheta, -2, 1\right)}{\mathsf{PI}\left(\right)}}, 1 + c\right)} \]
    12. lower-*.f3297.6

      \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{\mathsf{fma}\left(cosTheta, cosTheta \cdot \mathsf{fma}\left(\color{blue}{cosTheta \cdot cosTheta}, 0.5, -1\right), 1\right)}{cosTheta}, \sqrt{\frac{\mathsf{fma}\left(cosTheta, -2, 1\right)}{\pi}}, 1 + c\right)} \]
  8. Applied rewrites97.6%

    \[\leadsto \frac{1}{\mathsf{fma}\left(\color{blue}{\frac{\mathsf{fma}\left(cosTheta, cosTheta \cdot \mathsf{fma}\left(cosTheta \cdot cosTheta, 0.5, -1\right), 1\right)}{cosTheta}}, \sqrt{\frac{\mathsf{fma}\left(cosTheta, -2, 1\right)}{\pi}}, 1 + c\right)} \]
  9. Add Preprocessing

Alternative 5: 97.6% accurate, 2.7× speedup?

\[\begin{array}{l} \\ \frac{1}{\left(1 + c\right) + \frac{\mathsf{fma}\left(cosTheta, -cosTheta, 1\right)}{cosTheta \cdot \sqrt{\frac{\pi}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}}} \end{array} \]
(FPCore (cosTheta c)
 :precision binary32
 (/
  1.0
  (+
   (+ 1.0 c)
   (/
    (fma cosTheta (- cosTheta) 1.0)
    (* cosTheta (sqrt (/ PI (fma cosTheta -2.0 1.0))))))))
float code(float cosTheta, float c) {
	return 1.0f / ((1.0f + c) + (fmaf(cosTheta, -cosTheta, 1.0f) / (cosTheta * sqrtf((((float) M_PI) / fmaf(cosTheta, -2.0f, 1.0f))))));
}
function code(cosTheta, c)
	return Float32(Float32(1.0) / Float32(Float32(Float32(1.0) + c) + Float32(fma(cosTheta, Float32(-cosTheta), Float32(1.0)) / Float32(cosTheta * sqrt(Float32(Float32(pi) / fma(cosTheta, Float32(-2.0), Float32(1.0))))))))
end
\begin{array}{l}

\\
\frac{1}{\left(1 + c\right) + \frac{\mathsf{fma}\left(cosTheta, -cosTheta, 1\right)}{cosTheta \cdot \sqrt{\frac{\pi}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}}}
\end{array}
Derivation
  1. Initial program 98.1%

    \[\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. Add Preprocessing
  3. Taylor expanded in c around 0

    \[\leadsto \frac{1}{\color{blue}{1 + \left(c + \frac{e^{-1 \cdot {cosTheta}^{2}}}{cosTheta} \cdot \sqrt{\frac{1 - 2 \cdot cosTheta}{\mathsf{PI}\left(\right)}}\right)}} \]
  4. Step-by-step derivation
    1. associate-+r+N/A

      \[\leadsto \frac{1}{\color{blue}{\left(1 + c\right) + \frac{e^{-1 \cdot {cosTheta}^{2}}}{cosTheta} \cdot \sqrt{\frac{1 - 2 \cdot cosTheta}{\mathsf{PI}\left(\right)}}}} \]
    2. +-commutativeN/A

      \[\leadsto \frac{1}{\color{blue}{\frac{e^{-1 \cdot {cosTheta}^{2}}}{cosTheta} \cdot \sqrt{\frac{1 - 2 \cdot cosTheta}{\mathsf{PI}\left(\right)}} + \left(1 + c\right)}} \]
    3. lower-fma.f32N/A

      \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(\frac{e^{-1 \cdot {cosTheta}^{2}}}{cosTheta}, \sqrt{\frac{1 - 2 \cdot cosTheta}{\mathsf{PI}\left(\right)}}, 1 + c\right)}} \]
  5. Applied rewrites98.2%

    \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(\frac{e^{cosTheta \cdot \left(-cosTheta\right)}}{cosTheta}, \sqrt{\frac{\mathsf{fma}\left(cosTheta, -2, 1\right)}{\pi}}, 1 + c\right)}} \]
  6. Step-by-step derivation
    1. lift-fma.f32N/A

      \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{e^{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}{cosTheta}, \sqrt{\frac{\color{blue}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}{\mathsf{PI}\left(\right)}}, 1 + c\right)} \]
    2. lift-PI.f32N/A

      \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{e^{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}{cosTheta}, \sqrt{\frac{\mathsf{fma}\left(cosTheta, -2, 1\right)}{\color{blue}{\mathsf{PI}\left(\right)}}}, 1 + c\right)} \]
    3. clear-numN/A

      \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{e^{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}{cosTheta}, \sqrt{\color{blue}{\frac{1}{\frac{\mathsf{PI}\left(\right)}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}}}, 1 + c\right)} \]
    4. sqrt-divN/A

      \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{e^{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}{cosTheta}, \color{blue}{\frac{\sqrt{1}}{\sqrt{\frac{\mathsf{PI}\left(\right)}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}}}, 1 + c\right)} \]
    5. metadata-evalN/A

      \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{e^{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}{cosTheta}, \frac{\color{blue}{1}}{\sqrt{\frac{\mathsf{PI}\left(\right)}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}}, 1 + c\right)} \]
    6. lower-/.f32N/A

      \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{e^{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}{cosTheta}, \color{blue}{\frac{1}{\sqrt{\frac{\mathsf{PI}\left(\right)}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}}}, 1 + c\right)} \]
    7. lower-sqrt.f32N/A

      \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{e^{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}{cosTheta}, \frac{1}{\color{blue}{\sqrt{\frac{\mathsf{PI}\left(\right)}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}}}, 1 + c\right)} \]
    8. lower-/.f3298.2

      \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{e^{cosTheta \cdot \left(-cosTheta\right)}}{cosTheta}, \frac{1}{\sqrt{\color{blue}{\frac{\pi}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}}}, 1 + c\right)} \]
  7. Applied rewrites98.2%

    \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{e^{cosTheta \cdot \left(-cosTheta\right)}}{cosTheta}, \color{blue}{\frac{1}{\sqrt{\frac{\pi}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}}}, 1 + c\right)} \]
  8. Step-by-step derivation
    1. lift-neg.f32N/A

      \[\leadsto \frac{1}{\frac{e^{cosTheta \cdot \color{blue}{\left(\mathsf{neg}\left(cosTheta\right)\right)}}}{cosTheta} \cdot \frac{1}{\sqrt{\frac{\mathsf{PI}\left(\right)}{cosTheta \cdot -2 + 1}}} + \left(1 + c\right)} \]
    2. lift-*.f32N/A

      \[\leadsto \frac{1}{\frac{e^{\color{blue}{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}}{cosTheta} \cdot \frac{1}{\sqrt{\frac{\mathsf{PI}\left(\right)}{cosTheta \cdot -2 + 1}}} + \left(1 + c\right)} \]
    3. lift-exp.f32N/A

      \[\leadsto \frac{1}{\frac{\color{blue}{e^{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}}{cosTheta} \cdot \frac{1}{\sqrt{\frac{\mathsf{PI}\left(\right)}{cosTheta \cdot -2 + 1}}} + \left(1 + c\right)} \]
    4. lift-/.f32N/A

      \[\leadsto \frac{1}{\color{blue}{\frac{e^{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}{cosTheta}} \cdot \frac{1}{\sqrt{\frac{\mathsf{PI}\left(\right)}{cosTheta \cdot -2 + 1}}} + \left(1 + c\right)} \]
    5. lift-PI.f32N/A

      \[\leadsto \frac{1}{\frac{e^{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}{cosTheta} \cdot \frac{1}{\sqrt{\frac{\color{blue}{\mathsf{PI}\left(\right)}}{cosTheta \cdot -2 + 1}}} + \left(1 + c\right)} \]
    6. lift-fma.f32N/A

      \[\leadsto \frac{1}{\frac{e^{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}{cosTheta} \cdot \frac{1}{\sqrt{\frac{\mathsf{PI}\left(\right)}{\color{blue}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}}} + \left(1 + c\right)} \]
    7. lift-/.f32N/A

      \[\leadsto \frac{1}{\frac{e^{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}{cosTheta} \cdot \frac{1}{\sqrt{\color{blue}{\frac{\mathsf{PI}\left(\right)}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}}} + \left(1 + c\right)} \]
    8. lift-sqrt.f32N/A

      \[\leadsto \frac{1}{\frac{e^{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}{cosTheta} \cdot \frac{1}{\color{blue}{\sqrt{\frac{\mathsf{PI}\left(\right)}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}}} + \left(1 + c\right)} \]
    9. lift-/.f32N/A

      \[\leadsto \frac{1}{\frac{e^{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}{cosTheta} \cdot \color{blue}{\frac{1}{\sqrt{\frac{\mathsf{PI}\left(\right)}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}}} + \left(1 + c\right)} \]
    10. lift-+.f32N/A

      \[\leadsto \frac{1}{\frac{e^{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}{cosTheta} \cdot \frac{1}{\sqrt{\frac{\mathsf{PI}\left(\right)}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}} + \color{blue}{\left(1 + c\right)}} \]
    11. lower-+.f32N/A

      \[\leadsto \frac{1}{\color{blue}{\frac{e^{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)}}{cosTheta} \cdot \frac{1}{\sqrt{\frac{\mathsf{PI}\left(\right)}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}} + \left(1 + c\right)}} \]
  9. Applied rewrites98.6%

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

    \[\leadsto \frac{1}{\frac{\color{blue}{1 + -1 \cdot {cosTheta}^{2}}}{cosTheta \cdot \sqrt{\frac{\mathsf{PI}\left(\right)}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}} + \left(1 + c\right)} \]
  11. Step-by-step derivation
    1. +-commutativeN/A

      \[\leadsto \frac{1}{\frac{\color{blue}{-1 \cdot {cosTheta}^{2} + 1}}{cosTheta \cdot \sqrt{\frac{\mathsf{PI}\left(\right)}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}} + \left(1 + c\right)} \]
    2. mul-1-negN/A

      \[\leadsto \frac{1}{\frac{\color{blue}{\left(\mathsf{neg}\left({cosTheta}^{2}\right)\right)} + 1}{cosTheta \cdot \sqrt{\frac{\mathsf{PI}\left(\right)}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}} + \left(1 + c\right)} \]
    3. unpow2N/A

      \[\leadsto \frac{1}{\frac{\left(\mathsf{neg}\left(\color{blue}{cosTheta \cdot cosTheta}\right)\right) + 1}{cosTheta \cdot \sqrt{\frac{\mathsf{PI}\left(\right)}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}} + \left(1 + c\right)} \]
    4. distribute-rgt-neg-inN/A

      \[\leadsto \frac{1}{\frac{\color{blue}{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)} + 1}{cosTheta \cdot \sqrt{\frac{\mathsf{PI}\left(\right)}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}} + \left(1 + c\right)} \]
    5. mul-1-negN/A

      \[\leadsto \frac{1}{\frac{cosTheta \cdot \color{blue}{\left(-1 \cdot cosTheta\right)} + 1}{cosTheta \cdot \sqrt{\frac{\mathsf{PI}\left(\right)}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}} + \left(1 + c\right)} \]
    6. lower-fma.f32N/A

      \[\leadsto \frac{1}{\frac{\color{blue}{\mathsf{fma}\left(cosTheta, -1 \cdot cosTheta, 1\right)}}{cosTheta \cdot \sqrt{\frac{\mathsf{PI}\left(\right)}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}} + \left(1 + c\right)} \]
    7. mul-1-negN/A

      \[\leadsto \frac{1}{\frac{\mathsf{fma}\left(cosTheta, \color{blue}{\mathsf{neg}\left(cosTheta\right)}, 1\right)}{cosTheta \cdot \sqrt{\frac{\mathsf{PI}\left(\right)}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}} + \left(1 + c\right)} \]
    8. lower-neg.f3297.2

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

    \[\leadsto \frac{1}{\frac{\color{blue}{\mathsf{fma}\left(cosTheta, -cosTheta, 1\right)}}{cosTheta \cdot \sqrt{\frac{\pi}{\mathsf{fma}\left(cosTheta, -2, 1\right)}}} + \left(1 + c\right)} \]
  13. Final simplification97.2%

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

Alternative 6: 96.9% accurate, 2.7× speedup?

\[\begin{array}{l} \\ \frac{1}{\mathsf{fma}\left(\frac{\mathsf{fma}\left(cosTheta, -cosTheta, 1\right)}{cosTheta}, \sqrt{\frac{\mathsf{fma}\left(cosTheta, -2, 1\right)}{\pi}}, 1 + c\right)} \end{array} \]
(FPCore (cosTheta c)
 :precision binary32
 (/
  1.0
  (fma
   (/ (fma cosTheta (- cosTheta) 1.0) cosTheta)
   (sqrt (/ (fma cosTheta -2.0 1.0) PI))
   (+ 1.0 c))))
float code(float cosTheta, float c) {
	return 1.0f / fmaf((fmaf(cosTheta, -cosTheta, 1.0f) / cosTheta), sqrtf((fmaf(cosTheta, -2.0f, 1.0f) / ((float) M_PI))), (1.0f + c));
}
function code(cosTheta, c)
	return Float32(Float32(1.0) / fma(Float32(fma(cosTheta, Float32(-cosTheta), Float32(1.0)) / cosTheta), sqrt(Float32(fma(cosTheta, Float32(-2.0), Float32(1.0)) / Float32(pi))), Float32(Float32(1.0) + c)))
end
\begin{array}{l}

\\
\frac{1}{\mathsf{fma}\left(\frac{\mathsf{fma}\left(cosTheta, -cosTheta, 1\right)}{cosTheta}, \sqrt{\frac{\mathsf{fma}\left(cosTheta, -2, 1\right)}{\pi}}, 1 + c\right)}
\end{array}
Derivation
  1. Initial program 98.1%

    \[\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. Add Preprocessing
  3. Taylor expanded in c around 0

    \[\leadsto \frac{1}{\color{blue}{1 + \left(c + \frac{e^{-1 \cdot {cosTheta}^{2}}}{cosTheta} \cdot \sqrt{\frac{1 - 2 \cdot cosTheta}{\mathsf{PI}\left(\right)}}\right)}} \]
  4. Step-by-step derivation
    1. associate-+r+N/A

      \[\leadsto \frac{1}{\color{blue}{\left(1 + c\right) + \frac{e^{-1 \cdot {cosTheta}^{2}}}{cosTheta} \cdot \sqrt{\frac{1 - 2 \cdot cosTheta}{\mathsf{PI}\left(\right)}}}} \]
    2. +-commutativeN/A

      \[\leadsto \frac{1}{\color{blue}{\frac{e^{-1 \cdot {cosTheta}^{2}}}{cosTheta} \cdot \sqrt{\frac{1 - 2 \cdot cosTheta}{\mathsf{PI}\left(\right)}} + \left(1 + c\right)}} \]
    3. lower-fma.f32N/A

      \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(\frac{e^{-1 \cdot {cosTheta}^{2}}}{cosTheta}, \sqrt{\frac{1 - 2 \cdot cosTheta}{\mathsf{PI}\left(\right)}}, 1 + c\right)}} \]
  5. Applied rewrites98.2%

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

    \[\leadsto \frac{1}{\mathsf{fma}\left(\color{blue}{\frac{1 + -1 \cdot {cosTheta}^{2}}{cosTheta}}, \sqrt{\frac{\mathsf{fma}\left(cosTheta, -2, 1\right)}{\mathsf{PI}\left(\right)}}, 1 + c\right)} \]
  7. Step-by-step derivation
    1. lower-/.f32N/A

      \[\leadsto \frac{1}{\mathsf{fma}\left(\color{blue}{\frac{1 + -1 \cdot {cosTheta}^{2}}{cosTheta}}, \sqrt{\frac{\mathsf{fma}\left(cosTheta, -2, 1\right)}{\mathsf{PI}\left(\right)}}, 1 + c\right)} \]
    2. +-commutativeN/A

      \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{\color{blue}{-1 \cdot {cosTheta}^{2} + 1}}{cosTheta}, \sqrt{\frac{\mathsf{fma}\left(cosTheta, -2, 1\right)}{\mathsf{PI}\left(\right)}}, 1 + c\right)} \]
    3. mul-1-negN/A

      \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{\color{blue}{\left(\mathsf{neg}\left({cosTheta}^{2}\right)\right)} + 1}{cosTheta}, \sqrt{\frac{\mathsf{fma}\left(cosTheta, -2, 1\right)}{\mathsf{PI}\left(\right)}}, 1 + c\right)} \]
    4. unpow2N/A

      \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{\left(\mathsf{neg}\left(\color{blue}{cosTheta \cdot cosTheta}\right)\right) + 1}{cosTheta}, \sqrt{\frac{\mathsf{fma}\left(cosTheta, -2, 1\right)}{\mathsf{PI}\left(\right)}}, 1 + c\right)} \]
    5. distribute-rgt-neg-inN/A

      \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{\color{blue}{cosTheta \cdot \left(\mathsf{neg}\left(cosTheta\right)\right)} + 1}{cosTheta}, \sqrt{\frac{\mathsf{fma}\left(cosTheta, -2, 1\right)}{\mathsf{PI}\left(\right)}}, 1 + c\right)} \]
    6. mul-1-negN/A

      \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{cosTheta \cdot \color{blue}{\left(-1 \cdot cosTheta\right)} + 1}{cosTheta}, \sqrt{\frac{\mathsf{fma}\left(cosTheta, -2, 1\right)}{\mathsf{PI}\left(\right)}}, 1 + c\right)} \]
    7. lower-fma.f32N/A

      \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{\color{blue}{\mathsf{fma}\left(cosTheta, -1 \cdot cosTheta, 1\right)}}{cosTheta}, \sqrt{\frac{\mathsf{fma}\left(cosTheta, -2, 1\right)}{\mathsf{PI}\left(\right)}}, 1 + c\right)} \]
    8. mul-1-negN/A

      \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{\mathsf{fma}\left(cosTheta, \color{blue}{\mathsf{neg}\left(cosTheta\right)}, 1\right)}{cosTheta}, \sqrt{\frac{\mathsf{fma}\left(cosTheta, -2, 1\right)}{\mathsf{PI}\left(\right)}}, 1 + c\right)} \]
    9. lower-neg.f3296.7

      \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{\mathsf{fma}\left(cosTheta, \color{blue}{-cosTheta}, 1\right)}{cosTheta}, \sqrt{\frac{\mathsf{fma}\left(cosTheta, -2, 1\right)}{\pi}}, 1 + c\right)} \]
  8. Applied rewrites96.7%

    \[\leadsto \frac{1}{\mathsf{fma}\left(\color{blue}{\frac{\mathsf{fma}\left(cosTheta, -cosTheta, 1\right)}{cosTheta}}, \sqrt{\frac{\mathsf{fma}\left(cosTheta, -2, 1\right)}{\pi}}, 1 + c\right)} \]
  9. Add Preprocessing

Alternative 7: 96.2% accurate, 3.0× speedup?

\[\begin{array}{l} \\ \frac{1}{\frac{\mathsf{fma}\left(\mathsf{fma}\left(cosTheta, \mathsf{fma}\left(cosTheta, -1.5, -1\right), 1\right), \sqrt{\frac{1}{\pi}}, cosTheta\right)}{cosTheta}} \end{array} \]
(FPCore (cosTheta c)
 :precision binary32
 (/
  1.0
  (/
   (fma (fma cosTheta (fma cosTheta -1.5 -1.0) 1.0) (sqrt (/ 1.0 PI)) cosTheta)
   cosTheta)))
float code(float cosTheta, float c) {
	return 1.0f / (fmaf(fmaf(cosTheta, fmaf(cosTheta, -1.5f, -1.0f), 1.0f), sqrtf((1.0f / ((float) M_PI))), cosTheta) / cosTheta);
}
function code(cosTheta, c)
	return Float32(Float32(1.0) / Float32(fma(fma(cosTheta, fma(cosTheta, Float32(-1.5), Float32(-1.0)), Float32(1.0)), sqrt(Float32(Float32(1.0) / Float32(pi))), cosTheta) / cosTheta))
end
\begin{array}{l}

\\
\frac{1}{\frac{\mathsf{fma}\left(\mathsf{fma}\left(cosTheta, \mathsf{fma}\left(cosTheta, -1.5, -1\right), 1\right), \sqrt{\frac{1}{\pi}}, cosTheta\right)}{cosTheta}}
\end{array}
Derivation
  1. Initial program 98.1%

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

    \[\leadsto \frac{1}{\color{blue}{\frac{\sqrt{\frac{1}{\mathsf{PI}\left(\right)}} + cosTheta \cdot \left(1 + \left(c + \left(-1 \cdot \sqrt{\frac{1}{\mathsf{PI}\left(\right)}} + cosTheta \cdot \left(-1 \cdot \sqrt{\frac{1}{\mathsf{PI}\left(\right)}} + \frac{-1}{2} \cdot \sqrt{\frac{1}{\mathsf{PI}\left(\right)}}\right)\right)\right)\right)}{cosTheta}}} \]
  4. Step-by-step derivation
    1. lower-/.f32N/A

      \[\leadsto \frac{1}{\color{blue}{\frac{\sqrt{\frac{1}{\mathsf{PI}\left(\right)}} + cosTheta \cdot \left(1 + \left(c + \left(-1 \cdot \sqrt{\frac{1}{\mathsf{PI}\left(\right)}} + cosTheta \cdot \left(-1 \cdot \sqrt{\frac{1}{\mathsf{PI}\left(\right)}} + \frac{-1}{2} \cdot \sqrt{\frac{1}{\mathsf{PI}\left(\right)}}\right)\right)\right)\right)}{cosTheta}}} \]
  5. Applied rewrites95.7%

    \[\leadsto \frac{1}{\color{blue}{\frac{\sqrt{\frac{1}{\pi}} + \mathsf{fma}\left(cosTheta, \mathsf{fma}\left(\sqrt{\frac{1}{\pi}}, \mathsf{fma}\left(-1.5, cosTheta, -1\right), c\right), cosTheta\right)}{cosTheta}}} \]
  6. Taylor expanded in c around 0

    \[\leadsto \frac{1}{\frac{\color{blue}{cosTheta + \left(\sqrt{\frac{1}{\mathsf{PI}\left(\right)}} + \left(cosTheta \cdot \left(\frac{-3}{2} \cdot cosTheta - 1\right)\right) \cdot \sqrt{\frac{1}{\mathsf{PI}\left(\right)}}\right)}}{cosTheta}} \]
  7. Step-by-step derivation
    1. +-commutativeN/A

      \[\leadsto \frac{1}{\frac{\color{blue}{\left(\sqrt{\frac{1}{\mathsf{PI}\left(\right)}} + \left(cosTheta \cdot \left(\frac{-3}{2} \cdot cosTheta - 1\right)\right) \cdot \sqrt{\frac{1}{\mathsf{PI}\left(\right)}}\right) + cosTheta}}{cosTheta}} \]
    2. distribute-rgt1-inN/A

      \[\leadsto \frac{1}{\frac{\color{blue}{\left(cosTheta \cdot \left(\frac{-3}{2} \cdot cosTheta - 1\right) + 1\right) \cdot \sqrt{\frac{1}{\mathsf{PI}\left(\right)}}} + cosTheta}{cosTheta}} \]
    3. lower-fma.f32N/A

      \[\leadsto \frac{1}{\frac{\color{blue}{\mathsf{fma}\left(cosTheta \cdot \left(\frac{-3}{2} \cdot cosTheta - 1\right) + 1, \sqrt{\frac{1}{\mathsf{PI}\left(\right)}}, cosTheta\right)}}{cosTheta}} \]
    4. lower-fma.f32N/A

      \[\leadsto \frac{1}{\frac{\mathsf{fma}\left(\color{blue}{\mathsf{fma}\left(cosTheta, \frac{-3}{2} \cdot cosTheta - 1, 1\right)}, \sqrt{\frac{1}{\mathsf{PI}\left(\right)}}, cosTheta\right)}{cosTheta}} \]
    5. sub-negN/A

      \[\leadsto \frac{1}{\frac{\mathsf{fma}\left(\mathsf{fma}\left(cosTheta, \color{blue}{\frac{-3}{2} \cdot cosTheta + \left(\mathsf{neg}\left(1\right)\right)}, 1\right), \sqrt{\frac{1}{\mathsf{PI}\left(\right)}}, cosTheta\right)}{cosTheta}} \]
    6. *-commutativeN/A

      \[\leadsto \frac{1}{\frac{\mathsf{fma}\left(\mathsf{fma}\left(cosTheta, \color{blue}{cosTheta \cdot \frac{-3}{2}} + \left(\mathsf{neg}\left(1\right)\right), 1\right), \sqrt{\frac{1}{\mathsf{PI}\left(\right)}}, cosTheta\right)}{cosTheta}} \]
    7. metadata-evalN/A

      \[\leadsto \frac{1}{\frac{\mathsf{fma}\left(\mathsf{fma}\left(cosTheta, cosTheta \cdot \frac{-3}{2} + \color{blue}{-1}, 1\right), \sqrt{\frac{1}{\mathsf{PI}\left(\right)}}, cosTheta\right)}{cosTheta}} \]
    8. lower-fma.f32N/A

      \[\leadsto \frac{1}{\frac{\mathsf{fma}\left(\mathsf{fma}\left(cosTheta, \color{blue}{\mathsf{fma}\left(cosTheta, \frac{-3}{2}, -1\right)}, 1\right), \sqrt{\frac{1}{\mathsf{PI}\left(\right)}}, cosTheta\right)}{cosTheta}} \]
    9. lower-sqrt.f32N/A

      \[\leadsto \frac{1}{\frac{\mathsf{fma}\left(\mathsf{fma}\left(cosTheta, \mathsf{fma}\left(cosTheta, \frac{-3}{2}, -1\right), 1\right), \color{blue}{\sqrt{\frac{1}{\mathsf{PI}\left(\right)}}}, cosTheta\right)}{cosTheta}} \]
    10. lower-/.f32N/A

      \[\leadsto \frac{1}{\frac{\mathsf{fma}\left(\mathsf{fma}\left(cosTheta, \mathsf{fma}\left(cosTheta, \frac{-3}{2}, -1\right), 1\right), \sqrt{\color{blue}{\frac{1}{\mathsf{PI}\left(\right)}}}, cosTheta\right)}{cosTheta}} \]
    11. lower-PI.f3295.0

      \[\leadsto \frac{1}{\frac{\mathsf{fma}\left(\mathsf{fma}\left(cosTheta, \mathsf{fma}\left(cosTheta, -1.5, -1\right), 1\right), \sqrt{\frac{1}{\color{blue}{\pi}}}, cosTheta\right)}{cosTheta}} \]
  8. Applied rewrites95.0%

    \[\leadsto \frac{1}{\frac{\color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(cosTheta, \mathsf{fma}\left(cosTheta, -1.5, -1\right), 1\right), \sqrt{\frac{1}{\pi}}, cosTheta\right)}}{cosTheta}} \]
  9. Add Preprocessing

Alternative 8: 96.3% accurate, 3.6× speedup?

\[\begin{array}{l} \\ \frac{cosTheta}{\mathsf{fma}\left(\mathsf{fma}\left(cosTheta, \mathsf{fma}\left(cosTheta, -1.5, -1\right), 1\right), \sqrt{\frac{1}{\pi}}, cosTheta\right)} \end{array} \]
(FPCore (cosTheta c)
 :precision binary32
 (/
  cosTheta
  (fma
   (fma cosTheta (fma cosTheta -1.5 -1.0) 1.0)
   (sqrt (/ 1.0 PI))
   cosTheta)))
float code(float cosTheta, float c) {
	return cosTheta / fmaf(fmaf(cosTheta, fmaf(cosTheta, -1.5f, -1.0f), 1.0f), sqrtf((1.0f / ((float) M_PI))), cosTheta);
}
function code(cosTheta, c)
	return Float32(cosTheta / fma(fma(cosTheta, fma(cosTheta, Float32(-1.5), Float32(-1.0)), Float32(1.0)), sqrt(Float32(Float32(1.0) / Float32(pi))), cosTheta))
end
\begin{array}{l}

\\
\frac{cosTheta}{\mathsf{fma}\left(\mathsf{fma}\left(cosTheta, \mathsf{fma}\left(cosTheta, -1.5, -1\right), 1\right), \sqrt{\frac{1}{\pi}}, cosTheta\right)}
\end{array}
Derivation
  1. Initial program 98.1%

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

    \[\leadsto \frac{1}{\color{blue}{\frac{\sqrt{\frac{1}{\mathsf{PI}\left(\right)}} + cosTheta \cdot \left(1 + \left(c + \left(-1 \cdot \sqrt{\frac{1}{\mathsf{PI}\left(\right)}} + cosTheta \cdot \left(-1 \cdot \sqrt{\frac{1}{\mathsf{PI}\left(\right)}} + \frac{-1}{2} \cdot \sqrt{\frac{1}{\mathsf{PI}\left(\right)}}\right)\right)\right)\right)}{cosTheta}}} \]
  4. Step-by-step derivation
    1. lower-/.f32N/A

      \[\leadsto \frac{1}{\color{blue}{\frac{\sqrt{\frac{1}{\mathsf{PI}\left(\right)}} + cosTheta \cdot \left(1 + \left(c + \left(-1 \cdot \sqrt{\frac{1}{\mathsf{PI}\left(\right)}} + cosTheta \cdot \left(-1 \cdot \sqrt{\frac{1}{\mathsf{PI}\left(\right)}} + \frac{-1}{2} \cdot \sqrt{\frac{1}{\mathsf{PI}\left(\right)}}\right)\right)\right)\right)}{cosTheta}}} \]
  5. Applied rewrites95.7%

    \[\leadsto \frac{1}{\color{blue}{\frac{\sqrt{\frac{1}{\pi}} + \mathsf{fma}\left(cosTheta, \mathsf{fma}\left(\sqrt{\frac{1}{\pi}}, \mathsf{fma}\left(-1.5, cosTheta, -1\right), c\right), cosTheta\right)}{cosTheta}}} \]
  6. Taylor expanded in c around 0

    \[\leadsto \color{blue}{\frac{cosTheta}{cosTheta + \left(\sqrt{\frac{1}{\mathsf{PI}\left(\right)}} + \left(cosTheta \cdot \left(\frac{-3}{2} \cdot cosTheta - 1\right)\right) \cdot \sqrt{\frac{1}{\mathsf{PI}\left(\right)}}\right)}} \]
  7. Step-by-step derivation
    1. lower-/.f32N/A

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

      \[\leadsto \frac{cosTheta}{\color{blue}{\left(\sqrt{\frac{1}{\mathsf{PI}\left(\right)}} + \left(cosTheta \cdot \left(\frac{-3}{2} \cdot cosTheta - 1\right)\right) \cdot \sqrt{\frac{1}{\mathsf{PI}\left(\right)}}\right) + cosTheta}} \]
    3. distribute-rgt1-inN/A

      \[\leadsto \frac{cosTheta}{\color{blue}{\left(cosTheta \cdot \left(\frac{-3}{2} \cdot cosTheta - 1\right) + 1\right) \cdot \sqrt{\frac{1}{\mathsf{PI}\left(\right)}}} + cosTheta} \]
    4. lower-fma.f32N/A

      \[\leadsto \frac{cosTheta}{\color{blue}{\mathsf{fma}\left(cosTheta \cdot \left(\frac{-3}{2} \cdot cosTheta - 1\right) + 1, \sqrt{\frac{1}{\mathsf{PI}\left(\right)}}, cosTheta\right)}} \]
    5. lower-fma.f32N/A

      \[\leadsto \frac{cosTheta}{\mathsf{fma}\left(\color{blue}{\mathsf{fma}\left(cosTheta, \frac{-3}{2} \cdot cosTheta - 1, 1\right)}, \sqrt{\frac{1}{\mathsf{PI}\left(\right)}}, cosTheta\right)} \]
    6. sub-negN/A

      \[\leadsto \frac{cosTheta}{\mathsf{fma}\left(\mathsf{fma}\left(cosTheta, \color{blue}{\frac{-3}{2} \cdot cosTheta + \left(\mathsf{neg}\left(1\right)\right)}, 1\right), \sqrt{\frac{1}{\mathsf{PI}\left(\right)}}, cosTheta\right)} \]
    7. *-commutativeN/A

      \[\leadsto \frac{cosTheta}{\mathsf{fma}\left(\mathsf{fma}\left(cosTheta, \color{blue}{cosTheta \cdot \frac{-3}{2}} + \left(\mathsf{neg}\left(1\right)\right), 1\right), \sqrt{\frac{1}{\mathsf{PI}\left(\right)}}, cosTheta\right)} \]
    8. metadata-evalN/A

      \[\leadsto \frac{cosTheta}{\mathsf{fma}\left(\mathsf{fma}\left(cosTheta, cosTheta \cdot \frac{-3}{2} + \color{blue}{-1}, 1\right), \sqrt{\frac{1}{\mathsf{PI}\left(\right)}}, cosTheta\right)} \]
    9. lower-fma.f32N/A

      \[\leadsto \frac{cosTheta}{\mathsf{fma}\left(\mathsf{fma}\left(cosTheta, \color{blue}{\mathsf{fma}\left(cosTheta, \frac{-3}{2}, -1\right)}, 1\right), \sqrt{\frac{1}{\mathsf{PI}\left(\right)}}, cosTheta\right)} \]
    10. lower-sqrt.f32N/A

      \[\leadsto \frac{cosTheta}{\mathsf{fma}\left(\mathsf{fma}\left(cosTheta, \mathsf{fma}\left(cosTheta, \frac{-3}{2}, -1\right), 1\right), \color{blue}{\sqrt{\frac{1}{\mathsf{PI}\left(\right)}}}, cosTheta\right)} \]
    11. lower-/.f32N/A

      \[\leadsto \frac{cosTheta}{\mathsf{fma}\left(\mathsf{fma}\left(cosTheta, \mathsf{fma}\left(cosTheta, \frac{-3}{2}, -1\right), 1\right), \sqrt{\color{blue}{\frac{1}{\mathsf{PI}\left(\right)}}}, cosTheta\right)} \]
    12. lower-PI.f3295.0

      \[\leadsto \frac{cosTheta}{\mathsf{fma}\left(\mathsf{fma}\left(cosTheta, \mathsf{fma}\left(cosTheta, -1.5, -1\right), 1\right), \sqrt{\frac{1}{\color{blue}{\pi}}}, cosTheta\right)} \]
  8. Applied rewrites95.0%

    \[\leadsto \color{blue}{\frac{cosTheta}{\mathsf{fma}\left(\mathsf{fma}\left(cosTheta, \mathsf{fma}\left(cosTheta, -1.5, -1\right), 1\right), \sqrt{\frac{1}{\pi}}, cosTheta\right)}} \]
  9. Add Preprocessing

Alternative 9: 95.8% accurate, 4.1× speedup?

\[\begin{array}{l} \\ cosTheta \cdot \mathsf{fma}\left(\pi + \mathsf{fma}\left(\pi, c, -\sqrt{\pi}\right), -cosTheta, \sqrt{\pi}\right) \end{array} \]
(FPCore (cosTheta c)
 :precision binary32
 (* cosTheta (fma (+ PI (fma PI c (- (sqrt PI)))) (- cosTheta) (sqrt PI))))
float code(float cosTheta, float c) {
	return cosTheta * fmaf((((float) M_PI) + fmaf(((float) M_PI), c, -sqrtf(((float) M_PI)))), -cosTheta, sqrtf(((float) M_PI)));
}
function code(cosTheta, c)
	return Float32(cosTheta * fma(Float32(Float32(pi) + fma(Float32(pi), c, Float32(-sqrt(Float32(pi))))), Float32(-cosTheta), sqrt(Float32(pi))))
end
\begin{array}{l}

\\
cosTheta \cdot \mathsf{fma}\left(\pi + \mathsf{fma}\left(\pi, c, -\sqrt{\pi}\right), -cosTheta, \sqrt{\pi}\right)
\end{array}
Derivation
  1. Initial program 98.1%

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

    \[\leadsto \color{blue}{cosTheta \cdot \left(\sqrt{\mathsf{PI}\left(\right)} + -1 \cdot \left(cosTheta \cdot \left(\mathsf{PI}\left(\right) \cdot \left(1 + \left(c + -1 \cdot \sqrt{\frac{1}{\mathsf{PI}\left(\right)}}\right)\right)\right)\right)\right)} \]
  4. Step-by-step derivation
    1. lower-*.f32N/A

      \[\leadsto \color{blue}{cosTheta \cdot \left(\sqrt{\mathsf{PI}\left(\right)} + -1 \cdot \left(cosTheta \cdot \left(\mathsf{PI}\left(\right) \cdot \left(1 + \left(c + -1 \cdot \sqrt{\frac{1}{\mathsf{PI}\left(\right)}}\right)\right)\right)\right)\right)} \]
    2. +-commutativeN/A

      \[\leadsto cosTheta \cdot \color{blue}{\left(-1 \cdot \left(cosTheta \cdot \left(\mathsf{PI}\left(\right) \cdot \left(1 + \left(c + -1 \cdot \sqrt{\frac{1}{\mathsf{PI}\left(\right)}}\right)\right)\right)\right) + \sqrt{\mathsf{PI}\left(\right)}\right)} \]
    3. associate-*r*N/A

      \[\leadsto cosTheta \cdot \left(\color{blue}{\left(-1 \cdot cosTheta\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \left(1 + \left(c + -1 \cdot \sqrt{\frac{1}{\mathsf{PI}\left(\right)}}\right)\right)\right)} + \sqrt{\mathsf{PI}\left(\right)}\right) \]
    4. *-commutativeN/A

      \[\leadsto cosTheta \cdot \left(\color{blue}{\left(\mathsf{PI}\left(\right) \cdot \left(1 + \left(c + -1 \cdot \sqrt{\frac{1}{\mathsf{PI}\left(\right)}}\right)\right)\right) \cdot \left(-1 \cdot cosTheta\right)} + \sqrt{\mathsf{PI}\left(\right)}\right) \]
    5. lower-fma.f32N/A

      \[\leadsto cosTheta \cdot \color{blue}{\mathsf{fma}\left(\mathsf{PI}\left(\right) \cdot \left(1 + \left(c + -1 \cdot \sqrt{\frac{1}{\mathsf{PI}\left(\right)}}\right)\right), -1 \cdot cosTheta, \sqrt{\mathsf{PI}\left(\right)}\right)} \]
  5. Applied rewrites94.2%

    \[\leadsto \color{blue}{cosTheta \cdot \mathsf{fma}\left(\mathsf{fma}\left(\pi, c - \sqrt{\frac{1}{\pi}}, \pi\right), -cosTheta, \sqrt{\pi}\right)} \]
  6. Taylor expanded in c around 0

    \[\leadsto cosTheta \cdot \mathsf{fma}\left(\color{blue}{\mathsf{PI}\left(\right) + \left(-1 \cdot \sqrt{\mathsf{PI}\left(\right)} + c \cdot \mathsf{PI}\left(\right)\right)}, \mathsf{neg}\left(cosTheta\right), \sqrt{\mathsf{PI}\left(\right)}\right) \]
  7. Step-by-step derivation
    1. lower-+.f32N/A

      \[\leadsto cosTheta \cdot \mathsf{fma}\left(\color{blue}{\mathsf{PI}\left(\right) + \left(-1 \cdot \sqrt{\mathsf{PI}\left(\right)} + c \cdot \mathsf{PI}\left(\right)\right)}, \mathsf{neg}\left(cosTheta\right), \sqrt{\mathsf{PI}\left(\right)}\right) \]
    2. lower-PI.f32N/A

      \[\leadsto cosTheta \cdot \mathsf{fma}\left(\color{blue}{\mathsf{PI}\left(\right)} + \left(-1 \cdot \sqrt{\mathsf{PI}\left(\right)} + c \cdot \mathsf{PI}\left(\right)\right), \mathsf{neg}\left(cosTheta\right), \sqrt{\mathsf{PI}\left(\right)}\right) \]
    3. +-commutativeN/A

      \[\leadsto cosTheta \cdot \mathsf{fma}\left(\mathsf{PI}\left(\right) + \color{blue}{\left(c \cdot \mathsf{PI}\left(\right) + -1 \cdot \sqrt{\mathsf{PI}\left(\right)}\right)}, \mathsf{neg}\left(cosTheta\right), \sqrt{\mathsf{PI}\left(\right)}\right) \]
    4. *-commutativeN/A

      \[\leadsto cosTheta \cdot \mathsf{fma}\left(\mathsf{PI}\left(\right) + \left(\color{blue}{\mathsf{PI}\left(\right) \cdot c} + -1 \cdot \sqrt{\mathsf{PI}\left(\right)}\right), \mathsf{neg}\left(cosTheta\right), \sqrt{\mathsf{PI}\left(\right)}\right) \]
    5. lower-fma.f32N/A

      \[\leadsto cosTheta \cdot \mathsf{fma}\left(\mathsf{PI}\left(\right) + \color{blue}{\mathsf{fma}\left(\mathsf{PI}\left(\right), c, -1 \cdot \sqrt{\mathsf{PI}\left(\right)}\right)}, \mathsf{neg}\left(cosTheta\right), \sqrt{\mathsf{PI}\left(\right)}\right) \]
    6. lower-PI.f32N/A

      \[\leadsto cosTheta \cdot \mathsf{fma}\left(\mathsf{PI}\left(\right) + \mathsf{fma}\left(\color{blue}{\mathsf{PI}\left(\right)}, c, -1 \cdot \sqrt{\mathsf{PI}\left(\right)}\right), \mathsf{neg}\left(cosTheta\right), \sqrt{\mathsf{PI}\left(\right)}\right) \]
    7. mul-1-negN/A

      \[\leadsto cosTheta \cdot \mathsf{fma}\left(\mathsf{PI}\left(\right) + \mathsf{fma}\left(\mathsf{PI}\left(\right), c, \color{blue}{\mathsf{neg}\left(\sqrt{\mathsf{PI}\left(\right)}\right)}\right), \mathsf{neg}\left(cosTheta\right), \sqrt{\mathsf{PI}\left(\right)}\right) \]
    8. lower-neg.f32N/A

      \[\leadsto cosTheta \cdot \mathsf{fma}\left(\mathsf{PI}\left(\right) + \mathsf{fma}\left(\mathsf{PI}\left(\right), c, \color{blue}{\mathsf{neg}\left(\sqrt{\mathsf{PI}\left(\right)}\right)}\right), \mathsf{neg}\left(cosTheta\right), \sqrt{\mathsf{PI}\left(\right)}\right) \]
    9. lower-sqrt.f32N/A

      \[\leadsto cosTheta \cdot \mathsf{fma}\left(\mathsf{PI}\left(\right) + \mathsf{fma}\left(\mathsf{PI}\left(\right), c, \mathsf{neg}\left(\color{blue}{\sqrt{\mathsf{PI}\left(\right)}}\right)\right), \mathsf{neg}\left(cosTheta\right), \sqrt{\mathsf{PI}\left(\right)}\right) \]
    10. lower-PI.f3294.2

      \[\leadsto cosTheta \cdot \mathsf{fma}\left(\pi + \mathsf{fma}\left(\pi, c, -\sqrt{\color{blue}{\pi}}\right), -cosTheta, \sqrt{\pi}\right) \]
  8. Applied rewrites94.2%

    \[\leadsto cosTheta \cdot \mathsf{fma}\left(\color{blue}{\pi + \mathsf{fma}\left(\pi, c, -\sqrt{\pi}\right)}, -cosTheta, \sqrt{\pi}\right) \]
  9. Add Preprocessing

Alternative 10: 95.7% accurate, 4.9× speedup?

\[\begin{array}{l} \\ cosTheta \cdot \mathsf{fma}\left(\pi - \sqrt{\pi}, -cosTheta, \sqrt{\pi}\right) \end{array} \]
(FPCore (cosTheta c)
 :precision binary32
 (* cosTheta (fma (- PI (sqrt PI)) (- cosTheta) (sqrt PI))))
float code(float cosTheta, float c) {
	return cosTheta * fmaf((((float) M_PI) - sqrtf(((float) M_PI))), -cosTheta, sqrtf(((float) M_PI)));
}
function code(cosTheta, c)
	return Float32(cosTheta * fma(Float32(Float32(pi) - sqrt(Float32(pi))), Float32(-cosTheta), sqrt(Float32(pi))))
end
\begin{array}{l}

\\
cosTheta \cdot \mathsf{fma}\left(\pi - \sqrt{\pi}, -cosTheta, \sqrt{\pi}\right)
\end{array}
Derivation
  1. Initial program 98.1%

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

    \[\leadsto \color{blue}{cosTheta \cdot \left(\sqrt{\mathsf{PI}\left(\right)} + -1 \cdot \left(cosTheta \cdot \left(\mathsf{PI}\left(\right) \cdot \left(1 + \left(c + -1 \cdot \sqrt{\frac{1}{\mathsf{PI}\left(\right)}}\right)\right)\right)\right)\right)} \]
  4. Step-by-step derivation
    1. lower-*.f32N/A

      \[\leadsto \color{blue}{cosTheta \cdot \left(\sqrt{\mathsf{PI}\left(\right)} + -1 \cdot \left(cosTheta \cdot \left(\mathsf{PI}\left(\right) \cdot \left(1 + \left(c + -1 \cdot \sqrt{\frac{1}{\mathsf{PI}\left(\right)}}\right)\right)\right)\right)\right)} \]
    2. +-commutativeN/A

      \[\leadsto cosTheta \cdot \color{blue}{\left(-1 \cdot \left(cosTheta \cdot \left(\mathsf{PI}\left(\right) \cdot \left(1 + \left(c + -1 \cdot \sqrt{\frac{1}{\mathsf{PI}\left(\right)}}\right)\right)\right)\right) + \sqrt{\mathsf{PI}\left(\right)}\right)} \]
    3. associate-*r*N/A

      \[\leadsto cosTheta \cdot \left(\color{blue}{\left(-1 \cdot cosTheta\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \left(1 + \left(c + -1 \cdot \sqrt{\frac{1}{\mathsf{PI}\left(\right)}}\right)\right)\right)} + \sqrt{\mathsf{PI}\left(\right)}\right) \]
    4. *-commutativeN/A

      \[\leadsto cosTheta \cdot \left(\color{blue}{\left(\mathsf{PI}\left(\right) \cdot \left(1 + \left(c + -1 \cdot \sqrt{\frac{1}{\mathsf{PI}\left(\right)}}\right)\right)\right) \cdot \left(-1 \cdot cosTheta\right)} + \sqrt{\mathsf{PI}\left(\right)}\right) \]
    5. lower-fma.f32N/A

      \[\leadsto cosTheta \cdot \color{blue}{\mathsf{fma}\left(\mathsf{PI}\left(\right) \cdot \left(1 + \left(c + -1 \cdot \sqrt{\frac{1}{\mathsf{PI}\left(\right)}}\right)\right), -1 \cdot cosTheta, \sqrt{\mathsf{PI}\left(\right)}\right)} \]
  5. Applied rewrites94.2%

    \[\leadsto \color{blue}{cosTheta \cdot \mathsf{fma}\left(\mathsf{fma}\left(\pi, c - \sqrt{\frac{1}{\pi}}, \pi\right), -cosTheta, \sqrt{\pi}\right)} \]
  6. Taylor expanded in c around 0

    \[\leadsto cosTheta \cdot \mathsf{fma}\left(\color{blue}{\mathsf{PI}\left(\right) + -1 \cdot \sqrt{\mathsf{PI}\left(\right)}}, \mathsf{neg}\left(cosTheta\right), \sqrt{\mathsf{PI}\left(\right)}\right) \]
  7. Step-by-step derivation
    1. mul-1-negN/A

      \[\leadsto cosTheta \cdot \mathsf{fma}\left(\mathsf{PI}\left(\right) + \color{blue}{\left(\mathsf{neg}\left(\sqrt{\mathsf{PI}\left(\right)}\right)\right)}, \mathsf{neg}\left(cosTheta\right), \sqrt{\mathsf{PI}\left(\right)}\right) \]
    2. unsub-negN/A

      \[\leadsto cosTheta \cdot \mathsf{fma}\left(\color{blue}{\mathsf{PI}\left(\right) - \sqrt{\mathsf{PI}\left(\right)}}, \mathsf{neg}\left(cosTheta\right), \sqrt{\mathsf{PI}\left(\right)}\right) \]
    3. lower--.f32N/A

      \[\leadsto cosTheta \cdot \mathsf{fma}\left(\color{blue}{\mathsf{PI}\left(\right) - \sqrt{\mathsf{PI}\left(\right)}}, \mathsf{neg}\left(cosTheta\right), \sqrt{\mathsf{PI}\left(\right)}\right) \]
    4. lower-PI.f32N/A

      \[\leadsto cosTheta \cdot \mathsf{fma}\left(\color{blue}{\mathsf{PI}\left(\right)} - \sqrt{\mathsf{PI}\left(\right)}, \mathsf{neg}\left(cosTheta\right), \sqrt{\mathsf{PI}\left(\right)}\right) \]
    5. lower-sqrt.f32N/A

      \[\leadsto cosTheta \cdot \mathsf{fma}\left(\mathsf{PI}\left(\right) - \color{blue}{\sqrt{\mathsf{PI}\left(\right)}}, \mathsf{neg}\left(cosTheta\right), \sqrt{\mathsf{PI}\left(\right)}\right) \]
    6. lower-PI.f3293.9

      \[\leadsto cosTheta \cdot \mathsf{fma}\left(\pi - \sqrt{\color{blue}{\pi}}, -cosTheta, \sqrt{\pi}\right) \]
  8. Applied rewrites93.9%

    \[\leadsto cosTheta \cdot \mathsf{fma}\left(\color{blue}{\pi - \sqrt{\pi}}, -cosTheta, \sqrt{\pi}\right) \]
  9. Add Preprocessing

Alternative 11: 92.8% accurate, 5.5× speedup?

\[\begin{array}{l} \\ \frac{\sqrt{\pi}}{\frac{1}{cosTheta}} \end{array} \]
(FPCore (cosTheta c) :precision binary32 (/ (sqrt PI) (/ 1.0 cosTheta)))
float code(float cosTheta, float c) {
	return sqrtf(((float) M_PI)) / (1.0f / cosTheta);
}
function code(cosTheta, c)
	return Float32(sqrt(Float32(pi)) / Float32(Float32(1.0) / cosTheta))
end
function tmp = code(cosTheta, c)
	tmp = sqrt(single(pi)) / (single(1.0) / cosTheta);
end
\begin{array}{l}

\\
\frac{\sqrt{\pi}}{\frac{1}{cosTheta}}
\end{array}
Derivation
  1. Initial program 98.1%

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

    \[\leadsto \frac{1}{\color{blue}{\frac{1}{cosTheta} \cdot \sqrt{\frac{1}{\mathsf{PI}\left(\right)}}}} \]
  4. Step-by-step derivation
    1. associate-*l/N/A

      \[\leadsto \frac{1}{\color{blue}{\frac{1 \cdot \sqrt{\frac{1}{\mathsf{PI}\left(\right)}}}{cosTheta}}} \]
    2. *-lft-identityN/A

      \[\leadsto \frac{1}{\frac{\color{blue}{\sqrt{\frac{1}{\mathsf{PI}\left(\right)}}}}{cosTheta}} \]
    3. lower-/.f32N/A

      \[\leadsto \frac{1}{\color{blue}{\frac{\sqrt{\frac{1}{\mathsf{PI}\left(\right)}}}{cosTheta}}} \]
    4. lower-sqrt.f32N/A

      \[\leadsto \frac{1}{\frac{\color{blue}{\sqrt{\frac{1}{\mathsf{PI}\left(\right)}}}}{cosTheta}} \]
    5. lower-/.f32N/A

      \[\leadsto \frac{1}{\frac{\sqrt{\color{blue}{\frac{1}{\mathsf{PI}\left(\right)}}}}{cosTheta}} \]
    6. lower-PI.f3290.6

      \[\leadsto \frac{1}{\frac{\sqrt{\frac{1}{\color{blue}{\pi}}}}{cosTheta}} \]
  5. Applied rewrites90.6%

    \[\leadsto \frac{1}{\color{blue}{\frac{\sqrt{\frac{1}{\pi}}}{cosTheta}}} \]
  6. Step-by-step derivation
    1. lift-PI.f32N/A

      \[\leadsto \frac{1}{\frac{\sqrt{\frac{1}{\color{blue}{\mathsf{PI}\left(\right)}}}}{cosTheta}} \]
    2. lift-/.f32N/A

      \[\leadsto \frac{1}{\frac{\sqrt{\color{blue}{\frac{1}{\mathsf{PI}\left(\right)}}}}{cosTheta}} \]
    3. lift-sqrt.f32N/A

      \[\leadsto \frac{1}{\frac{\color{blue}{\sqrt{\frac{1}{\mathsf{PI}\left(\right)}}}}{cosTheta}} \]
    4. div-invN/A

      \[\leadsto \frac{1}{\color{blue}{\sqrt{\frac{1}{\mathsf{PI}\left(\right)}} \cdot \frac{1}{cosTheta}}} \]
    5. lift-/.f32N/A

      \[\leadsto \frac{1}{\sqrt{\frac{1}{\mathsf{PI}\left(\right)}} \cdot \color{blue}{\frac{1}{cosTheta}}} \]
    6. associate-/r*N/A

      \[\leadsto \color{blue}{\frac{\frac{1}{\sqrt{\frac{1}{\mathsf{PI}\left(\right)}}}}{\frac{1}{cosTheta}}} \]
    7. lift-sqrt.f32N/A

      \[\leadsto \frac{\frac{1}{\color{blue}{\sqrt{\frac{1}{\mathsf{PI}\left(\right)}}}}}{\frac{1}{cosTheta}} \]
    8. lift-/.f32N/A

      \[\leadsto \frac{\frac{1}{\sqrt{\color{blue}{\frac{1}{\mathsf{PI}\left(\right)}}}}}{\frac{1}{cosTheta}} \]
    9. sqrt-divN/A

      \[\leadsto \frac{\frac{1}{\color{blue}{\frac{\sqrt{1}}{\sqrt{\mathsf{PI}\left(\right)}}}}}{\frac{1}{cosTheta}} \]
    10. metadata-evalN/A

      \[\leadsto \frac{\frac{1}{\frac{\color{blue}{1}}{\sqrt{\mathsf{PI}\left(\right)}}}}{\frac{1}{cosTheta}} \]
    11. lift-sqrt.f32N/A

      \[\leadsto \frac{\frac{1}{\frac{1}{\color{blue}{\sqrt{\mathsf{PI}\left(\right)}}}}}{\frac{1}{cosTheta}} \]
    12. remove-double-divN/A

      \[\leadsto \frac{\color{blue}{\sqrt{\mathsf{PI}\left(\right)}}}{\frac{1}{cosTheta}} \]
    13. lower-/.f3291.2

      \[\leadsto \color{blue}{\frac{\sqrt{\pi}}{\frac{1}{cosTheta}}} \]
  7. Applied rewrites91.2%

    \[\leadsto \color{blue}{\frac{\sqrt{\pi}}{\frac{1}{cosTheta}}} \]
  8. Add Preprocessing

Alternative 12: 93.0% accurate, 11.4× speedup?

\[\begin{array}{l} \\ cosTheta \cdot \sqrt{\pi} \end{array} \]
(FPCore (cosTheta c) :precision binary32 (* cosTheta (sqrt PI)))
float code(float cosTheta, float c) {
	return cosTheta * sqrtf(((float) M_PI));
}
function code(cosTheta, c)
	return Float32(cosTheta * sqrt(Float32(pi)))
end
function tmp = code(cosTheta, c)
	tmp = cosTheta * sqrt(single(pi));
end
\begin{array}{l}

\\
cosTheta \cdot \sqrt{\pi}
\end{array}
Derivation
  1. Initial program 98.1%

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

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

      \[\leadsto \color{blue}{cosTheta \cdot \sqrt{\mathsf{PI}\left(\right)}} \]
    2. lower-sqrt.f32N/A

      \[\leadsto cosTheta \cdot \color{blue}{\sqrt{\mathsf{PI}\left(\right)}} \]
    3. lower-PI.f3291.2

      \[\leadsto cosTheta \cdot \sqrt{\color{blue}{\pi}} \]
  5. Applied rewrites91.2%

    \[\leadsto \color{blue}{cosTheta \cdot \sqrt{\pi}} \]
  6. Add Preprocessing

Alternative 13: 5.0% accurate, 15.3× speedup?

\[\begin{array}{l} \\ \frac{1}{c} \end{array} \]
(FPCore (cosTheta c) :precision binary32 (/ 1.0 c))
float code(float cosTheta, float c) {
	return 1.0f / c;
}
real(4) function code(costheta, c)
    real(4), intent (in) :: costheta
    real(4), intent (in) :: c
    code = 1.0e0 / c
end function
function code(cosTheta, c)
	return Float32(Float32(1.0) / c)
end
function tmp = code(cosTheta, c)
	tmp = single(1.0) / c;
end
\begin{array}{l}

\\
\frac{1}{c}
\end{array}
Derivation
  1. Initial program 98.1%

    \[\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. Add Preprocessing
  3. Taylor expanded in c around inf

    \[\leadsto \color{blue}{\frac{1}{c}} \]
  4. Step-by-step derivation
    1. lower-/.f325.1

      \[\leadsto \color{blue}{\frac{1}{c}} \]
  5. Applied rewrites5.1%

    \[\leadsto \color{blue}{\frac{1}{c}} \]
  6. Add Preprocessing

Reproduce

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