def sub_pre(e):
 reps = [a for a in e.atoms(Add) if a.could_extract_minus_sign()]
 reps.sort(key=default_sort_key)
 e = e.xreplace(dict(((a, Mul._from_args([S.NegativeOne, (- a)])) for a in reps)))
 if isinstance(e, Basic):
  negs = {}
  for a in sorted(e.atoms(Add), key=default_sort_key):
   if ((a in reps) or a.could_extract_minus_sign()):
    negs[a] = Mul._from_args([S.One, S.NegativeOne, (- a)])
  e = e.xreplace(negs)
 return e

def sub_pre ( e ) : reps = [ a for a in e . atoms ( Add ) if a . could_extract_minus_sign ( ) ] reps . sort ( key = default_sort_key ) e = e . xreplace ( dict ( ( ( a , Mul . _from_args ( [ S . NegativeOne , ( - a ) ] ) ) for a in reps ) ) ) if isinstance ( e , Basic ) : negs = { } for a in sorted ( e . atoms ( Add ) , key = default_sort_key ) : if ( ( a in reps ) or a . could_extract_minus_sign ( ) ) : negs [ a ] = Mul . _from_args ( [ S . One , S . NegativeOne , ( - a ) ] ) e = e . xreplace ( negs ) return e
replace y - x with - if -1 can be extracted from y - x .