Toniolo and Linder, Equation (3b), real

?

Percentage Accurate: 93.7% → 99.7%
Time: 25.2s
Precision: binary64
Cost: 32384

?

\[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
\[\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) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0)))) (sin th)))
(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) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)))) * 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.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) {
	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.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.hypot(math.sin(ky), math.sin(kx))) * 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 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) / sqrt(((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) * 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[(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_] := 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]
\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th
\begin{array}{l}

\\
\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin th
\end{array}

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.

Herbie found 18 alternatives:

AlternativeAccuracySpeedup

Accuracy vs Speed

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.

Bogosity?

Bogosity

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Initial program 94.7%

    \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
  2. Simplified99.7%

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

    [Start]94.7%

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

    +-commutative [=>]94.7%

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

    unpow2 [=>]94.7%

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

    unpow2 [=>]94.7%

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

    hypot-def [=>]99.7%

    \[ \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \cdot \sin th \]
  3. Final simplification99.7%

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

Alternatives

Alternative 1
Accuracy99.7%
Cost32384
\[\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin th \]
Alternative 2
Accuracy47.1%
Cost58712
\[\begin{array}{l} t_1 := \frac{\sin ky}{kx}\\ \mathbf{if}\;\sin ky \leq -1 \cdot 10^{-27}:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq -1 \cdot 10^{-217}:\\ \;\;\;\;th \cdot \frac{ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}\\ \mathbf{elif}\;\sin ky \leq -1 \cdot 10^{-306}:\\ \;\;\;\;\left|\sin th \cdot t_1\right|\\ \mathbf{elif}\;\sin ky \leq 2 \cdot 10^{-292}:\\ \;\;\;\;\frac{\sin th}{1 + \frac{kx}{ky} \cdot \frac{kx \cdot 0.5}{ky}}\\ \mathbf{elif}\;\sin ky \leq 2 \cdot 10^{-191}:\\ \;\;\;\;\sin th \cdot \left|t_1\right|\\ \mathbf{elif}\;\sin ky \leq 10^{-147}:\\ \;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin ky \cdot \sin th}{\sin ky}\\ \end{array} \]
Alternative 3
Accuracy47.1%
Cost58712
\[\begin{array}{l} t_1 := \frac{\sin ky}{kx}\\ \mathbf{if}\;\sin ky \leq -1 \cdot 10^{-27}:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq -1 \cdot 10^{-217}:\\ \;\;\;\;ky \cdot \frac{th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}\\ \mathbf{elif}\;\sin ky \leq -1 \cdot 10^{-306}:\\ \;\;\;\;\left|\sin th \cdot t_1\right|\\ \mathbf{elif}\;\sin ky \leq 2 \cdot 10^{-292}:\\ \;\;\;\;\frac{\sin th}{1 + \frac{kx}{ky} \cdot \frac{kx \cdot 0.5}{ky}}\\ \mathbf{elif}\;\sin ky \leq 2 \cdot 10^{-191}:\\ \;\;\;\;\sin th \cdot \left|t_1\right|\\ \mathbf{elif}\;\sin ky \leq 10^{-147}:\\ \;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin ky \cdot \sin th}{\sin ky}\\ \end{array} \]
Alternative 4
Accuracy66.6%
Cost52112
\[\begin{array}{l} t_1 := \left|\sin th\right|\\ \mathbf{if}\;\sin th \leq -0.72:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\sin th \leq -0.15:\\ \;\;\;\;\sin ky \cdot \frac{\sin th}{\sin kx}\\ \mathbf{elif}\;\sin th \leq -0.065:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\sin th \leq 0.0005:\\ \;\;\;\;\sin ky \cdot \frac{th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}\\ \mathbf{else}:\\ \;\;\;\;\sin ky \cdot \left|\frac{\sin th}{\sin ky}\right|\\ \end{array} \]
Alternative 5
Accuracy66.6%
Cost52112
\[\begin{array}{l} t_1 := \left|\sin th\right|\\ \mathbf{if}\;\sin th \leq -0.72:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\sin th \leq -0.15:\\ \;\;\;\;\sin ky \cdot \frac{\sin th}{\sin kx}\\ \mathbf{elif}\;\sin th \leq -0.065:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\sin th \leq 0.0005:\\ \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot th\\ \mathbf{else}:\\ \;\;\;\;\sin ky \cdot \left|\frac{\sin th}{\sin ky}\right|\\ \end{array} \]
Alternative 6
Accuracy53.1%
Cost52048
\[\begin{array}{l} t_1 := \frac{\sin ky}{\sin kx}\\ \mathbf{if}\;\sin ky \leq -1 \cdot 10^{-27}:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq -1 \cdot 10^{-183}:\\ \;\;\;\;ky \cdot \frac{th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}\\ \mathbf{elif}\;\sin ky \leq -1 \cdot 10^{-306}:\\ \;\;\;\;\left|\sin th \cdot t_1\right|\\ \mathbf{elif}\;\sin ky \leq 10^{-109}:\\ \;\;\;\;\sin th \cdot \left|t_1\right|\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
Alternative 7
Accuracy48.3%
Cost45516
\[\begin{array}{l} \mathbf{if}\;\sin ky \leq -1 \cdot 10^{-27}:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq -1 \cdot 10^{-183}:\\ \;\;\;\;ky \cdot \frac{th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}\\ \mathbf{elif}\;\sin ky \leq 2 \cdot 10^{-145}:\\ \;\;\;\;\left|\sin th \cdot \frac{\sin ky}{\sin kx}\right|\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin ky \cdot \sin th}{\sin ky}\\ \end{array} \]
Alternative 8
Accuracy76.8%
Cost39048
\[\begin{array}{l} t_1 := \mathsf{hypot}\left(\sin ky, \sin kx\right)\\ \mathbf{if}\;\sin ky \leq -0.04:\\ \;\;\;\;\frac{\sin ky}{t_1} \cdot th\\ \mathbf{elif}\;\sin ky \leq 2 \cdot 10^{-5}:\\ \;\;\;\;ky \cdot \frac{\sin th}{t_1}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
Alternative 9
Accuracy76.9%
Cost39048
\[\begin{array}{l} t_1 := \mathsf{hypot}\left(\sin ky, \sin kx\right)\\ \mathbf{if}\;\sin ky \leq -0.04:\\ \;\;\;\;\frac{\sin ky}{t_1} \cdot th\\ \mathbf{elif}\;\sin ky \leq 2 \cdot 10^{-5}:\\ \;\;\;\;\frac{\sin th}{\frac{t_1}{ky}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
Alternative 10
Accuracy46.6%
Cost32584
\[\begin{array}{l} \mathbf{if}\;\sin ky \leq -1 \cdot 10^{-60}:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq 10^{-147}:\\ \;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin ky \cdot \sin th}{\sin ky}\\ \end{array} \]
Alternative 11
Accuracy99.6%
Cost32384
\[\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \]
Alternative 12
Accuracy46.4%
Cost26184
\[\begin{array}{l} \mathbf{if}\;\sin ky \leq -1 \cdot 10^{-60}:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq 10^{-147}:\\ \;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
Alternative 13
Accuracy41.1%
Cost19784
\[\begin{array}{l} \mathbf{if}\;\sin ky \leq -1 \cdot 10^{-60}:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq 5 \cdot 10^{-164}:\\ \;\;\;\;\sin th \cdot \frac{ky}{kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
Alternative 14
Accuracy33.4%
Cost13252
\[\begin{array}{l} \mathbf{if}\;\sin ky \leq 5 \cdot 10^{-164}:\\ \;\;\;\;\sin th \cdot \frac{ky}{kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
Alternative 15
Accuracy32.5%
Cost6984
\[\begin{array}{l} \mathbf{if}\;ky \leq -0.112:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq 3.1 \cdot 10^{-140}:\\ \;\;\;\;ky \cdot \frac{th}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
Alternative 16
Accuracy31.0%
Cost6728
\[\begin{array}{l} \mathbf{if}\;ky \leq -0.135:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq 1.18 \cdot 10^{-163}:\\ \;\;\;\;th \cdot \frac{ky}{kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
Alternative 17
Accuracy21.3%
Cost584
\[\begin{array}{l} \mathbf{if}\;ky \leq -8 \cdot 10^{-10}:\\ \;\;\;\;th\\ \mathbf{elif}\;ky \leq 7.5 \cdot 10^{-88}:\\ \;\;\;\;th \cdot \frac{ky}{kx}\\ \mathbf{else}:\\ \;\;\;\;th\\ \end{array} \]
Alternative 18
Accuracy13.7%
Cost64
\[th \]

Reproduce?

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