You could probably use the `.rewrite()` machinery for this (see core/basic.py L1552). This would require defining methods that look like `_eval_rewrite_as_*`.