Functional Problem Solving (CSC 151 2014F) : EBoards

CSC151.01 2014F, Class 15: Transforming Images


Overview

Preliminaries

Admin

Upcoming Work

Extra Credit Opportunities

Academic

Peer Support

Miscellaneous

Questions on the Exam

There are some cases in the Quincunx problem in which the center seems to have a non-integer coordinate. What should I do in such cases?

Read the email.

Summary: At least two choices. You can refuse to compute. You can use a nearby pixel. Your documentation MUST specify which you've chosen.

Can you show a sample test for numerator-sum-fraction-reduced?

Yes.

    (define nsfr-tests
      (test-suite
       "Tests of numerator-sum-fraction-reduced"
       (test-case
        "1/2 plus 1/2"
        (check-= (numerator-sum-fraction-reduced 1 2 1 2) 1 0))
       (test-case
        "1/3 plus 1/2"
        (check-= (numerator-sum-fraction-reduced 1 3 1 2) 5 0))))a

How many tests is enough for that test suite?

Enough that you feel confident that a procedure that passes your tests is almost certainly correct.

About a dozen, provided they explore different potential challenges. E.g., just asking 1/2+1/3, 1/3+1/4, 1/4+1/5, .... doesn't really challenge the procedure in different ways.

Do we have to use the generalized approach that you used for problem 4, or can we just work with particular values.

I'm fine if you just work with particular values.

How carefully should I write my postconditions for problem 1?

Carefully enough that someone who wants to be lazy and just meet the postconditions will still have to achieve the goals of the procedure.

Please try to use "math" or Scheme rather than English to specify the postconditions.

You may have to refer to the results of the other procedures (but I think we noted that).

Can I define a procedure that takes an image and another value as input?

Yes.

    (define nt
      (lambda (value image)
        COMPUTATION))

    (define uniform-pixel
    (lambda (n image)
    (image-set-pixel! image n n "red")))

Can you show me how to log in to MathLAN from my computer?

Yes, but not today.

Review of Key Ideas

Topic Prep

Preliminary Questions

Can you only compose two procedures if they take the same parameters?

It's a bit more complicated than that. You can only compose two procedures if the output of one can serve as the input to the next. For example, since image-load takes a string and returns an image, and image-show takes an image (and returns an image), we can write (compose image-show image-load), but not the other way around.

Right now, we will primarily compose functions that take the same kind of input and have the same kind of output, such as color transformations.

Can we return multiple value?

After tomorrow.

Followup Questions

Talk to your partner: What, if anything, was confusing about the reading?
(Feel free to post to the question board.)

Followup Questions

Can you explain the following?

    (image-variant kitten (lambda (color) (irgb (irgb-red color) 0 0)))

How can the computer use the lambda expressions?

    (image-variant kitten (lambda (color) (irgb (irgb-red color) 0 0)))

Why does the image-variant work even though you haven't provided an input?

    (image-variant kitten irgb-redder)

Can I use the composition operator with math functions?

Yes

    (define qad (o square square))

Can I use the composition operator to write something that returns f^n(x)?

Yes, eventually.

Lab

Three approaches I've seen to undoing irgb-redder, at least for most values

(define anti-redder (o irgb-darker irgb-darker irgb-greener irgb-bluer))

(define anti-redder (o irgb-complement irgb-redder irgb-complement))

(define anti-redder (lambda (color) (irgb (- (irgb-red color) 16)
                                          (irgb-green color)
                                          (irgb-blue color))))