dasickis

05-10-2007, 06:55 AM

I was wondering how I should write this expression parsing function:

I'm trying to create a new operator (→) that outputs:

P Q P->Q

T T T

T F F

F T T

F F T

As you may have guessed the logic is (P==Q)||Q

Another operator I'm trying to create is (↔) that outputs

P Q P->Q

T T T

T F F

F T F

F F T

As you may have guessed the logic is (P==Q)||Q

The logic here is P==Q[/CODE]

Additionally, I need to parse logical quantifiers so that:

∃x becomes names.some(function(x){...})

∀x becomes names.every(function(x){...})

For example:

∃x Dodec(x) becomes names.some(function(x){return Dodec(x)})

∃x ∃y Smaller(x,y) becomes names.some(function(x){names.some(function(y){return Smaller(x,y)})})

∃x ∃y ∀z Between(x,y,z) becomes names.some(function(x){names.some(function(y)names.some(function(x){names.some(function(z){return Between(x,y,z)})})})

For a well formed logical statement, a person needs to properly parenthesize the statement.

Valid examples:

(Dodec(a)→Dodec(b))→Dodec(c)

∃x(Dodec(x) && ∃y Smaller(x,y))

Invalid Examples:

Dodec(a)→Dodec(b)→Dodec(c)

∃x Dodec(x) && ∃ySmaller(x,y) [Valid: ∃x Dodec(x) && ∃x∃ySmaller(x,y), the quantifier does not carry through]

For more information on logic:http://en.wikipedia.org/wiki/Predicate_logic

I'm trying to create a new operator (→) that outputs:

P Q P->Q

T T T

T F F

F T T

F F T

As you may have guessed the logic is (P==Q)||Q

Another operator I'm trying to create is (↔) that outputs

P Q P->Q

T T T

T F F

F T F

F F T

As you may have guessed the logic is (P==Q)||Q

The logic here is P==Q[/CODE]

Additionally, I need to parse logical quantifiers so that:

∃x becomes names.some(function(x){...})

∀x becomes names.every(function(x){...})

For example:

∃x Dodec(x) becomes names.some(function(x){return Dodec(x)})

∃x ∃y Smaller(x,y) becomes names.some(function(x){names.some(function(y){return Smaller(x,y)})})

∃x ∃y ∀z Between(x,y,z) becomes names.some(function(x){names.some(function(y)names.some(function(x){names.some(function(z){return Between(x,y,z)})})})

For a well formed logical statement, a person needs to properly parenthesize the statement.

Valid examples:

(Dodec(a)→Dodec(b))→Dodec(c)

∃x(Dodec(x) && ∃y Smaller(x,y))

Invalid Examples:

Dodec(a)→Dodec(b)→Dodec(c)

∃x Dodec(x) && ∃ySmaller(x,y) [Valid: ∃x Dodec(x) && ∃x∃ySmaller(x,y), the quantifier does not carry through]

For more information on logic:http://en.wikipedia.org/wiki/Predicate_logic