\documentclass[12pt,letterpaper]{article}

% ---- Standard packages only ----
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{amsmath,amssymb,amsthm}
\usepackage{geometry}
\usepackage{graphicx}
\usepackage{fancyhdr}
\usepackage{enumitem}
\setlist[itemize]{itemsep=1pt,topsep=2pt,parsep=1pt,partopsep=0pt}
\usepackage{xcolor}
\usepackage{listings}
\usepackage[colorlinks=true,linkcolor=blue,citecolor=blue,urlcolor=blue]{hyperref}

% ---- Page layout ----
\geometry{margin=2.5cm,headheight=14pt,headsep=8pt}
\setlength{\parindent}{0pt}
\setlength{\parskip}{3pt plus 1pt}

% ---- Header / footer ----
\pagestyle{fancy}
\fancyhf{}
\rhead{\small\coursecode\ --- \studentname}
\lhead{\small Homework \hwnumber}
\rfoot{Page \thepage}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}

% ---- Metadata (edit these) ----
\newcommand{\coursecode}{Phys 256}
\newcommand{\hwnumber}{1}
\newcommand{\studentname}{Student Name}

% ---- Python listings style ----
\definecolor{codebg}{rgb}{0.97,0.97,0.95}
\definecolor{codekey}{rgb}{0.20,0.40,0.70}
\definecolor{codecom}{rgb}{0.40,0.40,0.40}
\definecolor{codestr}{rgb}{0.60,0.10,0.10}

\lstdefinestyle{pythonstyle}{
  language=Python,
  backgroundcolor=\color{codebg},
  basicstyle=\ttfamily\small,
  keywordstyle=\color{codekey}\bfseries,
  commentstyle=\color{codecom}\itshape,
  stringstyle=\color{codestr},
  showstringspaces=false,
  breaklines=true,
  frame=single,
  rulecolor=\color{codecom},
  numbers=left,
  numberstyle=\tiny\color{codecom},
  stepnumber=1,
  numbersep=8pt,
  tabsize=4,
  captionpos=b
}
\lstset{style=pythonstyle}

% ---- \problem and \solution commands ----
\newcounter{problem}
\makeatletter
\newcommand{\problem}[1]{%
  \refstepcounter{problem}%
  \vspace{6pt}\noindent{\fontsize{14pt}{16pt}\bfseries Problem \theproblem: #1}%
  \par\nobreak\vspace{3pt}}
\newcommand{\solution}{%
  \vspace{-2pt}%
  {\fontsize{14pt}{16pt}\bfseries\noindent Solution\par\nobreak\vspace{2pt}}}
\makeatother

% ---- Custom compact title (redefines \maketitle) ----
\makeatletter
\renewcommand{\maketitle}{%
  \thispagestyle{empty}%
  \noindent{\Large\bfseries \coursecode\ --- Homework \hwnumber}%
  \par\vspace{2pt}%
  \noindent{\studentname}%
  \par\vspace{8pt}%
  \hrule\vspace{10pt}}
\makeatother

\begin{document}
\maketitle

% =========================================================
\section*{Instructions}
\begin{itemize}
  \item Write your solutions clearly and show all steps.
  \item Code should be included in a \texttt{python} listing block similar
	  to listing~\ref{lst:math_module_example} and listing~\ref{lst:numpy_module_example}
  \item Listings should be labeled as in examples provided in
	  listing~\ref{lst:math_module_example} and listing~\ref{lst:numpy_module_example}
  \item you should mention listings and figures in the text unless they appear exactly in
	  the context of the sentence, i.e. ``have a look at listing~\ref{lst:numpy_module_example}''
	  is good and ``have a look at listing below'' is bad
	  (especially when there are several possible listings to looks
	  at). If you use \LaTeX{},  it can place a listing  or a figure at the arbitrary
	  location.
  \item Submit PDF file along with your source files (if it is required).
\end{itemize}

\section*{Extra information}
We are basically learning to use Python as a calculator. Because math
functionality was afterthought in Python, many math functions are
implemented in additional modules. The standard way to get access to them
would be through loading \texttt{math} module with \texttt{import} command.
See how to calculate an exponential function in
listing~\ref{lst:math_module_example}.
\begin{lstlisting}[caption={Example of \texttt{math} module use}, label={lst:math_module_example}]
>>> import math
>>> math.exp(2)
7.38905609893065
\end{lstlisting}
i.e. you would have to prepped function name with \texttt{math.} to be able
to use it. You can get similar result via  use of \texttt{numpy} module (as shown
in listing~\ref{lst:numpy_module_example}), but the outcome
might look a bit cryptic.
\begin{lstlisting}[caption={Example of \texttt{numpy} module use}, label={lst:numpy_module_example}]
>>> import numpy
>>> numpy.exp(2)
np.float64(7.38905609893065)
\end{lstlisting}

% =========================================================
\problem{(2 points)}
%---------------------------------------------------------------
Find the value of the expression
\begin{equation*}
	(3.2)^{4}-1+\ln(3)
\end{equation*}
where $\ln$ is the natural logarithm (use \texttt{log} in Python).

\problem{(1 points)}
%---------------------------------------------------------------
Which units are expected by trigonometric functions ($\sin, \cos, \tan$)
in Python is it degree, radians, steradian, or gradian. Prove it with examples.

\problem{(1 points)}
%---------------------------------------------------------------
What variable name should you type to get numerical $\pi$ representation?

\problem{(2 points)}
%---------------------------------------------------------------
Find the value of the expression
\begin{equation*}
	\sin(2 \pi + \pi/3) + \tan(\pi/8)
\end{equation*}

\problem{(2 points)}
%---------------------------------------------------------------
Find the value of the expression
\begin{equation*}
	e^{\sin(\pi/4)} - \log_{10}(25)
\end{equation*}
Use \texttt{exp} for exponent function and \texttt{log10} for logarithm to
the base of 10.

\problem{(2 points)}
%---------------------------------------------------------------
Find the value of the expression
\begin{equation*}
	\cos^2(\pi/3)
\end{equation*}
Notice that human/mathematical notation is quite different from what Python
is expecting.

\problem{(4 points)}
%---------------------------------------------------------------
Find the largest number $x$ (one significant digit is enough) such that the
numerical evaluation of expression
\begin{equation*}
	(1+x)-1
\end{equation*}
equals to zero. The value of $x$ gives you an estimate of the relative
uncertainty of your calculations with Python, try to keep it in mind when
you do calculations. Note that $x$ is actually rather small. 

\problem{(3 points)}
%---------------------------------------------------------------
Find the value of the expression
\begin{equation*}
	100 \times (1/7 +  10^{-22}) - 100/7
\end{equation*}
Algebraically you should get $10^{-20}$, but outcome is much larger.
Explain it.

\problem{(3 points)}
%---------------------------------------------------------------
Find the numerical value of the expression
\begin{equation*}
	10^{16} + 1 - 10^{16}	
\end{equation*}
with Python.
Algebraically you should get 1. If your result is not 1, please,  explain.

\end{document}
