Assignment 2 - Question

38 views
Skip to first unread message

kwong ho

unread,
Oct 1, 2012, 10:03:45 AM10/1/12
to fp...@googlegroups.com
Hi All,

I have some problem on Forall and exists.

Do I understand the "forall" meaning correctly? 

ForAll
My interpretation is : "For all element in given set, they have to pass the given conditions. " => " any 1 element in the given set fail the condition is false, return false"
Forall ( given sets, condition) return true if all element 

Exists:
My interpretation is : "For any element in given set, that pass the given conditions. " => "any 1 element in the given set pass the condition is true, return true"
how do I relate to Forall

Thanks,
Kelvin

Xianming Mu

unread,
Oct 1, 2012, 10:36:16 AM10/1/12
to kwong ho, fp...@googlegroups.com
刚才可能说得不太清楚,还是用中文吧,既然是中文小组。
举个例子,“存在一个硬币是正面” 等价于 “不是所有的硬币都是反面”。 我觉得这是个关键点。

--
You received this message because you are subscribed to the Google Groups "fp-cn" group.
To post to this group, send email to fp...@googlegroups.com.
To unsubscribe from this group, send email to fp-cn+un...@googlegroups.com.
Visit this group at http://groups.google.com/group/fp-cn?hl=en.
 
 



--
Regards,

Samuel

kwong ho

unread,
Oct 1, 2012, 12:55:56 PM10/1/12
to fp...@googlegroups.com, kwong ho
謝~~ 我想我清楚 the relationship.

Forall : all element in s: Set is pass p-condition return true.  
In other words, if find 1 false, return false 
 
Exists : only 1 element in s: Set is pass the p-condition return true 
In other words, if find 1 true, return true  

the relationship of exists is flipped result and flipped condition

BZ

unread,
Oct 1, 2012, 9:09:56 PM10/1/12
to fp...@googlegroups.com, kwong ho
就是这个意思。如果你的exist()里不调用forall()会被扣分。

Leonard Siu

unread,
Oct 3, 2012, 10:54:19 AM10/3/12
to fp...@googlegroups.com
I believe your understanding is correct for both cases, however I don't think Exists is related to ForAll, at least not with my implementation. For my implementation, they both follow the same structure outline in the assignment:

def forall(s: Set, p: Int => Boolean): Boolean = {
 def iter(a: Int): Boolean = {
   if (???) ???
   else if (???) ???
   else iter(???)
 }
 iter(???)

kwong ho

unread,
Oct 3, 2012, 11:35:56 AM10/3/12
to fp...@googlegroups.com
After all the hints, I able to make a one liner of exists using forall. 

--
You received this message because you are subscribed to the Google Groups "fp-cn" group.
To post to this group, send email to fp...@googlegroups.com.
To unsubscribe from this group, send email to fp-cn+un...@googlegroups.com.
Visit this group at http://groups.google.com/group/fp-cn?hl=en.
 
 



--
Regards,
Kwong W. Ho

Xianming Mu

unread,
Oct 3, 2012, 12:53:11 PM10/3/12
to fp...@googlegroups.com
For the exists implementation, I was also inspired by some comment from the forum. I just count it as the most significante obstacle between me and full score :)
Samuel

kwong ho

unread,
Oct 3, 2012, 12:55:25 PM10/3/12
to fp...@googlegroups.com

Forall : Only all element in s: Set pass p-condition return true. || any 1 element fail p-condition, return false In other words, if find 1 false, return false

Exists : Only all element in s: Set fail the p-condition, return false || any 1 element pass the p-condition return true In other words, if find 1 true, return true

the relationship between exists and forall , flipped condition and flipped the result will be the other one

Reply all
Reply to author
Forward
0 new messages