fix bugs of expand and partial trace