function for Akiyama–Tanigawa algorithm