#NEWLINE# def decompose( self ) : #NEWLINE# #INDENT# 'Decomposes IQFT into elementary gates.' #NEWLINE# start = self . args [ 0 ] #NEWLINE# finish = self . args [ 1 ] #NEWLINE# circuit = 1 #NEWLINE# for i in range ( ( ( finish - start ) // 2 ) ) : #NEWLINE# #INDENT# circuit = ( SwapGate ( ( i + start ) , ( ( finish - i ) - 1 ) ) * circuit ) #NEWLINE# #UNINDENT# for level in range ( start , finish ) : #NEWLINE# #INDENT# for i in reversed ( range ( ( level - start ) ) ) : #NEWLINE# #INDENT# circuit = ( CGate ( ( ( level - i ) - 1 ) , RkGate ( level , ( ( - i ) - 2 ) ) ) * circuit ) #NEWLINE# #UNINDENT# circuit = ( HadamardGate ( level ) * circuit ) #NEWLINE# #UNINDENT# return circuit