kill(all)$

fluid  : divergence of tensor( = vector),version 1.0,part 3
peter.vlasschaert@gmail.com,25/05/2019

before : vector : tensor ( order 1),see part 1

load packages

load(lrats)$

load(linearalgebra)$

kronecker delta : operator
---------------------------------------

1e) : kronecker delta operator: 'maxima'
=================================

p1:kron_delta(e1,e1);

p2a:kron_delta(e2,e1);
p2b:kron_delta(e1,e2);
p2c:kron_delta(x,y);

2e) : my kronecker delta 
=====================

krondelta(s1,s2):=block([],if s1=s2 then 1 else 0);

rem  :    s1 = s2   =>  1
               s1 ≠ s2   =>  0

p2a1:krondelta(e2,e1);
p2b1:krondelta(e1,e2);
p2c1:krondelta(x,y);
p2d1:krondelta(x,x);

divergence of a vector:operator
------------------------------------------------

depends([f],[x,y,z]);

gradf(m) := diff(m,x)*e1+diff(m,y)*e2+diff(m,z)*e3;

p3a:gradf(f);

vector representation : 

p3b: u*e1+v*e2+w*e3;

result :
======
.  :  non commutative operator , see , 'p3d1,p3d2'
*  :  commutative operator         ,  see ,'p3c1,p3c2'

commutative operator:
===================

p3c1:expand(p3a*p3b);

p3c2:args(p3c1);

non commutative operator :
=======================

p3d1:expand(p3a.p3b);
p3d2:args(p3d1);

solve : problem non commutative operator
------------------------------------------------------------------

one term:
========

p3d3:p3d2[1];

p3d4:part(p3d3,1,1);

p3d5:part(p3d3,2,1);

p3d6:krondelta(p3d4,p3d5);

p3d7:p3d6*part(p3d3,1,2)*part(p3d3,2,2);

all terms :
========

scalarpr_nabla_vec(fa,fb) := block([],
    fc: expand(fa.fb),
    fd:args(fc),
    hl:[],
   for i:1 thru length(fd)
   do(
    fe:fd[i],
    ff1:part(fe,1,1),
    ff2:part(fe,2,1),
    fg:krondelta(ff1,ff2) *part(fe,1,2) *part(fe,2,2),
    hl:endcons(fg,hl)    
         ),
    som:sum(hl[i],i,1,length(fd)),
    return(som)
  );                   
    

final result : div(vector)
-----------------------------------

reduce :  opration with one rank .
rem : vector => scalar.

p4:scalarpr_nabla_vec(p3a,p3b);

with index notation  'p4'
-----------------------------------

p4a:[u=u[1],v=u[2],w=u[3]];
p4b:[x=x[1],y=x[2],z=x[3]];

p4c:join(p4a,p4b);

p4d:subst(p4c,p4);

dependencies;

p4e:[f=f(x[1],x[2],x[3])];

p4f:subst(p4e,p4d);

vector : [u[1],u[2],u[3]]
var       : [x[1],x[2],x[3]]