HairBSDF, gamma for a refracted ray

Percentage Accurate: 91.9% → 98.7%
Time: 5.2s
Alternatives: 3
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)\]
\[\sin^{-1} \left(\frac{h}{\sqrt{eta \cdot eta - \frac{sinTheta\_O \cdot sinTheta\_O}{\sqrt{1 - sinTheta\_O \cdot sinTheta\_O}}}}\right) \]
(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
\sin^{-1} \left(\frac{h}{\sqrt{eta \cdot eta - \frac{sinTheta\_O \cdot sinTheta\_O}{\sqrt{1 - sinTheta\_O \cdot sinTheta\_O}}}}\right)

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

\[\sin^{-1} \left(\frac{h}{\sqrt{eta \cdot eta - \frac{sinTheta\_O \cdot sinTheta\_O}{\sqrt{1 - sinTheta\_O \cdot sinTheta\_O}}}}\right) \]
(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
\sin^{-1} \left(\frac{h}{\sqrt{eta \cdot eta - \frac{sinTheta\_O \cdot sinTheta\_O}{\sqrt{1 - sinTheta\_O \cdot sinTheta\_O}}}}\right)

Alternative 1: 98.7% accurate, 0.8× speedup?

\[\begin{array}{l} t_0 := \left|sinTheta\_O\right| \cdot \left|sinTheta\_O\right|\\ \mathbf{if}\;\left|sinTheta\_O\right| \leq 2.5000000488537034 \cdot 10^{-25}:\\ \;\;\;\;\sin^{-1} \left(\frac{h}{eta}\right)\\ \mathbf{else}:\\ \;\;\;\;\sin^{-1} \left(\frac{h}{\sqrt{eta \cdot eta - \frac{t\_0}{\sqrt{1 - t\_0}}}}\right)\\ \end{array} \]
(FPCore (sinTheta_O h eta)
 :precision binary32
 (let* ((t_0 (* (fabs sinTheta_O) (fabs sinTheta_O))))
   (if (<= (fabs sinTheta_O) 2.5000000488537034e-25)
     (asin (/ h eta))
     (asin (/ h (sqrt (- (* eta eta) (/ t_0 (sqrt (- 1.0 t_0))))))))))
float code(float sinTheta_O, float h, float eta) {
	float t_0 = fabsf(sinTheta_O) * fabsf(sinTheta_O);
	float tmp;
	if (fabsf(sinTheta_O) <= 2.5000000488537034e-25f) {
		tmp = asinf((h / eta));
	} else {
		tmp = asinf((h / sqrtf(((eta * eta) - (t_0 / sqrtf((1.0f - t_0)))))));
	}
	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) :: t_0
    real(4) :: tmp
    t_0 = abs(sintheta_o) * abs(sintheta_o)
    if (abs(sintheta_o) <= 2.5000000488537034e-25) then
        tmp = asin((h / eta))
    else
        tmp = asin((h / sqrt(((eta * eta) - (t_0 / sqrt((1.0e0 - t_0)))))))
    end if
    code = tmp
end function
function code(sinTheta_O, h, eta)
	t_0 = Float32(abs(sinTheta_O) * abs(sinTheta_O))
	tmp = Float32(0.0)
	if (abs(sinTheta_O) <= Float32(2.5000000488537034e-25))
		tmp = asin(Float32(h / eta));
	else
		tmp = asin(Float32(h / sqrt(Float32(Float32(eta * eta) - Float32(t_0 / sqrt(Float32(Float32(1.0) - t_0)))))));
	end
	return tmp
end
function tmp_2 = code(sinTheta_O, h, eta)
	t_0 = abs(sinTheta_O) * abs(sinTheta_O);
	tmp = single(0.0);
	if (abs(sinTheta_O) <= single(2.5000000488537034e-25))
		tmp = asin((h / eta));
	else
		tmp = asin((h / sqrt(((eta * eta) - (t_0 / sqrt((single(1.0) - t_0)))))));
	end
	tmp_2 = tmp;
end
\begin{array}{l}
t_0 := \left|sinTheta\_O\right| \cdot \left|sinTheta\_O\right|\\
\mathbf{if}\;\left|sinTheta\_O\right| \leq 2.5000000488537034 \cdot 10^{-25}:\\
\;\;\;\;\sin^{-1} \left(\frac{h}{eta}\right)\\

\mathbf{else}:\\
\;\;\;\;\sin^{-1} \left(\frac{h}{\sqrt{eta \cdot eta - \frac{t\_0}{\sqrt{1 - t\_0}}}}\right)\\


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if sinTheta_O < 2.50000005e-25

    1. Initial program 91.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 eta around inf

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

        \[\leadsto \sin^{-1} \left(\frac{h}{\color{blue}{eta}}\right) \]
    4. Applied rewrites95.5%

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

    if 2.50000005e-25 < sinTheta_O

    1. Initial program 91.9%

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

Alternative 2: 98.6% accurate, 1.2× speedup?

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

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


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if sinTheta_O < 2.50000005e-25

    1. Initial program 91.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 eta around inf

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

        \[\leadsto \sin^{-1} \left(\frac{h}{\color{blue}{eta}}\right) \]
    4. Applied rewrites95.5%

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

    if 2.50000005e-25 < sinTheta_O

    1. Initial program 91.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}{\sqrt{eta \cdot eta - \frac{sinTheta\_O \cdot sinTheta\_O}{\color{blue}{1}}}}\right) \]
    3. Step-by-step derivation
      1. Applied rewrites91.8%

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

          \[\leadsto \sin^{-1} \left(\frac{h}{\sqrt{\color{blue}{eta \cdot eta - \frac{sinTheta\_O \cdot sinTheta\_O}{1}}}}\right) \]
        2. sub-flipN/A

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

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

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

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

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

          \[\leadsto \sin^{-1} \left(\frac{h}{\sqrt{\mathsf{fma}\left(eta, eta, \mathsf{neg}\left(\color{blue}{\frac{sinTheta\_O}{1} \cdot sinTheta\_O}\right)\right)}}\right) \]
        8. distribute-rgt-neg-inN/A

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

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

          \[\leadsto \sin^{-1} \left(\frac{h}{\sqrt{\mathsf{fma}\left(eta, eta, \color{blue}{\frac{sinTheta\_O}{1}} \cdot \left(\mathsf{neg}\left(sinTheta\_O\right)\right)\right)}}\right) \]
        11. lower-neg.f3291.8%

          \[\leadsto \sin^{-1} \left(\frac{h}{\sqrt{\mathsf{fma}\left(eta, eta, \frac{sinTheta\_O}{1} \cdot \color{blue}{\left(-sinTheta\_O\right)}\right)}}\right) \]
      3. Applied rewrites91.8%

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

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

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

      Alternative 3: 95.5% accurate, 3.6× speedup?

      \[\sin^{-1} \left(\frac{h}{eta}\right) \]
      (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
      
      \sin^{-1} \left(\frac{h}{eta}\right)
      
      Derivation
      1. Initial program 91.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 eta around inf

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

          \[\leadsto \sin^{-1} \left(\frac{h}{\color{blue}{eta}}\right) \]
      4. Applied rewrites95.5%

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

      Reproduce

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