I would suggest using verbose_pre_order_iter in contains , and returning a vector of left/right decisions which you can pop every time you hit a BasePattern::Product in this loop. I'd also make contains non-public or rename it to reflect the richer return value.
BasePattern::get has O(n^2) asymptotics although there exists an O(n) algorithm.
https://github.com/BlockstreamResearch/simfony/pull/38#discussion_r1616353544