From efc8e702770222a7a62db35e1c5352dea1dbca45 Mon Sep 17 00:00:00 2001 From: Daniel Bosk Date: Fri, 14 Jul 2023 17:01:23 +0200 Subject: [PATCH 01/12] Adds pythontex --- research/misconceptions/preamble.tex | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/research/misconceptions/preamble.tex b/research/misconceptions/preamble.tex index 82192b2d..bf943134 100644 --- a/research/misconceptions/preamble.tex +++ b/research/misconceptions/preamble.tex @@ -12,8 +12,13 @@ \usepackage[inline]{enumitem} \setlist[enumerate]{label=(\arabic*)} -\usepackage{minted} +\usepackage[outputdir=ltxobj]{minted} \setminted{autogobble,linenos} +\usepackage{pythontex} +\setpythontexfv{numbers=left} +\setpythontexoutputdir{.} +\setpythontexworkingdir{..} + \usepackage{verbatim} % adds environment for commenting out blocks of text & for better verbatim \usepackage{caption} % make it possible to include more than one captioned figure/table in a single float From 52771f5135ede9032855c5cca383537946b1f4b2 Mon Sep 17 00:00:00 2001 From: Daniel Bosk Date: Fri, 14 Jul 2023 17:00:34 +0200 Subject: [PATCH 02/12] Switches misconceptions to compile using makefiles --- research/misconceptions/Makefile | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/research/misconceptions/Makefile b/research/misconceptions/Makefile index 5c6216a2..646cc45c 100644 --- a/research/misconceptions/Makefile +++ b/research/misconceptions/Makefile @@ -1,11 +1,18 @@ +LATEXFLAGS= -shell-escape +TEX_PYTHONTEX= yes + .PHONY: all all: article.pdf article.pdf: article.tex - latexmk -shell-escape -pdf $< - article.pdf: bibliography.bib article.pdf: preamble.tex + +article.pdf: introduction.tex +article.pdf: background.tex +article.pdf: method.tex +article.pdf: results-overview.tex + article.pdf: classes.tex article.pdf: conditionals.tex article.pdf: functions-variables.tex @@ -13,11 +20,11 @@ article.pdf: problem-solving.tex article.pdf: repetitions.tex article.pdf: tools.tex article.pdf: types.tex -article.pdf: background.tex -article.pdf: introduction.tex -article.pdf: method.tex .PHONY: clean clean: latexmk -C ${RM} article.bbl article.run.xml + +INCLUDE_MAKEFILES?=../../makefiles +include ${INCLUDE_MAKEFILES}/tex.mk From 667eb57bc2a4acff4686b9dcb53f09278e11f9aa Mon Sep 17 00:00:00 2001 From: Daniel Bosk Date: Fri, 21 Jul 2023 21:18:03 +0200 Subject: [PATCH 03/12] Adds examples on func args from NCOL slides --- research/misconceptions/Makefile | 2 +- .../misconceptions/functions-variables.tex | 55 +++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/research/misconceptions/Makefile b/research/misconceptions/Makefile index 646cc45c..48946db9 100644 --- a/research/misconceptions/Makefile +++ b/research/misconceptions/Makefile @@ -11,7 +11,7 @@ article.pdf: preamble.tex article.pdf: introduction.tex article.pdf: background.tex article.pdf: method.tex -article.pdf: results-overview.tex +#article.pdf: results-overview.tex article.pdf: classes.tex article.pdf: conditionals.tex diff --git a/research/misconceptions/functions-variables.tex b/research/misconceptions/functions-variables.tex index c9a2d359..594aec00 100644 --- a/research/misconceptions/functions-variables.tex +++ b/research/misconceptions/functions-variables.tex @@ -5,6 +5,61 @@ \subsection{Functions and variables} section will be divided into several categories, which will reflect the different areas that students have trouble grasping. +\subsection{Arguments to functions} + +We start with the following example. +\begin{pyblock}[greet] +def greet(name, place): + print(f"Hello {name}, so you're from {place}?") + +def main(): + name = "Ada" + place = "Computer Town" + greet(name, place) + +main() +\end{pyblock} +The output of running the code will be: +\stdoutpythontex[verbatim] + +\subsection{Scope of identifiers} + +\begin{pyblock}[greet-scope][highlightlines={5-7}] +def greet(name, place): + print(f"Hello {name}, so you're from {place}?") + +def main(): + the_name = "Ada" + the_place = "Computer Town" + greet(the_name, the_place) + +main() +\end{pyblock} + +\begin{pyblock}[greet-scope-more][highlightlines={5}] +def greet(name, place) + print(f"Hello {name}, so you're from {place}?") + +def main(): + greet("Ada", "Computer Town") + +main() +\end{pyblock} + +\subsection{Order of arguments} + +\begin{pyblock}[greet-order][highlightlines={1,7}] +def greet(name, place): + print(f"Hello {name}, so you're from {place}?") + +def main(): + name = "Ada" + place = "Computer Town" + greet(place, name) + +main() +\end{pyblock} + \subsubsection{Conceptual understanding of variables} According to \textcite{ From 9bb59478b066dd9746bff7dc8b5c441856115612 Mon Sep 17 00:00:00 2001 From: Daniel Bosk Date: Sun, 23 Jul 2023 23:16:21 +0200 Subject: [PATCH 04/12] Starts rewrite of functions-variables section --- .../misconceptions/functions-variables.tex | 192 +++++++++--------- 1 file changed, 99 insertions(+), 93 deletions(-) diff --git a/research/misconceptions/functions-variables.tex b/research/misconceptions/functions-variables.tex index 594aec00..27ec0d48 100644 --- a/research/misconceptions/functions-variables.tex +++ b/research/misconceptions/functions-variables.tex @@ -5,98 +5,41 @@ \subsection{Functions and variables} section will be divided into several categories, which will reflect the different areas that students have trouble grasping. -\subsection{Arguments to functions} - -We start with the following example. -\begin{pyblock}[greet] -def greet(name, place): - print(f"Hello {name}, so you're from {place}?") - -def main(): - name = "Ada" - place = "Computer Town" - greet(name, place) - -main() -\end{pyblock} -The output of running the code will be: -\stdoutpythontex[verbatim] - -\subsection{Scope of identifiers} - -\begin{pyblock}[greet-scope][highlightlines={5-7}] -def greet(name, place): - print(f"Hello {name}, so you're from {place}?") - -def main(): - the_name = "Ada" - the_place = "Computer Town" - greet(the_name, the_place) - -main() -\end{pyblock} - -\begin{pyblock}[greet-scope-more][highlightlines={5}] -def greet(name, place) - print(f"Hello {name}, so you're from {place}?") - -def main(): - greet("Ada", "Computer Town") - -main() -\end{pyblock} - -\subsection{Order of arguments} - -\begin{pyblock}[greet-order][highlightlines={1,7}] -def greet(name, place): - print(f"Hello {name}, so you're from {place}?") - -def main(): - name = "Ada" - place = "Computer Town" - greet(place, name) - -main() -\end{pyblock} - - \subsubsection{Conceptual understanding of variables} + According to \textcite{ Kohn2017VariableEvaluation,Plass2015Variables,Doukakis2007}, sometimes students believe that variables can hold an entire algorithm and -therefore see a variable as a function (or a mathematical equation). This -will -create problems when a student creates a variable in belief that the -variable -will dynamically change its value when the equation would change its value, -or be updated -when the variable is used in the program. Another misconception that goes -hand in hand with the assumption that a +therefore see a variable as a function (or a mathematical equation). +This will create problems when a student creates a variable in belief that the +variable will dynamically change its value when the equation would change its +value, or be updated when the variable is used in the program. + +Another misconception that goes hand in hand with the assumption that a variable holds an equation and not a single value, is that if in the return -statement the student returns an equation, the student believes that the -return +statement the student returns an equation, the student believes that the return value will be that equation, not the value that the equation represents \parencite{Kohn2017VariableEvaluation}. From a variation theoretic perspective, we can say several things about this: \begin{enumerate} - \item That variables and functions are interconnected and should be -treated - simultaneously (not \enquote{one thing at a time}), to be able to -contrast + \item That variables and functions are interconnected and should be treated + simultaneously (not \enquote{one thing at a time}), to be able to contrast them \parencite[\cf][Ch~6, pp~167--168]{NCOL}. \item Unlike in mathematics, every line in a piece of program (in an imperative language) constitutes a new state of the program. - We must teach this to students through a series of patterns, as -dictated by + We must teach this to students through a series of patterns, as dictated by variation theory. \end{enumerate} -A pattern that could be used to help students understand how a variable -defined by a mathematical statement (for example (\mintinline{python}{x = a -+b})) is interpreted by Python, could be as followed: +So, how should we teach functions and variables according to variation theory? +Let's assume that the students know variables and equations from mathematics +and that that's the only prerequisite knowledge. + +A pattern that could be used to help students understand how a variable defined +by a mathematical statement (for example \mintinline{python}{x = a + b}) is +interpreted by Python, could be as followed: \begin{description} \item [Contrast] Show the contrast between where x first is defined by @@ -107,29 +50,34 @@ \subsubsection{Conceptual understanding of variables} \hfill \begin{minipage}[t]{0.45\columnwidth} - \begin{minted}{python} - def example(): - a = 1 - b = 2 - x = a + b + \begin{pyblock}[varstateC1] +a = 1 +b = 2 +x = a + b - return x - \end{minted} +print(f"x = {x}") + \end{pyblock} + + \vspace{0.5em} + Which yields the following: + \stdoutpythontex[varstateC1][verbatim] \end{minipage} \hfill \begin{minipage}[t]{0.45\columnwidth} - \begin{minted}[highlightlines={5-6}]{python} - def example(): - a = 1 - b = 2 - x = a + b - a = 2 - b = 3 - - return x - \end{minted} + \begin{pyblock}[varstateC2][highlightlines={4-5}] +a = 1 +b = 2 +x = a + b +a = 2 +b = 3 + +print(f"x = {x}") + \end{pyblock} + + \vspace{0.5em} + Which yields the following: + \stdoutpythontex[varstateC2][verbatim] \end{minipage} -\newline Now, according to variation theory, only the aspect in focus should change. @@ -1176,4 +1124,62 @@ \subsubsection{Variables in mathematics vs programming} \item[Fusion] \end{description} +\endinput + +\subsection{Arguments to functions} + +We start with the following example. +\begin{pyblock}[greet] +def greet(name, place): + print(f"Hello {name}, so you're from {place}?") + +def main(): + name = "Ada" + place = "Computer Town" + greet(name, place) + +main() +\end{pyblock} +The output of running the code will be: +\stdoutpythontex[verbatim] + +\subsection{Scope of identifiers} + +\begin{pyblock}[greet-scope][highlightlines={5-7}] +def greet(name, place): + print(f"Hello {name}, so you're from {place}?") + +def main(): + the_name = "Ada" + the_place = "Computer Town" + greet(the_name, the_place) + +main() +\end{pyblock} + +\begin{pyblock}[greet-scope-more][highlightlines={5}] +def greet(name, place) + print(f"Hello {name}, so you're from {place}?") + +def main(): + greet("Ada", "Computer Town") + +main() +\end{pyblock} + +\subsection{Order of arguments} + +\begin{pyblock}[greet-order][highlightlines={1,7}] +def greet(name, place): + print(f"Hello {name}, so you're from {place}?") + +def main(): + name = "Ada" + place = "Computer Town" + greet(place, name) + +main() +\end{pyblock} + + From 205eb78926eeb84d27f3bd82572a80a7353bbde5 Mon Sep 17 00:00:00 2001 From: Daniel Bosk Date: Mon, 24 Jul 2023 00:01:07 +0200 Subject: [PATCH 05/12] Updates first few examples in functions-variables --- .../misconceptions/functions-variables.tex | 205 +++++++++--------- 1 file changed, 99 insertions(+), 106 deletions(-) diff --git a/research/misconceptions/functions-variables.tex b/research/misconceptions/functions-variables.tex index 27ec0d48..f17cf246 100644 --- a/research/misconceptions/functions-variables.tex +++ b/research/misconceptions/functions-variables.tex @@ -37,34 +37,31 @@ \subsubsection{Conceptual understanding of variables} Let's assume that the students know variables and equations from mathematics and that that's the only prerequisite knowledge. -A pattern that could be used to help students understand how a variable defined -by a mathematical statement (for example \mintinline{python}{x = a + b}) is -interpreted by Python, could be as followed: +\subsubsection{Statefulness of variables} \begin{description} - \item [Contrast] Show the contrast between where x first is defined by -addition of variables, then by addition of variables where the value -of the variables is changed after the definition of x. The contrast is -shown by printing all these variations, where the value of x is -invariant, but the value of the variables is the variant. + \item [Contrast] We must introduce variation in the aspect (dimension) of + statefulness of variables, but keep all other aspects (dimensions) + invariant. - \hfill -\begin{minipage}[t]{0.45\columnwidth} - \begin{pyblock}[varstateC1] + \begin{minipage}[t]{0.45\columnwidth} + \begin{pyblock}[varstateC1] a = 1 b = 2 x = a + b + + print(f"x = {x}") - \end{pyblock} + \end{pyblock} - \vspace{0.5em} - Which yields the following: - \stdoutpythontex[varstateC1][verbatim] -\end{minipage} -\hfill -\begin{minipage}[t]{0.45\columnwidth} - \begin{pyblock}[varstateC2][highlightlines={4-5}] + \vspace{0.5em} + Which yields the following: + \printpythontex[verbatim] + \end{minipage} + \hfill + \begin{minipage}[t]{0.45\columnwidth} + \begin{pyblock}[varstateC2][highlightlines={4-5}] a = 1 b = 2 x = a + b @@ -72,96 +69,92 @@ \subsubsection{Conceptual understanding of variables} b = 3 print(f"x = {x}") - \end{pyblock} - - \vspace{0.5em} - Which yields the following: - \stdoutpythontex[varstateC2][verbatim] -\end{minipage} - - Now, according to variation theory, only the aspect in focus should -change. - Hence, we kept the name \mintinline{python}{example} in both code -snippets - above. - This implies that we must show the students how we change this -function, - not create a new function that with a different name with the -differences. - (It would be natural to call one \mintinline{python}{example1} and the - other \mintinline{python}{example2}, but that should not be done at -this - stage.) - - \item [Generalisation] In the generalisation pattern we instead let -the value of \mintinline{python}{x} vary, and keep the critical aspect -(the definition) invariant. - -\hfill - \begin{minipage}[t]{0.45\columnwidth} - \begin{minted}{python} - def example(): - a = 3 - b = 2 - x = a + b - - return x - \end{minted} -\end{minipage} -\hfill -\begin{minipage}[t]{0.45\columnwidth} - \begin{minted}[highlightcolor=light-green, highlightlines={4,6}]{python} - def example(): - a = 2 - b = 5 - x = a + b - - return x - \end{minted} -\end{minipage} -\newline + \end{pyblock} + + \vspace{0.5em} + Which yields the following: + \printpythontex[verbatim] + \end{minipage} - \item [Fusion] Here we will let the definition and value of x vary, -and also use the functionality of functions (in order to teach -functions and variables simultaneously). + The contrast is the update of the variables \mintinline{python}{a} and + \mintinline{python}{b}, which doesn't cause any change (as would be + expected according to the misconception). -\hfill -\begin{minipage}[t]{0.3\columnwidth} - \begin{minted}{python} - def example(a, b): - x = a + b - - return x - \end{minted} -\end{minipage} -\hfill -\begin{minipage}[t]{0.3\columnwidth} - \begin{minted}[highlightlines={}]{python} - def example(a, b): - a = 1 - b = 2 - x = a + b - a = 2 - b = 3 - - return x - \end{minted} -\end{minipage} -\hfill -\begin{minipage}[t]{0.3\columnwidth} - \begin{minted}[highlightlines={7}]{python} - def example(): - a = 1 - b = 2 - x = a + b - a = 2 - b = 3 - x = a + b - - return x - \end{minted} -\end{minipage} + \item [Generalisation] In the generalisation pattern we want to generalise + phenomenon to other examples. + \begin{minipage}[t]{0.45\columnwidth} + \begin{pyblock}[varstateG1] +a = 3 +b = 2 +c = a + b +a = 1 +b = 5 + +print(f"c = {c}") + \end{pyblock} + + \vspace{0.5em} + Which yields the following: + \printpythontex[verbatim] + \end{minipage} + \hfill + \begin{minipage}[t]{0.45\columnwidth} + \begin{pyblock}[varstateG2] +name = "Ada" +greeting = "Hi" +msg = f"{greeting} {name}!" +name = "Beda" + + +print(msg) + \end{pyblock} + + \vspace{0.5em} + Which yields the following: + \printpythontex[verbatim] + \end{minipage} + + We see that we've varied the variable names and the types, still the same + effect. + + \item [Fusion] We can finish by updating the original definition after the + updates. + + \begin{minipage}[t]{0.45\columnwidth} + \begin{pyblock}[varstateG2][highlightlines=5] +name = "Ada" +greeting = "Hi" +msg = f"{greeting} {name}!" +name = "Beda" +msg = f"{greeting} {name}!" + +print(msg) + \end{pyblock} + + \vspace{0.5em} + Which yields the following: + \printpythontex[verbatim] + \end{minipage} + \hfill + \begin{minipage}[t]{0.45\columnwidth} + \begin{pyblock}[varstateG2] +name = "Ada" +greeting = "Hi" +msg = f"{greeting} {name}!" +name = "Beda" + + +print(msg) + \end{pyblock} + + \vspace{0.5em} + Which yields the following: + \printpythontex[verbatim] + \end{minipage} + + We reuse that last example from the generalization to make the difference + clear. \end{description} From fcb517d99e8e5178432cf67bed6974dec4d9e715 Mon Sep 17 00:00:00 2001 From: Daniel Bosk Date: Mon, 24 Jul 2023 10:12:03 +0200 Subject: [PATCH 06/12] Improves first functions example - Removes fusion, those examples should be generalisation. - Adds XXX about functions next. --- .../misconceptions/functions-variables.tex | 63 +++++++++++++++---- 1 file changed, 52 insertions(+), 11 deletions(-) diff --git a/research/misconceptions/functions-variables.tex b/research/misconceptions/functions-variables.tex index f17cf246..6c981962 100644 --- a/research/misconceptions/functions-variables.tex +++ b/research/misconceptions/functions-variables.tex @@ -77,11 +77,15 @@ \subsubsection{Statefulness of variables} \end{minipage} The contrast is the update of the variables \mintinline{python}{a} and - \mintinline{python}{b}, which doesn't cause any change (as would be - expected according to the misconception). + \mintinline{python}{b}, which doesn't cause any change---as would be + expected according to the misconception identified by + \textcite{Kohn2017VariableEvaluation,Plass2015Variables,Doukakis2007}, that + sometimes students believe that variables can hold an entire algorithm and + therefore see a variable as a function (or a mathematical equation). \item [Generalisation] In the generalisation pattern we want to generalise - phenomenon to other examples. + phenomenon to other examples, so that the student can observe when the + phenomenon occurs. \begin{minipage}[t]{0.45\columnwidth} \begin{pyblock}[varstateG1] @@ -118,16 +122,15 @@ \subsubsection{Statefulness of variables} We see that we've varied the variable names and the types, still the same effect. - \item [Fusion] We can finish by updating the original definition after the - updates. + We can finish by updating the original definition after the updates. \begin{minipage}[t]{0.45\columnwidth} - \begin{pyblock}[varstateG2][highlightlines=5] + \begin{pyblock}[varstateG2] name = "Ada" greeting = "Hi" msg = f"{greeting} {name}!" name = "Beda" -msg = f"{greeting} {name}!" + print(msg) \end{pyblock} @@ -138,12 +141,12 @@ \subsubsection{Statefulness of variables} \end{minipage} \hfill \begin{minipage}[t]{0.45\columnwidth} - \begin{pyblock}[varstateG2] + \begin{pyblock}[varstateG2][highlightlines=5] name = "Ada" greeting = "Hi" msg = f"{greeting} {name}!" name = "Beda" - +msg = f"{greeting} {name}!" print(msg) \end{pyblock} @@ -153,10 +156,48 @@ \subsubsection{Statefulness of variables} \printpythontex[verbatim] \end{minipage} - We reuse that last example from the generalization to make the difference - clear. + And then the first example again: + + \begin{minipage}[t]{0.45\columnwidth} + \begin{pyblock}[varstateG1] +a = 3 +b = 2 +c = a + b +a = 1 +b = 5 + +print(f"c = {c}") + \end{pyblock} + + \vspace{0.5em} + Which yields the following: + \printpythontex[verbatim] + \end{minipage} + \hfill + \begin{minipage}[t]{0.45\columnwidth} + \begin{pyblock}[varstateG1][highlightlines=6] +a = 3 +b = 2 +c = a + b +a = 1 +b = 5 +c = a + b +print(f"c = {c}") + \end{pyblock} + + \vspace{0.5em} + Which yields the following: + \printpythontex[verbatim] + \end{minipage} \end{description} +Now, this was just one aspect of the misconception that students believe that +variables can hold an entire algorithm and therefore see a variable as a +function (or a mathematical equation). +We also have that expected behaviour, namely through functions. + +XXX Introduce pattern for functions using the first example from above, now +we'll show how to achieve the expected behaviour by using functions. \subsubsection{Defining variables and functions} From 112a63f09471a126ada5b658437477f4e2b51400 Mon Sep 17 00:00:00 2001 From: Daniel Bosk Date: Mon, 24 Jul 2023 10:39:59 +0200 Subject: [PATCH 07/12] Adds first example of variability of functions --- .../misconceptions/functions-variables.tex | 60 ++++++++++++++++++- 1 file changed, 58 insertions(+), 2 deletions(-) diff --git a/research/misconceptions/functions-variables.tex b/research/misconceptions/functions-variables.tex index 6c981962..f6ce7661 100644 --- a/research/misconceptions/functions-variables.tex +++ b/research/misconceptions/functions-variables.tex @@ -196,8 +196,64 @@ \subsubsection{Statefulness of variables} function (or a mathematical equation). We also have that expected behaviour, namely through functions. -XXX Introduce pattern for functions using the first example from above, now -we'll show how to achieve the expected behaviour by using functions. +\subsubsection{Variability of functions} + +The students' expectation that \(y = kx + m\) is a function +\parencite{Kohn2017VariableEvaluation,Plass2015Variables,Doukakis2007} is +likely due to the mathematical shorthand for \(y(x) = kx + m\). +Above we introduced a series of pattern showing that +\mintinline{python}{y = k*x + m} +is not the same as the dynamic relation in mathematics, +\(y = kx + m\). +However, we can achieve that dynamic relation in Python too, through functions. +Next, we'll go back and show a series of patterns to achieve the expected +behaviour. + +\begin{description} + \item [Contrast] We must introduce variation in the aspect (dimension) of + statefulness of variables, but keep all other aspects (dimensions) + invariant. + + \begin{minipage}[t]{0.45\columnwidth} + \begin{pyblock}[funcC1] +a = 1 +b = 2 +x = a + b +a = 2 +b = 3 + +print(f"x = {x}") + \end{pyblock} + + \vspace{0.5em} + Which yields the following: + \printpythontex[verbatim] + \end{minipage} + \hfill + \begin{minipage}[t]{0.45\columnwidth} + \begin{pyblock}[funcC2][highlightlines={1-2}] +def x(a, b): + return a + b + + + +print(f"x(1, 2) = {x(1, 2)}") +print(f"x(2, 3) = {x(2, 3)}") + \end{pyblock} + + \vspace{0.5em} + Which yields the following: + \printpythontex[verbatim] + \end{minipage} +\end{description} + +XXX Treat the other aspects related to functions: scope, default values, ... + +Another misconception that goes hand in hand with the assumption that a +variable holds an equation and not a single value, is that if in the return +statement the student returns an equation, the student believes that the return +value will be that equation, not the value that the equation represents +\parencite{Kohn2017VariableEvaluation}. \subsubsection{Defining variables and functions} From 14cbcab5269faa2dcbf0798192d31d7a73bf76a9 Mon Sep 17 00:00:00 2001 From: Daniel Bosk Date: Mon, 24 Jul 2023 10:43:42 +0200 Subject: [PATCH 08/12] Adds highlight in variability of functions contrast --- research/misconceptions/functions-variables.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/research/misconceptions/functions-variables.tex b/research/misconceptions/functions-variables.tex index f6ce7661..54c56568 100644 --- a/research/misconceptions/functions-variables.tex +++ b/research/misconceptions/functions-variables.tex @@ -215,7 +215,7 @@ \subsubsection{Variability of functions} invariant. \begin{minipage}[t]{0.45\columnwidth} - \begin{pyblock}[funcC1] + \begin{pyblock}[funcC1][highlightlines=3] a = 1 b = 2 x = a + b From b0c453c1268e54ed85a11054cec9973c49f0f881 Mon Sep 17 00:00:00 2001 From: Daniel Bosk Date: Tue, 25 Jul 2023 10:36:58 +0200 Subject: [PATCH 09/12] Adds generalisation and fusion for functionality of functions --- .../misconceptions/functions-variables.tex | 74 ++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) diff --git a/research/misconceptions/functions-variables.tex b/research/misconceptions/functions-variables.tex index 54c56568..85e93971 100644 --- a/research/misconceptions/functions-variables.tex +++ b/research/misconceptions/functions-variables.tex @@ -204,7 +204,7 @@ \subsubsection{Variability of functions} Above we introduced a series of pattern showing that \mintinline{python}{y = k*x + m} is not the same as the dynamic relation in mathematics, -\(y = kx + m\). +\(y = kx + m\) (or \(y(x) = kx + m\) to be precise). However, we can achieve that dynamic relation in Python too, through functions. Next, we'll go back and show a series of patterns to achieve the expected behaviour. @@ -245,6 +245,78 @@ \subsubsection{Variability of functions} Which yields the following: \printpythontex[verbatim] \end{minipage} + + \item[Generalisation] We'd like to generalise this. + + \begin{minipage}[t]{0.45\columnwidth} + \begin{pyblock}[funcG1] +def y(x): + return 2*x + 5 + +print(f"y(1) = {y(1)}") +print(f"y(2) = {y(2)}") + \end{pyblock} + + \vspace{0.5em} + Which yields the following: + \printpythontex[verbatim] + \end{minipage} + \hfill + \begin{minipage}[t]{0.45\columnwidth} + \begin{pyblock}[funcG2] +def greet(name, greeting): + return f"{greeting} {name}!" + +print(greet("Ada", "Hi")) +print(greet("Beda", "Hi")) + \end{pyblock} + + \vspace{0.5em} + Which yields the following: + \printpythontex[verbatim] + \end{minipage} + + \item[Fusion] Now we'd like to fuse this back with the statefulness of + variables from above. + + \begin{minipage}[t]{0.45\columnwidth} + \begin{pyblock}[funcG1] +def y(x): + return 2*x + 5 + +y1 = y(1) +y2 = y(2) +y3 = y(5) + +print(f"y1 = {y1}") +print(f"y2 = {y2}") +print(f"y3 = {y3}") + \end{pyblock} + + \vspace{0.5em} + Which yields the following: + \printpythontex[verbatim] + \end{minipage} + \hfill + \begin{minipage}[t]{0.45\columnwidth} + \begin{pyblock}[funcG2] +def greet(name, greeting): + return f"{greeting} {name}!" + + + +msg = greet("Ada", "Hi") +print(msg) + +msg = greet("Beda", "Hi") +print(msg) + \end{pyblock} + + \vspace{0.5em} + Which yields the following: + \printpythontex[verbatim] + \end{minipage} + \end{description} XXX Treat the other aspects related to functions: scope, default values, ... From c18386dcf51c7d64a9aec16392e703b9b29fb47f Mon Sep 17 00:00:00 2001 From: Daniel Bosk Date: Tue, 25 Jul 2023 21:34:53 +0200 Subject: [PATCH 10/12] Improves commentary on what varies and what doesn't --- .../misconceptions/functions-variables.tex | 64 ++++++++++++++----- research/misconceptions/preamble.tex | 2 + 2 files changed, 49 insertions(+), 17 deletions(-) diff --git a/research/misconceptions/functions-variables.tex b/research/misconceptions/functions-variables.tex index 85e93971..d5e9d7e8 100644 --- a/research/misconceptions/functions-variables.tex +++ b/research/misconceptions/functions-variables.tex @@ -34,15 +34,35 @@ \subsubsection{Conceptual understanding of variables} \end{enumerate} So, how should we teach functions and variables according to variation theory? -Let's assume that the students know variables and equations from mathematics -and that that's the only prerequisite knowledge. - -\subsubsection{Statefulness of variables} +Let's assume that the students know variables, functions (or relations or maps) +and equations from mathematics and that that's the only prerequisite knowledge. + +From the variation theoretic perspective, one \emph{critial aspect} (dimension +of variation) is the type of object that an identifier refers to. +Functions (as a type) is a \emph{critical feature} in that dimension. +But all non-functional types are also critical features that the students must +learn to discern\footnote{% + Actually, this is not only true for programming, it's equally true for + mathematics. + Unfortunately, it's not until university-level mathematics (at least in the + Swedish context) that most students are taught to specify that \(y\colon + \mathbb{R}\to \mathbb{R}\) is a function and \(x\in\mathbb{R}\) is simply a + variable such that \(y\mapsto kx + m\). + Those details are usually lost in the \enquote{equationification} of + functions at lower levels. +}. + +Another critical aspect (dimension of variation) contains the features +statefulness (of an algorithm) and statelessness (of equations). + +\subsubsection{Statefulness of variable assignments} \begin{description} - \item [Contrast] We must introduce variation in the aspect (dimension) of - statefulness of variables, but keep all other aspects (dimensions) - invariant. + \item [Contrast] We must introduce variation in the aspect (dimension of + variability) of statefulness of variables, but keep all other aspects + (dimensions) invariant. + Varying the statefulness of variables is variation in where we notice it + and where we don't. \begin{minipage}[t]{0.45\columnwidth} \begin{pyblock}[varstateC1] @@ -84,8 +104,11 @@ \subsubsection{Statefulness of variables} therefore see a variable as a function (or a mathematical equation). \item [Generalisation] In the generalisation pattern we want to generalise - phenomenon to other examples, so that the student can observe when the - phenomenon occurs. + phenomenon (statefulness) to other examples, so that the student can + observe when the phenomenon occurs. + This means that we keep the aspect (dimension of variability) of + statefulness of variables invariant (we can observe it) while we vary + other available aspects (for example variable names or values). \begin{minipage}[t]{0.45\columnwidth} \begin{pyblock}[varstateG1] @@ -122,7 +145,8 @@ \subsubsection{Statefulness of variables} We see that we've varied the variable names and the types, still the same effect. - We can finish by updating the original definition after the updates. + We can finish by updating the original definition after the updates, to + show that then we don't get the effect. \begin{minipage}[t]{0.45\columnwidth} \begin{pyblock}[varstateG2] @@ -156,7 +180,7 @@ \subsubsection{Statefulness of variables} \printpythontex[verbatim] \end{minipage} - And then the first example again: + And then the same thing with the first example again: \begin{minipage}[t]{0.45\columnwidth} \begin{pyblock}[varstateG1] @@ -200,19 +224,23 @@ \subsubsection{Variability of functions} The students' expectation that \(y = kx + m\) is a function \parencite{Kohn2017VariableEvaluation,Plass2015Variables,Doukakis2007} is -likely due to the mathematical shorthand for \(y(x) = kx + m\). +likely due to the mathematical shorthand for \(y(x) = kx + m\), where +\enquote{\((x)\)} is dropped. Above we introduced a series of pattern showing that \mintinline{python}{y = k*x + m} is not the same as the dynamic relation in mathematics, -\(y = kx + m\) (or \(y(x) = kx + m\) to be precise). +\(y = kx + m\) (or rather \(y(x) = kx + m\) to be precise). However, we can achieve that dynamic relation in Python too, through functions. Next, we'll go back and show a series of patterns to achieve the expected behaviour. \begin{description} - \item [Contrast] We must introduce variation in the aspect (dimension) of - statefulness of variables, but keep all other aspects (dimensions) - invariant. + \item [Contrast] We must introduce variation in the aspect (dimension of + variation) of functionality of functions, where we have the behaviour the + students expected from mathematics. + (But keep all other aspects/dimensions invariant.) + For this, we return to the original example, but make another contrast this + time. \begin{minipage}[t]{0.45\columnwidth} \begin{pyblock}[funcC1][highlightlines=3] @@ -246,7 +274,9 @@ \subsubsection{Variability of functions} \printpythontex[verbatim] \end{minipage} - \item[Generalisation] We'd like to generalise this. + \item[Generalisation] To generalise, we must keep this aspect invariant (the + dynamic behaviour of a function), but vary other aspects (such as function + names and what they do). \begin{minipage}[t]{0.45\columnwidth} \begin{pyblock}[funcG1] diff --git a/research/misconceptions/preamble.tex b/research/misconceptions/preamble.tex index bf943134..3a13208b 100644 --- a/research/misconceptions/preamble.tex +++ b/research/misconceptions/preamble.tex @@ -7,6 +7,8 @@ \usepackage[all]{foreign} +\usepackage{amsfonts} + %%% PACKAGES \usepackage{booktabs} % for much better looking tables \usepackage[inline]{enumitem} From 41b985c9f7ebf6a3fb7f3d21dd0a890b25eb88ff Mon Sep 17 00:00:00 2001 From: Daniel Bosk Date: Wed, 26 Jul 2023 13:33:19 +0200 Subject: [PATCH 11/12] Minor clarification in functions-variables --- research/misconceptions/functions-variables.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/research/misconceptions/functions-variables.tex b/research/misconceptions/functions-variables.tex index d5e9d7e8..918da61e 100644 --- a/research/misconceptions/functions-variables.tex +++ b/research/misconceptions/functions-variables.tex @@ -225,7 +225,7 @@ \subsubsection{Variability of functions} The students' expectation that \(y = kx + m\) is a function \parencite{Kohn2017VariableEvaluation,Plass2015Variables,Doukakis2007} is likely due to the mathematical shorthand for \(y(x) = kx + m\), where -\enquote{\((x)\)} is dropped. +\enquote{\((x)\)} is dropped (the \enquote{equationification} of functions). Above we introduced a series of pattern showing that \mintinline{python}{y = k*x + m} is not the same as the dynamic relation in mathematics, From 9759926e6820a587845c9c2396e49df5442f6791 Mon Sep 17 00:00:00 2001 From: Daniel Bosk Date: Thu, 27 Jul 2023 21:18:01 +0200 Subject: [PATCH 12/12] Rearranges examples and adds new ones to use the space --- .../misconceptions/functions-variables.tex | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/research/misconceptions/functions-variables.tex b/research/misconceptions/functions-variables.tex index 918da61e..88b2767e 100644 --- a/research/misconceptions/functions-variables.tex +++ b/research/misconceptions/functions-variables.tex @@ -328,12 +328,51 @@ \subsubsection{Variability of functions} \printpythontex[verbatim] \end{minipage} \hfill + \begin{minipage}[t]{0.45\columnwidth} + \begin{pyblock}[funcG1] +def y(x): + return 2*x + 5 + + +y1 = y(1) +print(f"y1 = {y1}") +y2 = y(2) +print(f"y2 = {y2}") +y3 = y(5) +print(f"y3 = {y3}") + \end{pyblock} + + \vspace{0.5em} + Which yields the following: + \printpythontex[verbatim] + \end{minipage} + + We also give two versions of the greeting example. + We reuse the same variable and also vary the order of assignments and + printing: + + \begin{minipage}[t]{0.45\columnwidth} \begin{pyblock}[funcG2] def greet(name, greeting): return f"{greeting} {name}!" +msg1 = greet("Ada", "Hi") +msg2 = greet("Beda", "Hi") + +print(msg1) +print(msg2) + \end{pyblock} + \vspace{0.5em} + Which yields the following: + \printpythontex[verbatim] + \end{minipage} + \hfill + \begin{minipage}[t]{0.45\columnwidth} + \begin{pyblock}[funcG2] +def greet(name, greeting): + return f"{greeting} {name}!" msg = greet("Ada", "Hi") print(msg)