COMP280: Hw04 Q&A
Newsgroup posts re 03spring's hw01:
---------------------
> On problems that ask us to show something, can we simply show something
> by example?
>
No; showing something holds for a few particular sets may help you
understand a problem (Cf. "write test cases"),
but doesn't count as showing it for the general case (Cf. "write code...").
(It is possible to show that something is *not* true, simply
by showing a counterexample.)
Think of "show" as a weakened version of "prove" -- give some concise
reasoning why this is true in general. So you don't need to be quite
so microscopic as the proofs in lecture01 notes (as posted),
but you do need to argue both sides of an if-and-only-if.
You can use the back-of-the-book answers for other "show" problems,
as a guideline (though please add more whitespace than Rosen does
in those solutions !-)
--ian
---------------------
Note on section 1.7, #18: Show (A-B)-C = (A-C)-(B-C):
You may use the set identities from the chapter,
or (as in lecture) the fact that two sets are equal
iff they are subsets of each other.
Strive to give a clear explanation for every step you make. For example:
"x is in (A-B)-C means, x in (A-B) and x not-in C. (Def'n of set subtraction),
Further, x in (A-B) means (again by def'n of set-) that ..."
-------------------------
> Since it's been 2 years or so since I've taken Comp210, I'm a little rusty
> on my Scheme skills. ... can you direct me towards some programs in
> Scheme so I can re-familiarlize myself with the language?
>
hi jason --
(a) office hrs are a good resource;
(b) looking over lecture notes for previous comp210 can work, eg
http://www.owlnet.rice.edu/~comp210/01fall/Lectures/
(c) A quick review:
The hw answers will be similar to the already-provided code.
- use parentheses iff you want to apply a function to arguments
arguments, using prefix notation. E.g.,
(* 7 14)
applies * to 7 and 14.
- The keyword "define" is one way to define functions. E.g.
;; discriminant: number, number, number --> number
;; Return b^2-4ac, a useful quantity in highschool algebra.
;;
(define (discriminant a b c) (- (* b b) (* 4 a c)))
(This use of "define" simultaneously creates a function,
and gives it a name.)
- The keyword "lambda" creates a function (w/o giving it a name).
For example, (lambda (a b c) (- (* b b) (* 4 a c)))
is the same function as above, but we didn't associate a name with it.
This is useful when (say) having a function which returns a function.
- For structures (objects w/o methods): see lect04.shtml on
the above comp210 link. In a nutshell, using the keyword
(define-struct [structname] ([field1] [field2] ...))
automagically creates a constructor function "make-[structname]",
and selector functions "[structname]-[fieldname]".
You can look at the provided code for union and intersection,
to see how they each return a function,
and then see how that function might be applied in the body
of "element-of?", by using the first rule above.
> I am fairly
> familiar with Java and C as I just completed Comp320 and Comp212, if there
> is any way equivalent programs can be written in those languages.
(These can be done in java or c++, but it is clunky -- rather than
pass around functions, you have to define an extra class with one method
(of the desired signature), and pass around instances of that class.)