extract_terms function

Extract and format terms from solutions