<s> from sympy . core . function import Derivative <EOL> from sympy . vector . vector import Vector <EOL> from sympy . vector . coordsysrect import CoordSysCartesian <EOL> from sympy . simplify import simplify <EOL> from sympy . core . symbol import symbols <EOL> from sympy . core import S <EOL> from sympy import sin , cos <EOL> from sympy . vector . functions import ( curl , divergence , gradient , <EOL> is_conservative , is_solenoidal , <EOL> scalar_potential , <EOL> scalar_potential_difference ) <EOL> from sympy . utilities . pytest import raises <EOL> C = CoordSysCartesian ( '<STR_LIT:C>' ) <EOL> i , j , k = C . base_vectors ( ) <EOL> x , y , z = C . base_scalars ( ) <EOL> delop = C . delop <EOL> a , b , c , q = symbols ( '<STR_LIT>' ) <EOL> def test_del_operator ( ) : <EOL> assert ( delop ^ Vector . zero == <EOL> ( Derivative ( <NUM_LIT:0> , C . y ) - Derivative ( <NUM_LIT:0> , C . z ) ) * C . i + <EOL> ( - Derivative ( <NUM_LIT:0> , C . x ) + Derivative ( <NUM_LIT:0> , C . z ) ) * C . j + <EOL> ( Derivative ( <NUM_LIT:0> , C . x ) - Derivative ( <NUM_LIT:0> , C . y ) ) * C . k ) <EOL> assert ( ( delop ^ Vector . zero ) . doit ( ) == Vector . zero == <EOL> curl ( Vector . zero , C ) ) <EOL> assert delop . cross ( Vector . zero ) == delop ^ Vector . zero <EOL> assert ( delop ^ i ) . doit ( ) == Vector . zero <EOL> assert delop . cross ( <NUM_LIT:2> * y ** <NUM_LIT:2> * j , doit = True ) == Vector . zero <EOL> assert delop . cross ( <NUM_LIT:2> * y ** <NUM_LIT:2> * j ) == delop ^ <NUM_LIT:2> * y ** <NUM_LIT:2> * j <EOL> v = x * y * z * ( i + j + k ) <EOL> assert ( ( delop ^ v ) . doit ( ) == <EOL> ( - x * y + x * z ) * i + ( x * y - y * z ) * j + ( - x * z + y * z ) * k == <EOL> curl ( v , C ) ) <EOL> assert delop ^ v == delop . cross ( v ) <EOL> assert ( delop . cross ( <NUM_LIT:2> * x ** <NUM_LIT:2> * j ) == <EOL> ( Derivative ( <NUM_LIT:0> , C . y ) - Derivative ( <NUM_LIT:2> * C . x ** <NUM_LIT:2> , C . z ) ) * C . i + <EOL> ( - Derivative ( <NUM_LIT:0> , C . x ) + Derivative ( <NUM_LIT:0> , C . z ) ) * C . j + <EOL> ( - Derivative ( <NUM_LIT:0> , C . y ) + Derivative ( <NUM_LIT:2> * C . x ** <NUM_LIT:2> , C . x ) ) * C . k ) <EOL> assert ( delop . cross ( <NUM_LIT:2> * x ** <NUM_LIT:2> * j , doit = True ) == <NUM_LIT:4> * x * k == <EOL> curl ( <NUM_LIT:2> * x ** <NUM_LIT:2> * j , C ) ) <EOL> assert delop & Vector . zero == S ( <NUM_LIT:0> ) == divergence ( Vector . zero , C ) <EOL> assert ( delop & Vector . zero ) . doit ( ) == S ( <NUM_LIT:0> ) <EOL> assert delop . dot ( Vector . zero ) == delop & Vector . zero <EOL> assert ( delop & i ) . doit ( ) == S ( <NUM_LIT:0> ) <EOL> assert ( delop & x ** <NUM_LIT:2> * i ) . doit ( ) == <NUM_LIT:2> * x == divergence ( x ** <NUM_LIT:2> * i , C ) <EOL> assert ( delop . dot ( v , doit = True ) == x * y + y * z + z * x == <EOL> divergence ( v , C ) ) <EOL> assert delop & v == delop . dot ( v ) <EOL> assert delop . dot ( <NUM_LIT:1> / ( x * y * z ) * ( i + j + k ) , doit = True ) == - <NUM_LIT:1> / ( x * y * z ** <NUM_LIT:2> ) - <NUM_LIT:1> / ( x * y ** <NUM_LIT:2> * z ) - <NUM_LIT:1> / ( x ** <NUM_LIT:2> * y * z ) <EOL> v = x * i + y * j + z * k <EOL> assert ( delop & v == Derivative ( C . x , C . x ) + <EOL> Derivative ( C . y , C . y ) + Derivative ( C . z , C . z ) ) <EOL> assert delop . dot ( v , doit = True ) == <NUM_LIT:3> == divergence ( v , C ) <EOL> assert delop & v == delop . dot ( v ) <EOL> assert simplify ( ( delop & v ) . doit ( ) ) == <NUM_LIT:3> <EOL> assert ( delop . gradient ( <NUM_LIT:0> , doit = True ) == Vector . zero == <EOL> gradient ( <NUM_LIT:0> , C ) ) <EOL> assert delop . gradient ( <NUM_LIT:0> ) == delop ( <NUM_LIT:0> ) <EOL> assert ( delop ( S ( <NUM_LIT:0> ) ) ) . doit ( ) == Vector . zero <EOL> assert ( delop ( x ) == ( Derivative ( C . x , C . x ) ) * C . i + <EOL> ( Derivative ( C . x , C . y ) ) * C . j + ( Derivative ( C . x , C . z ) ) * C . k ) <EOL> assert ( delop ( x ) ) . doit ( ) == i == gradient ( x , C ) <EOL> assert ( delop ( x * y * z ) == <EOL> ( Derivative ( C . x * C . y * C . z , C . x ) ) * C . i + <EOL> ( Derivative ( C . x * C . y * C . z , C . y ) ) * C . j + <EOL> ( Derivative ( C . x * C . y * C . z , C . z ) ) * C . k ) <EOL> assert ( delop . gradient ( x * y * z , doit = True ) == <EOL> y * z * i + z * x * j + x * y * k == <EOL> gradient ( x * y * z , C ) ) <EOL> assert delop ( x * y * z ) == delop . gradient ( x * y * z ) <EOL> assert ( delop ( <NUM_LIT:2> * x ** <NUM_LIT:2> ) ) . doit ( ) == <NUM_LIT:4> * x * i <EOL> assert ( ( delop ( a * sin ( y ) / x ) ) . doit ( ) == <EOL> - a * sin ( y ) / x ** <NUM_LIT:2> * i + a * cos ( y ) / x * j ) <EOL> assert ( Vector . zero & delop ) ( a ) == S ( <NUM_LIT:0> ) <EOL> assert ( ( Vector . zero & delop ) ( a ) ) . doit ( ) == S ( <NUM_LIT:0> ) <EOL> assert ( ( v & delop ) ( Vector . zero ) ) . doit ( ) == Vector . zero <EOL> assert ( ( v & delop ) ( S ( <NUM_LIT:0> ) ) ) . doit ( ) == S ( <NUM_LIT:0> ) <EOL> assert ( ( i & delop ) ( x ) ) . doit ( ) == <NUM_LIT:1> <EOL> assert ( ( j & delop ) ( y ) ) . doit ( ) == <NUM_LIT:1> <EOL> assert ( ( k & delop ) ( z ) ) . doit ( ) == <NUM_LIT:1> <EOL> assert ( ( i & delop ) ( x * y * z ) ) . doit ( ) == y * z <EOL> assert ( ( v & delop ) ( x ) ) . doit ( ) == x <EOL> assert ( ( v & delop ) ( x * y * z ) ) . doit ( ) == <NUM_LIT:3> * x * y * z <EOL> assert ( v & delop ) ( x + y + z ) == C . x + C . y + C . z <EOL> assert ( ( v & delop ) ( x + y + z ) ) . doit ( ) == x + y + z <EOL> assert ( ( v & delop ) ( v ) ) . doit ( ) == v <EOL> assert ( ( i & delop ) ( v ) ) . doit ( ) == i <EOL> assert ( ( j & delop ) ( v ) ) . doit ( ) == j <EOL> assert ( ( k & delop ) ( v ) ) . doit ( ) == k <EOL> assert ( ( v & delop ) ( Vector . zero ) ) . doit ( ) == Vector . zero <EOL> def test_product_rules ( ) : <EOL> """<STR_LIT>""" <EOL> f = <NUM_LIT:2> * x * y * z <EOL> g = x * y + y * z + z * x <EOL> u = x ** <NUM_LIT:2> * i + <NUM_LIT:4> * j - y ** <NUM_LIT:2> * z * k <EOL> v = <NUM_LIT:4> * i + x * y * z * k <EOL> lhs = delop ( f * g , doit = True ) <EOL> rhs = ( f * delop ( g ) + g * delop ( f ) ) . doit ( ) <EOL> assert simplify ( lhs ) == simplify ( rhs ) <EOL> lhs = delop ( u & v ) . doit ( ) <EOL> rhs = ( ( u ^ ( delop ^ v ) ) + ( v ^ ( delop ^ u ) ) + ( ( u & delop ) ( v ) ) + ( ( v & delop ) ( u ) ) ) . doit ( ) <EOL> assert simplify ( lhs ) == simplify ( rhs ) <EOL> lhs = ( delop & ( f * v ) ) . doit ( ) <EOL> rhs = ( ( f * ( delop & v ) ) + ( v & ( delop ( f ) ) ) ) . doit ( ) <EOL> assert simplify ( lhs ) == simplify ( rhs ) <EOL> lhs = ( delop & ( u ^ v ) ) . doit ( ) <EOL> rhs = ( ( v & ( delop ^ u ) ) - ( u & ( delop ^ v ) ) ) . doit ( ) <EOL> assert simplify ( lhs ) == simplify ( rhs ) <EOL> lhs = ( delop ^ ( f * v ) ) . doit ( ) <EOL> rhs = ( ( ( delop ( f ) ) ^ v ) + ( f * ( delop ^ v ) ) ) . doit ( ) <EOL> assert simplify ( lhs ) == simplify ( rhs ) <EOL> lhs = ( delop ^ ( u ^ v ) ) . doit ( ) <EOL> rhs = ( ( u * ( delop & v ) - v * ( delop & u ) + <EOL> ( v & delop ) ( u ) - ( u & delop ) ( v ) ) ) . doit ( ) <EOL> assert simplify ( lhs ) == simplify ( rhs ) <EOL> P = C . orient_new_axis ( '<STR_LIT:P>' , q , C . k ) <EOL> scalar_field = <NUM_LIT:2> * x ** <NUM_LIT:2> * y * z <EOL> grad_field = gradient ( scalar_field , C ) <EOL> vector_field = y ** <NUM_LIT:2> * i + <NUM_LIT:3> * x * j + <NUM_LIT:5> * y * z * k <EOL> curl_field = curl ( vector_field , C ) <EOL> def test_conservative ( ) : <EOL> assert is_conservative ( Vector . zero ) is True <EOL> assert is_conservative ( i ) is True <EOL> assert is_conservative ( <NUM_LIT:2> * i + <NUM_LIT:3> * j + <NUM_LIT:4> * k ) is True <EOL> assert ( is_conservative ( y * z * i + x * z * j + x * y * k ) is <EOL> True ) <EOL> assert is_conservative ( x * j ) is False <EOL> assert is_conservative ( grad_field ) is True <EOL> assert is_conservative ( curl_field ) is False <EOL> assert ( is_conservative ( <NUM_LIT:4> * x * y * z * i + <NUM_LIT:2> * x ** <NUM_LIT:2> * z * j ) is <EOL> False ) <EOL> assert is_conservative ( z * P . i + P . x * k ) is True <EOL> def test_solenoidal ( ) : <EOL> assert is_solenoidal ( Vector . zero ) is True <EOL> assert is_solenoidal ( i ) is True <EOL> assert is_solenoidal ( <NUM_LIT:2> * i + <NUM_LIT:3> * j + <NUM_LIT:4> * k ) is True <EOL> assert ( is_solenoidal ( y * z * i + x * z * j + x * y * k ) is <EOL> True ) <EOL> assert is_solenoidal ( y * j ) is False <EOL> assert is_solenoidal ( grad_field ) is False <EOL> assert is_solenoidal ( curl_field ) is True <EOL> assert is_solenoidal ( ( - <NUM_LIT:2> * y + <NUM_LIT:3> ) * k ) is True <EOL> assert is_solenoidal ( cos ( q ) * i + sin ( q ) * j + cos ( q ) * P . k ) is True <EOL> assert is_solenoidal ( z * P . i + P . x * k ) is True <EOL> def test_scalar_potential ( ) : <EOL> assert scalar_potential ( Vector . zero , C ) == <NUM_LIT:0> <EOL> assert scalar_potential ( i , C ) == x <EOL> assert scalar_potential ( j , C ) == y <EOL> assert scalar_potential ( k , C ) == z <EOL> assert scalar_potential ( y * z * i + x * z * j + x * y * k , C ) == x * y * z <EOL> assert scalar_potential ( grad_field , C ) == scalar_field <EOL> assert scalar_potential ( z * P . i + P . x * k , C ) == x * z * cos ( q ) + y * z * sin ( q ) <EOL> assert scalar_potential ( z * P . i + P . x * k , P ) == P . x * P . z <EOL> raises ( ValueError , lambda : scalar_potential ( x * j , C ) ) <EOL> def test_scalar_potential_difference ( ) : <EOL> point1 = C . origin . locate_new ( '<STR_LIT>' , <NUM_LIT:1> * i + <NUM_LIT:2> * j + <NUM_LIT:3> * k ) <EOL> point2 = C . origin . locate_new ( '<STR_LIT>' , <NUM_LIT:4> * i + <NUM_LIT:5> * j + <NUM_LIT:6> * k ) <EOL> genericpointC = C . origin . locate_new ( '<STR_LIT>' , x * i + y * j + z * k ) <EOL> genericpointP = P . origin . locate_new ( '<STR_LIT>' , P . x * P . i + P . y * P . j + P . z * P . k ) <EOL> assert scalar_potential_difference ( S ( <NUM_LIT:0> ) , C , point1 , point2 ) == <NUM_LIT:0> <EOL> assert ( scalar_potential_difference ( scalar_field , C , C . origin , <EOL> genericpointC ) == <EOL> scalar_field ) <EOL> assert ( scalar_potential_difference ( grad_field , C , C . origin , <EOL> genericpointC ) == <EOL> scalar_field ) <EOL> assert scalar_potential_difference ( grad_field , C , point1 , point2 ) == <NUM_LIT> <EOL> assert ( scalar_potential_difference ( y * z * i + x * z * j + <EOL> x * y * k , C , point1 , <EOL> genericpointC ) == <EOL> x * y * z - <NUM_LIT:6> ) <EOL> potential_diff_P = ( <NUM_LIT:2> * P . z * ( P . x * sin ( q ) + P . y * cos ( q ) ) * <EOL> ( P . x * cos ( q ) - P . y * sin ( q ) ) ** <NUM_LIT:2> ) <EOL> assert ( scalar_potential_difference ( grad_field , P , P . origin , <EOL> genericpointP ) . simplify ( ) == <EOL> potential_diff_P . simplify ( ) ) </s>
