Common sub-expression sharing for term representation