A community for students. Sign up today!
Here's the question you clicked on:
 0 viewing
 2 years ago
Ex1.3 in SICP: We're supposed to define a procedure that takes three numbers as arguments and returns the sum of the squares of the two larger numbers. How do you treat the case {0,0,1}? In that case there _aren't_ two larger numbers. If you tried this question did you have to make (unjustified?) assumptions? Thanks.
 2 years ago
Ex1.3 in SICP: We're supposed to define a procedure that takes three numbers as arguments and returns the sum of the squares of the two larger numbers. How do you treat the case {0,0,1}? In that case there _aren't_ two larger numbers. If you tried this question did you have to make (unjustified?) assumptions? Thanks.

This Question is Closed

azka.niazi
 2 years ago
Best ResponseYou've already chosen the best response.1If your algorithm works perfectly for all inputs, then giving 0,0 and 1 as arguments must give you the answer: \[0^{2}+1^{1}\] There could be another way to debate about the correctness of the answers. Logically speaking, the two numbers which the program picks as the greater two should, at least, not be less than the third number (whose square hasn't been included in answer). Because when it comes to equality, whatever you pick, it doesn't really matter. That should be natural assumption I believe. Although mathematically speaking, if a number x is not greater than y, then it can be either equal to y or less than it. So, the equality x=y is included in negation of x>y. But in the end, i would close my answer on a pretty satisfying statement: Our program has to give us an answer. It has to use the highest two values it has to give an answer i.e. do the best with whatever it has got. So what are its highest two numbers, the sum of the squares of those two will be our answer. No real need to make an additional assumption. Hope that answers your question!

azka.niazi
 2 years ago
Best ResponseYou've already chosen the best response.1sorry, thats \[0^{2}+1^{2}\]

benjaminf
 2 years ago
Best ResponseYou've already chosen the best response.0Okay, you're right. But just to be annoying about it...what if the purpose of this excise was to start building a program that would help you choose the shortest traveling distance between two islands (via other islands.) Then it's not just a matter of what the sumofsquares value is, but also how you got it, i.e. which numbers (directional parameters) you chose. At least, that what it seems like to me! but I'll be using your interpretation, so thank you.

azka.niazi
 2 years ago
Best ResponseYou've already chosen the best response.1Well, it is not annoying actually. Answering questions has its own pleasure. I must admit some confusion about this shortest distance thing you mentioned. Not that I don't understand the problem, but because the nature of the problem seems very different to me. Ex 1.3 is a far simpler problem (it is chapter 1 after all!). Other than that shortest distance problem is quantified in terms of numerical values which is the sum of all the distances it has to cover over a path. The least sum out of all possible paths will be the answer. I think you are worried about how to keep track of the path itself (which has the shortest distance). There are algorithms for that too  Googleing might help. But more important are the Data Structures which are used to represent maps/graphs. Anyway, the book, in a later chapter, does talk about trees and graphs. p.s. you're welcome! :)

benjaminf
 2 years ago
Best ResponseYou've already chosen the best response.0I thought the distance example would be handy to show that (0,0,1) and (0,1,0) are different, maybe not when you're calculating the sum of squares, but definitely when you have to make a choice between them. But that, like you said, is a different kind of problem. Instead, the exercise just asks for the sum of squares of the two larger numbers. You rightly point out that it doesn't matter which {0} I pick, the answer is the same, and I went with that for my solution. But I think it's also valid to say that in a case where there _aren't_ two larger numbers it's _not possible_ to return the sumofsquares for two larger numbers and returning some version NOT DEFINED might also be okay.

azka.niazi
 2 years ago
Best ResponseYou've already chosen the best response.1yes you're absolutely right. i have no reason to disagree.
Ask your own question
Ask a QuestionFind more explanations on OpenStudy
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.