A framework for fast quantum mechanical algorithms