Average Error: 4.1 → 0.6
Time: 49.5s
Precision: binary64
Cost: 45448
\[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
\[\begin{array}{l} t_1 := \frac{\sin th \cdot \sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}\\ \mathbf{if}\;\sin kx \leq -0.04:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\sin kx \leq 10^{-7}:\\ \;\;\;\;\frac{\sin th}{\frac{\mathsf{hypot}\left(kx, \sin ky\right)}{\sin ky}}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (* (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0)))) (sin th)))
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (/ (* (sin th) (sin ky)) (hypot (sin ky) (sin kx)))))
   (if (<= (sin kx) -0.04)
     t_1
     (if (<= (sin kx) 1e-7)
       (/ (sin th) (/ (hypot kx (sin ky)) (sin ky)))
       t_1))))
double code(double kx, double ky, double th) {
	return (sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)))) * sin(th);
}
double code(double kx, double ky, double th) {
	double t_1 = (sin(th) * sin(ky)) / hypot(sin(ky), sin(kx));
	double tmp;
	if (sin(kx) <= -0.04) {
		tmp = t_1;
	} else if (sin(kx) <= 1e-7) {
		tmp = sin(th) / (hypot(kx, sin(ky)) / sin(ky));
	} else {
		tmp = t_1;
	}
	return tmp;
}
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);
}
public static double code(double kx, double ky, double th) {
	double t_1 = (Math.sin(th) * Math.sin(ky)) / Math.hypot(Math.sin(ky), Math.sin(kx));
	double tmp;
	if (Math.sin(kx) <= -0.04) {
		tmp = t_1;
	} else if (Math.sin(kx) <= 1e-7) {
		tmp = Math.sin(th) / (Math.hypot(kx, Math.sin(ky)) / Math.sin(ky));
	} else {
		tmp = t_1;
	}
	return tmp;
}
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)
def code(kx, ky, th):
	t_1 = (math.sin(th) * math.sin(ky)) / math.hypot(math.sin(ky), math.sin(kx))
	tmp = 0
	if math.sin(kx) <= -0.04:
		tmp = t_1
	elif math.sin(kx) <= 1e-7:
		tmp = math.sin(th) / (math.hypot(kx, math.sin(ky)) / math.sin(ky))
	else:
		tmp = t_1
	return tmp
function code(kx, ky, th)
	return Float64(Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) * sin(th))
end
function code(kx, ky, th)
	t_1 = Float64(Float64(sin(th) * sin(ky)) / hypot(sin(ky), sin(kx)))
	tmp = 0.0
	if (sin(kx) <= -0.04)
		tmp = t_1;
	elseif (sin(kx) <= 1e-7)
		tmp = Float64(sin(th) / Float64(hypot(kx, sin(ky)) / sin(ky)));
	else
		tmp = t_1;
	end
	return tmp
end
function tmp = code(kx, ky, th)
	tmp = (sin(ky) / sqrt(((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) * sin(th);
end
function tmp_2 = code(kx, ky, th)
	t_1 = (sin(th) * sin(ky)) / hypot(sin(ky), sin(kx));
	tmp = 0.0;
	if (sin(kx) <= -0.04)
		tmp = t_1;
	elseif (sin(kx) <= 1e-7)
		tmp = sin(th) / (hypot(kx, sin(ky)) / sin(ky));
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
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]
code[kx_, ky_, th_] := Block[{t$95$1 = N[(N[(N[Sin[th], $MachinePrecision] * N[Sin[ky], $MachinePrecision]), $MachinePrecision] / N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Sin[kx], $MachinePrecision], -0.04], t$95$1, If[LessEqual[N[Sin[kx], $MachinePrecision], 1e-7], N[(N[Sin[th], $MachinePrecision] / N[(N[Sqrt[kx ^ 2 + N[Sin[ky], $MachinePrecision] ^ 2], $MachinePrecision] / N[Sin[ky], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th
\begin{array}{l}
t_1 := \frac{\sin th \cdot \sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}\\
\mathbf{if}\;\sin kx \leq -0.04:\\
\;\;\;\;t_1\\

\mathbf{elif}\;\sin kx \leq 10^{-7}:\\
\;\;\;\;\frac{\sin th}{\frac{\mathsf{hypot}\left(kx, \sin ky\right)}{\sin ky}}\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 2 regimes
  2. if (sin.f64 kx) < -0.0400000000000000008 or 9.9999999999999995e-8 < (sin.f64 kx)

    1. Initial program 0.4

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Applied egg-rr0.6

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\left(0.5 - 0.5 \cdot \cos \left(kx + kx\right)\right)} + {\sin ky}^{2}}} \cdot \sin th \]
    3. Applied egg-rr0.4

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

    if -0.0400000000000000008 < (sin.f64 kx) < 9.9999999999999995e-8

    1. Initial program 7.8

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Applied egg-rr0.1

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

      \[\leadsto \frac{\sin th}{\frac{\mathsf{hypot}\left(\color{blue}{kx}, \sin ky\right)}{\sin ky}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin kx \leq -0.04:\\ \;\;\;\;\frac{\sin th \cdot \sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}\\ \mathbf{elif}\;\sin kx \leq 10^{-7}:\\ \;\;\;\;\frac{\sin th}{\frac{\mathsf{hypot}\left(kx, \sin ky\right)}{\sin ky}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin th \cdot \sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}\\ \end{array} \]

Alternatives

Alternative 1
Error13.9
Cost65356
\[\begin{array}{l} t_1 := \sin th \cdot \frac{\sin ky}{\sqrt{0.5 + \cos \left(kx \cdot 2\right) \cdot -0.5}}\\ t_2 := {\sin kx}^{2}\\ \mathbf{if}\;t_2 \leq 5 \cdot 10^{-10}:\\ \;\;\;\;\frac{\sin th}{\frac{\mathsf{hypot}\left(kx, \sin ky\right)}{\sin ky}}\\ \mathbf{elif}\;t_2 \leq 0.22:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_2 \leq 0.54:\\ \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right) \cdot \left(\frac{1}{th} + th \cdot 0.16666666666666666\right)}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error24.9
Cost58644
\[\begin{array}{l} t_1 := \left(\sin th \cdot ky\right) \cdot \sqrt{\frac{1}{0.5 + \cos \left(kx \cdot 2\right) \cdot -0.5}}\\ \mathbf{if}\;\sin th \leq -0.96:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\sin th \leq -0.66:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;\sin th \leq -0.296:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\sin th \leq -0.05:\\ \;\;\;\;\sqrt{{\sin th}^{2}}\\ \mathbf{elif}\;\sin th \leq 4 \cdot 10^{-5}:\\ \;\;\;\;\frac{\sin ky}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{th}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
Alternative 3
Error14.6
Cost52112
\[\begin{array}{l} t_1 := \left(\sin th \cdot ky\right) \cdot \sqrt{\frac{1}{0.5 + \cos \left(kx \cdot 2\right) \cdot -0.5}}\\ \mathbf{if}\;\sin kx \leq -0.912:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\sin kx \leq -0.484:\\ \;\;\;\;\frac{\sin ky}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{th}}\\ \mathbf{elif}\;\sin kx \leq -0.05:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\sin kx \leq 2 \cdot 10^{-5}:\\ \;\;\;\;\frac{\sin th}{\frac{\mathsf{hypot}\left(kx, \sin ky\right)}{\sin ky}}\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\sin kx}\\ \end{array} \]
Alternative 4
Error37.1
Cost45648
\[\begin{array}{l} \mathbf{if}\;\sin kx \leq -2 \cdot 10^{-44}:\\ \;\;\;\;ky \cdot \frac{th}{\sqrt{{\sin kx}^{2}}}\\ \mathbf{elif}\;\sin kx \leq -5 \cdot 10^{-273}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;\sin kx \leq 10^{-250}:\\ \;\;\;\;\sqrt{{\sin th}^{2}}\\ \mathbf{elif}\;\sin kx \leq 5 \cdot 10^{-128}:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\sin ky \cdot \frac{\sin th}{\sin kx}\\ \end{array} \]
Alternative 5
Error33.7
Cost45648
\[\begin{array}{l} \mathbf{if}\;\sin kx \leq -0.05:\\ \;\;\;\;\left(\sin th \cdot ky\right) \cdot \sqrt{\frac{1}{0.5 + \cos \left(kx \cdot 2\right) \cdot -0.5}}\\ \mathbf{elif}\;\sin kx \leq -5 \cdot 10^{-273}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;\sin kx \leq 10^{-250}:\\ \;\;\;\;\sqrt{{\sin th}^{2}}\\ \mathbf{elif}\;\sin kx \leq 5 \cdot 10^{-128}:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\sin ky \cdot \frac{\sin th}{\sin kx}\\ \end{array} \]
Alternative 6
Error13.2
Cost39048
\[\begin{array}{l} \mathbf{if}\;\sin kx \leq -0.04:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\sqrt{0.5 + \cos \left(kx \cdot 2\right) \cdot -0.5}}\\ \mathbf{elif}\;\sin kx \leq 2 \cdot 10^{-5}:\\ \;\;\;\;\frac{\sin th}{\frac{\mathsf{hypot}\left(kx, \sin ky\right)}{\sin ky}}\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\sin kx}\\ \end{array} \]
Alternative 7
Error0.2
Cost32384
\[\frac{\sin th}{\frac{\mathsf{hypot}\left(\sin kx, \sin ky\right)}{\sin ky}} \]
Alternative 8
Error34.4
Cost26184
\[\begin{array}{l} \mathbf{if}\;\sin ky \leq -5 \cdot 10^{-25}:\\ \;\;\;\;\sqrt{{\sin th}^{2}}\\ \mathbf{elif}\;\sin ky \leq 2 \cdot 10^{-126}:\\ \;\;\;\;ky \cdot \frac{\sin th}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
Alternative 9
Error38.4
Cost13384
\[\begin{array}{l} \mathbf{if}\;ky \leq -2.6852159100877643 \cdot 10^{+33}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq 1.761721877997747 \cdot 10^{-126}:\\ \;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
Alternative 10
Error38.4
Cost13384
\[\begin{array}{l} \mathbf{if}\;ky \leq -2.6852159100877643 \cdot 10^{+33}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq 1.761721877997747 \cdot 10^{-126}:\\ \;\;\;\;ky \cdot \frac{\sin th}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
Alternative 11
Error44.1
Cost13252
\[\begin{array}{l} \mathbf{if}\;\sin ky \leq 10^{-237}:\\ \;\;\;\;th \cdot \frac{\sin ky}{kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
Alternative 12
Error43.6
Cost6984
\[\begin{array}{l} \mathbf{if}\;ky \leq -1078333431473.9033:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq 3.731262313640193 \cdot 10^{-239}:\\ \;\;\;\;\frac{ky}{\frac{\sin kx}{th}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
Alternative 13
Error43.5
Cost6984
\[\begin{array}{l} \mathbf{if}\;ky \leq -1078333431473.9033:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq 3.731262313640193 \cdot 10^{-239}:\\ \;\;\;\;th \cdot \frac{ky}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
Alternative 14
Error44.9
Cost6728
\[\begin{array}{l} \mathbf{if}\;ky \leq -3.987174777426221 \cdot 10^{+42}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq 6.586137216934689 \cdot 10^{-238}:\\ \;\;\;\;ky \cdot \frac{th}{kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
Alternative 15
Error49.9
Cost584
\[\begin{array}{l} \mathbf{if}\;ky \leq -1078333431473.9033:\\ \;\;\;\;th\\ \mathbf{elif}\;ky \leq 1.761721877997747 \cdot 10^{-126}:\\ \;\;\;\;ky \cdot \frac{th}{kx}\\ \mathbf{else}:\\ \;\;\;\;th\\ \end{array} \]
Alternative 16
Error55.2
Cost64
\[th \]

Error

Reproduce

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