Average Error: 20.3 → 20.3
Time: 17.5s
Precision: binary64
Cost: 20488
\[{\left(a \cdot \cos \left(\pi \cdot \frac{angle}{180}\right)\right)}^{2} + {\left(b \cdot \sin \left(\pi \cdot \frac{angle}{180}\right)\right)}^{2} \]
\[\begin{array}{l} t_0 := 0.005555555555555556 \cdot \left(b \cdot angle\right)\\ t_1 := 1 - \cos \left(angle \cdot \left(\pi \cdot 0.011111111111111112\right)\right)\\ \mathbf{if}\;angle \leq -0.0048:\\ \;\;\;\;{a}^{2} + \frac{b}{\frac{2}{b}} \cdot t_1\\ \mathbf{elif}\;angle \leq 0.00385:\\ \;\;\;\;{a}^{2} + \left(t_0 \cdot t_0\right) \cdot {\pi}^{2}\\ \mathbf{else}:\\ \;\;\;\;{a}^{2} + \frac{t_1}{\frac{2}{b \cdot b}}\\ \end{array} \]
(FPCore (a b angle)
 :precision binary64
 (+
  (pow (* a (cos (* PI (/ angle 180.0)))) 2.0)
  (pow (* b (sin (* PI (/ angle 180.0)))) 2.0)))
(FPCore (a b angle)
 :precision binary64
 (let* ((t_0 (* 0.005555555555555556 (* b angle)))
        (t_1 (- 1.0 (cos (* angle (* PI 0.011111111111111112))))))
   (if (<= angle -0.0048)
     (+ (pow a 2.0) (* (/ b (/ 2.0 b)) t_1))
     (if (<= angle 0.00385)
       (+ (pow a 2.0) (* (* t_0 t_0) (pow PI 2.0)))
       (+ (pow a 2.0) (/ t_1 (/ 2.0 (* b b))))))))
double code(double a, double b, double angle) {
	return pow((a * cos((((double) M_PI) * (angle / 180.0)))), 2.0) + pow((b * sin((((double) M_PI) * (angle / 180.0)))), 2.0);
}
double code(double a, double b, double angle) {
	double t_0 = 0.005555555555555556 * (b * angle);
	double t_1 = 1.0 - cos((angle * (((double) M_PI) * 0.011111111111111112)));
	double tmp;
	if (angle <= -0.0048) {
		tmp = pow(a, 2.0) + ((b / (2.0 / b)) * t_1);
	} else if (angle <= 0.00385) {
		tmp = pow(a, 2.0) + ((t_0 * t_0) * pow(((double) M_PI), 2.0));
	} else {
		tmp = pow(a, 2.0) + (t_1 / (2.0 / (b * b)));
	}
	return tmp;
}
public static double code(double a, double b, double angle) {
	return Math.pow((a * Math.cos((Math.PI * (angle / 180.0)))), 2.0) + Math.pow((b * Math.sin((Math.PI * (angle / 180.0)))), 2.0);
}
public static double code(double a, double b, double angle) {
	double t_0 = 0.005555555555555556 * (b * angle);
	double t_1 = 1.0 - Math.cos((angle * (Math.PI * 0.011111111111111112)));
	double tmp;
	if (angle <= -0.0048) {
		tmp = Math.pow(a, 2.0) + ((b / (2.0 / b)) * t_1);
	} else if (angle <= 0.00385) {
		tmp = Math.pow(a, 2.0) + ((t_0 * t_0) * Math.pow(Math.PI, 2.0));
	} else {
		tmp = Math.pow(a, 2.0) + (t_1 / (2.0 / (b * b)));
	}
	return tmp;
}
def code(a, b, angle):
	return math.pow((a * math.cos((math.pi * (angle / 180.0)))), 2.0) + math.pow((b * math.sin((math.pi * (angle / 180.0)))), 2.0)
def code(a, b, angle):
	t_0 = 0.005555555555555556 * (b * angle)
	t_1 = 1.0 - math.cos((angle * (math.pi * 0.011111111111111112)))
	tmp = 0
	if angle <= -0.0048:
		tmp = math.pow(a, 2.0) + ((b / (2.0 / b)) * t_1)
	elif angle <= 0.00385:
		tmp = math.pow(a, 2.0) + ((t_0 * t_0) * math.pow(math.pi, 2.0))
	else:
		tmp = math.pow(a, 2.0) + (t_1 / (2.0 / (b * b)))
	return tmp
function code(a, b, angle)
	return Float64((Float64(a * cos(Float64(pi * Float64(angle / 180.0)))) ^ 2.0) + (Float64(b * sin(Float64(pi * Float64(angle / 180.0)))) ^ 2.0))
end
function code(a, b, angle)
	t_0 = Float64(0.005555555555555556 * Float64(b * angle))
	t_1 = Float64(1.0 - cos(Float64(angle * Float64(pi * 0.011111111111111112))))
	tmp = 0.0
	if (angle <= -0.0048)
		tmp = Float64((a ^ 2.0) + Float64(Float64(b / Float64(2.0 / b)) * t_1));
	elseif (angle <= 0.00385)
		tmp = Float64((a ^ 2.0) + Float64(Float64(t_0 * t_0) * (pi ^ 2.0)));
	else
		tmp = Float64((a ^ 2.0) + Float64(t_1 / Float64(2.0 / Float64(b * b))));
	end
	return tmp
end
function tmp = code(a, b, angle)
	tmp = ((a * cos((pi * (angle / 180.0)))) ^ 2.0) + ((b * sin((pi * (angle / 180.0)))) ^ 2.0);
end
function tmp_2 = code(a, b, angle)
	t_0 = 0.005555555555555556 * (b * angle);
	t_1 = 1.0 - cos((angle * (pi * 0.011111111111111112)));
	tmp = 0.0;
	if (angle <= -0.0048)
		tmp = (a ^ 2.0) + ((b / (2.0 / b)) * t_1);
	elseif (angle <= 0.00385)
		tmp = (a ^ 2.0) + ((t_0 * t_0) * (pi ^ 2.0));
	else
		tmp = (a ^ 2.0) + (t_1 / (2.0 / (b * b)));
	end
	tmp_2 = tmp;
end
code[a_, b_, angle_] := N[(N[Power[N[(a * N[Cos[N[(Pi * N[(angle / 180.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[(b * N[Sin[N[(Pi * N[(angle / 180.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
code[a_, b_, angle_] := Block[{t$95$0 = N[(0.005555555555555556 * N[(b * angle), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 - N[Cos[N[(angle * N[(Pi * 0.011111111111111112), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[angle, -0.0048], N[(N[Power[a, 2.0], $MachinePrecision] + N[(N[(b / N[(2.0 / b), $MachinePrecision]), $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision], If[LessEqual[angle, 0.00385], N[(N[Power[a, 2.0], $MachinePrecision] + N[(N[(t$95$0 * t$95$0), $MachinePrecision] * N[Power[Pi, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Power[a, 2.0], $MachinePrecision] + N[(t$95$1 / N[(2.0 / N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
{\left(a \cdot \cos \left(\pi \cdot \frac{angle}{180}\right)\right)}^{2} + {\left(b \cdot \sin \left(\pi \cdot \frac{angle}{180}\right)\right)}^{2}
\begin{array}{l}
t_0 := 0.005555555555555556 \cdot \left(b \cdot angle\right)\\
t_1 := 1 - \cos \left(angle \cdot \left(\pi \cdot 0.011111111111111112\right)\right)\\
\mathbf{if}\;angle \leq -0.0048:\\
\;\;\;\;{a}^{2} + \frac{b}{\frac{2}{b}} \cdot t_1\\

\mathbf{elif}\;angle \leq 0.00385:\\
\;\;\;\;{a}^{2} + \left(t_0 \cdot t_0\right) \cdot {\pi}^{2}\\

\mathbf{else}:\\
\;\;\;\;{a}^{2} + \frac{t_1}{\frac{2}{b \cdot b}}\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 3 regimes
  2. if angle < -0.00479999999999999958

    1. Initial program 44.4

      \[{\left(a \cdot \cos \left(\pi \cdot \frac{angle}{180}\right)\right)}^{2} + {\left(b \cdot \sin \left(\pi \cdot \frac{angle}{180}\right)\right)}^{2} \]
    2. Taylor expanded in angle around 0 44.7

      \[\leadsto {\left(a \cdot \color{blue}{1}\right)}^{2} + {\left(b \cdot \sin \left(\pi \cdot \frac{angle}{180}\right)\right)}^{2} \]
    3. Applied egg-rr44.8

      \[\leadsto {\left(a \cdot 1\right)}^{2} + \color{blue}{\frac{\left(b \cdot b\right) \cdot \left(\cos \left(\left(\pi \cdot angle\right) \cdot 0\right) - \cos \left(\left(\pi \cdot angle\right) \cdot 0.011111111111111112\right)\right)}{2}} \]
    4. Simplified44.7

      \[\leadsto {\left(a \cdot 1\right)}^{2} + \color{blue}{\frac{b}{\frac{2}{b}} \cdot \left(1 - \cos \left(angle \cdot \left(\pi \cdot 0.011111111111111112\right)\right)\right)} \]
      Proof

      [Start]44.8

      \[ {\left(a \cdot 1\right)}^{2} + \frac{\left(b \cdot b\right) \cdot \left(\cos \left(\left(\pi \cdot angle\right) \cdot 0\right) - \cos \left(\left(\pi \cdot angle\right) \cdot 0.011111111111111112\right)\right)}{2} \]

      unpow2 [<=]44.8

      \[ {\left(a \cdot 1\right)}^{2} + \frac{\color{blue}{{b}^{2}} \cdot \left(\cos \left(\left(\pi \cdot angle\right) \cdot 0\right) - \cos \left(\left(\pi \cdot angle\right) \cdot 0.011111111111111112\right)\right)}{2} \]

      associate-*l/ [<=]44.8

      \[ {\left(a \cdot 1\right)}^{2} + \color{blue}{\frac{{b}^{2}}{2} \cdot \left(\cos \left(\left(\pi \cdot angle\right) \cdot 0\right) - \cos \left(\left(\pi \cdot angle\right) \cdot 0.011111111111111112\right)\right)} \]

      unpow2 [=>]44.8

      \[ {\left(a \cdot 1\right)}^{2} + \frac{\color{blue}{b \cdot b}}{2} \cdot \left(\cos \left(\left(\pi \cdot angle\right) \cdot 0\right) - \cos \left(\left(\pi \cdot angle\right) \cdot 0.011111111111111112\right)\right) \]

      associate-/l* [=>]44.8

      \[ {\left(a \cdot 1\right)}^{2} + \color{blue}{\frac{b}{\frac{2}{b}}} \cdot \left(\cos \left(\left(\pi \cdot angle\right) \cdot 0\right) - \cos \left(\left(\pi \cdot angle\right) \cdot 0.011111111111111112\right)\right) \]

      mul0-rgt [=>]44.8

      \[ {\left(a \cdot 1\right)}^{2} + \frac{b}{\frac{2}{b}} \cdot \left(\cos \color{blue}{0} - \cos \left(\left(\pi \cdot angle\right) \cdot 0.011111111111111112\right)\right) \]

      cos-0 [=>]44.8

      \[ {\left(a \cdot 1\right)}^{2} + \frac{b}{\frac{2}{b}} \cdot \left(\color{blue}{1} - \cos \left(\left(\pi \cdot angle\right) \cdot 0.011111111111111112\right)\right) \]

      *-commutative [=>]44.8

      \[ {\left(a \cdot 1\right)}^{2} + \frac{b}{\frac{2}{b}} \cdot \left(1 - \cos \left(\color{blue}{\left(angle \cdot \pi\right)} \cdot 0.011111111111111112\right)\right) \]

      associate-*l* [=>]44.7

      \[ {\left(a \cdot 1\right)}^{2} + \frac{b}{\frac{2}{b}} \cdot \left(1 - \cos \color{blue}{\left(angle \cdot \left(\pi \cdot 0.011111111111111112\right)\right)}\right) \]

    if -0.00479999999999999958 < angle < 0.0038500000000000001

    1. Initial program 0.3

      \[{\left(a \cdot \cos \left(\pi \cdot \frac{angle}{180}\right)\right)}^{2} + {\left(b \cdot \sin \left(\pi \cdot \frac{angle}{180}\right)\right)}^{2} \]
    2. Taylor expanded in angle around 0 0.3

      \[\leadsto {\left(a \cdot \color{blue}{1}\right)}^{2} + {\left(b \cdot \sin \left(\pi \cdot \frac{angle}{180}\right)\right)}^{2} \]
    3. Taylor expanded in angle around 0 0.4

      \[\leadsto {\left(a \cdot 1\right)}^{2} + {\color{blue}{\left(0.005555555555555556 \cdot \left(angle \cdot \left(b \cdot \pi\right)\right)\right)}}^{2} \]
    4. Applied egg-rr0.3

      \[\leadsto {\left(a \cdot 1\right)}^{2} + \color{blue}{\left(\left(0.005555555555555556 \cdot \left(angle \cdot b\right)\right) \cdot \left(0.005555555555555556 \cdot \left(angle \cdot b\right)\right)\right) \cdot {\pi}^{2}} \]

    if 0.0038500000000000001 < angle

    1. Initial program 45.7

      \[{\left(a \cdot \cos \left(\pi \cdot \frac{angle}{180}\right)\right)}^{2} + {\left(b \cdot \sin \left(\pi \cdot \frac{angle}{180}\right)\right)}^{2} \]
    2. Taylor expanded in angle around 0 45.4

      \[\leadsto {\left(a \cdot \color{blue}{1}\right)}^{2} + {\left(b \cdot \sin \left(\pi \cdot \frac{angle}{180}\right)\right)}^{2} \]
    3. Applied egg-rr45.4

      \[\leadsto {\left(a \cdot 1\right)}^{2} + \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left({\left(\sin \left(\pi \cdot \left(angle \cdot 0.005555555555555556\right)\right) \cdot b\right)}^{2}\right)\right)} \]
    4. Taylor expanded in angle around inf 45.5

      \[\leadsto {\left(a \cdot 1\right)}^{2} + \mathsf{expm1}\left(\mathsf{log1p}\left({\left(\color{blue}{\sin \left(0.005555555555555556 \cdot \left(angle \cdot \pi\right)\right)} \cdot b\right)}^{2}\right)\right) \]
    5. Applied egg-rr45.5

      \[\leadsto {\left(a \cdot 1\right)}^{2} + \color{blue}{\frac{\left(b \cdot b\right) \cdot \left(\cos 0 - \cos \left(\left(angle \cdot \pi\right) \cdot 0.011111111111111112\right)\right)}{2}} \]
    6. Simplified45.4

      \[\leadsto {\left(a \cdot 1\right)}^{2} + \color{blue}{\frac{1 - \cos \left(angle \cdot \left(\pi \cdot 0.011111111111111112\right)\right)}{\frac{2}{b \cdot b}}} \]
      Proof

      [Start]45.5

      \[ {\left(a \cdot 1\right)}^{2} + \frac{\left(b \cdot b\right) \cdot \left(\cos 0 - \cos \left(\left(angle \cdot \pi\right) \cdot 0.011111111111111112\right)\right)}{2} \]

      *-commutative [=>]45.5

      \[ {\left(a \cdot 1\right)}^{2} + \frac{\color{blue}{\left(\cos 0 - \cos \left(\left(angle \cdot \pi\right) \cdot 0.011111111111111112\right)\right) \cdot \left(b \cdot b\right)}}{2} \]

      associate-/l* [=>]45.5

      \[ {\left(a \cdot 1\right)}^{2} + \color{blue}{\frac{\cos 0 - \cos \left(\left(angle \cdot \pi\right) \cdot 0.011111111111111112\right)}{\frac{2}{b \cdot b}}} \]

      cos-0 [=>]45.5

      \[ {\left(a \cdot 1\right)}^{2} + \frac{\color{blue}{1} - \cos \left(\left(angle \cdot \pi\right) \cdot 0.011111111111111112\right)}{\frac{2}{b \cdot b}} \]

      associate-*l* [=>]45.4

      \[ {\left(a \cdot 1\right)}^{2} + \frac{1 - \cos \color{blue}{\left(angle \cdot \left(\pi \cdot 0.011111111111111112\right)\right)}}{\frac{2}{b \cdot b}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification20.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;angle \leq -0.0048:\\ \;\;\;\;{a}^{2} + \frac{b}{\frac{2}{b}} \cdot \left(1 - \cos \left(angle \cdot \left(\pi \cdot 0.011111111111111112\right)\right)\right)\\ \mathbf{elif}\;angle \leq 0.00385:\\ \;\;\;\;{a}^{2} + \left(\left(0.005555555555555556 \cdot \left(b \cdot angle\right)\right) \cdot \left(0.005555555555555556 \cdot \left(b \cdot angle\right)\right)\right) \cdot {\pi}^{2}\\ \mathbf{else}:\\ \;\;\;\;{a}^{2} + \frac{1 - \cos \left(angle \cdot \left(\pi \cdot 0.011111111111111112\right)\right)}{\frac{2}{b \cdot b}}\\ \end{array} \]

Alternatives

Alternative 1
Error20.3
Cost26240
\[{a}^{2} + {\left(b \cdot \sin \left(\frac{\pi}{\frac{180}{angle}}\right)\right)}^{2} \]
Alternative 2
Error20.3
Cost26240
\[{a}^{2} + {\left(b \cdot \sin \left(0.005555555555555556 \cdot \left(\pi \cdot angle\right)\right)\right)}^{2} \]
Alternative 3
Error20.3
Cost20425
\[\begin{array}{l} \mathbf{if}\;angle \leq -0.0048 \lor \neg \left(angle \leq 0.00385\right):\\ \;\;\;\;{a}^{2} + \frac{b}{\frac{2}{b}} \cdot \left(1 - \cos \left(angle \cdot \left(\pi \cdot 0.011111111111111112\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;{a}^{2} + {\left(angle \cdot \left(b \cdot \left(\pi \cdot 0.005555555555555556\right)\right)\right)}^{2}\\ \end{array} \]
Alternative 4
Error20.3
Cost20424
\[\begin{array}{l} t_0 := 1 - \cos \left(angle \cdot \left(\pi \cdot 0.011111111111111112\right)\right)\\ \mathbf{if}\;angle \leq -0.0048:\\ \;\;\;\;{a}^{2} + \frac{b}{\frac{2}{b}} \cdot t_0\\ \mathbf{elif}\;angle \leq 0.00385:\\ \;\;\;\;{a}^{2} + {\left(angle \cdot \left(b \cdot \left(\pi \cdot 0.005555555555555556\right)\right)\right)}^{2}\\ \mathbf{else}:\\ \;\;\;\;{a}^{2} + t_0 \cdot \frac{b \cdot b}{2}\\ \end{array} \]
Alternative 5
Error20.3
Cost20424
\[\begin{array}{l} t_0 := 1 - \cos \left(angle \cdot \left(\pi \cdot 0.011111111111111112\right)\right)\\ \mathbf{if}\;angle \leq -0.0048:\\ \;\;\;\;{a}^{2} + \frac{b}{\frac{2}{b}} \cdot t_0\\ \mathbf{elif}\;angle \leq 0.00385:\\ \;\;\;\;{a}^{2} + {\left(angle \cdot \left(b \cdot \left(\pi \cdot 0.005555555555555556\right)\right)\right)}^{2}\\ \mathbf{else}:\\ \;\;\;\;{a}^{2} + \frac{t_0}{\frac{2}{b \cdot b}}\\ \end{array} \]
Alternative 6
Error23.5
Cost20360
\[\begin{array}{l} \mathbf{if}\;b \leq -1 \cdot 10^{+119}:\\ \;\;\;\;{a}^{2} + {\left(0.005555555555555556 \cdot \left(angle \cdot \left(b \cdot \pi\right)\right)\right)}^{2}\\ \mathbf{elif}\;b \leq 5.2 \cdot 10^{-163}:\\ \;\;\;\;{a}^{2} + 3.08641975308642 \cdot 10^{-5} \cdot \left({\pi}^{2} \cdot \left(angle \cdot \left(angle \cdot \left(b \cdot b\right)\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;{a}^{2} + 3.08641975308642 \cdot 10^{-5} \cdot {\left(\pi \cdot \left(b \cdot angle\right)\right)}^{2}\\ \end{array} \]
Alternative 7
Error23.8
Cost20360
\[\begin{array}{l} \mathbf{if}\;b \leq -3 \cdot 10^{+119}:\\ \;\;\;\;{a}^{2} + {\left(0.005555555555555556 \cdot \left(angle \cdot \left(b \cdot \pi\right)\right)\right)}^{2}\\ \mathbf{elif}\;b \leq 1.5 \cdot 10^{+139}:\\ \;\;\;\;{a}^{2} + 3.08641975308642 \cdot 10^{-5} \cdot \left({\pi}^{2} \cdot \left(angle \cdot \left(angle \cdot \left(b \cdot b\right)\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;{a}^{2} + 3.08641975308642 \cdot 10^{-5} \cdot \left(b \cdot \left(\left(\pi \cdot angle\right) \cdot \left(\pi \cdot \left(b \cdot angle\right)\right)\right)\right)\\ \end{array} \]
Alternative 8
Error25.9
Cost19840
\[{a}^{2} + 3.08641975308642 \cdot 10^{-5} \cdot {\left(angle \cdot \left(b \cdot \pi\right)\right)}^{2} \]
Alternative 9
Error25.8
Cost19840
\[{a}^{2} + {\left(0.005555555555555556 \cdot \left(angle \cdot \left(b \cdot \pi\right)\right)\right)}^{2} \]
Alternative 10
Error25.8
Cost19840
\[{a}^{2} + {\left(angle \cdot \left(b \cdot \left(\pi \cdot 0.005555555555555556\right)\right)\right)}^{2} \]

Error

Reproduce

herbie shell --seed 2022356 
(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)))