Live data from Hacker News

Conversations with a six-year-old on functional programming (2018)

byorgey.wordpress.com

51–60 of 161 posts

Re: Conversations with a six-year-old on functional programming (2018)

#51
post #25
post #22

What's the optimal strategy for choosing inputs in order to guess the nature of the machine?

I don't think that this problem is even computable, since the functions could be arbitrarily complex. If you restrict the nature of the functions e.g. "polynomials of degree at most d", then the answer depends on the restriction. For the polynomial of degree <= d case the solution is d+1 inputs, every polynomial of degree at most d is uniquely determined by d+1 points.

Sure, but it's bounded by human creativity, and there's anyway a difference between reliably and deterministically computing the function, and a sort of approximation with repeated guesses, or reaching a certain confidence.

I only have vague recollections of numerical analysis, I remembered the Newton-Raphson method (no good: we don't have an oracle for f'(x), just f(x)) and stumbled into the Runge-Kutta Wikipedia page which I'd forgotten about (also no good).

But it seems like a good strategy would be to test one number, guess assuming constant, test a second, guess assuming linear, test a third, guess assuming first order polynomial, and so on.

In the presence of step changes or the like though I suppose there's nothing you can do.

Re: Conversations with a six-year-old on functional programming (2018)

#52
This kid is going to be so much better of in life in a STEM field than his peers without a parent who teaches functional programming/theory courses and as one that takes an interest in their children (which I am sure most, of not all, parents do). I say this because reading the story helped me see that I should do this when I have kids: expose them early on to what I’m doing and help them get ahead anyway I can (if they so choose a STEM aligned career they’ll be advantaged some) but also wishing I had parents that finished college so they could do this for me. They didn’t and I made it out okay so I’ll just better the next generation where I can. What a cool post. And that kid sounds really smart. I bet he’s going to go on to do big things.

Re: Conversations with a six-year-old on functional programming (2018)

#53

I find kids understand the concept of functions really intuitively if it is stated simply - input -> func -> output, it doesn't have to be difficult maths, and it can make for some great games. It looks a little intimidating if using the notation in this article but they easily grasp that a function transforms inputs and returns outputs, and it can be a fun introduction to maths and programming, and then later to thi…

Agreed! My kids are slightly older but we've long enjoyed a roadtrip game that's a variation on 20 questions: "give me an input, I'll respond with an output, then you guess what the 'machine' [algorithm|function] did". They'd get to provide one input, I'd respond w one output, then they'd get one chance to define the operation -- to which I'd respond only yes or no -- before the next person's turn to test it. Whoever…

This reminds me of a prediction game experiment I heard that was described like the following. \*

The researchers presented the following to people.

   f(1) = true
   f(2) = true
   f(4) = true
   f(8) = true
And asked, what is f?

And the people will immediately jump in and test 16, 32, and then proudly declare that

   f = x -> x = 2^n for some integer n
Forgetting to test f(3), f(5), etc.

With more examination it turns out that

   f = x -> true.
\* I wish I could remember more of the details such as whether it was an experiment or just an illustration of one but it's not an easy thing to search for and I rely on memory and searching too much.

Re: Conversations with a six-year-old on functional programming (2018)

#54

Earlier quoted context omitted.

Agreed! My kids are slightly older but we've long enjoyed a roadtrip game that's a variation on 20 questions: "give me an input, I'll respond with an output, then you guess what the 'machine' [algorithm|function] did". They'd get to provide one input, I'd respond w one output, then they'd get one chance to define the operation -- to which I'd respond only yes or no -- before the next person's turn to test it. Whoever…

I taught at a programming camp one summer, and my favourite example of this that I drove several kids crazy with was "above the line, below the line". Given any input word, I would tell them whether it was above the line, or below the line (which corresponded to acceptable and unacceptable behaviour in camp-speak). I think only two kids figured it out on their own, and each time I challenged them to write a program t…

    let descenders = ['q','y','g','p','j'];
    let isBelow = (word) => descenders.some(d => word.includes(d));

    let tests = {
      "Hacker" : false,
      "News" : false,
      "chrisweekly" : true,
      "programming" : true,
    };
    
    for (const test in tests) {
      let pass = isBelow(test) == tests[test];
      console.log( pass ? `Passed for ${test}` : `Failed for ${test}` );
    }

Re: Conversations with a six-year-old on functional programming (2018)

#55
post #25
post #22

What's the optimal strategy for choosing inputs in order to guess the nature of the machine?

I don't think that this problem is even computable, since the functions could be arbitrarily complex. If you restrict the nature of the functions e.g. "polynomials of degree at most d", then the answer depends on the restriction. For the polynomial of degree <= d case the solution is d+1 inputs, every polynomial of degree at most d is uniquely determined by d+1 points.

If the functions are restricted to polynomials with non-negative integer coefficients, you only need 2 inputs regardless of degree. Proof left as an exercise to the reader.

Re: Conversations with a six-year-old on functional programming (2018)

#57

Earlier quoted context omitted.

Agreed! My kids are slightly older but we've long enjoyed a roadtrip game that's a variation on 20 questions: "give me an input, I'll respond with an output, then you guess what the 'machine' [algorithm|function] did". They'd get to provide one input, I'd respond w one output, then they'd get one chance to define the operation -- to which I'd respond only yes or no -- before the next person's turn to test it. Whoever…

I taught at a programming camp one summer, and my favourite example of this that I drove several kids crazy with was "above the line, below the line". Given any input word, I would tell them whether it was above the line, or below the line (which corresponded to acceptable and unacceptable behaviour in camp-speak). I think only two kids figured it out on their own, and each time I challenged them to write a program t…

[deleted]

Re: Conversations with a six-year-old on functional programming (2018)

#58
post #47

"He gasped in astonishment at the idea of putting function machines into function machines" "He gasped in astonishment as I carefully explained the results of the double-slit experiment." Surely more like that this describes a 6yo kid being excited about something their parent is excited about and a product of implicit empathy, than any significant insight? I hate to lose reputation with downvotes for sounding negati…

Wait, how do you get from function spaces to the double-slit experiment? Or is it just for illustration of two moments...

With regards to your message, I think it's impossible to say whether another person understands something well from reaction. Unfortunately, that is why student focused textbooks (vs. graduate textbooks) usually have a lot of exercises.

Edit: By the way, on a somewhat unrelated topic, I have been told that Lawvere thought that set theory was a "historical error" (these kind of semi-biographical stories are code for trying to explain a mathematician's personality, a futile exercise). I wonder if I'll ever be able to meet him and ask him why he thinks that. (I suspect that it will lead to some Lisptopians becoming excited about objects being immaterial. At which point one should remind Lisptopians not to mix programming the activity with mathematics the activity.) It's ironic that set theory is the best way to learn category theory, at which point you to some extent abandon set theory. Maybe it's the pedagicical value of set theory? I wonder if Lawvere would take all my persistent questions kindly.

Re: Conversations with a six-year-old on functional programming (2018)

#59

I find kids understand the concept of functions really intuitively if it is stated simply - input -> func -> output, it doesn't have to be difficult maths, and it can make for some great games. It looks a little intimidating if using the notation in this article but they easily grasp that a function transforms inputs and returns outputs, and it can be a fun introduction to maths and programming, and then later to thi…

For what it's worth, this intuition is sound and I think it works just as well if you formalize[1] it to be used to illustrate the lambda calculus.

[1] http://dkeenan.com/Lambda/

Re: Conversations with a six-year-old on functional programming (2018)

#60
The most key point of this is right at the start:

"I decided to just answer straightforwardly"

That can make all the difference in your interactions with your child and how they learn about this world.

Too many problems are caused by parents not being honest with their kids. Be straightforward, no matter how awkward the explanations may be. Avoid patronizing simplifications and saying things like "you'll understand when you're older". If they're not able to understand or decide they don't want to, they'll stop asking.

and also one of the best ways of improving your own understanding of something is to try explaining it to someone else, and who better than a child? If they say some tradition is stupid or silly, maybe it is! If you can't defend it to them, why do you follow it?

Who knows, maybe you'll even make an unexpected friend to share your interests with. :)

Post reply on HN