ab-angle->ABCF A

Percentage Accurate: 80.2% → 80.1%
Time: 15.2s
Alternatives: 15
Speedup: 2.0×

Specification

?
\[\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
 (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:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 15 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 80.2% accurate, 1.0× speedup?

\[\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
 (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}

Alternative 1: 80.1% accurate, 1.0× speedup?

\[\begin{array}{l} angle_m = \left|angle\right| \\ {\left(a \cdot \sin \left({\left({\left(\pi \cdot \left(angle\_m \cdot 0.005555555555555556\right)\right)}^{0.5}\right)}^{2}\right)\right)}^{2} + b \cdot b \end{array} \]
angle_m = (fabs.f64 angle)
(FPCore (a b angle_m)
 :precision binary64
 (+
  (pow
   (* a (sin (pow (pow (* PI (* angle_m 0.005555555555555556)) 0.5) 2.0)))
   2.0)
  (* b b)))
angle_m = fabs(angle);
double code(double a, double b, double angle_m) {
	return pow((a * sin(pow(pow((((double) M_PI) * (angle_m * 0.005555555555555556)), 0.5), 2.0))), 2.0) + (b * b);
}
angle_m = Math.abs(angle);
public static double code(double a, double b, double angle_m) {
	return Math.pow((a * Math.sin(Math.pow(Math.pow((Math.PI * (angle_m * 0.005555555555555556)), 0.5), 2.0))), 2.0) + (b * b);
}
angle_m = math.fabs(angle)
def code(a, b, angle_m):
	return math.pow((a * math.sin(math.pow(math.pow((math.pi * (angle_m * 0.005555555555555556)), 0.5), 2.0))), 2.0) + (b * b)
angle_m = abs(angle)
function code(a, b, angle_m)
	return Float64((Float64(a * sin(((Float64(pi * Float64(angle_m * 0.005555555555555556)) ^ 0.5) ^ 2.0))) ^ 2.0) + Float64(b * b))
end
angle_m = abs(angle);
function tmp = code(a, b, angle_m)
	tmp = ((a * sin((((pi * (angle_m * 0.005555555555555556)) ^ 0.5) ^ 2.0))) ^ 2.0) + (b * b);
end
angle_m = N[Abs[angle], $MachinePrecision]
code[a_, b_, angle$95$m_] := N[(N[Power[N[(a * N[Sin[N[Power[N[Power[N[(Pi * N[(angle$95$m * 0.005555555555555556), $MachinePrecision]), $MachinePrecision], 0.5], $MachinePrecision], 2.0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
angle_m = \left|angle\right|

\\
{\left(a \cdot \sin \left({\left({\left(\pi \cdot \left(angle\_m \cdot 0.005555555555555556\right)\right)}^{0.5}\right)}^{2}\right)\right)}^{2} + b \cdot b
\end{array}
Derivation
  1. Initial program 78.0%

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

    \[\leadsto {\left(a \cdot \sin \left(\frac{angle}{180} \cdot \mathsf{PI}\left(\right)\right)\right)}^{2} + {\left(b \cdot \color{blue}{1}\right)}^{2} \]
  4. Step-by-step derivation
    1. Applied rewrites78.5%

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

      \[\leadsto {\left(a \cdot \sin \left(\frac{angle}{180} \cdot \mathsf{PI}\left(\right)\right)\right)}^{2} + \color{blue}{{b}^{2}} \]
    3. Step-by-step derivation
      1. unpow2N/A

        \[\leadsto {\left(a \cdot \sin \left(\frac{angle}{180} \cdot \mathsf{PI}\left(\right)\right)\right)}^{2} + \color{blue}{b \cdot b} \]
      2. lower-*.f6478.5

        \[\leadsto {\left(a \cdot \sin \left(\frac{angle}{180} \cdot \pi\right)\right)}^{2} + \color{blue}{b \cdot b} \]
    4. Applied rewrites78.5%

      \[\leadsto {\left(a \cdot \sin \left(\frac{angle}{180} \cdot \pi\right)\right)}^{2} + \color{blue}{b \cdot b} \]
    5. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto {\left(a \cdot \sin \color{blue}{\left(\frac{angle}{180} \cdot \mathsf{PI}\left(\right)\right)}\right)}^{2} + b \cdot b \]
      2. lift-/.f64N/A

        \[\leadsto {\left(a \cdot \sin \left(\color{blue}{\frac{angle}{180}} \cdot \mathsf{PI}\left(\right)\right)\right)}^{2} + b \cdot b \]
      3. clear-numN/A

        \[\leadsto {\left(a \cdot \sin \left(\color{blue}{\frac{1}{\frac{180}{angle}}} \cdot \mathsf{PI}\left(\right)\right)\right)}^{2} + b \cdot b \]
      4. associate-*l/N/A

        \[\leadsto {\left(a \cdot \sin \color{blue}{\left(\frac{1 \cdot \mathsf{PI}\left(\right)}{\frac{180}{angle}}\right)}\right)}^{2} + b \cdot b \]
      5. *-lft-identityN/A

        \[\leadsto {\left(a \cdot \sin \left(\frac{\color{blue}{\mathsf{PI}\left(\right)}}{\frac{180}{angle}}\right)\right)}^{2} + b \cdot b \]
      6. lower-/.f64N/A

        \[\leadsto {\left(a \cdot \sin \color{blue}{\left(\frac{\mathsf{PI}\left(\right)}{\frac{180}{angle}}\right)}\right)}^{2} + b \cdot b \]
      7. lower-/.f6478.5

        \[\leadsto {\left(a \cdot \sin \left(\frac{\pi}{\color{blue}{\frac{180}{angle}}}\right)\right)}^{2} + b \cdot b \]
    6. Applied rewrites78.5%

      \[\leadsto {\left(a \cdot \sin \color{blue}{\left(\frac{\pi}{\frac{180}{angle}}\right)}\right)}^{2} + b \cdot b \]
    7. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto {\left(a \cdot \sin \color{blue}{\left(\frac{\mathsf{PI}\left(\right)}{\frac{180}{angle}}\right)}\right)}^{2} + b \cdot b \]
      2. clear-numN/A

        \[\leadsto {\left(a \cdot \sin \color{blue}{\left(\frac{1}{\frac{\frac{180}{angle}}{\mathsf{PI}\left(\right)}}\right)}\right)}^{2} + b \cdot b \]
      3. lift-/.f64N/A

        \[\leadsto {\left(a \cdot \sin \left(\frac{1}{\frac{\color{blue}{\frac{180}{angle}}}{\mathsf{PI}\left(\right)}}\right)\right)}^{2} + b \cdot b \]
      4. associate-/r*N/A

        \[\leadsto {\left(a \cdot \sin \left(\frac{1}{\color{blue}{\frac{180}{angle \cdot \mathsf{PI}\left(\right)}}}\right)\right)}^{2} + b \cdot b \]
      5. lift-*.f64N/A

        \[\leadsto {\left(a \cdot \sin \left(\frac{1}{\frac{180}{\color{blue}{angle \cdot \mathsf{PI}\left(\right)}}}\right)\right)}^{2} + b \cdot b \]
      6. lift-/.f64N/A

        \[\leadsto {\left(a \cdot \sin \left(\frac{1}{\color{blue}{\frac{180}{angle \cdot \mathsf{PI}\left(\right)}}}\right)\right)}^{2} + b \cdot b \]
      7. inv-powN/A

        \[\leadsto {\left(a \cdot \sin \color{blue}{\left({\left(\frac{180}{angle \cdot \mathsf{PI}\left(\right)}\right)}^{-1}\right)}\right)}^{2} + b \cdot b \]
      8. sqr-powN/A

        \[\leadsto {\left(a \cdot \sin \color{blue}{\left({\left(\frac{180}{angle \cdot \mathsf{PI}\left(\right)}\right)}^{\left(\frac{-1}{2}\right)} \cdot {\left(\frac{180}{angle \cdot \mathsf{PI}\left(\right)}\right)}^{\left(\frac{-1}{2}\right)}\right)}\right)}^{2} + b \cdot b \]
      9. pow2N/A

        \[\leadsto {\left(a \cdot \sin \color{blue}{\left({\left({\left(\frac{180}{angle \cdot \mathsf{PI}\left(\right)}\right)}^{\left(\frac{-1}{2}\right)}\right)}^{2}\right)}\right)}^{2} + b \cdot b \]
      10. lower-pow.f64N/A

        \[\leadsto {\left(a \cdot \sin \color{blue}{\left({\left({\left(\frac{180}{angle \cdot \mathsf{PI}\left(\right)}\right)}^{\left(\frac{-1}{2}\right)}\right)}^{2}\right)}\right)}^{2} + b \cdot b \]
    8. Applied rewrites78.5%

      \[\leadsto {\left(a \cdot \sin \color{blue}{\left({\left({\left(\pi \cdot \left(angle \cdot 0.005555555555555556\right)\right)}^{0.5}\right)}^{2}\right)}\right)}^{2} + b \cdot b \]
    9. Add Preprocessing

    Alternative 2: 80.2% accurate, 1.9× speedup?

    \[\begin{array}{l} angle_m = \left|angle\right| \\ b \cdot b + {\left(a \cdot \sin \left(\pi \cdot \frac{-1}{\frac{-180}{angle\_m}}\right)\right)}^{2} \end{array} \]
    angle_m = (fabs.f64 angle)
    (FPCore (a b angle_m)
     :precision binary64
     (+ (* b b) (pow (* a (sin (* PI (/ -1.0 (/ -180.0 angle_m))))) 2.0)))
    angle_m = fabs(angle);
    double code(double a, double b, double angle_m) {
    	return (b * b) + pow((a * sin((((double) M_PI) * (-1.0 / (-180.0 / angle_m))))), 2.0);
    }
    
    angle_m = Math.abs(angle);
    public static double code(double a, double b, double angle_m) {
    	return (b * b) + Math.pow((a * Math.sin((Math.PI * (-1.0 / (-180.0 / angle_m))))), 2.0);
    }
    
    angle_m = math.fabs(angle)
    def code(a, b, angle_m):
    	return (b * b) + math.pow((a * math.sin((math.pi * (-1.0 / (-180.0 / angle_m))))), 2.0)
    
    angle_m = abs(angle)
    function code(a, b, angle_m)
    	return Float64(Float64(b * b) + (Float64(a * sin(Float64(pi * Float64(-1.0 / Float64(-180.0 / angle_m))))) ^ 2.0))
    end
    
    angle_m = abs(angle);
    function tmp = code(a, b, angle_m)
    	tmp = (b * b) + ((a * sin((pi * (-1.0 / (-180.0 / angle_m))))) ^ 2.0);
    end
    
    angle_m = N[Abs[angle], $MachinePrecision]
    code[a_, b_, angle$95$m_] := N[(N[(b * b), $MachinePrecision] + N[Power[N[(a * N[Sin[N[(Pi * N[(-1.0 / N[(-180.0 / angle$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
    
    \begin{array}{l}
    angle_m = \left|angle\right|
    
    \\
    b \cdot b + {\left(a \cdot \sin \left(\pi \cdot \frac{-1}{\frac{-180}{angle\_m}}\right)\right)}^{2}
    \end{array}
    
    Derivation
    1. Initial program 80.2%

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

      \[\leadsto {\left(a \cdot \sin \left(\frac{angle}{180} \cdot \mathsf{PI}\left(\right)\right)\right)}^{2} + {\left(b \cdot \color{blue}{1}\right)}^{2} \]
    4. Step-by-step derivation
      1. Applied rewrites80.2%

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

        \[\leadsto {\left(a \cdot \sin \left(\frac{angle}{180} \cdot \mathsf{PI}\left(\right)\right)\right)}^{2} + \color{blue}{{b}^{2}} \]
      3. Step-by-step derivation
        1. unpow2N/A

          \[\leadsto {\left(a \cdot \sin \left(\frac{angle}{180} \cdot \mathsf{PI}\left(\right)\right)\right)}^{2} + \color{blue}{b \cdot b} \]
        2. lower-*.f6480.2

          \[\leadsto {\left(a \cdot \sin \left(\frac{angle}{180} \cdot \pi\right)\right)}^{2} + \color{blue}{b \cdot b} \]
      4. Applied rewrites80.2%

        \[\leadsto {\left(a \cdot \sin \left(\frac{angle}{180} \cdot \pi\right)\right)}^{2} + \color{blue}{b \cdot b} \]
      5. Step-by-step derivation
        1. lift-*.f64N/A

          \[\leadsto {\left(a \cdot \sin \color{blue}{\left(\frac{angle}{180} \cdot \mathsf{PI}\left(\right)\right)}\right)}^{2} + b \cdot b \]
        2. lift-/.f64N/A

          \[\leadsto {\left(a \cdot \sin \left(\color{blue}{\frac{angle}{180}} \cdot \mathsf{PI}\left(\right)\right)\right)}^{2} + b \cdot b \]
        3. clear-numN/A

          \[\leadsto {\left(a \cdot \sin \left(\color{blue}{\frac{1}{\frac{180}{angle}}} \cdot \mathsf{PI}\left(\right)\right)\right)}^{2} + b \cdot b \]
        4. associate-*l/N/A

          \[\leadsto {\left(a \cdot \sin \color{blue}{\left(\frac{1 \cdot \mathsf{PI}\left(\right)}{\frac{180}{angle}}\right)}\right)}^{2} + b \cdot b \]
        5. *-lft-identityN/A

          \[\leadsto {\left(a \cdot \sin \left(\frac{\color{blue}{\mathsf{PI}\left(\right)}}{\frac{180}{angle}}\right)\right)}^{2} + b \cdot b \]
        6. lower-/.f64N/A

          \[\leadsto {\left(a \cdot \sin \color{blue}{\left(\frac{\mathsf{PI}\left(\right)}{\frac{180}{angle}}\right)}\right)}^{2} + b \cdot b \]
        7. lower-/.f6480.2

          \[\leadsto {\left(a \cdot \sin \left(\frac{\pi}{\color{blue}{\frac{180}{angle}}}\right)\right)}^{2} + b \cdot b \]
      6. Applied rewrites80.2%

        \[\leadsto {\left(a \cdot \sin \color{blue}{\left(\frac{\pi}{\frac{180}{angle}}\right)}\right)}^{2} + b \cdot b \]
      7. Step-by-step derivation
        1. lift-/.f64N/A

          \[\leadsto {\left(a \cdot \sin \color{blue}{\left(\frac{\mathsf{PI}\left(\right)}{\frac{180}{angle}}\right)}\right)}^{2} + b \cdot b \]
        2. frac-2negN/A

          \[\leadsto {\left(a \cdot \sin \color{blue}{\left(\frac{\mathsf{neg}\left(\mathsf{PI}\left(\right)\right)}{\mathsf{neg}\left(\frac{180}{angle}\right)}\right)}\right)}^{2} + b \cdot b \]
        3. div-invN/A

          \[\leadsto {\left(a \cdot \sin \color{blue}{\left(\left(\mathsf{neg}\left(\mathsf{PI}\left(\right)\right)\right) \cdot \frac{1}{\mathsf{neg}\left(\frac{180}{angle}\right)}\right)}\right)}^{2} + b \cdot b \]
        4. lower-*.f64N/A

          \[\leadsto {\left(a \cdot \sin \color{blue}{\left(\left(\mathsf{neg}\left(\mathsf{PI}\left(\right)\right)\right) \cdot \frac{1}{\mathsf{neg}\left(\frac{180}{angle}\right)}\right)}\right)}^{2} + b \cdot b \]
        5. lower-neg.f64N/A

          \[\leadsto {\left(a \cdot \sin \left(\color{blue}{\left(\mathsf{neg}\left(\mathsf{PI}\left(\right)\right)\right)} \cdot \frac{1}{\mathsf{neg}\left(\frac{180}{angle}\right)}\right)\right)}^{2} + b \cdot b \]
        6. lower-/.f64N/A

          \[\leadsto {\left(a \cdot \sin \left(\left(\mathsf{neg}\left(\mathsf{PI}\left(\right)\right)\right) \cdot \color{blue}{\frac{1}{\mathsf{neg}\left(\frac{180}{angle}\right)}}\right)\right)}^{2} + b \cdot b \]
        7. lift-/.f64N/A

          \[\leadsto {\left(a \cdot \sin \left(\left(\mathsf{neg}\left(\mathsf{PI}\left(\right)\right)\right) \cdot \frac{1}{\mathsf{neg}\left(\color{blue}{\frac{180}{angle}}\right)}\right)\right)}^{2} + b \cdot b \]
        8. distribute-neg-fracN/A

          \[\leadsto {\left(a \cdot \sin \left(\left(\mathsf{neg}\left(\mathsf{PI}\left(\right)\right)\right) \cdot \frac{1}{\color{blue}{\frac{\mathsf{neg}\left(180\right)}{angle}}}\right)\right)}^{2} + b \cdot b \]
        9. lower-/.f64N/A

          \[\leadsto {\left(a \cdot \sin \left(\left(\mathsf{neg}\left(\mathsf{PI}\left(\right)\right)\right) \cdot \frac{1}{\color{blue}{\frac{\mathsf{neg}\left(180\right)}{angle}}}\right)\right)}^{2} + b \cdot b \]
        10. metadata-eval80.2

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

        \[\leadsto {\left(a \cdot \sin \color{blue}{\left(\left(-\pi\right) \cdot \frac{1}{\frac{-180}{angle}}\right)}\right)}^{2} + b \cdot b \]
      9. Final simplification80.2%

        \[\leadsto b \cdot b + {\left(a \cdot \sin \left(\pi \cdot \frac{-1}{\frac{-180}{angle}}\right)\right)}^{2} \]
      10. Add Preprocessing

      Reproduce

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