sin(cos(tan(acos(atan(asin(x))))))

Percentage Accurate: 11.4% → 13.6%
Time: 12.6s
Alternatives: 3
Speedup: 1.0×

Specification

?
\[-1000000000 \leq x \land x \leq 1000000000\]
\[\begin{array}{l} \\ \sin \cos \tan \cos^{-1} \tan^{-1} \sin^{-1} x \end{array} \]
(FPCore (x) :precision binary64 (sin (cos (tan (acos (atan (asin x)))))))
double code(double x) {
	return sin(cos(tan(acos(atan(asin(x))))));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = sin(cos(tan(acos(atan(asin(x))))))
end function
public static double code(double x) {
	return Math.sin(Math.cos(Math.tan(Math.acos(Math.atan(Math.asin(x))))));
}
def code(x):
	return math.sin(math.cos(math.tan(math.acos(math.atan(math.asin(x))))))
function code(x)
	return sin(cos(tan(acos(atan(asin(x))))))
end
function tmp = code(x)
	tmp = sin(cos(tan(acos(atan(asin(x))))));
end
code[x_] := N[Sin[N[Cos[N[Tan[N[ArcCos[N[ArcTan[N[ArcSin[x], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\sin \cos \tan \cos^{-1} \tan^{-1} \sin^{-1} x
\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 3 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: 11.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \sin \cos \tan \cos^{-1} \tan^{-1} \sin^{-1} x \end{array} \]
(FPCore (x) :precision binary64 (sin (cos (tan (acos (atan (asin x)))))))
double code(double x) {
	return sin(cos(tan(acos(atan(asin(x))))));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = sin(cos(tan(acos(atan(asin(x))))))
end function
public static double code(double x) {
	return Math.sin(Math.cos(Math.tan(Math.acos(Math.atan(Math.asin(x))))));
}
def code(x):
	return math.sin(math.cos(math.tan(math.acos(math.atan(math.asin(x))))))
function code(x)
	return sin(cos(tan(acos(atan(asin(x))))))
end
function tmp = code(x)
	tmp = sin(cos(tan(acos(atan(asin(x))))));
end
code[x_] := N[Sin[N[Cos[N[Tan[N[ArcCos[N[ArcTan[N[ArcSin[x], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\sin \cos \tan \cos^{-1} \tan^{-1} \sin^{-1} x
\end{array}

Alternative 1: 13.6% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \tan^{-1} \sin^{-1} x\\ \sin \cos \left(\sin \cos^{-1} t\_0 \cdot \frac{-1}{t\_0}\right) \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (atan (asin x)))) (sin (cos (* (sin (acos t_0)) (/ -1.0 t_0))))))
double code(double x) {
	double t_0 = atan(asin(x));
	return sin(cos((sin(acos(t_0)) * (-1.0 / t_0))));
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: t_0
    t_0 = atan(asin(x))
    code = sin(cos((sin(acos(t_0)) * ((-1.0d0) / t_0))))
end function
public static double code(double x) {
	double t_0 = Math.atan(Math.asin(x));
	return Math.sin(Math.cos((Math.sin(Math.acos(t_0)) * (-1.0 / t_0))));
}
def code(x):
	t_0 = math.atan(math.asin(x))
	return math.sin(math.cos((math.sin(math.acos(t_0)) * (-1.0 / t_0))))
function code(x)
	t_0 = atan(asin(x))
	return sin(cos(Float64(sin(acos(t_0)) * Float64(-1.0 / t_0))))
end
function tmp = code(x)
	t_0 = atan(asin(x));
	tmp = sin(cos((sin(acos(t_0)) * (-1.0 / t_0))));
end
code[x_] := Block[{t$95$0 = N[ArcTan[N[ArcSin[x], $MachinePrecision]], $MachinePrecision]}, N[Sin[N[Cos[N[(N[Sin[N[ArcCos[t$95$0], $MachinePrecision]], $MachinePrecision] * N[(-1.0 / t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \tan^{-1} \sin^{-1} x\\
\sin \cos \left(\sin \cos^{-1} t\_0 \cdot \frac{-1}{t\_0}\right)
\end{array}
\end{array}
Derivation
  1. Initial program 11.0%

    \[\sin \cos \tan \cos^{-1} \tan^{-1} \sin^{-1} x \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-tan.f64N/A

      \[\leadsto \sin \cos \color{blue}{\tan \cos^{-1} \tan^{-1} \sin^{-1} x} \]
    2. tan-quotN/A

      \[\leadsto \sin \cos \color{blue}{\left(\frac{\sin \cos^{-1} \tan^{-1} \sin^{-1} x}{\cos \cos^{-1} \tan^{-1} \sin^{-1} x}\right)} \]
    3. lift-acos.f64N/A

      \[\leadsto \sin \cos \left(\frac{\sin \cos^{-1} \tan^{-1} \sin^{-1} x}{\cos \color{blue}{\cos^{-1} \tan^{-1} \sin^{-1} x}}\right) \]
    4. cos-acosN/A

      \[\leadsto \sin \cos \left(\frac{\sin \cos^{-1} \tan^{-1} \sin^{-1} x}{\color{blue}{\tan^{-1} \sin^{-1} x}}\right) \]
    5. frac-2negN/A

      \[\leadsto \sin \cos \color{blue}{\left(\frac{\mathsf{neg}\left(\sin \cos^{-1} \tan^{-1} \sin^{-1} x\right)}{\mathsf{neg}\left(\tan^{-1} \sin^{-1} x\right)}\right)} \]
    6. div-invN/A

      \[\leadsto \sin \cos \color{blue}{\left(\left(\mathsf{neg}\left(\sin \cos^{-1} \tan^{-1} \sin^{-1} x\right)\right) \cdot \frac{1}{\mathsf{neg}\left(\tan^{-1} \sin^{-1} x\right)}\right)} \]
    7. lower-*.f64N/A

      \[\leadsto \sin \cos \color{blue}{\left(\left(\mathsf{neg}\left(\sin \cos^{-1} \tan^{-1} \sin^{-1} x\right)\right) \cdot \frac{1}{\mathsf{neg}\left(\tan^{-1} \sin^{-1} x\right)}\right)} \]
    8. lower-neg.f64N/A

      \[\leadsto \sin \cos \left(\color{blue}{\left(-\sin \cos^{-1} \tan^{-1} \sin^{-1} x\right)} \cdot \frac{1}{\mathsf{neg}\left(\tan^{-1} \sin^{-1} x\right)}\right) \]
    9. lower-sin.f64N/A

      \[\leadsto \sin \cos \left(\left(-\color{blue}{\sin \cos^{-1} \tan^{-1} \sin^{-1} x}\right) \cdot \frac{1}{\mathsf{neg}\left(\tan^{-1} \sin^{-1} x\right)}\right) \]
    10. frac-2negN/A

      \[\leadsto \sin \cos \left(\left(-\sin \cos^{-1} \tan^{-1} \sin^{-1} x\right) \cdot \color{blue}{\frac{\mathsf{neg}\left(1\right)}{\mathsf{neg}\left(\left(\mathsf{neg}\left(\tan^{-1} \sin^{-1} x\right)\right)\right)}}\right) \]
    11. metadata-evalN/A

      \[\leadsto \sin \cos \left(\left(-\sin \cos^{-1} \tan^{-1} \sin^{-1} x\right) \cdot \frac{\color{blue}{-1}}{\mathsf{neg}\left(\left(\mathsf{neg}\left(\tan^{-1} \sin^{-1} x\right)\right)\right)}\right) \]
    12. remove-double-negN/A

      \[\leadsto \sin \cos \left(\left(-\sin \cos^{-1} \tan^{-1} \sin^{-1} x\right) \cdot \frac{-1}{\color{blue}{\tan^{-1} \sin^{-1} x}}\right) \]
    13. lower-/.f6412.8

      \[\leadsto \sin \cos \left(\left(-\sin \cos^{-1} \tan^{-1} \sin^{-1} x\right) \cdot \color{blue}{\frac{-1}{\tan^{-1} \sin^{-1} x}}\right) \]
  4. Applied rewrites12.8%

    \[\leadsto \sin \cos \color{blue}{\left(\left(-\sin \cos^{-1} \tan^{-1} \sin^{-1} x\right) \cdot \frac{-1}{\tan^{-1} \sin^{-1} x}\right)} \]
  5. Final simplification12.8%

    \[\leadsto \sin \cos \left(\sin \cos^{-1} \tan^{-1} \sin^{-1} x \cdot \frac{-1}{\tan^{-1} \sin^{-1} x}\right) \]
  6. Add Preprocessing

Alternative 2: 13.6% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \sin \cos \left({\tan \sin^{-1} \tan^{-1} \sin^{-1} x}^{-1}\right) \end{array} \]
(FPCore (x)
 :precision binary64
 (sin (cos (pow (tan (asin (atan (asin x)))) -1.0))))
double code(double x) {
	return sin(cos(pow(tan(asin(atan(asin(x)))), -1.0)));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = sin(cos((tan(asin(atan(asin(x)))) ** (-1.0d0))))
end function
public static double code(double x) {
	return Math.sin(Math.cos(Math.pow(Math.tan(Math.asin(Math.atan(Math.asin(x)))), -1.0)));
}
def code(x):
	return math.sin(math.cos(math.pow(math.tan(math.asin(math.atan(math.asin(x)))), -1.0)))
function code(x)
	return sin(cos((tan(asin(atan(asin(x)))) ^ -1.0)))
end
function tmp = code(x)
	tmp = sin(cos((tan(asin(atan(asin(x)))) ^ -1.0)));
end
code[x_] := N[Sin[N[Cos[N[Power[N[Tan[N[ArcSin[N[ArcTan[N[ArcSin[x], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]], $MachinePrecision], -1.0], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\sin \cos \left({\tan \sin^{-1} \tan^{-1} \sin^{-1} x}^{-1}\right)
\end{array}
Derivation
  1. Initial program 11.0%

    \[\sin \cos \tan \cos^{-1} \tan^{-1} \sin^{-1} x \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-tan.f64N/A

      \[\leadsto \sin \cos \color{blue}{\tan \cos^{-1} \tan^{-1} \sin^{-1} x} \]
    2. tan-quotN/A

      \[\leadsto \sin \cos \color{blue}{\left(\frac{\sin \cos^{-1} \tan^{-1} \sin^{-1} x}{\cos \cos^{-1} \tan^{-1} \sin^{-1} x}\right)} \]
    3. lift-acos.f64N/A

      \[\leadsto \sin \cos \left(\frac{\sin \cos^{-1} \tan^{-1} \sin^{-1} x}{\cos \color{blue}{\cos^{-1} \tan^{-1} \sin^{-1} x}}\right) \]
    4. cos-acosN/A

      \[\leadsto \sin \cos \left(\frac{\sin \cos^{-1} \tan^{-1} \sin^{-1} x}{\color{blue}{\tan^{-1} \sin^{-1} x}}\right) \]
    5. clear-numN/A

      \[\leadsto \sin \cos \color{blue}{\left(\frac{1}{\frac{\tan^{-1} \sin^{-1} x}{\sin \cos^{-1} \tan^{-1} \sin^{-1} x}}\right)} \]
    6. lower-/.f64N/A

      \[\leadsto \sin \cos \color{blue}{\left(\frac{1}{\frac{\tan^{-1} \sin^{-1} x}{\sin \cos^{-1} \tan^{-1} \sin^{-1} x}}\right)} \]
    7. sin-asinN/A

      \[\leadsto \sin \cos \left(\frac{1}{\frac{\color{blue}{\sin \sin^{-1} \tan^{-1} \sin^{-1} x}}{\sin \cos^{-1} \tan^{-1} \sin^{-1} x}}\right) \]
    8. lift-acos.f64N/A

      \[\leadsto \sin \cos \left(\frac{1}{\frac{\sin \sin^{-1} \tan^{-1} \sin^{-1} x}{\sin \color{blue}{\cos^{-1} \tan^{-1} \sin^{-1} x}}}\right) \]
    9. sin-acosN/A

      \[\leadsto \sin \cos \left(\frac{1}{\frac{\sin \sin^{-1} \tan^{-1} \sin^{-1} x}{\color{blue}{\sqrt{1 - \tan^{-1} \sin^{-1} x \cdot \tan^{-1} \sin^{-1} x}}}}\right) \]
    10. cos-asinN/A

      \[\leadsto \sin \cos \left(\frac{1}{\frac{\sin \sin^{-1} \tan^{-1} \sin^{-1} x}{\color{blue}{\cos \sin^{-1} \tan^{-1} \sin^{-1} x}}}\right) \]
    11. quot-tanN/A

      \[\leadsto \sin \cos \left(\frac{1}{\color{blue}{\tan \sin^{-1} \tan^{-1} \sin^{-1} x}}\right) \]
    12. lower-tan.f64N/A

      \[\leadsto \sin \cos \left(\frac{1}{\color{blue}{\tan \sin^{-1} \tan^{-1} \sin^{-1} x}}\right) \]
    13. lower-asin.f6412.8

      \[\leadsto \sin \cos \left(\frac{1}{\tan \color{blue}{\sin^{-1} \tan^{-1} \sin^{-1} x}}\right) \]
  4. Applied rewrites12.8%

    \[\leadsto \sin \cos \color{blue}{\left(\frac{1}{\tan \sin^{-1} \tan^{-1} \sin^{-1} x}\right)} \]
  5. Final simplification12.8%

    \[\leadsto \sin \cos \left({\tan \sin^{-1} \tan^{-1} \sin^{-1} x}^{-1}\right) \]
  6. Add Preprocessing

Alternative 3: 11.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \sin \cos \tan \cos^{-1} \tan^{-1} \sin^{-1} x \end{array} \]
(FPCore (x) :precision binary64 (sin (cos (tan (acos (atan (asin x)))))))
double code(double x) {
	return sin(cos(tan(acos(atan(asin(x))))));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = sin(cos(tan(acos(atan(asin(x))))))
end function
public static double code(double x) {
	return Math.sin(Math.cos(Math.tan(Math.acos(Math.atan(Math.asin(x))))));
}
def code(x):
	return math.sin(math.cos(math.tan(math.acos(math.atan(math.asin(x))))))
function code(x)
	return sin(cos(tan(acos(atan(asin(x))))))
end
function tmp = code(x)
	tmp = sin(cos(tan(acos(atan(asin(x))))));
end
code[x_] := N[Sin[N[Cos[N[Tan[N[ArcCos[N[ArcTan[N[ArcSin[x], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\sin \cos \tan \cos^{-1} \tan^{-1} \sin^{-1} x
\end{array}
Derivation
  1. Initial program 11.0%

    \[\sin \cos \tan \cos^{-1} \tan^{-1} \sin^{-1} x \]
  2. Add Preprocessing
  3. Add Preprocessing

Reproduce

?
herbie shell --seed 1 
(FPCore (x)
  :name "sin(cos(tan(acos(atan(asin(x))))))"
  :precision binary64
  :pre (and (<= -1000000000.0 x) (<= x 1000000000.0))
  (sin (cos (tan (acos (atan (asin x)))))))