forall and exists

1,301 views
Skip to first unread message

Richard Kuo

unread,
Sep 30, 2012, 12:14:57 AM9/30/12
to scala-c...@googlegroups.com

Can get some feedback?

I may use http://en.wikipedia.org/wiki/Universal_quantification and http://en.wikipedia.org/wiki/Existential_quantification#Negation for discussion, there is a set p= {23,33,55} and our nature number bound range is -1000<n<1000, we call it s.

“forall”  All the numbers in p is in bound range, s.

“exists” At least one element in the set s can satisfy one element in p. and every element in p is in s.

“map”  there is a set A {1,2,3} if f(x) = x + 5. The result of mapping is set B (6, 7, 8)

Am I correct?

Pankaj Gupta

unread,
Sep 30, 2012, 2:02:54 AM9/30/12
to scala-c...@googlegroups.com
Hi Richard,

I think you have misinterpreted the question. The set s has the property that all values in it are between -1000 and 1000 but s does not consist of all these values. s could for example be { -2, 1, 4, 5}. I just picked an example it could be any other set as long as all entries exist within bounds. p on the other hand is not a set but a condition. Although, I think p can be thought of as a set as well.


This is my interpretation of forall:
Check whether every element of s satisfies p. Since s is defined as a function from Int to Boolean the only way to find all actual values in s is to test all integers for whether they belong to s. This would be prohibitive, hence for making this check easy the problem statement reduces the bound from all integers to all integers between -1000 and 1000. So what we need to do to implement forall is to iterate over the range and test that all numbers that turn out to be in s also satisfy p.

exists: There is at least one element in p that satisfies. As the problem statement suggests this can be implements very easily using forall. 

Your interpretation of map is correct. You'll have to think functionally though since we don't know the actual elements in the set; we just know how to test whether an element belongs to set. My implementation of map is based on the exists function above. For me it helped to think this way:
An element x will exist in the mapped set if there exists an element y in the original set such that f(y) == x.

Hope that helps.

Pankaj

--
You received this message because you are subscribed to the Google Groups "Scala discussion based on Coursera" group.
To unsubscribe from this group, send email to scala-courser...@googlegroups.com.
Visit this group at http://groups.google.com/group/scala-coursera?hl=en.
 
 

Richard Kuo

unread,
Sep 30, 2012, 2:48:14 AM9/30/12
to scala-c...@googlegroups.com
Pankaj,
Thank you, I need to think more.

Richard

Richard Kuo

unread,
Sep 30, 2012, 3:12:03 AM9/30/12
to scala-c...@googlegroups.com
I think I got "forall"
-1000<n<1000 just to limit our search space.
s is a black box which contains many numbers and we do not what is in it.
p is the condition that all numbers in the box s need to satisfy.

we need to write a generic function for different p and s to work.
different p and s is in test code.

Robert Kohlenberger

unread,
Oct 4, 2012, 1:26:16 AM10/4/12
to scala-c...@googlegroups.com
Hi Richard,

Sorry I couldn't reply earlier.  Did Pankaj's response help?  Hope you're making progress!  - Bob

Richard Kuo

unread,
Oct 4, 2012, 1:43:15 AM10/4/12
to scala-c...@googlegroups.com
Bob, 
Thank you for asking. I think I understand both forall and exist to small degree to write the code. I think I have some minor mistake somewhere. If we have to chat tomorrow, I maybe able to locate the gap. I went thru all wk3 video once today. 

I learned a lot during my struggle, submitted wk2 homework and got partial credit first. write a little, test a little, build on the things passed.

richard 
Reply all
Reply to author
Forward
0 new messages