Toniolo and Linder, Equation (3b), real

Percentage Accurate: 93.4% → 99.7%
Time: 13.6s
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.4% 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 92.0%

    \[\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: 80.0% accurate, 0.2× speedup?

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

\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(ky, -0.16666666666666666 \cdot \left(ky \cdot ky\right), ky\right)\\
t_2 := \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}\\
t_3 := \sin ky \cdot \left(th \cdot \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)}}\right)\\
\mathbf{if}\;t\_2 \leq -0.999:\\
\;\;\;\;\sin th \cdot \frac{\sin ky}{\sqrt{\mathsf{fma}\left(\cos \left(ky + ky\right), -0.5, 0.5\right) + kx \cdot kx}}\\

\mathbf{elif}\;t\_2 \leq -0.2:\\
\;\;\;\;t\_3\\

\mathbf{elif}\;t\_2 \leq 0.02:\\
\;\;\;\;\sin th \cdot \frac{\sin ky}{\mathsf{hypot}\left(t\_1, \sin kx\right)}\\

\mathbf{elif}\;t\_2 \leq 0.99:\\
\;\;\;\;t\_3\\

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

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


\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))))) < -0.998999999999999999

    1. Initial program 85.5%

      \[\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-*.f6484.5

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

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

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

    if -0.998999999999999999 < (/.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.20000000000000001 or 0.0200000000000000004 < (/.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.98999999999999999

    1. Initial program 99.2%

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

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

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

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      4. associate-/l*N/A

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

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

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

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

      \[\leadsto \color{blue}{\left(th \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)} \cdot \sin ky \]
    6. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \color{blue}{\left(th \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)} \cdot \sin ky \]
      2. lower-sqrt.f64N/A

        \[\leadsto \left(th \cdot \color{blue}{\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) \cdot \sin ky \]
      3. lower-/.f64N/A

        \[\leadsto \left(th \cdot \sqrt{\color{blue}{\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) \cdot \sin ky \]
      4. associate-+r+N/A

        \[\leadsto \left(th \cdot \sqrt{\frac{1}{\color{blue}{\left(\frac{1}{2} + \frac{-1}{2} \cdot \cos \left(2 \cdot ky\right)\right) + \frac{1}{2} \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)}}}\right) \cdot \sin ky \]
      5. +-commutativeN/A

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

        \[\leadsto \left(th \cdot \sqrt{\frac{1}{\color{blue}{\mathsf{fma}\left(\frac{1}{2}, 1 - \cos \left(2 \cdot kx\right), \frac{1}{2} + \frac{-1}{2} \cdot \cos \left(2 \cdot ky\right)\right)}}}\right) \cdot \sin ky \]
      7. metadata-evalN/A

        \[\leadsto \left(th \cdot \sqrt{\frac{1}{\mathsf{fma}\left(\frac{1}{2}, 1 - \cos \left(\color{blue}{\left(\mathsf{neg}\left(-2\right)\right)} \cdot kx\right), \frac{1}{2} + \frac{-1}{2} \cdot \cos \left(2 \cdot ky\right)\right)}}\right) \cdot \sin ky \]
      8. distribute-lft-neg-inN/A

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

        \[\leadsto \left(th \cdot \sqrt{\frac{1}{\mathsf{fma}\left(\frac{1}{2}, \color{blue}{1 - \cos \left(\mathsf{neg}\left(-2 \cdot kx\right)\right)}, \frac{1}{2} + \frac{-1}{2} \cdot \cos \left(2 \cdot ky\right)\right)}}\right) \cdot \sin ky \]
      10. cos-negN/A

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

        \[\leadsto \left(th \cdot \sqrt{\frac{1}{\mathsf{fma}\left(\frac{1}{2}, 1 - \color{blue}{\cos \left(-2 \cdot kx\right)}, \frac{1}{2} + \frac{-1}{2} \cdot \cos \left(2 \cdot ky\right)\right)}}\right) \cdot \sin ky \]
      12. *-commutativeN/A

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

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

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

      \[\leadsto \color{blue}{\left(th \cdot \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)}}\right)} \cdot \sin ky \]

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

    1. Initial program 99.3%

      \[\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-*.f6496.7

        \[\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 rewrites96.7%

      \[\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.98999999999999999 < (/.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.f6496.4

        \[\leadsto \color{blue}{\sin th} \]
    5. Applied rewrites96.4%

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

    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)))))

    1. Initial program 3.4%

      \[\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. Taylor expanded in kx around 0

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \color{blue}{\mathsf{fma}\left(kx, -0.16666666666666666 \cdot \left(kx \cdot kx\right), kx\right)}\right)} \cdot \sin th \]
    8. 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)}, \mathsf{fma}\left(kx, \frac{-1}{6} \cdot \left(kx \cdot kx\right), kx\right)\right)} \cdot \sin th \]
    9. 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)}, \mathsf{fma}\left(kx, \frac{-1}{6} \cdot \left(kx \cdot kx\right), kx\right)\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}, \mathsf{fma}\left(kx, \frac{-1}{6} \cdot \left(kx \cdot kx\right), kx\right)\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}, \mathsf{fma}\left(kx, \frac{-1}{6} \cdot \left(kx \cdot kx\right), kx\right)\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)}, \mathsf{fma}\left(kx, \frac{-1}{6} \cdot \left(kx \cdot kx\right), kx\right)\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), \mathsf{fma}\left(kx, \frac{-1}{6} \cdot \left(kx \cdot kx\right), kx\right)\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), \mathsf{fma}\left(kx, \frac{-1}{6} \cdot \left(kx \cdot kx\right), kx\right)\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), \mathsf{fma}\left(kx, \frac{-1}{6} \cdot \left(kx \cdot kx\right), kx\right)\right)} \cdot \sin th \]
      8. lower-*.f6499.7

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

      \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{\mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot -0.16666666666666666, ky\right)}, \mathsf{fma}\left(kx, -0.16666666666666666 \cdot \left(kx \cdot kx\right), kx\right)\right)} \cdot \sin th \]
  3. Recombined 5 regimes into one program.
  4. Final simplification80.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq -0.999:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\sqrt{\mathsf{fma}\left(\cos \left(ky + ky\right), -0.5, 0.5\right) + kx \cdot kx}}\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq -0.2:\\ \;\;\;\;\sin ky \cdot \left(th \cdot \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)}}\right)\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.02:\\ \;\;\;\;\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.99:\\ \;\;\;\;\sin ky \cdot \left(th \cdot \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)}}\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), \mathsf{fma}\left(kx, -0.16666666666666666 \cdot \left(kx \cdot kx\right), kx\right)\right)}\\ \end{array} \]
  5. Add Preprocessing

Reproduce

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