Encode subformulaes as tree