ab-angle->ABCF A

Percentage Accurate: 79.6% → 79.5%
Time: 13.8s
Alternatives: 11
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 11 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: 79.6% 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: 79.5% accurate, 1.9× speedup?

\[\begin{array}{l} \\ {\left(a \cdot \sin \left(\frac{angle \cdot \pi}{180}\right)\right)}^{2} + b \cdot b \end{array} \]
(FPCore (a b angle)
 :precision binary64
 (+ (pow (* a (sin (/ (* angle PI) 180.0))) 2.0) (* b b)))
double code(double a, double b, double angle) {
	return pow((a * sin(((angle * ((double) M_PI)) / 180.0))), 2.0) + (b * b);
}
public static double code(double a, double b, double angle) {
	return Math.pow((a * Math.sin(((angle * Math.PI) / 180.0))), 2.0) + (b * b);
}
def code(a, b, angle):
	return math.pow((a * math.sin(((angle * math.pi) / 180.0))), 2.0) + (b * b)
function code(a, b, angle)
	return Float64((Float64(a * sin(Float64(Float64(angle * pi) / 180.0))) ^ 2.0) + Float64(b * b))
end
function tmp = code(a, b, angle)
	tmp = ((a * sin(((angle * pi) / 180.0))) ^ 2.0) + (b * b);
end
code[a_, b_, angle_] := N[(N[Power[N[(a * N[Sin[N[(N[(angle * Pi), $MachinePrecision] / 180.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
{\left(a \cdot \sin \left(\frac{angle \cdot \pi}{180}\right)\right)}^{2} + b \cdot b
\end{array}
Derivation
  1. Initial program 82.4%

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

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

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

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

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

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

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

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

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

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

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

    Alternative 2: 79.6% accurate, 2.0× speedup?

    \[\begin{array}{l} \\ b \cdot b + {\left(a \cdot \sin \left(angle \cdot \left(\pi \cdot 0.005555555555555556\right)\right)\right)}^{2} \end{array} \]
    (FPCore (a b angle)
     :precision binary64
     (+ (* b b) (pow (* a (sin (* angle (* PI 0.005555555555555556)))) 2.0)))
    double code(double a, double b, double angle) {
    	return (b * b) + pow((a * sin((angle * (((double) M_PI) * 0.005555555555555556)))), 2.0);
    }
    
    public static double code(double a, double b, double angle) {
    	return (b * b) + Math.pow((a * Math.sin((angle * (Math.PI * 0.005555555555555556)))), 2.0);
    }
    
    def code(a, b, angle):
    	return (b * b) + math.pow((a * math.sin((angle * (math.pi * 0.005555555555555556)))), 2.0)
    
    function code(a, b, angle)
    	return Float64(Float64(b * b) + (Float64(a * sin(Float64(angle * Float64(pi * 0.005555555555555556)))) ^ 2.0))
    end
    
    function tmp = code(a, b, angle)
    	tmp = (b * b) + ((a * sin((angle * (pi * 0.005555555555555556)))) ^ 2.0);
    end
    
    code[a_, b_, angle_] := N[(N[(b * b), $MachinePrecision] + N[Power[N[(a * N[Sin[N[(angle * N[(Pi * 0.005555555555555556), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
    
    \begin{array}{l}
    
    \\
    b \cdot b + {\left(a \cdot \sin \left(angle \cdot \left(\pi \cdot 0.005555555555555556\right)\right)\right)}^{2}
    \end{array}
    
    Derivation
    1. Initial program 79.6%

      \[{\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. Simplified79.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto {\color{blue}{\left(\sin \left(\left(angle \cdot 0.005555555555555556\right) \cdot \pi\right) \cdot a\right)}}^{2} + b \cdot b \]
      7. Applied egg-rr79.6%

        \[\leadsto {\color{blue}{\left(\sin \left(angle \cdot \left(\pi \cdot 0.005555555555555556\right)\right) \cdot a\right)}}^{2} + b \cdot b \]
      8. Final simplification79.6%

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

      Reproduce

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