?

Average Error: 4.1 → 3.5
Time: 32.1s
Precision: binary64
Cost: 90820

?

\[\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}}} \cdot \sin th\\ \mathbf{if}\;t_1 \leq 1:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;ky \cdot \frac{\sin th}{kx}\\ \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))))
          (sin th))))
   (if (<= t_1 1.0) t_1 (* ky (/ (sin th) kx)))))
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)))) * sin(th);
	double tmp;
	if (t_1 <= 1.0) {
		tmp = t_1;
	} else {
		tmp = ky * (sin(th) / kx);
	}
	return tmp;
}
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
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: t_1
    real(8) :: tmp
    t_1 = (sin(ky) / sqrt(((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)))) * sin(th)
    if (t_1 <= 1.0d0) then
        tmp = t_1
    else
        tmp = ky * (sin(th) / kx)
    end if
    code = tmp
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);
}
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)))) * Math.sin(th);
	double tmp;
	if (t_1 <= 1.0) {
		tmp = t_1;
	} else {
		tmp = ky * (Math.sin(th) / kx);
	}
	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)))) * math.sin(th)
	tmp = 0
	if t_1 <= 1.0:
		tmp = t_1
	else:
		tmp = ky * (math.sin(th) / kx)
	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(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) * sin(th))
	tmp = 0.0
	if (t_1 <= 1.0)
		tmp = t_1;
	else
		tmp = Float64(ky * Float64(sin(th) / kx));
	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)))) * sin(th);
	tmp = 0.0;
	if (t_1 <= 1.0)
		tmp = t_1;
	else
		tmp = ky * (sin(th) / kx);
	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[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]}, If[LessEqual[t$95$1, 1.0], t$95$1, N[(ky * N[(N[Sin[th], $MachinePrecision] / kx), $MachinePrecision]), $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}}} \cdot \sin th\\
\mathbf{if}\;t_1 \leq 1:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;ky \cdot \frac{\sin th}{kx}\\


\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 (*.f64 (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) 2) (pow.f64 (sin.f64 ky) 2)))) (sin.f64 th)) < 1

    1. Initial program 2.3

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

    if 1 < (*.f64 (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) 2) (pow.f64 (sin.f64 ky) 2)))) (sin.f64 th))

    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 ky around 0 49.1

      \[\leadsto \color{blue}{\frac{\sin th \cdot ky}{kx}} \]
    4. Simplified44.7

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

      [Start]49.1

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

      rational.json-simplify-49 [=>]44.7

      \[ \color{blue}{ky \cdot \frac{\sin th}{kx}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification3.5

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

Alternatives

Alternative 1
Error17.3
Cost52040
\[\begin{array}{l} \mathbf{if}\;\sin kx \leq -0.0001:\\ \;\;\;\;\left(\sqrt{\frac{1}{{\sin kx}^{2}}} \cdot \sin ky\right) \cdot \sin th\\ \mathbf{elif}\;\sin kx \leq 10^{-14}:\\ \;\;\;\;\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 2
Error17.1
Cost52040
\[\begin{array}{l} \mathbf{if}\;\sin ky \leq -0.001:\\ \;\;\;\;\left(\sqrt{\frac{1}{{\sin ky}^{2}}} \cdot \sin ky\right) \cdot \sin th\\ \mathbf{elif}\;\sin ky \leq 2 \cdot 10^{-6}:\\ \;\;\;\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {ky}^{2}}} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
Alternative 3
Error27.9
Cost45576
\[\begin{array}{l} \mathbf{if}\;\sin ky \leq -0.004:\\ \;\;\;\;\sqrt{\frac{1}{{\sin ky}^{2}}} \cdot \left(\sin ky \cdot th\right)\\ \mathbf{elif}\;\sin ky \leq 5 \cdot 10^{-67}:\\ \;\;\;\;\left(\sqrt{\frac{1}{{\sin kx}^{2}}} \cdot \sin ky\right) \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
Alternative 4
Error23.7
Cost45576
\[\begin{array}{l} \mathbf{if}\;\sin ky \leq -5 \cdot 10^{-87}:\\ \;\;\;\;\left(\sqrt{\frac{1}{{\sin ky}^{2}}} \cdot \sin ky\right) \cdot \sin th\\ \mathbf{elif}\;\sin ky \leq 5 \cdot 10^{-67}:\\ \;\;\;\;\left(\sqrt{\frac{1}{{\sin kx}^{2}}} \cdot \sin ky\right) \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
Alternative 5
Error33.9
Cost39880
\[\begin{array}{l} \mathbf{if}\;\sin ky \leq -2 \cdot 10^{-98}:\\ \;\;\;\;\sqrt{\frac{1}{{\sin ky}^{2}}} \cdot \left(\sin ky \cdot th\right)\\ \mathbf{elif}\;\sin ky \leq 5 \cdot 10^{-67}:\\ \;\;\;\;\frac{1}{\frac{\sin kx}{ky} + \left(0.5 \cdot \frac{1}{\sin kx} + 0.16666666666666666 \cdot \sin kx\right) \cdot ky} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
Alternative 6
Error33.9
Cost32644
\[\begin{array}{l} \mathbf{if}\;\sin ky \leq -2 \cdot 10^{-98}:\\ \;\;\;\;\sqrt{\frac{1}{{\sin ky}^{2}}} \cdot \left(\sin ky \cdot th\right)\\ \mathbf{elif}\;\sin ky \leq 5 \cdot 10^{-67}:\\ \;\;\;\;\frac{ky}{\sin kx} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
Alternative 7
Error37.2
Cost26052
\[\begin{array}{l} \mathbf{if}\;\sin ky \leq 5 \cdot 10^{-67}:\\ \;\;\;\;\frac{\sin ky}{\sin kx} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
Alternative 8
Error38.3
Cost13384
\[\begin{array}{l} \mathbf{if}\;ky \leq -1900000000000:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq 2.5 \cdot 10^{-60}:\\ \;\;\;\;\frac{ky}{\sin kx} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
Alternative 9
Error42.1
Cost13380
\[\begin{array}{l} \mathbf{if}\;\sin ky \leq 10^{-98}:\\ \;\;\;\;-1 \cdot \left(ky \cdot \frac{\sin th}{kx}\right)\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
Alternative 10
Error42.1
Cost13316
\[\begin{array}{l} \mathbf{if}\;\sin ky \leq 10^{-98}:\\ \;\;\;\;\frac{ky}{-kx} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
Alternative 11
Error42.6
Cost13252
\[\begin{array}{l} \mathbf{if}\;\sin ky \leq 5 \cdot 10^{-75}:\\ \;\;\;\;ky \cdot \frac{\sin th}{kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
Alternative 12
Error43.9
Cost6728
\[\begin{array}{l} \mathbf{if}\;ky \leq -1750:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq 1.65 \cdot 10^{-192}:\\ \;\;\;\;\frac{0.5}{\frac{\frac{0.5}{th}}{\frac{ky}{kx}}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
Alternative 13
Error50.1
Cost840
\[\begin{array}{l} \mathbf{if}\;ky \leq -1750:\\ \;\;\;\;th\\ \mathbf{elif}\;ky \leq 10^{-66}:\\ \;\;\;\;th \cdot \left(\frac{0.5}{kx} \cdot \left(ky + ky\right)\right)\\ \mathbf{else}:\\ \;\;\;\;th\\ \end{array} \]
Alternative 14
Error50.2
Cost584
\[\begin{array}{l} \mathbf{if}\;ky \leq -1750:\\ \;\;\;\;th\\ \mathbf{elif}\;ky \leq 1.9 \cdot 10^{-60}:\\ \;\;\;\;ky \cdot \frac{th}{kx}\\ \mathbf{else}:\\ \;\;\;\;th\\ \end{array} \]
Alternative 15
Error50.1
Cost584
\[\begin{array}{l} \mathbf{if}\;ky \leq -950:\\ \;\;\;\;th\\ \mathbf{elif}\;ky \leq 1.02 \cdot 10^{-66}:\\ \;\;\;\;th \cdot \frac{ky}{kx}\\ \mathbf{else}:\\ \;\;\;\;th\\ \end{array} \]
Alternative 16
Error55.3
Cost64
\[th \]

Error

Reproduce?

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