Toniolo and Linder, Equation (3b), real

Percentage Accurate: 94.2% → 99.7%
Time: 13.6s
Alternatives: 14
Speedup: 1.2×

Specification

?
\[\begin{array}{l} \\ \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (* (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0)))) (sin th)))
double code(double kx, double ky, double th) {
	return (sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)))) * sin(th);
}
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(8) function code(kx, ky, th)
use fmin_fmax_functions
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    code = (sin(ky) / sqrt(((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)))) * sin(th)
end function
public static double code(double kx, double ky, double th) {
	return (Math.sin(ky) / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)))) * Math.sin(th);
}
def code(kx, ky, th):
	return (math.sin(ky) / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)))) * math.sin(th)
function code(kx, ky, th)
	return Float64(Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) * sin(th))
end
function tmp = code(kx, ky, th)
	tmp = (sin(ky) / sqrt(((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) * sin(th);
end
code[kx_, ky_, th_] := N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 14 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: 94.2% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (* (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0)))) (sin th)))
double code(double kx, double ky, double th) {
	return (sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)))) * sin(th);
}
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(8) function code(kx, ky, th)
use fmin_fmax_functions
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    code = (sin(ky) / sqrt(((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)))) * sin(th)
end function
public static double code(double kx, double ky, double th) {
	return (Math.sin(ky) / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)))) * Math.sin(th);
}
def code(kx, ky, th):
	return (math.sin(ky) / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)))) * math.sin(th)
function code(kx, ky, th)
	return Float64(Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) * sin(th))
end
function tmp = code(kx, ky, th)
	tmp = (sin(ky) / sqrt(((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) * sin(th);
end
code[kx_, ky_, th_] := N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th
\end{array}

Alternative 1: 99.7% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin th \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (* (/ (sin ky) (hypot (sin ky) (sin kx))) (sin th)))
double code(double kx, double ky, double th) {
	return (sin(ky) / hypot(sin(ky), sin(kx))) * sin(th);
}
public static double code(double kx, double ky, double th) {
	return (Math.sin(ky) / Math.hypot(Math.sin(ky), Math.sin(kx))) * Math.sin(th);
}
def code(kx, ky, th):
	return (math.sin(ky) / math.hypot(math.sin(ky), math.sin(kx))) * math.sin(th)
function code(kx, ky, th)
	return Float64(Float64(sin(ky) / hypot(sin(ky), sin(kx))) * sin(th))
end
function tmp = code(kx, ky, th)
	tmp = (sin(ky) / hypot(sin(ky), sin(kx))) * sin(th);
end
code[kx_, ky_, th_] := N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin th
\end{array}
Derivation
  1. Initial program 91.4%

    \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-varN/A

      \[\leadsto \frac{\sin ky}{\sqrt{{\sin \color{blue}{kx}}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. lift-sin.f64N/A

      \[\leadsto \frac{\sin ky}{\sqrt{{\color{blue}{\sin kx}}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    3. lift-literalN/A

      \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{\color{blue}{2}} + {\sin ky}^{2}}} \cdot \sin th \]
    4. lift-pow.f64N/A

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
    5. lift-varN/A

      \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin \color{blue}{ky}}^{2}}} \cdot \sin th \]
    6. lift-sin.f64N/A

      \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\color{blue}{\sin ky}}^{2}}} \cdot \sin th \]
    7. lift-literalN/A

      \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{\color{blue}{2}}}} \cdot \sin th \]
    8. lift-pow.f64N/A

      \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{{\sin ky}^{2}}}} \cdot \sin th \]
    9. lift-+.f64N/A

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
    10. lift-sqrt.f64N/A

      \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
    11. lower-hypot.f64N/A

      \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \cdot \sin th \]
    12. lift-sin.f64N/A

      \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{\sin ky}, \sin kx\right)} \cdot \sin th \]
    13. lift-varN/A

      \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin \color{blue}{ky}, \sin kx\right)} \cdot \sin th \]
    14. lift-sin.f64N/A

      \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \color{blue}{\sin kx}\right)} \cdot \sin th \]
    15. lift-var99.6

      \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin \color{blue}{kx}\right)} \cdot \sin th \]
  4. Applied rewrites99.6%

    \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \cdot \sin th \]
  5. Add Preprocessing

Alternative 2: 55.6% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}\\ \mathbf{if}\;t\_1 \leq -0.9998:\\ \;\;\;\;\sin ky \cdot \frac{th}{\mathsf{hypot}\left(kx, \sin ky\right)}\\ \mathbf{elif}\;t\_1 \leq 2 \cdot 10^{-12}:\\ \;\;\;\;\frac{\sin ky}{\sin kx} \cdot \sin th\\ \mathbf{elif}\;t\_1 \leq 2:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(kx, ky\right)}\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0))))))
   (if (<= t_1 -0.9998)
     (* (sin ky) (/ th (hypot kx (sin ky))))
     (if (<= t_1 2e-12)
       (* (/ (sin ky) (sin kx)) (sin th))
       (if (<= t_1 2.0) (sin th) (* (sin ky) (/ (sin th) (hypot kx ky))))))))
double code(double kx, double ky, double th) {
	double t_1 = sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)));
	double tmp;
	if (t_1 <= -0.9998) {
		tmp = sin(ky) * (th / hypot(kx, sin(ky)));
	} else if (t_1 <= 2e-12) {
		tmp = (sin(ky) / sin(kx)) * sin(th);
	} else if (t_1 <= 2.0) {
		tmp = sin(th);
	} else {
		tmp = sin(ky) * (sin(th) / hypot(kx, ky));
	}
	return tmp;
}
public static double code(double kx, double ky, double th) {
	double t_1 = Math.sin(ky) / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)));
	double tmp;
	if (t_1 <= -0.9998) {
		tmp = Math.sin(ky) * (th / Math.hypot(kx, Math.sin(ky)));
	} else if (t_1 <= 2e-12) {
		tmp = (Math.sin(ky) / Math.sin(kx)) * Math.sin(th);
	} else if (t_1 <= 2.0) {
		tmp = Math.sin(th);
	} else {
		tmp = Math.sin(ky) * (Math.sin(th) / Math.hypot(kx, ky));
	}
	return tmp;
}
def code(kx, ky, th):
	t_1 = math.sin(ky) / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)))
	tmp = 0
	if t_1 <= -0.9998:
		tmp = math.sin(ky) * (th / math.hypot(kx, math.sin(ky)))
	elif t_1 <= 2e-12:
		tmp = (math.sin(ky) / math.sin(kx)) * math.sin(th)
	elif t_1 <= 2.0:
		tmp = math.sin(th)
	else:
		tmp = math.sin(ky) * (math.sin(th) / math.hypot(kx, ky))
	return tmp
function code(kx, ky, th)
	t_1 = Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0))))
	tmp = 0.0
	if (t_1 <= -0.9998)
		tmp = Float64(sin(ky) * Float64(th / hypot(kx, sin(ky))));
	elseif (t_1 <= 2e-12)
		tmp = Float64(Float64(sin(ky) / sin(kx)) * sin(th));
	elseif (t_1 <= 2.0)
		tmp = sin(th);
	else
		tmp = Float64(sin(ky) * Float64(sin(th) / hypot(kx, ky)));
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	t_1 = sin(ky) / sqrt(((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)));
	tmp = 0.0;
	if (t_1 <= -0.9998)
		tmp = sin(ky) * (th / hypot(kx, sin(ky)));
	elseif (t_1 <= 2e-12)
		tmp = (sin(ky) / sin(kx)) * sin(th);
	elseif (t_1 <= 2.0)
		tmp = sin(th);
	else
		tmp = sin(ky) * (sin(th) / hypot(kx, ky));
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := Block[{t$95$1 = N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -0.9998], N[(N[Sin[ky], $MachinePrecision] * N[(th / N[Sqrt[kx ^ 2 + N[Sin[ky], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 2e-12], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 2.0], N[Sin[th], $MachinePrecision], N[(N[Sin[ky], $MachinePrecision] * N[(N[Sin[th], $MachinePrecision] / N[Sqrt[kx ^ 2 + ky ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}\\
\mathbf{if}\;t\_1 \leq -0.9998:\\
\;\;\;\;\sin ky \cdot \frac{th}{\mathsf{hypot}\left(kx, \sin ky\right)}\\

\mathbf{elif}\;t\_1 \leq 2 \cdot 10^{-12}:\\
\;\;\;\;\frac{\sin ky}{\sin kx} \cdot \sin th\\

\mathbf{elif}\;t\_1 \leq 2:\\
\;\;\;\;\sin th\\

\mathbf{else}:\\
\;\;\;\;\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(kx, ky\right)}\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -0.99980000000000002

    1. Initial program 80.9%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Applied rewrites99.7%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}} \]
    4. Taylor expanded in kx around 0

      \[\leadsto \sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\color{blue}{kx}, \sin ky\right)} \]
    5. Step-by-step derivation
      1. Applied rewrites99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\color{blue}{kx}, \sin ky\right)} \]
      2. Taylor expanded in th around 0

        \[\leadsto \sin ky \cdot \frac{\color{blue}{th}}{\mathsf{hypot}\left(kx, \sin ky\right)} \]
      3. Step-by-step derivation
        1. Applied rewrites48.1%

          \[\leadsto \sin ky \cdot \frac{\color{blue}{th}}{\mathsf{hypot}\left(kx, \sin ky\right)} \]

        if -0.99980000000000002 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 1.99999999999999996e-12

        1. Initial program 98.2%

          \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
        2. Add Preprocessing
        3. Taylor expanded in ky around 0

          \[\leadsto \frac{\sin ky}{\color{blue}{\sin kx}} \cdot \sin th \]
        4. Step-by-step derivation
          1. Applied rewrites53.7%

            \[\leadsto \frac{\sin ky}{\color{blue}{\sin kx}} \cdot \sin th \]

          if 1.99999999999999996e-12 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 2

          1. Initial program 98.6%

            \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
          2. Add Preprocessing
          3. Taylor expanded in kx around 0

            \[\leadsto \color{blue}{\sin th} \]
          4. Step-by-step derivation
            1. Applied rewrites65.1%

              \[\leadsto \color{blue}{\sin th} \]

            if 2 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

            1. Initial program 2.7%

              \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
            2. Add Preprocessing
            3. Applied rewrites100.0%

              \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}} \]
            4. Taylor expanded in kx around 0

              \[\leadsto \sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\color{blue}{kx}, \sin ky\right)} \]
            5. Step-by-step derivation
              1. Applied rewrites100.0%

                \[\leadsto \sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\color{blue}{kx}, \sin ky\right)} \]
              2. Taylor expanded in ky around 0

                \[\leadsto \sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(kx, \color{blue}{ky}\right)} \]
              3. Step-by-step derivation
                1. Applied rewrites100.0%

                  \[\leadsto \sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(kx, \color{blue}{ky}\right)} \]
              4. Recombined 4 regimes into one program.
              5. Add Preprocessing

              Alternative 3: 54.5% accurate, 0.5× speedup?

              \[\begin{array}{l} \\ \begin{array}{l} t_1 := \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}\\ \mathbf{if}\;t\_1 \leq -0.9998:\\ \;\;\;\;\sin ky \cdot \frac{th}{\mathsf{hypot}\left(kx, \sin ky\right)}\\ \mathbf{elif}\;t\_1 \leq 2 \cdot 10^{-12}:\\ \;\;\;\;\frac{\sin ky}{\sin kx} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
              (FPCore (kx ky th)
               :precision binary64
               (let* ((t_1 (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0))))))
                 (if (<= t_1 -0.9998)
                   (* (sin ky) (/ th (hypot kx (sin ky))))
                   (if (<= t_1 2e-12) (* (/ (sin ky) (sin kx)) (sin th)) (sin th)))))
              double code(double kx, double ky, double th) {
              	double t_1 = sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)));
              	double tmp;
              	if (t_1 <= -0.9998) {
              		tmp = sin(ky) * (th / hypot(kx, sin(ky)));
              	} else if (t_1 <= 2e-12) {
              		tmp = (sin(ky) / sin(kx)) * sin(th);
              	} else {
              		tmp = sin(th);
              	}
              	return tmp;
              }
              
              public static double code(double kx, double ky, double th) {
              	double t_1 = Math.sin(ky) / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)));
              	double tmp;
              	if (t_1 <= -0.9998) {
              		tmp = Math.sin(ky) * (th / Math.hypot(kx, Math.sin(ky)));
              	} else if (t_1 <= 2e-12) {
              		tmp = (Math.sin(ky) / Math.sin(kx)) * Math.sin(th);
              	} else {
              		tmp = Math.sin(th);
              	}
              	return tmp;
              }
              
              def code(kx, ky, th):
              	t_1 = math.sin(ky) / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)))
              	tmp = 0
              	if t_1 <= -0.9998:
              		tmp = math.sin(ky) * (th / math.hypot(kx, math.sin(ky)))
              	elif t_1 <= 2e-12:
              		tmp = (math.sin(ky) / math.sin(kx)) * math.sin(th)
              	else:
              		tmp = math.sin(th)
              	return tmp
              
              function code(kx, ky, th)
              	t_1 = Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0))))
              	tmp = 0.0
              	if (t_1 <= -0.9998)
              		tmp = Float64(sin(ky) * Float64(th / hypot(kx, sin(ky))));
              	elseif (t_1 <= 2e-12)
              		tmp = Float64(Float64(sin(ky) / sin(kx)) * sin(th));
              	else
              		tmp = sin(th);
              	end
              	return tmp
              end
              
              function tmp_2 = code(kx, ky, th)
              	t_1 = sin(ky) / sqrt(((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)));
              	tmp = 0.0;
              	if (t_1 <= -0.9998)
              		tmp = sin(ky) * (th / hypot(kx, sin(ky)));
              	elseif (t_1 <= 2e-12)
              		tmp = (sin(ky) / sin(kx)) * sin(th);
              	else
              		tmp = sin(th);
              	end
              	tmp_2 = tmp;
              end
              
              code[kx_, ky_, th_] := Block[{t$95$1 = N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -0.9998], N[(N[Sin[ky], $MachinePrecision] * N[(th / N[Sqrt[kx ^ 2 + N[Sin[ky], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 2e-12], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]]
              
              \begin{array}{l}
              
              \\
              \begin{array}{l}
              t_1 := \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}\\
              \mathbf{if}\;t\_1 \leq -0.9998:\\
              \;\;\;\;\sin ky \cdot \frac{th}{\mathsf{hypot}\left(kx, \sin ky\right)}\\
              
              \mathbf{elif}\;t\_1 \leq 2 \cdot 10^{-12}:\\
              \;\;\;\;\frac{\sin ky}{\sin kx} \cdot \sin th\\
              
              \mathbf{else}:\\
              \;\;\;\;\sin th\\
              
              
              \end{array}
              \end{array}
              
              Derivation
              1. Split input into 3 regimes
              2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -0.99980000000000002

                1. Initial program 80.9%

                  \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                2. Add Preprocessing
                3. Applied rewrites99.7%

                  \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}} \]
                4. Taylor expanded in kx around 0

                  \[\leadsto \sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\color{blue}{kx}, \sin ky\right)} \]
                5. Step-by-step derivation
                  1. Applied rewrites99.7%

                    \[\leadsto \sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\color{blue}{kx}, \sin ky\right)} \]
                  2. Taylor expanded in th around 0

                    \[\leadsto \sin ky \cdot \frac{\color{blue}{th}}{\mathsf{hypot}\left(kx, \sin ky\right)} \]
                  3. Step-by-step derivation
                    1. Applied rewrites48.1%

                      \[\leadsto \sin ky \cdot \frac{\color{blue}{th}}{\mathsf{hypot}\left(kx, \sin ky\right)} \]

                    if -0.99980000000000002 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 1.99999999999999996e-12

                    1. Initial program 98.2%

                      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                    2. Add Preprocessing
                    3. Taylor expanded in ky around 0

                      \[\leadsto \frac{\sin ky}{\color{blue}{\sin kx}} \cdot \sin th \]
                    4. Step-by-step derivation
                      1. Applied rewrites53.7%

                        \[\leadsto \frac{\sin ky}{\color{blue}{\sin kx}} \cdot \sin th \]

                      if 1.99999999999999996e-12 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

                      1. Initial program 86.9%

                        \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                      2. Add Preprocessing
                      3. Taylor expanded in kx around 0

                        \[\leadsto \color{blue}{\sin th} \]
                      4. Step-by-step derivation
                        1. Applied rewrites64.4%

                          \[\leadsto \color{blue}{\sin th} \]
                      5. Recombined 3 regimes into one program.
                      6. Add Preprocessing

                      Alternative 4: 45.9% accurate, 0.7× speedup?

                      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 2 \cdot 10^{-12}:\\ \;\;\;\;\frac{\sin ky}{\sin kx} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
                      (FPCore (kx ky th)
                       :precision binary64
                       (if (<= (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0)))) 2e-12)
                         (* (/ (sin ky) (sin kx)) (sin th))
                         (sin th)))
                      double code(double kx, double ky, double th) {
                      	double tmp;
                      	if ((sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)))) <= 2e-12) {
                      		tmp = (sin(ky) / sin(kx)) * sin(th);
                      	} else {
                      		tmp = sin(th);
                      	}
                      	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(8) function code(kx, ky, th)
                      use fmin_fmax_functions
                          real(8), intent (in) :: kx
                          real(8), intent (in) :: ky
                          real(8), intent (in) :: th
                          real(8) :: tmp
                          if ((sin(ky) / sqrt(((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)))) <= 2d-12) then
                              tmp = (sin(ky) / sin(kx)) * sin(th)
                          else
                              tmp = sin(th)
                          end if
                          code = tmp
                      end function
                      
                      public static double code(double kx, double ky, double th) {
                      	double tmp;
                      	if ((Math.sin(ky) / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)))) <= 2e-12) {
                      		tmp = (Math.sin(ky) / Math.sin(kx)) * Math.sin(th);
                      	} else {
                      		tmp = Math.sin(th);
                      	}
                      	return tmp;
                      }
                      
                      def code(kx, ky, th):
                      	tmp = 0
                      	if (math.sin(ky) / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)))) <= 2e-12:
                      		tmp = (math.sin(ky) / math.sin(kx)) * math.sin(th)
                      	else:
                      		tmp = math.sin(th)
                      	return tmp
                      
                      function code(kx, ky, th)
                      	tmp = 0.0
                      	if (Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) <= 2e-12)
                      		tmp = Float64(Float64(sin(ky) / sin(kx)) * sin(th));
                      	else
                      		tmp = sin(th);
                      	end
                      	return tmp
                      end
                      
                      function tmp_2 = code(kx, ky, th)
                      	tmp = 0.0;
                      	if ((sin(ky) / sqrt(((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) <= 2e-12)
                      		tmp = (sin(ky) / sin(kx)) * sin(th);
                      	else
                      		tmp = sin(th);
                      	end
                      	tmp_2 = tmp;
                      end
                      
                      code[kx_, ky_, th_] := If[LessEqual[N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2e-12], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]
                      
                      \begin{array}{l}
                      
                      \\
                      \begin{array}{l}
                      \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 2 \cdot 10^{-12}:\\
                      \;\;\;\;\frac{\sin ky}{\sin kx} \cdot \sin th\\
                      
                      \mathbf{else}:\\
                      \;\;\;\;\sin th\\
                      
                      
                      \end{array}
                      \end{array}
                      
                      Derivation
                      1. Split input into 2 regimes
                      2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 1.99999999999999996e-12

                        1. Initial program 93.9%

                          \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                        2. Add Preprocessing
                        3. Taylor expanded in ky around 0

                          \[\leadsto \frac{\sin ky}{\color{blue}{\sin kx}} \cdot \sin th \]
                        4. Step-by-step derivation
                          1. Applied rewrites41.5%

                            \[\leadsto \frac{\sin ky}{\color{blue}{\sin kx}} \cdot \sin th \]

                          if 1.99999999999999996e-12 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

                          1. Initial program 86.9%

                            \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                          2. Add Preprocessing
                          3. Taylor expanded in kx around 0

                            \[\leadsto \color{blue}{\sin th} \]
                          4. Step-by-step derivation
                            1. Applied rewrites64.4%

                              \[\leadsto \color{blue}{\sin th} \]
                          5. Recombined 2 regimes into one program.
                          6. Add Preprocessing

                          Alternative 5: 45.9% accurate, 0.7× speedup?

                          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 2 \cdot 10^{-12}:\\ \;\;\;\;\sin ky \cdot \frac{\sin th}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
                          (FPCore (kx ky th)
                           :precision binary64
                           (if (<= (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0)))) 2e-12)
                             (* (sin ky) (/ (sin th) (sin kx)))
                             (sin th)))
                          double code(double kx, double ky, double th) {
                          	double tmp;
                          	if ((sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)))) <= 2e-12) {
                          		tmp = sin(ky) * (sin(th) / sin(kx));
                          	} else {
                          		tmp = sin(th);
                          	}
                          	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(8) function code(kx, ky, th)
                          use fmin_fmax_functions
                              real(8), intent (in) :: kx
                              real(8), intent (in) :: ky
                              real(8), intent (in) :: th
                              real(8) :: tmp
                              if ((sin(ky) / sqrt(((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)))) <= 2d-12) then
                                  tmp = sin(ky) * (sin(th) / sin(kx))
                              else
                                  tmp = sin(th)
                              end if
                              code = tmp
                          end function
                          
                          public static double code(double kx, double ky, double th) {
                          	double tmp;
                          	if ((Math.sin(ky) / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)))) <= 2e-12) {
                          		tmp = Math.sin(ky) * (Math.sin(th) / Math.sin(kx));
                          	} else {
                          		tmp = Math.sin(th);
                          	}
                          	return tmp;
                          }
                          
                          def code(kx, ky, th):
                          	tmp = 0
                          	if (math.sin(ky) / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)))) <= 2e-12:
                          		tmp = math.sin(ky) * (math.sin(th) / math.sin(kx))
                          	else:
                          		tmp = math.sin(th)
                          	return tmp
                          
                          function code(kx, ky, th)
                          	tmp = 0.0
                          	if (Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) <= 2e-12)
                          		tmp = Float64(sin(ky) * Float64(sin(th) / sin(kx)));
                          	else
                          		tmp = sin(th);
                          	end
                          	return tmp
                          end
                          
                          function tmp_2 = code(kx, ky, th)
                          	tmp = 0.0;
                          	if ((sin(ky) / sqrt(((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) <= 2e-12)
                          		tmp = sin(ky) * (sin(th) / sin(kx));
                          	else
                          		tmp = sin(th);
                          	end
                          	tmp_2 = tmp;
                          end
                          
                          code[kx_, ky_, th_] := If[LessEqual[N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2e-12], N[(N[Sin[ky], $MachinePrecision] * N[(N[Sin[th], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]
                          
                          \begin{array}{l}
                          
                          \\
                          \begin{array}{l}
                          \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 2 \cdot 10^{-12}:\\
                          \;\;\;\;\sin ky \cdot \frac{\sin th}{\sin kx}\\
                          
                          \mathbf{else}:\\
                          \;\;\;\;\sin th\\
                          
                          
                          \end{array}
                          \end{array}
                          
                          Derivation
                          1. Split input into 2 regimes
                          2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 1.99999999999999996e-12

                            1. Initial program 93.9%

                              \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                            2. Add Preprocessing
                            3. Applied rewrites99.6%

                              \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}} \]
                            4. Taylor expanded in ky around 0

                              \[\leadsto \sin ky \cdot \color{blue}{\frac{\sin th}{\sin kx}} \]
                            5. Step-by-step derivation
                              1. Applied rewrites41.5%

                                \[\leadsto \sin ky \cdot \color{blue}{\frac{\sin th}{\sin kx}} \]

                              if 1.99999999999999996e-12 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

                              1. Initial program 86.9%

                                \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                              2. Add Preprocessing
                              3. Taylor expanded in kx around 0

                                \[\leadsto \color{blue}{\sin th} \]
                              4. Step-by-step derivation
                                1. Applied rewrites64.4%

                                  \[\leadsto \color{blue}{\sin th} \]
                              5. Recombined 2 regimes into one program.
                              6. Add Preprocessing

                              Alternative 6: 44.7% accurate, 0.8× speedup?

                              \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 2 \cdot 10^{-12}:\\ \;\;\;\;ky \cdot \frac{\sin th}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
                              (FPCore (kx ky th)
                               :precision binary64
                               (if (<= (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0)))) 2e-12)
                                 (* ky (/ (sin th) (sin kx)))
                                 (sin th)))
                              double code(double kx, double ky, double th) {
                              	double tmp;
                              	if ((sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)))) <= 2e-12) {
                              		tmp = ky * (sin(th) / sin(kx));
                              	} else {
                              		tmp = sin(th);
                              	}
                              	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(8) function code(kx, ky, th)
                              use fmin_fmax_functions
                                  real(8), intent (in) :: kx
                                  real(8), intent (in) :: ky
                                  real(8), intent (in) :: th
                                  real(8) :: tmp
                                  if ((sin(ky) / sqrt(((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)))) <= 2d-12) then
                                      tmp = ky * (sin(th) / sin(kx))
                                  else
                                      tmp = sin(th)
                                  end if
                                  code = tmp
                              end function
                              
                              public static double code(double kx, double ky, double th) {
                              	double tmp;
                              	if ((Math.sin(ky) / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)))) <= 2e-12) {
                              		tmp = ky * (Math.sin(th) / Math.sin(kx));
                              	} else {
                              		tmp = Math.sin(th);
                              	}
                              	return tmp;
                              }
                              
                              def code(kx, ky, th):
                              	tmp = 0
                              	if (math.sin(ky) / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)))) <= 2e-12:
                              		tmp = ky * (math.sin(th) / math.sin(kx))
                              	else:
                              		tmp = math.sin(th)
                              	return tmp
                              
                              function code(kx, ky, th)
                              	tmp = 0.0
                              	if (Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) <= 2e-12)
                              		tmp = Float64(ky * Float64(sin(th) / sin(kx)));
                              	else
                              		tmp = sin(th);
                              	end
                              	return tmp
                              end
                              
                              function tmp_2 = code(kx, ky, th)
                              	tmp = 0.0;
                              	if ((sin(ky) / sqrt(((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) <= 2e-12)
                              		tmp = ky * (sin(th) / sin(kx));
                              	else
                              		tmp = sin(th);
                              	end
                              	tmp_2 = tmp;
                              end
                              
                              code[kx_, ky_, th_] := If[LessEqual[N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2e-12], N[(ky * N[(N[Sin[th], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]
                              
                              \begin{array}{l}
                              
                              \\
                              \begin{array}{l}
                              \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 2 \cdot 10^{-12}:\\
                              \;\;\;\;ky \cdot \frac{\sin th}{\sin kx}\\
                              
                              \mathbf{else}:\\
                              \;\;\;\;\sin th\\
                              
                              
                              \end{array}
                              \end{array}
                              
                              Derivation
                              1. Split input into 2 regimes
                              2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 1.99999999999999996e-12

                                1. Initial program 93.9%

                                  \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                2. Add Preprocessing
                                3. Applied rewrites99.6%

                                  \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}} \]
                                4. Taylor expanded in ky around 0

                                  \[\leadsto \sin ky \cdot \color{blue}{\frac{\sin th}{\sin kx}} \]
                                5. Step-by-step derivation
                                  1. Applied rewrites41.5%

                                    \[\leadsto \sin ky \cdot \color{blue}{\frac{\sin th}{\sin kx}} \]
                                  2. Taylor expanded in ky around 0

                                    \[\leadsto \color{blue}{ky} \cdot \frac{\sin th}{\sin kx} \]
                                  3. Step-by-step derivation
                                    1. Applied rewrites39.7%

                                      \[\leadsto \color{blue}{ky} \cdot \frac{\sin th}{\sin kx} \]

                                    if 1.99999999999999996e-12 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

                                    1. Initial program 86.9%

                                      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                    2. Add Preprocessing
                                    3. Taylor expanded in kx around 0

                                      \[\leadsto \color{blue}{\sin th} \]
                                    4. Step-by-step derivation
                                      1. Applied rewrites64.4%

                                        \[\leadsto \color{blue}{\sin th} \]
                                    5. Recombined 2 regimes into one program.
                                    6. Add Preprocessing

                                    Alternative 7: 44.1% accurate, 0.8× speedup?

                                    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 2 \cdot 10^{-12}:\\ \;\;\;\;\frac{\sin th \cdot ky}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
                                    (FPCore (kx ky th)
                                     :precision binary64
                                     (if (<= (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0)))) 2e-12)
                                       (/ (* (sin th) ky) (sin kx))
                                       (sin th)))
                                    double code(double kx, double ky, double th) {
                                    	double tmp;
                                    	if ((sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)))) <= 2e-12) {
                                    		tmp = (sin(th) * ky) / sin(kx);
                                    	} else {
                                    		tmp = sin(th);
                                    	}
                                    	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(8) function code(kx, ky, th)
                                    use fmin_fmax_functions
                                        real(8), intent (in) :: kx
                                        real(8), intent (in) :: ky
                                        real(8), intent (in) :: th
                                        real(8) :: tmp
                                        if ((sin(ky) / sqrt(((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)))) <= 2d-12) then
                                            tmp = (sin(th) * ky) / sin(kx)
                                        else
                                            tmp = sin(th)
                                        end if
                                        code = tmp
                                    end function
                                    
                                    public static double code(double kx, double ky, double th) {
                                    	double tmp;
                                    	if ((Math.sin(ky) / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)))) <= 2e-12) {
                                    		tmp = (Math.sin(th) * ky) / Math.sin(kx);
                                    	} else {
                                    		tmp = Math.sin(th);
                                    	}
                                    	return tmp;
                                    }
                                    
                                    def code(kx, ky, th):
                                    	tmp = 0
                                    	if (math.sin(ky) / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)))) <= 2e-12:
                                    		tmp = (math.sin(th) * ky) / math.sin(kx)
                                    	else:
                                    		tmp = math.sin(th)
                                    	return tmp
                                    
                                    function code(kx, ky, th)
                                    	tmp = 0.0
                                    	if (Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) <= 2e-12)
                                    		tmp = Float64(Float64(sin(th) * ky) / sin(kx));
                                    	else
                                    		tmp = sin(th);
                                    	end
                                    	return tmp
                                    end
                                    
                                    function tmp_2 = code(kx, ky, th)
                                    	tmp = 0.0;
                                    	if ((sin(ky) / sqrt(((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) <= 2e-12)
                                    		tmp = (sin(th) * ky) / sin(kx);
                                    	else
                                    		tmp = sin(th);
                                    	end
                                    	tmp_2 = tmp;
                                    end
                                    
                                    code[kx_, ky_, th_] := If[LessEqual[N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2e-12], N[(N[(N[Sin[th], $MachinePrecision] * ky), $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]
                                    
                                    \begin{array}{l}
                                    
                                    \\
                                    \begin{array}{l}
                                    \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 2 \cdot 10^{-12}:\\
                                    \;\;\;\;\frac{\sin th \cdot ky}{\sin kx}\\
                                    
                                    \mathbf{else}:\\
                                    \;\;\;\;\sin th\\
                                    
                                    
                                    \end{array}
                                    \end{array}
                                    
                                    Derivation
                                    1. Split input into 2 regimes
                                    2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 1.99999999999999996e-12

                                      1. Initial program 93.9%

                                        \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                      2. Add Preprocessing
                                      3. Taylor expanded in ky around 0

                                        \[\leadsto \color{blue}{\frac{ky \cdot \sin th}{\sin kx}} \]
                                      4. Step-by-step derivation
                                        1. Applied rewrites38.7%

                                          \[\leadsto \color{blue}{\frac{\sin th \cdot ky}{\sin kx}} \]

                                        if 1.99999999999999996e-12 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

                                        1. Initial program 86.9%

                                          \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                        2. Add Preprocessing
                                        3. Taylor expanded in kx around 0

                                          \[\leadsto \color{blue}{\sin th} \]
                                        4. Step-by-step derivation
                                          1. Applied rewrites64.4%

                                            \[\leadsto \color{blue}{\sin th} \]
                                        5. Recombined 2 regimes into one program.
                                        6. Add Preprocessing

                                        Alternative 8: 36.1% accurate, 1.0× speedup?

                                        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 2 \cdot 10^{-12}:\\ \;\;\;\;\frac{ky}{\sin kx} \cdot th\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
                                        (FPCore (kx ky th)
                                         :precision binary64
                                         (if (<= (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0)))) 2e-12)
                                           (* (/ ky (sin kx)) th)
                                           (sin th)))
                                        double code(double kx, double ky, double th) {
                                        	double tmp;
                                        	if ((sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)))) <= 2e-12) {
                                        		tmp = (ky / sin(kx)) * th;
                                        	} else {
                                        		tmp = sin(th);
                                        	}
                                        	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(8) function code(kx, ky, th)
                                        use fmin_fmax_functions
                                            real(8), intent (in) :: kx
                                            real(8), intent (in) :: ky
                                            real(8), intent (in) :: th
                                            real(8) :: tmp
                                            if ((sin(ky) / sqrt(((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)))) <= 2d-12) then
                                                tmp = (ky / sin(kx)) * th
                                            else
                                                tmp = sin(th)
                                            end if
                                            code = tmp
                                        end function
                                        
                                        public static double code(double kx, double ky, double th) {
                                        	double tmp;
                                        	if ((Math.sin(ky) / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)))) <= 2e-12) {
                                        		tmp = (ky / Math.sin(kx)) * th;
                                        	} else {
                                        		tmp = Math.sin(th);
                                        	}
                                        	return tmp;
                                        }
                                        
                                        def code(kx, ky, th):
                                        	tmp = 0
                                        	if (math.sin(ky) / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)))) <= 2e-12:
                                        		tmp = (ky / math.sin(kx)) * th
                                        	else:
                                        		tmp = math.sin(th)
                                        	return tmp
                                        
                                        function code(kx, ky, th)
                                        	tmp = 0.0
                                        	if (Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) <= 2e-12)
                                        		tmp = Float64(Float64(ky / sin(kx)) * th);
                                        	else
                                        		tmp = sin(th);
                                        	end
                                        	return tmp
                                        end
                                        
                                        function tmp_2 = code(kx, ky, th)
                                        	tmp = 0.0;
                                        	if ((sin(ky) / sqrt(((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) <= 2e-12)
                                        		tmp = (ky / sin(kx)) * th;
                                        	else
                                        		tmp = sin(th);
                                        	end
                                        	tmp_2 = tmp;
                                        end
                                        
                                        code[kx_, ky_, th_] := If[LessEqual[N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2e-12], N[(N[(ky / N[Sin[kx], $MachinePrecision]), $MachinePrecision] * th), $MachinePrecision], N[Sin[th], $MachinePrecision]]
                                        
                                        \begin{array}{l}
                                        
                                        \\
                                        \begin{array}{l}
                                        \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 2 \cdot 10^{-12}:\\
                                        \;\;\;\;\frac{ky}{\sin kx} \cdot th\\
                                        
                                        \mathbf{else}:\\
                                        \;\;\;\;\sin th\\
                                        
                                        
                                        \end{array}
                                        \end{array}
                                        
                                        Derivation
                                        1. Split input into 2 regimes
                                        2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 1.99999999999999996e-12

                                          1. Initial program 93.9%

                                            \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                          2. Add Preprocessing
                                          3. Taylor expanded in ky around 0

                                            \[\leadsto \frac{\sin ky}{\color{blue}{\sin kx}} \cdot \sin th \]
                                          4. Step-by-step derivation
                                            1. Applied rewrites41.5%

                                              \[\leadsto \frac{\sin ky}{\color{blue}{\sin kx}} \cdot \sin th \]
                                            2. Taylor expanded in th around 0

                                              \[\leadsto \frac{\sin ky}{\sin kx} \cdot \color{blue}{th} \]
                                            3. Step-by-step derivation
                                              1. Applied rewrites26.1%

                                                \[\leadsto \frac{\sin ky}{\sin kx} \cdot \color{blue}{th} \]
                                              2. Taylor expanded in ky around 0

                                                \[\leadsto \frac{\color{blue}{ky}}{\sin kx} \cdot th \]
                                              3. Step-by-step derivation
                                                1. Applied rewrites25.3%

                                                  \[\leadsto \frac{\color{blue}{ky}}{\sin kx} \cdot th \]

                                                if 1.99999999999999996e-12 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

                                                1. Initial program 86.9%

                                                  \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                                2. Add Preprocessing
                                                3. Taylor expanded in kx around 0

                                                  \[\leadsto \color{blue}{\sin th} \]
                                                4. Step-by-step derivation
                                                  1. Applied rewrites64.4%

                                                    \[\leadsto \color{blue}{\sin th} \]
                                                5. Recombined 2 regimes into one program.
                                                6. Add Preprocessing

                                                Alternative 9: 33.6% accurate, 1.0× speedup?

                                                \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 5 \cdot 10^{-25}:\\ \;\;\;\;\frac{ky}{kx} \cdot th\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
                                                (FPCore (kx ky th)
                                                 :precision binary64
                                                 (if (<= (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0)))) 5e-25)
                                                   (* (/ ky kx) th)
                                                   (sin th)))
                                                double code(double kx, double ky, double th) {
                                                	double tmp;
                                                	if ((sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)))) <= 5e-25) {
                                                		tmp = (ky / kx) * th;
                                                	} else {
                                                		tmp = sin(th);
                                                	}
                                                	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(8) function code(kx, ky, th)
                                                use fmin_fmax_functions
                                                    real(8), intent (in) :: kx
                                                    real(8), intent (in) :: ky
                                                    real(8), intent (in) :: th
                                                    real(8) :: tmp
                                                    if ((sin(ky) / sqrt(((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)))) <= 5d-25) then
                                                        tmp = (ky / kx) * th
                                                    else
                                                        tmp = sin(th)
                                                    end if
                                                    code = tmp
                                                end function
                                                
                                                public static double code(double kx, double ky, double th) {
                                                	double tmp;
                                                	if ((Math.sin(ky) / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)))) <= 5e-25) {
                                                		tmp = (ky / kx) * th;
                                                	} else {
                                                		tmp = Math.sin(th);
                                                	}
                                                	return tmp;
                                                }
                                                
                                                def code(kx, ky, th):
                                                	tmp = 0
                                                	if (math.sin(ky) / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)))) <= 5e-25:
                                                		tmp = (ky / kx) * th
                                                	else:
                                                		tmp = math.sin(th)
                                                	return tmp
                                                
                                                function code(kx, ky, th)
                                                	tmp = 0.0
                                                	if (Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) <= 5e-25)
                                                		tmp = Float64(Float64(ky / kx) * th);
                                                	else
                                                		tmp = sin(th);
                                                	end
                                                	return tmp
                                                end
                                                
                                                function tmp_2 = code(kx, ky, th)
                                                	tmp = 0.0;
                                                	if ((sin(ky) / sqrt(((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) <= 5e-25)
                                                		tmp = (ky / kx) * th;
                                                	else
                                                		tmp = sin(th);
                                                	end
                                                	tmp_2 = tmp;
                                                end
                                                
                                                code[kx_, ky_, th_] := If[LessEqual[N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 5e-25], N[(N[(ky / kx), $MachinePrecision] * th), $MachinePrecision], N[Sin[th], $MachinePrecision]]
                                                
                                                \begin{array}{l}
                                                
                                                \\
                                                \begin{array}{l}
                                                \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 5 \cdot 10^{-25}:\\
                                                \;\;\;\;\frac{ky}{kx} \cdot th\\
                                                
                                                \mathbf{else}:\\
                                                \;\;\;\;\sin th\\
                                                
                                                
                                                \end{array}
                                                \end{array}
                                                
                                                Derivation
                                                1. Split input into 2 regimes
                                                2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 4.99999999999999962e-25

                                                  1. Initial program 93.8%

                                                    \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                                  2. Add Preprocessing
                                                  3. Taylor expanded in ky around 0

                                                    \[\leadsto \frac{\sin ky}{\color{blue}{\sin kx}} \cdot \sin th \]
                                                  4. Step-by-step derivation
                                                    1. Applied rewrites41.1%

                                                      \[\leadsto \frac{\sin ky}{\color{blue}{\sin kx}} \cdot \sin th \]
                                                    2. Taylor expanded in th around 0

                                                      \[\leadsto \frac{\sin ky}{\sin kx} \cdot \color{blue}{th} \]
                                                    3. Step-by-step derivation
                                                      1. Applied rewrites25.9%

                                                        \[\leadsto \frac{\sin ky}{\sin kx} \cdot \color{blue}{th} \]
                                                      2. Taylor expanded in ky around 0

                                                        \[\leadsto \frac{\color{blue}{ky}}{\sin kx} \cdot th \]
                                                      3. Step-by-step derivation
                                                        1. Applied rewrites25.1%

                                                          \[\leadsto \frac{\color{blue}{ky}}{\sin kx} \cdot th \]
                                                        2. Taylor expanded in kx around 0

                                                          \[\leadsto \frac{ky}{kx} \cdot th \]
                                                        3. Step-by-step derivation
                                                          1. Applied rewrites21.6%

                                                            \[\leadsto \frac{ky}{kx} \cdot th \]

                                                          if 4.99999999999999962e-25 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

                                                          1. Initial program 87.3%

                                                            \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                                          2. Add Preprocessing
                                                          3. Taylor expanded in kx around 0

                                                            \[\leadsto \color{blue}{\sin th} \]
                                                          4. Step-by-step derivation
                                                            1. Applied rewrites62.6%

                                                              \[\leadsto \color{blue}{\sin th} \]
                                                          5. Recombined 2 regimes into one program.
                                                          6. Add Preprocessing

                                                          Alternative 10: 23.2% accurate, 1.2× speedup?

                                                          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 5 \cdot 10^{-25}:\\ \;\;\;\;\frac{ky}{kx} \cdot th\\ \mathbf{else}:\\ \;\;\;\;th\\ \end{array} \end{array} \]
                                                          (FPCore (kx ky th)
                                                           :precision binary64
                                                           (if (<= (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0)))) 5e-25)
                                                             (* (/ ky kx) th)
                                                             th))
                                                          double code(double kx, double ky, double th) {
                                                          	double tmp;
                                                          	if ((sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)))) <= 5e-25) {
                                                          		tmp = (ky / kx) * th;
                                                          	} else {
                                                          		tmp = th;
                                                          	}
                                                          	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(8) function code(kx, ky, th)
                                                          use fmin_fmax_functions
                                                              real(8), intent (in) :: kx
                                                              real(8), intent (in) :: ky
                                                              real(8), intent (in) :: th
                                                              real(8) :: tmp
                                                              if ((sin(ky) / sqrt(((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)))) <= 5d-25) then
                                                                  tmp = (ky / kx) * th
                                                              else
                                                                  tmp = th
                                                              end if
                                                              code = tmp
                                                          end function
                                                          
                                                          public static double code(double kx, double ky, double th) {
                                                          	double tmp;
                                                          	if ((Math.sin(ky) / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)))) <= 5e-25) {
                                                          		tmp = (ky / kx) * th;
                                                          	} else {
                                                          		tmp = th;
                                                          	}
                                                          	return tmp;
                                                          }
                                                          
                                                          def code(kx, ky, th):
                                                          	tmp = 0
                                                          	if (math.sin(ky) / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)))) <= 5e-25:
                                                          		tmp = (ky / kx) * th
                                                          	else:
                                                          		tmp = th
                                                          	return tmp
                                                          
                                                          function code(kx, ky, th)
                                                          	tmp = 0.0
                                                          	if (Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) <= 5e-25)
                                                          		tmp = Float64(Float64(ky / kx) * th);
                                                          	else
                                                          		tmp = th;
                                                          	end
                                                          	return tmp
                                                          end
                                                          
                                                          function tmp_2 = code(kx, ky, th)
                                                          	tmp = 0.0;
                                                          	if ((sin(ky) / sqrt(((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) <= 5e-25)
                                                          		tmp = (ky / kx) * th;
                                                          	else
                                                          		tmp = th;
                                                          	end
                                                          	tmp_2 = tmp;
                                                          end
                                                          
                                                          code[kx_, ky_, th_] := If[LessEqual[N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 5e-25], N[(N[(ky / kx), $MachinePrecision] * th), $MachinePrecision], th]
                                                          
                                                          \begin{array}{l}
                                                          
                                                          \\
                                                          \begin{array}{l}
                                                          \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 5 \cdot 10^{-25}:\\
                                                          \;\;\;\;\frac{ky}{kx} \cdot th\\
                                                          
                                                          \mathbf{else}:\\
                                                          \;\;\;\;th\\
                                                          
                                                          
                                                          \end{array}
                                                          \end{array}
                                                          
                                                          Derivation
                                                          1. Split input into 2 regimes
                                                          2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 4.99999999999999962e-25

                                                            1. Initial program 93.8%

                                                              \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                                            2. Add Preprocessing
                                                            3. Taylor expanded in ky around 0

                                                              \[\leadsto \frac{\sin ky}{\color{blue}{\sin kx}} \cdot \sin th \]
                                                            4. Step-by-step derivation
                                                              1. Applied rewrites41.1%

                                                                \[\leadsto \frac{\sin ky}{\color{blue}{\sin kx}} \cdot \sin th \]
                                                              2. Taylor expanded in th around 0

                                                                \[\leadsto \frac{\sin ky}{\sin kx} \cdot \color{blue}{th} \]
                                                              3. Step-by-step derivation
                                                                1. Applied rewrites25.9%

                                                                  \[\leadsto \frac{\sin ky}{\sin kx} \cdot \color{blue}{th} \]
                                                                2. Taylor expanded in ky around 0

                                                                  \[\leadsto \frac{\color{blue}{ky}}{\sin kx} \cdot th \]
                                                                3. Step-by-step derivation
                                                                  1. Applied rewrites25.1%

                                                                    \[\leadsto \frac{\color{blue}{ky}}{\sin kx} \cdot th \]
                                                                  2. Taylor expanded in kx around 0

                                                                    \[\leadsto \frac{ky}{kx} \cdot th \]
                                                                  3. Step-by-step derivation
                                                                    1. Applied rewrites21.6%

                                                                      \[\leadsto \frac{ky}{kx} \cdot th \]

                                                                    if 4.99999999999999962e-25 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

                                                                    1. Initial program 87.3%

                                                                      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                                                    2. Add Preprocessing
                                                                    3. Taylor expanded in kx around 0

                                                                      \[\leadsto \color{blue}{\sin th} \]
                                                                    4. Step-by-step derivation
                                                                      1. Applied rewrites62.6%

                                                                        \[\leadsto \color{blue}{\sin th} \]
                                                                      2. Taylor expanded in th around 0

                                                                        \[\leadsto th \]
                                                                      3. Step-by-step derivation
                                                                        1. Applied rewrites31.3%

                                                                          \[\leadsto th \]
                                                                      4. Recombined 2 regimes into one program.
                                                                      5. Add Preprocessing

                                                                      Alternative 11: 99.6% accurate, 1.2× speedup?

                                                                      \[\begin{array}{l} \\ \sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin kx, \sin ky\right)} \end{array} \]
                                                                      (FPCore (kx ky th)
                                                                       :precision binary64
                                                                       (* (sin ky) (/ (sin th) (hypot (sin kx) (sin ky)))))
                                                                      double code(double kx, double ky, double th) {
                                                                      	return sin(ky) * (sin(th) / hypot(sin(kx), sin(ky)));
                                                                      }
                                                                      
                                                                      public static double code(double kx, double ky, double th) {
                                                                      	return Math.sin(ky) * (Math.sin(th) / Math.hypot(Math.sin(kx), Math.sin(ky)));
                                                                      }
                                                                      
                                                                      def code(kx, ky, th):
                                                                      	return math.sin(ky) * (math.sin(th) / math.hypot(math.sin(kx), math.sin(ky)))
                                                                      
                                                                      function code(kx, ky, th)
                                                                      	return Float64(sin(ky) * Float64(sin(th) / hypot(sin(kx), sin(ky))))
                                                                      end
                                                                      
                                                                      function tmp = code(kx, ky, th)
                                                                      	tmp = sin(ky) * (sin(th) / hypot(sin(kx), sin(ky)));
                                                                      end
                                                                      
                                                                      code[kx_, ky_, th_] := N[(N[Sin[ky], $MachinePrecision] * N[(N[Sin[th], $MachinePrecision] / N[Sqrt[N[Sin[kx], $MachinePrecision] ^ 2 + N[Sin[ky], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
                                                                      
                                                                      \begin{array}{l}
                                                                      
                                                                      \\
                                                                      \sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}
                                                                      \end{array}
                                                                      
                                                                      Derivation
                                                                      1. Initial program 91.4%

                                                                        \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                                                      2. Add Preprocessing
                                                                      3. Applied rewrites99.6%

                                                                        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}} \]
                                                                      4. Add Preprocessing

                                                                      Alternative 12: 66.3% accurate, 1.5× speedup?

                                                                      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;th \leq 4.9 \cdot 10^{-5}:\\ \;\;\;\;\sin ky \cdot \frac{th}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin th \cdot ky}{\mathsf{hypot}\left(\sin kx, ky\right)}\\ \end{array} \end{array} \]
                                                                      (FPCore (kx ky th)
                                                                       :precision binary64
                                                                       (if (<= th 4.9e-5)
                                                                         (* (sin ky) (/ th (hypot (sin kx) (sin ky))))
                                                                         (/ (* (sin th) ky) (hypot (sin kx) ky))))
                                                                      double code(double kx, double ky, double th) {
                                                                      	double tmp;
                                                                      	if (th <= 4.9e-5) {
                                                                      		tmp = sin(ky) * (th / hypot(sin(kx), sin(ky)));
                                                                      	} else {
                                                                      		tmp = (sin(th) * ky) / hypot(sin(kx), ky);
                                                                      	}
                                                                      	return tmp;
                                                                      }
                                                                      
                                                                      public static double code(double kx, double ky, double th) {
                                                                      	double tmp;
                                                                      	if (th <= 4.9e-5) {
                                                                      		tmp = Math.sin(ky) * (th / Math.hypot(Math.sin(kx), Math.sin(ky)));
                                                                      	} else {
                                                                      		tmp = (Math.sin(th) * ky) / Math.hypot(Math.sin(kx), ky);
                                                                      	}
                                                                      	return tmp;
                                                                      }
                                                                      
                                                                      def code(kx, ky, th):
                                                                      	tmp = 0
                                                                      	if th <= 4.9e-5:
                                                                      		tmp = math.sin(ky) * (th / math.hypot(math.sin(kx), math.sin(ky)))
                                                                      	else:
                                                                      		tmp = (math.sin(th) * ky) / math.hypot(math.sin(kx), ky)
                                                                      	return tmp
                                                                      
                                                                      function code(kx, ky, th)
                                                                      	tmp = 0.0
                                                                      	if (th <= 4.9e-5)
                                                                      		tmp = Float64(sin(ky) * Float64(th / hypot(sin(kx), sin(ky))));
                                                                      	else
                                                                      		tmp = Float64(Float64(sin(th) * ky) / hypot(sin(kx), ky));
                                                                      	end
                                                                      	return tmp
                                                                      end
                                                                      
                                                                      function tmp_2 = code(kx, ky, th)
                                                                      	tmp = 0.0;
                                                                      	if (th <= 4.9e-5)
                                                                      		tmp = sin(ky) * (th / hypot(sin(kx), sin(ky)));
                                                                      	else
                                                                      		tmp = (sin(th) * ky) / hypot(sin(kx), ky);
                                                                      	end
                                                                      	tmp_2 = tmp;
                                                                      end
                                                                      
                                                                      code[kx_, ky_, th_] := If[LessEqual[th, 4.9e-5], N[(N[Sin[ky], $MachinePrecision] * N[(th / N[Sqrt[N[Sin[kx], $MachinePrecision] ^ 2 + N[Sin[ky], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Sin[th], $MachinePrecision] * ky), $MachinePrecision] / N[Sqrt[N[Sin[kx], $MachinePrecision] ^ 2 + ky ^ 2], $MachinePrecision]), $MachinePrecision]]
                                                                      
                                                                      \begin{array}{l}
                                                                      
                                                                      \\
                                                                      \begin{array}{l}
                                                                      \mathbf{if}\;th \leq 4.9 \cdot 10^{-5}:\\
                                                                      \;\;\;\;\sin ky \cdot \frac{th}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}\\
                                                                      
                                                                      \mathbf{else}:\\
                                                                      \;\;\;\;\frac{\sin th \cdot ky}{\mathsf{hypot}\left(\sin kx, ky\right)}\\
                                                                      
                                                                      
                                                                      \end{array}
                                                                      \end{array}
                                                                      
                                                                      Derivation
                                                                      1. Split input into 2 regimes
                                                                      2. if th < 4.9e-5

                                                                        1. Initial program 90.9%

                                                                          \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                                                        2. Add Preprocessing
                                                                        3. Applied rewrites99.7%

                                                                          \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}} \]
                                                                        4. Taylor expanded in th around 0

                                                                          \[\leadsto \sin ky \cdot \frac{\color{blue}{th}}{\mathsf{hypot}\left(\sin kx, \sin ky\right)} \]
                                                                        5. Step-by-step derivation
                                                                          1. Applied rewrites62.5%

                                                                            \[\leadsto \sin ky \cdot \frac{\color{blue}{th}}{\mathsf{hypot}\left(\sin kx, \sin ky\right)} \]

                                                                          if 4.9e-5 < th

                                                                          1. Initial program 93.4%

                                                                            \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                                                          2. Add Preprocessing
                                                                          3. Applied rewrites99.3%

                                                                            \[\leadsto \color{blue}{\frac{\sin th \cdot \sin ky}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}} \]
                                                                          4. Taylor expanded in ky around 0

                                                                            \[\leadsto \frac{\sin th \cdot \sin ky}{\mathsf{hypot}\left(\sin kx, \color{blue}{ky}\right)} \]
                                                                          5. Step-by-step derivation
                                                                            1. Applied rewrites58.1%

                                                                              \[\leadsto \frac{\sin th \cdot \sin ky}{\mathsf{hypot}\left(\sin kx, \color{blue}{ky}\right)} \]
                                                                            2. Taylor expanded in ky around 0

                                                                              \[\leadsto \frac{\sin th \cdot \color{blue}{ky}}{\mathsf{hypot}\left(\sin kx, ky\right)} \]
                                                                            3. Step-by-step derivation
                                                                              1. Applied rewrites69.7%

                                                                                \[\leadsto \frac{\sin th \cdot \color{blue}{ky}}{\mathsf{hypot}\left(\sin kx, ky\right)} \]
                                                                            4. Recombined 2 regimes into one program.
                                                                            5. Add Preprocessing

                                                                            Alternative 13: 49.4% accurate, 2.0× speedup?

                                                                            \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;th \leq 7.5 \cdot 10^{-93}:\\ \;\;\;\;\sin ky \cdot \frac{th}{\mathsf{hypot}\left(kx, \sin ky\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin th \cdot ky}{\mathsf{hypot}\left(\sin kx, ky\right)}\\ \end{array} \end{array} \]
                                                                            (FPCore (kx ky th)
                                                                             :precision binary64
                                                                             (if (<= th 7.5e-93)
                                                                               (* (sin ky) (/ th (hypot kx (sin ky))))
                                                                               (/ (* (sin th) ky) (hypot (sin kx) ky))))
                                                                            double code(double kx, double ky, double th) {
                                                                            	double tmp;
                                                                            	if (th <= 7.5e-93) {
                                                                            		tmp = sin(ky) * (th / hypot(kx, sin(ky)));
                                                                            	} else {
                                                                            		tmp = (sin(th) * ky) / hypot(sin(kx), ky);
                                                                            	}
                                                                            	return tmp;
                                                                            }
                                                                            
                                                                            public static double code(double kx, double ky, double th) {
                                                                            	double tmp;
                                                                            	if (th <= 7.5e-93) {
                                                                            		tmp = Math.sin(ky) * (th / Math.hypot(kx, Math.sin(ky)));
                                                                            	} else {
                                                                            		tmp = (Math.sin(th) * ky) / Math.hypot(Math.sin(kx), ky);
                                                                            	}
                                                                            	return tmp;
                                                                            }
                                                                            
                                                                            def code(kx, ky, th):
                                                                            	tmp = 0
                                                                            	if th <= 7.5e-93:
                                                                            		tmp = math.sin(ky) * (th / math.hypot(kx, math.sin(ky)))
                                                                            	else:
                                                                            		tmp = (math.sin(th) * ky) / math.hypot(math.sin(kx), ky)
                                                                            	return tmp
                                                                            
                                                                            function code(kx, ky, th)
                                                                            	tmp = 0.0
                                                                            	if (th <= 7.5e-93)
                                                                            		tmp = Float64(sin(ky) * Float64(th / hypot(kx, sin(ky))));
                                                                            	else
                                                                            		tmp = Float64(Float64(sin(th) * ky) / hypot(sin(kx), ky));
                                                                            	end
                                                                            	return tmp
                                                                            end
                                                                            
                                                                            function tmp_2 = code(kx, ky, th)
                                                                            	tmp = 0.0;
                                                                            	if (th <= 7.5e-93)
                                                                            		tmp = sin(ky) * (th / hypot(kx, sin(ky)));
                                                                            	else
                                                                            		tmp = (sin(th) * ky) / hypot(sin(kx), ky);
                                                                            	end
                                                                            	tmp_2 = tmp;
                                                                            end
                                                                            
                                                                            code[kx_, ky_, th_] := If[LessEqual[th, 7.5e-93], N[(N[Sin[ky], $MachinePrecision] * N[(th / N[Sqrt[kx ^ 2 + N[Sin[ky], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Sin[th], $MachinePrecision] * ky), $MachinePrecision] / N[Sqrt[N[Sin[kx], $MachinePrecision] ^ 2 + ky ^ 2], $MachinePrecision]), $MachinePrecision]]
                                                                            
                                                                            \begin{array}{l}
                                                                            
                                                                            \\
                                                                            \begin{array}{l}
                                                                            \mathbf{if}\;th \leq 7.5 \cdot 10^{-93}:\\
                                                                            \;\;\;\;\sin ky \cdot \frac{th}{\mathsf{hypot}\left(kx, \sin ky\right)}\\
                                                                            
                                                                            \mathbf{else}:\\
                                                                            \;\;\;\;\frac{\sin th \cdot ky}{\mathsf{hypot}\left(\sin kx, ky\right)}\\
                                                                            
                                                                            
                                                                            \end{array}
                                                                            \end{array}
                                                                            
                                                                            Derivation
                                                                            1. Split input into 2 regimes
                                                                            2. if th < 7.50000000000000034e-93

                                                                              1. Initial program 90.5%

                                                                                \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                                                              2. Add Preprocessing
                                                                              3. Applied rewrites99.6%

                                                                                \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}} \]
                                                                              4. Taylor expanded in kx around 0

                                                                                \[\leadsto \sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\color{blue}{kx}, \sin ky\right)} \]
                                                                              5. Step-by-step derivation
                                                                                1. Applied rewrites57.3%

                                                                                  \[\leadsto \sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\color{blue}{kx}, \sin ky\right)} \]
                                                                                2. Taylor expanded in th around 0

                                                                                  \[\leadsto \sin ky \cdot \frac{\color{blue}{th}}{\mathsf{hypot}\left(kx, \sin ky\right)} \]
                                                                                3. Step-by-step derivation
                                                                                  1. Applied rewrites40.2%

                                                                                    \[\leadsto \sin ky \cdot \frac{\color{blue}{th}}{\mathsf{hypot}\left(kx, \sin ky\right)} \]

                                                                                  if 7.50000000000000034e-93 < th

                                                                                  1. Initial program 93.6%

                                                                                    \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                                                                  2. Add Preprocessing
                                                                                  3. Applied rewrites99.4%

                                                                                    \[\leadsto \color{blue}{\frac{\sin th \cdot \sin ky}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}} \]
                                                                                  4. Taylor expanded in ky around 0

                                                                                    \[\leadsto \frac{\sin th \cdot \sin ky}{\mathsf{hypot}\left(\sin kx, \color{blue}{ky}\right)} \]
                                                                                  5. Step-by-step derivation
                                                                                    1. Applied rewrites61.8%

                                                                                      \[\leadsto \frac{\sin th \cdot \sin ky}{\mathsf{hypot}\left(\sin kx, \color{blue}{ky}\right)} \]
                                                                                    2. Taylor expanded in ky around 0

                                                                                      \[\leadsto \frac{\sin th \cdot \color{blue}{ky}}{\mathsf{hypot}\left(\sin kx, ky\right)} \]
                                                                                    3. Step-by-step derivation
                                                                                      1. Applied rewrites75.3%

                                                                                        \[\leadsto \frac{\sin th \cdot \color{blue}{ky}}{\mathsf{hypot}\left(\sin kx, ky\right)} \]
                                                                                    4. Recombined 2 regimes into one program.
                                                                                    5. Add Preprocessing

                                                                                    Alternative 14: 13.6% accurate, 632.0× speedup?

                                                                                    \[\begin{array}{l} \\ th \end{array} \]
                                                                                    (FPCore (kx ky th) :precision binary64 th)
                                                                                    double code(double kx, double ky, double th) {
                                                                                    	return th;
                                                                                    }
                                                                                    
                                                                                    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(8) function code(kx, ky, th)
                                                                                    use fmin_fmax_functions
                                                                                        real(8), intent (in) :: kx
                                                                                        real(8), intent (in) :: ky
                                                                                        real(8), intent (in) :: th
                                                                                        code = th
                                                                                    end function
                                                                                    
                                                                                    public static double code(double kx, double ky, double th) {
                                                                                    	return th;
                                                                                    }
                                                                                    
                                                                                    def code(kx, ky, th):
                                                                                    	return th
                                                                                    
                                                                                    function code(kx, ky, th)
                                                                                    	return th
                                                                                    end
                                                                                    
                                                                                    function tmp = code(kx, ky, th)
                                                                                    	tmp = th;
                                                                                    end
                                                                                    
                                                                                    code[kx_, ky_, th_] := th
                                                                                    
                                                                                    \begin{array}{l}
                                                                                    
                                                                                    \\
                                                                                    th
                                                                                    \end{array}
                                                                                    
                                                                                    Derivation
                                                                                    1. Initial program 91.4%

                                                                                      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                                                                    2. Add Preprocessing
                                                                                    3. Taylor expanded in kx around 0

                                                                                      \[\leadsto \color{blue}{\sin th} \]
                                                                                    4. Step-by-step derivation
                                                                                      1. Applied rewrites25.0%

                                                                                        \[\leadsto \color{blue}{\sin th} \]
                                                                                      2. Taylor expanded in th around 0

                                                                                        \[\leadsto th \]
                                                                                      3. Step-by-step derivation
                                                                                        1. Applied rewrites13.7%

                                                                                          \[\leadsto th \]
                                                                                        2. Add Preprocessing

                                                                                        Reproduce

                                                                                        ?
                                                                                        herbie shell --seed 2025021 
                                                                                        (FPCore (kx ky th)
                                                                                          :name "Toniolo and Linder, Equation (3b), real"
                                                                                          :precision binary64
                                                                                          (* (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0)))) (sin th)))