Average Error: 20.5 → 20.9
Time: 18.1s
Precision: binary64
Cost: 26372
\[{\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} \mathbf{if}\;angle \leq 1.8 \cdot 10^{-11}:\\ \;\;\;\;{a}^{2} + {\left(b \cdot \mathsf{expm1}\left(\pi \cdot \left(angle \cdot 0.005555555555555556\right)\right)\right)}^{2}\\ \mathbf{else}:\\ \;\;\;\;{a}^{2} + \frac{b}{\frac{2}{b}} \cdot \left(1 - \cos \left(angle \cdot \left(\pi \cdot 0.011111111111111112\right)\right)\right)\\ \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
 (if (<= angle 1.8e-11)
   (+
    (pow a 2.0)
    (pow (* b (expm1 (* PI (* angle 0.005555555555555556)))) 2.0))
   (+
    (pow a 2.0)
    (* (/ b (/ 2.0 b)) (- 1.0 (cos (* angle (* PI 0.011111111111111112))))))))
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 tmp;
	if (angle <= 1.8e-11) {
		tmp = pow(a, 2.0) + pow((b * expm1((((double) M_PI) * (angle * 0.005555555555555556)))), 2.0);
	} else {
		tmp = pow(a, 2.0) + ((b / (2.0 / b)) * (1.0 - cos((angle * (((double) M_PI) * 0.011111111111111112)))));
	}
	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 tmp;
	if (angle <= 1.8e-11) {
		tmp = Math.pow(a, 2.0) + Math.pow((b * Math.expm1((Math.PI * (angle * 0.005555555555555556)))), 2.0);
	} else {
		tmp = Math.pow(a, 2.0) + ((b / (2.0 / b)) * (1.0 - Math.cos((angle * (Math.PI * 0.011111111111111112)))));
	}
	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):
	tmp = 0
	if angle <= 1.8e-11:
		tmp = math.pow(a, 2.0) + math.pow((b * math.expm1((math.pi * (angle * 0.005555555555555556)))), 2.0)
	else:
		tmp = math.pow(a, 2.0) + ((b / (2.0 / b)) * (1.0 - math.cos((angle * (math.pi * 0.011111111111111112)))))
	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)
	tmp = 0.0
	if (angle <= 1.8e-11)
		tmp = Float64((a ^ 2.0) + (Float64(b * expm1(Float64(pi * Float64(angle * 0.005555555555555556)))) ^ 2.0));
	else
		tmp = Float64((a ^ 2.0) + Float64(Float64(b / Float64(2.0 / b)) * Float64(1.0 - cos(Float64(angle * Float64(pi * 0.011111111111111112))))));
	end
	return 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_] := If[LessEqual[angle, 1.8e-11], N[(N[Power[a, 2.0], $MachinePrecision] + N[Power[N[(b * N[(Exp[N[(Pi * N[(angle * 0.005555555555555556), $MachinePrecision]), $MachinePrecision]] - 1), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision], N[(N[Power[a, 2.0], $MachinePrecision] + N[(N[(b / N[(2.0 / b), $MachinePrecision]), $MachinePrecision] * N[(1.0 - N[Cos[N[(angle * N[(Pi * 0.011111111111111112), $MachinePrecision]), $MachinePrecision]], $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}
\mathbf{if}\;angle \leq 1.8 \cdot 10^{-11}:\\
\;\;\;\;{a}^{2} + {\left(b \cdot \mathsf{expm1}\left(\pi \cdot \left(angle \cdot 0.005555555555555556\right)\right)\right)}^{2}\\

\mathbf{else}:\\
\;\;\;\;{a}^{2} + \frac{b}{\frac{2}{b}} \cdot \left(1 - \cos \left(angle \cdot \left(\pi \cdot 0.011111111111111112\right)\right)\right)\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 2 regimes
  2. if angle < 1.79999999999999992e-11

    1. Initial program 13.5

      \[{\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 13.5

      \[\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-rr13.5

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

      \[\leadsto {\left(a \cdot 1\right)}^{2} + {\left(b \cdot \mathsf{expm1}\left(\color{blue}{0.005555555555555556 \cdot \left(angle \cdot \pi\right)}\right)\right)}^{2} \]
    5. Simplified13.8

      \[\leadsto {\left(a \cdot 1\right)}^{2} + {\left(b \cdot \mathsf{expm1}\left(\color{blue}{\pi \cdot \left(0.005555555555555556 \cdot angle\right)}\right)\right)}^{2} \]
      Proof
      (+.f64 (pow.f64 (*.f64 a 1) 2) (pow.f64 (*.f64 b (expm1.f64 (*.f64 (PI.f64) (*.f64 1/180 angle)))) 2)): 0 points increase in error, 0 points decrease in error
      (+.f64 (pow.f64 (*.f64 a 1) 2) (pow.f64 (*.f64 b (expm1.f64 (*.f64 (PI.f64) (Rewrite<= *-commutative_binary64 (*.f64 angle 1/180))))) 2)): 5 points increase in error, 0 points decrease in error
      (+.f64 (pow.f64 (*.f64 a 1) 2) (pow.f64 (*.f64 b (expm1.f64 (Rewrite=> associate-*r*_binary64 (*.f64 (*.f64 (PI.f64) angle) 1/180)))) 2)): 0 points increase in error, 5 points decrease in error
      (+.f64 (pow.f64 (*.f64 a 1) 2) (pow.f64 (*.f64 b (expm1.f64 (*.f64 (Rewrite=> *-commutative_binary64 (*.f64 angle (PI.f64))) 1/180))) 2)): 0 points increase in error, 5 points decrease in error
      (+.f64 (pow.f64 (*.f64 a 1) 2) (pow.f64 (*.f64 b (expm1.f64 (Rewrite<= *-commutative_binary64 (*.f64 1/180 (*.f64 angle (PI.f64)))))) 2)): 0 points increase in error, 0 points decrease in error

    if 1.79999999999999992e-11 < angle

    1. Initial program 43.8

      \[{\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.0

      \[\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.5

      \[\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.5

      \[\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
      (+.f64 (pow.f64 (*.f64 a 1) 2) (*.f64 (/.f64 b (/.f64 2 b)) (-.f64 1 (cos.f64 (*.f64 angle (*.f64 (PI.f64) 1/90)))))): 0 points increase in error, 0 points decrease in error
      (+.f64 (pow.f64 (*.f64 a 1) 2) (*.f64 (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 b b) 2)) (-.f64 1 (cos.f64 (*.f64 angle (*.f64 (PI.f64) 1/90)))))): 9 points increase in error, 0 points decrease in error
      (+.f64 (pow.f64 (*.f64 a 1) 2) (*.f64 (/.f64 (Rewrite<= unpow2_binary64 (pow.f64 b 2)) 2) (-.f64 1 (cos.f64 (*.f64 angle (*.f64 (PI.f64) 1/90)))))): 9 points increase in error, 0 points decrease in error
      (+.f64 (pow.f64 (*.f64 a 1) 2) (*.f64 (/.f64 (pow.f64 b 2) 2) (-.f64 (Rewrite<= cos-0_binary64 (cos.f64 0)) (cos.f64 (*.f64 angle (*.f64 (PI.f64) 1/90)))))): 0 points increase in error, 9 points decrease in error
      (+.f64 (pow.f64 (*.f64 a 1) 2) (*.f64 (/.f64 (pow.f64 b 2) 2) (-.f64 (cos.f64 (Rewrite<= mul0-rgt_binary64 (*.f64 (*.f64 (PI.f64) angle) 0))) (cos.f64 (*.f64 angle (*.f64 (PI.f64) 1/90)))))): 0 points increase in error, 0 points decrease in error
      (+.f64 (pow.f64 (*.f64 a 1) 2) (*.f64 (/.f64 (pow.f64 b 2) 2) (-.f64 (cos.f64 (*.f64 (*.f64 (PI.f64) angle) 0)) (cos.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 angle (PI.f64)) 1/90)))))): 9 points increase in error, 0 points decrease in error
      (+.f64 (pow.f64 (*.f64 a 1) 2) (*.f64 (/.f64 (pow.f64 b 2) 2) (-.f64 (cos.f64 (*.f64 (*.f64 (PI.f64) angle) 0)) (cos.f64 (*.f64 (Rewrite<= *-commutative_binary64 (*.f64 (PI.f64) angle)) 1/90))))): 9 points increase in error, 0 points decrease in error
      (+.f64 (pow.f64 (*.f64 a 1) 2) (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 (pow.f64 b 2) (-.f64 (cos.f64 (*.f64 (*.f64 (PI.f64) angle) 0)) (cos.f64 (*.f64 (*.f64 (PI.f64) angle) 1/90)))) 2))): 0 points increase in error, 9 points decrease in error
      (+.f64 (pow.f64 (*.f64 a 1) 2) (/.f64 (*.f64 (Rewrite=> unpow2_binary64 (*.f64 b b)) (-.f64 (cos.f64 (*.f64 (*.f64 (PI.f64) angle) 0)) (cos.f64 (*.f64 (*.f64 (PI.f64) angle) 1/90)))) 2)): 9 points increase in error, 0 points decrease in error
  3. Recombined 2 regimes into one program.
  4. Final simplification20.9

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

Alternatives

Alternative 1
Error20.5
Cost65664
\[{\left(a \cdot \cos \left(\frac{\pi}{\sqrt[3]{\frac{180}{angle}}} \cdot \frac{1}{{\left(\frac{\sqrt[3]{180}}{\frac{1}{\sqrt[3]{\frac{1}{angle}}}}\right)}^{2}}\right)\right)}^{2} + {\left(b \cdot \sin \left(\pi \cdot \frac{angle}{180}\right)\right)}^{2} \]
Alternative 2
Error20.8
Cost33088
\[{a}^{2} + {\left(b \cdot \mathsf{expm1}\left(\pi \cdot \left(angle \cdot 0.005555555555555556 + \pi \cdot \left(\left(angle \cdot angle\right) \cdot -1.54320987654321 \cdot 10^{-5}\right)\right)\right)\right)}^{2} \]
Alternative 3
Error20.6
Cost26368
\[{a}^{2} + {\left(b \cdot \sin \left(\frac{\frac{\pi}{180}}{\frac{1}{angle}}\right)\right)}^{2} \]
Alternative 4
Error20.6
Cost26240
\[{a}^{2} + {\left(b \cdot \sin \left(0.005555555555555556 \cdot \left(\pi \cdot angle\right)\right)\right)}^{2} \]
Alternative 5
Error20.9
Cost20425
\[\begin{array}{l} \mathbf{if}\;angle \leq -5.4 \cdot 10^{+15} \lor \neg \left(angle \leq 1.8 \cdot 10^{-11}\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(0.005555555555555556 \cdot \left(angle \cdot \left(\pi \cdot b\right)\right)\right)}^{2}\\ \end{array} \]
Alternative 6
Error20.9
Cost20424
\[\begin{array}{l} \mathbf{if}\;angle \leq -5.4 \cdot 10^{+15}:\\ \;\;\;\;{a}^{2} + \frac{b \cdot b}{\frac{2}{1 - \cos \left(\left(\pi \cdot angle\right) \cdot 0.011111111111111112\right)}}\\ \mathbf{elif}\;angle \leq 1.8 \cdot 10^{-11}:\\ \;\;\;\;{a}^{2} + {\left(0.005555555555555556 \cdot \left(angle \cdot \left(\pi \cdot b\right)\right)\right)}^{2}\\ \mathbf{else}:\\ \;\;\;\;{a}^{2} + \frac{b}{\frac{2}{b}} \cdot \left(1 - \cos \left(angle \cdot \left(\pi \cdot 0.011111111111111112\right)\right)\right)\\ \end{array} \]
Alternative 7
Error23.9
Cost20360
\[\begin{array}{l} \mathbf{if}\;b \leq -1.95 \cdot 10^{+136}:\\ \;\;\;\;{a}^{2} + {\left(b \cdot \left(\pi \cdot angle\right)\right)}^{2} \cdot 3.08641975308642 \cdot 10^{-5}\\ \mathbf{elif}\;b \leq 10^{-15}:\\ \;\;\;\;{a}^{2} + \left(angle \cdot \left(angle \cdot \left(b \cdot b\right)\right)\right) \cdot \left(3.08641975308642 \cdot 10^{-5} \cdot {\pi}^{2}\right)\\ \mathbf{else}:\\ \;\;\;\;{a}^{2} + {\left(0.005555555555555556 \cdot \left(angle \cdot \left(\pi \cdot b\right)\right)\right)}^{2}\\ \end{array} \]
Alternative 8
Error26.2
Cost19840
\[{a}^{2} + 3.08641975308642 \cdot 10^{-5} \cdot {\left(angle \cdot \left(\pi \cdot b\right)\right)}^{2} \]
Alternative 9
Error26.2
Cost19840
\[{a}^{2} + {\left(b \cdot \left(\pi \cdot angle\right)\right)}^{2} \cdot 3.08641975308642 \cdot 10^{-5} \]
Alternative 10
Error26.2
Cost19840
\[{a}^{2} + {\left(0.005555555555555556 \cdot \left(angle \cdot \left(\pi \cdot b\right)\right)\right)}^{2} \]

Error

Reproduce

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