HairBSDF, Mp, upper

Percentage Accurate: 98.6% → 98.8%
Time: 6.2s
Alternatives: 18
Speedup: 0.9×

Specification

?
\[\left(\left(\left(\left(\left(-1 \leq cosTheta\_i \land cosTheta\_i \leq 1\right) \land \left(-1 \leq cosTheta\_O \land cosTheta\_O \leq 1\right)\right) \land \left(-1 \leq sinTheta\_i \land sinTheta\_i \leq 1\right)\right) \land \left(-1 \leq sinTheta\_O \land sinTheta\_O \leq 1\right)\right) \land 0.1 < v\right) \land v \leq 1.5707964\]
\[\begin{array}{l} \\ \frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \end{array} \]
(FPCore (cosTheta_i cosTheta_O sinTheta_i sinTheta_O v)
 :precision binary32
 (/
  (* (exp (- (/ (* sinTheta_i sinTheta_O) v))) (/ (* cosTheta_i cosTheta_O) v))
  (* (* (sinh (/ 1.0 v)) 2.0) v)))
float code(float cosTheta_i, float cosTheta_O, float sinTheta_i, float sinTheta_O, float v) {
	return (expf(-((sinTheta_i * sinTheta_O) / v)) * ((cosTheta_i * cosTheta_O) / v)) / ((sinhf((1.0f / v)) * 2.0f) * v);
}
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_i, costheta_o, sintheta_i, sintheta_o, v)
use fmin_fmax_functions
    real(4), intent (in) :: costheta_i
    real(4), intent (in) :: costheta_o
    real(4), intent (in) :: sintheta_i
    real(4), intent (in) :: sintheta_o
    real(4), intent (in) :: v
    code = (exp(-((sintheta_i * sintheta_o) / v)) * ((costheta_i * costheta_o) / v)) / ((sinh((1.0e0 / v)) * 2.0e0) * v)
end function
function code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v)
	return Float32(Float32(exp(Float32(-Float32(Float32(sinTheta_i * sinTheta_O) / v))) * Float32(Float32(cosTheta_i * cosTheta_O) / v)) / Float32(Float32(sinh(Float32(Float32(1.0) / v)) * Float32(2.0)) * v))
end
function tmp = code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v)
	tmp = (exp(-((sinTheta_i * sinTheta_O) / v)) * ((cosTheta_i * cosTheta_O) / v)) / ((sinh((single(1.0) / v)) * single(2.0)) * v);
end
\begin{array}{l}

\\
\frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v}
\end{array}

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

\[\begin{array}{l} \\ \frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \end{array} \]
(FPCore (cosTheta_i cosTheta_O sinTheta_i sinTheta_O v)
 :precision binary32
 (/
  (* (exp (- (/ (* sinTheta_i sinTheta_O) v))) (/ (* cosTheta_i cosTheta_O) v))
  (* (* (sinh (/ 1.0 v)) 2.0) v)))
float code(float cosTheta_i, float cosTheta_O, float sinTheta_i, float sinTheta_O, float v) {
	return (expf(-((sinTheta_i * sinTheta_O) / v)) * ((cosTheta_i * cosTheta_O) / v)) / ((sinhf((1.0f / v)) * 2.0f) * v);
}
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_i, costheta_o, sintheta_i, sintheta_o, v)
use fmin_fmax_functions
    real(4), intent (in) :: costheta_i
    real(4), intent (in) :: costheta_o
    real(4), intent (in) :: sintheta_i
    real(4), intent (in) :: sintheta_o
    real(4), intent (in) :: v
    code = (exp(-((sintheta_i * sintheta_o) / v)) * ((costheta_i * costheta_o) / v)) / ((sinh((1.0e0 / v)) * 2.0e0) * v)
end function
function code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v)
	return Float32(Float32(exp(Float32(-Float32(Float32(sinTheta_i * sinTheta_O) / v))) * Float32(Float32(cosTheta_i * cosTheta_O) / v)) / Float32(Float32(sinh(Float32(Float32(1.0) / v)) * Float32(2.0)) * v))
end
function tmp = code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v)
	tmp = (exp(-((sinTheta_i * sinTheta_O) / v)) * ((cosTheta_i * cosTheta_O) / v)) / ((sinh((single(1.0) / v)) * single(2.0)) * v);
end
\begin{array}{l}

\\
\frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v}
\end{array}

Alternative 1: 98.8% accurate, 0.6× speedup?

\[\begin{array}{l} cosTheta_i\_m = \left|cosTheta\_i\right| \\ cosTheta_i\_s = \mathsf{copysign}\left(1, cosTheta\_i\right) \\ cosTheta_O\_m = \left|cosTheta\_O\right| \\ cosTheta_O\_s = \mathsf{copysign}\left(1, cosTheta\_O\right) \\ [cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v] = \mathsf{sort}([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])\\ \\ \begin{array}{l} t_0 := e^{\frac{1}{v}} - e^{-\frac{1}{v}}\\ cosTheta\_O\_s \cdot \left(cosTheta\_i\_s \cdot \left(\left(\frac{cosTheta\_O\_m}{t\_0 \cdot \left(v \cdot v\right)} + \left(-\frac{\left(sinTheta\_O \cdot sinTheta\_i\right) \cdot cosTheta\_O\_m}{\left(\left(v \cdot v\right) \cdot v\right) \cdot t\_0}\right)\right) \cdot cosTheta\_i\_m\right)\right) \end{array} \end{array} \]
cosTheta_i\_m = (fabs.f32 cosTheta_i)
cosTheta_i\_s = (copysign.f32 #s(literal 1 binary32) cosTheta_i)
cosTheta_O\_m = (fabs.f32 cosTheta_O)
cosTheta_O\_s = (copysign.f32 #s(literal 1 binary32) cosTheta_O)
NOTE: cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, and v should be sorted in increasing order before calling this function.
(FPCore (cosTheta_O_s cosTheta_i_s cosTheta_i_m cosTheta_O_m sinTheta_i sinTheta_O v)
 :precision binary32
 (let* ((t_0 (- (exp (/ 1.0 v)) (exp (- (/ 1.0 v))))))
   (*
    cosTheta_O_s
    (*
     cosTheta_i_s
     (*
      (+
       (/ cosTheta_O_m (* t_0 (* v v)))
       (-
        (/ (* (* sinTheta_O sinTheta_i) cosTheta_O_m) (* (* (* v v) v) t_0))))
      cosTheta_i_m)))))
cosTheta_i\_m = fabs(cosTheta_i);
cosTheta_i\_s = copysign(1.0, cosTheta_i);
cosTheta_O\_m = fabs(cosTheta_O);
cosTheta_O\_s = copysign(1.0, cosTheta_O);
assert(cosTheta_i_m < cosTheta_O_m && cosTheta_O_m < sinTheta_i && sinTheta_i < sinTheta_O && sinTheta_O < v);
float code(float cosTheta_O_s, float cosTheta_i_s, float cosTheta_i_m, float cosTheta_O_m, float sinTheta_i, float sinTheta_O, float v) {
	float t_0 = expf((1.0f / v)) - expf(-(1.0f / v));
	return cosTheta_O_s * (cosTheta_i_s * (((cosTheta_O_m / (t_0 * (v * v))) + -(((sinTheta_O * sinTheta_i) * cosTheta_O_m) / (((v * v) * v) * t_0))) * cosTheta_i_m));
}
cosTheta_i\_m =     private
cosTheta_i\_s =     private
cosTheta_O\_m =     private
cosTheta_O\_s =     private
NOTE: cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, and v should be sorted in increasing order before calling this function.
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_o_s, costheta_i_s, costheta_i_m, costheta_o_m, sintheta_i, sintheta_o, v)
use fmin_fmax_functions
    real(4), intent (in) :: costheta_o_s
    real(4), intent (in) :: costheta_i_s
    real(4), intent (in) :: costheta_i_m
    real(4), intent (in) :: costheta_o_m
    real(4), intent (in) :: sintheta_i
    real(4), intent (in) :: sintheta_o
    real(4), intent (in) :: v
    real(4) :: t_0
    t_0 = exp((1.0e0 / v)) - exp(-(1.0e0 / v))
    code = costheta_o_s * (costheta_i_s * (((costheta_o_m / (t_0 * (v * v))) + -(((sintheta_o * sintheta_i) * costheta_o_m) / (((v * v) * v) * t_0))) * costheta_i_m))
end function
cosTheta_i\_m = abs(cosTheta_i)
cosTheta_i\_s = copysign(1.0, cosTheta_i)
cosTheta_O\_m = abs(cosTheta_O)
cosTheta_O\_s = copysign(1.0, cosTheta_O)
cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v = sort([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])
function code(cosTheta_O_s, cosTheta_i_s, cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v)
	t_0 = Float32(exp(Float32(Float32(1.0) / v)) - exp(Float32(-Float32(Float32(1.0) / v))))
	return Float32(cosTheta_O_s * Float32(cosTheta_i_s * Float32(Float32(Float32(cosTheta_O_m / Float32(t_0 * Float32(v * v))) + Float32(-Float32(Float32(Float32(sinTheta_O * sinTheta_i) * cosTheta_O_m) / Float32(Float32(Float32(v * v) * v) * t_0)))) * cosTheta_i_m)))
end
cosTheta_i\_m = abs(cosTheta_i);
cosTheta_i\_s = sign(cosTheta_i) * abs(1.0);
cosTheta_O\_m = abs(cosTheta_O);
cosTheta_O\_s = sign(cosTheta_O) * abs(1.0);
cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v = num2cell(sort([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])){:}
function tmp = code(cosTheta_O_s, cosTheta_i_s, cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v)
	t_0 = exp((single(1.0) / v)) - exp(-(single(1.0) / v));
	tmp = cosTheta_O_s * (cosTheta_i_s * (((cosTheta_O_m / (t_0 * (v * v))) + -(((sinTheta_O * sinTheta_i) * cosTheta_O_m) / (((v * v) * v) * t_0))) * cosTheta_i_m));
end
\begin{array}{l}
cosTheta_i\_m = \left|cosTheta\_i\right|
\\
cosTheta_i\_s = \mathsf{copysign}\left(1, cosTheta\_i\right)
\\
cosTheta_O\_m = \left|cosTheta\_O\right|
\\
cosTheta_O\_s = \mathsf{copysign}\left(1, cosTheta\_O\right)
\\
[cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v] = \mathsf{sort}([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])\\
\\
\begin{array}{l}
t_0 := e^{\frac{1}{v}} - e^{-\frac{1}{v}}\\
cosTheta\_O\_s \cdot \left(cosTheta\_i\_s \cdot \left(\left(\frac{cosTheta\_O\_m}{t\_0 \cdot \left(v \cdot v\right)} + \left(-\frac{\left(sinTheta\_O \cdot sinTheta\_i\right) \cdot cosTheta\_O\_m}{\left(\left(v \cdot v\right) \cdot v\right) \cdot t\_0}\right)\right) \cdot cosTheta\_i\_m\right)\right)
\end{array}
\end{array}
Derivation
  1. Initial program 98.6%

    \[\frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
  2. Taylor expanded in sinTheta_i around 0

    \[\leadsto \color{blue}{-1 \cdot \frac{cosTheta\_O \cdot \left(cosTheta\_i \cdot \left(sinTheta\_O \cdot sinTheta\_i\right)\right)}{{v}^{3} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)} + \frac{cosTheta\_O \cdot cosTheta\_i}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)}} \]
  3. Step-by-step derivation
    1. +-commutativeN/A

      \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)} + \color{blue}{-1 \cdot \frac{cosTheta\_O \cdot \left(cosTheta\_i \cdot \left(sinTheta\_O \cdot sinTheta\_i\right)\right)}{{v}^{3} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)}} \]
    2. associate-/l*N/A

      \[\leadsto cosTheta\_O \cdot \frac{cosTheta\_i}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)} + \color{blue}{-1} \cdot \frac{cosTheta\_O \cdot \left(cosTheta\_i \cdot \left(sinTheta\_O \cdot sinTheta\_i\right)\right)}{{v}^{3} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)} \]
    3. lower-fma.f32N/A

      \[\leadsto \mathsf{fma}\left(cosTheta\_O, \color{blue}{\frac{cosTheta\_i}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)}}, -1 \cdot \frac{cosTheta\_O \cdot \left(cosTheta\_i \cdot \left(sinTheta\_O \cdot sinTheta\_i\right)\right)}{{v}^{3} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)}\right) \]
  4. Applied rewrites98.6%

    \[\leadsto \color{blue}{\mathsf{fma}\left(cosTheta\_O, \frac{cosTheta\_i}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot \left(v \cdot v\right)}, \frac{-\left(\left(sinTheta\_O \cdot sinTheta\_i\right) \cdot cosTheta\_i\right) \cdot cosTheta\_O}{\left(\left(v \cdot v\right) \cdot v\right) \cdot \left(\sinh \left(\frac{1}{v}\right) \cdot 2\right)}\right)} \]
  5. Taylor expanded in cosTheta_i around 0

    \[\leadsto cosTheta\_i \cdot \color{blue}{\left(-1 \cdot \frac{cosTheta\_O \cdot \left(sinTheta\_O \cdot sinTheta\_i\right)}{{v}^{3} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)} + \frac{cosTheta\_O}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)}\right)} \]
  6. Step-by-step derivation
    1. *-commutativeN/A

      \[\leadsto \left(-1 \cdot \frac{cosTheta\_O \cdot \left(sinTheta\_O \cdot sinTheta\_i\right)}{{v}^{3} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)} + \frac{cosTheta\_O}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)}\right) \cdot cosTheta\_i \]
    2. lower-*.f32N/A

      \[\leadsto \left(-1 \cdot \frac{cosTheta\_O \cdot \left(sinTheta\_O \cdot sinTheta\_i\right)}{{v}^{3} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)} + \frac{cosTheta\_O}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)}\right) \cdot cosTheta\_i \]
  7. Applied rewrites98.5%

    \[\leadsto \left(\frac{cosTheta\_O}{\left(e^{\frac{1}{v}} - e^{-\frac{1}{v}}\right) \cdot \left(v \cdot v\right)} + \left(-\frac{\left(sinTheta\_O \cdot sinTheta\_i\right) \cdot cosTheta\_O}{\left(\left(v \cdot v\right) \cdot v\right) \cdot \left(e^{\frac{1}{v}} - e^{-\frac{1}{v}}\right)}\right)\right) \cdot \color{blue}{cosTheta\_i} \]
  8. Add Preprocessing

Alternative 2: 98.8% accurate, 0.9× speedup?

\[\begin{array}{l} cosTheta_i\_m = \left|cosTheta\_i\right| \\ cosTheta_i\_s = \mathsf{copysign}\left(1, cosTheta\_i\right) \\ cosTheta_O\_m = \left|cosTheta\_O\right| \\ cosTheta_O\_s = \mathsf{copysign}\left(1, cosTheta\_O\right) \\ [cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v] = \mathsf{sort}([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])\\ \\ cosTheta\_O\_s \cdot \left(cosTheta\_i\_s \cdot \left(\frac{e^{\frac{sinTheta\_O \cdot sinTheta\_i}{-v}}}{\sinh \left(\frac{1}{v}\right) \cdot 2} \cdot \left(\left(cosTheta\_O\_m \cdot \left(cosTheta\_i\_m \cdot \frac{1}{v}\right)\right) \cdot \frac{1}{v}\right)\right)\right) \end{array} \]
cosTheta_i\_m = (fabs.f32 cosTheta_i)
cosTheta_i\_s = (copysign.f32 #s(literal 1 binary32) cosTheta_i)
cosTheta_O\_m = (fabs.f32 cosTheta_O)
cosTheta_O\_s = (copysign.f32 #s(literal 1 binary32) cosTheta_O)
NOTE: cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, and v should be sorted in increasing order before calling this function.
(FPCore (cosTheta_O_s cosTheta_i_s cosTheta_i_m cosTheta_O_m sinTheta_i sinTheta_O v)
 :precision binary32
 (*
  cosTheta_O_s
  (*
   cosTheta_i_s
   (*
    (/ (exp (/ (* sinTheta_O sinTheta_i) (- v))) (* (sinh (/ 1.0 v)) 2.0))
    (* (* cosTheta_O_m (* cosTheta_i_m (/ 1.0 v))) (/ 1.0 v))))))
cosTheta_i\_m = fabs(cosTheta_i);
cosTheta_i\_s = copysign(1.0, cosTheta_i);
cosTheta_O\_m = fabs(cosTheta_O);
cosTheta_O\_s = copysign(1.0, cosTheta_O);
assert(cosTheta_i_m < cosTheta_O_m && cosTheta_O_m < sinTheta_i && sinTheta_i < sinTheta_O && sinTheta_O < v);
float code(float cosTheta_O_s, float cosTheta_i_s, float cosTheta_i_m, float cosTheta_O_m, float sinTheta_i, float sinTheta_O, float v) {
	return cosTheta_O_s * (cosTheta_i_s * ((expf(((sinTheta_O * sinTheta_i) / -v)) / (sinhf((1.0f / v)) * 2.0f)) * ((cosTheta_O_m * (cosTheta_i_m * (1.0f / v))) * (1.0f / v))));
}
cosTheta_i\_m =     private
cosTheta_i\_s =     private
cosTheta_O\_m =     private
cosTheta_O\_s =     private
NOTE: cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, and v should be sorted in increasing order before calling this function.
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_o_s, costheta_i_s, costheta_i_m, costheta_o_m, sintheta_i, sintheta_o, v)
use fmin_fmax_functions
    real(4), intent (in) :: costheta_o_s
    real(4), intent (in) :: costheta_i_s
    real(4), intent (in) :: costheta_i_m
    real(4), intent (in) :: costheta_o_m
    real(4), intent (in) :: sintheta_i
    real(4), intent (in) :: sintheta_o
    real(4), intent (in) :: v
    code = costheta_o_s * (costheta_i_s * ((exp(((sintheta_o * sintheta_i) / -v)) / (sinh((1.0e0 / v)) * 2.0e0)) * ((costheta_o_m * (costheta_i_m * (1.0e0 / v))) * (1.0e0 / v))))
end function
cosTheta_i\_m = abs(cosTheta_i)
cosTheta_i\_s = copysign(1.0, cosTheta_i)
cosTheta_O\_m = abs(cosTheta_O)
cosTheta_O\_s = copysign(1.0, cosTheta_O)
cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v = sort([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])
function code(cosTheta_O_s, cosTheta_i_s, cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v)
	return Float32(cosTheta_O_s * Float32(cosTheta_i_s * Float32(Float32(exp(Float32(Float32(sinTheta_O * sinTheta_i) / Float32(-v))) / Float32(sinh(Float32(Float32(1.0) / v)) * Float32(2.0))) * Float32(Float32(cosTheta_O_m * Float32(cosTheta_i_m * Float32(Float32(1.0) / v))) * Float32(Float32(1.0) / v)))))
end
cosTheta_i\_m = abs(cosTheta_i);
cosTheta_i\_s = sign(cosTheta_i) * abs(1.0);
cosTheta_O\_m = abs(cosTheta_O);
cosTheta_O\_s = sign(cosTheta_O) * abs(1.0);
cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v = num2cell(sort([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])){:}
function tmp = code(cosTheta_O_s, cosTheta_i_s, cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v)
	tmp = cosTheta_O_s * (cosTheta_i_s * ((exp(((sinTheta_O * sinTheta_i) / -v)) / (sinh((single(1.0) / v)) * single(2.0))) * ((cosTheta_O_m * (cosTheta_i_m * (single(1.0) / v))) * (single(1.0) / v))));
end
\begin{array}{l}
cosTheta_i\_m = \left|cosTheta\_i\right|
\\
cosTheta_i\_s = \mathsf{copysign}\left(1, cosTheta\_i\right)
\\
cosTheta_O\_m = \left|cosTheta\_O\right|
\\
cosTheta_O\_s = \mathsf{copysign}\left(1, cosTheta\_O\right)
\\
[cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v] = \mathsf{sort}([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])\\
\\
cosTheta\_O\_s \cdot \left(cosTheta\_i\_s \cdot \left(\frac{e^{\frac{sinTheta\_O \cdot sinTheta\_i}{-v}}}{\sinh \left(\frac{1}{v}\right) \cdot 2} \cdot \left(\left(cosTheta\_O\_m \cdot \left(cosTheta\_i\_m \cdot \frac{1}{v}\right)\right) \cdot \frac{1}{v}\right)\right)\right)
\end{array}
Derivation
  1. Initial program 98.6%

    \[\frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
  2. Applied rewrites98.5%

    \[\leadsto \color{blue}{\frac{e^{\frac{sinTheta\_O \cdot sinTheta\_i}{-v}}}{\sinh \left(\frac{1}{v}\right) \cdot 2} \cdot \frac{\frac{cosTheta\_O \cdot cosTheta\_i}{v}}{v}} \]
  3. Step-by-step derivation
    1. lift-/.f32N/A

      \[\leadsto \frac{e^{\frac{sinTheta\_O \cdot sinTheta\_i}{-v}}}{\sinh \left(\frac{1}{v}\right) \cdot 2} \cdot \color{blue}{\frac{\frac{cosTheta\_O \cdot cosTheta\_i}{v}}{v}} \]
    2. lift-*.f32N/A

      \[\leadsto \frac{e^{\frac{sinTheta\_O \cdot sinTheta\_i}{-v}}}{\sinh \left(\frac{1}{v}\right) \cdot 2} \cdot \frac{\frac{\color{blue}{cosTheta\_O \cdot cosTheta\_i}}{v}}{v} \]
    3. lift-/.f32N/A

      \[\leadsto \frac{e^{\frac{sinTheta\_O \cdot sinTheta\_i}{-v}}}{\sinh \left(\frac{1}{v}\right) \cdot 2} \cdot \frac{\color{blue}{\frac{cosTheta\_O \cdot cosTheta\_i}{v}}}{v} \]
    4. mult-flipN/A

      \[\leadsto \frac{e^{\frac{sinTheta\_O \cdot sinTheta\_i}{-v}}}{\sinh \left(\frac{1}{v}\right) \cdot 2} \cdot \color{blue}{\left(\frac{cosTheta\_O \cdot cosTheta\_i}{v} \cdot \frac{1}{v}\right)} \]
    5. lower-*.f32N/A

      \[\leadsto \frac{e^{\frac{sinTheta\_O \cdot sinTheta\_i}{-v}}}{\sinh \left(\frac{1}{v}\right) \cdot 2} \cdot \color{blue}{\left(\frac{cosTheta\_O \cdot cosTheta\_i}{v} \cdot \frac{1}{v}\right)} \]
    6. associate-/l*N/A

      \[\leadsto \frac{e^{\frac{sinTheta\_O \cdot sinTheta\_i}{-v}}}{\sinh \left(\frac{1}{v}\right) \cdot 2} \cdot \left(\color{blue}{\left(cosTheta\_O \cdot \frac{cosTheta\_i}{v}\right)} \cdot \frac{1}{v}\right) \]
    7. lift-/.f32N/A

      \[\leadsto \frac{e^{\frac{sinTheta\_O \cdot sinTheta\_i}{-v}}}{\sinh \left(\frac{1}{v}\right) \cdot 2} \cdot \left(\left(cosTheta\_O \cdot \color{blue}{\frac{cosTheta\_i}{v}}\right) \cdot \frac{1}{v}\right) \]
    8. lift-*.f32N/A

      \[\leadsto \frac{e^{\frac{sinTheta\_O \cdot sinTheta\_i}{-v}}}{\sinh \left(\frac{1}{v}\right) \cdot 2} \cdot \left(\color{blue}{\left(cosTheta\_O \cdot \frac{cosTheta\_i}{v}\right)} \cdot \frac{1}{v}\right) \]
    9. lift-/.f3298.7

      \[\leadsto \frac{e^{\frac{sinTheta\_O \cdot sinTheta\_i}{-v}}}{\sinh \left(\frac{1}{v}\right) \cdot 2} \cdot \left(\left(cosTheta\_O \cdot \frac{cosTheta\_i}{v}\right) \cdot \color{blue}{\frac{1}{v}}\right) \]
  4. Applied rewrites98.7%

    \[\leadsto \frac{e^{\frac{sinTheta\_O \cdot sinTheta\_i}{-v}}}{\sinh \left(\frac{1}{v}\right) \cdot 2} \cdot \color{blue}{\left(\left(cosTheta\_O \cdot \frac{cosTheta\_i}{v}\right) \cdot \frac{1}{v}\right)} \]
  5. Step-by-step derivation
    1. lift-/.f32N/A

      \[\leadsto \frac{e^{\frac{sinTheta\_O \cdot sinTheta\_i}{-v}}}{\sinh \left(\frac{1}{v}\right) \cdot 2} \cdot \left(\left(cosTheta\_O \cdot \color{blue}{\frac{cosTheta\_i}{v}}\right) \cdot \frac{1}{v}\right) \]
    2. mult-flipN/A

      \[\leadsto \frac{e^{\frac{sinTheta\_O \cdot sinTheta\_i}{-v}}}{\sinh \left(\frac{1}{v}\right) \cdot 2} \cdot \left(\left(cosTheta\_O \cdot \color{blue}{\left(cosTheta\_i \cdot \frac{1}{v}\right)}\right) \cdot \frac{1}{v}\right) \]
    3. lower-*.f32N/A

      \[\leadsto \frac{e^{\frac{sinTheta\_O \cdot sinTheta\_i}{-v}}}{\sinh \left(\frac{1}{v}\right) \cdot 2} \cdot \left(\left(cosTheta\_O \cdot \color{blue}{\left(cosTheta\_i \cdot \frac{1}{v}\right)}\right) \cdot \frac{1}{v}\right) \]
    4. lift-/.f3298.8

      \[\leadsto \frac{e^{\frac{sinTheta\_O \cdot sinTheta\_i}{-v}}}{\sinh \left(\frac{1}{v}\right) \cdot 2} \cdot \left(\left(cosTheta\_O \cdot \left(cosTheta\_i \cdot \color{blue}{\frac{1}{v}}\right)\right) \cdot \frac{1}{v}\right) \]
  6. Applied rewrites98.8%

    \[\leadsto \frac{e^{\frac{sinTheta\_O \cdot sinTheta\_i}{-v}}}{\sinh \left(\frac{1}{v}\right) \cdot 2} \cdot \left(\left(cosTheta\_O \cdot \color{blue}{\left(cosTheta\_i \cdot \frac{1}{v}\right)}\right) \cdot \frac{1}{v}\right) \]
  7. Add Preprocessing

Alternative 3: 98.5% accurate, 0.9× speedup?

\[\begin{array}{l} cosTheta_i\_m = \left|cosTheta\_i\right| \\ cosTheta_i\_s = \mathsf{copysign}\left(1, cosTheta\_i\right) \\ cosTheta_O\_m = \left|cosTheta\_O\right| \\ cosTheta_O\_s = \mathsf{copysign}\left(1, cosTheta\_O\right) \\ [cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v] = \mathsf{sort}([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])\\ \\ cosTheta\_O\_s \cdot \left(cosTheta\_i\_s \cdot \frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \left(cosTheta\_i\_m \cdot \left(cosTheta\_O\_m \cdot \frac{1}{v}\right)\right)}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v}\right) \end{array} \]
cosTheta_i\_m = (fabs.f32 cosTheta_i)
cosTheta_i\_s = (copysign.f32 #s(literal 1 binary32) cosTheta_i)
cosTheta_O\_m = (fabs.f32 cosTheta_O)
cosTheta_O\_s = (copysign.f32 #s(literal 1 binary32) cosTheta_O)
NOTE: cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, and v should be sorted in increasing order before calling this function.
(FPCore (cosTheta_O_s cosTheta_i_s cosTheta_i_m cosTheta_O_m sinTheta_i sinTheta_O v)
 :precision binary32
 (*
  cosTheta_O_s
  (*
   cosTheta_i_s
   (/
    (*
     (exp (- (/ (* sinTheta_i sinTheta_O) v)))
     (* cosTheta_i_m (* cosTheta_O_m (/ 1.0 v))))
    (* (* (sinh (/ 1.0 v)) 2.0) v)))))
cosTheta_i\_m = fabs(cosTheta_i);
cosTheta_i\_s = copysign(1.0, cosTheta_i);
cosTheta_O\_m = fabs(cosTheta_O);
cosTheta_O\_s = copysign(1.0, cosTheta_O);
assert(cosTheta_i_m < cosTheta_O_m && cosTheta_O_m < sinTheta_i && sinTheta_i < sinTheta_O && sinTheta_O < v);
float code(float cosTheta_O_s, float cosTheta_i_s, float cosTheta_i_m, float cosTheta_O_m, float sinTheta_i, float sinTheta_O, float v) {
	return cosTheta_O_s * (cosTheta_i_s * ((expf(-((sinTheta_i * sinTheta_O) / v)) * (cosTheta_i_m * (cosTheta_O_m * (1.0f / v)))) / ((sinhf((1.0f / v)) * 2.0f) * v)));
}
cosTheta_i\_m =     private
cosTheta_i\_s =     private
cosTheta_O\_m =     private
cosTheta_O\_s =     private
NOTE: cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, and v should be sorted in increasing order before calling this function.
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_o_s, costheta_i_s, costheta_i_m, costheta_o_m, sintheta_i, sintheta_o, v)
use fmin_fmax_functions
    real(4), intent (in) :: costheta_o_s
    real(4), intent (in) :: costheta_i_s
    real(4), intent (in) :: costheta_i_m
    real(4), intent (in) :: costheta_o_m
    real(4), intent (in) :: sintheta_i
    real(4), intent (in) :: sintheta_o
    real(4), intent (in) :: v
    code = costheta_o_s * (costheta_i_s * ((exp(-((sintheta_i * sintheta_o) / v)) * (costheta_i_m * (costheta_o_m * (1.0e0 / v)))) / ((sinh((1.0e0 / v)) * 2.0e0) * v)))
end function
cosTheta_i\_m = abs(cosTheta_i)
cosTheta_i\_s = copysign(1.0, cosTheta_i)
cosTheta_O\_m = abs(cosTheta_O)
cosTheta_O\_s = copysign(1.0, cosTheta_O)
cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v = sort([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])
function code(cosTheta_O_s, cosTheta_i_s, cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v)
	return Float32(cosTheta_O_s * Float32(cosTheta_i_s * Float32(Float32(exp(Float32(-Float32(Float32(sinTheta_i * sinTheta_O) / v))) * Float32(cosTheta_i_m * Float32(cosTheta_O_m * Float32(Float32(1.0) / v)))) / Float32(Float32(sinh(Float32(Float32(1.0) / v)) * Float32(2.0)) * v))))
end
cosTheta_i\_m = abs(cosTheta_i);
cosTheta_i\_s = sign(cosTheta_i) * abs(1.0);
cosTheta_O\_m = abs(cosTheta_O);
cosTheta_O\_s = sign(cosTheta_O) * abs(1.0);
cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v = num2cell(sort([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])){:}
function tmp = code(cosTheta_O_s, cosTheta_i_s, cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v)
	tmp = cosTheta_O_s * (cosTheta_i_s * ((exp(-((sinTheta_i * sinTheta_O) / v)) * (cosTheta_i_m * (cosTheta_O_m * (single(1.0) / v)))) / ((sinh((single(1.0) / v)) * single(2.0)) * v)));
end
\begin{array}{l}
cosTheta_i\_m = \left|cosTheta\_i\right|
\\
cosTheta_i\_s = \mathsf{copysign}\left(1, cosTheta\_i\right)
\\
cosTheta_O\_m = \left|cosTheta\_O\right|
\\
cosTheta_O\_s = \mathsf{copysign}\left(1, cosTheta\_O\right)
\\
[cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v] = \mathsf{sort}([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])\\
\\
cosTheta\_O\_s \cdot \left(cosTheta\_i\_s \cdot \frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \left(cosTheta\_i\_m \cdot \left(cosTheta\_O\_m \cdot \frac{1}{v}\right)\right)}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v}\right)
\end{array}
Derivation
  1. Initial program 98.6%

    \[\frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
  2. Step-by-step derivation
    1. lift-*.f32N/A

      \[\leadsto \frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \frac{\color{blue}{cosTheta\_i \cdot cosTheta\_O}}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
    2. lift-/.f32N/A

      \[\leadsto \frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \color{blue}{\frac{cosTheta\_i \cdot cosTheta\_O}{v}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
    3. associate-/l*N/A

      \[\leadsto \frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \color{blue}{\left(cosTheta\_i \cdot \frac{cosTheta\_O}{v}\right)}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
    4. lower-*.f32N/A

      \[\leadsto \frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \color{blue}{\left(cosTheta\_i \cdot \frac{cosTheta\_O}{v}\right)}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
    5. lower-/.f3298.6

      \[\leadsto \frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \left(cosTheta\_i \cdot \color{blue}{\frac{cosTheta\_O}{v}}\right)}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
  3. Applied rewrites98.6%

    \[\leadsto \frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \color{blue}{\left(cosTheta\_i \cdot \frac{cosTheta\_O}{v}\right)}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
  4. Step-by-step derivation
    1. lift-/.f32N/A

      \[\leadsto \frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \left(cosTheta\_i \cdot \color{blue}{\frac{cosTheta\_O}{v}}\right)}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
    2. mult-flipN/A

      \[\leadsto \frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \left(cosTheta\_i \cdot \color{blue}{\left(cosTheta\_O \cdot \frac{1}{v}\right)}\right)}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
    3. lower-*.f32N/A

      \[\leadsto \frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \left(cosTheta\_i \cdot \color{blue}{\left(cosTheta\_O \cdot \frac{1}{v}\right)}\right)}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
    4. lift-/.f3298.8

      \[\leadsto \frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \left(cosTheta\_i \cdot \left(cosTheta\_O \cdot \color{blue}{\frac{1}{v}}\right)\right)}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
  5. Applied rewrites98.8%

    \[\leadsto \frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \left(cosTheta\_i \cdot \color{blue}{\left(cosTheta\_O \cdot \frac{1}{v}\right)}\right)}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
  6. Add Preprocessing

Alternative 4: 98.4% accurate, 1.6× speedup?

\[\begin{array}{l} cosTheta_i\_m = \left|cosTheta\_i\right| \\ cosTheta_i\_s = \mathsf{copysign}\left(1, cosTheta\_i\right) \\ cosTheta_O\_m = \left|cosTheta\_O\right| \\ cosTheta_O\_s = \mathsf{copysign}\left(1, cosTheta\_O\right) \\ [cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v] = \mathsf{sort}([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])\\ \\ cosTheta\_O\_s \cdot \left(cosTheta\_i\_s \cdot \left(\frac{cosTheta\_O\_m}{\left(v \cdot v\right) \cdot \left(2 \cdot \sinh \left(\frac{1}{v}\right)\right)} \cdot cosTheta\_i\_m\right)\right) \end{array} \]
cosTheta_i\_m = (fabs.f32 cosTheta_i)
cosTheta_i\_s = (copysign.f32 #s(literal 1 binary32) cosTheta_i)
cosTheta_O\_m = (fabs.f32 cosTheta_O)
cosTheta_O\_s = (copysign.f32 #s(literal 1 binary32) cosTheta_O)
NOTE: cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, and v should be sorted in increasing order before calling this function.
(FPCore (cosTheta_O_s cosTheta_i_s cosTheta_i_m cosTheta_O_m sinTheta_i sinTheta_O v)
 :precision binary32
 (*
  cosTheta_O_s
  (*
   cosTheta_i_s
   (* (/ cosTheta_O_m (* (* v v) (* 2.0 (sinh (/ 1.0 v))))) cosTheta_i_m))))
cosTheta_i\_m = fabs(cosTheta_i);
cosTheta_i\_s = copysign(1.0, cosTheta_i);
cosTheta_O\_m = fabs(cosTheta_O);
cosTheta_O\_s = copysign(1.0, cosTheta_O);
assert(cosTheta_i_m < cosTheta_O_m && cosTheta_O_m < sinTheta_i && sinTheta_i < sinTheta_O && sinTheta_O < v);
float code(float cosTheta_O_s, float cosTheta_i_s, float cosTheta_i_m, float cosTheta_O_m, float sinTheta_i, float sinTheta_O, float v) {
	return cosTheta_O_s * (cosTheta_i_s * ((cosTheta_O_m / ((v * v) * (2.0f * sinhf((1.0f / v))))) * cosTheta_i_m));
}
cosTheta_i\_m =     private
cosTheta_i\_s =     private
cosTheta_O\_m =     private
cosTheta_O\_s =     private
NOTE: cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, and v should be sorted in increasing order before calling this function.
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_o_s, costheta_i_s, costheta_i_m, costheta_o_m, sintheta_i, sintheta_o, v)
use fmin_fmax_functions
    real(4), intent (in) :: costheta_o_s
    real(4), intent (in) :: costheta_i_s
    real(4), intent (in) :: costheta_i_m
    real(4), intent (in) :: costheta_o_m
    real(4), intent (in) :: sintheta_i
    real(4), intent (in) :: sintheta_o
    real(4), intent (in) :: v
    code = costheta_o_s * (costheta_i_s * ((costheta_o_m / ((v * v) * (2.0e0 * sinh((1.0e0 / v))))) * costheta_i_m))
end function
cosTheta_i\_m = abs(cosTheta_i)
cosTheta_i\_s = copysign(1.0, cosTheta_i)
cosTheta_O\_m = abs(cosTheta_O)
cosTheta_O\_s = copysign(1.0, cosTheta_O)
cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v = sort([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])
function code(cosTheta_O_s, cosTheta_i_s, cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v)
	return Float32(cosTheta_O_s * Float32(cosTheta_i_s * Float32(Float32(cosTheta_O_m / Float32(Float32(v * v) * Float32(Float32(2.0) * sinh(Float32(Float32(1.0) / v))))) * cosTheta_i_m)))
end
cosTheta_i\_m = abs(cosTheta_i);
cosTheta_i\_s = sign(cosTheta_i) * abs(1.0);
cosTheta_O\_m = abs(cosTheta_O);
cosTheta_O\_s = sign(cosTheta_O) * abs(1.0);
cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v = num2cell(sort([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])){:}
function tmp = code(cosTheta_O_s, cosTheta_i_s, cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v)
	tmp = cosTheta_O_s * (cosTheta_i_s * ((cosTheta_O_m / ((v * v) * (single(2.0) * sinh((single(1.0) / v))))) * cosTheta_i_m));
end
\begin{array}{l}
cosTheta_i\_m = \left|cosTheta\_i\right|
\\
cosTheta_i\_s = \mathsf{copysign}\left(1, cosTheta\_i\right)
\\
cosTheta_O\_m = \left|cosTheta\_O\right|
\\
cosTheta_O\_s = \mathsf{copysign}\left(1, cosTheta\_O\right)
\\
[cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v] = \mathsf{sort}([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])\\
\\
cosTheta\_O\_s \cdot \left(cosTheta\_i\_s \cdot \left(\frac{cosTheta\_O\_m}{\left(v \cdot v\right) \cdot \left(2 \cdot \sinh \left(\frac{1}{v}\right)\right)} \cdot cosTheta\_i\_m\right)\right)
\end{array}
Derivation
  1. Initial program 98.6%

    \[\frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
  2. Taylor expanded in sinTheta_i around 0

    \[\leadsto \color{blue}{-1 \cdot \frac{cosTheta\_O \cdot \left(cosTheta\_i \cdot \left(sinTheta\_O \cdot sinTheta\_i\right)\right)}{{v}^{3} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)} + \frac{cosTheta\_O \cdot cosTheta\_i}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)}} \]
  3. Step-by-step derivation
    1. +-commutativeN/A

      \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)} + \color{blue}{-1 \cdot \frac{cosTheta\_O \cdot \left(cosTheta\_i \cdot \left(sinTheta\_O \cdot sinTheta\_i\right)\right)}{{v}^{3} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)}} \]
    2. associate-/l*N/A

      \[\leadsto cosTheta\_O \cdot \frac{cosTheta\_i}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)} + \color{blue}{-1} \cdot \frac{cosTheta\_O \cdot \left(cosTheta\_i \cdot \left(sinTheta\_O \cdot sinTheta\_i\right)\right)}{{v}^{3} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)} \]
    3. lower-fma.f32N/A

      \[\leadsto \mathsf{fma}\left(cosTheta\_O, \color{blue}{\frac{cosTheta\_i}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)}}, -1 \cdot \frac{cosTheta\_O \cdot \left(cosTheta\_i \cdot \left(sinTheta\_O \cdot sinTheta\_i\right)\right)}{{v}^{3} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)}\right) \]
  4. Applied rewrites98.6%

    \[\leadsto \color{blue}{\mathsf{fma}\left(cosTheta\_O, \frac{cosTheta\_i}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot \left(v \cdot v\right)}, \frac{-\left(\left(sinTheta\_O \cdot sinTheta\_i\right) \cdot cosTheta\_i\right) \cdot cosTheta\_O}{\left(\left(v \cdot v\right) \cdot v\right) \cdot \left(\sinh \left(\frac{1}{v}\right) \cdot 2\right)}\right)} \]
  5. Taylor expanded in cosTheta_i around 0

    \[\leadsto cosTheta\_i \cdot \color{blue}{\left(-1 \cdot \frac{cosTheta\_O \cdot \left(sinTheta\_O \cdot sinTheta\_i\right)}{{v}^{3} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)} + \frac{cosTheta\_O}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)}\right)} \]
  6. Step-by-step derivation
    1. *-commutativeN/A

      \[\leadsto \left(-1 \cdot \frac{cosTheta\_O \cdot \left(sinTheta\_O \cdot sinTheta\_i\right)}{{v}^{3} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)} + \frac{cosTheta\_O}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)}\right) \cdot cosTheta\_i \]
    2. lower-*.f32N/A

      \[\leadsto \left(-1 \cdot \frac{cosTheta\_O \cdot \left(sinTheta\_O \cdot sinTheta\_i\right)}{{v}^{3} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)} + \frac{cosTheta\_O}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)}\right) \cdot cosTheta\_i \]
  7. Applied rewrites98.5%

    \[\leadsto \left(\frac{cosTheta\_O}{\left(e^{\frac{1}{v}} - e^{-\frac{1}{v}}\right) \cdot \left(v \cdot v\right)} + \left(-\frac{\left(sinTheta\_O \cdot sinTheta\_i\right) \cdot cosTheta\_O}{\left(\left(v \cdot v\right) \cdot v\right) \cdot \left(e^{\frac{1}{v}} - e^{-\frac{1}{v}}\right)}\right)\right) \cdot \color{blue}{cosTheta\_i} \]
  8. Taylor expanded in sinTheta_i around 0

    \[\leadsto \frac{cosTheta\_O}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - e^{\mathsf{neg}\left(\frac{1}{v}\right)}\right)} \cdot cosTheta\_i \]
  9. Step-by-step derivation
    1. rec-expN/A

      \[\leadsto \frac{cosTheta\_O}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)} \cdot cosTheta\_i \]
    2. lower-/.f32N/A

      \[\leadsto \frac{cosTheta\_O}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)} \cdot cosTheta\_i \]
    3. rec-expN/A

      \[\leadsto \frac{cosTheta\_O}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - e^{\mathsf{neg}\left(\frac{1}{v}\right)}\right)} \cdot cosTheta\_i \]
    4. lower-*.f32N/A

      \[\leadsto \frac{cosTheta\_O}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - e^{\mathsf{neg}\left(\frac{1}{v}\right)}\right)} \cdot cosTheta\_i \]
    5. pow2N/A

      \[\leadsto \frac{cosTheta\_O}{\left(v \cdot v\right) \cdot \left(e^{\frac{1}{v}} - e^{\mathsf{neg}\left(\frac{1}{v}\right)}\right)} \cdot cosTheta\_i \]
    6. lift-*.f32N/A

      \[\leadsto \frac{cosTheta\_O}{\left(v \cdot v\right) \cdot \left(e^{\frac{1}{v}} - e^{\mathsf{neg}\left(\frac{1}{v}\right)}\right)} \cdot cosTheta\_i \]
    7. sinh-undef-revN/A

      \[\leadsto \frac{cosTheta\_O}{\left(v \cdot v\right) \cdot \left(2 \cdot \sinh \left(\frac{1}{v}\right)\right)} \cdot cosTheta\_i \]
    8. lift-sinh.f32N/A

      \[\leadsto \frac{cosTheta\_O}{\left(v \cdot v\right) \cdot \left(2 \cdot \sinh \left(\frac{1}{v}\right)\right)} \cdot cosTheta\_i \]
    9. lift-/.f32N/A

      \[\leadsto \frac{cosTheta\_O}{\left(v \cdot v\right) \cdot \left(2 \cdot \sinh \left(\frac{1}{v}\right)\right)} \cdot cosTheta\_i \]
    10. lift-*.f3298.4

      \[\leadsto \frac{cosTheta\_O}{\left(v \cdot v\right) \cdot \left(2 \cdot \sinh \left(\frac{1}{v}\right)\right)} \cdot cosTheta\_i \]
  10. Applied rewrites98.4%

    \[\leadsto \frac{cosTheta\_O}{\left(v \cdot v\right) \cdot \left(2 \cdot \sinh \left(\frac{1}{v}\right)\right)} \cdot cosTheta\_i \]
  11. Add Preprocessing

Alternative 5: 98.4% accurate, 1.7× speedup?

\[\begin{array}{l} cosTheta_i\_m = \left|cosTheta\_i\right| \\ cosTheta_i\_s = \mathsf{copysign}\left(1, cosTheta\_i\right) \\ cosTheta_O\_m = \left|cosTheta\_O\right| \\ cosTheta_O\_s = \mathsf{copysign}\left(1, cosTheta\_O\right) \\ [cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v] = \mathsf{sort}([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])\\ \\ cosTheta\_O\_s \cdot \left(cosTheta\_i\_s \cdot \left(\frac{cosTheta\_i\_m}{\left(\sinh \left(\frac{1}{v}\right) \cdot \left(v + v\right)\right) \cdot v} \cdot cosTheta\_O\_m\right)\right) \end{array} \]
cosTheta_i\_m = (fabs.f32 cosTheta_i)
cosTheta_i\_s = (copysign.f32 #s(literal 1 binary32) cosTheta_i)
cosTheta_O\_m = (fabs.f32 cosTheta_O)
cosTheta_O\_s = (copysign.f32 #s(literal 1 binary32) cosTheta_O)
NOTE: cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, and v should be sorted in increasing order before calling this function.
(FPCore (cosTheta_O_s cosTheta_i_s cosTheta_i_m cosTheta_O_m sinTheta_i sinTheta_O v)
 :precision binary32
 (*
  cosTheta_O_s
  (*
   cosTheta_i_s
   (* (/ cosTheta_i_m (* (* (sinh (/ 1.0 v)) (+ v v)) v)) cosTheta_O_m))))
cosTheta_i\_m = fabs(cosTheta_i);
cosTheta_i\_s = copysign(1.0, cosTheta_i);
cosTheta_O\_m = fabs(cosTheta_O);
cosTheta_O\_s = copysign(1.0, cosTheta_O);
assert(cosTheta_i_m < cosTheta_O_m && cosTheta_O_m < sinTheta_i && sinTheta_i < sinTheta_O && sinTheta_O < v);
float code(float cosTheta_O_s, float cosTheta_i_s, float cosTheta_i_m, float cosTheta_O_m, float sinTheta_i, float sinTheta_O, float v) {
	return cosTheta_O_s * (cosTheta_i_s * ((cosTheta_i_m / ((sinhf((1.0f / v)) * (v + v)) * v)) * cosTheta_O_m));
}
cosTheta_i\_m =     private
cosTheta_i\_s =     private
cosTheta_O\_m =     private
cosTheta_O\_s =     private
NOTE: cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, and v should be sorted in increasing order before calling this function.
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_o_s, costheta_i_s, costheta_i_m, costheta_o_m, sintheta_i, sintheta_o, v)
use fmin_fmax_functions
    real(4), intent (in) :: costheta_o_s
    real(4), intent (in) :: costheta_i_s
    real(4), intent (in) :: costheta_i_m
    real(4), intent (in) :: costheta_o_m
    real(4), intent (in) :: sintheta_i
    real(4), intent (in) :: sintheta_o
    real(4), intent (in) :: v
    code = costheta_o_s * (costheta_i_s * ((costheta_i_m / ((sinh((1.0e0 / v)) * (v + v)) * v)) * costheta_o_m))
end function
cosTheta_i\_m = abs(cosTheta_i)
cosTheta_i\_s = copysign(1.0, cosTheta_i)
cosTheta_O\_m = abs(cosTheta_O)
cosTheta_O\_s = copysign(1.0, cosTheta_O)
cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v = sort([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])
function code(cosTheta_O_s, cosTheta_i_s, cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v)
	return Float32(cosTheta_O_s * Float32(cosTheta_i_s * Float32(Float32(cosTheta_i_m / Float32(Float32(sinh(Float32(Float32(1.0) / v)) * Float32(v + v)) * v)) * cosTheta_O_m)))
end
cosTheta_i\_m = abs(cosTheta_i);
cosTheta_i\_s = sign(cosTheta_i) * abs(1.0);
cosTheta_O\_m = abs(cosTheta_O);
cosTheta_O\_s = sign(cosTheta_O) * abs(1.0);
cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v = num2cell(sort([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])){:}
function tmp = code(cosTheta_O_s, cosTheta_i_s, cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v)
	tmp = cosTheta_O_s * (cosTheta_i_s * ((cosTheta_i_m / ((sinh((single(1.0) / v)) * (v + v)) * v)) * cosTheta_O_m));
end
\begin{array}{l}
cosTheta_i\_m = \left|cosTheta\_i\right|
\\
cosTheta_i\_s = \mathsf{copysign}\left(1, cosTheta\_i\right)
\\
cosTheta_O\_m = \left|cosTheta\_O\right|
\\
cosTheta_O\_s = \mathsf{copysign}\left(1, cosTheta\_O\right)
\\
[cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v] = \mathsf{sort}([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])\\
\\
cosTheta\_O\_s \cdot \left(cosTheta\_i\_s \cdot \left(\frac{cosTheta\_i\_m}{\left(\sinh \left(\frac{1}{v}\right) \cdot \left(v + v\right)\right) \cdot v} \cdot cosTheta\_O\_m\right)\right)
\end{array}
Derivation
  1. Initial program 98.6%

    \[\frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
  2. Step-by-step derivation
    1. lift-*.f32N/A

      \[\leadsto \frac{\color{blue}{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
    2. lift-exp.f32N/A

      \[\leadsto \frac{\color{blue}{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
    3. lift-neg.f32N/A

      \[\leadsto \frac{e^{\color{blue}{\mathsf{neg}\left(\frac{sinTheta\_i \cdot sinTheta\_O}{v}\right)}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
    4. lift-*.f32N/A

      \[\leadsto \frac{e^{\mathsf{neg}\left(\frac{\color{blue}{sinTheta\_i \cdot sinTheta\_O}}{v}\right)} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
    5. lift-/.f32N/A

      \[\leadsto \frac{e^{\mathsf{neg}\left(\color{blue}{\frac{sinTheta\_i \cdot sinTheta\_O}{v}}\right)} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
    6. lift-*.f32N/A

      \[\leadsto \frac{e^{\mathsf{neg}\left(\frac{sinTheta\_i \cdot sinTheta\_O}{v}\right)} \cdot \frac{\color{blue}{cosTheta\_i \cdot cosTheta\_O}}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
    7. lift-/.f32N/A

      \[\leadsto \frac{e^{\mathsf{neg}\left(\frac{sinTheta\_i \cdot sinTheta\_O}{v}\right)} \cdot \color{blue}{\frac{cosTheta\_i \cdot cosTheta\_O}{v}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
    8. *-commutativeN/A

      \[\leadsto \frac{\color{blue}{\frac{cosTheta\_i \cdot cosTheta\_O}{v} \cdot e^{\mathsf{neg}\left(\frac{sinTheta\_i \cdot sinTheta\_O}{v}\right)}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
    9. *-commutativeN/A

      \[\leadsto \frac{\frac{\color{blue}{cosTheta\_O \cdot cosTheta\_i}}{v} \cdot e^{\mathsf{neg}\left(\frac{sinTheta\_i \cdot sinTheta\_O}{v}\right)}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
    10. division-flipN/A

      \[\leadsto \frac{\color{blue}{\frac{1}{\frac{v}{cosTheta\_O \cdot cosTheta\_i}}} \cdot e^{\mathsf{neg}\left(\frac{sinTheta\_i \cdot sinTheta\_O}{v}\right)}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
    11. exp-negN/A

      \[\leadsto \frac{\frac{1}{\frac{v}{cosTheta\_O \cdot cosTheta\_i}} \cdot \color{blue}{\frac{1}{e^{\frac{sinTheta\_i \cdot sinTheta\_O}{v}}}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
    12. *-commutativeN/A

      \[\leadsto \frac{\frac{1}{\frac{v}{cosTheta\_O \cdot cosTheta\_i}} \cdot \frac{1}{e^{\frac{\color{blue}{sinTheta\_O \cdot sinTheta\_i}}{v}}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
    13. frac-timesN/A

      \[\leadsto \frac{\color{blue}{\frac{1 \cdot 1}{\frac{v}{cosTheta\_O \cdot cosTheta\_i} \cdot e^{\frac{sinTheta\_O \cdot sinTheta\_i}{v}}}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
    14. metadata-evalN/A

      \[\leadsto \frac{\frac{\color{blue}{1}}{\frac{v}{cosTheta\_O \cdot cosTheta\_i} \cdot e^{\frac{sinTheta\_O \cdot sinTheta\_i}{v}}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
    15. lower-/.f32N/A

      \[\leadsto \frac{\color{blue}{\frac{1}{\frac{v}{cosTheta\_O \cdot cosTheta\_i} \cdot e^{\frac{sinTheta\_O \cdot sinTheta\_i}{v}}}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
    16. lower-*.f32N/A

      \[\leadsto \frac{\frac{1}{\color{blue}{\frac{v}{cosTheta\_O \cdot cosTheta\_i} \cdot e^{\frac{sinTheta\_O \cdot sinTheta\_i}{v}}}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
  3. Applied rewrites95.1%

    \[\leadsto \frac{\color{blue}{\frac{1}{\frac{v}{cosTheta\_O \cdot cosTheta\_i} \cdot e^{\frac{sinTheta\_O \cdot sinTheta\_i}{v}}}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
  4. Taylor expanded in sinTheta_i around 0

    \[\leadsto \color{blue}{\frac{cosTheta\_O \cdot cosTheta\_i}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)}} \]
  5. Step-by-step derivation
    1. lower-/.f32N/A

      \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\color{blue}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)}} \]
    2. lift-*.f32N/A

      \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\color{blue}{{v}^{2}} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)} \]
    3. *-commutativeN/A

      \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right) \cdot \color{blue}{{v}^{2}}} \]
    4. lower-*.f32N/A

      \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right) \cdot \color{blue}{{v}^{2}}} \]
    5. lower--.f32N/A

      \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right) \cdot {\color{blue}{v}}^{2}} \]
    6. lower-exp.f32N/A

      \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right) \cdot {v}^{2}} \]
    7. lift-/.f32N/A

      \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right) \cdot {v}^{2}} \]
    8. rec-expN/A

      \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - e^{\mathsf{neg}\left(\frac{1}{v}\right)}\right) \cdot {v}^{2}} \]
    9. lower-exp.f32N/A

      \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - e^{\mathsf{neg}\left(\frac{1}{v}\right)}\right) \cdot {v}^{2}} \]
    10. lower-neg.f32N/A

      \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - e^{-\frac{1}{v}}\right) \cdot {v}^{2}} \]
    11. lift-/.f32N/A

      \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - e^{-\frac{1}{v}}\right) \cdot {v}^{2}} \]
    12. pow2N/A

      \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - e^{-\frac{1}{v}}\right) \cdot \left(v \cdot \color{blue}{v}\right)} \]
    13. lift-*.f3298.3

      \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - e^{-\frac{1}{v}}\right) \cdot \left(v \cdot \color{blue}{v}\right)} \]
  6. Applied rewrites98.3%

    \[\leadsto \color{blue}{\frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - e^{-\frac{1}{v}}\right) \cdot \left(v \cdot v\right)}} \]
  7. Applied rewrites98.4%

    \[\leadsto \frac{cosTheta\_i}{\left(\sinh \left(\frac{1}{v}\right) \cdot \left(v + v\right)\right) \cdot v} \cdot \color{blue}{cosTheta\_O} \]
  8. Add Preprocessing

Alternative 6: 98.4% accurate, 1.7× speedup?

\[\begin{array}{l} cosTheta_i\_m = \left|cosTheta\_i\right| \\ cosTheta_i\_s = \mathsf{copysign}\left(1, cosTheta\_i\right) \\ cosTheta_O\_m = \left|cosTheta\_O\right| \\ cosTheta_O\_s = \mathsf{copysign}\left(1, cosTheta\_O\right) \\ [cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v] = \mathsf{sort}([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])\\ \\ cosTheta\_O\_s \cdot \left(cosTheta\_i\_s \cdot \left(\frac{cosTheta\_O\_m}{\left(\sinh \left(\frac{1}{v}\right) \cdot \left(v + v\right)\right) \cdot v} \cdot cosTheta\_i\_m\right)\right) \end{array} \]
cosTheta_i\_m = (fabs.f32 cosTheta_i)
cosTheta_i\_s = (copysign.f32 #s(literal 1 binary32) cosTheta_i)
cosTheta_O\_m = (fabs.f32 cosTheta_O)
cosTheta_O\_s = (copysign.f32 #s(literal 1 binary32) cosTheta_O)
NOTE: cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, and v should be sorted in increasing order before calling this function.
(FPCore (cosTheta_O_s cosTheta_i_s cosTheta_i_m cosTheta_O_m sinTheta_i sinTheta_O v)
 :precision binary32
 (*
  cosTheta_O_s
  (*
   cosTheta_i_s
   (* (/ cosTheta_O_m (* (* (sinh (/ 1.0 v)) (+ v v)) v)) cosTheta_i_m))))
cosTheta_i\_m = fabs(cosTheta_i);
cosTheta_i\_s = copysign(1.0, cosTheta_i);
cosTheta_O\_m = fabs(cosTheta_O);
cosTheta_O\_s = copysign(1.0, cosTheta_O);
assert(cosTheta_i_m < cosTheta_O_m && cosTheta_O_m < sinTheta_i && sinTheta_i < sinTheta_O && sinTheta_O < v);
float code(float cosTheta_O_s, float cosTheta_i_s, float cosTheta_i_m, float cosTheta_O_m, float sinTheta_i, float sinTheta_O, float v) {
	return cosTheta_O_s * (cosTheta_i_s * ((cosTheta_O_m / ((sinhf((1.0f / v)) * (v + v)) * v)) * cosTheta_i_m));
}
cosTheta_i\_m =     private
cosTheta_i\_s =     private
cosTheta_O\_m =     private
cosTheta_O\_s =     private
NOTE: cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, and v should be sorted in increasing order before calling this function.
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_o_s, costheta_i_s, costheta_i_m, costheta_o_m, sintheta_i, sintheta_o, v)
use fmin_fmax_functions
    real(4), intent (in) :: costheta_o_s
    real(4), intent (in) :: costheta_i_s
    real(4), intent (in) :: costheta_i_m
    real(4), intent (in) :: costheta_o_m
    real(4), intent (in) :: sintheta_i
    real(4), intent (in) :: sintheta_o
    real(4), intent (in) :: v
    code = costheta_o_s * (costheta_i_s * ((costheta_o_m / ((sinh((1.0e0 / v)) * (v + v)) * v)) * costheta_i_m))
end function
cosTheta_i\_m = abs(cosTheta_i)
cosTheta_i\_s = copysign(1.0, cosTheta_i)
cosTheta_O\_m = abs(cosTheta_O)
cosTheta_O\_s = copysign(1.0, cosTheta_O)
cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v = sort([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])
function code(cosTheta_O_s, cosTheta_i_s, cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v)
	return Float32(cosTheta_O_s * Float32(cosTheta_i_s * Float32(Float32(cosTheta_O_m / Float32(Float32(sinh(Float32(Float32(1.0) / v)) * Float32(v + v)) * v)) * cosTheta_i_m)))
end
cosTheta_i\_m = abs(cosTheta_i);
cosTheta_i\_s = sign(cosTheta_i) * abs(1.0);
cosTheta_O\_m = abs(cosTheta_O);
cosTheta_O\_s = sign(cosTheta_O) * abs(1.0);
cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v = num2cell(sort([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])){:}
function tmp = code(cosTheta_O_s, cosTheta_i_s, cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v)
	tmp = cosTheta_O_s * (cosTheta_i_s * ((cosTheta_O_m / ((sinh((single(1.0) / v)) * (v + v)) * v)) * cosTheta_i_m));
end
\begin{array}{l}
cosTheta_i\_m = \left|cosTheta\_i\right|
\\
cosTheta_i\_s = \mathsf{copysign}\left(1, cosTheta\_i\right)
\\
cosTheta_O\_m = \left|cosTheta\_O\right|
\\
cosTheta_O\_s = \mathsf{copysign}\left(1, cosTheta\_O\right)
\\
[cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v] = \mathsf{sort}([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])\\
\\
cosTheta\_O\_s \cdot \left(cosTheta\_i\_s \cdot \left(\frac{cosTheta\_O\_m}{\left(\sinh \left(\frac{1}{v}\right) \cdot \left(v + v\right)\right) \cdot v} \cdot cosTheta\_i\_m\right)\right)
\end{array}
Derivation
  1. Initial program 98.6%

    \[\frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
  2. Taylor expanded in sinTheta_i around 0

    \[\leadsto \color{blue}{-1 \cdot \frac{cosTheta\_O \cdot \left(cosTheta\_i \cdot \left(sinTheta\_O \cdot sinTheta\_i\right)\right)}{{v}^{3} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)} + \frac{cosTheta\_O \cdot cosTheta\_i}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)}} \]
  3. Step-by-step derivation
    1. +-commutativeN/A

      \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)} + \color{blue}{-1 \cdot \frac{cosTheta\_O \cdot \left(cosTheta\_i \cdot \left(sinTheta\_O \cdot sinTheta\_i\right)\right)}{{v}^{3} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)}} \]
    2. associate-/l*N/A

      \[\leadsto cosTheta\_O \cdot \frac{cosTheta\_i}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)} + \color{blue}{-1} \cdot \frac{cosTheta\_O \cdot \left(cosTheta\_i \cdot \left(sinTheta\_O \cdot sinTheta\_i\right)\right)}{{v}^{3} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)} \]
    3. lower-fma.f32N/A

      \[\leadsto \mathsf{fma}\left(cosTheta\_O, \color{blue}{\frac{cosTheta\_i}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)}}, -1 \cdot \frac{cosTheta\_O \cdot \left(cosTheta\_i \cdot \left(sinTheta\_O \cdot sinTheta\_i\right)\right)}{{v}^{3} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)}\right) \]
  4. Applied rewrites98.6%

    \[\leadsto \color{blue}{\mathsf{fma}\left(cosTheta\_O, \frac{cosTheta\_i}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot \left(v \cdot v\right)}, \frac{-\left(\left(sinTheta\_O \cdot sinTheta\_i\right) \cdot cosTheta\_i\right) \cdot cosTheta\_O}{\left(\left(v \cdot v\right) \cdot v\right) \cdot \left(\sinh \left(\frac{1}{v}\right) \cdot 2\right)}\right)} \]
  5. Taylor expanded in cosTheta_i around 0

    \[\leadsto cosTheta\_i \cdot \color{blue}{\left(-1 \cdot \frac{cosTheta\_O \cdot \left(sinTheta\_O \cdot sinTheta\_i\right)}{{v}^{3} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)} + \frac{cosTheta\_O}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)}\right)} \]
  6. Step-by-step derivation
    1. *-commutativeN/A

      \[\leadsto \left(-1 \cdot \frac{cosTheta\_O \cdot \left(sinTheta\_O \cdot sinTheta\_i\right)}{{v}^{3} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)} + \frac{cosTheta\_O}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)}\right) \cdot cosTheta\_i \]
    2. lower-*.f32N/A

      \[\leadsto \left(-1 \cdot \frac{cosTheta\_O \cdot \left(sinTheta\_O \cdot sinTheta\_i\right)}{{v}^{3} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)} + \frac{cosTheta\_O}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)}\right) \cdot cosTheta\_i \]
  7. Applied rewrites98.5%

    \[\leadsto \left(\frac{cosTheta\_O}{\left(e^{\frac{1}{v}} - e^{-\frac{1}{v}}\right) \cdot \left(v \cdot v\right)} + \left(-\frac{\left(sinTheta\_O \cdot sinTheta\_i\right) \cdot cosTheta\_O}{\left(\left(v \cdot v\right) \cdot v\right) \cdot \left(e^{\frac{1}{v}} - e^{-\frac{1}{v}}\right)}\right)\right) \cdot \color{blue}{cosTheta\_i} \]
  8. Taylor expanded in sinTheta_i around 0

    \[\leadsto \frac{cosTheta\_O}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - e^{\mathsf{neg}\left(\frac{1}{v}\right)}\right)} \cdot cosTheta\_i \]
  9. Step-by-step derivation
    1. rec-expN/A

      \[\leadsto \frac{cosTheta\_O}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)} \cdot cosTheta\_i \]
    2. lower-/.f32N/A

      \[\leadsto \frac{cosTheta\_O}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)} \cdot cosTheta\_i \]
    3. rec-expN/A

      \[\leadsto \frac{cosTheta\_O}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - e^{\mathsf{neg}\left(\frac{1}{v}\right)}\right)} \cdot cosTheta\_i \]
    4. lower-*.f32N/A

      \[\leadsto \frac{cosTheta\_O}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - e^{\mathsf{neg}\left(\frac{1}{v}\right)}\right)} \cdot cosTheta\_i \]
    5. pow2N/A

      \[\leadsto \frac{cosTheta\_O}{\left(v \cdot v\right) \cdot \left(e^{\frac{1}{v}} - e^{\mathsf{neg}\left(\frac{1}{v}\right)}\right)} \cdot cosTheta\_i \]
    6. lift-*.f32N/A

      \[\leadsto \frac{cosTheta\_O}{\left(v \cdot v\right) \cdot \left(e^{\frac{1}{v}} - e^{\mathsf{neg}\left(\frac{1}{v}\right)}\right)} \cdot cosTheta\_i \]
    7. sinh-undef-revN/A

      \[\leadsto \frac{cosTheta\_O}{\left(v \cdot v\right) \cdot \left(2 \cdot \sinh \left(\frac{1}{v}\right)\right)} \cdot cosTheta\_i \]
    8. lift-sinh.f32N/A

      \[\leadsto \frac{cosTheta\_O}{\left(v \cdot v\right) \cdot \left(2 \cdot \sinh \left(\frac{1}{v}\right)\right)} \cdot cosTheta\_i \]
    9. lift-/.f32N/A

      \[\leadsto \frac{cosTheta\_O}{\left(v \cdot v\right) \cdot \left(2 \cdot \sinh \left(\frac{1}{v}\right)\right)} \cdot cosTheta\_i \]
    10. lift-*.f3298.4

      \[\leadsto \frac{cosTheta\_O}{\left(v \cdot v\right) \cdot \left(2 \cdot \sinh \left(\frac{1}{v}\right)\right)} \cdot cosTheta\_i \]
  10. Applied rewrites98.4%

    \[\leadsto \frac{cosTheta\_O}{\left(v \cdot v\right) \cdot \left(2 \cdot \sinh \left(\frac{1}{v}\right)\right)} \cdot cosTheta\_i \]
  11. Applied rewrites98.4%

    \[\leadsto \frac{cosTheta\_O}{\left(\sinh \left(\frac{1}{v}\right) \cdot \left(v + v\right)\right) \cdot v} \cdot \color{blue}{cosTheta\_i} \]
  12. Add Preprocessing

Alternative 7: 98.3% accurate, 1.7× speedup?

\[\begin{array}{l} cosTheta_i\_m = \left|cosTheta\_i\right| \\ cosTheta_i\_s = \mathsf{copysign}\left(1, cosTheta\_i\right) \\ cosTheta_O\_m = \left|cosTheta\_O\right| \\ cosTheta_O\_s = \mathsf{copysign}\left(1, cosTheta\_O\right) \\ [cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v] = \mathsf{sort}([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])\\ \\ cosTheta\_O\_s \cdot \left(cosTheta\_i\_s \cdot \frac{cosTheta\_O\_m \cdot cosTheta\_i\_m}{\left(\sinh \left(\frac{1}{v}\right) \cdot \left(v + v\right)\right) \cdot v}\right) \end{array} \]
cosTheta_i\_m = (fabs.f32 cosTheta_i)
cosTheta_i\_s = (copysign.f32 #s(literal 1 binary32) cosTheta_i)
cosTheta_O\_m = (fabs.f32 cosTheta_O)
cosTheta_O\_s = (copysign.f32 #s(literal 1 binary32) cosTheta_O)
NOTE: cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, and v should be sorted in increasing order before calling this function.
(FPCore (cosTheta_O_s cosTheta_i_s cosTheta_i_m cosTheta_O_m sinTheta_i sinTheta_O v)
 :precision binary32
 (*
  cosTheta_O_s
  (*
   cosTheta_i_s
   (/ (* cosTheta_O_m cosTheta_i_m) (* (* (sinh (/ 1.0 v)) (+ v v)) v)))))
cosTheta_i\_m = fabs(cosTheta_i);
cosTheta_i\_s = copysign(1.0, cosTheta_i);
cosTheta_O\_m = fabs(cosTheta_O);
cosTheta_O\_s = copysign(1.0, cosTheta_O);
assert(cosTheta_i_m < cosTheta_O_m && cosTheta_O_m < sinTheta_i && sinTheta_i < sinTheta_O && sinTheta_O < v);
float code(float cosTheta_O_s, float cosTheta_i_s, float cosTheta_i_m, float cosTheta_O_m, float sinTheta_i, float sinTheta_O, float v) {
	return cosTheta_O_s * (cosTheta_i_s * ((cosTheta_O_m * cosTheta_i_m) / ((sinhf((1.0f / v)) * (v + v)) * v)));
}
cosTheta_i\_m =     private
cosTheta_i\_s =     private
cosTheta_O\_m =     private
cosTheta_O\_s =     private
NOTE: cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, and v should be sorted in increasing order before calling this function.
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_o_s, costheta_i_s, costheta_i_m, costheta_o_m, sintheta_i, sintheta_o, v)
use fmin_fmax_functions
    real(4), intent (in) :: costheta_o_s
    real(4), intent (in) :: costheta_i_s
    real(4), intent (in) :: costheta_i_m
    real(4), intent (in) :: costheta_o_m
    real(4), intent (in) :: sintheta_i
    real(4), intent (in) :: sintheta_o
    real(4), intent (in) :: v
    code = costheta_o_s * (costheta_i_s * ((costheta_o_m * costheta_i_m) / ((sinh((1.0e0 / v)) * (v + v)) * v)))
end function
cosTheta_i\_m = abs(cosTheta_i)
cosTheta_i\_s = copysign(1.0, cosTheta_i)
cosTheta_O\_m = abs(cosTheta_O)
cosTheta_O\_s = copysign(1.0, cosTheta_O)
cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v = sort([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])
function code(cosTheta_O_s, cosTheta_i_s, cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v)
	return Float32(cosTheta_O_s * Float32(cosTheta_i_s * Float32(Float32(cosTheta_O_m * cosTheta_i_m) / Float32(Float32(sinh(Float32(Float32(1.0) / v)) * Float32(v + v)) * v))))
end
cosTheta_i\_m = abs(cosTheta_i);
cosTheta_i\_s = sign(cosTheta_i) * abs(1.0);
cosTheta_O\_m = abs(cosTheta_O);
cosTheta_O\_s = sign(cosTheta_O) * abs(1.0);
cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v = num2cell(sort([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])){:}
function tmp = code(cosTheta_O_s, cosTheta_i_s, cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v)
	tmp = cosTheta_O_s * (cosTheta_i_s * ((cosTheta_O_m * cosTheta_i_m) / ((sinh((single(1.0) / v)) * (v + v)) * v)));
end
\begin{array}{l}
cosTheta_i\_m = \left|cosTheta\_i\right|
\\
cosTheta_i\_s = \mathsf{copysign}\left(1, cosTheta\_i\right)
\\
cosTheta_O\_m = \left|cosTheta\_O\right|
\\
cosTheta_O\_s = \mathsf{copysign}\left(1, cosTheta\_O\right)
\\
[cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v] = \mathsf{sort}([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])\\
\\
cosTheta\_O\_s \cdot \left(cosTheta\_i\_s \cdot \frac{cosTheta\_O\_m \cdot cosTheta\_i\_m}{\left(\sinh \left(\frac{1}{v}\right) \cdot \left(v + v\right)\right) \cdot v}\right)
\end{array}
Derivation
  1. Initial program 98.6%

    \[\frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
  2. Step-by-step derivation
    1. lift-*.f32N/A

      \[\leadsto \frac{\color{blue}{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
    2. lift-exp.f32N/A

      \[\leadsto \frac{\color{blue}{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
    3. lift-neg.f32N/A

      \[\leadsto \frac{e^{\color{blue}{\mathsf{neg}\left(\frac{sinTheta\_i \cdot sinTheta\_O}{v}\right)}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
    4. lift-*.f32N/A

      \[\leadsto \frac{e^{\mathsf{neg}\left(\frac{\color{blue}{sinTheta\_i \cdot sinTheta\_O}}{v}\right)} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
    5. lift-/.f32N/A

      \[\leadsto \frac{e^{\mathsf{neg}\left(\color{blue}{\frac{sinTheta\_i \cdot sinTheta\_O}{v}}\right)} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
    6. lift-*.f32N/A

      \[\leadsto \frac{e^{\mathsf{neg}\left(\frac{sinTheta\_i \cdot sinTheta\_O}{v}\right)} \cdot \frac{\color{blue}{cosTheta\_i \cdot cosTheta\_O}}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
    7. lift-/.f32N/A

      \[\leadsto \frac{e^{\mathsf{neg}\left(\frac{sinTheta\_i \cdot sinTheta\_O}{v}\right)} \cdot \color{blue}{\frac{cosTheta\_i \cdot cosTheta\_O}{v}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
    8. *-commutativeN/A

      \[\leadsto \frac{\color{blue}{\frac{cosTheta\_i \cdot cosTheta\_O}{v} \cdot e^{\mathsf{neg}\left(\frac{sinTheta\_i \cdot sinTheta\_O}{v}\right)}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
    9. *-commutativeN/A

      \[\leadsto \frac{\frac{\color{blue}{cosTheta\_O \cdot cosTheta\_i}}{v} \cdot e^{\mathsf{neg}\left(\frac{sinTheta\_i \cdot sinTheta\_O}{v}\right)}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
    10. division-flipN/A

      \[\leadsto \frac{\color{blue}{\frac{1}{\frac{v}{cosTheta\_O \cdot cosTheta\_i}}} \cdot e^{\mathsf{neg}\left(\frac{sinTheta\_i \cdot sinTheta\_O}{v}\right)}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
    11. exp-negN/A

      \[\leadsto \frac{\frac{1}{\frac{v}{cosTheta\_O \cdot cosTheta\_i}} \cdot \color{blue}{\frac{1}{e^{\frac{sinTheta\_i \cdot sinTheta\_O}{v}}}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
    12. *-commutativeN/A

      \[\leadsto \frac{\frac{1}{\frac{v}{cosTheta\_O \cdot cosTheta\_i}} \cdot \frac{1}{e^{\frac{\color{blue}{sinTheta\_O \cdot sinTheta\_i}}{v}}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
    13. frac-timesN/A

      \[\leadsto \frac{\color{blue}{\frac{1 \cdot 1}{\frac{v}{cosTheta\_O \cdot cosTheta\_i} \cdot e^{\frac{sinTheta\_O \cdot sinTheta\_i}{v}}}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
    14. metadata-evalN/A

      \[\leadsto \frac{\frac{\color{blue}{1}}{\frac{v}{cosTheta\_O \cdot cosTheta\_i} \cdot e^{\frac{sinTheta\_O \cdot sinTheta\_i}{v}}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
    15. lower-/.f32N/A

      \[\leadsto \frac{\color{blue}{\frac{1}{\frac{v}{cosTheta\_O \cdot cosTheta\_i} \cdot e^{\frac{sinTheta\_O \cdot sinTheta\_i}{v}}}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
    16. lower-*.f32N/A

      \[\leadsto \frac{\frac{1}{\color{blue}{\frac{v}{cosTheta\_O \cdot cosTheta\_i} \cdot e^{\frac{sinTheta\_O \cdot sinTheta\_i}{v}}}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
  3. Applied rewrites95.1%

    \[\leadsto \frac{\color{blue}{\frac{1}{\frac{v}{cosTheta\_O \cdot cosTheta\_i} \cdot e^{\frac{sinTheta\_O \cdot sinTheta\_i}{v}}}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
  4. Taylor expanded in sinTheta_i around 0

    \[\leadsto \color{blue}{\frac{cosTheta\_O \cdot cosTheta\_i}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)}} \]
  5. Step-by-step derivation
    1. lower-/.f32N/A

      \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\color{blue}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)}} \]
    2. lift-*.f32N/A

      \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\color{blue}{{v}^{2}} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)} \]
    3. *-commutativeN/A

      \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right) \cdot \color{blue}{{v}^{2}}} \]
    4. lower-*.f32N/A

      \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right) \cdot \color{blue}{{v}^{2}}} \]
    5. lower--.f32N/A

      \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right) \cdot {\color{blue}{v}}^{2}} \]
    6. lower-exp.f32N/A

      \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right) \cdot {v}^{2}} \]
    7. lift-/.f32N/A

      \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right) \cdot {v}^{2}} \]
    8. rec-expN/A

      \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - e^{\mathsf{neg}\left(\frac{1}{v}\right)}\right) \cdot {v}^{2}} \]
    9. lower-exp.f32N/A

      \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - e^{\mathsf{neg}\left(\frac{1}{v}\right)}\right) \cdot {v}^{2}} \]
    10. lower-neg.f32N/A

      \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - e^{-\frac{1}{v}}\right) \cdot {v}^{2}} \]
    11. lift-/.f32N/A

      \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - e^{-\frac{1}{v}}\right) \cdot {v}^{2}} \]
    12. pow2N/A

      \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - e^{-\frac{1}{v}}\right) \cdot \left(v \cdot \color{blue}{v}\right)} \]
    13. lift-*.f3298.3

      \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - e^{-\frac{1}{v}}\right) \cdot \left(v \cdot \color{blue}{v}\right)} \]
  6. Applied rewrites98.3%

    \[\leadsto \color{blue}{\frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - e^{-\frac{1}{v}}\right) \cdot \left(v \cdot v\right)}} \]
  7. Step-by-step derivation
    1. lift-*.f32N/A

      \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - e^{-\frac{1}{v}}\right) \cdot \left(v \cdot \color{blue}{v}\right)} \]
    2. lift-*.f32N/A

      \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - e^{-\frac{1}{v}}\right) \cdot \color{blue}{\left(v \cdot v\right)}} \]
    3. lift--.f32N/A

      \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - e^{-\frac{1}{v}}\right) \cdot \left(\color{blue}{v} \cdot v\right)} \]
    4. lift-/.f32N/A

      \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - e^{-\frac{1}{v}}\right) \cdot \left(v \cdot v\right)} \]
    5. lift-exp.f32N/A

      \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - e^{-\frac{1}{v}}\right) \cdot \left(v \cdot v\right)} \]
    6. lift-exp.f32N/A

      \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - e^{-\frac{1}{v}}\right) \cdot \left(v \cdot v\right)} \]
    7. lift-/.f32N/A

      \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - e^{-\frac{1}{v}}\right) \cdot \left(v \cdot v\right)} \]
    8. lift-neg.f32N/A

      \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - e^{\mathsf{neg}\left(\frac{1}{v}\right)}\right) \cdot \left(v \cdot v\right)} \]
    9. associate-*r*N/A

      \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(\left(e^{\frac{1}{v}} - e^{\mathsf{neg}\left(\frac{1}{v}\right)}\right) \cdot v\right) \cdot \color{blue}{v}} \]
    10. sinh-undef-revN/A

      \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(\left(2 \cdot \sinh \left(\frac{1}{v}\right)\right) \cdot v\right) \cdot v} \]
    11. *-commutativeN/A

      \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v\right) \cdot v} \]
    12. lower-*.f32N/A

      \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v\right) \cdot \color{blue}{v}} \]
    13. associate-*l*N/A

      \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(\sinh \left(\frac{1}{v}\right) \cdot \left(2 \cdot v\right)\right) \cdot v} \]
    14. lower-*.f32N/A

      \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(\sinh \left(\frac{1}{v}\right) \cdot \left(2 \cdot v\right)\right) \cdot v} \]
    15. lift-sinh.f32N/A

      \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(\sinh \left(\frac{1}{v}\right) \cdot \left(2 \cdot v\right)\right) \cdot v} \]
    16. lift-/.f32N/A

      \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(\sinh \left(\frac{1}{v}\right) \cdot \left(2 \cdot v\right)\right) \cdot v} \]
    17. count-2-revN/A

      \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(\sinh \left(\frac{1}{v}\right) \cdot \left(v + v\right)\right) \cdot v} \]
    18. lower-+.f3298.3

      \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(\sinh \left(\frac{1}{v}\right) \cdot \left(v + v\right)\right) \cdot v} \]
  8. Applied rewrites98.3%

    \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(\sinh \left(\frac{1}{v}\right) \cdot \left(v + v\right)\right) \cdot \color{blue}{v}} \]
  9. Add Preprocessing

Alternative 8: 76.9% accurate, 1.6× speedup?

\[\begin{array}{l} cosTheta_i\_m = \left|cosTheta\_i\right| \\ cosTheta_i\_s = \mathsf{copysign}\left(1, cosTheta\_i\right) \\ cosTheta_O\_m = \left|cosTheta\_O\right| \\ cosTheta_O\_s = \mathsf{copysign}\left(1, cosTheta\_O\right) \\ [cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v] = \mathsf{sort}([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])\\ \\ cosTheta\_O\_s \cdot \left(cosTheta\_i\_s \cdot \begin{array}{l} \mathbf{if}\;v \leq 0.33000001311302185:\\ \;\;\;\;\frac{cosTheta\_O\_m \cdot cosTheta\_i\_m}{\left(e^{\frac{1}{v}} - 1\right) \cdot \left(v \cdot v\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{cosTheta\_O\_m \cdot cosTheta\_i\_m}{-\left(\left(-\frac{0.3333333333333333 + \frac{0.016666666666666666}{v \cdot v}}{v \cdot v}\right) - 2\right) \cdot v}\\ \end{array}\right) \end{array} \]
cosTheta_i\_m = (fabs.f32 cosTheta_i)
cosTheta_i\_s = (copysign.f32 #s(literal 1 binary32) cosTheta_i)
cosTheta_O\_m = (fabs.f32 cosTheta_O)
cosTheta_O\_s = (copysign.f32 #s(literal 1 binary32) cosTheta_O)
NOTE: cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, and v should be sorted in increasing order before calling this function.
(FPCore (cosTheta_O_s cosTheta_i_s cosTheta_i_m cosTheta_O_m sinTheta_i sinTheta_O v)
 :precision binary32
 (*
  cosTheta_O_s
  (*
   cosTheta_i_s
   (if (<= v 0.33000001311302185)
     (/ (* cosTheta_O_m cosTheta_i_m) (* (- (exp (/ 1.0 v)) 1.0) (* v v)))
     (/
      (* cosTheta_O_m cosTheta_i_m)
      (-
       (*
        (-
         (-
          (/ (+ 0.3333333333333333 (/ 0.016666666666666666 (* v v))) (* v v)))
         2.0)
        v)))))))
cosTheta_i\_m = fabs(cosTheta_i);
cosTheta_i\_s = copysign(1.0, cosTheta_i);
cosTheta_O\_m = fabs(cosTheta_O);
cosTheta_O\_s = copysign(1.0, cosTheta_O);
assert(cosTheta_i_m < cosTheta_O_m && cosTheta_O_m < sinTheta_i && sinTheta_i < sinTheta_O && sinTheta_O < v);
float code(float cosTheta_O_s, float cosTheta_i_s, float cosTheta_i_m, float cosTheta_O_m, float sinTheta_i, float sinTheta_O, float v) {
	float tmp;
	if (v <= 0.33000001311302185f) {
		tmp = (cosTheta_O_m * cosTheta_i_m) / ((expf((1.0f / v)) - 1.0f) * (v * v));
	} else {
		tmp = (cosTheta_O_m * cosTheta_i_m) / -((-((0.3333333333333333f + (0.016666666666666666f / (v * v))) / (v * v)) - 2.0f) * v);
	}
	return cosTheta_O_s * (cosTheta_i_s * tmp);
}
cosTheta_i\_m =     private
cosTheta_i\_s =     private
cosTheta_O\_m =     private
cosTheta_O\_s =     private
NOTE: cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, and v should be sorted in increasing order before calling this function.
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_o_s, costheta_i_s, costheta_i_m, costheta_o_m, sintheta_i, sintheta_o, v)
use fmin_fmax_functions
    real(4), intent (in) :: costheta_o_s
    real(4), intent (in) :: costheta_i_s
    real(4), intent (in) :: costheta_i_m
    real(4), intent (in) :: costheta_o_m
    real(4), intent (in) :: sintheta_i
    real(4), intent (in) :: sintheta_o
    real(4), intent (in) :: v
    real(4) :: tmp
    if (v <= 0.33000001311302185e0) then
        tmp = (costheta_o_m * costheta_i_m) / ((exp((1.0e0 / v)) - 1.0e0) * (v * v))
    else
        tmp = (costheta_o_m * costheta_i_m) / -((-((0.3333333333333333e0 + (0.016666666666666666e0 / (v * v))) / (v * v)) - 2.0e0) * v)
    end if
    code = costheta_o_s * (costheta_i_s * tmp)
end function
cosTheta_i\_m = abs(cosTheta_i)
cosTheta_i\_s = copysign(1.0, cosTheta_i)
cosTheta_O\_m = abs(cosTheta_O)
cosTheta_O\_s = copysign(1.0, cosTheta_O)
cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v = sort([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])
function code(cosTheta_O_s, cosTheta_i_s, cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v)
	tmp = Float32(0.0)
	if (v <= Float32(0.33000001311302185))
		tmp = Float32(Float32(cosTheta_O_m * cosTheta_i_m) / Float32(Float32(exp(Float32(Float32(1.0) / v)) - Float32(1.0)) * Float32(v * v)));
	else
		tmp = Float32(Float32(cosTheta_O_m * cosTheta_i_m) / Float32(-Float32(Float32(Float32(-Float32(Float32(Float32(0.3333333333333333) + Float32(Float32(0.016666666666666666) / Float32(v * v))) / Float32(v * v))) - Float32(2.0)) * v)));
	end
	return Float32(cosTheta_O_s * Float32(cosTheta_i_s * tmp))
end
cosTheta_i\_m = abs(cosTheta_i);
cosTheta_i\_s = sign(cosTheta_i) * abs(1.0);
cosTheta_O\_m = abs(cosTheta_O);
cosTheta_O\_s = sign(cosTheta_O) * abs(1.0);
cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v = num2cell(sort([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])){:}
function tmp_2 = code(cosTheta_O_s, cosTheta_i_s, cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v)
	tmp = single(0.0);
	if (v <= single(0.33000001311302185))
		tmp = (cosTheta_O_m * cosTheta_i_m) / ((exp((single(1.0) / v)) - single(1.0)) * (v * v));
	else
		tmp = (cosTheta_O_m * cosTheta_i_m) / -((-((single(0.3333333333333333) + (single(0.016666666666666666) / (v * v))) / (v * v)) - single(2.0)) * v);
	end
	tmp_2 = cosTheta_O_s * (cosTheta_i_s * tmp);
end
\begin{array}{l}
cosTheta_i\_m = \left|cosTheta\_i\right|
\\
cosTheta_i\_s = \mathsf{copysign}\left(1, cosTheta\_i\right)
\\
cosTheta_O\_m = \left|cosTheta\_O\right|
\\
cosTheta_O\_s = \mathsf{copysign}\left(1, cosTheta\_O\right)
\\
[cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v] = \mathsf{sort}([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])\\
\\
cosTheta\_O\_s \cdot \left(cosTheta\_i\_s \cdot \begin{array}{l}
\mathbf{if}\;v \leq 0.33000001311302185:\\
\;\;\;\;\frac{cosTheta\_O\_m \cdot cosTheta\_i\_m}{\left(e^{\frac{1}{v}} - 1\right) \cdot \left(v \cdot v\right)}\\

\mathbf{else}:\\
\;\;\;\;\frac{cosTheta\_O\_m \cdot cosTheta\_i\_m}{-\left(\left(-\frac{0.3333333333333333 + \frac{0.016666666666666666}{v \cdot v}}{v \cdot v}\right) - 2\right) \cdot v}\\


\end{array}\right)
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if v < 0.330000013

    1. Initial program 98.1%

      \[\frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
    2. Step-by-step derivation
      1. lift-*.f32N/A

        \[\leadsto \frac{\color{blue}{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
      2. lift-exp.f32N/A

        \[\leadsto \frac{\color{blue}{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
      3. lift-neg.f32N/A

        \[\leadsto \frac{e^{\color{blue}{\mathsf{neg}\left(\frac{sinTheta\_i \cdot sinTheta\_O}{v}\right)}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
      4. lift-*.f32N/A

        \[\leadsto \frac{e^{\mathsf{neg}\left(\frac{\color{blue}{sinTheta\_i \cdot sinTheta\_O}}{v}\right)} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
      5. lift-/.f32N/A

        \[\leadsto \frac{e^{\mathsf{neg}\left(\color{blue}{\frac{sinTheta\_i \cdot sinTheta\_O}{v}}\right)} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
      6. lift-*.f32N/A

        \[\leadsto \frac{e^{\mathsf{neg}\left(\frac{sinTheta\_i \cdot sinTheta\_O}{v}\right)} \cdot \frac{\color{blue}{cosTheta\_i \cdot cosTheta\_O}}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
      7. lift-/.f32N/A

        \[\leadsto \frac{e^{\mathsf{neg}\left(\frac{sinTheta\_i \cdot sinTheta\_O}{v}\right)} \cdot \color{blue}{\frac{cosTheta\_i \cdot cosTheta\_O}{v}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
      8. *-commutativeN/A

        \[\leadsto \frac{\color{blue}{\frac{cosTheta\_i \cdot cosTheta\_O}{v} \cdot e^{\mathsf{neg}\left(\frac{sinTheta\_i \cdot sinTheta\_O}{v}\right)}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
      9. *-commutativeN/A

        \[\leadsto \frac{\frac{\color{blue}{cosTheta\_O \cdot cosTheta\_i}}{v} \cdot e^{\mathsf{neg}\left(\frac{sinTheta\_i \cdot sinTheta\_O}{v}\right)}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
      10. division-flipN/A

        \[\leadsto \frac{\color{blue}{\frac{1}{\frac{v}{cosTheta\_O \cdot cosTheta\_i}}} \cdot e^{\mathsf{neg}\left(\frac{sinTheta\_i \cdot sinTheta\_O}{v}\right)}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
      11. exp-negN/A

        \[\leadsto \frac{\frac{1}{\frac{v}{cosTheta\_O \cdot cosTheta\_i}} \cdot \color{blue}{\frac{1}{e^{\frac{sinTheta\_i \cdot sinTheta\_O}{v}}}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
      12. *-commutativeN/A

        \[\leadsto \frac{\frac{1}{\frac{v}{cosTheta\_O \cdot cosTheta\_i}} \cdot \frac{1}{e^{\frac{\color{blue}{sinTheta\_O \cdot sinTheta\_i}}{v}}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
      13. frac-timesN/A

        \[\leadsto \frac{\color{blue}{\frac{1 \cdot 1}{\frac{v}{cosTheta\_O \cdot cosTheta\_i} \cdot e^{\frac{sinTheta\_O \cdot sinTheta\_i}{v}}}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
      14. metadata-evalN/A

        \[\leadsto \frac{\frac{\color{blue}{1}}{\frac{v}{cosTheta\_O \cdot cosTheta\_i} \cdot e^{\frac{sinTheta\_O \cdot sinTheta\_i}{v}}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
      15. lower-/.f32N/A

        \[\leadsto \frac{\color{blue}{\frac{1}{\frac{v}{cosTheta\_O \cdot cosTheta\_i} \cdot e^{\frac{sinTheta\_O \cdot sinTheta\_i}{v}}}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
      16. lower-*.f32N/A

        \[\leadsto \frac{\frac{1}{\color{blue}{\frac{v}{cosTheta\_O \cdot cosTheta\_i} \cdot e^{\frac{sinTheta\_O \cdot sinTheta\_i}{v}}}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
    3. Applied rewrites95.5%

      \[\leadsto \frac{\color{blue}{\frac{1}{\frac{v}{cosTheta\_O \cdot cosTheta\_i} \cdot e^{\frac{sinTheta\_O \cdot sinTheta\_i}{v}}}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
    4. Taylor expanded in sinTheta_i around 0

      \[\leadsto \color{blue}{\frac{cosTheta\_O \cdot cosTheta\_i}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)}} \]
    5. Step-by-step derivation
      1. lower-/.f32N/A

        \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\color{blue}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)}} \]
      2. lift-*.f32N/A

        \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\color{blue}{{v}^{2}} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)} \]
      3. *-commutativeN/A

        \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right) \cdot \color{blue}{{v}^{2}}} \]
      4. lower-*.f32N/A

        \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right) \cdot \color{blue}{{v}^{2}}} \]
      5. lower--.f32N/A

        \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right) \cdot {\color{blue}{v}}^{2}} \]
      6. lower-exp.f32N/A

        \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right) \cdot {v}^{2}} \]
      7. lift-/.f32N/A

        \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right) \cdot {v}^{2}} \]
      8. rec-expN/A

        \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - e^{\mathsf{neg}\left(\frac{1}{v}\right)}\right) \cdot {v}^{2}} \]
      9. lower-exp.f32N/A

        \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - e^{\mathsf{neg}\left(\frac{1}{v}\right)}\right) \cdot {v}^{2}} \]
      10. lower-neg.f32N/A

        \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - e^{-\frac{1}{v}}\right) \cdot {v}^{2}} \]
      11. lift-/.f32N/A

        \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - e^{-\frac{1}{v}}\right) \cdot {v}^{2}} \]
      12. pow2N/A

        \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - e^{-\frac{1}{v}}\right) \cdot \left(v \cdot \color{blue}{v}\right)} \]
      13. lift-*.f3297.9

        \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - e^{-\frac{1}{v}}\right) \cdot \left(v \cdot \color{blue}{v}\right)} \]
    6. Applied rewrites97.9%

      \[\leadsto \color{blue}{\frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - e^{-\frac{1}{v}}\right) \cdot \left(v \cdot v\right)}} \]
    7. Taylor expanded in v around inf

      \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - 1\right) \cdot \left(v \cdot v\right)} \]
    8. Step-by-step derivation
      1. Applied rewrites75.7%

        \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - 1\right) \cdot \left(v \cdot v\right)} \]

      if 0.330000013 < v

      1. Initial program 98.9%

        \[\frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
      2. Step-by-step derivation
        1. lift-*.f32N/A

          \[\leadsto \frac{\color{blue}{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
        2. lift-exp.f32N/A

          \[\leadsto \frac{\color{blue}{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
        3. lift-neg.f32N/A

          \[\leadsto \frac{e^{\color{blue}{\mathsf{neg}\left(\frac{sinTheta\_i \cdot sinTheta\_O}{v}\right)}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
        4. lift-*.f32N/A

          \[\leadsto \frac{e^{\mathsf{neg}\left(\frac{\color{blue}{sinTheta\_i \cdot sinTheta\_O}}{v}\right)} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
        5. lift-/.f32N/A

          \[\leadsto \frac{e^{\mathsf{neg}\left(\color{blue}{\frac{sinTheta\_i \cdot sinTheta\_O}{v}}\right)} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
        6. lift-*.f32N/A

          \[\leadsto \frac{e^{\mathsf{neg}\left(\frac{sinTheta\_i \cdot sinTheta\_O}{v}\right)} \cdot \frac{\color{blue}{cosTheta\_i \cdot cosTheta\_O}}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
        7. lift-/.f32N/A

          \[\leadsto \frac{e^{\mathsf{neg}\left(\frac{sinTheta\_i \cdot sinTheta\_O}{v}\right)} \cdot \color{blue}{\frac{cosTheta\_i \cdot cosTheta\_O}{v}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
        8. *-commutativeN/A

          \[\leadsto \frac{\color{blue}{\frac{cosTheta\_i \cdot cosTheta\_O}{v} \cdot e^{\mathsf{neg}\left(\frac{sinTheta\_i \cdot sinTheta\_O}{v}\right)}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
        9. *-commutativeN/A

          \[\leadsto \frac{\frac{\color{blue}{cosTheta\_O \cdot cosTheta\_i}}{v} \cdot e^{\mathsf{neg}\left(\frac{sinTheta\_i \cdot sinTheta\_O}{v}\right)}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
        10. division-flipN/A

          \[\leadsto \frac{\color{blue}{\frac{1}{\frac{v}{cosTheta\_O \cdot cosTheta\_i}}} \cdot e^{\mathsf{neg}\left(\frac{sinTheta\_i \cdot sinTheta\_O}{v}\right)}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
        11. exp-negN/A

          \[\leadsto \frac{\frac{1}{\frac{v}{cosTheta\_O \cdot cosTheta\_i}} \cdot \color{blue}{\frac{1}{e^{\frac{sinTheta\_i \cdot sinTheta\_O}{v}}}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
        12. *-commutativeN/A

          \[\leadsto \frac{\frac{1}{\frac{v}{cosTheta\_O \cdot cosTheta\_i}} \cdot \frac{1}{e^{\frac{\color{blue}{sinTheta\_O \cdot sinTheta\_i}}{v}}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
        13. frac-timesN/A

          \[\leadsto \frac{\color{blue}{\frac{1 \cdot 1}{\frac{v}{cosTheta\_O \cdot cosTheta\_i} \cdot e^{\frac{sinTheta\_O \cdot sinTheta\_i}{v}}}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
        14. metadata-evalN/A

          \[\leadsto \frac{\frac{\color{blue}{1}}{\frac{v}{cosTheta\_O \cdot cosTheta\_i} \cdot e^{\frac{sinTheta\_O \cdot sinTheta\_i}{v}}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
        15. lower-/.f32N/A

          \[\leadsto \frac{\color{blue}{\frac{1}{\frac{v}{cosTheta\_O \cdot cosTheta\_i} \cdot e^{\frac{sinTheta\_O \cdot sinTheta\_i}{v}}}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
        16. lower-*.f32N/A

          \[\leadsto \frac{\frac{1}{\color{blue}{\frac{v}{cosTheta\_O \cdot cosTheta\_i} \cdot e^{\frac{sinTheta\_O \cdot sinTheta\_i}{v}}}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
      3. Applied rewrites94.8%

        \[\leadsto \frac{\color{blue}{\frac{1}{\frac{v}{cosTheta\_O \cdot cosTheta\_i} \cdot e^{\frac{sinTheta\_O \cdot sinTheta\_i}{v}}}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
      4. Taylor expanded in sinTheta_i around 0

        \[\leadsto \color{blue}{\frac{cosTheta\_O \cdot cosTheta\_i}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)}} \]
      5. Step-by-step derivation
        1. lower-/.f32N/A

          \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\color{blue}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)}} \]
        2. lift-*.f32N/A

          \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\color{blue}{{v}^{2}} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)} \]
        3. *-commutativeN/A

          \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right) \cdot \color{blue}{{v}^{2}}} \]
        4. lower-*.f32N/A

          \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right) \cdot \color{blue}{{v}^{2}}} \]
        5. lower--.f32N/A

          \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right) \cdot {\color{blue}{v}}^{2}} \]
        6. lower-exp.f32N/A

          \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right) \cdot {v}^{2}} \]
        7. lift-/.f32N/A

          \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right) \cdot {v}^{2}} \]
        8. rec-expN/A

          \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - e^{\mathsf{neg}\left(\frac{1}{v}\right)}\right) \cdot {v}^{2}} \]
        9. lower-exp.f32N/A

          \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - e^{\mathsf{neg}\left(\frac{1}{v}\right)}\right) \cdot {v}^{2}} \]
        10. lower-neg.f32N/A

          \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - e^{-\frac{1}{v}}\right) \cdot {v}^{2}} \]
        11. lift-/.f32N/A

          \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - e^{-\frac{1}{v}}\right) \cdot {v}^{2}} \]
        12. pow2N/A

          \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - e^{-\frac{1}{v}}\right) \cdot \left(v \cdot \color{blue}{v}\right)} \]
        13. lift-*.f3298.7

          \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - e^{-\frac{1}{v}}\right) \cdot \left(v \cdot \color{blue}{v}\right)} \]
      6. Applied rewrites98.7%

        \[\leadsto \color{blue}{\frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - e^{-\frac{1}{v}}\right) \cdot \left(v \cdot v\right)}} \]
      7. Taylor expanded in v around -inf

        \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{-1 \cdot \color{blue}{\left(v \cdot \left(-1 \cdot \frac{\frac{1}{3} + \frac{1}{60} \cdot \frac{1}{{v}^{2}}}{{v}^{2}} - 2\right)\right)}} \]
      8. Step-by-step derivation
        1. pow2N/A

          \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{-1 \cdot \left(v \cdot \left(-1 \cdot \frac{\frac{1}{3} + \frac{1}{60} \cdot \frac{1}{{v}^{2}}}{{v}^{2}} - 2\right)\right)} \]
        2. *-commutativeN/A

          \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{-1 \cdot \left(\color{blue}{v} \cdot \left(-1 \cdot \frac{\frac{1}{3} + \frac{1}{60} \cdot \frac{1}{{v}^{2}}}{{v}^{2}} - 2\right)\right)} \]
        3. pow2N/A

          \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{-1 \cdot \left(v \cdot \left(-1 \cdot \frac{\frac{1}{3} + \frac{1}{60} \cdot \frac{1}{{v}^{2}}}{{v}^{2}} - 2\right)\right)} \]
        4. sinh-undef-revN/A

          \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{-1 \cdot \left(v \cdot \left(-1 \cdot \frac{\frac{1}{3} + \frac{1}{60} \cdot \frac{1}{{v}^{2}}}{{v}^{2}} - 2\right)\right)} \]
        5. mul-1-negN/A

          \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\mathsf{neg}\left(v \cdot \left(-1 \cdot \frac{\frac{1}{3} + \frac{1}{60} \cdot \frac{1}{{v}^{2}}}{{v}^{2}} - 2\right)\right)} \]
        6. lower-neg.f32N/A

          \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{-v \cdot \left(-1 \cdot \frac{\frac{1}{3} + \frac{1}{60} \cdot \frac{1}{{v}^{2}}}{{v}^{2}} - 2\right)} \]
        7. *-commutativeN/A

          \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{-\left(-1 \cdot \frac{\frac{1}{3} + \frac{1}{60} \cdot \frac{1}{{v}^{2}}}{{v}^{2}} - 2\right) \cdot v} \]
        8. lower-*.f32N/A

          \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{-\left(-1 \cdot \frac{\frac{1}{3} + \frac{1}{60} \cdot \frac{1}{{v}^{2}}}{{v}^{2}} - 2\right) \cdot v} \]
      9. Applied rewrites77.8%

        \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{-\left(\left(-\frac{0.3333333333333333 + \frac{0.016666666666666666}{v \cdot v}}{v \cdot v}\right) - 2\right) \cdot v} \]
    9. Recombined 2 regimes into one program.
    10. Add Preprocessing

    Alternative 9: 72.7% accurate, 1.6× speedup?

    \[\begin{array}{l} cosTheta_i\_m = \left|cosTheta\_i\right| \\ cosTheta_i\_s = \mathsf{copysign}\left(1, cosTheta\_i\right) \\ cosTheta_O\_m = \left|cosTheta\_O\right| \\ cosTheta_O\_s = \mathsf{copysign}\left(1, cosTheta\_O\right) \\ [cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v] = \mathsf{sort}([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])\\ \\ cosTheta\_O\_s \cdot \left(cosTheta\_i\_s \cdot \begin{array}{l} \mathbf{if}\;v \leq 0.46000000834465027:\\ \;\;\;\;\frac{cosTheta\_O\_m \cdot cosTheta\_i\_m}{\left(e^{\frac{1}{v}} - 1\right) \cdot \left(v \cdot v\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{cosTheta\_O\_m}{\left(v \cdot v\right) \cdot \left(2 \cdot \frac{1 + \frac{0.16666666666666666}{v \cdot v}}{v}\right)} \cdot cosTheta\_i\_m\\ \end{array}\right) \end{array} \]
    cosTheta_i\_m = (fabs.f32 cosTheta_i)
    cosTheta_i\_s = (copysign.f32 #s(literal 1 binary32) cosTheta_i)
    cosTheta_O\_m = (fabs.f32 cosTheta_O)
    cosTheta_O\_s = (copysign.f32 #s(literal 1 binary32) cosTheta_O)
    NOTE: cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, and v should be sorted in increasing order before calling this function.
    (FPCore (cosTheta_O_s cosTheta_i_s cosTheta_i_m cosTheta_O_m sinTheta_i sinTheta_O v)
     :precision binary32
     (*
      cosTheta_O_s
      (*
       cosTheta_i_s
       (if (<= v 0.46000000834465027)
         (/ (* cosTheta_O_m cosTheta_i_m) (* (- (exp (/ 1.0 v)) 1.0) (* v v)))
         (*
          (/
           cosTheta_O_m
           (* (* v v) (* 2.0 (/ (+ 1.0 (/ 0.16666666666666666 (* v v))) v))))
          cosTheta_i_m)))))
    cosTheta_i\_m = fabs(cosTheta_i);
    cosTheta_i\_s = copysign(1.0, cosTheta_i);
    cosTheta_O\_m = fabs(cosTheta_O);
    cosTheta_O\_s = copysign(1.0, cosTheta_O);
    assert(cosTheta_i_m < cosTheta_O_m && cosTheta_O_m < sinTheta_i && sinTheta_i < sinTheta_O && sinTheta_O < v);
    float code(float cosTheta_O_s, float cosTheta_i_s, float cosTheta_i_m, float cosTheta_O_m, float sinTheta_i, float sinTheta_O, float v) {
    	float tmp;
    	if (v <= 0.46000000834465027f) {
    		tmp = (cosTheta_O_m * cosTheta_i_m) / ((expf((1.0f / v)) - 1.0f) * (v * v));
    	} else {
    		tmp = (cosTheta_O_m / ((v * v) * (2.0f * ((1.0f + (0.16666666666666666f / (v * v))) / v)))) * cosTheta_i_m;
    	}
    	return cosTheta_O_s * (cosTheta_i_s * tmp);
    }
    
    cosTheta_i\_m =     private
    cosTheta_i\_s =     private
    cosTheta_O\_m =     private
    cosTheta_O\_s =     private
    NOTE: cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, and v should be sorted in increasing order before calling this function.
    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_o_s, costheta_i_s, costheta_i_m, costheta_o_m, sintheta_i, sintheta_o, v)
    use fmin_fmax_functions
        real(4), intent (in) :: costheta_o_s
        real(4), intent (in) :: costheta_i_s
        real(4), intent (in) :: costheta_i_m
        real(4), intent (in) :: costheta_o_m
        real(4), intent (in) :: sintheta_i
        real(4), intent (in) :: sintheta_o
        real(4), intent (in) :: v
        real(4) :: tmp
        if (v <= 0.46000000834465027e0) then
            tmp = (costheta_o_m * costheta_i_m) / ((exp((1.0e0 / v)) - 1.0e0) * (v * v))
        else
            tmp = (costheta_o_m / ((v * v) * (2.0e0 * ((1.0e0 + (0.16666666666666666e0 / (v * v))) / v)))) * costheta_i_m
        end if
        code = costheta_o_s * (costheta_i_s * tmp)
    end function
    
    cosTheta_i\_m = abs(cosTheta_i)
    cosTheta_i\_s = copysign(1.0, cosTheta_i)
    cosTheta_O\_m = abs(cosTheta_O)
    cosTheta_O\_s = copysign(1.0, cosTheta_O)
    cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v = sort([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])
    function code(cosTheta_O_s, cosTheta_i_s, cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v)
    	tmp = Float32(0.0)
    	if (v <= Float32(0.46000000834465027))
    		tmp = Float32(Float32(cosTheta_O_m * cosTheta_i_m) / Float32(Float32(exp(Float32(Float32(1.0) / v)) - Float32(1.0)) * Float32(v * v)));
    	else
    		tmp = Float32(Float32(cosTheta_O_m / Float32(Float32(v * v) * Float32(Float32(2.0) * Float32(Float32(Float32(1.0) + Float32(Float32(0.16666666666666666) / Float32(v * v))) / v)))) * cosTheta_i_m);
    	end
    	return Float32(cosTheta_O_s * Float32(cosTheta_i_s * tmp))
    end
    
    cosTheta_i\_m = abs(cosTheta_i);
    cosTheta_i\_s = sign(cosTheta_i) * abs(1.0);
    cosTheta_O\_m = abs(cosTheta_O);
    cosTheta_O\_s = sign(cosTheta_O) * abs(1.0);
    cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v = num2cell(sort([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])){:}
    function tmp_2 = code(cosTheta_O_s, cosTheta_i_s, cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v)
    	tmp = single(0.0);
    	if (v <= single(0.46000000834465027))
    		tmp = (cosTheta_O_m * cosTheta_i_m) / ((exp((single(1.0) / v)) - single(1.0)) * (v * v));
    	else
    		tmp = (cosTheta_O_m / ((v * v) * (single(2.0) * ((single(1.0) + (single(0.16666666666666666) / (v * v))) / v)))) * cosTheta_i_m;
    	end
    	tmp_2 = cosTheta_O_s * (cosTheta_i_s * tmp);
    end
    
    \begin{array}{l}
    cosTheta_i\_m = \left|cosTheta\_i\right|
    \\
    cosTheta_i\_s = \mathsf{copysign}\left(1, cosTheta\_i\right)
    \\
    cosTheta_O\_m = \left|cosTheta\_O\right|
    \\
    cosTheta_O\_s = \mathsf{copysign}\left(1, cosTheta\_O\right)
    \\
    [cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v] = \mathsf{sort}([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])\\
    \\
    cosTheta\_O\_s \cdot \left(cosTheta\_i\_s \cdot \begin{array}{l}
    \mathbf{if}\;v \leq 0.46000000834465027:\\
    \;\;\;\;\frac{cosTheta\_O\_m \cdot cosTheta\_i\_m}{\left(e^{\frac{1}{v}} - 1\right) \cdot \left(v \cdot v\right)}\\
    
    \mathbf{else}:\\
    \;\;\;\;\frac{cosTheta\_O\_m}{\left(v \cdot v\right) \cdot \left(2 \cdot \frac{1 + \frac{0.16666666666666666}{v \cdot v}}{v}\right)} \cdot cosTheta\_i\_m\\
    
    
    \end{array}\right)
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if v < 0.460000008

      1. Initial program 98.3%

        \[\frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
      2. Step-by-step derivation
        1. lift-*.f32N/A

          \[\leadsto \frac{\color{blue}{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
        2. lift-exp.f32N/A

          \[\leadsto \frac{\color{blue}{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
        3. lift-neg.f32N/A

          \[\leadsto \frac{e^{\color{blue}{\mathsf{neg}\left(\frac{sinTheta\_i \cdot sinTheta\_O}{v}\right)}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
        4. lift-*.f32N/A

          \[\leadsto \frac{e^{\mathsf{neg}\left(\frac{\color{blue}{sinTheta\_i \cdot sinTheta\_O}}{v}\right)} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
        5. lift-/.f32N/A

          \[\leadsto \frac{e^{\mathsf{neg}\left(\color{blue}{\frac{sinTheta\_i \cdot sinTheta\_O}{v}}\right)} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
        6. lift-*.f32N/A

          \[\leadsto \frac{e^{\mathsf{neg}\left(\frac{sinTheta\_i \cdot sinTheta\_O}{v}\right)} \cdot \frac{\color{blue}{cosTheta\_i \cdot cosTheta\_O}}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
        7. lift-/.f32N/A

          \[\leadsto \frac{e^{\mathsf{neg}\left(\frac{sinTheta\_i \cdot sinTheta\_O}{v}\right)} \cdot \color{blue}{\frac{cosTheta\_i \cdot cosTheta\_O}{v}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
        8. *-commutativeN/A

          \[\leadsto \frac{\color{blue}{\frac{cosTheta\_i \cdot cosTheta\_O}{v} \cdot e^{\mathsf{neg}\left(\frac{sinTheta\_i \cdot sinTheta\_O}{v}\right)}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
        9. *-commutativeN/A

          \[\leadsto \frac{\frac{\color{blue}{cosTheta\_O \cdot cosTheta\_i}}{v} \cdot e^{\mathsf{neg}\left(\frac{sinTheta\_i \cdot sinTheta\_O}{v}\right)}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
        10. division-flipN/A

          \[\leadsto \frac{\color{blue}{\frac{1}{\frac{v}{cosTheta\_O \cdot cosTheta\_i}}} \cdot e^{\mathsf{neg}\left(\frac{sinTheta\_i \cdot sinTheta\_O}{v}\right)}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
        11. exp-negN/A

          \[\leadsto \frac{\frac{1}{\frac{v}{cosTheta\_O \cdot cosTheta\_i}} \cdot \color{blue}{\frac{1}{e^{\frac{sinTheta\_i \cdot sinTheta\_O}{v}}}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
        12. *-commutativeN/A

          \[\leadsto \frac{\frac{1}{\frac{v}{cosTheta\_O \cdot cosTheta\_i}} \cdot \frac{1}{e^{\frac{\color{blue}{sinTheta\_O \cdot sinTheta\_i}}{v}}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
        13. frac-timesN/A

          \[\leadsto \frac{\color{blue}{\frac{1 \cdot 1}{\frac{v}{cosTheta\_O \cdot cosTheta\_i} \cdot e^{\frac{sinTheta\_O \cdot sinTheta\_i}{v}}}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
        14. metadata-evalN/A

          \[\leadsto \frac{\frac{\color{blue}{1}}{\frac{v}{cosTheta\_O \cdot cosTheta\_i} \cdot e^{\frac{sinTheta\_O \cdot sinTheta\_i}{v}}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
        15. lower-/.f32N/A

          \[\leadsto \frac{\color{blue}{\frac{1}{\frac{v}{cosTheta\_O \cdot cosTheta\_i} \cdot e^{\frac{sinTheta\_O \cdot sinTheta\_i}{v}}}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
        16. lower-*.f32N/A

          \[\leadsto \frac{\frac{1}{\color{blue}{\frac{v}{cosTheta\_O \cdot cosTheta\_i} \cdot e^{\frac{sinTheta\_O \cdot sinTheta\_i}{v}}}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
      3. Applied rewrites95.3%

        \[\leadsto \frac{\color{blue}{\frac{1}{\frac{v}{cosTheta\_O \cdot cosTheta\_i} \cdot e^{\frac{sinTheta\_O \cdot sinTheta\_i}{v}}}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
      4. Taylor expanded in sinTheta_i around 0

        \[\leadsto \color{blue}{\frac{cosTheta\_O \cdot cosTheta\_i}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)}} \]
      5. Step-by-step derivation
        1. lower-/.f32N/A

          \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\color{blue}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)}} \]
        2. lift-*.f32N/A

          \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\color{blue}{{v}^{2}} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)} \]
        3. *-commutativeN/A

          \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right) \cdot \color{blue}{{v}^{2}}} \]
        4. lower-*.f32N/A

          \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right) \cdot \color{blue}{{v}^{2}}} \]
        5. lower--.f32N/A

          \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right) \cdot {\color{blue}{v}}^{2}} \]
        6. lower-exp.f32N/A

          \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right) \cdot {v}^{2}} \]
        7. lift-/.f32N/A

          \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right) \cdot {v}^{2}} \]
        8. rec-expN/A

          \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - e^{\mathsf{neg}\left(\frac{1}{v}\right)}\right) \cdot {v}^{2}} \]
        9. lower-exp.f32N/A

          \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - e^{\mathsf{neg}\left(\frac{1}{v}\right)}\right) \cdot {v}^{2}} \]
        10. lower-neg.f32N/A

          \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - e^{-\frac{1}{v}}\right) \cdot {v}^{2}} \]
        11. lift-/.f32N/A

          \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - e^{-\frac{1}{v}}\right) \cdot {v}^{2}} \]
        12. pow2N/A

          \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - e^{-\frac{1}{v}}\right) \cdot \left(v \cdot \color{blue}{v}\right)} \]
        13. lift-*.f3298.1

          \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - e^{-\frac{1}{v}}\right) \cdot \left(v \cdot \color{blue}{v}\right)} \]
      6. Applied rewrites98.1%

        \[\leadsto \color{blue}{\frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - e^{-\frac{1}{v}}\right) \cdot \left(v \cdot v\right)}} \]
      7. Taylor expanded in v around inf

        \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - 1\right) \cdot \left(v \cdot v\right)} \]
      8. Step-by-step derivation
        1. Applied rewrites73.9%

          \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - 1\right) \cdot \left(v \cdot v\right)} \]

        if 0.460000008 < v

        1. Initial program 98.9%

          \[\frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
        2. Taylor expanded in sinTheta_i around 0

          \[\leadsto \color{blue}{-1 \cdot \frac{cosTheta\_O \cdot \left(cosTheta\_i \cdot \left(sinTheta\_O \cdot sinTheta\_i\right)\right)}{{v}^{3} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)} + \frac{cosTheta\_O \cdot cosTheta\_i}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)}} \]
        3. Step-by-step derivation
          1. +-commutativeN/A

            \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)} + \color{blue}{-1 \cdot \frac{cosTheta\_O \cdot \left(cosTheta\_i \cdot \left(sinTheta\_O \cdot sinTheta\_i\right)\right)}{{v}^{3} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)}} \]
          2. associate-/l*N/A

            \[\leadsto cosTheta\_O \cdot \frac{cosTheta\_i}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)} + \color{blue}{-1} \cdot \frac{cosTheta\_O \cdot \left(cosTheta\_i \cdot \left(sinTheta\_O \cdot sinTheta\_i\right)\right)}{{v}^{3} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)} \]
          3. lower-fma.f32N/A

            \[\leadsto \mathsf{fma}\left(cosTheta\_O, \color{blue}{\frac{cosTheta\_i}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)}}, -1 \cdot \frac{cosTheta\_O \cdot \left(cosTheta\_i \cdot \left(sinTheta\_O \cdot sinTheta\_i\right)\right)}{{v}^{3} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)}\right) \]
        4. Applied rewrites99.0%

          \[\leadsto \color{blue}{\mathsf{fma}\left(cosTheta\_O, \frac{cosTheta\_i}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot \left(v \cdot v\right)}, \frac{-\left(\left(sinTheta\_O \cdot sinTheta\_i\right) \cdot cosTheta\_i\right) \cdot cosTheta\_O}{\left(\left(v \cdot v\right) \cdot v\right) \cdot \left(\sinh \left(\frac{1}{v}\right) \cdot 2\right)}\right)} \]
        5. Taylor expanded in cosTheta_i around 0

          \[\leadsto cosTheta\_i \cdot \color{blue}{\left(-1 \cdot \frac{cosTheta\_O \cdot \left(sinTheta\_O \cdot sinTheta\_i\right)}{{v}^{3} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)} + \frac{cosTheta\_O}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)}\right)} \]
        6. Step-by-step derivation
          1. *-commutativeN/A

            \[\leadsto \left(-1 \cdot \frac{cosTheta\_O \cdot \left(sinTheta\_O \cdot sinTheta\_i\right)}{{v}^{3} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)} + \frac{cosTheta\_O}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)}\right) \cdot cosTheta\_i \]
          2. lower-*.f32N/A

            \[\leadsto \left(-1 \cdot \frac{cosTheta\_O \cdot \left(sinTheta\_O \cdot sinTheta\_i\right)}{{v}^{3} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)} + \frac{cosTheta\_O}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)}\right) \cdot cosTheta\_i \]
        7. Applied rewrites98.9%

          \[\leadsto \left(\frac{cosTheta\_O}{\left(e^{\frac{1}{v}} - e^{-\frac{1}{v}}\right) \cdot \left(v \cdot v\right)} + \left(-\frac{\left(sinTheta\_O \cdot sinTheta\_i\right) \cdot cosTheta\_O}{\left(\left(v \cdot v\right) \cdot v\right) \cdot \left(e^{\frac{1}{v}} - e^{-\frac{1}{v}}\right)}\right)\right) \cdot \color{blue}{cosTheta\_i} \]
        8. Taylor expanded in sinTheta_i around 0

          \[\leadsto \frac{cosTheta\_O}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - e^{\mathsf{neg}\left(\frac{1}{v}\right)}\right)} \cdot cosTheta\_i \]
        9. Step-by-step derivation
          1. rec-expN/A

            \[\leadsto \frac{cosTheta\_O}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)} \cdot cosTheta\_i \]
          2. lower-/.f32N/A

            \[\leadsto \frac{cosTheta\_O}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)} \cdot cosTheta\_i \]
          3. rec-expN/A

            \[\leadsto \frac{cosTheta\_O}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - e^{\mathsf{neg}\left(\frac{1}{v}\right)}\right)} \cdot cosTheta\_i \]
          4. lower-*.f32N/A

            \[\leadsto \frac{cosTheta\_O}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - e^{\mathsf{neg}\left(\frac{1}{v}\right)}\right)} \cdot cosTheta\_i \]
          5. pow2N/A

            \[\leadsto \frac{cosTheta\_O}{\left(v \cdot v\right) \cdot \left(e^{\frac{1}{v}} - e^{\mathsf{neg}\left(\frac{1}{v}\right)}\right)} \cdot cosTheta\_i \]
          6. lift-*.f32N/A

            \[\leadsto \frac{cosTheta\_O}{\left(v \cdot v\right) \cdot \left(e^{\frac{1}{v}} - e^{\mathsf{neg}\left(\frac{1}{v}\right)}\right)} \cdot cosTheta\_i \]
          7. sinh-undef-revN/A

            \[\leadsto \frac{cosTheta\_O}{\left(v \cdot v\right) \cdot \left(2 \cdot \sinh \left(\frac{1}{v}\right)\right)} \cdot cosTheta\_i \]
          8. lift-sinh.f32N/A

            \[\leadsto \frac{cosTheta\_O}{\left(v \cdot v\right) \cdot \left(2 \cdot \sinh \left(\frac{1}{v}\right)\right)} \cdot cosTheta\_i \]
          9. lift-/.f32N/A

            \[\leadsto \frac{cosTheta\_O}{\left(v \cdot v\right) \cdot \left(2 \cdot \sinh \left(\frac{1}{v}\right)\right)} \cdot cosTheta\_i \]
          10. lift-*.f3298.8

            \[\leadsto \frac{cosTheta\_O}{\left(v \cdot v\right) \cdot \left(2 \cdot \sinh \left(\frac{1}{v}\right)\right)} \cdot cosTheta\_i \]
        10. Applied rewrites98.8%

          \[\leadsto \frac{cosTheta\_O}{\left(v \cdot v\right) \cdot \left(2 \cdot \sinh \left(\frac{1}{v}\right)\right)} \cdot cosTheta\_i \]
        11. Taylor expanded in v around inf

          \[\leadsto \frac{cosTheta\_O}{\left(v \cdot v\right) \cdot \left(2 \cdot \frac{1 + \frac{1}{6} \cdot \frac{1}{{v}^{2}}}{v}\right)} \cdot cosTheta\_i \]
        12. Step-by-step derivation
          1. lower-/.f32N/A

            \[\leadsto \frac{cosTheta\_O}{\left(v \cdot v\right) \cdot \left(2 \cdot \frac{1 + \frac{1}{6} \cdot \frac{1}{{v}^{2}}}{v}\right)} \cdot cosTheta\_i \]
          2. lower-+.f32N/A

            \[\leadsto \frac{cosTheta\_O}{\left(v \cdot v\right) \cdot \left(2 \cdot \frac{1 + \frac{1}{6} \cdot \frac{1}{{v}^{2}}}{v}\right)} \cdot cosTheta\_i \]
          3. mult-flip-revN/A

            \[\leadsto \frac{cosTheta\_O}{\left(v \cdot v\right) \cdot \left(2 \cdot \frac{1 + \frac{\frac{1}{6}}{{v}^{2}}}{v}\right)} \cdot cosTheta\_i \]
          4. lower-/.f32N/A

            \[\leadsto \frac{cosTheta\_O}{\left(v \cdot v\right) \cdot \left(2 \cdot \frac{1 + \frac{\frac{1}{6}}{{v}^{2}}}{v}\right)} \cdot cosTheta\_i \]
          5. pow2N/A

            \[\leadsto \frac{cosTheta\_O}{\left(v \cdot v\right) \cdot \left(2 \cdot \frac{1 + \frac{\frac{1}{6}}{v \cdot v}}{v}\right)} \cdot cosTheta\_i \]
          6. lift-*.f3271.0

            \[\leadsto \frac{cosTheta\_O}{\left(v \cdot v\right) \cdot \left(2 \cdot \frac{1 + \frac{0.16666666666666666}{v \cdot v}}{v}\right)} \cdot cosTheta\_i \]
        13. Applied rewrites71.0%

          \[\leadsto \frac{cosTheta\_O}{\left(v \cdot v\right) \cdot \left(2 \cdot \frac{1 + \frac{0.16666666666666666}{v \cdot v}}{v}\right)} \cdot cosTheta\_i \]
      9. Recombined 2 regimes into one program.
      10. Add Preprocessing

      Alternative 10: 64.8% accurate, 1.9× speedup?

      \[\begin{array}{l} cosTheta_i\_m = \left|cosTheta\_i\right| \\ cosTheta_i\_s = \mathsf{copysign}\left(1, cosTheta\_i\right) \\ cosTheta_O\_m = \left|cosTheta\_O\right| \\ cosTheta_O\_s = \mathsf{copysign}\left(1, cosTheta\_O\right) \\ [cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v] = \mathsf{sort}([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])\\ \\ cosTheta\_O\_s \cdot \left(cosTheta\_i\_s \cdot \left(\frac{cosTheta\_O\_m}{\left(v \cdot v\right) \cdot \left(2 \cdot \frac{1 + \frac{0.16666666666666666}{v \cdot v}}{v}\right)} \cdot cosTheta\_i\_m\right)\right) \end{array} \]
      cosTheta_i\_m = (fabs.f32 cosTheta_i)
      cosTheta_i\_s = (copysign.f32 #s(literal 1 binary32) cosTheta_i)
      cosTheta_O\_m = (fabs.f32 cosTheta_O)
      cosTheta_O\_s = (copysign.f32 #s(literal 1 binary32) cosTheta_O)
      NOTE: cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, and v should be sorted in increasing order before calling this function.
      (FPCore (cosTheta_O_s cosTheta_i_s cosTheta_i_m cosTheta_O_m sinTheta_i sinTheta_O v)
       :precision binary32
       (*
        cosTheta_O_s
        (*
         cosTheta_i_s
         (*
          (/
           cosTheta_O_m
           (* (* v v) (* 2.0 (/ (+ 1.0 (/ 0.16666666666666666 (* v v))) v))))
          cosTheta_i_m))))
      cosTheta_i\_m = fabs(cosTheta_i);
      cosTheta_i\_s = copysign(1.0, cosTheta_i);
      cosTheta_O\_m = fabs(cosTheta_O);
      cosTheta_O\_s = copysign(1.0, cosTheta_O);
      assert(cosTheta_i_m < cosTheta_O_m && cosTheta_O_m < sinTheta_i && sinTheta_i < sinTheta_O && sinTheta_O < v);
      float code(float cosTheta_O_s, float cosTheta_i_s, float cosTheta_i_m, float cosTheta_O_m, float sinTheta_i, float sinTheta_O, float v) {
      	return cosTheta_O_s * (cosTheta_i_s * ((cosTheta_O_m / ((v * v) * (2.0f * ((1.0f + (0.16666666666666666f / (v * v))) / v)))) * cosTheta_i_m));
      }
      
      cosTheta_i\_m =     private
      cosTheta_i\_s =     private
      cosTheta_O\_m =     private
      cosTheta_O\_s =     private
      NOTE: cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, and v should be sorted in increasing order before calling this function.
      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_o_s, costheta_i_s, costheta_i_m, costheta_o_m, sintheta_i, sintheta_o, v)
      use fmin_fmax_functions
          real(4), intent (in) :: costheta_o_s
          real(4), intent (in) :: costheta_i_s
          real(4), intent (in) :: costheta_i_m
          real(4), intent (in) :: costheta_o_m
          real(4), intent (in) :: sintheta_i
          real(4), intent (in) :: sintheta_o
          real(4), intent (in) :: v
          code = costheta_o_s * (costheta_i_s * ((costheta_o_m / ((v * v) * (2.0e0 * ((1.0e0 + (0.16666666666666666e0 / (v * v))) / v)))) * costheta_i_m))
      end function
      
      cosTheta_i\_m = abs(cosTheta_i)
      cosTheta_i\_s = copysign(1.0, cosTheta_i)
      cosTheta_O\_m = abs(cosTheta_O)
      cosTheta_O\_s = copysign(1.0, cosTheta_O)
      cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v = sort([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])
      function code(cosTheta_O_s, cosTheta_i_s, cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v)
      	return Float32(cosTheta_O_s * Float32(cosTheta_i_s * Float32(Float32(cosTheta_O_m / Float32(Float32(v * v) * Float32(Float32(2.0) * Float32(Float32(Float32(1.0) + Float32(Float32(0.16666666666666666) / Float32(v * v))) / v)))) * cosTheta_i_m)))
      end
      
      cosTheta_i\_m = abs(cosTheta_i);
      cosTheta_i\_s = sign(cosTheta_i) * abs(1.0);
      cosTheta_O\_m = abs(cosTheta_O);
      cosTheta_O\_s = sign(cosTheta_O) * abs(1.0);
      cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v = num2cell(sort([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])){:}
      function tmp = code(cosTheta_O_s, cosTheta_i_s, cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v)
      	tmp = cosTheta_O_s * (cosTheta_i_s * ((cosTheta_O_m / ((v * v) * (single(2.0) * ((single(1.0) + (single(0.16666666666666666) / (v * v))) / v)))) * cosTheta_i_m));
      end
      
      \begin{array}{l}
      cosTheta_i\_m = \left|cosTheta\_i\right|
      \\
      cosTheta_i\_s = \mathsf{copysign}\left(1, cosTheta\_i\right)
      \\
      cosTheta_O\_m = \left|cosTheta\_O\right|
      \\
      cosTheta_O\_s = \mathsf{copysign}\left(1, cosTheta\_O\right)
      \\
      [cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v] = \mathsf{sort}([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])\\
      \\
      cosTheta\_O\_s \cdot \left(cosTheta\_i\_s \cdot \left(\frac{cosTheta\_O\_m}{\left(v \cdot v\right) \cdot \left(2 \cdot \frac{1 + \frac{0.16666666666666666}{v \cdot v}}{v}\right)} \cdot cosTheta\_i\_m\right)\right)
      \end{array}
      
      Derivation
      1. Initial program 98.6%

        \[\frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
      2. Taylor expanded in sinTheta_i around 0

        \[\leadsto \color{blue}{-1 \cdot \frac{cosTheta\_O \cdot \left(cosTheta\_i \cdot \left(sinTheta\_O \cdot sinTheta\_i\right)\right)}{{v}^{3} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)} + \frac{cosTheta\_O \cdot cosTheta\_i}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)}} \]
      3. Step-by-step derivation
        1. +-commutativeN/A

          \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)} + \color{blue}{-1 \cdot \frac{cosTheta\_O \cdot \left(cosTheta\_i \cdot \left(sinTheta\_O \cdot sinTheta\_i\right)\right)}{{v}^{3} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)}} \]
        2. associate-/l*N/A

          \[\leadsto cosTheta\_O \cdot \frac{cosTheta\_i}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)} + \color{blue}{-1} \cdot \frac{cosTheta\_O \cdot \left(cosTheta\_i \cdot \left(sinTheta\_O \cdot sinTheta\_i\right)\right)}{{v}^{3} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)} \]
        3. lower-fma.f32N/A

          \[\leadsto \mathsf{fma}\left(cosTheta\_O, \color{blue}{\frac{cosTheta\_i}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)}}, -1 \cdot \frac{cosTheta\_O \cdot \left(cosTheta\_i \cdot \left(sinTheta\_O \cdot sinTheta\_i\right)\right)}{{v}^{3} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)}\right) \]
      4. Applied rewrites98.6%

        \[\leadsto \color{blue}{\mathsf{fma}\left(cosTheta\_O, \frac{cosTheta\_i}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot \left(v \cdot v\right)}, \frac{-\left(\left(sinTheta\_O \cdot sinTheta\_i\right) \cdot cosTheta\_i\right) \cdot cosTheta\_O}{\left(\left(v \cdot v\right) \cdot v\right) \cdot \left(\sinh \left(\frac{1}{v}\right) \cdot 2\right)}\right)} \]
      5. Taylor expanded in cosTheta_i around 0

        \[\leadsto cosTheta\_i \cdot \color{blue}{\left(-1 \cdot \frac{cosTheta\_O \cdot \left(sinTheta\_O \cdot sinTheta\_i\right)}{{v}^{3} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)} + \frac{cosTheta\_O}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)}\right)} \]
      6. Step-by-step derivation
        1. *-commutativeN/A

          \[\leadsto \left(-1 \cdot \frac{cosTheta\_O \cdot \left(sinTheta\_O \cdot sinTheta\_i\right)}{{v}^{3} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)} + \frac{cosTheta\_O}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)}\right) \cdot cosTheta\_i \]
        2. lower-*.f32N/A

          \[\leadsto \left(-1 \cdot \frac{cosTheta\_O \cdot \left(sinTheta\_O \cdot sinTheta\_i\right)}{{v}^{3} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)} + \frac{cosTheta\_O}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)}\right) \cdot cosTheta\_i \]
      7. Applied rewrites98.5%

        \[\leadsto \left(\frac{cosTheta\_O}{\left(e^{\frac{1}{v}} - e^{-\frac{1}{v}}\right) \cdot \left(v \cdot v\right)} + \left(-\frac{\left(sinTheta\_O \cdot sinTheta\_i\right) \cdot cosTheta\_O}{\left(\left(v \cdot v\right) \cdot v\right) \cdot \left(e^{\frac{1}{v}} - e^{-\frac{1}{v}}\right)}\right)\right) \cdot \color{blue}{cosTheta\_i} \]
      8. Taylor expanded in sinTheta_i around 0

        \[\leadsto \frac{cosTheta\_O}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - e^{\mathsf{neg}\left(\frac{1}{v}\right)}\right)} \cdot cosTheta\_i \]
      9. Step-by-step derivation
        1. rec-expN/A

          \[\leadsto \frac{cosTheta\_O}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)} \cdot cosTheta\_i \]
        2. lower-/.f32N/A

          \[\leadsto \frac{cosTheta\_O}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)} \cdot cosTheta\_i \]
        3. rec-expN/A

          \[\leadsto \frac{cosTheta\_O}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - e^{\mathsf{neg}\left(\frac{1}{v}\right)}\right)} \cdot cosTheta\_i \]
        4. lower-*.f32N/A

          \[\leadsto \frac{cosTheta\_O}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - e^{\mathsf{neg}\left(\frac{1}{v}\right)}\right)} \cdot cosTheta\_i \]
        5. pow2N/A

          \[\leadsto \frac{cosTheta\_O}{\left(v \cdot v\right) \cdot \left(e^{\frac{1}{v}} - e^{\mathsf{neg}\left(\frac{1}{v}\right)}\right)} \cdot cosTheta\_i \]
        6. lift-*.f32N/A

          \[\leadsto \frac{cosTheta\_O}{\left(v \cdot v\right) \cdot \left(e^{\frac{1}{v}} - e^{\mathsf{neg}\left(\frac{1}{v}\right)}\right)} \cdot cosTheta\_i \]
        7. sinh-undef-revN/A

          \[\leadsto \frac{cosTheta\_O}{\left(v \cdot v\right) \cdot \left(2 \cdot \sinh \left(\frac{1}{v}\right)\right)} \cdot cosTheta\_i \]
        8. lift-sinh.f32N/A

          \[\leadsto \frac{cosTheta\_O}{\left(v \cdot v\right) \cdot \left(2 \cdot \sinh \left(\frac{1}{v}\right)\right)} \cdot cosTheta\_i \]
        9. lift-/.f32N/A

          \[\leadsto \frac{cosTheta\_O}{\left(v \cdot v\right) \cdot \left(2 \cdot \sinh \left(\frac{1}{v}\right)\right)} \cdot cosTheta\_i \]
        10. lift-*.f3298.4

          \[\leadsto \frac{cosTheta\_O}{\left(v \cdot v\right) \cdot \left(2 \cdot \sinh \left(\frac{1}{v}\right)\right)} \cdot cosTheta\_i \]
      10. Applied rewrites98.4%

        \[\leadsto \frac{cosTheta\_O}{\left(v \cdot v\right) \cdot \left(2 \cdot \sinh \left(\frac{1}{v}\right)\right)} \cdot cosTheta\_i \]
      11. Taylor expanded in v around inf

        \[\leadsto \frac{cosTheta\_O}{\left(v \cdot v\right) \cdot \left(2 \cdot \frac{1 + \frac{1}{6} \cdot \frac{1}{{v}^{2}}}{v}\right)} \cdot cosTheta\_i \]
      12. Step-by-step derivation
        1. lower-/.f32N/A

          \[\leadsto \frac{cosTheta\_O}{\left(v \cdot v\right) \cdot \left(2 \cdot \frac{1 + \frac{1}{6} \cdot \frac{1}{{v}^{2}}}{v}\right)} \cdot cosTheta\_i \]
        2. lower-+.f32N/A

          \[\leadsto \frac{cosTheta\_O}{\left(v \cdot v\right) \cdot \left(2 \cdot \frac{1 + \frac{1}{6} \cdot \frac{1}{{v}^{2}}}{v}\right)} \cdot cosTheta\_i \]
        3. mult-flip-revN/A

          \[\leadsto \frac{cosTheta\_O}{\left(v \cdot v\right) \cdot \left(2 \cdot \frac{1 + \frac{\frac{1}{6}}{{v}^{2}}}{v}\right)} \cdot cosTheta\_i \]
        4. lower-/.f32N/A

          \[\leadsto \frac{cosTheta\_O}{\left(v \cdot v\right) \cdot \left(2 \cdot \frac{1 + \frac{\frac{1}{6}}{{v}^{2}}}{v}\right)} \cdot cosTheta\_i \]
        5. pow2N/A

          \[\leadsto \frac{cosTheta\_O}{\left(v \cdot v\right) \cdot \left(2 \cdot \frac{1 + \frac{\frac{1}{6}}{v \cdot v}}{v}\right)} \cdot cosTheta\_i \]
        6. lift-*.f3264.8

          \[\leadsto \frac{cosTheta\_O}{\left(v \cdot v\right) \cdot \left(2 \cdot \frac{1 + \frac{0.16666666666666666}{v \cdot v}}{v}\right)} \cdot cosTheta\_i \]
      13. Applied rewrites64.8%

        \[\leadsto \frac{cosTheta\_O}{\left(v \cdot v\right) \cdot \left(2 \cdot \frac{1 + \frac{0.16666666666666666}{v \cdot v}}{v}\right)} \cdot cosTheta\_i \]
      14. Add Preprocessing

      Alternative 11: 64.8% accurate, 2.4× speedup?

      \[\begin{array}{l} cosTheta_i\_m = \left|cosTheta\_i\right| \\ cosTheta_i\_s = \mathsf{copysign}\left(1, cosTheta\_i\right) \\ cosTheta_O\_m = \left|cosTheta\_O\right| \\ cosTheta_O\_s = \mathsf{copysign}\left(1, cosTheta\_O\right) \\ [cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v] = \mathsf{sort}([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])\\ \\ cosTheta\_O\_s \cdot \left(cosTheta\_i\_s \cdot \frac{1 \cdot \left(cosTheta\_i\_m \cdot \frac{cosTheta\_O\_m}{v}\right)}{2 + \frac{0.3333333333333333}{v \cdot v}}\right) \end{array} \]
      cosTheta_i\_m = (fabs.f32 cosTheta_i)
      cosTheta_i\_s = (copysign.f32 #s(literal 1 binary32) cosTheta_i)
      cosTheta_O\_m = (fabs.f32 cosTheta_O)
      cosTheta_O\_s = (copysign.f32 #s(literal 1 binary32) cosTheta_O)
      NOTE: cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, and v should be sorted in increasing order before calling this function.
      (FPCore (cosTheta_O_s cosTheta_i_s cosTheta_i_m cosTheta_O_m sinTheta_i sinTheta_O v)
       :precision binary32
       (*
        cosTheta_O_s
        (*
         cosTheta_i_s
         (/
          (* 1.0 (* cosTheta_i_m (/ cosTheta_O_m v)))
          (+ 2.0 (/ 0.3333333333333333 (* v v)))))))
      cosTheta_i\_m = fabs(cosTheta_i);
      cosTheta_i\_s = copysign(1.0, cosTheta_i);
      cosTheta_O\_m = fabs(cosTheta_O);
      cosTheta_O\_s = copysign(1.0, cosTheta_O);
      assert(cosTheta_i_m < cosTheta_O_m && cosTheta_O_m < sinTheta_i && sinTheta_i < sinTheta_O && sinTheta_O < v);
      float code(float cosTheta_O_s, float cosTheta_i_s, float cosTheta_i_m, float cosTheta_O_m, float sinTheta_i, float sinTheta_O, float v) {
      	return cosTheta_O_s * (cosTheta_i_s * ((1.0f * (cosTheta_i_m * (cosTheta_O_m / v))) / (2.0f + (0.3333333333333333f / (v * v)))));
      }
      
      cosTheta_i\_m =     private
      cosTheta_i\_s =     private
      cosTheta_O\_m =     private
      cosTheta_O\_s =     private
      NOTE: cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, and v should be sorted in increasing order before calling this function.
      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_o_s, costheta_i_s, costheta_i_m, costheta_o_m, sintheta_i, sintheta_o, v)
      use fmin_fmax_functions
          real(4), intent (in) :: costheta_o_s
          real(4), intent (in) :: costheta_i_s
          real(4), intent (in) :: costheta_i_m
          real(4), intent (in) :: costheta_o_m
          real(4), intent (in) :: sintheta_i
          real(4), intent (in) :: sintheta_o
          real(4), intent (in) :: v
          code = costheta_o_s * (costheta_i_s * ((1.0e0 * (costheta_i_m * (costheta_o_m / v))) / (2.0e0 + (0.3333333333333333e0 / (v * v)))))
      end function
      
      cosTheta_i\_m = abs(cosTheta_i)
      cosTheta_i\_s = copysign(1.0, cosTheta_i)
      cosTheta_O\_m = abs(cosTheta_O)
      cosTheta_O\_s = copysign(1.0, cosTheta_O)
      cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v = sort([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])
      function code(cosTheta_O_s, cosTheta_i_s, cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v)
      	return Float32(cosTheta_O_s * Float32(cosTheta_i_s * Float32(Float32(Float32(1.0) * Float32(cosTheta_i_m * Float32(cosTheta_O_m / v))) / Float32(Float32(2.0) + Float32(Float32(0.3333333333333333) / Float32(v * v))))))
      end
      
      cosTheta_i\_m = abs(cosTheta_i);
      cosTheta_i\_s = sign(cosTheta_i) * abs(1.0);
      cosTheta_O\_m = abs(cosTheta_O);
      cosTheta_O\_s = sign(cosTheta_O) * abs(1.0);
      cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v = num2cell(sort([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])){:}
      function tmp = code(cosTheta_O_s, cosTheta_i_s, cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v)
      	tmp = cosTheta_O_s * (cosTheta_i_s * ((single(1.0) * (cosTheta_i_m * (cosTheta_O_m / v))) / (single(2.0) + (single(0.3333333333333333) / (v * v)))));
      end
      
      \begin{array}{l}
      cosTheta_i\_m = \left|cosTheta\_i\right|
      \\
      cosTheta_i\_s = \mathsf{copysign}\left(1, cosTheta\_i\right)
      \\
      cosTheta_O\_m = \left|cosTheta\_O\right|
      \\
      cosTheta_O\_s = \mathsf{copysign}\left(1, cosTheta\_O\right)
      \\
      [cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v] = \mathsf{sort}([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])\\
      \\
      cosTheta\_O\_s \cdot \left(cosTheta\_i\_s \cdot \frac{1 \cdot \left(cosTheta\_i\_m \cdot \frac{cosTheta\_O\_m}{v}\right)}{2 + \frac{0.3333333333333333}{v \cdot v}}\right)
      \end{array}
      
      Derivation
      1. Initial program 98.6%

        \[\frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
      2. Step-by-step derivation
        1. lift-*.f32N/A

          \[\leadsto \frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \frac{\color{blue}{cosTheta\_i \cdot cosTheta\_O}}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
        2. lift-/.f32N/A

          \[\leadsto \frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \color{blue}{\frac{cosTheta\_i \cdot cosTheta\_O}{v}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
        3. associate-/l*N/A

          \[\leadsto \frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \color{blue}{\left(cosTheta\_i \cdot \frac{cosTheta\_O}{v}\right)}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
        4. lower-*.f32N/A

          \[\leadsto \frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \color{blue}{\left(cosTheta\_i \cdot \frac{cosTheta\_O}{v}\right)}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
        5. lower-/.f3298.6

          \[\leadsto \frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \left(cosTheta\_i \cdot \color{blue}{\frac{cosTheta\_O}{v}}\right)}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
      3. Applied rewrites98.6%

        \[\leadsto \frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \color{blue}{\left(cosTheta\_i \cdot \frac{cosTheta\_O}{v}\right)}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
      4. Taylor expanded in sinTheta_i around 0

        \[\leadsto \frac{\color{blue}{1} \cdot \left(cosTheta\_i \cdot \frac{cosTheta\_O}{v}\right)}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
      5. Step-by-step derivation
        1. Applied rewrites98.4%

          \[\leadsto \frac{\color{blue}{1} \cdot \left(cosTheta\_i \cdot \frac{cosTheta\_O}{v}\right)}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
        2. Taylor expanded in v around inf

          \[\leadsto \frac{1 \cdot \left(cosTheta\_i \cdot \frac{cosTheta\_O}{v}\right)}{\color{blue}{2 + \frac{1}{3} \cdot \frac{1}{{v}^{2}}}} \]
        3. Step-by-step derivation
          1. lower-+.f32N/A

            \[\leadsto \frac{1 \cdot \left(cosTheta\_i \cdot \frac{cosTheta\_O}{v}\right)}{2 + \color{blue}{\frac{1}{3} \cdot \frac{1}{{v}^{2}}}} \]
          2. mult-flip-revN/A

            \[\leadsto \frac{1 \cdot \left(cosTheta\_i \cdot \frac{cosTheta\_O}{v}\right)}{2 + \frac{\frac{1}{3}}{\color{blue}{{v}^{2}}}} \]
          3. lower-/.f32N/A

            \[\leadsto \frac{1 \cdot \left(cosTheta\_i \cdot \frac{cosTheta\_O}{v}\right)}{2 + \frac{\frac{1}{3}}{\color{blue}{{v}^{2}}}} \]
          4. pow2N/A

            \[\leadsto \frac{1 \cdot \left(cosTheta\_i \cdot \frac{cosTheta\_O}{v}\right)}{2 + \frac{\frac{1}{3}}{v \cdot \color{blue}{v}}} \]
          5. lift-*.f3264.8

            \[\leadsto \frac{1 \cdot \left(cosTheta\_i \cdot \frac{cosTheta\_O}{v}\right)}{2 + \frac{0.3333333333333333}{v \cdot \color{blue}{v}}} \]
        4. Applied rewrites64.8%

          \[\leadsto \frac{1 \cdot \left(cosTheta\_i \cdot \frac{cosTheta\_O}{v}\right)}{\color{blue}{2 + \frac{0.3333333333333333}{v \cdot v}}} \]
        5. Add Preprocessing

        Alternative 12: 64.8% accurate, 2.8× speedup?

        \[\begin{array}{l} cosTheta_i\_m = \left|cosTheta\_i\right| \\ cosTheta_i\_s = \mathsf{copysign}\left(1, cosTheta\_i\right) \\ cosTheta_O\_m = \left|cosTheta\_O\right| \\ cosTheta_O\_s = \mathsf{copysign}\left(1, cosTheta\_O\right) \\ [cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v] = \mathsf{sort}([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])\\ \\ cosTheta\_O\_s \cdot \left(cosTheta\_i\_s \cdot \frac{cosTheta\_O\_m \cdot cosTheta\_i\_m}{\left(2 + \frac{0.3333333333333333}{v \cdot v}\right) \cdot v}\right) \end{array} \]
        cosTheta_i\_m = (fabs.f32 cosTheta_i)
        cosTheta_i\_s = (copysign.f32 #s(literal 1 binary32) cosTheta_i)
        cosTheta_O\_m = (fabs.f32 cosTheta_O)
        cosTheta_O\_s = (copysign.f32 #s(literal 1 binary32) cosTheta_O)
        NOTE: cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, and v should be sorted in increasing order before calling this function.
        (FPCore (cosTheta_O_s cosTheta_i_s cosTheta_i_m cosTheta_O_m sinTheta_i sinTheta_O v)
         :precision binary32
         (*
          cosTheta_O_s
          (*
           cosTheta_i_s
           (/
            (* cosTheta_O_m cosTheta_i_m)
            (* (+ 2.0 (/ 0.3333333333333333 (* v v))) v)))))
        cosTheta_i\_m = fabs(cosTheta_i);
        cosTheta_i\_s = copysign(1.0, cosTheta_i);
        cosTheta_O\_m = fabs(cosTheta_O);
        cosTheta_O\_s = copysign(1.0, cosTheta_O);
        assert(cosTheta_i_m < cosTheta_O_m && cosTheta_O_m < sinTheta_i && sinTheta_i < sinTheta_O && sinTheta_O < v);
        float code(float cosTheta_O_s, float cosTheta_i_s, float cosTheta_i_m, float cosTheta_O_m, float sinTheta_i, float sinTheta_O, float v) {
        	return cosTheta_O_s * (cosTheta_i_s * ((cosTheta_O_m * cosTheta_i_m) / ((2.0f + (0.3333333333333333f / (v * v))) * v)));
        }
        
        cosTheta_i\_m =     private
        cosTheta_i\_s =     private
        cosTheta_O\_m =     private
        cosTheta_O\_s =     private
        NOTE: cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, and v should be sorted in increasing order before calling this function.
        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_o_s, costheta_i_s, costheta_i_m, costheta_o_m, sintheta_i, sintheta_o, v)
        use fmin_fmax_functions
            real(4), intent (in) :: costheta_o_s
            real(4), intent (in) :: costheta_i_s
            real(4), intent (in) :: costheta_i_m
            real(4), intent (in) :: costheta_o_m
            real(4), intent (in) :: sintheta_i
            real(4), intent (in) :: sintheta_o
            real(4), intent (in) :: v
            code = costheta_o_s * (costheta_i_s * ((costheta_o_m * costheta_i_m) / ((2.0e0 + (0.3333333333333333e0 / (v * v))) * v)))
        end function
        
        cosTheta_i\_m = abs(cosTheta_i)
        cosTheta_i\_s = copysign(1.0, cosTheta_i)
        cosTheta_O\_m = abs(cosTheta_O)
        cosTheta_O\_s = copysign(1.0, cosTheta_O)
        cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v = sort([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])
        function code(cosTheta_O_s, cosTheta_i_s, cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v)
        	return Float32(cosTheta_O_s * Float32(cosTheta_i_s * Float32(Float32(cosTheta_O_m * cosTheta_i_m) / Float32(Float32(Float32(2.0) + Float32(Float32(0.3333333333333333) / Float32(v * v))) * v))))
        end
        
        cosTheta_i\_m = abs(cosTheta_i);
        cosTheta_i\_s = sign(cosTheta_i) * abs(1.0);
        cosTheta_O\_m = abs(cosTheta_O);
        cosTheta_O\_s = sign(cosTheta_O) * abs(1.0);
        cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v = num2cell(sort([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])){:}
        function tmp = code(cosTheta_O_s, cosTheta_i_s, cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v)
        	tmp = cosTheta_O_s * (cosTheta_i_s * ((cosTheta_O_m * cosTheta_i_m) / ((single(2.0) + (single(0.3333333333333333) / (v * v))) * v)));
        end
        
        \begin{array}{l}
        cosTheta_i\_m = \left|cosTheta\_i\right|
        \\
        cosTheta_i\_s = \mathsf{copysign}\left(1, cosTheta\_i\right)
        \\
        cosTheta_O\_m = \left|cosTheta\_O\right|
        \\
        cosTheta_O\_s = \mathsf{copysign}\left(1, cosTheta\_O\right)
        \\
        [cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v] = \mathsf{sort}([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])\\
        \\
        cosTheta\_O\_s \cdot \left(cosTheta\_i\_s \cdot \frac{cosTheta\_O\_m \cdot cosTheta\_i\_m}{\left(2 + \frac{0.3333333333333333}{v \cdot v}\right) \cdot v}\right)
        \end{array}
        
        Derivation
        1. Initial program 98.6%

          \[\frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
        2. Step-by-step derivation
          1. lift-*.f32N/A

            \[\leadsto \frac{\color{blue}{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
          2. lift-exp.f32N/A

            \[\leadsto \frac{\color{blue}{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
          3. lift-neg.f32N/A

            \[\leadsto \frac{e^{\color{blue}{\mathsf{neg}\left(\frac{sinTheta\_i \cdot sinTheta\_O}{v}\right)}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
          4. lift-*.f32N/A

            \[\leadsto \frac{e^{\mathsf{neg}\left(\frac{\color{blue}{sinTheta\_i \cdot sinTheta\_O}}{v}\right)} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
          5. lift-/.f32N/A

            \[\leadsto \frac{e^{\mathsf{neg}\left(\color{blue}{\frac{sinTheta\_i \cdot sinTheta\_O}{v}}\right)} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
          6. lift-*.f32N/A

            \[\leadsto \frac{e^{\mathsf{neg}\left(\frac{sinTheta\_i \cdot sinTheta\_O}{v}\right)} \cdot \frac{\color{blue}{cosTheta\_i \cdot cosTheta\_O}}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
          7. lift-/.f32N/A

            \[\leadsto \frac{e^{\mathsf{neg}\left(\frac{sinTheta\_i \cdot sinTheta\_O}{v}\right)} \cdot \color{blue}{\frac{cosTheta\_i \cdot cosTheta\_O}{v}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
          8. *-commutativeN/A

            \[\leadsto \frac{\color{blue}{\frac{cosTheta\_i \cdot cosTheta\_O}{v} \cdot e^{\mathsf{neg}\left(\frac{sinTheta\_i \cdot sinTheta\_O}{v}\right)}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
          9. *-commutativeN/A

            \[\leadsto \frac{\frac{\color{blue}{cosTheta\_O \cdot cosTheta\_i}}{v} \cdot e^{\mathsf{neg}\left(\frac{sinTheta\_i \cdot sinTheta\_O}{v}\right)}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
          10. division-flipN/A

            \[\leadsto \frac{\color{blue}{\frac{1}{\frac{v}{cosTheta\_O \cdot cosTheta\_i}}} \cdot e^{\mathsf{neg}\left(\frac{sinTheta\_i \cdot sinTheta\_O}{v}\right)}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
          11. exp-negN/A

            \[\leadsto \frac{\frac{1}{\frac{v}{cosTheta\_O \cdot cosTheta\_i}} \cdot \color{blue}{\frac{1}{e^{\frac{sinTheta\_i \cdot sinTheta\_O}{v}}}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
          12. *-commutativeN/A

            \[\leadsto \frac{\frac{1}{\frac{v}{cosTheta\_O \cdot cosTheta\_i}} \cdot \frac{1}{e^{\frac{\color{blue}{sinTheta\_O \cdot sinTheta\_i}}{v}}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
          13. frac-timesN/A

            \[\leadsto \frac{\color{blue}{\frac{1 \cdot 1}{\frac{v}{cosTheta\_O \cdot cosTheta\_i} \cdot e^{\frac{sinTheta\_O \cdot sinTheta\_i}{v}}}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
          14. metadata-evalN/A

            \[\leadsto \frac{\frac{\color{blue}{1}}{\frac{v}{cosTheta\_O \cdot cosTheta\_i} \cdot e^{\frac{sinTheta\_O \cdot sinTheta\_i}{v}}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
          15. lower-/.f32N/A

            \[\leadsto \frac{\color{blue}{\frac{1}{\frac{v}{cosTheta\_O \cdot cosTheta\_i} \cdot e^{\frac{sinTheta\_O \cdot sinTheta\_i}{v}}}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
          16. lower-*.f32N/A

            \[\leadsto \frac{\frac{1}{\color{blue}{\frac{v}{cosTheta\_O \cdot cosTheta\_i} \cdot e^{\frac{sinTheta\_O \cdot sinTheta\_i}{v}}}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
        3. Applied rewrites95.1%

          \[\leadsto \frac{\color{blue}{\frac{1}{\frac{v}{cosTheta\_O \cdot cosTheta\_i} \cdot e^{\frac{sinTheta\_O \cdot sinTheta\_i}{v}}}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
        4. Taylor expanded in sinTheta_i around 0

          \[\leadsto \color{blue}{\frac{cosTheta\_O \cdot cosTheta\_i}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)}} \]
        5. Step-by-step derivation
          1. lower-/.f32N/A

            \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\color{blue}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)}} \]
          2. lift-*.f32N/A

            \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\color{blue}{{v}^{2}} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)} \]
          3. *-commutativeN/A

            \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right) \cdot \color{blue}{{v}^{2}}} \]
          4. lower-*.f32N/A

            \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right) \cdot \color{blue}{{v}^{2}}} \]
          5. lower--.f32N/A

            \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right) \cdot {\color{blue}{v}}^{2}} \]
          6. lower-exp.f32N/A

            \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right) \cdot {v}^{2}} \]
          7. lift-/.f32N/A

            \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right) \cdot {v}^{2}} \]
          8. rec-expN/A

            \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - e^{\mathsf{neg}\left(\frac{1}{v}\right)}\right) \cdot {v}^{2}} \]
          9. lower-exp.f32N/A

            \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - e^{\mathsf{neg}\left(\frac{1}{v}\right)}\right) \cdot {v}^{2}} \]
          10. lower-neg.f32N/A

            \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - e^{-\frac{1}{v}}\right) \cdot {v}^{2}} \]
          11. lift-/.f32N/A

            \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - e^{-\frac{1}{v}}\right) \cdot {v}^{2}} \]
          12. pow2N/A

            \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - e^{-\frac{1}{v}}\right) \cdot \left(v \cdot \color{blue}{v}\right)} \]
          13. lift-*.f3298.3

            \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - e^{-\frac{1}{v}}\right) \cdot \left(v \cdot \color{blue}{v}\right)} \]
        6. Applied rewrites98.3%

          \[\leadsto \color{blue}{\frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - e^{-\frac{1}{v}}\right) \cdot \left(v \cdot v\right)}} \]
        7. Taylor expanded in v around inf

          \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{v \cdot \color{blue}{\left(2 + \frac{1}{3} \cdot \frac{1}{{v}^{2}}\right)}} \]
        8. Step-by-step derivation
          1. pow2N/A

            \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{v \cdot \left(2 + \frac{1}{3} \cdot \frac{1}{{v}^{2}}\right)} \]
          2. *-commutativeN/A

            \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{v \cdot \left(\color{blue}{2} + \frac{1}{3} \cdot \frac{1}{{v}^{2}}\right)} \]
          3. pow2N/A

            \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{v \cdot \left(2 + \frac{1}{3} \cdot \frac{1}{{v}^{2}}\right)} \]
          4. sinh-undef-revN/A

            \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{v \cdot \left(2 + \frac{1}{3} \cdot \frac{1}{{v}^{2}}\right)} \]
          5. *-commutativeN/A

            \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(2 + \frac{1}{3} \cdot \frac{1}{{v}^{2}}\right) \cdot v} \]
          6. lower-*.f32N/A

            \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(2 + \frac{1}{3} \cdot \frac{1}{{v}^{2}}\right) \cdot v} \]
          7. lower-+.f32N/A

            \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(2 + \frac{1}{3} \cdot \frac{1}{{v}^{2}}\right) \cdot v} \]
          8. mult-flip-revN/A

            \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(2 + \frac{\frac{1}{3}}{{v}^{2}}\right) \cdot v} \]
          9. lower-/.f32N/A

            \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(2 + \frac{\frac{1}{3}}{{v}^{2}}\right) \cdot v} \]
          10. pow2N/A

            \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(2 + \frac{\frac{1}{3}}{v \cdot v}\right) \cdot v} \]
          11. lift-*.f3264.8

            \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(2 + \frac{0.3333333333333333}{v \cdot v}\right) \cdot v} \]
        9. Applied rewrites64.8%

          \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(2 + \frac{0.3333333333333333}{v \cdot v}\right) \cdot \color{blue}{v}} \]
        10. Add Preprocessing

        Alternative 13: 59.7% accurate, 3.9× speedup?

        \[\begin{array}{l} cosTheta_i\_m = \left|cosTheta\_i\right| \\ cosTheta_i\_s = \mathsf{copysign}\left(1, cosTheta\_i\right) \\ cosTheta_O\_m = \left|cosTheta\_O\right| \\ cosTheta_O\_s = \mathsf{copysign}\left(1, cosTheta\_O\right) \\ [cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v] = \mathsf{sort}([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])\\ \\ cosTheta\_O\_s \cdot \left(cosTheta\_i\_s \cdot \left(0.5 \cdot \frac{1}{\frac{v}{cosTheta\_O\_m \cdot cosTheta\_i\_m}}\right)\right) \end{array} \]
        cosTheta_i\_m = (fabs.f32 cosTheta_i)
        cosTheta_i\_s = (copysign.f32 #s(literal 1 binary32) cosTheta_i)
        cosTheta_O\_m = (fabs.f32 cosTheta_O)
        cosTheta_O\_s = (copysign.f32 #s(literal 1 binary32) cosTheta_O)
        NOTE: cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, and v should be sorted in increasing order before calling this function.
        (FPCore (cosTheta_O_s cosTheta_i_s cosTheta_i_m cosTheta_O_m sinTheta_i sinTheta_O v)
         :precision binary32
         (*
          cosTheta_O_s
          (* cosTheta_i_s (* 0.5 (/ 1.0 (/ v (* cosTheta_O_m cosTheta_i_m)))))))
        cosTheta_i\_m = fabs(cosTheta_i);
        cosTheta_i\_s = copysign(1.0, cosTheta_i);
        cosTheta_O\_m = fabs(cosTheta_O);
        cosTheta_O\_s = copysign(1.0, cosTheta_O);
        assert(cosTheta_i_m < cosTheta_O_m && cosTheta_O_m < sinTheta_i && sinTheta_i < sinTheta_O && sinTheta_O < v);
        float code(float cosTheta_O_s, float cosTheta_i_s, float cosTheta_i_m, float cosTheta_O_m, float sinTheta_i, float sinTheta_O, float v) {
        	return cosTheta_O_s * (cosTheta_i_s * (0.5f * (1.0f / (v / (cosTheta_O_m * cosTheta_i_m)))));
        }
        
        cosTheta_i\_m =     private
        cosTheta_i\_s =     private
        cosTheta_O\_m =     private
        cosTheta_O\_s =     private
        NOTE: cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, and v should be sorted in increasing order before calling this function.
        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_o_s, costheta_i_s, costheta_i_m, costheta_o_m, sintheta_i, sintheta_o, v)
        use fmin_fmax_functions
            real(4), intent (in) :: costheta_o_s
            real(4), intent (in) :: costheta_i_s
            real(4), intent (in) :: costheta_i_m
            real(4), intent (in) :: costheta_o_m
            real(4), intent (in) :: sintheta_i
            real(4), intent (in) :: sintheta_o
            real(4), intent (in) :: v
            code = costheta_o_s * (costheta_i_s * (0.5e0 * (1.0e0 / (v / (costheta_o_m * costheta_i_m)))))
        end function
        
        cosTheta_i\_m = abs(cosTheta_i)
        cosTheta_i\_s = copysign(1.0, cosTheta_i)
        cosTheta_O\_m = abs(cosTheta_O)
        cosTheta_O\_s = copysign(1.0, cosTheta_O)
        cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v = sort([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])
        function code(cosTheta_O_s, cosTheta_i_s, cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v)
        	return Float32(cosTheta_O_s * Float32(cosTheta_i_s * Float32(Float32(0.5) * Float32(Float32(1.0) / Float32(v / Float32(cosTheta_O_m * cosTheta_i_m))))))
        end
        
        cosTheta_i\_m = abs(cosTheta_i);
        cosTheta_i\_s = sign(cosTheta_i) * abs(1.0);
        cosTheta_O\_m = abs(cosTheta_O);
        cosTheta_O\_s = sign(cosTheta_O) * abs(1.0);
        cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v = num2cell(sort([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])){:}
        function tmp = code(cosTheta_O_s, cosTheta_i_s, cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v)
        	tmp = cosTheta_O_s * (cosTheta_i_s * (single(0.5) * (single(1.0) / (v / (cosTheta_O_m * cosTheta_i_m)))));
        end
        
        \begin{array}{l}
        cosTheta_i\_m = \left|cosTheta\_i\right|
        \\
        cosTheta_i\_s = \mathsf{copysign}\left(1, cosTheta\_i\right)
        \\
        cosTheta_O\_m = \left|cosTheta\_O\right|
        \\
        cosTheta_O\_s = \mathsf{copysign}\left(1, cosTheta\_O\right)
        \\
        [cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v] = \mathsf{sort}([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])\\
        \\
        cosTheta\_O\_s \cdot \left(cosTheta\_i\_s \cdot \left(0.5 \cdot \frac{1}{\frac{v}{cosTheta\_O\_m \cdot cosTheta\_i\_m}}\right)\right)
        \end{array}
        
        Derivation
        1. Initial program 98.6%

          \[\frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
        2. Taylor expanded in v around inf

          \[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{cosTheta\_O \cdot cosTheta\_i}{v}} \]
        3. Step-by-step derivation
          1. lower-*.f32N/A

            \[\leadsto \frac{1}{2} \cdot \color{blue}{\frac{cosTheta\_O \cdot cosTheta\_i}{v}} \]
          2. lower-/.f32N/A

            \[\leadsto \frac{1}{2} \cdot \frac{cosTheta\_O \cdot cosTheta\_i}{\color{blue}{v}} \]
          3. lower-*.f3259.2

            \[\leadsto 0.5 \cdot \frac{cosTheta\_O \cdot cosTheta\_i}{v} \]
        4. Applied rewrites59.2%

          \[\leadsto \color{blue}{0.5 \cdot \frac{cosTheta\_O \cdot cosTheta\_i}{v}} \]
        5. Step-by-step derivation
          1. lift-*.f32N/A

            \[\leadsto \frac{1}{2} \cdot \frac{cosTheta\_O \cdot cosTheta\_i}{v} \]
          2. lift-/.f32N/A

            \[\leadsto \frac{1}{2} \cdot \frac{cosTheta\_O \cdot cosTheta\_i}{\color{blue}{v}} \]
          3. division-flipN/A

            \[\leadsto \frac{1}{2} \cdot \frac{1}{\color{blue}{\frac{v}{cosTheta\_O \cdot cosTheta\_i}}} \]
          4. lower-/.f32N/A

            \[\leadsto \frac{1}{2} \cdot \frac{1}{\color{blue}{\frac{v}{cosTheta\_O \cdot cosTheta\_i}}} \]
          5. lift-/.f32N/A

            \[\leadsto \frac{1}{2} \cdot \frac{1}{\frac{v}{\color{blue}{cosTheta\_O \cdot cosTheta\_i}}} \]
          6. lift-*.f3259.7

            \[\leadsto 0.5 \cdot \frac{1}{\frac{v}{cosTheta\_O \cdot \color{blue}{cosTheta\_i}}} \]
        6. Applied rewrites59.7%

          \[\leadsto 0.5 \cdot \frac{1}{\color{blue}{\frac{v}{cosTheta\_O \cdot cosTheta\_i}}} \]
        7. Add Preprocessing

        Alternative 14: 59.2% accurate, 5.2× speedup?

        \[\begin{array}{l} cosTheta_i\_m = \left|cosTheta\_i\right| \\ cosTheta_i\_s = \mathsf{copysign}\left(1, cosTheta\_i\right) \\ cosTheta_O\_m = \left|cosTheta\_O\right| \\ cosTheta_O\_s = \mathsf{copysign}\left(1, cosTheta\_O\right) \\ [cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v] = \mathsf{sort}([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])\\ \\ cosTheta\_O\_s \cdot \left(cosTheta\_i\_s \cdot \frac{\left(cosTheta\_O\_m \cdot cosTheta\_i\_m\right) \cdot 0.5}{v}\right) \end{array} \]
        cosTheta_i\_m = (fabs.f32 cosTheta_i)
        cosTheta_i\_s = (copysign.f32 #s(literal 1 binary32) cosTheta_i)
        cosTheta_O\_m = (fabs.f32 cosTheta_O)
        cosTheta_O\_s = (copysign.f32 #s(literal 1 binary32) cosTheta_O)
        NOTE: cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, and v should be sorted in increasing order before calling this function.
        (FPCore (cosTheta_O_s cosTheta_i_s cosTheta_i_m cosTheta_O_m sinTheta_i sinTheta_O v)
         :precision binary32
         (* cosTheta_O_s (* cosTheta_i_s (/ (* (* cosTheta_O_m cosTheta_i_m) 0.5) v))))
        cosTheta_i\_m = fabs(cosTheta_i);
        cosTheta_i\_s = copysign(1.0, cosTheta_i);
        cosTheta_O\_m = fabs(cosTheta_O);
        cosTheta_O\_s = copysign(1.0, cosTheta_O);
        assert(cosTheta_i_m < cosTheta_O_m && cosTheta_O_m < sinTheta_i && sinTheta_i < sinTheta_O && sinTheta_O < v);
        float code(float cosTheta_O_s, float cosTheta_i_s, float cosTheta_i_m, float cosTheta_O_m, float sinTheta_i, float sinTheta_O, float v) {
        	return cosTheta_O_s * (cosTheta_i_s * (((cosTheta_O_m * cosTheta_i_m) * 0.5f) / v));
        }
        
        cosTheta_i\_m =     private
        cosTheta_i\_s =     private
        cosTheta_O\_m =     private
        cosTheta_O\_s =     private
        NOTE: cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, and v should be sorted in increasing order before calling this function.
        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_o_s, costheta_i_s, costheta_i_m, costheta_o_m, sintheta_i, sintheta_o, v)
        use fmin_fmax_functions
            real(4), intent (in) :: costheta_o_s
            real(4), intent (in) :: costheta_i_s
            real(4), intent (in) :: costheta_i_m
            real(4), intent (in) :: costheta_o_m
            real(4), intent (in) :: sintheta_i
            real(4), intent (in) :: sintheta_o
            real(4), intent (in) :: v
            code = costheta_o_s * (costheta_i_s * (((costheta_o_m * costheta_i_m) * 0.5e0) / v))
        end function
        
        cosTheta_i\_m = abs(cosTheta_i)
        cosTheta_i\_s = copysign(1.0, cosTheta_i)
        cosTheta_O\_m = abs(cosTheta_O)
        cosTheta_O\_s = copysign(1.0, cosTheta_O)
        cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v = sort([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])
        function code(cosTheta_O_s, cosTheta_i_s, cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v)
        	return Float32(cosTheta_O_s * Float32(cosTheta_i_s * Float32(Float32(Float32(cosTheta_O_m * cosTheta_i_m) * Float32(0.5)) / v)))
        end
        
        cosTheta_i\_m = abs(cosTheta_i);
        cosTheta_i\_s = sign(cosTheta_i) * abs(1.0);
        cosTheta_O\_m = abs(cosTheta_O);
        cosTheta_O\_s = sign(cosTheta_O) * abs(1.0);
        cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v = num2cell(sort([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])){:}
        function tmp = code(cosTheta_O_s, cosTheta_i_s, cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v)
        	tmp = cosTheta_O_s * (cosTheta_i_s * (((cosTheta_O_m * cosTheta_i_m) * single(0.5)) / v));
        end
        
        \begin{array}{l}
        cosTheta_i\_m = \left|cosTheta\_i\right|
        \\
        cosTheta_i\_s = \mathsf{copysign}\left(1, cosTheta\_i\right)
        \\
        cosTheta_O\_m = \left|cosTheta\_O\right|
        \\
        cosTheta_O\_s = \mathsf{copysign}\left(1, cosTheta\_O\right)
        \\
        [cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v] = \mathsf{sort}([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])\\
        \\
        cosTheta\_O\_s \cdot \left(cosTheta\_i\_s \cdot \frac{\left(cosTheta\_O\_m \cdot cosTheta\_i\_m\right) \cdot 0.5}{v}\right)
        \end{array}
        
        Derivation
        1. Initial program 98.6%

          \[\frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
        2. Taylor expanded in v around inf

          \[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{cosTheta\_O \cdot cosTheta\_i}{v}} \]
        3. Step-by-step derivation
          1. lower-*.f32N/A

            \[\leadsto \frac{1}{2} \cdot \color{blue}{\frac{cosTheta\_O \cdot cosTheta\_i}{v}} \]
          2. lower-/.f32N/A

            \[\leadsto \frac{1}{2} \cdot \frac{cosTheta\_O \cdot cosTheta\_i}{\color{blue}{v}} \]
          3. lower-*.f3259.2

            \[\leadsto 0.5 \cdot \frac{cosTheta\_O \cdot cosTheta\_i}{v} \]
        4. Applied rewrites59.2%

          \[\leadsto \color{blue}{0.5 \cdot \frac{cosTheta\_O \cdot cosTheta\_i}{v}} \]
        5. Step-by-step derivation
          1. lift-*.f32N/A

            \[\leadsto \frac{1}{2} \cdot \color{blue}{\frac{cosTheta\_O \cdot cosTheta\_i}{v}} \]
          2. lift-*.f32N/A

            \[\leadsto \frac{1}{2} \cdot \frac{cosTheta\_O \cdot cosTheta\_i}{v} \]
          3. lift-/.f32N/A

            \[\leadsto \frac{1}{2} \cdot \frac{cosTheta\_O \cdot cosTheta\_i}{\color{blue}{v}} \]
          4. associate-*r/N/A

            \[\leadsto \frac{\frac{1}{2} \cdot \left(cosTheta\_O \cdot cosTheta\_i\right)}{\color{blue}{v}} \]
          5. lower-/.f32N/A

            \[\leadsto \frac{\frac{1}{2} \cdot \left(cosTheta\_O \cdot cosTheta\_i\right)}{\color{blue}{v}} \]
          6. *-commutativeN/A

            \[\leadsto \frac{\left(cosTheta\_O \cdot cosTheta\_i\right) \cdot \frac{1}{2}}{v} \]
          7. lower-*.f32N/A

            \[\leadsto \frac{\left(cosTheta\_O \cdot cosTheta\_i\right) \cdot \frac{1}{2}}{v} \]
          8. lift-*.f3259.2

            \[\leadsto \frac{\left(cosTheta\_O \cdot cosTheta\_i\right) \cdot 0.5}{v} \]
        6. Applied rewrites59.2%

          \[\leadsto \frac{\left(cosTheta\_O \cdot cosTheta\_i\right) \cdot 0.5}{\color{blue}{v}} \]
        7. Add Preprocessing

        Alternative 15: 59.2% accurate, 5.2× speedup?

        \[\begin{array}{l} cosTheta_i\_m = \left|cosTheta\_i\right| \\ cosTheta_i\_s = \mathsf{copysign}\left(1, cosTheta\_i\right) \\ cosTheta_O\_m = \left|cosTheta\_O\right| \\ cosTheta_O\_s = \mathsf{copysign}\left(1, cosTheta\_O\right) \\ [cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v] = \mathsf{sort}([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])\\ \\ cosTheta\_O\_s \cdot \left(cosTheta\_i\_s \cdot \left(0.5 \cdot \left(\frac{cosTheta\_O\_m}{v} \cdot cosTheta\_i\_m\right)\right)\right) \end{array} \]
        cosTheta_i\_m = (fabs.f32 cosTheta_i)
        cosTheta_i\_s = (copysign.f32 #s(literal 1 binary32) cosTheta_i)
        cosTheta_O\_m = (fabs.f32 cosTheta_O)
        cosTheta_O\_s = (copysign.f32 #s(literal 1 binary32) cosTheta_O)
        NOTE: cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, and v should be sorted in increasing order before calling this function.
        (FPCore (cosTheta_O_s cosTheta_i_s cosTheta_i_m cosTheta_O_m sinTheta_i sinTheta_O v)
         :precision binary32
         (* cosTheta_O_s (* cosTheta_i_s (* 0.5 (* (/ cosTheta_O_m v) cosTheta_i_m)))))
        cosTheta_i\_m = fabs(cosTheta_i);
        cosTheta_i\_s = copysign(1.0, cosTheta_i);
        cosTheta_O\_m = fabs(cosTheta_O);
        cosTheta_O\_s = copysign(1.0, cosTheta_O);
        assert(cosTheta_i_m < cosTheta_O_m && cosTheta_O_m < sinTheta_i && sinTheta_i < sinTheta_O && sinTheta_O < v);
        float code(float cosTheta_O_s, float cosTheta_i_s, float cosTheta_i_m, float cosTheta_O_m, float sinTheta_i, float sinTheta_O, float v) {
        	return cosTheta_O_s * (cosTheta_i_s * (0.5f * ((cosTheta_O_m / v) * cosTheta_i_m)));
        }
        
        cosTheta_i\_m =     private
        cosTheta_i\_s =     private
        cosTheta_O\_m =     private
        cosTheta_O\_s =     private
        NOTE: cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, and v should be sorted in increasing order before calling this function.
        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_o_s, costheta_i_s, costheta_i_m, costheta_o_m, sintheta_i, sintheta_o, v)
        use fmin_fmax_functions
            real(4), intent (in) :: costheta_o_s
            real(4), intent (in) :: costheta_i_s
            real(4), intent (in) :: costheta_i_m
            real(4), intent (in) :: costheta_o_m
            real(4), intent (in) :: sintheta_i
            real(4), intent (in) :: sintheta_o
            real(4), intent (in) :: v
            code = costheta_o_s * (costheta_i_s * (0.5e0 * ((costheta_o_m / v) * costheta_i_m)))
        end function
        
        cosTheta_i\_m = abs(cosTheta_i)
        cosTheta_i\_s = copysign(1.0, cosTheta_i)
        cosTheta_O\_m = abs(cosTheta_O)
        cosTheta_O\_s = copysign(1.0, cosTheta_O)
        cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v = sort([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])
        function code(cosTheta_O_s, cosTheta_i_s, cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v)
        	return Float32(cosTheta_O_s * Float32(cosTheta_i_s * Float32(Float32(0.5) * Float32(Float32(cosTheta_O_m / v) * cosTheta_i_m))))
        end
        
        cosTheta_i\_m = abs(cosTheta_i);
        cosTheta_i\_s = sign(cosTheta_i) * abs(1.0);
        cosTheta_O\_m = abs(cosTheta_O);
        cosTheta_O\_s = sign(cosTheta_O) * abs(1.0);
        cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v = num2cell(sort([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])){:}
        function tmp = code(cosTheta_O_s, cosTheta_i_s, cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v)
        	tmp = cosTheta_O_s * (cosTheta_i_s * (single(0.5) * ((cosTheta_O_m / v) * cosTheta_i_m)));
        end
        
        \begin{array}{l}
        cosTheta_i\_m = \left|cosTheta\_i\right|
        \\
        cosTheta_i\_s = \mathsf{copysign}\left(1, cosTheta\_i\right)
        \\
        cosTheta_O\_m = \left|cosTheta\_O\right|
        \\
        cosTheta_O\_s = \mathsf{copysign}\left(1, cosTheta\_O\right)
        \\
        [cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v] = \mathsf{sort}([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])\\
        \\
        cosTheta\_O\_s \cdot \left(cosTheta\_i\_s \cdot \left(0.5 \cdot \left(\frac{cosTheta\_O\_m}{v} \cdot cosTheta\_i\_m\right)\right)\right)
        \end{array}
        
        Derivation
        1. Initial program 98.6%

          \[\frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
        2. Taylor expanded in v around inf

          \[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{cosTheta\_O \cdot cosTheta\_i}{v}} \]
        3. Step-by-step derivation
          1. lower-*.f32N/A

            \[\leadsto \frac{1}{2} \cdot \color{blue}{\frac{cosTheta\_O \cdot cosTheta\_i}{v}} \]
          2. lower-/.f32N/A

            \[\leadsto \frac{1}{2} \cdot \frac{cosTheta\_O \cdot cosTheta\_i}{\color{blue}{v}} \]
          3. lower-*.f3259.2

            \[\leadsto 0.5 \cdot \frac{cosTheta\_O \cdot cosTheta\_i}{v} \]
        4. Applied rewrites59.2%

          \[\leadsto \color{blue}{0.5 \cdot \frac{cosTheta\_O \cdot cosTheta\_i}{v}} \]
        5. Step-by-step derivation
          1. lift-*.f32N/A

            \[\leadsto \frac{1}{2} \cdot \frac{cosTheta\_O \cdot cosTheta\_i}{v} \]
          2. *-commutativeN/A

            \[\leadsto \frac{1}{2} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v} \]
          3. lift-/.f32N/A

            \[\leadsto \frac{1}{2} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{\color{blue}{v}} \]
          4. associate-/l*N/A

            \[\leadsto \frac{1}{2} \cdot \left(cosTheta\_i \cdot \color{blue}{\frac{cosTheta\_O}{v}}\right) \]
          5. *-commutativeN/A

            \[\leadsto \frac{1}{2} \cdot \left(\frac{cosTheta\_O}{v} \cdot \color{blue}{cosTheta\_i}\right) \]
          6. lower-*.f32N/A

            \[\leadsto \frac{1}{2} \cdot \left(\frac{cosTheta\_O}{v} \cdot \color{blue}{cosTheta\_i}\right) \]
          7. lift-/.f3259.2

            \[\leadsto 0.5 \cdot \left(\frac{cosTheta\_O}{v} \cdot cosTheta\_i\right) \]
        6. Applied rewrites59.2%

          \[\leadsto 0.5 \cdot \left(\frac{cosTheta\_O}{v} \cdot \color{blue}{cosTheta\_i}\right) \]
        7. Add Preprocessing

        Alternative 16: 59.2% accurate, 5.2× speedup?

        \[\begin{array}{l} cosTheta_i\_m = \left|cosTheta\_i\right| \\ cosTheta_i\_s = \mathsf{copysign}\left(1, cosTheta\_i\right) \\ cosTheta_O\_m = \left|cosTheta\_O\right| \\ cosTheta_O\_s = \mathsf{copysign}\left(1, cosTheta\_O\right) \\ [cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v] = \mathsf{sort}([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])\\ \\ cosTheta\_O\_s \cdot \left(cosTheta\_i\_s \cdot \left(0.5 \cdot \left(cosTheta\_O\_m \cdot \frac{cosTheta\_i\_m}{v}\right)\right)\right) \end{array} \]
        cosTheta_i\_m = (fabs.f32 cosTheta_i)
        cosTheta_i\_s = (copysign.f32 #s(literal 1 binary32) cosTheta_i)
        cosTheta_O\_m = (fabs.f32 cosTheta_O)
        cosTheta_O\_s = (copysign.f32 #s(literal 1 binary32) cosTheta_O)
        NOTE: cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, and v should be sorted in increasing order before calling this function.
        (FPCore (cosTheta_O_s cosTheta_i_s cosTheta_i_m cosTheta_O_m sinTheta_i sinTheta_O v)
         :precision binary32
         (* cosTheta_O_s (* cosTheta_i_s (* 0.5 (* cosTheta_O_m (/ cosTheta_i_m v))))))
        cosTheta_i\_m = fabs(cosTheta_i);
        cosTheta_i\_s = copysign(1.0, cosTheta_i);
        cosTheta_O\_m = fabs(cosTheta_O);
        cosTheta_O\_s = copysign(1.0, cosTheta_O);
        assert(cosTheta_i_m < cosTheta_O_m && cosTheta_O_m < sinTheta_i && sinTheta_i < sinTheta_O && sinTheta_O < v);
        float code(float cosTheta_O_s, float cosTheta_i_s, float cosTheta_i_m, float cosTheta_O_m, float sinTheta_i, float sinTheta_O, float v) {
        	return cosTheta_O_s * (cosTheta_i_s * (0.5f * (cosTheta_O_m * (cosTheta_i_m / v))));
        }
        
        cosTheta_i\_m =     private
        cosTheta_i\_s =     private
        cosTheta_O\_m =     private
        cosTheta_O\_s =     private
        NOTE: cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, and v should be sorted in increasing order before calling this function.
        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_o_s, costheta_i_s, costheta_i_m, costheta_o_m, sintheta_i, sintheta_o, v)
        use fmin_fmax_functions
            real(4), intent (in) :: costheta_o_s
            real(4), intent (in) :: costheta_i_s
            real(4), intent (in) :: costheta_i_m
            real(4), intent (in) :: costheta_o_m
            real(4), intent (in) :: sintheta_i
            real(4), intent (in) :: sintheta_o
            real(4), intent (in) :: v
            code = costheta_o_s * (costheta_i_s * (0.5e0 * (costheta_o_m * (costheta_i_m / v))))
        end function
        
        cosTheta_i\_m = abs(cosTheta_i)
        cosTheta_i\_s = copysign(1.0, cosTheta_i)
        cosTheta_O\_m = abs(cosTheta_O)
        cosTheta_O\_s = copysign(1.0, cosTheta_O)
        cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v = sort([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])
        function code(cosTheta_O_s, cosTheta_i_s, cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v)
        	return Float32(cosTheta_O_s * Float32(cosTheta_i_s * Float32(Float32(0.5) * Float32(cosTheta_O_m * Float32(cosTheta_i_m / v)))))
        end
        
        cosTheta_i\_m = abs(cosTheta_i);
        cosTheta_i\_s = sign(cosTheta_i) * abs(1.0);
        cosTheta_O\_m = abs(cosTheta_O);
        cosTheta_O\_s = sign(cosTheta_O) * abs(1.0);
        cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v = num2cell(sort([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])){:}
        function tmp = code(cosTheta_O_s, cosTheta_i_s, cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v)
        	tmp = cosTheta_O_s * (cosTheta_i_s * (single(0.5) * (cosTheta_O_m * (cosTheta_i_m / v))));
        end
        
        \begin{array}{l}
        cosTheta_i\_m = \left|cosTheta\_i\right|
        \\
        cosTheta_i\_s = \mathsf{copysign}\left(1, cosTheta\_i\right)
        \\
        cosTheta_O\_m = \left|cosTheta\_O\right|
        \\
        cosTheta_O\_s = \mathsf{copysign}\left(1, cosTheta\_O\right)
        \\
        [cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v] = \mathsf{sort}([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])\\
        \\
        cosTheta\_O\_s \cdot \left(cosTheta\_i\_s \cdot \left(0.5 \cdot \left(cosTheta\_O\_m \cdot \frac{cosTheta\_i\_m}{v}\right)\right)\right)
        \end{array}
        
        Derivation
        1. Initial program 98.6%

          \[\frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
        2. Taylor expanded in v around inf

          \[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{cosTheta\_O \cdot cosTheta\_i}{v}} \]
        3. Step-by-step derivation
          1. lower-*.f32N/A

            \[\leadsto \frac{1}{2} \cdot \color{blue}{\frac{cosTheta\_O \cdot cosTheta\_i}{v}} \]
          2. lower-/.f32N/A

            \[\leadsto \frac{1}{2} \cdot \frac{cosTheta\_O \cdot cosTheta\_i}{\color{blue}{v}} \]
          3. lower-*.f3259.2

            \[\leadsto 0.5 \cdot \frac{cosTheta\_O \cdot cosTheta\_i}{v} \]
        4. Applied rewrites59.2%

          \[\leadsto \color{blue}{0.5 \cdot \frac{cosTheta\_O \cdot cosTheta\_i}{v}} \]
        5. Step-by-step derivation
          1. lift-*.f32N/A

            \[\leadsto \frac{1}{2} \cdot \frac{cosTheta\_O \cdot cosTheta\_i}{v} \]
          2. lift-/.f32N/A

            \[\leadsto \frac{1}{2} \cdot \frac{cosTheta\_O \cdot cosTheta\_i}{\color{blue}{v}} \]
          3. associate-/l*N/A

            \[\leadsto \frac{1}{2} \cdot \left(cosTheta\_O \cdot \color{blue}{\frac{cosTheta\_i}{v}}\right) \]
          4. lower-*.f32N/A

            \[\leadsto \frac{1}{2} \cdot \left(cosTheta\_O \cdot \color{blue}{\frac{cosTheta\_i}{v}}\right) \]
          5. lower-/.f3259.2

            \[\leadsto 0.5 \cdot \left(cosTheta\_O \cdot \frac{cosTheta\_i}{\color{blue}{v}}\right) \]
        6. Applied rewrites59.2%

          \[\leadsto 0.5 \cdot \left(cosTheta\_O \cdot \color{blue}{\frac{cosTheta\_i}{v}}\right) \]
        7. Add Preprocessing

        Alternative 17: 59.2% accurate, 5.2× speedup?

        \[\begin{array}{l} cosTheta_i\_m = \left|cosTheta\_i\right| \\ cosTheta_i\_s = \mathsf{copysign}\left(1, cosTheta\_i\right) \\ cosTheta_O\_m = \left|cosTheta\_O\right| \\ cosTheta_O\_s = \mathsf{copysign}\left(1, cosTheta\_O\right) \\ [cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v] = \mathsf{sort}([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])\\ \\ cosTheta\_O\_s \cdot \left(cosTheta\_i\_s \cdot \left(\left(0.5 \cdot \frac{cosTheta\_O\_m}{v}\right) \cdot cosTheta\_i\_m\right)\right) \end{array} \]
        cosTheta_i\_m = (fabs.f32 cosTheta_i)
        cosTheta_i\_s = (copysign.f32 #s(literal 1 binary32) cosTheta_i)
        cosTheta_O\_m = (fabs.f32 cosTheta_O)
        cosTheta_O\_s = (copysign.f32 #s(literal 1 binary32) cosTheta_O)
        NOTE: cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, and v should be sorted in increasing order before calling this function.
        (FPCore (cosTheta_O_s cosTheta_i_s cosTheta_i_m cosTheta_O_m sinTheta_i sinTheta_O v)
         :precision binary32
         (* cosTheta_O_s (* cosTheta_i_s (* (* 0.5 (/ cosTheta_O_m v)) cosTheta_i_m))))
        cosTheta_i\_m = fabs(cosTheta_i);
        cosTheta_i\_s = copysign(1.0, cosTheta_i);
        cosTheta_O\_m = fabs(cosTheta_O);
        cosTheta_O\_s = copysign(1.0, cosTheta_O);
        assert(cosTheta_i_m < cosTheta_O_m && cosTheta_O_m < sinTheta_i && sinTheta_i < sinTheta_O && sinTheta_O < v);
        float code(float cosTheta_O_s, float cosTheta_i_s, float cosTheta_i_m, float cosTheta_O_m, float sinTheta_i, float sinTheta_O, float v) {
        	return cosTheta_O_s * (cosTheta_i_s * ((0.5f * (cosTheta_O_m / v)) * cosTheta_i_m));
        }
        
        cosTheta_i\_m =     private
        cosTheta_i\_s =     private
        cosTheta_O\_m =     private
        cosTheta_O\_s =     private
        NOTE: cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, and v should be sorted in increasing order before calling this function.
        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_o_s, costheta_i_s, costheta_i_m, costheta_o_m, sintheta_i, sintheta_o, v)
        use fmin_fmax_functions
            real(4), intent (in) :: costheta_o_s
            real(4), intent (in) :: costheta_i_s
            real(4), intent (in) :: costheta_i_m
            real(4), intent (in) :: costheta_o_m
            real(4), intent (in) :: sintheta_i
            real(4), intent (in) :: sintheta_o
            real(4), intent (in) :: v
            code = costheta_o_s * (costheta_i_s * ((0.5e0 * (costheta_o_m / v)) * costheta_i_m))
        end function
        
        cosTheta_i\_m = abs(cosTheta_i)
        cosTheta_i\_s = copysign(1.0, cosTheta_i)
        cosTheta_O\_m = abs(cosTheta_O)
        cosTheta_O\_s = copysign(1.0, cosTheta_O)
        cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v = sort([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])
        function code(cosTheta_O_s, cosTheta_i_s, cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v)
        	return Float32(cosTheta_O_s * Float32(cosTheta_i_s * Float32(Float32(Float32(0.5) * Float32(cosTheta_O_m / v)) * cosTheta_i_m)))
        end
        
        cosTheta_i\_m = abs(cosTheta_i);
        cosTheta_i\_s = sign(cosTheta_i) * abs(1.0);
        cosTheta_O\_m = abs(cosTheta_O);
        cosTheta_O\_s = sign(cosTheta_O) * abs(1.0);
        cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v = num2cell(sort([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])){:}
        function tmp = code(cosTheta_O_s, cosTheta_i_s, cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v)
        	tmp = cosTheta_O_s * (cosTheta_i_s * ((single(0.5) * (cosTheta_O_m / v)) * cosTheta_i_m));
        end
        
        \begin{array}{l}
        cosTheta_i\_m = \left|cosTheta\_i\right|
        \\
        cosTheta_i\_s = \mathsf{copysign}\left(1, cosTheta\_i\right)
        \\
        cosTheta_O\_m = \left|cosTheta\_O\right|
        \\
        cosTheta_O\_s = \mathsf{copysign}\left(1, cosTheta\_O\right)
        \\
        [cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v] = \mathsf{sort}([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])\\
        \\
        cosTheta\_O\_s \cdot \left(cosTheta\_i\_s \cdot \left(\left(0.5 \cdot \frac{cosTheta\_O\_m}{v}\right) \cdot cosTheta\_i\_m\right)\right)
        \end{array}
        
        Derivation
        1. Initial program 98.6%

          \[\frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
        2. Taylor expanded in sinTheta_i around 0

          \[\leadsto \color{blue}{-1 \cdot \frac{cosTheta\_O \cdot \left(cosTheta\_i \cdot \left(sinTheta\_O \cdot sinTheta\_i\right)\right)}{{v}^{3} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)} + \frac{cosTheta\_O \cdot cosTheta\_i}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)}} \]
        3. Step-by-step derivation
          1. +-commutativeN/A

            \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)} + \color{blue}{-1 \cdot \frac{cosTheta\_O \cdot \left(cosTheta\_i \cdot \left(sinTheta\_O \cdot sinTheta\_i\right)\right)}{{v}^{3} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)}} \]
          2. associate-/l*N/A

            \[\leadsto cosTheta\_O \cdot \frac{cosTheta\_i}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)} + \color{blue}{-1} \cdot \frac{cosTheta\_O \cdot \left(cosTheta\_i \cdot \left(sinTheta\_O \cdot sinTheta\_i\right)\right)}{{v}^{3} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)} \]
          3. lower-fma.f32N/A

            \[\leadsto \mathsf{fma}\left(cosTheta\_O, \color{blue}{\frac{cosTheta\_i}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)}}, -1 \cdot \frac{cosTheta\_O \cdot \left(cosTheta\_i \cdot \left(sinTheta\_O \cdot sinTheta\_i\right)\right)}{{v}^{3} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)}\right) \]
        4. Applied rewrites98.6%

          \[\leadsto \color{blue}{\mathsf{fma}\left(cosTheta\_O, \frac{cosTheta\_i}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot \left(v \cdot v\right)}, \frac{-\left(\left(sinTheta\_O \cdot sinTheta\_i\right) \cdot cosTheta\_i\right) \cdot cosTheta\_O}{\left(\left(v \cdot v\right) \cdot v\right) \cdot \left(\sinh \left(\frac{1}{v}\right) \cdot 2\right)}\right)} \]
        5. Taylor expanded in cosTheta_i around 0

          \[\leadsto cosTheta\_i \cdot \color{blue}{\left(-1 \cdot \frac{cosTheta\_O \cdot \left(sinTheta\_O \cdot sinTheta\_i\right)}{{v}^{3} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)} + \frac{cosTheta\_O}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)}\right)} \]
        6. Step-by-step derivation
          1. *-commutativeN/A

            \[\leadsto \left(-1 \cdot \frac{cosTheta\_O \cdot \left(sinTheta\_O \cdot sinTheta\_i\right)}{{v}^{3} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)} + \frac{cosTheta\_O}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)}\right) \cdot cosTheta\_i \]
          2. lower-*.f32N/A

            \[\leadsto \left(-1 \cdot \frac{cosTheta\_O \cdot \left(sinTheta\_O \cdot sinTheta\_i\right)}{{v}^{3} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)} + \frac{cosTheta\_O}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)}\right) \cdot cosTheta\_i \]
        7. Applied rewrites98.5%

          \[\leadsto \left(\frac{cosTheta\_O}{\left(e^{\frac{1}{v}} - e^{-\frac{1}{v}}\right) \cdot \left(v \cdot v\right)} + \left(-\frac{\left(sinTheta\_O \cdot sinTheta\_i\right) \cdot cosTheta\_O}{\left(\left(v \cdot v\right) \cdot v\right) \cdot \left(e^{\frac{1}{v}} - e^{-\frac{1}{v}}\right)}\right)\right) \cdot \color{blue}{cosTheta\_i} \]
        8. Taylor expanded in v around inf

          \[\leadsto \left(\frac{1}{2} \cdot \frac{cosTheta\_O}{v}\right) \cdot cosTheta\_i \]
        9. Step-by-step derivation
          1. lower-*.f32N/A

            \[\leadsto \left(\frac{1}{2} \cdot \frac{cosTheta\_O}{v}\right) \cdot cosTheta\_i \]
          2. lift-/.f3259.2

            \[\leadsto \left(0.5 \cdot \frac{cosTheta\_O}{v}\right) \cdot cosTheta\_i \]
        10. Applied rewrites59.2%

          \[\leadsto \left(0.5 \cdot \frac{cosTheta\_O}{v}\right) \cdot cosTheta\_i \]
        11. Add Preprocessing

        Alternative 18: 59.2% accurate, 5.5× speedup?

        \[\begin{array}{l} cosTheta_i\_m = \left|cosTheta\_i\right| \\ cosTheta_i\_s = \mathsf{copysign}\left(1, cosTheta\_i\right) \\ cosTheta_O\_m = \left|cosTheta\_O\right| \\ cosTheta_O\_s = \mathsf{copysign}\left(1, cosTheta\_O\right) \\ [cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v] = \mathsf{sort}([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])\\ \\ cosTheta\_O\_s \cdot \left(cosTheta\_i\_s \cdot \frac{cosTheta\_O\_m \cdot cosTheta\_i\_m}{v + v}\right) \end{array} \]
        cosTheta_i\_m = (fabs.f32 cosTheta_i)
        cosTheta_i\_s = (copysign.f32 #s(literal 1 binary32) cosTheta_i)
        cosTheta_O\_m = (fabs.f32 cosTheta_O)
        cosTheta_O\_s = (copysign.f32 #s(literal 1 binary32) cosTheta_O)
        NOTE: cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, and v should be sorted in increasing order before calling this function.
        (FPCore (cosTheta_O_s cosTheta_i_s cosTheta_i_m cosTheta_O_m sinTheta_i sinTheta_O v)
         :precision binary32
         (* cosTheta_O_s (* cosTheta_i_s (/ (* cosTheta_O_m cosTheta_i_m) (+ v v)))))
        cosTheta_i\_m = fabs(cosTheta_i);
        cosTheta_i\_s = copysign(1.0, cosTheta_i);
        cosTheta_O\_m = fabs(cosTheta_O);
        cosTheta_O\_s = copysign(1.0, cosTheta_O);
        assert(cosTheta_i_m < cosTheta_O_m && cosTheta_O_m < sinTheta_i && sinTheta_i < sinTheta_O && sinTheta_O < v);
        float code(float cosTheta_O_s, float cosTheta_i_s, float cosTheta_i_m, float cosTheta_O_m, float sinTheta_i, float sinTheta_O, float v) {
        	return cosTheta_O_s * (cosTheta_i_s * ((cosTheta_O_m * cosTheta_i_m) / (v + v)));
        }
        
        cosTheta_i\_m =     private
        cosTheta_i\_s =     private
        cosTheta_O\_m =     private
        cosTheta_O\_s =     private
        NOTE: cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, and v should be sorted in increasing order before calling this function.
        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_o_s, costheta_i_s, costheta_i_m, costheta_o_m, sintheta_i, sintheta_o, v)
        use fmin_fmax_functions
            real(4), intent (in) :: costheta_o_s
            real(4), intent (in) :: costheta_i_s
            real(4), intent (in) :: costheta_i_m
            real(4), intent (in) :: costheta_o_m
            real(4), intent (in) :: sintheta_i
            real(4), intent (in) :: sintheta_o
            real(4), intent (in) :: v
            code = costheta_o_s * (costheta_i_s * ((costheta_o_m * costheta_i_m) / (v + v)))
        end function
        
        cosTheta_i\_m = abs(cosTheta_i)
        cosTheta_i\_s = copysign(1.0, cosTheta_i)
        cosTheta_O\_m = abs(cosTheta_O)
        cosTheta_O\_s = copysign(1.0, cosTheta_O)
        cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v = sort([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])
        function code(cosTheta_O_s, cosTheta_i_s, cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v)
        	return Float32(cosTheta_O_s * Float32(cosTheta_i_s * Float32(Float32(cosTheta_O_m * cosTheta_i_m) / Float32(v + v))))
        end
        
        cosTheta_i\_m = abs(cosTheta_i);
        cosTheta_i\_s = sign(cosTheta_i) * abs(1.0);
        cosTheta_O\_m = abs(cosTheta_O);
        cosTheta_O\_s = sign(cosTheta_O) * abs(1.0);
        cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v = num2cell(sort([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])){:}
        function tmp = code(cosTheta_O_s, cosTheta_i_s, cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v)
        	tmp = cosTheta_O_s * (cosTheta_i_s * ((cosTheta_O_m * cosTheta_i_m) / (v + v)));
        end
        
        \begin{array}{l}
        cosTheta_i\_m = \left|cosTheta\_i\right|
        \\
        cosTheta_i\_s = \mathsf{copysign}\left(1, cosTheta\_i\right)
        \\
        cosTheta_O\_m = \left|cosTheta\_O\right|
        \\
        cosTheta_O\_s = \mathsf{copysign}\left(1, cosTheta\_O\right)
        \\
        [cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v] = \mathsf{sort}([cosTheta_i_m, cosTheta_O_m, sinTheta_i, sinTheta_O, v])\\
        \\
        cosTheta\_O\_s \cdot \left(cosTheta\_i\_s \cdot \frac{cosTheta\_O\_m \cdot cosTheta\_i\_m}{v + v}\right)
        \end{array}
        
        Derivation
        1. Initial program 98.6%

          \[\frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
        2. Step-by-step derivation
          1. lift-*.f32N/A

            \[\leadsto \frac{\color{blue}{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
          2. lift-exp.f32N/A

            \[\leadsto \frac{\color{blue}{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
          3. lift-neg.f32N/A

            \[\leadsto \frac{e^{\color{blue}{\mathsf{neg}\left(\frac{sinTheta\_i \cdot sinTheta\_O}{v}\right)}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
          4. lift-*.f32N/A

            \[\leadsto \frac{e^{\mathsf{neg}\left(\frac{\color{blue}{sinTheta\_i \cdot sinTheta\_O}}{v}\right)} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
          5. lift-/.f32N/A

            \[\leadsto \frac{e^{\mathsf{neg}\left(\color{blue}{\frac{sinTheta\_i \cdot sinTheta\_O}{v}}\right)} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
          6. lift-*.f32N/A

            \[\leadsto \frac{e^{\mathsf{neg}\left(\frac{sinTheta\_i \cdot sinTheta\_O}{v}\right)} \cdot \frac{\color{blue}{cosTheta\_i \cdot cosTheta\_O}}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
          7. lift-/.f32N/A

            \[\leadsto \frac{e^{\mathsf{neg}\left(\frac{sinTheta\_i \cdot sinTheta\_O}{v}\right)} \cdot \color{blue}{\frac{cosTheta\_i \cdot cosTheta\_O}{v}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
          8. *-commutativeN/A

            \[\leadsto \frac{\color{blue}{\frac{cosTheta\_i \cdot cosTheta\_O}{v} \cdot e^{\mathsf{neg}\left(\frac{sinTheta\_i \cdot sinTheta\_O}{v}\right)}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
          9. *-commutativeN/A

            \[\leadsto \frac{\frac{\color{blue}{cosTheta\_O \cdot cosTheta\_i}}{v} \cdot e^{\mathsf{neg}\left(\frac{sinTheta\_i \cdot sinTheta\_O}{v}\right)}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
          10. division-flipN/A

            \[\leadsto \frac{\color{blue}{\frac{1}{\frac{v}{cosTheta\_O \cdot cosTheta\_i}}} \cdot e^{\mathsf{neg}\left(\frac{sinTheta\_i \cdot sinTheta\_O}{v}\right)}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
          11. exp-negN/A

            \[\leadsto \frac{\frac{1}{\frac{v}{cosTheta\_O \cdot cosTheta\_i}} \cdot \color{blue}{\frac{1}{e^{\frac{sinTheta\_i \cdot sinTheta\_O}{v}}}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
          12. *-commutativeN/A

            \[\leadsto \frac{\frac{1}{\frac{v}{cosTheta\_O \cdot cosTheta\_i}} \cdot \frac{1}{e^{\frac{\color{blue}{sinTheta\_O \cdot sinTheta\_i}}{v}}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
          13. frac-timesN/A

            \[\leadsto \frac{\color{blue}{\frac{1 \cdot 1}{\frac{v}{cosTheta\_O \cdot cosTheta\_i} \cdot e^{\frac{sinTheta\_O \cdot sinTheta\_i}{v}}}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
          14. metadata-evalN/A

            \[\leadsto \frac{\frac{\color{blue}{1}}{\frac{v}{cosTheta\_O \cdot cosTheta\_i} \cdot e^{\frac{sinTheta\_O \cdot sinTheta\_i}{v}}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
          15. lower-/.f32N/A

            \[\leadsto \frac{\color{blue}{\frac{1}{\frac{v}{cosTheta\_O \cdot cosTheta\_i} \cdot e^{\frac{sinTheta\_O \cdot sinTheta\_i}{v}}}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
          16. lower-*.f32N/A

            \[\leadsto \frac{\frac{1}{\color{blue}{\frac{v}{cosTheta\_O \cdot cosTheta\_i} \cdot e^{\frac{sinTheta\_O \cdot sinTheta\_i}{v}}}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
        3. Applied rewrites95.1%

          \[\leadsto \frac{\color{blue}{\frac{1}{\frac{v}{cosTheta\_O \cdot cosTheta\_i} \cdot e^{\frac{sinTheta\_O \cdot sinTheta\_i}{v}}}}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
        4. Taylor expanded in sinTheta_i around 0

          \[\leadsto \color{blue}{\frac{cosTheta\_O \cdot cosTheta\_i}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)}} \]
        5. Step-by-step derivation
          1. lower-/.f32N/A

            \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\color{blue}{{v}^{2} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)}} \]
          2. lift-*.f32N/A

            \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\color{blue}{{v}^{2}} \cdot \left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right)} \]
          3. *-commutativeN/A

            \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right) \cdot \color{blue}{{v}^{2}}} \]
          4. lower-*.f32N/A

            \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right) \cdot \color{blue}{{v}^{2}}} \]
          5. lower--.f32N/A

            \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right) \cdot {\color{blue}{v}}^{2}} \]
          6. lower-exp.f32N/A

            \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right) \cdot {v}^{2}} \]
          7. lift-/.f32N/A

            \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - \frac{1}{e^{\frac{1}{v}}}\right) \cdot {v}^{2}} \]
          8. rec-expN/A

            \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - e^{\mathsf{neg}\left(\frac{1}{v}\right)}\right) \cdot {v}^{2}} \]
          9. lower-exp.f32N/A

            \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - e^{\mathsf{neg}\left(\frac{1}{v}\right)}\right) \cdot {v}^{2}} \]
          10. lower-neg.f32N/A

            \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - e^{-\frac{1}{v}}\right) \cdot {v}^{2}} \]
          11. lift-/.f32N/A

            \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - e^{-\frac{1}{v}}\right) \cdot {v}^{2}} \]
          12. pow2N/A

            \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - e^{-\frac{1}{v}}\right) \cdot \left(v \cdot \color{blue}{v}\right)} \]
          13. lift-*.f3298.3

            \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - e^{-\frac{1}{v}}\right) \cdot \left(v \cdot \color{blue}{v}\right)} \]
        6. Applied rewrites98.3%

          \[\leadsto \color{blue}{\frac{cosTheta\_O \cdot cosTheta\_i}{\left(e^{\frac{1}{v}} - e^{-\frac{1}{v}}\right) \cdot \left(v \cdot v\right)}} \]
        7. Taylor expanded in v around inf

          \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{2 \cdot \color{blue}{v}} \]
        8. Step-by-step derivation
          1. pow2N/A

            \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{2 \cdot v} \]
          2. *-commutativeN/A

            \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{2 \cdot v} \]
          3. pow2N/A

            \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{2 \cdot v} \]
          4. sinh-undef-revN/A

            \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{2 \cdot v} \]
          5. count-2-revN/A

            \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{v + v} \]
          6. lower-+.f3259.2

            \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{v + v} \]
        9. Applied rewrites59.2%

          \[\leadsto \frac{cosTheta\_O \cdot cosTheta\_i}{v + \color{blue}{v}} \]
        10. Add Preprocessing

        Reproduce

        ?
        herbie shell --seed 2025127 
        (FPCore (cosTheta_i cosTheta_O sinTheta_i sinTheta_O v)
          :name "HairBSDF, Mp, upper"
          :precision binary32
          :pre (and (and (and (and (and (and (<= -1.0 cosTheta_i) (<= cosTheta_i 1.0)) (and (<= -1.0 cosTheta_O) (<= cosTheta_O 1.0))) (and (<= -1.0 sinTheta_i) (<= sinTheta_i 1.0))) (and (<= -1.0 sinTheta_O) (<= sinTheta_O 1.0))) (< 0.1 v)) (<= v 1.5707964))
          (/ (* (exp (- (/ (* sinTheta_i sinTheta_O) v))) (/ (* cosTheta_i cosTheta_O) v)) (* (* (sinh (/ 1.0 v)) 2.0) v)))