Add test for is_referenced_before
Implement is_referenced_before predicate