Optimize isPattern, isVariable
Implement appTree <-> stack conversions; sketch affineReduce