(*Zad 1*)

Sum[(x^i*y^j*z^k)KroneckerDelta[i+j+k,1],{i,0,1},{j,0,1},{k,0,1}]

Clear[x,y,z]

x=r*Sin[θ]Cos[ϕ];
y=r*Sin[θ]Sin[ϕ];
z=r*Cos[θ];

x[r_,θ_,ϕ_]=r*Sin[θ]Cos[ϕ];
y[r_,θ_,ϕ_]=r*Sin[θ]Sin[ϕ];
z[r_,θ_,ϕ_]=r*Cos[θ];

Sum[(x^i*y^j*z^k)KroneckerDelta[i+j+k,1],{i,0,1},{j,0,1},{k,0,1}]

(*Zad 2*)

G[r_,α_]=Assuming[α>0,1/Sqrt[4π*Integrate[r^2Exp[-2α*r^2],{r,0,∞}]]Exp[-α*r^2]]
s1[r_]=1/Sqrt[4π*Integrate[r^2*Exp[-2r],{r,0,∞}]]*Exp[-r]

(*Wariacyjnie*)
En1s=-1/2*4π*Integrate[r^2s1[r]*Laplacian[s1[r],{r,θ,ϕ},"Spherical"],{r,0,∞}]-4π*Integrate[r*s1[r]^2,{r,0,∞}]
EnG[α_]=Assuming[α>0,-1/2*4π*Integrate[r^2G[r,α]*Laplacian[G[r,α],{r,θ,ϕ},"Spherical"],{r,0,∞}]-4π*Integrate[r*G[r,α]^2,{r,0,∞}]]

DEnG[α_]=EnG'[α]

OptAVar=Solve[DEnG[α]==0,α][[1]]

EnG[α]/.OptAVar
EnG[α]/.OptAVar//N
GVar[r_]=G[r,α]/.OptAVar

(*Fit1*)

DiffFun[r_,α_]=G[r,α]-s1[r]

DiffOvlp[α_]=4π*Assuming[α>0,Integrate[r^2DiffFun[r,α]^2,{r,0,∞}]]

DDiffOvlp[α_]=DiffOvlp'[α]

OptAFit1=FindRoot[DDiffOvlp[α]==0,{α,0.5}][[1]]

GFit1[r_]=G[r,α]/.OptAFit1

(*Fit2*)
dr=0.1;
Data=Table[{i*dr,s1[i*dr]},{i,0,100}];
Fitted=FindFit[Data,G[r,α],α,r][[1]]

GFit2[r_]=G[r,α]/.Fitted

Plot[{s1[Abs[r]],GVar[r],GFit1[r],GFit2[r]},{r,-5,5},PlotStyle->{Red,Thick,Dashed,Dashed}]

(*Zad 3*)

gp[α_,q_,Q_,n_]=(q-Q)^n*Exp[-α(q-Q)^2]

glm[α_,x_,y_,z_,X_,Y_,Z_,l_,m_]:=NN[l,m]Sum[CC[l,m,i,j,k]gp[α,x,X,i]gp[α,y,Y,j]gp[α,z,Z,k]*KroneckerDelta[i+j+k,l],{i,0,l},{j,0,l},{k,0,l}]

glm[α,x,y,z,0,0,0,0,0]

(*Stad zgadujemy, ze CC i NN w naszym przypadku wynosza 1 i normujemy*)

Assuming[α>0,1/Sqrt[Integrate[Exp[-α(x^2+y^2+z^2)]^2,{x,-∞,∞},{y,-∞,∞},{z,-∞,∞}]]]

g00[α_,x_,y_,z_]=(2/π)^(3/4)/Sqrt[1/α^(3/2)]Exp[-α(x^2+y^2+z^2)]

g[x1_,y1_,z1_,x2_,y2_,z2_,t_]=1/Sqrt[π]Exp[-t^2((x1-x2)^2+(y1-y2)^2+(z1-z2)^2)];

s[α_,β_]=Assuming[α>0&&β>0,Integrate[g00[α,x,y,z]g00[β,x,y,z],{x,-∞,∞},{y,-∞,∞},{z,-∞,∞}]]
h[α_,β_,Z_]=Assuming[α>0&&β>0&&t>0,-1/2Integrate[g00[α,x,y,z]Laplacian[g00[β,x,y,z],{x,y,z},"Cartesian"],{x,-∞,∞},{y,-∞,∞},{z,-∞,∞}]-Z*Integrate[g00[α,x,y,z]g00[β,x,y,z]g[x,y,z,0,0,0,t],{t,-∞,∞},{x,-∞,∞},{y,-∞,∞},{z,-∞,∞}]]
g[α_,β_,γ_,δ_]=Assuming[α>0&&β>0&&γ>0&&δ>0&&t>0,Integrate[g00[α,x1,y1,z1]g00[β,x1,y1,z1]Exp[-t^2 ((x1-x2)^2+(y1-y2)^2+(z1-z2)^2)]/Sqrt[π]g00[γ,x2,y2,z2]g00[δ,x2,y2,z2],{t,-∞,∞},{x1,-∞,∞},{y1,-∞,∞},{z1,-∞,∞},{x2,-∞,∞},{y2,-∞,∞},{z2,-∞,∞}]]