Beckmann Sample, normalization factor

Percentage Accurate: 97.9% → 98.7%
Time: 7.0s
Alternatives: 13
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
 (/
  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 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.9% accurate, 1.0× speedup?

\[\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
 (/
  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.7% accurate, 0.8× speedup?

\[\begin{array}{l} t_0 := \left(e^{cosTheta \cdot cosTheta} \cdot 1.7724539041519165\right) \cdot cosTheta\\ \frac{t\_0}{\mathsf{fma}\left(t\_0, c - -1, \sqrt{\left(1 - cosTheta\right) - cosTheta}\right)} \end{array} \]
(FPCore (cosTheta c)
 :precision binary32
 (let* ((t_0 (* (* (exp (* cosTheta cosTheta)) 1.7724539041519165) cosTheta)))
   (/ t_0 (fma t_0 (- c -1.0) (sqrt (- (- 1.0 cosTheta) cosTheta))))))
float code(float cosTheta, float c) {
	float t_0 = (expf((cosTheta * cosTheta)) * 1.7724539041519165f) * cosTheta;
	return t_0 / fmaf(t_0, (c - -1.0f), sqrtf(((1.0f - cosTheta) - cosTheta)));
}
function code(cosTheta, c)
	t_0 = Float32(Float32(exp(Float32(cosTheta * cosTheta)) * Float32(1.7724539041519165)) * cosTheta)
	return Float32(t_0 / fma(t_0, Float32(c - Float32(-1.0)), sqrt(Float32(Float32(Float32(1.0) - cosTheta) - cosTheta))))
end
\begin{array}{l}
t_0 := \left(e^{cosTheta \cdot cosTheta} \cdot 1.7724539041519165\right) \cdot cosTheta\\
\frac{t\_0}{\mathsf{fma}\left(t\_0, c - -1, \sqrt{\left(1 - cosTheta\right) - cosTheta}\right)}
\end{array}
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. lift-*.f32N/A

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

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

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

      \[\leadsto \frac{1}{\left(1 + c\right) + \left(\frac{1}{\sqrt{\pi}} \cdot \color{blue}{\frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}}\right) \cdot e^{\left(-cosTheta\right) \cdot cosTheta}} \]
    5. frac-timesN/A

      \[\leadsto \frac{1}{\left(1 + c\right) + \color{blue}{\frac{1 \cdot \sqrt{\left(1 - cosTheta\right) - cosTheta}}{\sqrt{\pi} \cdot cosTheta}} \cdot e^{\left(-cosTheta\right) \cdot cosTheta}} \]
    6. *-lft-identityN/A

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

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

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

      \[\leadsto \frac{1}{\left(1 + c\right) + \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\sqrt{\pi} \cdot cosTheta} \cdot e^{\color{blue}{\left(\mathsf{neg}\left(cosTheta\right)\right)} \cdot cosTheta}} \]
    10. distribute-lft-neg-outN/A

      \[\leadsto \frac{1}{\left(1 + c\right) + \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\sqrt{\pi} \cdot cosTheta} \cdot e^{\color{blue}{\mathsf{neg}\left(cosTheta \cdot cosTheta\right)}}} \]
    11. exp-negN/A

      \[\leadsto \frac{1}{\left(1 + c\right) + \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\sqrt{\pi} \cdot cosTheta} \cdot \color{blue}{\frac{1}{e^{cosTheta \cdot cosTheta}}}} \]
    12. frac-timesN/A

      \[\leadsto \frac{1}{\left(1 + c\right) + \color{blue}{\frac{\sqrt{\left(1 - cosTheta\right) - cosTheta} \cdot 1}{\left(\sqrt{\pi} \cdot cosTheta\right) \cdot e^{cosTheta \cdot cosTheta}}}} \]
    13. *-rgt-identityN/A

      \[\leadsto \frac{1}{\left(1 + c\right) + \frac{\color{blue}{\sqrt{\left(1 - cosTheta\right) - cosTheta}}}{\left(\sqrt{\pi} \cdot cosTheta\right) \cdot e^{cosTheta \cdot cosTheta}}} \]
    14. lower-/.f32N/A

      \[\leadsto \frac{1}{\left(1 + c\right) + \color{blue}{\frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\left(\sqrt{\pi} \cdot cosTheta\right) \cdot e^{cosTheta \cdot cosTheta}}}} \]
  3. Applied rewrites98.6%

    \[\leadsto \frac{1}{\left(1 + c\right) + \color{blue}{\frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\left(cosTheta \cdot \sqrt{\pi}\right) \cdot e^{cosTheta \cdot cosTheta}}}} \]
  4. Evaluated real constant98.6%

    \[\leadsto \frac{1}{\left(1 + c\right) + \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\left(cosTheta \cdot \color{blue}{1.7724539041519165}\right) \cdot e^{cosTheta \cdot cosTheta}}} \]
  5. Step-by-step derivation
    1. lift-/.f32N/A

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

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

      \[\leadsto \frac{1}{\left(1 + c\right) + \color{blue}{\frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\left(cosTheta \cdot \frac{14868421}{8388608}\right) \cdot e^{cosTheta \cdot cosTheta}}}} \]
    4. add-to-fractionN/A

      \[\leadsto \frac{1}{\color{blue}{\frac{\left(1 + c\right) \cdot \left(\left(cosTheta \cdot \frac{14868421}{8388608}\right) \cdot e^{cosTheta \cdot cosTheta}\right) + \sqrt{\left(1 - cosTheta\right) - cosTheta}}{\left(cosTheta \cdot \frac{14868421}{8388608}\right) \cdot e^{cosTheta \cdot cosTheta}}}} \]
    5. div-flip-revN/A

      \[\leadsto \color{blue}{\frac{\left(cosTheta \cdot \frac{14868421}{8388608}\right) \cdot e^{cosTheta \cdot cosTheta}}{\left(1 + c\right) \cdot \left(\left(cosTheta \cdot \frac{14868421}{8388608}\right) \cdot e^{cosTheta \cdot cosTheta}\right) + \sqrt{\left(1 - cosTheta\right) - cosTheta}}} \]
    6. lower-/.f32N/A

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

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

      \[\leadsto \frac{\color{blue}{\left(cosTheta \cdot \frac{14868421}{8388608}\right)} \cdot e^{cosTheta \cdot cosTheta}}{\left(1 + c\right) \cdot \left(\left(cosTheta \cdot \frac{14868421}{8388608}\right) \cdot e^{cosTheta \cdot cosTheta}\right) + \sqrt{\left(1 - cosTheta\right) - cosTheta}} \]
    9. associate-*l*N/A

      \[\leadsto \frac{\color{blue}{cosTheta \cdot \left(\frac{14868421}{8388608} \cdot e^{cosTheta \cdot cosTheta}\right)}}{\left(1 + c\right) \cdot \left(\left(cosTheta \cdot \frac{14868421}{8388608}\right) \cdot e^{cosTheta \cdot cosTheta}\right) + \sqrt{\left(1 - cosTheta\right) - cosTheta}} \]
    10. *-commutativeN/A

      \[\leadsto \frac{\color{blue}{\left(\frac{14868421}{8388608} \cdot e^{cosTheta \cdot cosTheta}\right) \cdot cosTheta}}{\left(1 + c\right) \cdot \left(\left(cosTheta \cdot \frac{14868421}{8388608}\right) \cdot e^{cosTheta \cdot cosTheta}\right) + \sqrt{\left(1 - cosTheta\right) - cosTheta}} \]
    11. lower-*.f32N/A

      \[\leadsto \frac{\color{blue}{\left(\frac{14868421}{8388608} \cdot e^{cosTheta \cdot cosTheta}\right) \cdot cosTheta}}{\left(1 + c\right) \cdot \left(\left(cosTheta \cdot \frac{14868421}{8388608}\right) \cdot e^{cosTheta \cdot cosTheta}\right) + \sqrt{\left(1 - cosTheta\right) - cosTheta}} \]
    12. *-commutativeN/A

      \[\leadsto \frac{\color{blue}{\left(e^{cosTheta \cdot cosTheta} \cdot \frac{14868421}{8388608}\right)} \cdot cosTheta}{\left(1 + c\right) \cdot \left(\left(cosTheta \cdot \frac{14868421}{8388608}\right) \cdot e^{cosTheta \cdot cosTheta}\right) + \sqrt{\left(1 - cosTheta\right) - cosTheta}} \]
    13. lower-*.f32N/A

      \[\leadsto \frac{\color{blue}{\left(e^{cosTheta \cdot cosTheta} \cdot \frac{14868421}{8388608}\right)} \cdot cosTheta}{\left(1 + c\right) \cdot \left(\left(cosTheta \cdot \frac{14868421}{8388608}\right) \cdot e^{cosTheta \cdot cosTheta}\right) + \sqrt{\left(1 - cosTheta\right) - cosTheta}} \]
  6. Applied rewrites98.7%

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

Alternative 2: 98.5% accurate, 1.2× speedup?

\[\frac{1}{\left(1 + c\right) + \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\left(e^{cosTheta \cdot cosTheta} \cdot cosTheta\right) \cdot 1.7724539041519165}} \]
(FPCore (cosTheta c)
 :precision binary32
 (/
  1.0
  (+
   (+ 1.0 c)
   (/
    (sqrt (- (- 1.0 cosTheta) cosTheta))
    (* (* (exp (* cosTheta cosTheta)) cosTheta) 1.7724539041519165)))))
float code(float cosTheta, float c) {
	return 1.0f / ((1.0f + c) + (sqrtf(((1.0f - cosTheta) - cosTheta)) / ((expf((cosTheta * cosTheta)) * cosTheta) * 1.7724539041519165f)));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(4) function code(costheta, c)
use fmin_fmax_functions
    real(4), intent (in) :: costheta
    real(4), intent (in) :: c
    code = 1.0e0 / ((1.0e0 + c) + (sqrt(((1.0e0 - costheta) - costheta)) / ((exp((costheta * costheta)) * costheta) * 1.7724539041519165e0)))
end function
function code(cosTheta, c)
	return Float32(Float32(1.0) / Float32(Float32(Float32(1.0) + c) + Float32(sqrt(Float32(Float32(Float32(1.0) - cosTheta) - cosTheta)) / Float32(Float32(exp(Float32(cosTheta * cosTheta)) * cosTheta) * Float32(1.7724539041519165)))))
end
function tmp = code(cosTheta, c)
	tmp = single(1.0) / ((single(1.0) + c) + (sqrt(((single(1.0) - cosTheta) - cosTheta)) / ((exp((cosTheta * cosTheta)) * cosTheta) * single(1.7724539041519165))));
end
\frac{1}{\left(1 + c\right) + \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\left(e^{cosTheta \cdot cosTheta} \cdot cosTheta\right) \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. Step-by-step derivation
    1. lift-*.f32N/A

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

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

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

      \[\leadsto \frac{1}{\left(1 + c\right) + \left(\frac{1}{\sqrt{\pi}} \cdot \color{blue}{\frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}}\right) \cdot e^{\left(-cosTheta\right) \cdot cosTheta}} \]
    5. frac-timesN/A

      \[\leadsto \frac{1}{\left(1 + c\right) + \color{blue}{\frac{1 \cdot \sqrt{\left(1 - cosTheta\right) - cosTheta}}{\sqrt{\pi} \cdot cosTheta}} \cdot e^{\left(-cosTheta\right) \cdot cosTheta}} \]
    6. *-lft-identityN/A

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

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

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

      \[\leadsto \frac{1}{\left(1 + c\right) + \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\sqrt{\pi} \cdot cosTheta} \cdot e^{\color{blue}{\left(\mathsf{neg}\left(cosTheta\right)\right)} \cdot cosTheta}} \]
    10. distribute-lft-neg-outN/A

      \[\leadsto \frac{1}{\left(1 + c\right) + \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\sqrt{\pi} \cdot cosTheta} \cdot e^{\color{blue}{\mathsf{neg}\left(cosTheta \cdot cosTheta\right)}}} \]
    11. exp-negN/A

      \[\leadsto \frac{1}{\left(1 + c\right) + \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\sqrt{\pi} \cdot cosTheta} \cdot \color{blue}{\frac{1}{e^{cosTheta \cdot cosTheta}}}} \]
    12. frac-timesN/A

      \[\leadsto \frac{1}{\left(1 + c\right) + \color{blue}{\frac{\sqrt{\left(1 - cosTheta\right) - cosTheta} \cdot 1}{\left(\sqrt{\pi} \cdot cosTheta\right) \cdot e^{cosTheta \cdot cosTheta}}}} \]
    13. *-rgt-identityN/A

      \[\leadsto \frac{1}{\left(1 + c\right) + \frac{\color{blue}{\sqrt{\left(1 - cosTheta\right) - cosTheta}}}{\left(\sqrt{\pi} \cdot cosTheta\right) \cdot e^{cosTheta \cdot cosTheta}}} \]
    14. lower-/.f32N/A

      \[\leadsto \frac{1}{\left(1 + c\right) + \color{blue}{\frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\left(\sqrt{\pi} \cdot cosTheta\right) \cdot e^{cosTheta \cdot cosTheta}}}} \]
  3. Applied rewrites98.6%

    \[\leadsto \frac{1}{\left(1 + c\right) + \color{blue}{\frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\left(cosTheta \cdot \sqrt{\pi}\right) \cdot e^{cosTheta \cdot cosTheta}}}} \]
  4. Evaluated real constant98.6%

    \[\leadsto \frac{1}{\left(1 + c\right) + \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\left(cosTheta \cdot \color{blue}{1.7724539041519165}\right) \cdot e^{cosTheta \cdot cosTheta}}} \]
  5. Step-by-step derivation
    1. lift-*.f32N/A

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

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

      \[\leadsto \frac{1}{\left(1 + c\right) + \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{e^{cosTheta \cdot cosTheta} \cdot \color{blue}{\left(cosTheta \cdot \frac{14868421}{8388608}\right)}}} \]
    4. associate-*r*N/A

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

      \[\leadsto \frac{1}{\left(1 + c\right) + \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\color{blue}{\left(e^{cosTheta \cdot cosTheta} \cdot cosTheta\right)} \cdot \frac{14868421}{8388608}}} \]
    6. lower-*.f3298.5%

      \[\leadsto \frac{1}{\left(1 + c\right) + \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\color{blue}{\left(e^{cosTheta \cdot cosTheta} \cdot cosTheta\right) \cdot 1.7724539041519165}}} \]
  6. Applied rewrites98.5%

    \[\leadsto \frac{1}{\left(1 + c\right) + \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\color{blue}{\left(e^{cosTheta \cdot cosTheta} \cdot cosTheta\right) \cdot 1.7724539041519165}}} \]
  7. Add Preprocessing

Alternative 3: 98.5% accurate, 1.2× speedup?

\[\frac{1}{c - \left(-1 - \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\left(cosTheta \cdot e^{cosTheta \cdot cosTheta}\right) \cdot 1.7724539041519165}\right)} \]
(FPCore (cosTheta c)
 :precision binary32
 (/
  1.0
  (-
   c
   (-
    -1.0
    (/
     (sqrt (- (- 1.0 cosTheta) cosTheta))
     (* (* cosTheta (exp (* cosTheta cosTheta))) 1.7724539041519165))))))
float code(float cosTheta, float c) {
	return 1.0f / (c - (-1.0f - (sqrtf(((1.0f - cosTheta) - cosTheta)) / ((cosTheta * expf((cosTheta * cosTheta))) * 1.7724539041519165f))));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(4) function code(costheta, c)
use fmin_fmax_functions
    real(4), intent (in) :: costheta
    real(4), intent (in) :: c
    code = 1.0e0 / (c - ((-1.0e0) - (sqrt(((1.0e0 - costheta) - costheta)) / ((costheta * exp((costheta * costheta))) * 1.7724539041519165e0))))
end function
function code(cosTheta, c)
	return Float32(Float32(1.0) / Float32(c - Float32(Float32(-1.0) - Float32(sqrt(Float32(Float32(Float32(1.0) - cosTheta) - cosTheta)) / Float32(Float32(cosTheta * exp(Float32(cosTheta * cosTheta))) * Float32(1.7724539041519165))))))
end
function tmp = code(cosTheta, c)
	tmp = single(1.0) / (c - (single(-1.0) - (sqrt(((single(1.0) - cosTheta) - cosTheta)) / ((cosTheta * exp((cosTheta * cosTheta))) * single(1.7724539041519165)))));
end
\frac{1}{c - \left(-1 - \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\left(cosTheta \cdot e^{cosTheta \cdot cosTheta}\right) \cdot 1.7724539041519165}\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. lift-*.f32N/A

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

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

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

      \[\leadsto \frac{1}{\left(1 + c\right) + \left(\frac{1}{\sqrt{\pi}} \cdot \color{blue}{\frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}}\right) \cdot e^{\left(-cosTheta\right) \cdot cosTheta}} \]
    5. frac-timesN/A

      \[\leadsto \frac{1}{\left(1 + c\right) + \color{blue}{\frac{1 \cdot \sqrt{\left(1 - cosTheta\right) - cosTheta}}{\sqrt{\pi} \cdot cosTheta}} \cdot e^{\left(-cosTheta\right) \cdot cosTheta}} \]
    6. *-lft-identityN/A

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

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

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

      \[\leadsto \frac{1}{\left(1 + c\right) + \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\sqrt{\pi} \cdot cosTheta} \cdot e^{\color{blue}{\left(\mathsf{neg}\left(cosTheta\right)\right)} \cdot cosTheta}} \]
    10. distribute-lft-neg-outN/A

      \[\leadsto \frac{1}{\left(1 + c\right) + \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\sqrt{\pi} \cdot cosTheta} \cdot e^{\color{blue}{\mathsf{neg}\left(cosTheta \cdot cosTheta\right)}}} \]
    11. exp-negN/A

      \[\leadsto \frac{1}{\left(1 + c\right) + \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\sqrt{\pi} \cdot cosTheta} \cdot \color{blue}{\frac{1}{e^{cosTheta \cdot cosTheta}}}} \]
    12. frac-timesN/A

      \[\leadsto \frac{1}{\left(1 + c\right) + \color{blue}{\frac{\sqrt{\left(1 - cosTheta\right) - cosTheta} \cdot 1}{\left(\sqrt{\pi} \cdot cosTheta\right) \cdot e^{cosTheta \cdot cosTheta}}}} \]
    13. *-rgt-identityN/A

      \[\leadsto \frac{1}{\left(1 + c\right) + \frac{\color{blue}{\sqrt{\left(1 - cosTheta\right) - cosTheta}}}{\left(\sqrt{\pi} \cdot cosTheta\right) \cdot e^{cosTheta \cdot cosTheta}}} \]
    14. lower-/.f32N/A

      \[\leadsto \frac{1}{\left(1 + c\right) + \color{blue}{\frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\left(\sqrt{\pi} \cdot cosTheta\right) \cdot e^{cosTheta \cdot cosTheta}}}} \]
  3. Applied rewrites98.6%

    \[\leadsto \frac{1}{\left(1 + c\right) + \color{blue}{\frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\left(cosTheta \cdot \sqrt{\pi}\right) \cdot e^{cosTheta \cdot cosTheta}}}} \]
  4. Evaluated real constant98.6%

    \[\leadsto \frac{1}{\left(1 + c\right) + \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\left(cosTheta \cdot \color{blue}{1.7724539041519165}\right) \cdot e^{cosTheta \cdot cosTheta}}} \]
  5. Step-by-step derivation
    1. lift-+.f32N/A

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

      \[\leadsto \frac{1}{\color{blue}{\left(c + 1\right)} + \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\left(cosTheta \cdot \frac{14868421}{8388608}\right) \cdot e^{cosTheta \cdot cosTheta}}} \]
    3. add-flip-revN/A

      \[\leadsto \frac{1}{\color{blue}{\left(c - \left(\mathsf{neg}\left(1\right)\right)\right)} + \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\left(cosTheta \cdot \frac{14868421}{8388608}\right) \cdot e^{cosTheta \cdot cosTheta}}} \]
    4. metadata-evalN/A

      \[\leadsto \frac{1}{\left(c - \color{blue}{-1}\right) + \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\left(cosTheta \cdot \frac{14868421}{8388608}\right) \cdot e^{cosTheta \cdot cosTheta}}} \]
    5. lower--.f3298.6%

      \[\leadsto \frac{1}{\color{blue}{\left(c - -1\right)} + \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\left(cosTheta \cdot 1.7724539041519165\right) \cdot e^{cosTheta \cdot cosTheta}}} \]
  6. Applied rewrites98.6%

    \[\leadsto \frac{1}{\color{blue}{\left(c - -1\right)} + \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\left(cosTheta \cdot 1.7724539041519165\right) \cdot e^{cosTheta \cdot cosTheta}}} \]
  7. Step-by-step derivation
    1. lift-+.f32N/A

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

      \[\leadsto \frac{1}{\color{blue}{\left(c - -1\right)} + \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\left(cosTheta \cdot \frac{14868421}{8388608}\right) \cdot e^{cosTheta \cdot cosTheta}}} \]
    3. associate-+l-N/A

      \[\leadsto \frac{1}{\color{blue}{c - \left(-1 - \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\left(cosTheta \cdot \frac{14868421}{8388608}\right) \cdot e^{cosTheta \cdot cosTheta}}\right)}} \]
    4. lower--.f32N/A

      \[\leadsto \frac{1}{\color{blue}{c - \left(-1 - \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\left(cosTheta \cdot \frac{14868421}{8388608}\right) \cdot e^{cosTheta \cdot cosTheta}}\right)}} \]
    5. lower--.f3298.6%

      \[\leadsto \frac{1}{c - \color{blue}{\left(-1 - \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\left(cosTheta \cdot 1.7724539041519165\right) \cdot e^{cosTheta \cdot cosTheta}}\right)}} \]
    6. lift-*.f32N/A

      \[\leadsto \frac{1}{c - \left(-1 - \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\color{blue}{\left(cosTheta \cdot \frac{14868421}{8388608}\right) \cdot e^{cosTheta \cdot cosTheta}}}\right)} \]
    7. lift-*.f32N/A

      \[\leadsto \frac{1}{c - \left(-1 - \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\color{blue}{\left(cosTheta \cdot \frac{14868421}{8388608}\right)} \cdot e^{cosTheta \cdot cosTheta}}\right)} \]
    8. associate-*l*N/A

      \[\leadsto \frac{1}{c - \left(-1 - \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\color{blue}{cosTheta \cdot \left(\frac{14868421}{8388608} \cdot e^{cosTheta \cdot cosTheta}\right)}}\right)} \]
    9. *-commutativeN/A

      \[\leadsto \frac{1}{c - \left(-1 - \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta \cdot \color{blue}{\left(e^{cosTheta \cdot cosTheta} \cdot \frac{14868421}{8388608}\right)}}\right)} \]
    10. associate-*r*N/A

      \[\leadsto \frac{1}{c - \left(-1 - \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\color{blue}{\left(cosTheta \cdot e^{cosTheta \cdot cosTheta}\right) \cdot \frac{14868421}{8388608}}}\right)} \]
    11. lower-*.f32N/A

      \[\leadsto \frac{1}{c - \left(-1 - \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\color{blue}{\left(cosTheta \cdot e^{cosTheta \cdot cosTheta}\right) \cdot \frac{14868421}{8388608}}}\right)} \]
    12. lower-*.f3298.5%

      \[\leadsto \frac{1}{c - \left(-1 - \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\color{blue}{\left(cosTheta \cdot e^{cosTheta \cdot cosTheta}\right)} \cdot 1.7724539041519165}\right)} \]
  8. Applied rewrites98.5%

    \[\leadsto \frac{1}{\color{blue}{c - \left(-1 - \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\left(cosTheta \cdot e^{cosTheta \cdot cosTheta}\right) \cdot 1.7724539041519165}\right)}} \]
  9. Add Preprocessing

Alternative 4: 97.9% accurate, 1.2× speedup?

\[\frac{1}{\mathsf{fma}\left(\frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta \cdot e^{cosTheta \cdot cosTheta}}, 0.5641895665989011, 1\right) + c} \]
(FPCore (cosTheta c)
 :precision binary32
 (/
  1.0
  (+
   (fma
    (/
     (sqrt (- (- 1.0 cosTheta) cosTheta))
     (* cosTheta (exp (* cosTheta cosTheta))))
    0.5641895665989011
    1.0)
   c)))
float code(float cosTheta, float c) {
	return 1.0f / (fmaf((sqrtf(((1.0f - cosTheta) - cosTheta)) / (cosTheta * expf((cosTheta * cosTheta)))), 0.5641895665989011f, 1.0f) + c);
}
function code(cosTheta, c)
	return Float32(Float32(1.0) / Float32(fma(Float32(sqrt(Float32(Float32(Float32(1.0) - cosTheta) - cosTheta)) / Float32(cosTheta * exp(Float32(cosTheta * cosTheta)))), Float32(0.5641895665989011), Float32(1.0)) + c))
end
\frac{1}{\mathsf{fma}\left(\frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta \cdot e^{cosTheta \cdot cosTheta}}, 0.5641895665989011, 1\right) + c}
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. lift-*.f32N/A

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

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

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

      \[\leadsto \frac{1}{\left(1 + c\right) + \left(\frac{1}{\sqrt{\pi}} \cdot \color{blue}{\frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}}\right) \cdot e^{\left(-cosTheta\right) \cdot cosTheta}} \]
    5. frac-timesN/A

      \[\leadsto \frac{1}{\left(1 + c\right) + \color{blue}{\frac{1 \cdot \sqrt{\left(1 - cosTheta\right) - cosTheta}}{\sqrt{\pi} \cdot cosTheta}} \cdot e^{\left(-cosTheta\right) \cdot cosTheta}} \]
    6. *-lft-identityN/A

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

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

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

      \[\leadsto \frac{1}{\left(1 + c\right) + \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\sqrt{\pi} \cdot cosTheta} \cdot e^{\color{blue}{\left(\mathsf{neg}\left(cosTheta\right)\right)} \cdot cosTheta}} \]
    10. distribute-lft-neg-outN/A

      \[\leadsto \frac{1}{\left(1 + c\right) + \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\sqrt{\pi} \cdot cosTheta} \cdot e^{\color{blue}{\mathsf{neg}\left(cosTheta \cdot cosTheta\right)}}} \]
    11. exp-negN/A

      \[\leadsto \frac{1}{\left(1 + c\right) + \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\sqrt{\pi} \cdot cosTheta} \cdot \color{blue}{\frac{1}{e^{cosTheta \cdot cosTheta}}}} \]
    12. frac-timesN/A

      \[\leadsto \frac{1}{\left(1 + c\right) + \color{blue}{\frac{\sqrt{\left(1 - cosTheta\right) - cosTheta} \cdot 1}{\left(\sqrt{\pi} \cdot cosTheta\right) \cdot e^{cosTheta \cdot cosTheta}}}} \]
    13. *-rgt-identityN/A

      \[\leadsto \frac{1}{\left(1 + c\right) + \frac{\color{blue}{\sqrt{\left(1 - cosTheta\right) - cosTheta}}}{\left(\sqrt{\pi} \cdot cosTheta\right) \cdot e^{cosTheta \cdot cosTheta}}} \]
    14. lower-/.f32N/A

      \[\leadsto \frac{1}{\left(1 + c\right) + \color{blue}{\frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\left(\sqrt{\pi} \cdot cosTheta\right) \cdot e^{cosTheta \cdot cosTheta}}}} \]
  3. Applied rewrites98.6%

    \[\leadsto \frac{1}{\left(1 + c\right) + \color{blue}{\frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\left(cosTheta \cdot \sqrt{\pi}\right) \cdot e^{cosTheta \cdot cosTheta}}}} \]
  4. Evaluated real constant98.6%

    \[\leadsto \frac{1}{\left(1 + c\right) + \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\left(cosTheta \cdot \color{blue}{1.7724539041519165}\right) \cdot e^{cosTheta \cdot cosTheta}}} \]
  5. Step-by-step derivation
    1. lift-+.f32N/A

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

      \[\leadsto \frac{1}{\color{blue}{\left(c + 1\right)} + \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\left(cosTheta \cdot \frac{14868421}{8388608}\right) \cdot e^{cosTheta \cdot cosTheta}}} \]
    3. add-flip-revN/A

      \[\leadsto \frac{1}{\color{blue}{\left(c - \left(\mathsf{neg}\left(1\right)\right)\right)} + \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\left(cosTheta \cdot \frac{14868421}{8388608}\right) \cdot e^{cosTheta \cdot cosTheta}}} \]
    4. metadata-evalN/A

      \[\leadsto \frac{1}{\left(c - \color{blue}{-1}\right) + \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\left(cosTheta \cdot \frac{14868421}{8388608}\right) \cdot e^{cosTheta \cdot cosTheta}}} \]
    5. lower--.f3298.6%

      \[\leadsto \frac{1}{\color{blue}{\left(c - -1\right)} + \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\left(cosTheta \cdot 1.7724539041519165\right) \cdot e^{cosTheta \cdot cosTheta}}} \]
  6. Applied rewrites98.6%

    \[\leadsto \frac{1}{\color{blue}{\left(c - -1\right)} + \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\left(cosTheta \cdot 1.7724539041519165\right) \cdot e^{cosTheta \cdot cosTheta}}} \]
  7. Step-by-step derivation
    1. lift-+.f32N/A

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

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

      \[\leadsto \frac{1}{\frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\left(cosTheta \cdot \frac{14868421}{8388608}\right) \cdot e^{cosTheta \cdot cosTheta}} + \color{blue}{\left(c - -1\right)}} \]
    4. sub-flipN/A

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

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

      \[\leadsto \frac{1}{\frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\left(cosTheta \cdot \frac{14868421}{8388608}\right) \cdot e^{cosTheta \cdot cosTheta}} + \color{blue}{\left(1 + c\right)}} \]
    7. associate-+r+N/A

      \[\leadsto \frac{1}{\color{blue}{\left(\frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\left(cosTheta \cdot \frac{14868421}{8388608}\right) \cdot e^{cosTheta \cdot cosTheta}} + 1\right) + c}} \]
    8. lower-+.f32N/A

      \[\leadsto \frac{1}{\color{blue}{\left(\frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\left(cosTheta \cdot \frac{14868421}{8388608}\right) \cdot e^{cosTheta \cdot cosTheta}} + 1\right) + c}} \]
  8. Applied rewrites97.9%

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

Alternative 5: 97.9% accurate, 1.2× speedup?

\[\frac{1}{\mathsf{fma}\left(\frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{e^{cosTheta \cdot cosTheta} \cdot cosTheta}, 0.5641895665989011, c - -1\right)} \]
(FPCore (cosTheta c)
 :precision binary32
 (/
  1.0
  (fma
   (/
    (sqrt (- (- 1.0 cosTheta) cosTheta))
    (* (exp (* cosTheta cosTheta)) cosTheta))
   0.5641895665989011
   (- c -1.0))))
float code(float cosTheta, float c) {
	return 1.0f / fmaf((sqrtf(((1.0f - cosTheta) - cosTheta)) / (expf((cosTheta * cosTheta)) * cosTheta)), 0.5641895665989011f, (c - -1.0f));
}
function code(cosTheta, c)
	return Float32(Float32(1.0) / fma(Float32(sqrt(Float32(Float32(Float32(1.0) - cosTheta) - cosTheta)) / Float32(exp(Float32(cosTheta * cosTheta)) * cosTheta)), Float32(0.5641895665989011), Float32(c - Float32(-1.0))))
end
\frac{1}{\mathsf{fma}\left(\frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{e^{cosTheta \cdot cosTheta} \cdot cosTheta}, 0.5641895665989011, 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. lift-*.f32N/A

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

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

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

      \[\leadsto \frac{1}{\left(1 + c\right) + \left(\frac{1}{\sqrt{\pi}} \cdot \color{blue}{\frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}}\right) \cdot e^{\left(-cosTheta\right) \cdot cosTheta}} \]
    5. frac-timesN/A

      \[\leadsto \frac{1}{\left(1 + c\right) + \color{blue}{\frac{1 \cdot \sqrt{\left(1 - cosTheta\right) - cosTheta}}{\sqrt{\pi} \cdot cosTheta}} \cdot e^{\left(-cosTheta\right) \cdot cosTheta}} \]
    6. *-lft-identityN/A

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

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

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

      \[\leadsto \frac{1}{\left(1 + c\right) + \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\sqrt{\pi} \cdot cosTheta} \cdot e^{\color{blue}{\left(\mathsf{neg}\left(cosTheta\right)\right)} \cdot cosTheta}} \]
    10. distribute-lft-neg-outN/A

      \[\leadsto \frac{1}{\left(1 + c\right) + \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\sqrt{\pi} \cdot cosTheta} \cdot e^{\color{blue}{\mathsf{neg}\left(cosTheta \cdot cosTheta\right)}}} \]
    11. exp-negN/A

      \[\leadsto \frac{1}{\left(1 + c\right) + \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\sqrt{\pi} \cdot cosTheta} \cdot \color{blue}{\frac{1}{e^{cosTheta \cdot cosTheta}}}} \]
    12. frac-timesN/A

      \[\leadsto \frac{1}{\left(1 + c\right) + \color{blue}{\frac{\sqrt{\left(1 - cosTheta\right) - cosTheta} \cdot 1}{\left(\sqrt{\pi} \cdot cosTheta\right) \cdot e^{cosTheta \cdot cosTheta}}}} \]
    13. *-rgt-identityN/A

      \[\leadsto \frac{1}{\left(1 + c\right) + \frac{\color{blue}{\sqrt{\left(1 - cosTheta\right) - cosTheta}}}{\left(\sqrt{\pi} \cdot cosTheta\right) \cdot e^{cosTheta \cdot cosTheta}}} \]
    14. lower-/.f32N/A

      \[\leadsto \frac{1}{\left(1 + c\right) + \color{blue}{\frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\left(\sqrt{\pi} \cdot cosTheta\right) \cdot e^{cosTheta \cdot cosTheta}}}} \]
  3. Applied rewrites98.6%

    \[\leadsto \frac{1}{\left(1 + c\right) + \color{blue}{\frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\left(cosTheta \cdot \sqrt{\pi}\right) \cdot e^{cosTheta \cdot cosTheta}}}} \]
  4. Evaluated real constant98.6%

    \[\leadsto \frac{1}{\left(1 + c\right) + \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\left(cosTheta \cdot \color{blue}{1.7724539041519165}\right) \cdot e^{cosTheta \cdot cosTheta}}} \]
  5. Step-by-step derivation
    1. lift-+.f32N/A

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

      \[\leadsto \frac{1}{\color{blue}{\left(c + 1\right)} + \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\left(cosTheta \cdot \frac{14868421}{8388608}\right) \cdot e^{cosTheta \cdot cosTheta}}} \]
    3. add-flip-revN/A

      \[\leadsto \frac{1}{\color{blue}{\left(c - \left(\mathsf{neg}\left(1\right)\right)\right)} + \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\left(cosTheta \cdot \frac{14868421}{8388608}\right) \cdot e^{cosTheta \cdot cosTheta}}} \]
    4. metadata-evalN/A

      \[\leadsto \frac{1}{\left(c - \color{blue}{-1}\right) + \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\left(cosTheta \cdot \frac{14868421}{8388608}\right) \cdot e^{cosTheta \cdot cosTheta}}} \]
    5. lower--.f3298.6%

      \[\leadsto \frac{1}{\color{blue}{\left(c - -1\right)} + \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\left(cosTheta \cdot 1.7724539041519165\right) \cdot e^{cosTheta \cdot cosTheta}}} \]
  6. Applied rewrites98.6%

    \[\leadsto \frac{1}{\color{blue}{\left(c - -1\right)} + \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\left(cosTheta \cdot 1.7724539041519165\right) \cdot e^{cosTheta \cdot cosTheta}}} \]
  7. Step-by-step derivation
    1. lift-+.f32N/A

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

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

      \[\leadsto \frac{1}{\color{blue}{\frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\left(cosTheta \cdot \frac{14868421}{8388608}\right) \cdot e^{cosTheta \cdot cosTheta}}} + \left(c - -1\right)} \]
    4. mult-flipN/A

      \[\leadsto \frac{1}{\color{blue}{\sqrt{\left(1 - cosTheta\right) - cosTheta} \cdot \frac{1}{\left(cosTheta \cdot \frac{14868421}{8388608}\right) \cdot e^{cosTheta \cdot cosTheta}}} + \left(c - -1\right)} \]
    5. associate-*r/N/A

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

      \[\leadsto \frac{1}{\frac{\sqrt{\left(1 - cosTheta\right) - cosTheta} \cdot 1}{\color{blue}{\left(cosTheta \cdot \frac{14868421}{8388608}\right) \cdot e^{cosTheta \cdot cosTheta}}} + \left(c - -1\right)} \]
    7. *-commutativeN/A

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

      \[\leadsto \frac{1}{\frac{\sqrt{\left(1 - cosTheta\right) - cosTheta} \cdot 1}{e^{cosTheta \cdot cosTheta} \cdot \color{blue}{\left(cosTheta \cdot \frac{14868421}{8388608}\right)}} + \left(c - -1\right)} \]
    9. associate-*r*N/A

      \[\leadsto \frac{1}{\frac{\sqrt{\left(1 - cosTheta\right) - cosTheta} \cdot 1}{\color{blue}{\left(e^{cosTheta \cdot cosTheta} \cdot cosTheta\right) \cdot \frac{14868421}{8388608}}} + \left(c - -1\right)} \]
    10. times-fracN/A

      \[\leadsto \frac{1}{\color{blue}{\frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{e^{cosTheta \cdot cosTheta} \cdot cosTheta} \cdot \frac{1}{\frac{14868421}{8388608}}} + \left(c - -1\right)} \]
    11. lift--.f32N/A

      \[\leadsto \frac{1}{\frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{e^{cosTheta \cdot cosTheta} \cdot cosTheta} \cdot \frac{1}{\frac{14868421}{8388608}} + \color{blue}{\left(c - -1\right)}} \]
    12. sub-flipN/A

      \[\leadsto \frac{1}{\frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{e^{cosTheta \cdot cosTheta} \cdot cosTheta} \cdot \frac{1}{\frac{14868421}{8388608}} + \color{blue}{\left(c + \left(\mathsf{neg}\left(-1\right)\right)\right)}} \]
    13. metadata-evalN/A

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

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

      \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(\frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{e^{cosTheta \cdot cosTheta} \cdot cosTheta}, \frac{1}{\frac{14868421}{8388608}}, 1 + c\right)}} \]
  8. Applied rewrites97.9%

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

Alternative 6: 97.1% accurate, 1.7× speedup?

\[\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}} \]
(FPCore (cosTheta c)
 :precision binary32
 (/
  1.0
  (/
   (+
    0.564189612865448
    (*
     cosTheta
     (+
      0.435810387134552
      (+
       c
       (* cosTheta (- (* 0.282094806432724 cosTheta) 0.846284419298172))))))
   cosTheta)))
float code(float cosTheta, float c) {
	return 1.0f / ((0.564189612865448f + (cosTheta * (0.435810387134552f + (c + (cosTheta * ((0.282094806432724f * cosTheta) - 0.846284419298172f)))))) / cosTheta);
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(4) function code(costheta, c)
use fmin_fmax_functions
    real(4), intent (in) :: costheta
    real(4), intent (in) :: c
    code = 1.0e0 / ((0.564189612865448e0 + (costheta * (0.435810387134552e0 + (c + (costheta * ((0.282094806432724e0 * costheta) - 0.846284419298172e0)))))) / costheta)
end function
function code(cosTheta, c)
	return Float32(Float32(1.0) / Float32(Float32(Float32(0.564189612865448) + Float32(cosTheta * Float32(Float32(0.435810387134552) + Float32(c + Float32(cosTheta * Float32(Float32(Float32(0.282094806432724) * cosTheta) - Float32(0.846284419298172))))))) / cosTheta))
end
function tmp = code(cosTheta, c)
	tmp = single(1.0) / ((single(0.564189612865448) + (cosTheta * (single(0.435810387134552) + (c + (cosTheta * ((single(0.282094806432724) * cosTheta) - single(0.846284419298172))))))) / cosTheta);
end
\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}}
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(\color{blue}{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}{\color{blue}{\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. lower-/.f32N/A

      \[\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)}{\color{blue}{cosTheta}}} \]
    2. lower-+.f32N/A

      \[\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}} \]
    3. lower-*.f32N/A

      \[\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. lower-+.f32N/A

      \[\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}} \]
    5. lower-+.f32N/A

      \[\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}} \]
    6. lower-*.f32N/A

      \[\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}} \]
    7. lower--.f32N/A

      \[\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}} \]
    8. lower-*.f3297.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}} \]
  5. Applied rewrites97.1%

    \[\leadsto \frac{1}{\color{blue}{\frac{0.564189612865448 + cosTheta \cdot \left(0.435810387134552 + \left(c + cosTheta \cdot \left(0.282094806432724 \cdot cosTheta - 0.846284419298172\right)\right)\right)}{cosTheta}}} \]
  6. Add Preprocessing

Alternative 7: 96.5% accurate, 2.0× speedup?

\[\frac{1}{\mathsf{fma}\left(\mathsf{fma}\left(-0.846284419298172, cosTheta, c\right) - -0.435810387134552, cosTheta, 0.564189612865448\right) \cdot \frac{1}{cosTheta}} \]
(FPCore (cosTheta c)
 :precision binary32
 (/
  1.0
  (*
   (fma
    (- (fma -0.846284419298172 cosTheta c) -0.435810387134552)
    cosTheta
    0.564189612865448)
   (/ 1.0 cosTheta))))
float code(float cosTheta, float c) {
	return 1.0f / (fmaf((fmaf(-0.846284419298172f, cosTheta, c) - -0.435810387134552f), cosTheta, 0.564189612865448f) * (1.0f / cosTheta));
}
function code(cosTheta, c)
	return Float32(Float32(1.0) / Float32(fma(Float32(fma(Float32(-0.846284419298172), cosTheta, c) - Float32(-0.435810387134552)), cosTheta, Float32(0.564189612865448)) * Float32(Float32(1.0) / cosTheta)))
end
\frac{1}{\mathsf{fma}\left(\mathsf{fma}\left(-0.846284419298172, cosTheta, c\right) - -0.435810387134552, cosTheta, 0.564189612865448\right) \cdot \frac{1}{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(\color{blue}{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}{\color{blue}{\frac{\frac{9465531}{16777216} + cosTheta \cdot \left(\frac{7311685}{16777216} + \left(c + \frac{-28396593}{33554432} \cdot cosTheta\right)\right)}{cosTheta}}} \]
  4. Step-by-step derivation
    1. lower-/.f32N/A

      \[\leadsto \frac{1}{\frac{\frac{9465531}{16777216} + cosTheta \cdot \left(\frac{7311685}{16777216} + \left(c + \frac{-28396593}{33554432} \cdot cosTheta\right)\right)}{\color{blue}{cosTheta}}} \]
    2. lower-+.f32N/A

      \[\leadsto \frac{1}{\frac{\frac{9465531}{16777216} + cosTheta \cdot \left(\frac{7311685}{16777216} + \left(c + \frac{-28396593}{33554432} \cdot cosTheta\right)\right)}{cosTheta}} \]
    3. lower-*.f32N/A

      \[\leadsto \frac{1}{\frac{\frac{9465531}{16777216} + cosTheta \cdot \left(\frac{7311685}{16777216} + \left(c + \frac{-28396593}{33554432} \cdot cosTheta\right)\right)}{cosTheta}} \]
    4. lower-+.f32N/A

      \[\leadsto \frac{1}{\frac{\frac{9465531}{16777216} + cosTheta \cdot \left(\frac{7311685}{16777216} + \left(c + \frac{-28396593}{33554432} \cdot cosTheta\right)\right)}{cosTheta}} \]
    5. lower-+.f32N/A

      \[\leadsto \frac{1}{\frac{\frac{9465531}{16777216} + cosTheta \cdot \left(\frac{7311685}{16777216} + \left(c + \frac{-28396593}{33554432} \cdot cosTheta\right)\right)}{cosTheta}} \]
    6. lower-*.f3296.5%

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

    \[\leadsto \frac{1}{\color{blue}{\frac{0.564189612865448 + cosTheta \cdot \left(0.435810387134552 + \left(c + -0.846284419298172 \cdot cosTheta\right)\right)}{cosTheta}}} \]
  6. Step-by-step derivation
    1. lift-/.f32N/A

      \[\leadsto \frac{1}{\frac{\frac{9465531}{16777216} + cosTheta \cdot \left(\frac{7311685}{16777216} + \left(c + \frac{-28396593}{33554432} \cdot cosTheta\right)\right)}{\color{blue}{cosTheta}}} \]
    2. mult-flipN/A

      \[\leadsto \frac{1}{\left(\frac{9465531}{16777216} + cosTheta \cdot \left(\frac{7311685}{16777216} + \left(c + \frac{-28396593}{33554432} \cdot cosTheta\right)\right)\right) \cdot \color{blue}{\frac{1}{cosTheta}}} \]
    3. lower-*.f32N/A

      \[\leadsto \frac{1}{\left(\frac{9465531}{16777216} + cosTheta \cdot \left(\frac{7311685}{16777216} + \left(c + \frac{-28396593}{33554432} \cdot cosTheta\right)\right)\right) \cdot \color{blue}{\frac{1}{cosTheta}}} \]
    4. lift-+.f32N/A

      \[\leadsto \frac{1}{\left(\frac{9465531}{16777216} + cosTheta \cdot \left(\frac{7311685}{16777216} + \left(c + \frac{-28396593}{33554432} \cdot cosTheta\right)\right)\right) \cdot \frac{\color{blue}{1}}{cosTheta}} \]
    5. +-commutativeN/A

      \[\leadsto \frac{1}{\left(cosTheta \cdot \left(\frac{7311685}{16777216} + \left(c + \frac{-28396593}{33554432} \cdot cosTheta\right)\right) + \frac{9465531}{16777216}\right) \cdot \frac{\color{blue}{1}}{cosTheta}} \]
    6. lift-*.f32N/A

      \[\leadsto \frac{1}{\left(cosTheta \cdot \left(\frac{7311685}{16777216} + \left(c + \frac{-28396593}{33554432} \cdot cosTheta\right)\right) + \frac{9465531}{16777216}\right) \cdot \frac{1}{cosTheta}} \]
    7. *-commutativeN/A

      \[\leadsto \frac{1}{\left(\left(\frac{7311685}{16777216} + \left(c + \frac{-28396593}{33554432} \cdot cosTheta\right)\right) \cdot cosTheta + \frac{9465531}{16777216}\right) \cdot \frac{1}{cosTheta}} \]
    8. lower-fma.f32N/A

      \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{7311685}{16777216} + \left(c + \frac{-28396593}{33554432} \cdot cosTheta\right), cosTheta, \frac{9465531}{16777216}\right) \cdot \frac{\color{blue}{1}}{cosTheta}} \]
    9. lift-+.f32N/A

      \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{7311685}{16777216} + \left(c + \frac{-28396593}{33554432} \cdot cosTheta\right), cosTheta, \frac{9465531}{16777216}\right) \cdot \frac{1}{cosTheta}} \]
    10. +-commutativeN/A

      \[\leadsto \frac{1}{\mathsf{fma}\left(\left(c + \frac{-28396593}{33554432} \cdot cosTheta\right) + \frac{7311685}{16777216}, cosTheta, \frac{9465531}{16777216}\right) \cdot \frac{1}{cosTheta}} \]
    11. add-flipN/A

      \[\leadsto \frac{1}{\mathsf{fma}\left(\left(c + \frac{-28396593}{33554432} \cdot cosTheta\right) - \left(\mathsf{neg}\left(\frac{7311685}{16777216}\right)\right), cosTheta, \frac{9465531}{16777216}\right) \cdot \frac{1}{cosTheta}} \]
    12. lower--.f32N/A

      \[\leadsto \frac{1}{\mathsf{fma}\left(\left(c + \frac{-28396593}{33554432} \cdot cosTheta\right) - \left(\mathsf{neg}\left(\frac{7311685}{16777216}\right)\right), cosTheta, \frac{9465531}{16777216}\right) \cdot \frac{1}{cosTheta}} \]
    13. lift-+.f32N/A

      \[\leadsto \frac{1}{\mathsf{fma}\left(\left(c + \frac{-28396593}{33554432} \cdot cosTheta\right) - \left(\mathsf{neg}\left(\frac{7311685}{16777216}\right)\right), cosTheta, \frac{9465531}{16777216}\right) \cdot \frac{1}{cosTheta}} \]
    14. +-commutativeN/A

      \[\leadsto \frac{1}{\mathsf{fma}\left(\left(\frac{-28396593}{33554432} \cdot cosTheta + c\right) - \left(\mathsf{neg}\left(\frac{7311685}{16777216}\right)\right), cosTheta, \frac{9465531}{16777216}\right) \cdot \frac{1}{cosTheta}} \]
    15. lift-*.f32N/A

      \[\leadsto \frac{1}{\mathsf{fma}\left(\left(\frac{-28396593}{33554432} \cdot cosTheta + c\right) - \left(\mathsf{neg}\left(\frac{7311685}{16777216}\right)\right), cosTheta, \frac{9465531}{16777216}\right) \cdot \frac{1}{cosTheta}} \]
    16. lower-fma.f32N/A

      \[\leadsto \frac{1}{\mathsf{fma}\left(\mathsf{fma}\left(\frac{-28396593}{33554432}, cosTheta, c\right) - \left(\mathsf{neg}\left(\frac{7311685}{16777216}\right)\right), cosTheta, \frac{9465531}{16777216}\right) \cdot \frac{1}{cosTheta}} \]
    17. metadata-evalN/A

      \[\leadsto \frac{1}{\mathsf{fma}\left(\mathsf{fma}\left(\frac{-28396593}{33554432}, cosTheta, c\right) - \frac{-7311685}{16777216}, cosTheta, \frac{9465531}{16777216}\right) \cdot \frac{1}{cosTheta}} \]
    18. lower-/.f3296.4%

      \[\leadsto \frac{1}{\mathsf{fma}\left(\mathsf{fma}\left(-0.846284419298172, cosTheta, c\right) - -0.435810387134552, cosTheta, 0.564189612865448\right) \cdot \frac{1}{\color{blue}{cosTheta}}} \]
  7. Applied rewrites96.4%

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

Alternative 8: 96.5% accurate, 2.1× speedup?

\[\frac{1}{\frac{0.564189612865448 + cosTheta \cdot \left(0.435810387134552 + \left(c + -0.846284419298172 \cdot cosTheta\right)\right)}{cosTheta}} \]
(FPCore (cosTheta c)
 :precision binary32
 (/
  1.0
  (/
   (+
    0.564189612865448
    (* cosTheta (+ 0.435810387134552 (+ c (* -0.846284419298172 cosTheta)))))
   cosTheta)))
float code(float cosTheta, float c) {
	return 1.0f / ((0.564189612865448f + (cosTheta * (0.435810387134552f + (c + (-0.846284419298172f * cosTheta))))) / cosTheta);
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(4) function code(costheta, c)
use fmin_fmax_functions
    real(4), intent (in) :: costheta
    real(4), intent (in) :: c
    code = 1.0e0 / ((0.564189612865448e0 + (costheta * (0.435810387134552e0 + (c + ((-0.846284419298172e0) * costheta))))) / costheta)
end function
function code(cosTheta, c)
	return Float32(Float32(1.0) / Float32(Float32(Float32(0.564189612865448) + Float32(cosTheta * Float32(Float32(0.435810387134552) + Float32(c + Float32(Float32(-0.846284419298172) * cosTheta))))) / cosTheta))
end
function tmp = code(cosTheta, c)
	tmp = single(1.0) / ((single(0.564189612865448) + (cosTheta * (single(0.435810387134552) + (c + (single(-0.846284419298172) * cosTheta))))) / cosTheta);
end
\frac{1}{\frac{0.564189612865448 + cosTheta \cdot \left(0.435810387134552 + \left(c + -0.846284419298172 \cdot cosTheta\right)\right)}{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(\color{blue}{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}{\color{blue}{\frac{\frac{9465531}{16777216} + cosTheta \cdot \left(\frac{7311685}{16777216} + \left(c + \frac{-28396593}{33554432} \cdot cosTheta\right)\right)}{cosTheta}}} \]
  4. Step-by-step derivation
    1. lower-/.f32N/A

      \[\leadsto \frac{1}{\frac{\frac{9465531}{16777216} + cosTheta \cdot \left(\frac{7311685}{16777216} + \left(c + \frac{-28396593}{33554432} \cdot cosTheta\right)\right)}{\color{blue}{cosTheta}}} \]
    2. lower-+.f32N/A

      \[\leadsto \frac{1}{\frac{\frac{9465531}{16777216} + cosTheta \cdot \left(\frac{7311685}{16777216} + \left(c + \frac{-28396593}{33554432} \cdot cosTheta\right)\right)}{cosTheta}} \]
    3. lower-*.f32N/A

      \[\leadsto \frac{1}{\frac{\frac{9465531}{16777216} + cosTheta \cdot \left(\frac{7311685}{16777216} + \left(c + \frac{-28396593}{33554432} \cdot cosTheta\right)\right)}{cosTheta}} \]
    4. lower-+.f32N/A

      \[\leadsto \frac{1}{\frac{\frac{9465531}{16777216} + cosTheta \cdot \left(\frac{7311685}{16777216} + \left(c + \frac{-28396593}{33554432} \cdot cosTheta\right)\right)}{cosTheta}} \]
    5. lower-+.f32N/A

      \[\leadsto \frac{1}{\frac{\frac{9465531}{16777216} + cosTheta \cdot \left(\frac{7311685}{16777216} + \left(c + \frac{-28396593}{33554432} \cdot cosTheta\right)\right)}{cosTheta}} \]
    6. lower-*.f3296.5%

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

    \[\leadsto \frac{1}{\color{blue}{\frac{0.564189612865448 + cosTheta \cdot \left(0.435810387134552 + \left(c + -0.846284419298172 \cdot cosTheta\right)\right)}{cosTheta}}} \]
  6. Add Preprocessing

Alternative 9: 96.4% accurate, 2.5× speedup?

\[\frac{1}{\left(\mathsf{fma}\left(-0.846284419298172, cosTheta, c\right) - -0.435810387134552\right) + \frac{0.564189612865448}{cosTheta}} \]
(FPCore (cosTheta c)
 :precision binary32
 (/
  1.0
  (+
   (- (fma -0.846284419298172 cosTheta c) -0.435810387134552)
   (/ 0.564189612865448 cosTheta))))
float code(float cosTheta, float c) {
	return 1.0f / ((fmaf(-0.846284419298172f, cosTheta, c) - -0.435810387134552f) + (0.564189612865448f / cosTheta));
}
function code(cosTheta, c)
	return Float32(Float32(1.0) / Float32(Float32(fma(Float32(-0.846284419298172), cosTheta, c) - Float32(-0.435810387134552)) + Float32(Float32(0.564189612865448) / cosTheta)))
end
\frac{1}{\left(\mathsf{fma}\left(-0.846284419298172, 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(\color{blue}{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}{\color{blue}{\frac{\frac{9465531}{16777216} + cosTheta \cdot \left(\frac{7311685}{16777216} + \left(c + \frac{-28396593}{33554432} \cdot cosTheta\right)\right)}{cosTheta}}} \]
  4. Step-by-step derivation
    1. lower-/.f32N/A

      \[\leadsto \frac{1}{\frac{\frac{9465531}{16777216} + cosTheta \cdot \left(\frac{7311685}{16777216} + \left(c + \frac{-28396593}{33554432} \cdot cosTheta\right)\right)}{\color{blue}{cosTheta}}} \]
    2. lower-+.f32N/A

      \[\leadsto \frac{1}{\frac{\frac{9465531}{16777216} + cosTheta \cdot \left(\frac{7311685}{16777216} + \left(c + \frac{-28396593}{33554432} \cdot cosTheta\right)\right)}{cosTheta}} \]
    3. lower-*.f32N/A

      \[\leadsto \frac{1}{\frac{\frac{9465531}{16777216} + cosTheta \cdot \left(\frac{7311685}{16777216} + \left(c + \frac{-28396593}{33554432} \cdot cosTheta\right)\right)}{cosTheta}} \]
    4. lower-+.f32N/A

      \[\leadsto \frac{1}{\frac{\frac{9465531}{16777216} + cosTheta \cdot \left(\frac{7311685}{16777216} + \left(c + \frac{-28396593}{33554432} \cdot cosTheta\right)\right)}{cosTheta}} \]
    5. lower-+.f32N/A

      \[\leadsto \frac{1}{\frac{\frac{9465531}{16777216} + cosTheta \cdot \left(\frac{7311685}{16777216} + \left(c + \frac{-28396593}{33554432} \cdot cosTheta\right)\right)}{cosTheta}} \]
    6. lower-*.f3296.5%

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

    \[\leadsto \frac{1}{\color{blue}{\frac{0.564189612865448 + cosTheta \cdot \left(0.435810387134552 + \left(c + -0.846284419298172 \cdot cosTheta\right)\right)}{cosTheta}}} \]
  6. Step-by-step derivation
    1. lift-/.f32N/A

      \[\leadsto \frac{1}{\frac{\frac{9465531}{16777216} + cosTheta \cdot \left(\frac{7311685}{16777216} + \left(c + \frac{-28396593}{33554432} \cdot cosTheta\right)\right)}{\color{blue}{cosTheta}}} \]
    2. lift-+.f32N/A

      \[\leadsto \frac{1}{\frac{\frac{9465531}{16777216} + cosTheta \cdot \left(\frac{7311685}{16777216} + \left(c + \frac{-28396593}{33554432} \cdot cosTheta\right)\right)}{cosTheta}} \]
    3. +-commutativeN/A

      \[\leadsto \frac{1}{\frac{cosTheta \cdot \left(\frac{7311685}{16777216} + \left(c + \frac{-28396593}{33554432} \cdot cosTheta\right)\right) + \frac{9465531}{16777216}}{cosTheta}} \]
    4. lift-*.f32N/A

      \[\leadsto \frac{1}{\frac{cosTheta \cdot \left(\frac{7311685}{16777216} + \left(c + \frac{-28396593}{33554432} \cdot cosTheta\right)\right) + \frac{9465531}{16777216}}{cosTheta}} \]
    5. *-commutativeN/A

      \[\leadsto \frac{1}{\frac{\left(\frac{7311685}{16777216} + \left(c + \frac{-28396593}{33554432} \cdot cosTheta\right)\right) \cdot cosTheta + \frac{9465531}{16777216}}{cosTheta}} \]
    6. add-to-fraction-revN/A

      \[\leadsto \frac{1}{\left(\frac{7311685}{16777216} + \left(c + \frac{-28396593}{33554432} \cdot cosTheta\right)\right) + \color{blue}{\frac{\frac{9465531}{16777216}}{cosTheta}}} \]
    7. lower-+.f32N/A

      \[\leadsto \frac{1}{\left(\frac{7311685}{16777216} + \left(c + \frac{-28396593}{33554432} \cdot cosTheta\right)\right) + \color{blue}{\frac{\frac{9465531}{16777216}}{cosTheta}}} \]
    8. lift-+.f32N/A

      \[\leadsto \frac{1}{\left(\frac{7311685}{16777216} + \left(c + \frac{-28396593}{33554432} \cdot cosTheta\right)\right) + \frac{\color{blue}{\frac{9465531}{16777216}}}{cosTheta}} \]
    9. +-commutativeN/A

      \[\leadsto \frac{1}{\left(\left(c + \frac{-28396593}{33554432} \cdot cosTheta\right) + \frac{7311685}{16777216}\right) + \frac{\color{blue}{\frac{9465531}{16777216}}}{cosTheta}} \]
    10. add-flipN/A

      \[\leadsto \frac{1}{\left(\left(c + \frac{-28396593}{33554432} \cdot cosTheta\right) - \left(\mathsf{neg}\left(\frac{7311685}{16777216}\right)\right)\right) + \frac{\color{blue}{\frac{9465531}{16777216}}}{cosTheta}} \]
    11. lower--.f32N/A

      \[\leadsto \frac{1}{\left(\left(c + \frac{-28396593}{33554432} \cdot cosTheta\right) - \left(\mathsf{neg}\left(\frac{7311685}{16777216}\right)\right)\right) + \frac{\color{blue}{\frac{9465531}{16777216}}}{cosTheta}} \]
    12. lift-+.f32N/A

      \[\leadsto \frac{1}{\left(\left(c + \frac{-28396593}{33554432} \cdot cosTheta\right) - \left(\mathsf{neg}\left(\frac{7311685}{16777216}\right)\right)\right) + \frac{\frac{9465531}{16777216}}{cosTheta}} \]
    13. +-commutativeN/A

      \[\leadsto \frac{1}{\left(\left(\frac{-28396593}{33554432} \cdot cosTheta + c\right) - \left(\mathsf{neg}\left(\frac{7311685}{16777216}\right)\right)\right) + \frac{\frac{9465531}{16777216}}{cosTheta}} \]
    14. lift-*.f32N/A

      \[\leadsto \frac{1}{\left(\left(\frac{-28396593}{33554432} \cdot cosTheta + c\right) - \left(\mathsf{neg}\left(\frac{7311685}{16777216}\right)\right)\right) + \frac{\frac{9465531}{16777216}}{cosTheta}} \]
    15. lower-fma.f32N/A

      \[\leadsto \frac{1}{\left(\mathsf{fma}\left(\frac{-28396593}{33554432}, cosTheta, c\right) - \left(\mathsf{neg}\left(\frac{7311685}{16777216}\right)\right)\right) + \frac{\frac{9465531}{16777216}}{cosTheta}} \]
    16. metadata-evalN/A

      \[\leadsto \frac{1}{\left(\mathsf{fma}\left(\frac{-28396593}{33554432}, cosTheta, c\right) - \frac{-7311685}{16777216}\right) + \frac{\frac{9465531}{16777216}}{cosTheta}} \]
    17. lower-/.f3296.5%

      \[\leadsto \frac{1}{\left(\mathsf{fma}\left(-0.846284419298172, cosTheta, c\right) - -0.435810387134552\right) + \frac{0.564189612865448}{\color{blue}{cosTheta}}} \]
  7. Applied rewrites96.5%

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

Alternative 10: 95.8% accurate, 3.1× speedup?

\[cosTheta \cdot \left(1.7724539041519165 + -3.141592842343371 \cdot \left(cosTheta \cdot \left(0.4358104334010989 + c\right)\right)\right) \]
(FPCore (cosTheta c)
 :precision binary32
 (*
  cosTheta
  (+
   1.7724539041519165
   (* -3.141592842343371 (* cosTheta (+ 0.4358104334010989 c))))))
float code(float cosTheta, float c) {
	return cosTheta * (1.7724539041519165f + (-3.141592842343371f * (cosTheta * (0.4358104334010989f + c))));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(4) function code(costheta, c)
use fmin_fmax_functions
    real(4), intent (in) :: costheta
    real(4), intent (in) :: c
    code = costheta * (1.7724539041519165e0 + ((-3.141592842343371e0) * (costheta * (0.4358104334010989e0 + c))))
end function
function code(cosTheta, c)
	return Float32(cosTheta * Float32(Float32(1.7724539041519165) + Float32(Float32(-3.141592842343371) * Float32(cosTheta * Float32(Float32(0.4358104334010989) + c)))))
end
function tmp = code(cosTheta, c)
	tmp = cosTheta * (single(1.7724539041519165) + (single(-3.141592842343371) * (cosTheta * (single(0.4358104334010989) + c))));
end
cosTheta \cdot \left(1.7724539041519165 + -3.141592842343371 \cdot \left(cosTheta \cdot \left(0.4358104334010989 + c\right)\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. lift-*.f32N/A

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

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

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

      \[\leadsto \frac{1}{\left(1 + c\right) + \left(\frac{1}{\sqrt{\pi}} \cdot \color{blue}{\frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}}\right) \cdot e^{\left(-cosTheta\right) \cdot cosTheta}} \]
    5. frac-timesN/A

      \[\leadsto \frac{1}{\left(1 + c\right) + \color{blue}{\frac{1 \cdot \sqrt{\left(1 - cosTheta\right) - cosTheta}}{\sqrt{\pi} \cdot cosTheta}} \cdot e^{\left(-cosTheta\right) \cdot cosTheta}} \]
    6. *-lft-identityN/A

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

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

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

      \[\leadsto \frac{1}{\left(1 + c\right) + \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\sqrt{\pi} \cdot cosTheta} \cdot e^{\color{blue}{\left(\mathsf{neg}\left(cosTheta\right)\right)} \cdot cosTheta}} \]
    10. distribute-lft-neg-outN/A

      \[\leadsto \frac{1}{\left(1 + c\right) + \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\sqrt{\pi} \cdot cosTheta} \cdot e^{\color{blue}{\mathsf{neg}\left(cosTheta \cdot cosTheta\right)}}} \]
    11. exp-negN/A

      \[\leadsto \frac{1}{\left(1 + c\right) + \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\sqrt{\pi} \cdot cosTheta} \cdot \color{blue}{\frac{1}{e^{cosTheta \cdot cosTheta}}}} \]
    12. frac-timesN/A

      \[\leadsto \frac{1}{\left(1 + c\right) + \color{blue}{\frac{\sqrt{\left(1 - cosTheta\right) - cosTheta} \cdot 1}{\left(\sqrt{\pi} \cdot cosTheta\right) \cdot e^{cosTheta \cdot cosTheta}}}} \]
    13. *-rgt-identityN/A

      \[\leadsto \frac{1}{\left(1 + c\right) + \frac{\color{blue}{\sqrt{\left(1 - cosTheta\right) - cosTheta}}}{\left(\sqrt{\pi} \cdot cosTheta\right) \cdot e^{cosTheta \cdot cosTheta}}} \]
    14. lower-/.f32N/A

      \[\leadsto \frac{1}{\left(1 + c\right) + \color{blue}{\frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\left(\sqrt{\pi} \cdot cosTheta\right) \cdot e^{cosTheta \cdot cosTheta}}}} \]
  3. Applied rewrites98.6%

    \[\leadsto \frac{1}{\left(1 + c\right) + \color{blue}{\frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\left(cosTheta \cdot \sqrt{\pi}\right) \cdot e^{cosTheta \cdot cosTheta}}}} \]
  4. Evaluated real constant98.6%

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

    \[\leadsto \color{blue}{cosTheta \cdot \left(\frac{14868421}{8388608} + \frac{-221069943033241}{70368744177664} \cdot \left(cosTheta \cdot \left(\frac{6479813}{14868421} + c\right)\right)\right)} \]
  6. Step-by-step derivation
    1. lower-*.f32N/A

      \[\leadsto cosTheta \cdot \color{blue}{\left(\frac{14868421}{8388608} + \frac{-221069943033241}{70368744177664} \cdot \left(cosTheta \cdot \left(\frac{6479813}{14868421} + c\right)\right)\right)} \]
    2. lower-+.f32N/A

      \[\leadsto cosTheta \cdot \left(\frac{14868421}{8388608} + \color{blue}{\frac{-221069943033241}{70368744177664} \cdot \left(cosTheta \cdot \left(\frac{6479813}{14868421} + c\right)\right)}\right) \]
    3. lower-*.f32N/A

      \[\leadsto cosTheta \cdot \left(\frac{14868421}{8388608} + \frac{-221069943033241}{70368744177664} \cdot \color{blue}{\left(cosTheta \cdot \left(\frac{6479813}{14868421} + c\right)\right)}\right) \]
    4. lower-*.f32N/A

      \[\leadsto cosTheta \cdot \left(\frac{14868421}{8388608} + \frac{-221069943033241}{70368744177664} \cdot \left(cosTheta \cdot \color{blue}{\left(\frac{6479813}{14868421} + c\right)}\right)\right) \]
    5. lower-+.f3295.8%

      \[\leadsto cosTheta \cdot \left(1.7724539041519165 + -3.141592842343371 \cdot \left(cosTheta \cdot \left(0.4358104334010989 + \color{blue}{c}\right)\right)\right) \]
  7. Applied rewrites95.8%

    \[\leadsto \color{blue}{cosTheta \cdot \left(1.7724539041519165 + -3.141592842343371 \cdot \left(cosTheta \cdot \left(0.4358104334010989 + c\right)\right)\right)} \]
  8. Add Preprocessing

Alternative 11: 95.5% accurate, 3.1× speedup?

\[cosTheta \cdot \left(1.7724537588012759 + -3.141592327088772 \cdot \left(cosTheta \cdot \left(0.435810387134552 + c\right)\right)\right) \]
(FPCore (cosTheta c)
 :precision binary32
 (*
  cosTheta
  (+
   1.7724537588012759
   (* -3.141592327088772 (* cosTheta (+ 0.435810387134552 c))))))
float code(float cosTheta, float c) {
	return cosTheta * (1.7724537588012759f + (-3.141592327088772f * (cosTheta * (0.435810387134552f + c))));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(4) function code(costheta, c)
use fmin_fmax_functions
    real(4), intent (in) :: costheta
    real(4), intent (in) :: c
    code = costheta * (1.7724537588012759e0 + ((-3.141592327088772e0) * (costheta * (0.435810387134552e0 + c))))
end function
function code(cosTheta, c)
	return Float32(cosTheta * Float32(Float32(1.7724537588012759) + Float32(Float32(-3.141592327088772) * Float32(cosTheta * Float32(Float32(0.435810387134552) + c)))))
end
function tmp = code(cosTheta, c)
	tmp = cosTheta * (single(1.7724537588012759) + (single(-3.141592327088772) * (cosTheta * (single(0.435810387134552) + c))));
end
cosTheta \cdot \left(1.7724537588012759 + -3.141592327088772 \cdot \left(cosTheta \cdot \left(0.435810387134552 + c\right)\right)\right)
Derivation
  1. Initial program 97.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(\color{blue}{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 \color{blue}{cosTheta \cdot \left(\frac{16777216}{9465531} + \frac{-281474976710656}{89596277111961} \cdot \left(cosTheta \cdot \left(\frac{7311685}{16777216} + c\right)\right)\right)} \]
  4. Step-by-step derivation
    1. lower-*.f32N/A

      \[\leadsto cosTheta \cdot \color{blue}{\left(\frac{16777216}{9465531} + \frac{-281474976710656}{89596277111961} \cdot \left(cosTheta \cdot \left(\frac{7311685}{16777216} + c\right)\right)\right)} \]
    2. lower-+.f32N/A

      \[\leadsto cosTheta \cdot \left(\frac{16777216}{9465531} + \color{blue}{\frac{-281474976710656}{89596277111961} \cdot \left(cosTheta \cdot \left(\frac{7311685}{16777216} + c\right)\right)}\right) \]
    3. lower-*.f32N/A

      \[\leadsto cosTheta \cdot \left(\frac{16777216}{9465531} + \frac{-281474976710656}{89596277111961} \cdot \color{blue}{\left(cosTheta \cdot \left(\frac{7311685}{16777216} + c\right)\right)}\right) \]
    4. lower-*.f32N/A

      \[\leadsto cosTheta \cdot \left(\frac{16777216}{9465531} + \frac{-281474976710656}{89596277111961} \cdot \left(cosTheta \cdot \color{blue}{\left(\frac{7311685}{16777216} + c\right)}\right)\right) \]
    5. lower-+.f3295.5%

      \[\leadsto cosTheta \cdot \left(1.7724537588012759 + -3.141592327088772 \cdot \left(cosTheta \cdot \left(0.435810387134552 + \color{blue}{c}\right)\right)\right) \]
  5. Applied rewrites95.5%

    \[\leadsto \color{blue}{cosTheta \cdot \left(1.7724537588012759 + -3.141592327088772 \cdot \left(cosTheta \cdot \left(0.435810387134552 + c\right)\right)\right)} \]
  6. Add Preprocessing

Alternative 12: 95.4% accurate, 4.9× speedup?

\[cosTheta \cdot \left(1.7724537588012759 + -1.3691385682874957 \cdot cosTheta\right) \]
(FPCore (cosTheta c)
 :precision binary32
 (* cosTheta (+ 1.7724537588012759 (* -1.3691385682874957 cosTheta))))
float code(float cosTheta, float c) {
	return cosTheta * (1.7724537588012759f + (-1.3691385682874957f * cosTheta));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(4) function code(costheta, c)
use fmin_fmax_functions
    real(4), intent (in) :: costheta
    real(4), intent (in) :: c
    code = costheta * (1.7724537588012759e0 + ((-1.3691385682874957e0) * costheta))
end function
function code(cosTheta, c)
	return Float32(cosTheta * Float32(Float32(1.7724537588012759) + Float32(Float32(-1.3691385682874957) * cosTheta)))
end
function tmp = code(cosTheta, c)
	tmp = cosTheta * (single(1.7724537588012759) + (single(-1.3691385682874957) * cosTheta));
end
cosTheta \cdot \left(1.7724537588012759 + -1.3691385682874957 \cdot cosTheta\right)
Derivation
  1. Initial program 97.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(\color{blue}{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 \color{blue}{cosTheta \cdot \left(\frac{16777216}{9465531} + \frac{-281474976710656}{89596277111961} \cdot \left(cosTheta \cdot \left(\frac{7311685}{16777216} + c\right)\right)\right)} \]
  4. Step-by-step derivation
    1. lower-*.f32N/A

      \[\leadsto cosTheta \cdot \color{blue}{\left(\frac{16777216}{9465531} + \frac{-281474976710656}{89596277111961} \cdot \left(cosTheta \cdot \left(\frac{7311685}{16777216} + c\right)\right)\right)} \]
    2. lower-+.f32N/A

      \[\leadsto cosTheta \cdot \left(\frac{16777216}{9465531} + \color{blue}{\frac{-281474976710656}{89596277111961} \cdot \left(cosTheta \cdot \left(\frac{7311685}{16777216} + c\right)\right)}\right) \]
    3. lower-*.f32N/A

      \[\leadsto cosTheta \cdot \left(\frac{16777216}{9465531} + \frac{-281474976710656}{89596277111961} \cdot \color{blue}{\left(cosTheta \cdot \left(\frac{7311685}{16777216} + c\right)\right)}\right) \]
    4. lower-*.f32N/A

      \[\leadsto cosTheta \cdot \left(\frac{16777216}{9465531} + \frac{-281474976710656}{89596277111961} \cdot \left(cosTheta \cdot \color{blue}{\left(\frac{7311685}{16777216} + c\right)}\right)\right) \]
    5. lower-+.f3295.5%

      \[\leadsto cosTheta \cdot \left(1.7724537588012759 + -3.141592327088772 \cdot \left(cosTheta \cdot \left(0.435810387134552 + \color{blue}{c}\right)\right)\right) \]
  5. Applied rewrites95.5%

    \[\leadsto \color{blue}{cosTheta \cdot \left(1.7724537588012759 + -3.141592327088772 \cdot \left(cosTheta \cdot \left(0.435810387134552 + c\right)\right)\right)} \]
  6. Taylor expanded in c around 0

    \[\leadsto cosTheta \cdot \left(1.7724537588012759 + \frac{-122669718568960}{89596277111961} \cdot \color{blue}{cosTheta}\right) \]
  7. Step-by-step derivation
    1. lower-*.f3295.4%

      \[\leadsto cosTheta \cdot \left(1.7724537588012759 + -1.3691385682874957 \cdot cosTheta\right) \]
  8. Applied rewrites95.4%

    \[\leadsto cosTheta \cdot \left(1.7724537588012759 + -1.3691385682874957 \cdot \color{blue}{cosTheta}\right) \]
  9. Add Preprocessing

Alternative 13: 92.9% accurate, 11.7× speedup?

\[1.7724537588012759 \cdot cosTheta \]
(FPCore (cosTheta c) :precision binary32 (* 1.7724537588012759 cosTheta))
float code(float cosTheta, float c) {
	return 1.7724537588012759f * cosTheta;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

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(\color{blue}{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 \color{blue}{\frac{16777216}{9465531} \cdot cosTheta} \]
  4. Step-by-step derivation
    1. lower-*.f3292.9%

      \[\leadsto 1.7724537588012759 \cdot \color{blue}{cosTheta} \]
  5. Applied rewrites92.9%

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

Reproduce

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