refactor(library/logic/cast): define heq using inductive datatypes

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>