move ap funtion from function.py'' to ap.py''