islegal test
merge from kun
found the bug in calculate_w_first_order:
merge from Kun