
(FPCore (a1 a2 th) :precision binary64 (let* ((t_1 (/ (cos th) (sqrt 2.0)))) (+ (* t_1 (* a1 a1)) (* t_1 (* a2 a2)))))
double code(double a1, double a2, double th) {
double t_1 = cos(th) / sqrt(2.0);
return (t_1 * (a1 * a1)) + (t_1 * (a2 * a2));
}
real(8) function code(a1, a2, th)
real(8), intent (in) :: a1
real(8), intent (in) :: a2
real(8), intent (in) :: th
real(8) :: t_1
t_1 = cos(th) / sqrt(2.0d0)
code = (t_1 * (a1 * a1)) + (t_1 * (a2 * a2))
end function
public static double code(double a1, double a2, double th) {
double t_1 = Math.cos(th) / Math.sqrt(2.0);
return (t_1 * (a1 * a1)) + (t_1 * (a2 * a2));
}
def code(a1, a2, th): t_1 = math.cos(th) / math.sqrt(2.0) return (t_1 * (a1 * a1)) + (t_1 * (a2 * a2))
function code(a1, a2, th) t_1 = Float64(cos(th) / sqrt(2.0)) return Float64(Float64(t_1 * Float64(a1 * a1)) + Float64(t_1 * Float64(a2 * a2))) end
function tmp = code(a1, a2, th) t_1 = cos(th) / sqrt(2.0); tmp = (t_1 * (a1 * a1)) + (t_1 * (a2 * a2)); end
code[a1_, a2_, th_] := Block[{t$95$1 = N[(N[Cos[th], $MachinePrecision] / N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]}, N[(N[(t$95$1 * N[(a1 * a1), $MachinePrecision]), $MachinePrecision] + N[(t$95$1 * N[(a2 * a2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{\cos th}{\sqrt{2}}\\
t\_1 \cdot \left(a1 \cdot a1\right) + t\_1 \cdot \left(a2 \cdot a2\right)
\end{array}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a1 a2 th) :precision binary64 (let* ((t_1 (/ (cos th) (sqrt 2.0)))) (+ (* t_1 (* a1 a1)) (* t_1 (* a2 a2)))))
double code(double a1, double a2, double th) {
double t_1 = cos(th) / sqrt(2.0);
return (t_1 * (a1 * a1)) + (t_1 * (a2 * a2));
}
real(8) function code(a1, a2, th)
real(8), intent (in) :: a1
real(8), intent (in) :: a2
real(8), intent (in) :: th
real(8) :: t_1
t_1 = cos(th) / sqrt(2.0d0)
code = (t_1 * (a1 * a1)) + (t_1 * (a2 * a2))
end function
public static double code(double a1, double a2, double th) {
double t_1 = Math.cos(th) / Math.sqrt(2.0);
return (t_1 * (a1 * a1)) + (t_1 * (a2 * a2));
}
def code(a1, a2, th): t_1 = math.cos(th) / math.sqrt(2.0) return (t_1 * (a1 * a1)) + (t_1 * (a2 * a2))
function code(a1, a2, th) t_1 = Float64(cos(th) / sqrt(2.0)) return Float64(Float64(t_1 * Float64(a1 * a1)) + Float64(t_1 * Float64(a2 * a2))) end
function tmp = code(a1, a2, th) t_1 = cos(th) / sqrt(2.0); tmp = (t_1 * (a1 * a1)) + (t_1 * (a2 * a2)); end
code[a1_, a2_, th_] := Block[{t$95$1 = N[(N[Cos[th], $MachinePrecision] / N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]}, N[(N[(t$95$1 * N[(a1 * a1), $MachinePrecision]), $MachinePrecision] + N[(t$95$1 * N[(a2 * a2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{\cos th}{\sqrt{2}}\\
t\_1 \cdot \left(a1 \cdot a1\right) + t\_1 \cdot \left(a2 \cdot a2\right)
\end{array}
\end{array}
(FPCore (a1 a2 th) :precision binary64 (let* ((t_1 (/ (cos th) (sqrt 2.0)))) (+ (* t_1 (* a1 a1)) (* t_1 (* a2 a2)))))
double code(double a1, double a2, double th) {
double t_1 = cos(th) / sqrt(2.0);
return (t_1 * (a1 * a1)) + (t_1 * (a2 * a2));
}
real(8) function code(a1, a2, th)
real(8), intent (in) :: a1
real(8), intent (in) :: a2
real(8), intent (in) :: th
real(8) :: t_1
t_1 = cos(th) / sqrt(2.0d0)
code = (t_1 * (a1 * a1)) + (t_1 * (a2 * a2))
end function
public static double code(double a1, double a2, double th) {
double t_1 = Math.cos(th) / Math.sqrt(2.0);
return (t_1 * (a1 * a1)) + (t_1 * (a2 * a2));
}
def code(a1, a2, th): t_1 = math.cos(th) / math.sqrt(2.0) return (t_1 * (a1 * a1)) + (t_1 * (a2 * a2))
function code(a1, a2, th) t_1 = Float64(cos(th) / sqrt(2.0)) return Float64(Float64(t_1 * Float64(a1 * a1)) + Float64(t_1 * Float64(a2 * a2))) end
function tmp = code(a1, a2, th) t_1 = cos(th) / sqrt(2.0); tmp = (t_1 * (a1 * a1)) + (t_1 * (a2 * a2)); end
code[a1_, a2_, th_] := Block[{t$95$1 = N[(N[Cos[th], $MachinePrecision] / N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]}, N[(N[(t$95$1 * N[(a1 * a1), $MachinePrecision]), $MachinePrecision] + N[(t$95$1 * N[(a2 * a2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{\cos th}{\sqrt{2}}\\
t\_1 \cdot \left(a1 \cdot a1\right) + t\_1 \cdot \left(a2 \cdot a2\right)
\end{array}
\end{array}
Initial program 99.6%
(FPCore (a1 a2 th) :precision binary64 (let* ((t_1 (/ (cos th) (sqrt 2.0)))) (if (<= (* a1 a1) 4.3e+98) (* t_1 (* a2 a2)) (* t_1 (* a1 a1)))))
double code(double a1, double a2, double th) {
double t_1 = cos(th) / sqrt(2.0);
double tmp;
if ((a1 * a1) <= 4.3e+98) {
tmp = t_1 * (a2 * a2);
} else {
tmp = t_1 * (a1 * a1);
}
return tmp;
}
real(8) function code(a1, a2, th)
real(8), intent (in) :: a1
real(8), intent (in) :: a2
real(8), intent (in) :: th
real(8) :: t_1
real(8) :: tmp
t_1 = cos(th) / sqrt(2.0d0)
if ((a1 * a1) <= 4.3d+98) then
tmp = t_1 * (a2 * a2)
else
tmp = t_1 * (a1 * a1)
end if
code = tmp
end function
public static double code(double a1, double a2, double th) {
double t_1 = Math.cos(th) / Math.sqrt(2.0);
double tmp;
if ((a1 * a1) <= 4.3e+98) {
tmp = t_1 * (a2 * a2);
} else {
tmp = t_1 * (a1 * a1);
}
return tmp;
}
def code(a1, a2, th): t_1 = math.cos(th) / math.sqrt(2.0) tmp = 0 if (a1 * a1) <= 4.3e+98: tmp = t_1 * (a2 * a2) else: tmp = t_1 * (a1 * a1) return tmp
function code(a1, a2, th) t_1 = Float64(cos(th) / sqrt(2.0)) tmp = 0.0 if (Float64(a1 * a1) <= 4.3e+98) tmp = Float64(t_1 * Float64(a2 * a2)); else tmp = Float64(t_1 * Float64(a1 * a1)); end return tmp end
function tmp_2 = code(a1, a2, th) t_1 = cos(th) / sqrt(2.0); tmp = 0.0; if ((a1 * a1) <= 4.3e+98) tmp = t_1 * (a2 * a2); else tmp = t_1 * (a1 * a1); end tmp_2 = tmp; end
code[a1_, a2_, th_] := Block[{t$95$1 = N[(N[Cos[th], $MachinePrecision] / N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(a1 * a1), $MachinePrecision], 4.3e+98], N[(t$95$1 * N[(a2 * a2), $MachinePrecision]), $MachinePrecision], N[(t$95$1 * N[(a1 * a1), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{\cos th}{\sqrt{2}}\\
\mathbf{if}\;a1 \cdot a1 \leq 4.3 \cdot 10^{+98}:\\
\;\;\;\;t\_1 \cdot \left(a2 \cdot a2\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1 \cdot \left(a1 \cdot a1\right)\\
\end{array}
\end{array}
if (*.f64 a1 a1) < 4.3000000000000001e98Initial program 99.5%
Taylor expanded in a2 around inf
Applied rewrites81.7%
if 4.3000000000000001e98 < (*.f64 a1 a1) Initial program 99.7%
Taylor expanded in a1 around 0
Applied rewrites88.7%
(FPCore (a1 a2 th) :precision binary64 (* (/ (cos th) (sqrt 2.0)) (* a1 a1)))
double code(double a1, double a2, double th) {
return (cos(th) / sqrt(2.0)) * (a1 * a1);
}
real(8) function code(a1, a2, th)
real(8), intent (in) :: a1
real(8), intent (in) :: a2
real(8), intent (in) :: th
code = (cos(th) / sqrt(2.0d0)) * (a1 * a1)
end function
public static double code(double a1, double a2, double th) {
return (Math.cos(th) / Math.sqrt(2.0)) * (a1 * a1);
}
def code(a1, a2, th): return (math.cos(th) / math.sqrt(2.0)) * (a1 * a1)
function code(a1, a2, th) return Float64(Float64(cos(th) / sqrt(2.0)) * Float64(a1 * a1)) end
function tmp = code(a1, a2, th) tmp = (cos(th) / sqrt(2.0)) * (a1 * a1); end
code[a1_, a2_, th_] := N[(N[(N[Cos[th], $MachinePrecision] / N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision] * N[(a1 * a1), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right)
\end{array}
Initial program 99.6%
Taylor expanded in a1 around 0
Applied rewrites57.8%
(FPCore (a1 a2 th) :precision binary64 (/ (cos th) (sqrt 2.0)))
double code(double a1, double a2, double th) {
return cos(th) / sqrt(2.0);
}
real(8) function code(a1, a2, th)
real(8), intent (in) :: a1
real(8), intent (in) :: a2
real(8), intent (in) :: th
code = cos(th) / sqrt(2.0d0)
end function
public static double code(double a1, double a2, double th) {
return Math.cos(th) / Math.sqrt(2.0);
}
def code(a1, a2, th): return math.cos(th) / math.sqrt(2.0)
function code(a1, a2, th) return Float64(cos(th) / sqrt(2.0)) end
function tmp = code(a1, a2, th) tmp = cos(th) / sqrt(2.0); end
code[a1_, a2_, th_] := N[(N[Cos[th], $MachinePrecision] / N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\cos th}{\sqrt{2}}
\end{array}
Initial program 99.6%
Taylor expanded in a1 around inf
Applied rewrites4.1%
Taylor expanded in a2 around inf
Applied rewrites4.1%
(FPCore (a1 a2 th) :precision binary64 (cos th))
double code(double a1, double a2, double th) {
return cos(th);
}
real(8) function code(a1, a2, th)
real(8), intent (in) :: a1
real(8), intent (in) :: a2
real(8), intent (in) :: th
code = cos(th)
end function
public static double code(double a1, double a2, double th) {
return Math.cos(th);
}
def code(a1, a2, th): return math.cos(th)
function code(a1, a2, th) return cos(th) end
function tmp = code(a1, a2, th) tmp = cos(th); end
code[a1_, a2_, th_] := N[Cos[th], $MachinePrecision]
\begin{array}{l}
\\
\cos th
\end{array}
Initial program 99.6%
Taylor expanded in a1 around inf
Applied rewrites4.1%
(FPCore (a1 a2 th) :precision binary64 (sqrt 2.0))
double code(double a1, double a2, double th) {
return sqrt(2.0);
}
real(8) function code(a1, a2, th)
real(8), intent (in) :: a1
real(8), intent (in) :: a2
real(8), intent (in) :: th
code = sqrt(2.0d0)
end function
public static double code(double a1, double a2, double th) {
return Math.sqrt(2.0);
}
def code(a1, a2, th): return math.sqrt(2.0)
function code(a1, a2, th) return sqrt(2.0) end
function tmp = code(a1, a2, th) tmp = sqrt(2.0); end
code[a1_, a2_, th_] := N[Sqrt[2.0], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{2}
\end{array}
Initial program 99.6%
Taylor expanded in a1 around inf
Applied rewrites4.1%
Taylor expanded in a2 around inf
Applied rewrites4.1%
Taylor expanded in a1 around inf
Applied rewrites3.4%
herbie shell --seed 2024321
(FPCore (a1 a2 th)
:name "Migdal et al, Equation (64)"
:precision binary64
:pre (TRUE)
(+ (* (/ (cos th) (sqrt 2.0)) (* a1 a1)) (* (/ (cos th) (sqrt 2.0)) (* a2 a2))))