\documentclass[12pt]{article}
\usepackage[Aymar]{ammaths}
\usealgorithms
\usetikz

\newcommand{\sto}{$\rightarrow$}

\newcommand{\returnline}{\psset{unit=8pt}
\begin{pspicture}(0,0)(1,1)
\psline(0.8,0.9)(0.8,0.3)(0.2,0.3)
\psline(0.4,0.1)(0.2,0.3)(0.5,0.5)
\end{pspicture}}

\newcommand{\casiotrig}{\psset{unit=10pt}
\begin{pspicture}(0,0)(0.5,1)
\pspolygon[fillstyle=solid,fillcolor=black](0,0)(0.5,0)(0.5,0.5)
\end{pspicture}}



\begin{document}
\restylealgo{plain}
\module{Algorithms and calculators}{01}{AP08}{1 period}

\prereq{Concept and examples of algorithms}

\object{\begin{itemize}
        \item Discover how algorithms can be implemented with a calculator.
	\end{itemize}}

\mater{\begin{itemize}
	\item Calculators.
	\item Slideshow.
	\item Task sheet.
	\end{itemize}}

\modpart{Programming}{55 mins}

Pupils work by pairs. They have to implement some algorithms with their calculator and understand how the programming language works.


\pagebreak

\moddocdis{Algorithms and calculators}{01}{AP08}{TI}

\sectionblack{Creating, Editing, Executing}

\begin{center}
\begin{tabular}{|c|c|}
\hline
Create a new program & \fbox{prgm} > NEW > 1:Create New \rule{0pt}{15pt}\\[5pt] \hline
Name the program & Alpha mode is automatic.\rule{0pt}{15pt}\\[5pt] \hline
Edit an existing program & \fbox{prgm} > EDIT > Choose the program \rule{0pt}{15pt}\\[5pt] \hline
Execute a program & \fbox{prgm} > EXEC > Choose the program \rule{0pt}{15pt}\\[5pt] \hline
\end{tabular}

\sectionblack{Programming instructions}

\begin{tabular}{|c|c|}
\hline
Assignment instruction $\rightarrow$ & Key \fbox{sto$\rightarrow$} \rule{0pt}{15pt}\\[5pt] \hline
Input/Output instructions & \fbox{prgm} > I/O \rule{0pt}{15pt}\\[5pt] \hline
Conditional instructions & \fbox{prgm} > CTL \rule{0pt}{15pt}\\[5pt] \hline
Loop instructions & \fbox{prgm} > CTL \rule{0pt}{15pt}\\[5pt] \hline
\end{tabular}

\sectionblack{Relations, logic and lists}

\begin{tabular}{|c|c|}
\hline
Relations ($=$, $<$) & \fbox{2nde}+\fbox{math} > TEST \rule{0pt}{15pt}\\[5pt] \hline
Logical operators (and, or) & \fbox{2nde}+\fbox{math} > LOGIC \rule{0pt}{15pt}\\[5pt] \hline
Lists names & \fbox{2nde} + Keys 1 to 6 \rule{0pt}{15pt}\\[5pt]
\hline
\end{tabular}
\end{center}

\pagebreak

\moddocdis{Algorithms and calculators}{01}{AP08}{CASIO}

\sectionblack{Creating, Editing, Executing}

\begin{center}
\begin{tabular}{|c|c|}
\hline
Create a new program & PRGM Menu > \fbox{F3} NEW \rule{0pt}{15pt}\\[5pt] \hline
Name the program & Alpha mode is automatic. \rule{0pt}{15pt}\\[5pt] \hline
Edit an existing program & PRGM Menu > Choose the program > \fbox{F2} EDIT \rule{0pt}{15pt}\\[5pt] \hline
Execute a program & PRGM Menu > Choose the program > \fbox{F1} EXE \rule{0pt}{15pt}\\[5pt] \hline
\end{tabular}

\sectionblack{Programming instructions}

\begin{tabular}{|c|c|}
\hline
Assignment instruction $\rightarrow$ & Key \fbox{$\rightarrow$} \rule{0pt}{15pt}\\[5pt] \hline
Input/Output instructions &\fbox{SHIFT}+\fbox{VARS} > \fbox{F4} ? or \fbox{F5} \casiotrig\rule{0pt}{15pt}\\[5pt]
\hline
Separator in a line & \fbox{SHIFT}+\fbox{VARS} > \fbox{F6} > \fbox{F1} :\rule{0pt}{15pt}\\[5pt] \hline
Conditional instructions & \fbox{SHIFT}+\fbox{VARS} > \fbox{F1} COM\rule{0pt}{15pt}\\[5pt] \hline
Loop instructions & \fbox{SHIFT}+\fbox{VARS} > \fbox{F1} COM > \fbox{F6} (once or twice) \rule{0pt}{15pt}\\[5pt]
\hline
\end{tabular}

\sectionblack{Relations, logic and lists}

\begin{tabular}{|c|c|}
\hline
Relations ($=$, $<$) & \fbox{SHIFT}+\fbox{VARS} > \fbox{F6} > \fbox{F6} > \fbox{F4}
LOGIC\rule{0pt}{15pt}\\[5pt] \hline
Logical operators (and, or) & fbox{OPTN} > \fbox{F6} > \fbox{F3} REL\rule{0pt}{15pt}\\[5pt] \hline
Lists names & fbox{OPTN} > \fbox{F1} LIST > \fbox{F1} List > Number \rule{0pt}{15pt}\\[5pt]
\hline
\end{tabular}
\end{center}

\pagebreak


\moddocdis{Algorithms and calculators}{01}{AP08}{CASIO Task sheet}

\sectionblack{Algorithm \# 1}

\begin{center}
\begin{tabular}{|c|c|}
\hline
\rowcolor{lightgray} Algorithm & Implementation \\ \hline
\parbox{7.5cm}{
\begin{algorithm}[H]
%\caption{ }
%\SetLine
%%\KwData{$A$ and $B$, real numbers}
\Begin{\KwIn{$A$, $B$}
$A\leftarrow A+B$ \;
$B\leftarrow A-B$ \;
$A\leftarrow A-B$ \;
\KwOut{$A$,$B$}}
\end{algorithm}
}&
\parbox{7.5cm}{\tt
?\sto A\returnline\\
?\sto B\returnline\\
A+B\sto A\returnline\\
A-B\sto B\returnline\\
A-B\sto A\returnline\\
``A=''\hspace*{-5pt}:A\casiotrig\\
``B=''\hspace*{-5pt}:B\returnline} \\
\hline
\end{tabular}
\end{center}


\begin{enumerate}
\item Copy the program in your calculator, naming it SWITCHAB.
\item Execute the program and fill out the table below.
\begin{center}
\begin{tabular}{|c|c|c|c|}
\hline
Input & \;\; $A=5$, $B=3$ \;\; & \;\;  $A=-2$, $B=1$ \;\; & \;\;  $A=-70$, $B=42$  \;\; \rule{0pt}{15pt}\\[5pt] \hline
Output &&& \rule{0pt}{15pt}\\[5pt] \hline
\end{tabular}
\end{center}

\end{enumerate}


\sectionblack{Algorithm \# 2}

\begin{center}
\begin{tabular}{|c|c|}
\hline
\rowcolor{lightgray} Algorithm & Implementation \\ \hline
\parbox{7.5cm}{\ \vspace*{5cm}}&
\parbox{7.5cm}{\tt
?\sto A\returnline\\
?\sto B\returnline\\
A+B\sto C\returnline\\
A-B\sto D\returnline\\
``C=''\hspace*{-5pt}:C\casiotrig\returnline\\
``D=''\hspace*{-5pt}:D\returnline} \\
\hline
\end{tabular}
\end{center}


\begin{enumerate}
\item Copy the program in your calculator, naming it SUMDIFF.
\item Execute the program and fill out the table below.
\begin{center}
\begin{tabular}{|c|c|c|c|}
\hline
Input & \;\; $A=5$, $B=3$ \;\; & \;\;  $A=-2$, $B=1$ \;\; & \;\;  $A=70$, $B=42$  \;\; \rule{0pt}{15pt}\\[5pt] \hline
Output &&& \rule{0pt}{15pt}\\[5pt] \hline
\end{tabular}
\end{center}
\item What seems to be the purpose of this algorithm ?\\
\begin{tabular}{p{14cm}}
\rule{0pt}{15pt}\\[5pt] \hline
\end{tabular}\bigskip
\item In the empty space above, write the algorithm in English with the usual presentation.
\end{enumerate}

\pagebreak


\sectionblack{Algorithm \# 3}

\begin{center}
\begin{tabular}{|c|c|}
\hline
\rowcolor{lightgray} Algorithm & Implementation \\ \hline
\parbox{7.5cm}{
\begin{algorithm}[H]
  %\SetLine
  %\KwData{$x$, real number}
  
	\Begin{\KwIn{$x$}
	\eIf{$x>0$}{\KwOut{$x$}}{\KwOut{$-x$}}
    }
\end{algorithm}
}& 
\parbox{7.5cm}{\tt
?\sto X\returnline\\
If X<0\hspace*{-5pt}:Then -X\sto X\hspace*{-5pt}:IfEnd\returnline\\
X\returnline} \\
\hline
\end{tabular}
\end{center}


\begin{enumerate}
\item Copy the program in your calculator, naming it ABSVAL.
\item Execute the program and fill out the table below
\begin{center}
\begin{tabular}{|c|c|c|c|c|c|}
\hline
Input & \;\; 17 \;\; & \;\; $-5$ \;\; & \;\; $-1.8$ \;\; & \;\; $15/7$ \;\; & \;\; $-\pi$ \;\; \rule{0pt}{15pt}\\[5pt]
\hline
Output &&&&& \rule{0pt}{15pt}\\[5pt] \hline
\end{tabular}
\end{center}
\item We want to modify the algorithm so that it will compute the square of any positive input and the opposite of the
square of any negative input. Write down below the new algorithm and how you would implement it with your calculator.

\end{enumerate}

\begin{center}
\begin{tabular}{|p{7.5cm}|p{7.5cm}|}
\hline
\rowcolor{lightgray} Algorithm & Implementation \\ \hline
\parbox{7.5cm}{\vspace{5cm}}&
\parbox{7.5cm}{\vspace{5cm}} \\
\hline
\end{tabular}
\end{center}

\begin{enumerate}\setcounter{enumi}{3}
\item Copy the new program in your calculator, naming it ALGSQUARE.
\item Execute the program and fill out the table below
\begin{center}
\begin{tabular}{|c|c|c|c|c|c|}
\hline
Input & \;\; 6 \;\; & \;\; $-5$ \;\; & \;\; $-11$ \;\; & \;\; $\sqrt{2}$ \;\; & \;\; $-\sqrt{5}$ \;\;
\rule{0pt}{15pt}\\[5pt] \hline
Output &&&&& \rule{0pt}{15pt}\\[5pt] \hline
\end{tabular}
\end{center}
\end{enumerate}

\pagebreak

\moddocdis{Algorithms and calculators}{01}{AP08}{TI Task sheet}

\sectionblack{Algorithm \# 1}

\begin{center}
\begin{tabular}{|c|c|}
\hline
\rowcolor{lightgray} Algorithm & Implementation \\ \hline
\parbox{7.5cm}{
\begin{algorithm}[H]
%\caption{ }
%\SetLine
%\KwData{$A$ and $B$, real numbers}
\Begin{\KwIn{$A$, $B$}
$A\leftarrow A+B$ \;
$B\leftarrow A-B$ \;
$A\leftarrow A-B$ \;
\KwOut{$A$,$B$}}
\end{algorithm}
}&
\parbox{7.5cm}{\tt
:Prompt A\\
:Prompt B\\
:A+B\sto A\\
:A-B\sto B\\
:A-B\sto A\\
:Disp A,B
} \\
\hline
\end{tabular}
\end{center}


\begin{enumerate}
\item Copy the program in your calculator, naming it SWITCHAB.
\item Execute the program and fill out the table below.
\begin{center}
\begin{tabular}{|c|c|c|c|}
\hline
Input & \;\; $A=5$, $B=3$ \;\; & \;\;  $A=-2$, $B=1$ \;\; & \;\;  $A=-70$, $B=42$  \;\; \rule{0pt}{15pt}\\[5pt] \hline
Output &&& \rule{0pt}{15pt}\\[5pt] \hline
\end{tabular}
\end{center}

\end{enumerate}


\sectionblack{Algorithm \# 2}

\begin{center}
\begin{tabular}{|c|c|}
\hline
\rowcolor{lightgray} Algorithm & Implementation \\ \hline
\parbox{7.5cm}{\ \vspace*{5cm}}&
\parbox{7.5cm}{\tt
:Prompt A\\
:Prompt B\\
:A+B\sto C\\
:A-B\sto D\\
:Disp C,D
} \\
\hline
\end{tabular}
\end{center}


\begin{enumerate}
\item Copy the program in your calculator, naming it SUMDIFF.
\item Execute the program and fill out the table below.
\begin{center}
\begin{tabular}{|c|c|c|c|}
\hline
Input & \;\; $A=5$, $B=3$ \;\; & \;\;  $A=-2$, $B=1$ \;\; & \;\;  $A=70$, $B=42$  \;\; \rule{0pt}{15pt}\\[5pt] \hline
Output &&& \rule{0pt}{15pt}\\[5pt] \hline
\end{tabular}
\end{center}
\item What seems to be the purpose of this algorithm ?\\
\begin{tabular}{p{14cm}}
\rule{0pt}{15pt}\\[5pt] \hline
\end{tabular}\bigskip
\item In the empty space above, write the algorithm in English with the usual presentation.
\end{enumerate}

\pagebreak


\sectionblack{Algorithm \# 3}

\begin{center}
\begin{tabular}{|c|c|}
\hline
\rowcolor{lightgray} Algorithm & Implementation \\ \hline
\parbox{7.5cm}{
\begin{algorithm}[H]
  %\SetLine
  %\KwData{$x$, real number}
  
	\Begin{\KwIn{$x$\;}
	\eIf{$x>0$}{\KwOut{$x$}}{\KwOut{$-x$}}
    }
\end{algorithm}
}& 
\parbox{7.5cm}{\tt
:Prompt X\\
:If X<0\\
:Then\\
:-X\sto X\\
:End\\
:Disp X} \\
\hline
\end{tabular}
\end{center}


\begin{enumerate}
\item Copy the program in your calculator, naming it ABSVAL.
\item Execute the program and fill out the table below
\begin{center}
\begin{tabular}{|c|c|c|c|c|c|}
\hline
Input & \;\; 17 \;\; & \;\; $-5$ \;\; & \;\; $-1.8$ \;\; & \;\; $15/7$ \;\; & \;\; $-\pi$ \;\; \rule{0pt}{15pt}\\[5pt] \hline
Output &&&&& \rule{0pt}{15pt}\\[5pt] \hline
\end{tabular}
\end{center}
\item We want to modify the algorithm so that it will compute the square of any positive input and the opposite of the square of any negative input. Write down below the new algorithm and how you would implement it with your calculator.

\end{enumerate}

\begin{center}
\begin{tabular}{|p{7.5cm}|p{7.5cm}|}
\hline
\rowcolor{lightgray} Algorithm & Implementation \\ \hline
\parbox{7.5cm}{\vspace{5cm}}&
\parbox{7.5cm}{\vspace{5cm}} \\
\hline
\end{tabular}
\end{center}

\begin{enumerate}\setcounter{enumi}{3}
\item Copy the new program in your calculator, naming it ALGSQUARE.
\item Execute the program and fill out the table below
\begin{center}
\begin{tabular}{|c|c|c|c|c|c|}
\hline
Input & \;\; 6 \;\; & \;\; $-5$ \;\; & \;\; $-11$ \;\; & \;\; $\sqrt{2}$ \;\; & \;\; $-\sqrt{5}$ \;\; \rule{0pt}{15pt}\\[5pt] \hline
Output &&&&& \rule{0pt}{15pt}\\[5pt] \hline
\end{tabular}
\end{center}
\end{enumerate}


\end{document}
