
(FPCore (a b angle) :precision binary64 (let* ((t_0 (* (/ angle 180.0) PI))) (+ (pow (* a (sin t_0)) 2.0) (pow (* b (cos t_0)) 2.0))))
double code(double a, double b, double angle) {
double t_0 = (angle / 180.0) * ((double) M_PI);
return pow((a * sin(t_0)), 2.0) + pow((b * cos(t_0)), 2.0);
}
public static double code(double a, double b, double angle) {
double t_0 = (angle / 180.0) * Math.PI;
return Math.pow((a * Math.sin(t_0)), 2.0) + Math.pow((b * Math.cos(t_0)), 2.0);
}
def code(a, b, angle): t_0 = (angle / 180.0) * math.pi return math.pow((a * math.sin(t_0)), 2.0) + math.pow((b * math.cos(t_0)), 2.0)
function code(a, b, angle) t_0 = Float64(Float64(angle / 180.0) * pi) return Float64((Float64(a * sin(t_0)) ^ 2.0) + (Float64(b * cos(t_0)) ^ 2.0)) end
function tmp = code(a, b, angle) t_0 = (angle / 180.0) * pi; tmp = ((a * sin(t_0)) ^ 2.0) + ((b * cos(t_0)) ^ 2.0); end
code[a_, b_, angle_] := Block[{t$95$0 = N[(N[(angle / 180.0), $MachinePrecision] * Pi), $MachinePrecision]}, N[(N[Power[N[(a * N[Sin[t$95$0], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[(b * N[Cos[t$95$0], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{angle}{180} \cdot \pi\\
{\left(a \cdot \sin t\_0\right)}^{2} + {\left(b \cdot \cos t\_0\right)}^{2}
\end{array}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b angle) :precision binary64 (let* ((t_0 (* (/ angle 180.0) PI))) (+ (pow (* a (sin t_0)) 2.0) (pow (* b (cos t_0)) 2.0))))
double code(double a, double b, double angle) {
double t_0 = (angle / 180.0) * ((double) M_PI);
return pow((a * sin(t_0)), 2.0) + pow((b * cos(t_0)), 2.0);
}
public static double code(double a, double b, double angle) {
double t_0 = (angle / 180.0) * Math.PI;
return Math.pow((a * Math.sin(t_0)), 2.0) + Math.pow((b * Math.cos(t_0)), 2.0);
}
def code(a, b, angle): t_0 = (angle / 180.0) * math.pi return math.pow((a * math.sin(t_0)), 2.0) + math.pow((b * math.cos(t_0)), 2.0)
function code(a, b, angle) t_0 = Float64(Float64(angle / 180.0) * pi) return Float64((Float64(a * sin(t_0)) ^ 2.0) + (Float64(b * cos(t_0)) ^ 2.0)) end
function tmp = code(a, b, angle) t_0 = (angle / 180.0) * pi; tmp = ((a * sin(t_0)) ^ 2.0) + ((b * cos(t_0)) ^ 2.0); end
code[a_, b_, angle_] := Block[{t$95$0 = N[(N[(angle / 180.0), $MachinePrecision] * Pi), $MachinePrecision]}, N[(N[Power[N[(a * N[Sin[t$95$0], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[(b * N[Cos[t$95$0], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{angle}{180} \cdot \pi\\
{\left(a \cdot \sin t\_0\right)}^{2} + {\left(b \cdot \cos t\_0\right)}^{2}
\end{array}
\end{array}
(FPCore (a b angle) :precision binary64 (+ (pow (* a (sin (* (* PI 0.005555555555555556) (/ 1.0 (/ 1.0 angle))))) 2.0) (* b b)))
double code(double a, double b, double angle) {
return pow((a * sin(((((double) M_PI) * 0.005555555555555556) * (1.0 / (1.0 / angle))))), 2.0) + (b * b);
}
public static double code(double a, double b, double angle) {
return Math.pow((a * Math.sin(((Math.PI * 0.005555555555555556) * (1.0 / (1.0 / angle))))), 2.0) + (b * b);
}
def code(a, b, angle): return math.pow((a * math.sin(((math.pi * 0.005555555555555556) * (1.0 / (1.0 / angle))))), 2.0) + (b * b)
function code(a, b, angle) return Float64((Float64(a * sin(Float64(Float64(pi * 0.005555555555555556) * Float64(1.0 / Float64(1.0 / angle))))) ^ 2.0) + Float64(b * b)) end
function tmp = code(a, b, angle) tmp = ((a * sin(((pi * 0.005555555555555556) * (1.0 / (1.0 / angle))))) ^ 2.0) + (b * b); end
code[a_, b_, angle_] := N[(N[Power[N[(a * N[Sin[N[(N[(Pi * 0.005555555555555556), $MachinePrecision] * N[(1.0 / N[(1.0 / angle), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(a \cdot \sin \left(\left(\pi \cdot 0.005555555555555556\right) \cdot \frac{1}{\frac{1}{angle}}\right)\right)}^{2} + b \cdot b
\end{array}
Initial program 80.8%
associate-*l/80.8%
associate-/l*80.8%
cos-neg80.8%
distribute-lft-neg-out80.8%
distribute-frac-neg80.8%
distribute-frac-neg80.8%
distribute-lft-neg-out80.8%
cos-neg80.8%
associate-*l/80.9%
associate-/l*81.0%
Simplified81.0%
Taylor expanded in angle around 0 81.2%
*-commutative81.2%
associate-/r/80.9%
div-inv80.9%
associate-/r*81.2%
div-inv81.2%
metadata-eval81.2%
Applied egg-rr81.2%
frac-2neg81.2%
div-inv81.3%
Applied egg-rr81.3%
*-rgt-identity81.3%
unpow281.3%
Applied egg-rr81.3%
Final simplification81.3%
(FPCore (a b angle) :precision binary64 (if (<= b 0.52) (pow (* a (sin (/ (* PI 0.005555555555555556) (/ 1.0 angle)))) 2.0) (pow b 2.0)))
double code(double a, double b, double angle) {
double tmp;
if (b <= 0.52) {
tmp = pow((a * sin(((((double) M_PI) * 0.005555555555555556) / (1.0 / angle)))), 2.0);
} else {
tmp = pow(b, 2.0);
}
return tmp;
}
public static double code(double a, double b, double angle) {
double tmp;
if (b <= 0.52) {
tmp = Math.pow((a * Math.sin(((Math.PI * 0.005555555555555556) / (1.0 / angle)))), 2.0);
} else {
tmp = Math.pow(b, 2.0);
}
return tmp;
}
def code(a, b, angle): tmp = 0 if b <= 0.52: tmp = math.pow((a * math.sin(((math.pi * 0.005555555555555556) / (1.0 / angle)))), 2.0) else: tmp = math.pow(b, 2.0) return tmp
function code(a, b, angle) tmp = 0.0 if (b <= 0.52) tmp = Float64(a * sin(Float64(Float64(pi * 0.005555555555555556) / Float64(1.0 / angle)))) ^ 2.0; else tmp = b ^ 2.0; end return tmp end
function tmp_2 = code(a, b, angle) tmp = 0.0; if (b <= 0.52) tmp = (a * sin(((pi * 0.005555555555555556) / (1.0 / angle)))) ^ 2.0; else tmp = b ^ 2.0; end tmp_2 = tmp; end
code[a_, b_, angle_] := If[LessEqual[b, 0.52], N[Power[N[(a * N[Sin[N[(N[(Pi * 0.005555555555555556), $MachinePrecision] / N[(1.0 / angle), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision], N[Power[b, 2.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 0.52:\\
\;\;\;\;{\left(a \cdot \sin \left(\frac{\pi \cdot 0.005555555555555556}{\frac{1}{angle}}\right)\right)}^{2}\\
\mathbf{else}:\\
\;\;\;\;{b}^{2}\\
\end{array}
\end{array}
if b < 0.52000000000000002Initial program 80.0%
associate-*l/80.0%
associate-/l*80.0%
cos-neg80.0%
distribute-lft-neg-out80.0%
distribute-frac-neg80.0%
distribute-frac-neg80.0%
distribute-lft-neg-out80.0%
cos-neg80.0%
associate-*l/80.1%
associate-/l*80.1%
Simplified80.1%
Taylor expanded in a around inf 44.8%
unpow244.8%
*-commutative44.8%
associate-*r*44.8%
unpow244.8%
swap-sqr57.4%
unpow257.4%
associate-*r*57.4%
*-commutative57.4%
Simplified57.4%
*-commutative57.4%
associate-*r*57.4%
*-commutative57.4%
/-rgt-identity57.4%
associate-/r/57.5%
Applied egg-rr57.5%
if 0.52000000000000002 < b Initial program 82.8%
associate-*l/82.8%
associate-/l*82.8%
cos-neg82.8%
distribute-lft-neg-out82.8%
distribute-frac-neg82.8%
distribute-frac-neg82.8%
distribute-lft-neg-out82.8%
cos-neg82.8%
associate-*l/83.0%
associate-/l*83.1%
Simplified83.1%
Taylor expanded in angle around 0 82.1%
(FPCore (a b angle) :precision binary64 (if (<= b 0.8) (pow (* a (sin (* 0.005555555555555556 (* PI angle)))) 2.0) (pow b 2.0)))
double code(double a, double b, double angle) {
double tmp;
if (b <= 0.8) {
tmp = pow((a * sin((0.005555555555555556 * (((double) M_PI) * angle)))), 2.0);
} else {
tmp = pow(b, 2.0);
}
return tmp;
}
public static double code(double a, double b, double angle) {
double tmp;
if (b <= 0.8) {
tmp = Math.pow((a * Math.sin((0.005555555555555556 * (Math.PI * angle)))), 2.0);
} else {
tmp = Math.pow(b, 2.0);
}
return tmp;
}
def code(a, b, angle): tmp = 0 if b <= 0.8: tmp = math.pow((a * math.sin((0.005555555555555556 * (math.pi * angle)))), 2.0) else: tmp = math.pow(b, 2.0) return tmp
function code(a, b, angle) tmp = 0.0 if (b <= 0.8) tmp = Float64(a * sin(Float64(0.005555555555555556 * Float64(pi * angle)))) ^ 2.0; else tmp = b ^ 2.0; end return tmp end
function tmp_2 = code(a, b, angle) tmp = 0.0; if (b <= 0.8) tmp = (a * sin((0.005555555555555556 * (pi * angle)))) ^ 2.0; else tmp = b ^ 2.0; end tmp_2 = tmp; end
code[a_, b_, angle_] := If[LessEqual[b, 0.8], N[Power[N[(a * N[Sin[N[(0.005555555555555556 * N[(Pi * angle), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision], N[Power[b, 2.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 0.8:\\
\;\;\;\;{\left(a \cdot \sin \left(0.005555555555555556 \cdot \left(\pi \cdot angle\right)\right)\right)}^{2}\\
\mathbf{else}:\\
\;\;\;\;{b}^{2}\\
\end{array}
\end{array}
if b < 0.80000000000000004Initial program 80.0%
associate-*l/80.0%
associate-/l*80.0%
cos-neg80.0%
distribute-lft-neg-out80.0%
distribute-frac-neg80.0%
distribute-frac-neg80.0%
distribute-lft-neg-out80.0%
cos-neg80.0%
associate-*l/80.1%
associate-/l*80.1%
Simplified80.1%
Taylor expanded in a around inf 44.8%
unpow244.8%
*-commutative44.8%
associate-*r*44.8%
unpow244.8%
swap-sqr57.4%
unpow257.4%
associate-*r*57.4%
*-commutative57.4%
Simplified57.4%
if 0.80000000000000004 < b Initial program 82.8%
associate-*l/82.8%
associate-/l*82.8%
cos-neg82.8%
distribute-lft-neg-out82.8%
distribute-frac-neg82.8%
distribute-frac-neg82.8%
distribute-lft-neg-out82.8%
cos-neg82.8%
associate-*l/83.0%
associate-/l*83.1%
Simplified83.1%
Taylor expanded in angle around 0 82.1%
Final simplification64.6%
(FPCore (a b angle) :precision binary64 (+ (* b b) (pow (* a (sin (* angle (/ PI 180.0)))) 2.0)))
double code(double a, double b, double angle) {
return (b * b) + pow((a * sin((angle * (((double) M_PI) / 180.0)))), 2.0);
}
public static double code(double a, double b, double angle) {
return (b * b) + Math.pow((a * Math.sin((angle * (Math.PI / 180.0)))), 2.0);
}
def code(a, b, angle): return (b * b) + math.pow((a * math.sin((angle * (math.pi / 180.0)))), 2.0)
function code(a, b, angle) return Float64(Float64(b * b) + (Float64(a * sin(Float64(angle * Float64(pi / 180.0)))) ^ 2.0)) end
function tmp = code(a, b, angle) tmp = (b * b) + ((a * sin((angle * (pi / 180.0)))) ^ 2.0); end
code[a_, b_, angle_] := N[(N[(b * b), $MachinePrecision] + N[Power[N[(a * N[Sin[N[(angle * N[(Pi / 180.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
b \cdot b + {\left(a \cdot \sin \left(angle \cdot \frac{\pi}{180}\right)\right)}^{2}
\end{array}
Initial program 80.8%
associate-*l/80.8%
associate-/l*80.8%
cos-neg80.8%
distribute-lft-neg-out80.8%
distribute-frac-neg80.8%
distribute-frac-neg80.8%
distribute-lft-neg-out80.8%
cos-neg80.8%
associate-*l/80.9%
associate-/l*81.0%
Simplified81.0%
Taylor expanded in angle around 0 81.2%
*-rgt-identity81.3%
unpow281.3%
Applied egg-rr81.2%
Final simplification81.2%
(FPCore (a b angle) :precision binary64 (pow b 2.0))
double code(double a, double b, double angle) {
return pow(b, 2.0);
}
real(8) function code(a, b, angle)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: angle
code = b ** 2.0d0
end function
public static double code(double a, double b, double angle) {
return Math.pow(b, 2.0);
}
def code(a, b, angle): return math.pow(b, 2.0)
function code(a, b, angle) return b ^ 2.0 end
function tmp = code(a, b, angle) tmp = b ^ 2.0; end
code[a_, b_, angle_] := N[Power[b, 2.0], $MachinePrecision]
\begin{array}{l}
\\
{b}^{2}
\end{array}
Initial program 80.8%
associate-*l/80.8%
associate-/l*80.8%
cos-neg80.8%
distribute-lft-neg-out80.8%
distribute-frac-neg80.8%
distribute-frac-neg80.8%
distribute-lft-neg-out80.8%
cos-neg80.8%
associate-*l/80.9%
associate-/l*81.0%
Simplified81.0%
Taylor expanded in angle around 0 52.1%
herbie shell --seed 2024144
(FPCore (a b angle)
:name "ab-angle->ABCF A"
:precision binary64
(+ (pow (* a (sin (* (/ angle 180.0) PI))) 2.0) (pow (* b (cos (* (/ angle 180.0) PI))) 2.0)))