#NEWLINE# def test_wicks( ) : #NEWLINE# #INDENT# ( p , q , r , s ) = symbols ( 'p,q,r,s' , above_fermi = True ) #NEWLINE# str = ( F ( p ) * Fd ( q ) ) #NEWLINE# assert ( wicks ( str ) == ( NO ( ( F ( p ) * Fd ( q ) ) ) + KroneckerDelta ( p , q ) ) ) #NEWLINE# str = ( Fd ( p ) * F ( q ) ) #NEWLINE# assert ( wicks ( str ) == NO ( ( Fd ( p ) * F ( q ) ) ) ) #NEWLINE# str = ( ( ( F ( p ) * Fd ( q ) ) * F ( r ) ) * Fd ( s ) ) #NEWLINE# nstr = wicks ( str ) #NEWLINE# fasit = NO ( ( ( ( ( ( KroneckerDelta ( p , q ) * KroneckerDelta ( r , s ) ) + ( ( KroneckerDelta ( p , q ) * AnnihilateFermion ( r ) ) * CreateFermion ( s ) ) ) + ( ( KroneckerDelta ( r , s ) * AnnihilateFermion ( p ) ) * CreateFermion ( q ) ) ) - ( ( KroneckerDelta ( p , s ) * AnnihilateFermion ( r ) ) * CreateFermion ( q ) ) ) - ( ( ( AnnihilateFermion ( p ) * AnnihilateFermion ( r ) ) * CreateFermion ( q ) ) * CreateFermion ( s ) ) ) ) #NEWLINE# assert ( nstr == fasit ) #NEWLINE# assert ( ( ( p * q ) * nstr ) . expand ( ) == wicks ( ( ( p * q ) * str ) ) ) #NEWLINE# assert ( ( ( ( nstr * p ) * q ) * 2 ) . expand ( ) == wicks ( ( ( ( str * p ) * q ) * 2 ) ) ) #NEWLINE# ( i , j , k , l ) = symbols ( 'i j k l' , below_fermi = True , cls = Dummy ) #NEWLINE# ( a , b , c , d ) = symbols ( 'a b c d' , above_fermi = True , cls = Dummy ) #NEWLINE# ( p , q , r , s ) = symbols ( 'p q r s' , cls = Dummy ) #NEWLINE# assert ( wicks ( ( ( F ( a ) * NO ( ( F ( i ) * F ( j ) ) ) ) * Fd ( b ) ) ) == ( NO ( ( ( ( F ( a ) * F ( i ) ) * F ( j ) ) * Fd ( b ) ) ) + ( KroneckerDelta ( a , b ) * NO ( ( F ( i ) * F ( j ) ) ) ) ) ) #NEWLINE# assert ( wicks ( ( ( F ( a ) * NO ( ( ( F ( i ) * F ( j ) ) * F ( k ) ) ) ) * Fd ( b ) ) ) == ( NO ( ( ( ( ( F ( a ) * F ( i ) ) * F ( j ) ) * F ( k ) ) * Fd ( b ) ) ) - ( KroneckerDelta ( a , b ) * NO ( ( ( F ( i ) * F ( j ) ) * F ( k ) ) ) ) ) ) #NEWLINE# expr = wicks ( ( ( Fd ( i ) * NO ( ( Fd ( j ) * F ( k ) ) ) ) * F ( l ) ) ) #NEWLINE# assert ( expr == ( ( ( ( ( ( - KroneckerDelta ( i , k ) ) * NO ( ( Fd ( j ) * F ( l ) ) ) ) - ( KroneckerDelta ( j , l ) * NO ( ( Fd ( i ) * F ( k ) ) ) ) ) - ( KroneckerDelta ( i , k ) * KroneckerDelta ( j , l ) ) ) + ( KroneckerDelta ( i , l ) * NO ( ( Fd ( j ) * F ( k ) ) ) ) ) + NO ( ( ( ( Fd ( i ) * Fd ( j ) ) * F ( k ) ) * F ( l ) ) ) ) ) #NEWLINE# expr = wicks ( ( ( F ( a ) * NO ( ( F ( b ) * Fd ( c ) ) ) ) * Fd ( d ) ) ) #NEWLINE# assert ( expr == ( ( ( ( ( ( - KroneckerDelta ( a , c ) ) * NO ( ( F ( b ) * Fd ( d ) ) ) ) - ( KroneckerDelta ( b , d ) * NO ( ( F ( a ) * Fd ( c ) ) ) ) ) - ( KroneckerDelta ( a , c ) * KroneckerDelta ( b , d ) ) ) + ( KroneckerDelta ( a , d ) * NO ( ( F ( b ) * Fd ( c ) ) ) ) ) + NO ( ( ( ( F ( a ) * F ( b ) ) * Fd ( c ) ) * Fd ( d ) ) ) ) )