Expressions with Bound Variables Quiz
1. Given that variable x has type string, write an expression to test
whether x contains any commas or semicolons.
exists c::x :- c = `,` | c = `;`
2. Given that variable s has type set of int:
- Write an expression stating that s contains at least one even
number
- Write an expression stating that for a given integer x, each element in s is either not even or
is not less than x
- Given that s contains at least one even number, write an expression to determine the lowest
even number in s
- Write an expression that yields all the even numbers in s
- Write an expression that yields the squares of all the numbers in s
- Write an expression that yields the squares of all the even numbers in
s
The following are not the only possible answers, because there are other ways of
expressing them.
- exists x::s :- x % 2 = 0
- forall y::s :- y % 2 ~= 0 | y >= x
- that x::s :- x % 2 = 0 & (forall y::s :- y % 2 ~= 0 | y >=
x)
- those x::s :- x % 2 = 0
- for x::s yield x * x
- for those x::s :- x % 2 = 0 yield x * x