
(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 7 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 (pow (hypot a (* b (sin (* angle (* PI 0.005555555555555556))))) 2.0))
double code(double a, double b, double angle) {
return pow(hypot(a, (b * sin((angle * (((double) M_PI) * 0.005555555555555556))))), 2.0);
}
public static double code(double a, double b, double angle) {
return Math.pow(Math.hypot(a, (b * Math.sin((angle * (Math.PI * 0.005555555555555556))))), 2.0);
}
def code(a, b, angle): return math.pow(math.hypot(a, (b * math.sin((angle * (math.pi * 0.005555555555555556))))), 2.0)
function code(a, b, angle) return hypot(a, Float64(b * sin(Float64(angle * Float64(pi * 0.005555555555555556))))) ^ 2.0 end
function tmp = code(a, b, angle) tmp = hypot(a, (b * sin((angle * (pi * 0.005555555555555556))))) ^ 2.0; end
code[a_, b_, angle_] := N[Power[N[Sqrt[a ^ 2 + N[(b * N[Sin[N[(angle * N[(Pi * 0.005555555555555556), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision], 2.0], $MachinePrecision]
\begin{array}{l}
\\
{\left(\mathsf{hypot}\left(a, b \cdot \sin \left(angle \cdot \left(\pi \cdot 0.005555555555555556\right)\right)\right)\right)}^{2}
\end{array}
Initial program 78.4%
associate-*r/78.4%
metadata-eval78.4%
metadata-eval78.4%
distribute-neg-frac278.4%
distribute-frac-neg78.4%
distribute-rgt-neg-out78.4%
associate-/l*78.4%
neg-mul-178.4%
*-commutative78.4%
associate-/l*78.4%
metadata-eval78.4%
metadata-eval78.4%
Simplified78.4%
Taylor expanded in angle around 0 78.7%
add-sqr-sqrt78.7%
pow278.7%
Applied egg-rr78.8%
(FPCore (a b angle) :precision binary64 (if (<= a 7.6e-149) (pow (* b (sin (* angle (* PI 0.005555555555555556)))) 2.0) (+ (pow a 2.0) (pow (* (* angle 0.005555555555555556) (* b PI)) 2.0))))
double code(double a, double b, double angle) {
double tmp;
if (a <= 7.6e-149) {
tmp = pow((b * sin((angle * (((double) M_PI) * 0.005555555555555556)))), 2.0);
} else {
tmp = pow(a, 2.0) + pow(((angle * 0.005555555555555556) * (b * ((double) M_PI))), 2.0);
}
return tmp;
}
public static double code(double a, double b, double angle) {
double tmp;
if (a <= 7.6e-149) {
tmp = Math.pow((b * Math.sin((angle * (Math.PI * 0.005555555555555556)))), 2.0);
} else {
tmp = Math.pow(a, 2.0) + Math.pow(((angle * 0.005555555555555556) * (b * Math.PI)), 2.0);
}
return tmp;
}
def code(a, b, angle): tmp = 0 if a <= 7.6e-149: tmp = math.pow((b * math.sin((angle * (math.pi * 0.005555555555555556)))), 2.0) else: tmp = math.pow(a, 2.0) + math.pow(((angle * 0.005555555555555556) * (b * math.pi)), 2.0) return tmp
function code(a, b, angle) tmp = 0.0 if (a <= 7.6e-149) tmp = Float64(b * sin(Float64(angle * Float64(pi * 0.005555555555555556)))) ^ 2.0; else tmp = Float64((a ^ 2.0) + (Float64(Float64(angle * 0.005555555555555556) * Float64(b * pi)) ^ 2.0)); end return tmp end
function tmp_2 = code(a, b, angle) tmp = 0.0; if (a <= 7.6e-149) tmp = (b * sin((angle * (pi * 0.005555555555555556)))) ^ 2.0; else tmp = (a ^ 2.0) + (((angle * 0.005555555555555556) * (b * pi)) ^ 2.0); end tmp_2 = tmp; end
code[a_, b_, angle_] := If[LessEqual[a, 7.6e-149], N[Power[N[(b * N[Sin[N[(angle * N[(Pi * 0.005555555555555556), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision], N[(N[Power[a, 2.0], $MachinePrecision] + N[Power[N[(N[(angle * 0.005555555555555556), $MachinePrecision] * N[(b * Pi), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 7.6 \cdot 10^{-149}:\\
\;\;\;\;{\left(b \cdot \sin \left(angle \cdot \left(\pi \cdot 0.005555555555555556\right)\right)\right)}^{2}\\
\mathbf{else}:\\
\;\;\;\;{a}^{2} + {\left(\left(angle \cdot 0.005555555555555556\right) \cdot \left(b \cdot \pi\right)\right)}^{2}\\
\end{array}
\end{array}
if a < 7.6000000000000001e-149Initial program 76.0%
associate-*r/76.0%
metadata-eval76.0%
metadata-eval76.0%
distribute-neg-frac276.0%
distribute-frac-neg76.0%
distribute-rgt-neg-out76.0%
associate-/l*76.0%
neg-mul-176.0%
*-commutative76.0%
associate-/l*76.0%
metadata-eval76.0%
metadata-eval76.0%
Simplified75.9%
Taylor expanded in a around 0 39.8%
unpow239.8%
*-commutative39.8%
unpow239.8%
swap-sqr47.9%
unpow247.9%
*-commutative47.9%
*-commutative47.9%
associate-*r*48.0%
Simplified48.0%
if 7.6000000000000001e-149 < a Initial program 82.0%
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*82.0%
neg-mul-182.0%
*-commutative82.0%
associate-/l*82.0%
metadata-eval82.0%
metadata-eval82.0%
Simplified82.1%
Taylor expanded in angle around 0 81.7%
Taylor expanded in angle around 0 79.8%
associate-*r*79.8%
*-commutative79.8%
Simplified79.8%
Final simplification60.8%
(FPCore (a b angle) :precision binary64 (if (<= a 7.6e-149) (pow (* b (sin (* angle (* PI 0.005555555555555556)))) 2.0) (pow (hypot a (* b (* 0.005555555555555556 (* angle PI)))) 2.0)))
double code(double a, double b, double angle) {
double tmp;
if (a <= 7.6e-149) {
tmp = pow((b * sin((angle * (((double) M_PI) * 0.005555555555555556)))), 2.0);
} else {
tmp = pow(hypot(a, (b * (0.005555555555555556 * (angle * ((double) M_PI))))), 2.0);
}
return tmp;
}
public static double code(double a, double b, double angle) {
double tmp;
if (a <= 7.6e-149) {
tmp = Math.pow((b * Math.sin((angle * (Math.PI * 0.005555555555555556)))), 2.0);
} else {
tmp = Math.pow(Math.hypot(a, (b * (0.005555555555555556 * (angle * Math.PI)))), 2.0);
}
return tmp;
}
def code(a, b, angle): tmp = 0 if a <= 7.6e-149: tmp = math.pow((b * math.sin((angle * (math.pi * 0.005555555555555556)))), 2.0) else: tmp = math.pow(math.hypot(a, (b * (0.005555555555555556 * (angle * math.pi)))), 2.0) return tmp
function code(a, b, angle) tmp = 0.0 if (a <= 7.6e-149) tmp = Float64(b * sin(Float64(angle * Float64(pi * 0.005555555555555556)))) ^ 2.0; else tmp = hypot(a, Float64(b * Float64(0.005555555555555556 * Float64(angle * pi)))) ^ 2.0; end return tmp end
function tmp_2 = code(a, b, angle) tmp = 0.0; if (a <= 7.6e-149) tmp = (b * sin((angle * (pi * 0.005555555555555556)))) ^ 2.0; else tmp = hypot(a, (b * (0.005555555555555556 * (angle * pi)))) ^ 2.0; end tmp_2 = tmp; end
code[a_, b_, angle_] := If[LessEqual[a, 7.6e-149], N[Power[N[(b * N[Sin[N[(angle * N[(Pi * 0.005555555555555556), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision], N[Power[N[Sqrt[a ^ 2 + N[(b * N[(0.005555555555555556 * N[(angle * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision], 2.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 7.6 \cdot 10^{-149}:\\
\;\;\;\;{\left(b \cdot \sin \left(angle \cdot \left(\pi \cdot 0.005555555555555556\right)\right)\right)}^{2}\\
\mathbf{else}:\\
\;\;\;\;{\left(\mathsf{hypot}\left(a, b \cdot \left(0.005555555555555556 \cdot \left(angle \cdot \pi\right)\right)\right)\right)}^{2}\\
\end{array}
\end{array}
if a < 7.6000000000000001e-149Initial program 76.0%
associate-*r/76.0%
metadata-eval76.0%
metadata-eval76.0%
distribute-neg-frac276.0%
distribute-frac-neg76.0%
distribute-rgt-neg-out76.0%
associate-/l*76.0%
neg-mul-176.0%
*-commutative76.0%
associate-/l*76.0%
metadata-eval76.0%
metadata-eval76.0%
Simplified75.9%
Taylor expanded in a around 0 39.8%
unpow239.8%
*-commutative39.8%
unpow239.8%
swap-sqr47.9%
unpow247.9%
*-commutative47.9%
*-commutative47.9%
associate-*r*48.0%
Simplified48.0%
if 7.6000000000000001e-149 < a Initial program 82.0%
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*82.0%
neg-mul-182.0%
*-commutative82.0%
associate-/l*82.0%
metadata-eval82.0%
metadata-eval82.0%
Simplified82.1%
Taylor expanded in angle around 0 81.7%
add-sqr-sqrt81.7%
pow281.7%
Applied egg-rr81.7%
Taylor expanded in angle around 0 79.8%
Final simplification60.8%
(FPCore (a b angle) :precision binary64 (if (<= a 5.6e-22) (pow (* b (sin (* angle (* PI 0.005555555555555556)))) 2.0) (* a a)))
double code(double a, double b, double angle) {
double tmp;
if (a <= 5.6e-22) {
tmp = pow((b * sin((angle * (((double) M_PI) * 0.005555555555555556)))), 2.0);
} else {
tmp = a * a;
}
return tmp;
}
public static double code(double a, double b, double angle) {
double tmp;
if (a <= 5.6e-22) {
tmp = Math.pow((b * Math.sin((angle * (Math.PI * 0.005555555555555556)))), 2.0);
} else {
tmp = a * a;
}
return tmp;
}
def code(a, b, angle): tmp = 0 if a <= 5.6e-22: tmp = math.pow((b * math.sin((angle * (math.pi * 0.005555555555555556)))), 2.0) else: tmp = a * a return tmp
function code(a, b, angle) tmp = 0.0 if (a <= 5.6e-22) tmp = Float64(b * sin(Float64(angle * Float64(pi * 0.005555555555555556)))) ^ 2.0; else tmp = Float64(a * a); end return tmp end
function tmp_2 = code(a, b, angle) tmp = 0.0; if (a <= 5.6e-22) tmp = (b * sin((angle * (pi * 0.005555555555555556)))) ^ 2.0; else tmp = a * a; end tmp_2 = tmp; end
code[a_, b_, angle_] := If[LessEqual[a, 5.6e-22], N[Power[N[(b * N[Sin[N[(angle * N[(Pi * 0.005555555555555556), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision], N[(a * a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 5.6 \cdot 10^{-22}:\\
\;\;\;\;{\left(b \cdot \sin \left(angle \cdot \left(\pi \cdot 0.005555555555555556\right)\right)\right)}^{2}\\
\mathbf{else}:\\
\;\;\;\;a \cdot a\\
\end{array}
\end{array}
if a < 5.5999999999999999e-22Initial program 76.1%
associate-*r/76.0%
metadata-eval76.0%
metadata-eval76.0%
distribute-neg-frac276.0%
distribute-frac-neg76.0%
distribute-rgt-neg-out76.0%
associate-/l*76.1%
neg-mul-176.1%
*-commutative76.1%
associate-/l*76.0%
metadata-eval76.0%
metadata-eval76.0%
Simplified76.0%
Taylor expanded in a around 0 39.5%
unpow239.5%
*-commutative39.5%
unpow239.5%
swap-sqr47.2%
unpow247.2%
*-commutative47.2%
*-commutative47.2%
associate-*r*47.2%
Simplified47.2%
if 5.5999999999999999e-22 < a Initial program 84.6%
associate-*r/84.7%
metadata-eval84.7%
metadata-eval84.7%
distribute-neg-frac284.7%
distribute-frac-neg84.7%
distribute-rgt-neg-out84.7%
associate-/l*84.6%
neg-mul-184.6%
*-commutative84.6%
associate-/l*84.7%
metadata-eval84.7%
metadata-eval84.7%
Simplified84.7%
Taylor expanded in angle around 0 77.3%
unpow285.5%
Applied egg-rr77.3%
Final simplification55.4%
(FPCore (a b angle) :precision binary64 (if (<= a 1.8e-22) (pow (* b (sin (* 0.005555555555555556 (* angle PI)))) 2.0) (* a a)))
double code(double a, double b, double angle) {
double tmp;
if (a <= 1.8e-22) {
tmp = pow((b * sin((0.005555555555555556 * (angle * ((double) M_PI))))), 2.0);
} else {
tmp = a * a;
}
return tmp;
}
public static double code(double a, double b, double angle) {
double tmp;
if (a <= 1.8e-22) {
tmp = Math.pow((b * Math.sin((0.005555555555555556 * (angle * Math.PI)))), 2.0);
} else {
tmp = a * a;
}
return tmp;
}
def code(a, b, angle): tmp = 0 if a <= 1.8e-22: tmp = math.pow((b * math.sin((0.005555555555555556 * (angle * math.pi)))), 2.0) else: tmp = a * a return tmp
function code(a, b, angle) tmp = 0.0 if (a <= 1.8e-22) tmp = Float64(b * sin(Float64(0.005555555555555556 * Float64(angle * pi)))) ^ 2.0; else tmp = Float64(a * a); end return tmp end
function tmp_2 = code(a, b, angle) tmp = 0.0; if (a <= 1.8e-22) tmp = (b * sin((0.005555555555555556 * (angle * pi)))) ^ 2.0; else tmp = a * a; end tmp_2 = tmp; end
code[a_, b_, angle_] := If[LessEqual[a, 1.8e-22], N[Power[N[(b * N[Sin[N[(0.005555555555555556 * N[(angle * Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision], N[(a * a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1.8 \cdot 10^{-22}:\\
\;\;\;\;{\left(b \cdot \sin \left(0.005555555555555556 \cdot \left(angle \cdot \pi\right)\right)\right)}^{2}\\
\mathbf{else}:\\
\;\;\;\;a \cdot a\\
\end{array}
\end{array}
if a < 1.7999999999999999e-22Initial program 76.1%
associate-*r/76.0%
metadata-eval76.0%
metadata-eval76.0%
distribute-neg-frac276.0%
distribute-frac-neg76.0%
distribute-rgt-neg-out76.0%
associate-/l*76.1%
neg-mul-176.1%
*-commutative76.1%
associate-/l*76.0%
metadata-eval76.0%
metadata-eval76.0%
Simplified76.0%
Taylor expanded in a around 0 39.5%
unpow239.5%
*-commutative39.5%
unpow239.5%
swap-sqr47.2%
unpow247.2%
*-commutative47.2%
Simplified47.2%
if 1.7999999999999999e-22 < a Initial program 84.6%
associate-*r/84.7%
metadata-eval84.7%
metadata-eval84.7%
distribute-neg-frac284.7%
distribute-frac-neg84.7%
distribute-rgt-neg-out84.7%
associate-/l*84.6%
neg-mul-184.6%
*-commutative84.6%
associate-/l*84.7%
metadata-eval84.7%
metadata-eval84.7%
Simplified84.7%
Taylor expanded in angle around 0 77.3%
unpow285.5%
Applied egg-rr77.3%
(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 78.4%
associate-*r/78.4%
metadata-eval78.4%
metadata-eval78.4%
distribute-neg-frac278.4%
distribute-frac-neg78.4%
distribute-rgt-neg-out78.4%
associate-/l*78.4%
neg-mul-178.4%
*-commutative78.4%
associate-/l*78.4%
metadata-eval78.4%
metadata-eval78.4%
Simplified78.4%
Taylor expanded in angle around 0 78.7%
unpow278.7%
Applied egg-rr78.7%
(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 78.4%
associate-*r/78.4%
metadata-eval78.4%
metadata-eval78.4%
distribute-neg-frac278.4%
distribute-frac-neg78.4%
distribute-rgt-neg-out78.4%
associate-/l*78.4%
neg-mul-178.4%
*-commutative78.4%
associate-/l*78.4%
metadata-eval78.4%
metadata-eval78.4%
Simplified78.4%
Taylor expanded in angle around 0 53.9%
unpow278.7%
Applied egg-rr53.9%
herbie shell --seed 2024185
(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)))