add bernstein algorithm