
(FPCore (a b angle) :precision binary64 (let* ((t_0 (* PI (/ angle 180.0)))) (+ (pow (* a (cos t_0)) 2.0) (pow (* b (sin t_0)) 2.0))))
double code(double a, double b, double angle) {
double t_0 = ((double) M_PI) * (angle / 180.0);
return pow((a * cos(t_0)), 2.0) + pow((b * sin(t_0)), 2.0);
}
public static double code(double a, double b, double angle) {
double t_0 = Math.PI * (angle / 180.0);
return Math.pow((a * Math.cos(t_0)), 2.0) + Math.pow((b * Math.sin(t_0)), 2.0);
}
def code(a, b, angle): t_0 = math.pi * (angle / 180.0) return math.pow((a * math.cos(t_0)), 2.0) + math.pow((b * math.sin(t_0)), 2.0)
function code(a, b, angle) t_0 = Float64(pi * Float64(angle / 180.0)) return Float64((Float64(a * cos(t_0)) ^ 2.0) + (Float64(b * sin(t_0)) ^ 2.0)) end
function tmp = code(a, b, angle) t_0 = pi * (angle / 180.0); tmp = ((a * cos(t_0)) ^ 2.0) + ((b * sin(t_0)) ^ 2.0); end
code[a_, b_, angle_] := Block[{t$95$0 = N[(Pi * N[(angle / 180.0), $MachinePrecision]), $MachinePrecision]}, N[(N[Power[N[(a * N[Cos[t$95$0], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[(b * N[Sin[t$95$0], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \pi \cdot \frac{angle}{180}\\
{\left(a \cdot \cos t\_0\right)}^{2} + {\left(b \cdot \sin t\_0\right)}^{2}
\end{array}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b angle) :precision binary64 (let* ((t_0 (* PI (/ angle 180.0)))) (+ (pow (* a (cos t_0)) 2.0) (pow (* b (sin t_0)) 2.0))))
double code(double a, double b, double angle) {
double t_0 = ((double) M_PI) * (angle / 180.0);
return pow((a * cos(t_0)), 2.0) + pow((b * sin(t_0)), 2.0);
}
public static double code(double a, double b, double angle) {
double t_0 = Math.PI * (angle / 180.0);
return Math.pow((a * Math.cos(t_0)), 2.0) + Math.pow((b * Math.sin(t_0)), 2.0);
}
def code(a, b, angle): t_0 = math.pi * (angle / 180.0) return math.pow((a * math.cos(t_0)), 2.0) + math.pow((b * math.sin(t_0)), 2.0)
function code(a, b, angle) t_0 = Float64(pi * Float64(angle / 180.0)) return Float64((Float64(a * cos(t_0)) ^ 2.0) + (Float64(b * sin(t_0)) ^ 2.0)) end
function tmp = code(a, b, angle) t_0 = pi * (angle / 180.0); tmp = ((a * cos(t_0)) ^ 2.0) + ((b * sin(t_0)) ^ 2.0); end
code[a_, b_, angle_] := Block[{t$95$0 = N[(Pi * N[(angle / 180.0), $MachinePrecision]), $MachinePrecision]}, N[(N[Power[N[(a * N[Cos[t$95$0], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[(b * N[Sin[t$95$0], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \pi \cdot \frac{angle}{180}\\
{\left(a \cdot \cos t\_0\right)}^{2} + {\left(b \cdot \sin t\_0\right)}^{2}
\end{array}
\end{array}
(FPCore (a b angle) :precision binary64 (+ (* a a) (pow (* b (sin (/ PI (/ 180.0 angle)))) 2.0)))
double code(double a, double b, double angle) {
return (a * a) + pow((b * sin((((double) M_PI) / (180.0 / angle)))), 2.0);
}
public static double code(double a, double b, double angle) {
return (a * a) + Math.pow((b * Math.sin((Math.PI / (180.0 / angle)))), 2.0);
}
def code(a, b, angle): return (a * a) + math.pow((b * math.sin((math.pi / (180.0 / angle)))), 2.0)
function code(a, b, angle) return Float64(Float64(a * a) + (Float64(b * sin(Float64(pi / Float64(180.0 / angle)))) ^ 2.0)) end
function tmp = code(a, b, angle) tmp = (a * a) + ((b * sin((pi / (180.0 / angle)))) ^ 2.0); end
code[a_, b_, angle_] := N[(N[(a * a), $MachinePrecision] + N[Power[N[(b * N[Sin[N[(Pi / N[(180.0 / angle), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
a \cdot a + {\left(b \cdot \sin \left(\frac{\pi}{\frac{180}{angle}}\right)\right)}^{2}
\end{array}
Initial program 82.7%
associate-*r/82.7%
metadata-eval82.7%
metadata-eval82.7%
distribute-neg-frac282.7%
distribute-frac-neg82.7%
distribute-rgt-neg-out82.7%
associate-/l*82.7%
neg-mul-182.7%
*-commutative82.7%
associate-/l*82.7%
metadata-eval82.7%
metadata-eval82.7%
Simplified82.8%
Taylor expanded in angle around 0 82.9%
metadata-eval82.9%
div-inv82.8%
clear-num82.9%
un-div-inv82.9%
Applied egg-rr82.9%
unpow282.9%
Applied egg-rr82.9%
(FPCore (a b angle) :precision binary64 (if (<= a 1.4e-149) (pow (* b (sin (* 0.005555555555555556 (* PI angle)))) 2.0) (+ (* a a) (pow (* 0.005555555555555556 (* PI (* b angle))) 2.0))))
double code(double a, double b, double angle) {
double tmp;
if (a <= 1.4e-149) {
tmp = pow((b * sin((0.005555555555555556 * (((double) M_PI) * angle)))), 2.0);
} else {
tmp = (a * a) + pow((0.005555555555555556 * (((double) M_PI) * (b * angle))), 2.0);
}
return tmp;
}
public static double code(double a, double b, double angle) {
double tmp;
if (a <= 1.4e-149) {
tmp = Math.pow((b * Math.sin((0.005555555555555556 * (Math.PI * angle)))), 2.0);
} else {
tmp = (a * a) + Math.pow((0.005555555555555556 * (Math.PI * (b * angle))), 2.0);
}
return tmp;
}
def code(a, b, angle): tmp = 0 if a <= 1.4e-149: tmp = math.pow((b * math.sin((0.005555555555555556 * (math.pi * angle)))), 2.0) else: tmp = (a * a) + math.pow((0.005555555555555556 * (math.pi * (b * angle))), 2.0) return tmp
function code(a, b, angle) tmp = 0.0 if (a <= 1.4e-149) tmp = Float64(b * sin(Float64(0.005555555555555556 * Float64(pi * angle)))) ^ 2.0; else tmp = Float64(Float64(a * a) + (Float64(0.005555555555555556 * Float64(pi * Float64(b * angle))) ^ 2.0)); end return tmp end
function tmp_2 = code(a, b, angle) tmp = 0.0; if (a <= 1.4e-149) tmp = (b * sin((0.005555555555555556 * (pi * angle)))) ^ 2.0; else tmp = (a * a) + ((0.005555555555555556 * (pi * (b * angle))) ^ 2.0); end tmp_2 = tmp; end
code[a_, b_, angle_] := If[LessEqual[a, 1.4e-149], N[Power[N[(b * N[Sin[N[(0.005555555555555556 * N[(Pi * angle), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision], N[(N[(a * a), $MachinePrecision] + N[Power[N[(0.005555555555555556 * N[(Pi * N[(b * angle), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1.4 \cdot 10^{-149}:\\
\;\;\;\;{\left(b \cdot \sin \left(0.005555555555555556 \cdot \left(\pi \cdot angle\right)\right)\right)}^{2}\\
\mathbf{else}:\\
\;\;\;\;a \cdot a + {\left(0.005555555555555556 \cdot \left(\pi \cdot \left(b \cdot angle\right)\right)\right)}^{2}\\
\end{array}
\end{array}
if a < 1.3999999999999999e-149Initial program 81.9%
associate-*r/81.9%
metadata-eval81.9%
metadata-eval81.9%
distribute-neg-frac281.9%
distribute-frac-neg81.9%
distribute-rgt-neg-out81.9%
associate-/l*81.9%
neg-mul-181.9%
*-commutative81.9%
associate-/l*82.0%
metadata-eval82.0%
metadata-eval82.0%
Simplified82.0%
Taylor expanded in a around 0 40.7%
unpow240.7%
*-commutative40.7%
unpow240.7%
swap-sqr48.0%
unpow248.0%
*-commutative48.0%
Simplified48.0%
if 1.3999999999999999e-149 < a Initial program 84.0%
associate-*r/83.8%
metadata-eval83.8%
metadata-eval83.8%
distribute-neg-frac283.8%
distribute-frac-neg83.8%
distribute-rgt-neg-out83.8%
associate-/l*84.0%
neg-mul-184.0%
*-commutative84.0%
associate-/l*83.9%
metadata-eval83.9%
metadata-eval83.9%
Simplified84.0%
Taylor expanded in angle around 0 84.2%
metadata-eval84.2%
div-inv84.1%
clear-num84.1%
un-div-inv84.1%
Applied egg-rr84.1%
unpow284.1%
Applied egg-rr84.1%
Taylor expanded in angle around 0 82.5%
associate-*r*82.5%
Simplified82.5%
Final simplification61.1%
(FPCore (a b angle) :precision binary64 (+ (* a a) (pow (* b (sin (* PI (* angle 0.005555555555555556)))) 2.0)))
double code(double a, double b, double angle) {
return (a * a) + pow((b * sin((((double) M_PI) * (angle * 0.005555555555555556)))), 2.0);
}
public static double code(double a, double b, double angle) {
return (a * a) + Math.pow((b * Math.sin((Math.PI * (angle * 0.005555555555555556)))), 2.0);
}
def code(a, b, angle): return (a * a) + math.pow((b * math.sin((math.pi * (angle * 0.005555555555555556)))), 2.0)
function code(a, b, angle) return Float64(Float64(a * a) + (Float64(b * sin(Float64(pi * Float64(angle * 0.005555555555555556)))) ^ 2.0)) end
function tmp = code(a, b, angle) tmp = (a * a) + ((b * sin((pi * (angle * 0.005555555555555556)))) ^ 2.0); end
code[a_, b_, angle_] := N[(N[(a * a), $MachinePrecision] + N[Power[N[(b * N[Sin[N[(Pi * N[(angle * 0.005555555555555556), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
a \cdot a + {\left(b \cdot \sin \left(\pi \cdot \left(angle \cdot 0.005555555555555556\right)\right)\right)}^{2}
\end{array}
Initial program 82.7%
associate-*r/82.7%
metadata-eval82.7%
metadata-eval82.7%
distribute-neg-frac282.7%
distribute-frac-neg82.7%
distribute-rgt-neg-out82.7%
associate-/l*82.7%
neg-mul-182.7%
*-commutative82.7%
associate-/l*82.7%
metadata-eval82.7%
metadata-eval82.7%
Simplified82.8%
Taylor expanded in angle around 0 82.9%
unpow282.9%
Applied egg-rr82.9%
(FPCore (a b angle) :precision binary64 (if (<= b 4.7e-154) (* a a) (+ (* a a) (pow (* 0.005555555555555556 (* PI (* b angle))) 2.0))))
double code(double a, double b, double angle) {
double tmp;
if (b <= 4.7e-154) {
tmp = a * a;
} else {
tmp = (a * a) + pow((0.005555555555555556 * (((double) M_PI) * (b * angle))), 2.0);
}
return tmp;
}
public static double code(double a, double b, double angle) {
double tmp;
if (b <= 4.7e-154) {
tmp = a * a;
} else {
tmp = (a * a) + Math.pow((0.005555555555555556 * (Math.PI * (b * angle))), 2.0);
}
return tmp;
}
def code(a, b, angle): tmp = 0 if b <= 4.7e-154: tmp = a * a else: tmp = (a * a) + math.pow((0.005555555555555556 * (math.pi * (b * angle))), 2.0) return tmp
function code(a, b, angle) tmp = 0.0 if (b <= 4.7e-154) tmp = Float64(a * a); else tmp = Float64(Float64(a * a) + (Float64(0.005555555555555556 * Float64(pi * Float64(b * angle))) ^ 2.0)); end return tmp end
function tmp_2 = code(a, b, angle) tmp = 0.0; if (b <= 4.7e-154) tmp = a * a; else tmp = (a * a) + ((0.005555555555555556 * (pi * (b * angle))) ^ 2.0); end tmp_2 = tmp; end
code[a_, b_, angle_] := If[LessEqual[b, 4.7e-154], N[(a * a), $MachinePrecision], N[(N[(a * a), $MachinePrecision] + N[Power[N[(0.005555555555555556 * N[(Pi * N[(b * angle), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 4.7 \cdot 10^{-154}:\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;a \cdot a + {\left(0.005555555555555556 \cdot \left(\pi \cdot \left(b \cdot angle\right)\right)\right)}^{2}\\
\end{array}
\end{array}
if b < 4.7000000000000002e-154Initial program 81.0%
associate-*r/80.9%
metadata-eval80.9%
metadata-eval80.9%
distribute-neg-frac280.9%
distribute-frac-neg80.9%
distribute-rgt-neg-out80.9%
associate-/l*81.0%
neg-mul-181.0%
*-commutative81.0%
associate-/l*81.0%
metadata-eval81.0%
metadata-eval81.0%
Simplified81.0%
Taylor expanded in angle around 0 62.8%
unpow281.3%
Applied egg-rr62.8%
if 4.7000000000000002e-154 < b Initial program 85.9%
associate-*r/85.9%
metadata-eval85.9%
metadata-eval85.9%
distribute-neg-frac285.9%
distribute-frac-neg85.9%
distribute-rgt-neg-out85.9%
associate-/l*85.9%
neg-mul-185.9%
*-commutative85.9%
associate-/l*85.9%
metadata-eval85.9%
metadata-eval85.9%
Simplified86.0%
Taylor expanded in angle around 0 86.1%
metadata-eval86.1%
div-inv85.9%
clear-num85.9%
un-div-inv86.0%
Applied egg-rr86.0%
unpow286.0%
Applied egg-rr86.0%
Taylor expanded in angle around 0 83.2%
associate-*r*83.2%
Simplified83.2%
Final simplification69.9%
(FPCore (a b angle) :precision binary64 (if (<= b 4.7e-154) (* a a) (+ (* a a) (pow (* 0.005555555555555556 (* angle (* b PI))) 2.0))))
double code(double a, double b, double angle) {
double tmp;
if (b <= 4.7e-154) {
tmp = a * a;
} else {
tmp = (a * a) + pow((0.005555555555555556 * (angle * (b * ((double) M_PI)))), 2.0);
}
return tmp;
}
public static double code(double a, double b, double angle) {
double tmp;
if (b <= 4.7e-154) {
tmp = a * a;
} else {
tmp = (a * a) + Math.pow((0.005555555555555556 * (angle * (b * Math.PI))), 2.0);
}
return tmp;
}
def code(a, b, angle): tmp = 0 if b <= 4.7e-154: tmp = a * a else: tmp = (a * a) + math.pow((0.005555555555555556 * (angle * (b * math.pi))), 2.0) return tmp
function code(a, b, angle) tmp = 0.0 if (b <= 4.7e-154) tmp = Float64(a * a); else tmp = Float64(Float64(a * a) + (Float64(0.005555555555555556 * Float64(angle * Float64(b * pi))) ^ 2.0)); end return tmp end
function tmp_2 = code(a, b, angle) tmp = 0.0; if (b <= 4.7e-154) tmp = a * a; else tmp = (a * a) + ((0.005555555555555556 * (angle * (b * pi))) ^ 2.0); end tmp_2 = tmp; end
code[a_, b_, angle_] := If[LessEqual[b, 4.7e-154], N[(a * a), $MachinePrecision], N[(N[(a * a), $MachinePrecision] + N[Power[N[(0.005555555555555556 * N[(angle * N[(b * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 4.7 \cdot 10^{-154}:\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;a \cdot a + {\left(0.005555555555555556 \cdot \left(angle \cdot \left(b \cdot \pi\right)\right)\right)}^{2}\\
\end{array}
\end{array}
if b < 4.7000000000000002e-154Initial program 81.0%
associate-*r/80.9%
metadata-eval80.9%
metadata-eval80.9%
distribute-neg-frac280.9%
distribute-frac-neg80.9%
distribute-rgt-neg-out80.9%
associate-/l*81.0%
neg-mul-181.0%
*-commutative81.0%
associate-/l*81.0%
metadata-eval81.0%
metadata-eval81.0%
Simplified81.0%
Taylor expanded in angle around 0 62.8%
unpow281.3%
Applied egg-rr62.8%
if 4.7000000000000002e-154 < b Initial program 85.9%
associate-*r/85.9%
metadata-eval85.9%
metadata-eval85.9%
distribute-neg-frac285.9%
distribute-frac-neg85.9%
distribute-rgt-neg-out85.9%
associate-/l*85.9%
neg-mul-185.9%
*-commutative85.9%
associate-/l*85.9%
metadata-eval85.9%
metadata-eval85.9%
Simplified86.0%
Taylor expanded in angle around 0 86.1%
metadata-eval86.1%
div-inv85.9%
clear-num85.9%
un-div-inv86.0%
Applied egg-rr86.0%
unpow286.0%
Applied egg-rr86.0%
Taylor expanded in angle around 0 83.2%
(FPCore (a b angle) :precision binary64 (* a a))
double code(double a, double b, double angle) {
return a * a;
}
real(8) function code(a, b, angle)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: angle
code = a * a
end function
public static double code(double a, double b, double angle) {
return a * a;
}
def code(a, b, angle): return a * a
function code(a, b, angle) return Float64(a * a) end
function tmp = code(a, b, angle) tmp = a * a; end
code[a_, b_, angle_] := N[(a * a), $MachinePrecision]
\begin{array}{l}
\\
a \cdot a
\end{array}
Initial program 82.7%
associate-*r/82.7%
metadata-eval82.7%
metadata-eval82.7%
distribute-neg-frac282.7%
distribute-frac-neg82.7%
distribute-rgt-neg-out82.7%
associate-/l*82.7%
neg-mul-182.7%
*-commutative82.7%
associate-/l*82.7%
metadata-eval82.7%
metadata-eval82.7%
Simplified82.8%
Taylor expanded in angle around 0 58.3%
unpow282.9%
Applied egg-rr58.3%
herbie shell --seed 2024172
(FPCore (a b angle)
:name "ab-angle->ABCF C"
:precision binary64
(+ (pow (* a (cos (* PI (/ angle 180.0)))) 2.0) (pow (* b (sin (* PI (/ angle 180.0)))) 2.0)))