Serialization of predicates

Fixes #1062