HairBSDF, gamma for a refracted ray

Percentage Accurate: 92.1% → 98.4%
Time: 3.6s
Alternatives: 4
Speedup: 3.6×

Specification

?
\[\left(\left(-1 \leq sinTheta\_O \land sinTheta\_O \leq 1\right) \land \left(-1 \leq h \land h \leq 1\right)\right) \land \left(0 \leq eta \land eta \leq 10\right)\]
\[\begin{array}{l} \\ \sin^{-1} \left(\frac{h}{\sqrt{eta \cdot eta - \frac{sinTheta\_O \cdot sinTheta\_O}{\sqrt{1 - sinTheta\_O \cdot sinTheta\_O}}}}\right) \end{array} \]
(FPCore (sinTheta_O h eta)
 :precision binary32
 (asin
  (/
   h
   (sqrt
    (-
     (* eta eta)
     (/
      (* sinTheta_O sinTheta_O)
      (sqrt (- 1.0 (* sinTheta_O sinTheta_O)))))))))
float code(float sinTheta_O, float h, float eta) {
	return asinf((h / sqrtf(((eta * eta) - ((sinTheta_O * sinTheta_O) / sqrtf((1.0f - (sinTheta_O * sinTheta_O))))))));
}
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(sintheta_o, h, eta)
use fmin_fmax_functions
    real(4), intent (in) :: sintheta_o
    real(4), intent (in) :: h
    real(4), intent (in) :: eta
    code = asin((h / sqrt(((eta * eta) - ((sintheta_o * sintheta_o) / sqrt((1.0e0 - (sintheta_o * sintheta_o))))))))
end function
function code(sinTheta_O, h, eta)
	return asin(Float32(h / sqrt(Float32(Float32(eta * eta) - Float32(Float32(sinTheta_O * sinTheta_O) / sqrt(Float32(Float32(1.0) - Float32(sinTheta_O * sinTheta_O))))))))
end
function tmp = code(sinTheta_O, h, eta)
	tmp = asin((h / sqrt(((eta * eta) - ((sinTheta_O * sinTheta_O) / sqrt((single(1.0) - (sinTheta_O * sinTheta_O))))))));
end
\begin{array}{l}

\\
\sin^{-1} \left(\frac{h}{\sqrt{eta \cdot eta - \frac{sinTheta\_O \cdot sinTheta\_O}{\sqrt{1 - sinTheta\_O \cdot sinTheta\_O}}}}\right)
\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 4 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: 92.1% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \sin^{-1} \left(\frac{h}{\sqrt{eta \cdot eta - \frac{sinTheta\_O \cdot sinTheta\_O}{\sqrt{1 - sinTheta\_O \cdot sinTheta\_O}}}}\right) \end{array} \]
(FPCore (sinTheta_O h eta)
 :precision binary32
 (asin
  (/
   h
   (sqrt
    (-
     (* eta eta)
     (/
      (* sinTheta_O sinTheta_O)
      (sqrt (- 1.0 (* sinTheta_O sinTheta_O)))))))))
float code(float sinTheta_O, float h, float eta) {
	return asinf((h / sqrtf(((eta * eta) - ((sinTheta_O * sinTheta_O) / sqrtf((1.0f - (sinTheta_O * sinTheta_O))))))));
}
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(sintheta_o, h, eta)
use fmin_fmax_functions
    real(4), intent (in) :: sintheta_o
    real(4), intent (in) :: h
    real(4), intent (in) :: eta
    code = asin((h / sqrt(((eta * eta) - ((sintheta_o * sintheta_o) / sqrt((1.0e0 - (sintheta_o * sintheta_o))))))))
end function
function code(sinTheta_O, h, eta)
	return asin(Float32(h / sqrt(Float32(Float32(eta * eta) - Float32(Float32(sinTheta_O * sinTheta_O) / sqrt(Float32(Float32(1.0) - Float32(sinTheta_O * sinTheta_O))))))))
end
function tmp = code(sinTheta_O, h, eta)
	tmp = asin((h / sqrt(((eta * eta) - ((sinTheta_O * sinTheta_O) / sqrt((single(1.0) - (sinTheta_O * sinTheta_O))))))));
end
\begin{array}{l}

\\
\sin^{-1} \left(\frac{h}{\sqrt{eta \cdot eta - \frac{sinTheta\_O \cdot sinTheta\_O}{\sqrt{1 - sinTheta\_O \cdot sinTheta\_O}}}}\right)
\end{array}

Alternative 1: 98.4% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;eta \leq 9.999999682655225 \cdot 10^{-21}:\\ \;\;\;\;\sin^{-1} \left(\frac{h}{eta}\right)\\ \mathbf{else}:\\ \;\;\;\;\sin^{-1} \left(\frac{h}{\sqrt{\mathsf{fma}\left(eta, eta, -sinTheta\_O \cdot sinTheta\_O\right)}}\right)\\ \end{array} \end{array} \]
(FPCore (sinTheta_O h eta)
 :precision binary32
 (if (<= eta 9.999999682655225e-21)
   (asin (/ h eta))
   (asin (/ h (sqrt (fma eta eta (- (* sinTheta_O sinTheta_O))))))))
float code(float sinTheta_O, float h, float eta) {
	float tmp;
	if (eta <= 9.999999682655225e-21f) {
		tmp = asinf((h / eta));
	} else {
		tmp = asinf((h / sqrtf(fmaf(eta, eta, -(sinTheta_O * sinTheta_O)))));
	}
	return tmp;
}
function code(sinTheta_O, h, eta)
	tmp = Float32(0.0)
	if (eta <= Float32(9.999999682655225e-21))
		tmp = asin(Float32(h / eta));
	else
		tmp = asin(Float32(h / sqrt(fma(eta, eta, Float32(-Float32(sinTheta_O * sinTheta_O))))));
	end
	return tmp
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;eta \leq 9.999999682655225 \cdot 10^{-21}:\\
\;\;\;\;\sin^{-1} \left(\frac{h}{eta}\right)\\

\mathbf{else}:\\
\;\;\;\;\sin^{-1} \left(\frac{h}{\sqrt{\mathsf{fma}\left(eta, eta, -sinTheta\_O \cdot sinTheta\_O\right)}}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if eta < 9.99999968e-21

    1. Initial program 23.9%

      \[\sin^{-1} \left(\frac{h}{\sqrt{eta \cdot eta - \frac{sinTheta\_O \cdot sinTheta\_O}{\sqrt{1 - sinTheta\_O \cdot sinTheta\_O}}}}\right) \]
    2. Taylor expanded in sinTheta_O around 0

      \[\leadsto \sin^{-1} \left(\frac{h}{\color{blue}{eta}}\right) \]
    3. Step-by-step derivation
      1. Applied rewrites89.3%

        \[\leadsto \sin^{-1} \left(\frac{h}{\color{blue}{eta}}\right) \]

      if 9.99999968e-21 < eta

      1. Initial program 99.7%

        \[\sin^{-1} \left(\frac{h}{\sqrt{eta \cdot eta - \frac{sinTheta\_O \cdot sinTheta\_O}{\sqrt{1 - sinTheta\_O \cdot sinTheta\_O}}}}\right) \]
      2. Taylor expanded in sinTheta_O around 0

        \[\leadsto \sin^{-1} \left(\frac{h}{\sqrt{\color{blue}{-1 \cdot {sinTheta\_O}^{2} + {eta}^{2}}}}\right) \]
      3. Step-by-step derivation
        1. mul-1-negN/A

          \[\leadsto \sin^{-1} \left(\frac{h}{\sqrt{\left(\mathsf{neg}\left({sinTheta\_O}^{2}\right)\right) + {\color{blue}{eta}}^{2}}}\right) \]
        2. +-commutativeN/A

          \[\leadsto \sin^{-1} \left(\frac{h}{\sqrt{{eta}^{2} + \color{blue}{\left(\mathsf{neg}\left({sinTheta\_O}^{2}\right)\right)}}}\right) \]
        3. pow2N/A

          \[\leadsto \sin^{-1} \left(\frac{h}{\sqrt{eta \cdot eta + \left(\mathsf{neg}\left(\color{blue}{{sinTheta\_O}^{2}}\right)\right)}}\right) \]
        4. lower-fma.f32N/A

          \[\leadsto \sin^{-1} \left(\frac{h}{\sqrt{\mathsf{fma}\left(eta, \color{blue}{eta}, \mathsf{neg}\left({sinTheta\_O}^{2}\right)\right)}}\right) \]
        5. lower-neg.f32N/A

          \[\leadsto \sin^{-1} \left(\frac{h}{\sqrt{\mathsf{fma}\left(eta, eta, -{sinTheta\_O}^{2}\right)}}\right) \]
        6. pow2N/A

          \[\leadsto \sin^{-1} \left(\frac{h}{\sqrt{\mathsf{fma}\left(eta, eta, -sinTheta\_O \cdot sinTheta\_O\right)}}\right) \]
        7. lift-*.f3299.5

          \[\leadsto \sin^{-1} \left(\frac{h}{\sqrt{\mathsf{fma}\left(eta, eta, -sinTheta\_O \cdot sinTheta\_O\right)}}\right) \]
      4. Applied rewrites99.5%

        \[\leadsto \sin^{-1} \left(\frac{h}{\sqrt{\color{blue}{\mathsf{fma}\left(eta, eta, -sinTheta\_O \cdot sinTheta\_O\right)}}}\right) \]
    4. Recombined 2 regimes into one program.
    5. Add Preprocessing

    Alternative 2: 97.5% accurate, 1.3× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;sinTheta\_O \leq 3.000000157232057 \cdot 10^{-23}:\\ \;\;\;\;\sin^{-1} \left(\frac{h}{eta}\right)\\ \mathbf{else}:\\ \;\;\;\;\sin^{-1} \left(\frac{h}{\sqrt{eta \cdot eta - sinTheta\_O \cdot sinTheta\_O}}\right)\\ \end{array} \end{array} \]
    (FPCore (sinTheta_O h eta)
     :precision binary32
     (if (<= sinTheta_O 3.000000157232057e-23)
       (asin (/ h eta))
       (asin (/ h (sqrt (- (* eta eta) (* sinTheta_O sinTheta_O)))))))
    float code(float sinTheta_O, float h, float eta) {
    	float tmp;
    	if (sinTheta_O <= 3.000000157232057e-23f) {
    		tmp = asinf((h / eta));
    	} else {
    		tmp = asinf((h / sqrtf(((eta * eta) - (sinTheta_O * sinTheta_O)))));
    	}
    	return tmp;
    }
    
    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(sintheta_o, h, eta)
    use fmin_fmax_functions
        real(4), intent (in) :: sintheta_o
        real(4), intent (in) :: h
        real(4), intent (in) :: eta
        real(4) :: tmp
        if (sintheta_o <= 3.000000157232057e-23) then
            tmp = asin((h / eta))
        else
            tmp = asin((h / sqrt(((eta * eta) - (sintheta_o * sintheta_o)))))
        end if
        code = tmp
    end function
    
    function code(sinTheta_O, h, eta)
    	tmp = Float32(0.0)
    	if (sinTheta_O <= Float32(3.000000157232057e-23))
    		tmp = asin(Float32(h / eta));
    	else
    		tmp = asin(Float32(h / sqrt(Float32(Float32(eta * eta) - Float32(sinTheta_O * sinTheta_O)))));
    	end
    	return tmp
    end
    
    function tmp_2 = code(sinTheta_O, h, eta)
    	tmp = single(0.0);
    	if (sinTheta_O <= single(3.000000157232057e-23))
    		tmp = asin((h / eta));
    	else
    		tmp = asin((h / sqrt(((eta * eta) - (sinTheta_O * sinTheta_O)))));
    	end
    	tmp_2 = tmp;
    end
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;sinTheta\_O \leq 3.000000157232057 \cdot 10^{-23}:\\
    \;\;\;\;\sin^{-1} \left(\frac{h}{eta}\right)\\
    
    \mathbf{else}:\\
    \;\;\;\;\sin^{-1} \left(\frac{h}{\sqrt{eta \cdot eta - sinTheta\_O \cdot sinTheta\_O}}\right)\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if sinTheta_O < 3.00000016e-23

      1. Initial program 90.1%

        \[\sin^{-1} \left(\frac{h}{\sqrt{eta \cdot eta - \frac{sinTheta\_O \cdot sinTheta\_O}{\sqrt{1 - sinTheta\_O \cdot sinTheta\_O}}}}\right) \]
      2. Taylor expanded in sinTheta_O around 0

        \[\leadsto \sin^{-1} \left(\frac{h}{\color{blue}{eta}}\right) \]
      3. Step-by-step derivation
        1. Applied rewrites96.4%

          \[\leadsto \sin^{-1} \left(\frac{h}{\color{blue}{eta}}\right) \]

        if 3.00000016e-23 < sinTheta_O

        1. Initial program 99.5%

          \[\sin^{-1} \left(\frac{h}{\sqrt{eta \cdot eta - \frac{sinTheta\_O \cdot sinTheta\_O}{\sqrt{1 - sinTheta\_O \cdot sinTheta\_O}}}}\right) \]
        2. Taylor expanded in sinTheta_O around 0

          \[\leadsto \sin^{-1} \left(\frac{h}{\sqrt{eta \cdot eta - \color{blue}{{sinTheta\_O}^{2}}}}\right) \]
        3. Step-by-step derivation
          1. pow2N/A

            \[\leadsto \sin^{-1} \left(\frac{h}{\sqrt{eta \cdot eta - sinTheta\_O \cdot \color{blue}{sinTheta\_O}}}\right) \]
          2. lift-*.f3298.9

            \[\leadsto \sin^{-1} \left(\frac{h}{\sqrt{eta \cdot eta - sinTheta\_O \cdot \color{blue}{sinTheta\_O}}}\right) \]
        4. Applied rewrites98.9%

          \[\leadsto \sin^{-1} \left(\frac{h}{\sqrt{eta \cdot eta - \color{blue}{sinTheta\_O \cdot sinTheta\_O}}}\right) \]
      4. Recombined 2 regimes into one program.
      5. Add Preprocessing

      Alternative 3: 96.9% accurate, 1.1× speedup?

      \[\begin{array}{l} \\ \sin^{-1} \left(\frac{\mathsf{fma}\left(\left(sinTheta\_O \cdot \frac{\frac{sinTheta\_O}{eta}}{eta}\right) \cdot h, 0.5, h\right)}{eta}\right) \end{array} \]
      (FPCore (sinTheta_O h eta)
       :precision binary32
       (asin (/ (fma (* (* sinTheta_O (/ (/ sinTheta_O eta) eta)) h) 0.5 h) eta)))
      float code(float sinTheta_O, float h, float eta) {
      	return asinf((fmaf(((sinTheta_O * ((sinTheta_O / eta) / eta)) * h), 0.5f, h) / eta));
      }
      
      function code(sinTheta_O, h, eta)
      	return asin(Float32(fma(Float32(Float32(sinTheta_O * Float32(Float32(sinTheta_O / eta) / eta)) * h), Float32(0.5), h) / eta))
      end
      
      \begin{array}{l}
      
      \\
      \sin^{-1} \left(\frac{\mathsf{fma}\left(\left(sinTheta\_O \cdot \frac{\frac{sinTheta\_O}{eta}}{eta}\right) \cdot h, 0.5, h\right)}{eta}\right)
      \end{array}
      
      Derivation
      1. Initial program 92.1%

        \[\sin^{-1} \left(\frac{h}{\sqrt{eta \cdot eta - \frac{sinTheta\_O \cdot sinTheta\_O}{\sqrt{1 - sinTheta\_O \cdot sinTheta\_O}}}}\right) \]
      2. Taylor expanded in sinTheta_O around 0

        \[\leadsto \sin^{-1} \color{blue}{\left(\frac{1}{2} \cdot \frac{h \cdot {sinTheta\_O}^{2}}{{eta}^{3}} + \frac{h}{eta}\right)} \]
      3. Step-by-step derivation
        1. *-commutativeN/A

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

          \[\leadsto \sin^{-1} \left(\mathsf{fma}\left(\frac{h \cdot {sinTheta\_O}^{2}}{{eta}^{3}}, \color{blue}{\frac{1}{2}}, \frac{h}{eta}\right)\right) \]
        3. lower-/.f32N/A

          \[\leadsto \sin^{-1} \left(\mathsf{fma}\left(\frac{h \cdot {sinTheta\_O}^{2}}{{eta}^{3}}, \frac{1}{2}, \frac{h}{eta}\right)\right) \]
        4. *-commutativeN/A

          \[\leadsto \sin^{-1} \left(\mathsf{fma}\left(\frac{{sinTheta\_O}^{2} \cdot h}{{eta}^{3}}, \frac{1}{2}, \frac{h}{eta}\right)\right) \]
        5. lower-*.f32N/A

          \[\leadsto \sin^{-1} \left(\mathsf{fma}\left(\frac{{sinTheta\_O}^{2} \cdot h}{{eta}^{3}}, \frac{1}{2}, \frac{h}{eta}\right)\right) \]
        6. pow2N/A

          \[\leadsto \sin^{-1} \left(\mathsf{fma}\left(\frac{\left(sinTheta\_O \cdot sinTheta\_O\right) \cdot h}{{eta}^{3}}, \frac{1}{2}, \frac{h}{eta}\right)\right) \]
        7. lift-*.f32N/A

          \[\leadsto \sin^{-1} \left(\mathsf{fma}\left(\frac{\left(sinTheta\_O \cdot sinTheta\_O\right) \cdot h}{{eta}^{3}}, \frac{1}{2}, \frac{h}{eta}\right)\right) \]
        8. unpow3N/A

          \[\leadsto \sin^{-1} \left(\mathsf{fma}\left(\frac{\left(sinTheta\_O \cdot sinTheta\_O\right) \cdot h}{\left(eta \cdot eta\right) \cdot eta}, \frac{1}{2}, \frac{h}{eta}\right)\right) \]
        9. pow2N/A

          \[\leadsto \sin^{-1} \left(\mathsf{fma}\left(\frac{\left(sinTheta\_O \cdot sinTheta\_O\right) \cdot h}{{eta}^{2} \cdot eta}, \frac{1}{2}, \frac{h}{eta}\right)\right) \]
        10. lower-*.f32N/A

          \[\leadsto \sin^{-1} \left(\mathsf{fma}\left(\frac{\left(sinTheta\_O \cdot sinTheta\_O\right) \cdot h}{{eta}^{2} \cdot eta}, \frac{1}{2}, \frac{h}{eta}\right)\right) \]
        11. pow2N/A

          \[\leadsto \sin^{-1} \left(\mathsf{fma}\left(\frac{\left(sinTheta\_O \cdot sinTheta\_O\right) \cdot h}{\left(eta \cdot eta\right) \cdot eta}, \frac{1}{2}, \frac{h}{eta}\right)\right) \]
        12. lift-*.f32N/A

          \[\leadsto \sin^{-1} \left(\mathsf{fma}\left(\frac{\left(sinTheta\_O \cdot sinTheta\_O\right) \cdot h}{\left(eta \cdot eta\right) \cdot eta}, \frac{1}{2}, \frac{h}{eta}\right)\right) \]
        13. lower-/.f3277.4

          \[\leadsto \sin^{-1} \left(\mathsf{fma}\left(\frac{\left(sinTheta\_O \cdot sinTheta\_O\right) \cdot h}{\left(eta \cdot eta\right) \cdot eta}, 0.5, \frac{h}{eta}\right)\right) \]
      4. Applied rewrites77.4%

        \[\leadsto \sin^{-1} \color{blue}{\left(\mathsf{fma}\left(\frac{\left(sinTheta\_O \cdot sinTheta\_O\right) \cdot h}{\left(eta \cdot eta\right) \cdot eta}, 0.5, \frac{h}{eta}\right)\right)} \]
      5. Taylor expanded in eta around inf

        \[\leadsto \sin^{-1} \left(\frac{h + \frac{1}{2} \cdot \frac{h \cdot {sinTheta\_O}^{2}}{{eta}^{2}}}{\color{blue}{eta}}\right) \]
      6. Step-by-step derivation
        1. lower-/.f32N/A

          \[\leadsto \sin^{-1} \left(\frac{h + \frac{1}{2} \cdot \frac{h \cdot {sinTheta\_O}^{2}}{{eta}^{2}}}{eta}\right) \]
        2. +-commutativeN/A

          \[\leadsto \sin^{-1} \left(\frac{\frac{1}{2} \cdot \frac{h \cdot {sinTheta\_O}^{2}}{{eta}^{2}} + h}{eta}\right) \]
        3. *-commutativeN/A

          \[\leadsto \sin^{-1} \left(\frac{\frac{h \cdot {sinTheta\_O}^{2}}{{eta}^{2}} \cdot \frac{1}{2} + h}{eta}\right) \]
        4. lower-fma.f32N/A

          \[\leadsto \sin^{-1} \left(\frac{\mathsf{fma}\left(\frac{h \cdot {sinTheta\_O}^{2}}{{eta}^{2}}, \frac{1}{2}, h\right)}{eta}\right) \]
        5. associate-/l*N/A

          \[\leadsto \sin^{-1} \left(\frac{\mathsf{fma}\left(h \cdot \frac{{sinTheta\_O}^{2}}{{eta}^{2}}, \frac{1}{2}, h\right)}{eta}\right) \]
        6. lower-*.f32N/A

          \[\leadsto \sin^{-1} \left(\frac{\mathsf{fma}\left(h \cdot \frac{{sinTheta\_O}^{2}}{{eta}^{2}}, \frac{1}{2}, h\right)}{eta}\right) \]
        7. lower-/.f32N/A

          \[\leadsto \sin^{-1} \left(\frac{\mathsf{fma}\left(h \cdot \frac{{sinTheta\_O}^{2}}{{eta}^{2}}, \frac{1}{2}, h\right)}{eta}\right) \]
        8. pow2N/A

          \[\leadsto \sin^{-1} \left(\frac{\mathsf{fma}\left(h \cdot \frac{sinTheta\_O \cdot sinTheta\_O}{{eta}^{2}}, \frac{1}{2}, h\right)}{eta}\right) \]
        9. lift-*.f32N/A

          \[\leadsto \sin^{-1} \left(\frac{\mathsf{fma}\left(h \cdot \frac{sinTheta\_O \cdot sinTheta\_O}{{eta}^{2}}, \frac{1}{2}, h\right)}{eta}\right) \]
        10. pow2N/A

          \[\leadsto \sin^{-1} \left(\frac{\mathsf{fma}\left(h \cdot \frac{sinTheta\_O \cdot sinTheta\_O}{eta \cdot eta}, \frac{1}{2}, h\right)}{eta}\right) \]
        11. lift-*.f3291.6

          \[\leadsto \sin^{-1} \left(\frac{\mathsf{fma}\left(h \cdot \frac{sinTheta\_O \cdot sinTheta\_O}{eta \cdot eta}, 0.5, h\right)}{eta}\right) \]
      7. Applied rewrites91.6%

        \[\leadsto \sin^{-1} \left(\frac{\mathsf{fma}\left(h \cdot \frac{sinTheta\_O \cdot sinTheta\_O}{eta \cdot eta}, 0.5, h\right)}{\color{blue}{eta}}\right) \]
      8. Step-by-step derivation
        1. Applied rewrites91.6%

          \[\leadsto \color{blue}{\sin^{-1} \left(\frac{\mathsf{fma}\left(\left(sinTheta\_O \cdot \frac{sinTheta\_O}{eta \cdot eta}\right) \cdot h, 0.5, h\right)}{eta}\right)} \]
        2. Step-by-step derivation
          1. lift-*.f32N/A

            \[\leadsto \sin^{-1} \left(\frac{\mathsf{fma}\left(\left(sinTheta\_O \cdot \frac{sinTheta\_O}{eta \cdot eta}\right) \cdot h, \frac{1}{2}, h\right)}{eta}\right) \]
          2. lift-/.f32N/A

            \[\leadsto \sin^{-1} \left(\frac{\mathsf{fma}\left(\left(sinTheta\_O \cdot \frac{sinTheta\_O}{eta \cdot eta}\right) \cdot h, \frac{1}{2}, h\right)}{eta}\right) \]
          3. associate-/r*N/A

            \[\leadsto \sin^{-1} \left(\frac{\mathsf{fma}\left(\left(sinTheta\_O \cdot \frac{\frac{sinTheta\_O}{eta}}{eta}\right) \cdot h, \frac{1}{2}, h\right)}{eta}\right) \]
          4. lift-/.f32N/A

            \[\leadsto \sin^{-1} \left(\frac{\mathsf{fma}\left(\left(sinTheta\_O \cdot \frac{\frac{sinTheta\_O}{eta}}{eta}\right) \cdot h, \frac{1}{2}, h\right)}{eta}\right) \]
          5. lower-/.f3297.5

            \[\leadsto \sin^{-1} \left(\frac{\mathsf{fma}\left(\left(sinTheta\_O \cdot \frac{\frac{sinTheta\_O}{eta}}{eta}\right) \cdot h, 0.5, h\right)}{eta}\right) \]
        3. Applied rewrites97.5%

          \[\leadsto \sin^{-1} \left(\frac{\mathsf{fma}\left(\left(sinTheta\_O \cdot \frac{\frac{sinTheta\_O}{eta}}{eta}\right) \cdot h, 0.5, h\right)}{eta}\right) \]
        4. Add Preprocessing

        Alternative 4: 95.2% accurate, 3.6× speedup?

        \[\begin{array}{l} \\ \sin^{-1} \left(\frac{h}{eta}\right) \end{array} \]
        (FPCore (sinTheta_O h eta) :precision binary32 (asin (/ h eta)))
        float code(float sinTheta_O, float h, float eta) {
        	return asinf((h / eta));
        }
        
        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(sintheta_o, h, eta)
        use fmin_fmax_functions
            real(4), intent (in) :: sintheta_o
            real(4), intent (in) :: h
            real(4), intent (in) :: eta
            code = asin((h / eta))
        end function
        
        function code(sinTheta_O, h, eta)
        	return asin(Float32(h / eta))
        end
        
        function tmp = code(sinTheta_O, h, eta)
        	tmp = asin((h / eta));
        end
        
        \begin{array}{l}
        
        \\
        \sin^{-1} \left(\frac{h}{eta}\right)
        \end{array}
        
        Derivation
        1. Initial program 92.1%

          \[\sin^{-1} \left(\frac{h}{\sqrt{eta \cdot eta - \frac{sinTheta\_O \cdot sinTheta\_O}{\sqrt{1 - sinTheta\_O \cdot sinTheta\_O}}}}\right) \]
        2. Taylor expanded in sinTheta_O around 0

          \[\leadsto \sin^{-1} \left(\frac{h}{\color{blue}{eta}}\right) \]
        3. Step-by-step derivation
          1. Applied rewrites95.2%

            \[\leadsto \sin^{-1} \left(\frac{h}{\color{blue}{eta}}\right) \]
          2. Add Preprocessing

          Reproduce

          ?
          herbie shell --seed 2025115 
          (FPCore (sinTheta_O h eta)
            :name "HairBSDF, gamma for a refracted ray"
            :precision binary32
            :pre (and (and (and (<= -1.0 sinTheta_O) (<= sinTheta_O 1.0)) (and (<= -1.0 h) (<= h 1.0))) (and (<= 0.0 eta) (<= eta 10.0)))
            (asin (/ h (sqrt (- (* eta eta) (/ (* sinTheta_O sinTheta_O) (sqrt (- 1.0 (* sinTheta_O sinTheta_O)))))))))