?

Average Error: 4.0 → 2.6
Time: 28.0s
Precision: binary64
Cost: 123208

?

\[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
\[\begin{array}{l} t_1 := \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;\frac{\sin ky}{-kx} \cdot \sin th\\ \mathbf{elif}\;t_1 \leq 0.9998:\\ \;\;\;\;t_1 \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\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)))
(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 (- INFINITY))
     (* (/ (sin ky) (- kx)) (sin th))
     (if (<= t_1 0.9998) (* t_1 (sin th)) (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);
}
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 <= -((double) INFINITY)) {
		tmp = (sin(ky) / -kx) * sin(th);
	} else if (t_1 <= 0.9998) {
		tmp = t_1 * sin(th);
	} else {
		tmp = sin(th);
	}
	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(ky) / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)));
	double tmp;
	if (t_1 <= -Double.POSITIVE_INFINITY) {
		tmp = (Math.sin(ky) / -kx) * Math.sin(th);
	} else if (t_1 <= 0.9998) {
		tmp = t_1 * Math.sin(th);
	} else {
		tmp = Math.sin(th);
	}
	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(ky) / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)))
	tmp = 0
	if t_1 <= -math.inf:
		tmp = (math.sin(ky) / -kx) * math.sin(th)
	elif t_1 <= 0.9998:
		tmp = t_1 * math.sin(th)
	else:
		tmp = math.sin(th)
	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(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0))))
	tmp = 0.0
	if (t_1 <= Float64(-Inf))
		tmp = Float64(Float64(sin(ky) / Float64(-kx)) * sin(th));
	elseif (t_1 <= 0.9998)
		tmp = Float64(t_1 * sin(th));
	else
		tmp = sin(th);
	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(ky) / sqrt(((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)));
	tmp = 0.0;
	if (t_1 <= -Inf)
		tmp = (sin(ky) / -kx) * sin(th);
	elseif (t_1 <= 0.9998)
		tmp = t_1 * sin(th);
	else
		tmp = sin(th);
	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[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, (-Infinity)], N[(N[(N[Sin[ky], $MachinePrecision] / (-kx)), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 0.9998], N[(t$95$1 * N[Sin[th], $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]]
\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th
\begin{array}{l}
t_1 := \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;\frac{\sin ky}{-kx} \cdot \sin th\\

\mathbf{elif}\;t_1 \leq 0.9998:\\
\;\;\;\;t_1 \cdot \sin th\\

\mathbf{else}:\\
\;\;\;\;\sin th\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Split input into 3 regimes
  2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) 2) (pow.f64 (sin.f64 ky) 2)))) < -inf.0

    1. Initial program 64.0

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

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
    3. Taylor expanded in kx around -inf 46.3

      \[\leadsto \frac{\sin ky}{\color{blue}{-1 \cdot kx}} \cdot \sin th \]
    4. Simplified46.3

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

      [Start]46.3

      \[ \frac{\sin ky}{-1 \cdot kx} \cdot \sin th \]

      rational_best_oopsla_all_46_json_45_simplify-74 [=>]46.3

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

      rational_best_oopsla_all_46_json_45_simplify-92 [=>]46.3

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

    if -inf.0 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) 2) (pow.f64 (sin.f64 ky) 2)))) < 0.99980000000000002

    1. Initial program 0.4

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]

    if 0.99980000000000002 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) 2) (pow.f64 (sin.f64 ky) 2))))

    1. Initial program 8.8

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

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

      \[\leadsto \color{blue}{\sin th} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification2.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq -\infty:\\ \;\;\;\;\frac{\sin ky}{-kx} \cdot \sin th\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.9998:\\ \;\;\;\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternatives

Alternative 1
Error18.4
Cost52040
\[\begin{array}{l} \mathbf{if}\;\sin ky \leq -0.001:\\ \;\;\;\;\frac{\sin ky}{\sqrt{{kx}^{2} + {\sin ky}^{2}}} \cdot \sin th\\ \mathbf{elif}\;\sin ky \leq 10^{-5}:\\ \;\;\;\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {ky}^{2}}} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
Alternative 2
Error33.2
Cost45640
\[\begin{array}{l} \mathbf{if}\;\sin ky \leq -0.05:\\ \;\;\;\;\sqrt{\frac{1}{{\sin ky}^{2}}} \cdot \left(\sin ky \cdot th\right)\\ \mathbf{elif}\;\sin ky \leq -1 \cdot 10^{-130}:\\ \;\;\;\;\frac{\sin ky}{\sqrt{{kx}^{2} + {ky}^{2}}} \cdot \sin th\\ \mathbf{elif}\;\sin ky \leq 2 \cdot 10^{-179}:\\ \;\;\;\;\frac{ky}{\sin kx} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
Alternative 3
Error24.2
Cost45508
\[\begin{array}{l} \mathbf{if}\;\sin kx \leq 10^{-22}:\\ \;\;\;\;\frac{\sin ky}{\sqrt{{kx}^{2} + {\sin ky}^{2}}} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin ky}{\sin kx} \cdot \sin th\\ \end{array} \]
Alternative 4
Error34.7
Cost32644
\[\begin{array}{l} \mathbf{if}\;\sin ky \leq -0.05:\\ \;\;\;\;\sqrt{\frac{1}{{\sin ky}^{2}}} \cdot \left(\sin ky \cdot th\right)\\ \mathbf{elif}\;\sin ky \leq 2 \cdot 10^{-179}:\\ \;\;\;\;\frac{\sin ky}{\sin kx} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
Alternative 5
Error38.0
Cost32584
\[\begin{array}{l} \mathbf{if}\;\sin kx \leq -1 \cdot 10^{-85}:\\ \;\;\;\;\frac{\sin ky}{-kx} \cdot \sin th\\ \mathbf{elif}\;\sin kx \leq 5 \cdot 10^{-155}:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin ky}{\sin kx} \cdot \sin th\\ \end{array} \]
Alternative 6
Error40.5
Cost26184
\[\begin{array}{l} \mathbf{if}\;\sin kx \leq -1 \cdot 10^{-85}:\\ \;\;\;\;-\frac{\sin ky \cdot th}{kx}\\ \mathbf{elif}\;\sin kx \leq 2 \cdot 10^{-141}:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\frac{ky}{\sin kx} \cdot \sin th\\ \end{array} \]
Alternative 7
Error40.7
Cost26184
\[\begin{array}{l} \mathbf{if}\;\sin kx \leq -1 \cdot 10^{-85}:\\ \;\;\;\;-\frac{\sin ky \cdot th}{kx}\\ \mathbf{elif}\;\sin kx \leq 2 \cdot 10^{-141}:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin th \cdot ky}{\sin kx}\\ \end{array} \]
Alternative 8
Error39.8
Cost26184
\[\begin{array}{l} \mathbf{if}\;\sin kx \leq -1 \cdot 10^{-85}:\\ \;\;\;\;-\frac{\sin ky \cdot \sin th}{kx}\\ \mathbf{elif}\;\sin kx \leq 2 \cdot 10^{-141}:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin th \cdot ky}{\sin kx}\\ \end{array} \]
Alternative 9
Error39.7
Cost26184
\[\begin{array}{l} \mathbf{if}\;\sin kx \leq -1 \cdot 10^{-85}:\\ \;\;\;\;\frac{\sin ky}{-kx} \cdot \sin th\\ \mathbf{elif}\;\sin kx \leq 2 \cdot 10^{-141}:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin th \cdot ky}{\sin kx}\\ \end{array} \]
Alternative 10
Error42.4
Cost13252
\[\begin{array}{l} \mathbf{if}\;\sin ky \leq 2 \cdot 10^{-179}:\\ \;\;\;\;\frac{ky}{kx} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
Alternative 11
Error44.4
Cost6728
\[\begin{array}{l} \mathbf{if}\;ky \leq -8 \cdot 10^{-15}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq 5.3 \cdot 10^{-192}:\\ \;\;\;\;\frac{th \cdot ky}{kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
Alternative 12
Error51.1
Cost584
\[\begin{array}{l} \mathbf{if}\;ky \leq -1 \cdot 10^{+44}:\\ \;\;\;\;th\\ \mathbf{elif}\;ky \leq 8.2 \cdot 10^{-192}:\\ \;\;\;\;\frac{th \cdot ky}{kx}\\ \mathbf{else}:\\ \;\;\;\;th\\ \end{array} \]
Alternative 13
Error55.5
Cost64
\[th \]

Error

Reproduce?

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