Toniolo and Linder, Equation (3b), real

Percentage Accurate: 93.8% → 99.7%
Time: 14.2s
Alternatives: 27
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);
}
real(8) function code(kx, ky, th)
    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 27 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: 93.8% 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);
}
real(8) function code(kx, ky, th)
    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 94.6%

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

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

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

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

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

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

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

      \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \cdot \sin th \]
    8. lower-hypot.f6499.7

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

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

Alternative 2: 78.6% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}\\ t_2 := \cos \left(ky + ky\right)\\ t_3 := \sin th \cdot \frac{\sin ky}{\mathsf{hypot}\left(\mathsf{fma}\left(ky, -0.16666666666666666 \cdot \left(ky \cdot ky\right), ky\right), \sin kx\right)}\\ \mathbf{if}\;t\_1 \leq -1:\\ \;\;\;\;\frac{\sin th}{\frac{\sqrt{kx \cdot kx + \mathsf{fma}\left(t\_2, -0.5, 0.5\right)}}{\sin ky}}\\ \mathbf{elif}\;t\_1 \leq -0.18:\\ \;\;\;\;\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, 0.5 + -0.5 \cdot t\_2\right)}} \cdot \left(\sin ky \cdot th\right)\\ \mathbf{elif}\;t\_1 \leq 0.35:\\ \;\;\;\;t\_3\\ \mathbf{elif}\;t\_1 \leq 0.999998:\\ \;\;\;\;th \cdot \left(\sqrt{\frac{1}{\mathsf{fma}\left(0.5, 1 - \cos \left(kx \cdot -2\right), \mathsf{fma}\left(-0.5, \cos \left(ky \cdot -2\right), 0.5\right)\right)}} \cdot \sin ky\right)\\ \mathbf{elif}\;t\_1 \leq 1:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;t\_3\\ \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)))))
        (t_2 (cos (+ ky ky)))
        (t_3
         (*
          (sin th)
          (/
           (sin ky)
           (hypot (fma ky (* -0.16666666666666666 (* ky ky)) ky) (sin kx))))))
   (if (<= t_1 -1.0)
     (/ (sin th) (/ (sqrt (+ (* kx kx) (fma t_2 -0.5 0.5))) (sin ky)))
     (if (<= t_1 -0.18)
       (*
        (sqrt (/ 1.0 (fma (- 1.0 (cos (+ kx kx))) 0.5 (+ 0.5 (* -0.5 t_2)))))
        (* (sin ky) th))
       (if (<= t_1 0.35)
         t_3
         (if (<= t_1 0.999998)
           (*
            th
            (*
             (sqrt
              (/
               1.0
               (fma
                0.5
                (- 1.0 (cos (* kx -2.0)))
                (fma -0.5 (cos (* ky -2.0)) 0.5))))
             (sin ky)))
           (if (<= t_1 1.0) (sin th) t_3)))))))
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 t_2 = cos((ky + ky));
	double t_3 = sin(th) * (sin(ky) / hypot(fma(ky, (-0.16666666666666666 * (ky * ky)), ky), sin(kx)));
	double tmp;
	if (t_1 <= -1.0) {
		tmp = sin(th) / (sqrt(((kx * kx) + fma(t_2, -0.5, 0.5))) / sin(ky));
	} else if (t_1 <= -0.18) {
		tmp = sqrt((1.0 / fma((1.0 - cos((kx + kx))), 0.5, (0.5 + (-0.5 * t_2))))) * (sin(ky) * th);
	} else if (t_1 <= 0.35) {
		tmp = t_3;
	} else if (t_1 <= 0.999998) {
		tmp = th * (sqrt((1.0 / fma(0.5, (1.0 - cos((kx * -2.0))), fma(-0.5, cos((ky * -2.0)), 0.5)))) * sin(ky));
	} else if (t_1 <= 1.0) {
		tmp = sin(th);
	} else {
		tmp = t_3;
	}
	return tmp;
}
function code(kx, ky, th)
	t_1 = Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0))))
	t_2 = cos(Float64(ky + ky))
	t_3 = Float64(sin(th) * Float64(sin(ky) / hypot(fma(ky, Float64(-0.16666666666666666 * Float64(ky * ky)), ky), sin(kx))))
	tmp = 0.0
	if (t_1 <= -1.0)
		tmp = Float64(sin(th) / Float64(sqrt(Float64(Float64(kx * kx) + fma(t_2, -0.5, 0.5))) / sin(ky)));
	elseif (t_1 <= -0.18)
		tmp = Float64(sqrt(Float64(1.0 / fma(Float64(1.0 - cos(Float64(kx + kx))), 0.5, Float64(0.5 + Float64(-0.5 * t_2))))) * Float64(sin(ky) * th));
	elseif (t_1 <= 0.35)
		tmp = t_3;
	elseif (t_1 <= 0.999998)
		tmp = Float64(th * Float64(sqrt(Float64(1.0 / fma(0.5, Float64(1.0 - cos(Float64(kx * -2.0))), fma(-0.5, cos(Float64(ky * -2.0)), 0.5)))) * sin(ky)));
	elseif (t_1 <= 1.0)
		tmp = sin(th);
	else
		tmp = t_3;
	end
	return 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]}, Block[{t$95$2 = N[Cos[N[(ky + ky), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(ky * N[(-0.16666666666666666 * N[(ky * ky), $MachinePrecision]), $MachinePrecision] + ky), $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -1.0], N[(N[Sin[th], $MachinePrecision] / N[(N[Sqrt[N[(N[(kx * kx), $MachinePrecision] + N[(t$95$2 * -0.5 + 0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sin[ky], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, -0.18], N[(N[Sqrt[N[(1.0 / N[(N[(1.0 - N[Cos[N[(kx + kx), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * 0.5 + N[(0.5 + N[(-0.5 * t$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] * th), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 0.35], t$95$3, If[LessEqual[t$95$1, 0.999998], N[(th * N[(N[Sqrt[N[(1.0 / N[(0.5 * N[(1.0 - N[Cos[N[(kx * -2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + N[(-0.5 * N[Cos[N[(ky * -2.0), $MachinePrecision]], $MachinePrecision] + 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Sin[ky], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 1.0], N[Sin[th], $MachinePrecision], t$95$3]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}\\
t_2 := \cos \left(ky + ky\right)\\
t_3 := \sin th \cdot \frac{\sin ky}{\mathsf{hypot}\left(\mathsf{fma}\left(ky, -0.16666666666666666 \cdot \left(ky \cdot ky\right), ky\right), \sin kx\right)}\\
\mathbf{if}\;t\_1 \leq -1:\\
\;\;\;\;\frac{\sin th}{\frac{\sqrt{kx \cdot kx + \mathsf{fma}\left(t\_2, -0.5, 0.5\right)}}{\sin ky}}\\

\mathbf{elif}\;t\_1 \leq -0.18:\\
\;\;\;\;\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, 0.5 + -0.5 \cdot t\_2\right)}} \cdot \left(\sin ky \cdot th\right)\\

\mathbf{elif}\;t\_1 \leq 0.35:\\
\;\;\;\;t\_3\\

\mathbf{elif}\;t\_1 \leq 0.999998:\\
\;\;\;\;th \cdot \left(\sqrt{\frac{1}{\mathsf{fma}\left(0.5, 1 - \cos \left(kx \cdot -2\right), \mathsf{fma}\left(-0.5, \cos \left(ky \cdot -2\right), 0.5\right)\right)}} \cdot \sin ky\right)\\

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

\mathbf{else}:\\
\;\;\;\;t\_3\\


\end{array}
\end{array}
Derivation
  1. Split input into 5 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

    1. Initial program 86.8%

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

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
    4. Step-by-step derivation
      1. unpow2N/A

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\sin ky}^{2}}} \cdot \sin th \]
      2. lower-*.f6486.8

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\sin ky}^{2}}} \cdot \sin th \]
    5. Applied rewrites86.8%

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\sin ky}^{2}}} \cdot \sin th \]
    6. Applied rewrites64.7%

      \[\leadsto \color{blue}{\frac{\sin th}{\frac{\sqrt{kx \cdot kx + \mathsf{fma}\left(\cos \left(ky + ky\right), -0.5, 0.5\right)}}{\sin ky}}} \]

    if -1 < (/.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.17999999999999999

    1. Initial program 99.1%

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

      \[\leadsto \color{blue}{\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, 0.5 + -0.5 \cdot \cos \left(ky + ky\right)\right)}} \cdot \frac{\sin th}{\frac{1}{\sin ky}}} \]
    4. Taylor expanded in th around 0

      \[\leadsto \sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, \frac{1}{2} + \frac{-1}{2} \cdot \cos \left(ky + ky\right)\right)}} \cdot \color{blue}{\left(th \cdot \sin ky\right)} \]
    5. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, \frac{1}{2} + \frac{-1}{2} \cdot \cos \left(ky + ky\right)\right)}} \cdot \color{blue}{\left(th \cdot \sin ky\right)} \]
      2. lower-sin.f6447.3

        \[\leadsto \sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, 0.5 + -0.5 \cdot \cos \left(ky + ky\right)\right)}} \cdot \left(th \cdot \color{blue}{\sin ky}\right) \]
    6. Applied rewrites47.3%

      \[\leadsto \sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, 0.5 + -0.5 \cdot \cos \left(ky + ky\right)\right)}} \cdot \color{blue}{\left(th \cdot \sin ky\right)} \]

    if -0.17999999999999999 < (/.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.34999999999999998 or 1 < (/.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 91.6%

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \cdot \sin th \]
      8. lower-hypot.f6499.6

        \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin 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. Taylor expanded in ky around 0

      \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{ky \cdot \left(1 + \frac{-1}{6} \cdot {ky}^{2}\right)}, \sin kx\right)} \cdot \sin th \]
    6. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(ky \cdot \color{blue}{\left(\frac{-1}{6} \cdot {ky}^{2} + 1\right)}, \sin kx\right)} \cdot \sin th \]
      2. distribute-lft-inN/A

        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{ky \cdot \left(\frac{-1}{6} \cdot {ky}^{2}\right) + ky \cdot 1}, \sin kx\right)} \cdot \sin th \]
      3. *-rgt-identityN/A

        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(ky \cdot \left(\frac{-1}{6} \cdot {ky}^{2}\right) + \color{blue}{ky}, \sin kx\right)} \cdot \sin th \]
      4. lower-fma.f64N/A

        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{\mathsf{fma}\left(ky, \frac{-1}{6} \cdot {ky}^{2}, ky\right)}, \sin kx\right)} \cdot \sin th \]
      5. *-commutativeN/A

        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\mathsf{fma}\left(ky, \color{blue}{{ky}^{2} \cdot \frac{-1}{6}}, ky\right), \sin kx\right)} \cdot \sin th \]
      6. lower-*.f64N/A

        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\mathsf{fma}\left(ky, \color{blue}{{ky}^{2} \cdot \frac{-1}{6}}, ky\right), \sin kx\right)} \cdot \sin th \]
      7. unpow2N/A

        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\mathsf{fma}\left(ky, \color{blue}{\left(ky \cdot ky\right)} \cdot \frac{-1}{6}, ky\right), \sin kx\right)} \cdot \sin th \]
      8. lower-*.f6493.0

        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\mathsf{fma}\left(ky, \color{blue}{\left(ky \cdot ky\right)} \cdot -0.16666666666666666, ky\right), \sin kx\right)} \cdot \sin th \]
    7. Applied rewrites93.0%

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

    if 0.34999999999999998 < (/.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.999998000000000054

    1. Initial program 99.3%

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

      \[\leadsto \color{blue}{\left(\sin ky \cdot \sin th\right) \cdot \sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, 0.5 + -0.5 \cdot \cos \left(ky + ky\right)\right)}}} \]
    4. Taylor expanded in th around 0

      \[\leadsto \color{blue}{th \cdot \left(\frac{-1}{6} \cdot \left(\left({th}^{2} \cdot \sin ky\right) \cdot \sqrt{\frac{1}{\frac{1}{2} + \left(\frac{-1}{2} \cdot \cos \left(2 \cdot ky\right) + \frac{1}{2} \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}\right) + \sin ky \cdot \sqrt{\frac{1}{\frac{1}{2} + \left(\frac{-1}{2} \cdot \cos \left(2 \cdot ky\right) + \frac{1}{2} \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}\right)} \]
    5. Applied rewrites50.0%

      \[\leadsto \color{blue}{th \cdot \left(\sqrt{\frac{1}{\mathsf{fma}\left(0.5, 1 - \cos \left(kx \cdot -2\right), \mathsf{fma}\left(-0.5, \cos \left(ky \cdot -2\right), 0.5\right)\right)}} \cdot \left(\mathsf{fma}\left(th, th \cdot -0.16666666666666666, 1\right) \cdot \sin ky\right)\right)} \]
    6. Taylor expanded in th around 0

      \[\leadsto th \cdot \left(\sqrt{\frac{1}{\mathsf{fma}\left(\frac{1}{2}, 1 - \cos \left(kx \cdot -2\right), \mathsf{fma}\left(\frac{-1}{2}, \cos \left(ky \cdot -2\right), \frac{1}{2}\right)\right)}} \cdot \sin ky\right) \]
    7. Step-by-step derivation
      1. Applied rewrites50.2%

        \[\leadsto th \cdot \left(\sqrt{\frac{1}{\mathsf{fma}\left(0.5, 1 - \cos \left(kx \cdot -2\right), \mathsf{fma}\left(-0.5, \cos \left(ky \cdot -2\right), 0.5\right)\right)}} \cdot \sin ky\right) \]

      if 0.999998000000000054 < (/.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

      1. Initial program 99.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. lower-sin.f6499.7

          \[\leadsto \color{blue}{\sin th} \]
      5. Applied rewrites99.7%

        \[\leadsto \color{blue}{\sin th} \]
    8. Recombined 5 regimes into one program.
    9. Final simplification78.6%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq -1:\\ \;\;\;\;\frac{\sin th}{\frac{\sqrt{kx \cdot kx + \mathsf{fma}\left(\cos \left(ky + ky\right), -0.5, 0.5\right)}}{\sin ky}}\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq -0.18:\\ \;\;\;\;\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, 0.5 + -0.5 \cdot \cos \left(ky + ky\right)\right)}} \cdot \left(\sin ky \cdot th\right)\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.35:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\mathsf{hypot}\left(\mathsf{fma}\left(ky, -0.16666666666666666 \cdot \left(ky \cdot ky\right), ky\right), \sin kx\right)}\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.999998:\\ \;\;\;\;th \cdot \left(\sqrt{\frac{1}{\mathsf{fma}\left(0.5, 1 - \cos \left(kx \cdot -2\right), \mathsf{fma}\left(-0.5, \cos \left(ky \cdot -2\right), 0.5\right)\right)}} \cdot \sin ky\right)\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 1:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\mathsf{hypot}\left(\mathsf{fma}\left(ky, -0.16666666666666666 \cdot \left(ky \cdot ky\right), ky\right), \sin kx\right)}\\ \end{array} \]
    10. Add Preprocessing

    Reproduce

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