function y=eip(u,v)

%this computes the energy inner product between two functions
%defined as vectors u,v. Typically, my vectors are of length 3, but I wrote
%the program so that it can handle taking inner products of functions
%defined on higher levels of SG given that their dimensions are the same.

w=round(log3(max(size(u))))-1;


if max(size(u))==max(size(v))
y=0;
for n=1:1:max(size(u))/3
    y=y+(u(3*n-2)-u(3*n-1))*(v(3*n-2)-v(3*n-1))+(u(3^n-2)-u(3*n))*(v(3^n-2)-v(3*n))+(u(3^n-1)-u(3^n))*(v(3^n-1)-v(3^n));
end
y=(5/3)^w*y;
else
    'I am afraid you are quite dumb. Your functions are not the same level!'
end
