factor out derive_rule_s