
(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:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(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}
(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}
Initial program 92.7%
(FPCore (kx ky th) :precision binary64 (if (<= (sin th) 1.15e-50) (pow (sin ky) 2.0) (sin ky)))
double code(double kx, double ky, double th) {
double tmp;
if (sin(th) <= 1.15e-50) {
tmp = pow(sin(ky), 2.0);
} else {
tmp = sin(ky);
}
return tmp;
}
real(8) function code(kx, ky, th)
real(8), intent (in) :: kx
real(8), intent (in) :: ky
real(8), intent (in) :: th
real(8) :: tmp
if (sin(th) <= 1.15d-50) then
tmp = sin(ky) ** 2.0d0
else
tmp = sin(ky)
end if
code = tmp
end function
public static double code(double kx, double ky, double th) {
double tmp;
if (Math.sin(th) <= 1.15e-50) {
tmp = Math.pow(Math.sin(ky), 2.0);
} else {
tmp = Math.sin(ky);
}
return tmp;
}
def code(kx, ky, th): tmp = 0 if math.sin(th) <= 1.15e-50: tmp = math.pow(math.sin(ky), 2.0) else: tmp = math.sin(ky) return tmp
function code(kx, ky, th) tmp = 0.0 if (sin(th) <= 1.15e-50) tmp = sin(ky) ^ 2.0; else tmp = sin(ky); end return tmp end
function tmp_2 = code(kx, ky, th) tmp = 0.0; if (sin(th) <= 1.15e-50) tmp = sin(ky) ^ 2.0; else tmp = sin(ky); end tmp_2 = tmp; end
code[kx_, ky_, th_] := If[LessEqual[N[Sin[th], $MachinePrecision], 1.15e-50], N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision], N[Sin[ky], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\sin th \leq 1.15 \cdot 10^{-50}:\\
\;\;\;\;{\sin ky}^{2}\\
\mathbf{else}:\\
\;\;\;\;\sin ky\\
\end{array}
\end{array}
if (sin.f64 th) < 1.1500000000000001e-50Initial program 94.2%
Taylor expanded in kx around 0
Applied rewrites19.0%
Taylor expanded in kx around 0
Applied rewrites13.2%
if 1.1500000000000001e-50 < (sin.f64 th) Initial program 88.7%
Taylor expanded in kx around 0
Applied rewrites14.2%
(FPCore (kx ky th) :precision binary64 (* (sin ky) (sin th)))
double code(double kx, double ky, double th) {
return sin(ky) * 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) * sin(th)
end function
public static double code(double kx, double ky, double th) {
return Math.sin(ky) * Math.sin(th);
}
def code(kx, ky, th): return math.sin(ky) * math.sin(th)
function code(kx, ky, th) return Float64(sin(ky) * sin(th)) end
function tmp = code(kx, ky, th) tmp = sin(ky) * sin(th); end
code[kx_, ky_, th_] := N[(N[Sin[ky], $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sin ky \cdot \sin th
\end{array}
Initial program 92.7%
Taylor expanded in kx around 0
Applied rewrites16.1%
Taylor expanded in kx around 0
Applied rewrites23.8%
(FPCore (kx ky th) :precision binary64 (sin ky))
double code(double kx, double ky, double th) {
return sin(ky);
}
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)
end function
public static double code(double kx, double ky, double th) {
return Math.sin(ky);
}
def code(kx, ky, th): return math.sin(ky)
function code(kx, ky, th) return sin(ky) end
function tmp = code(kx, ky, th) tmp = sin(ky); end
code[kx_, ky_, th_] := N[Sin[ky], $MachinePrecision]
\begin{array}{l}
\\
\sin ky
\end{array}
Initial program 92.7%
Taylor expanded in kx around 0
Applied rewrites6.6%
(FPCore (kx ky th) :precision binary64 (sin kx))
double code(double kx, double ky, double th) {
return sin(kx);
}
real(8) function code(kx, ky, th)
real(8), intent (in) :: kx
real(8), intent (in) :: ky
real(8), intent (in) :: th
code = sin(kx)
end function
public static double code(double kx, double ky, double th) {
return Math.sin(kx);
}
def code(kx, ky, th): return math.sin(kx)
function code(kx, ky, th) return sin(kx) end
function tmp = code(kx, ky, th) tmp = sin(kx); end
code[kx_, ky_, th_] := N[Sin[kx], $MachinePrecision]
\begin{array}{l}
\\
\sin kx
\end{array}
Initial program 92.7%
Taylor expanded in kx around 0
Applied rewrites5.4%
Taylor expanded in kx around 0
Applied rewrites3.6%
Taylor expanded in kx around 0
Applied rewrites4.6%
herbie shell --seed 2024321
(FPCore (kx ky th)
:name "Toniolo and Linder, Equation (3b), real"
:precision binary64
:pre (TRUE)
(* (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0)))) (sin th)))