Re: [Edu-sig] CTL: Computer Thinking Language
At 10:00 AM 3/2/2009 -0800, michel paul wrote:
Before I discovered Python a couple of years ago I was experimenting with a pseudo-code approach for expressing math concepts. I had this kind of stuff in mind:
factorial(n): if n < 2 ---> 1 else ---> n*factorial(n-1)
I like the feeling of action in --->, but I also like the self-explanatory "return". Any other suggestions? Strong preferences? We could use a symbol other than = for assignment, just to avoid confusion with the comparison operator and to introduce the idea of variables as labels, not containers. How about: a2 --> a**2 a --> b --> c --> 0 A simple demo:
c --> 1 # move label c, not a or b a,b,c (0, 0, 1)
I think some kind of a CTL approach would be especially good for a math curriculum. Maybe instead of 'Computer' TL, call it 'Computational' TL.
Good point. That was actually the choice in Fletcher's article. Kids will probably shorten it to computer, however.
It's what algebra should be these days. And if your CTL also RUNS, well, so much the better.
Most students, and probably most people, would read "2 + 2" as "2 plus 2", but notice how much more mathematically and computationally effective it would be if they could develop the habit of reading or thinking of "2 + 2" as "the sum of 2 and 2" or "sum(2, 2)". Think of the whole, the resulting value.
And how about "2 + 3 * 4"? Again, the typical reading would be "2 plus 3 times 4", and that's ambiguous, and so in math classes we have to talk about 'order of operations', and usually the only justification we give for 'order of operations' is that we have to have some kind of social agreements in place in order to avoid confusion. Right?
However, it is again more mathematically effective to read "2 + 3 * 4" as "the sum of 2 and the product of 3 and 4", or, sum(2, product(3, 4)). No ambiguity there! And this is how you have to think when you hook chains of functions together. This kind of stuff could be done very early in the curriculum. Doesn't have to wait for either advanced math classes or computer science.
It would be nice to avoid in CTL the complexities of precedence and associativity rules (very non-fundamental knowledge). How about we just do all operations in the order they occur, unless you force a different order with parens. 2 + 3 * 4 same as (2 + 3) * 4 2 + 3 * 4 ** 5 same as ((2 + 3) * 4) ** 5 On the other hand, we don't want to teach something students have to unlearn when they get to a real language. Since CTL is for CS0-level students, we should discourage complex expressions that rely on these rules, and not drill or test students on this particular choice. It's just there to make things easy for beginners.
Math teachers often forget, or are unaware, that the ordinary arithmetic operators are themselves functions. I think it would be good for math classes to explore this kind of functional composition for very simple ideas.
By the way, we started studying sequences today in class. What's a really good Pythonic tool for studying sequences ---> generators!
Should we include generators in CTL? Seems like students at this level should have graduated to a full-featured language. Might be fun just as an intellectual exercise to play around with an "advanced CTL". I've got some ideas for unifying all methods (class, static, normal) into one simple syntax, identical to functions. Here's what I have so far. Shall I put this up on a wiki, so we can all hack at it? === CTL Syntax === # operators & expressions 2 + 3 * 4 same as (2 + 3) * 4 2 + 3 * 4 ** 5 same as ((2 + 3) * 4) ** 5 # variables as labels applied to objects a2 --> a**2 a --> b --> c --> 0 # built in functions min(), max(), sum(), and sqrt() # custom functions f(a,b): (a+b)/2 f(a,b): (a+b)/(2*pi) # with an "outside" variable # functions with multiple statements f(a,b): a2 = a**2; b2 = b**2; return (a2 + b2)/2 # same but more readable f(a,b): a2 = a**2 b2 = b**2 return (a2 + b2)/2 # function returning a tuple (sneaky introduction to objects) f(a,b): (a, (a+b)/2, b)
f(2,4) (2, 3.0, 4)
# logic < <= == >= > != if elif else if a<b,(b-a); else (a-b) # control flow with multiple statements f(a,b): if a<(b-5), return a; if (b-5)<=a<=(b+5), return (a+b)/2; return b # recursion f(a,b): if a<b, f(a, b-a); elif b<a, f(a-b, b); else (a,b) factorial(n): if n < 2 ---> 1 else ---> n*factorial(n-1) ************************************************************ * * David MacQuigg, PhD email: macquigg at ece.arizona.edu * * * Research Associate phone: USA 520-721-4583 * * * * ECE Department, University of Arizona * * * * 9320 East Mikelyn Lane * * * * http://purl.net/macquigg Tucson, Arizona 85710 * ************************************************************ *
On Tue, Mar 3, 2009 at 2:27 PM, David MacQuigg <macquigg@ece.arizona.edu>wrote:
At 10:00 AM 3/2/2009 -0800, michel paul wrote:
Before I discovered Python a couple of years ago I was experimenting with a pseudo-code approach for expressing math concepts. I had this kind of stuff in mind:
factorial(n): if n < 2 ---> 1 else ---> n*factorial(n-1)
I like the feeling of action in --->, but I also like the self-explanatory "return". Any other suggestions? Strong preferences?
Oh no, not at all. My only point in even bringing this up was that I had been trying to formulate something like a CTL awhile ago, and then I discovered Python. Wow! What I found so delightful is that the kind of pseudo-code I was contemplating looked a whole lot like Python! I thought that was a really good sign. Yeah, Python is pseudo-code that runs! It already is a CTL. I think the most useful CTL for integration in math education should be as close to ordinary algebra as possible. That's what I had been trying to get at. Kids in algebra classes initially get confused by this 'return'. It doesn't look like what they usually see in math. So I thought an arrow might correspond to mapping notation for functions: f: x ---> y vs. Euler notation: f(x) = y. So that's why I originally opted for the arrow. However, once they've had even a little experience, the use of 'return' isn't all that strange to them. And then, the other day when I had them create generators for their HW assignment on sequences, wow! I was really pleased that they got the idea that 'yield' just meant that the function was on hold until called again. They seemed OK with that.
It would be nice to avoid in CTL the complexities of precedence and associativity rules (very non-fundamental knowledge). How about we just do all operations in the order they occur, unless you force a different order with parens.
In terms of integration into math classes, I think it would be better to maintain the traditional order of operations. (I realize here that I'm emphasizing math/CS fusion at a secondary level, and you're talking about CS0.) But using parentheses to clarify order - definitely! And then from there, it's easy to create functional compositions. Now, I wouldn't emphasize functional composition for ALL simple arithmetic expressions - that would just be silly. But I think doing that is an excellent kind of exercise. And then beyond that - turn the functional compositions into binary expression trees! I've had kids do that in math classes as exercises in order of operations. Take a typical arithmetic expression that has several things going on and turn it into a binary expression tree.
By the way, we started studying sequences today in class. What's a really good Pythonic tool for studying sequences ---> generators!
Should we include generators in CTL? Seems like students at this level should have graduated to a full-featured language.
Right, I'm not sure generators would need to be in a CTL. Again, in terms of math education, I would see the role of a CTL simply as providing a bridge between traditional static algebra and a more dynamic computational algebra. Since Python is already so close to a CTL, by the time we started including generators, we might as well just be using Python.
# function returning a tuple (sneaky introduction to objects) f(a,b): (a, (a+b)/2, b)
Yes, tuples as proto-objects! I've thought about that a lot. I think that would be very practical in the math curriculum. Tuples, ordered lists, can very easily represent all kinds of mathematical objects. I think a good computational math route starting in traditional algebra would be to develop the idea of tuples as representing various kinds of mathematical objects and to write functions that operate on these tuples and then to integrate this functionality into the 'tuples' themselves. - Michel
participants (2)
-
David MacQuigg -
michel paul