def _reduce_order(ap, bq, gen, key):
 ap = list(ap)
 bq = list(bq)
 ap.sort(key=key)
 bq.sort(key=key)
 nap = []
 operators = []
 for a in ap:
  op = None
  for i in range(len(bq)):
   op = gen(a, bq[i])
   if (op is not None):
    bq.pop(i)
    break
  if (op is None):
   nap.append(a)
  else:
   operators.append(op)
 return (nap, bq, operators)

def _reduce_order ( ap , bq , gen , key ) : ap = list ( ap ) bq = list ( bq ) ap . sort ( key = key ) bq . sort ( key = key ) nap = [ ] operators = [ ] for a in ap : op = None for i in range ( len ( bq ) ) : op = gen ( a , bq [ i ] ) if ( op is not None ) : bq . pop ( i ) break if ( op is None ) : nap . append ( a ) else : operators . append ( op ) return ( nap , bq , operators )
order reduction algorithm used in hypergeometric and meijer g .