Problem 1(S initial symbol, terminal symbols in bold font)
S ::= aSa | bSb |
aa | bb | a | b
S ::= a*ba*ba*
The languages generated by the two grammars are different:
the second one generates 01,
whereas the first one does not (because its shortest word has length 4).
Problem 2
fun maximize lt f (x::[]) = x
| maximize lt f (x::y::l) = if (lt (f x) (f y))
then (maximize lt f (y::l))
else (maximize lt f (x::l))
Problem 3
Type: int list list -> int list
Behavior:
On input l, it returns the list of l with the greatest length.
Type: int list -> int
Behavior:
On input l, it returns the largest element of l.
Type: int list -> int
Behavior:
On input l, it returns the element of l with the smallest square.
Type: int list list -> int list
Behavior:
On input l, it returns the list of l with the largest head.
Type: int*int list -> int*int
Behavior:
On input l, it returns the pair of l with the largest sum.