︠63b1184d-d889-4cbc-99b6-8bcd72679936s︠ #amma function for the sphere volume formula from sage.functions.other import gamma1 ︡a9e9374a-a107-447c-8e84-542d99326b43︡ ︠22cc9bfd-1305-471b-b3ea-73f392274a31s︠ #This section defines functions which return the volume of a region of an n-dimensional #sphere with 0,1,2, and 3 coordinates that are at least 1/2 #volume of a sphere of radius R in dimension n def sphere_vol(R,n): return (pi^(n/2)/gamma1(n/2+1)*R^n) #S_1 == volume of a sphere of radius 1 in dimension n with (at least) one coordinate >=1/2 #delta is the size of the sub intervals used def sphere_vol1(n,delta): sum=0 #length of the interval is 1-1/2=1/2 so we need (1/2)/delta intervals ##############round to nearest integer?################### for i in range(1/(2*delta)): #x is the midpoint of the interval x=1/2+(i+.5)*delta #evaluate the function at x and add it to the sum sum+=sphere_vol(sqrt(1-x^2),n-1)*delta return sum #S_2 == volume of a sphere of radius 1 in dimension n with (at least) two coordinates >=1/2 #delta is the size of the sub intervals used def sphere_vol2(n,delta): sum=0 #length of the interval is sqrt(3)/2-1/2 so we need (sqrt(3)-1)/(2*delta) intervals for i in range((sqrt(3)-1)/(2*delta)): #x is the midpoint of the interval x=1/2+(i+.5)*delta #length of the interval is (sqrt(1-x^2)-1/2) so we need (sqrt(1-x^2)-1/2)/delta intervals for j in range((sqrt(1-x^2)-1/2)/delta): #y is the midpoint of the interval y=1/2+(j+.5)*delta #evaluate the function at (x,y) and add it to the sum sum+=sphere_vol(sqrt(1-x^2-y^2),n-2)*delta^2 return sum # " " def sphere_vol3(n,delta): sum=0 for i in range((sqrt(2)-1)/(2*delta)): x=1/2+(i+.5)*delta for j in range((sqrt(3/4-x^2)-1/2)/delta): y=1/2+(j+.5)*delta for k in range((sqrt(1-x^2-y^2)-1/2)/delta): z=1/2+(k+.5)*delta sum+=sphere_vol(sqrt(1-x^2-y^2-z^2),n-3)*delta^3 return sum ︡19464f50-375d-4862-824b-e09b4a28ff24︡ ︠03435519-a05a-45ba-be6b-658a8f978cdfi︠ for n in range(3,10): S=sphere_vol(1,n) S1=sphere_vol1(n,.01) S2=sphere_vol2(n,.01) S3=sphere_vol3(n,.01) 2^n*(1/2^n*S-binomial(n,1)/2^(n-1)*S1+binomial(n,2)/2^(n-2)*S2-binomial(n,3)/2^(n-3)*S3) ︠43b3e5e9-ed5d-448c-8663-e1c0d6afe79as︠ #prints desired volumes for dimensions 4 through 20 # delta=.003 was used in the article 2 round(4*sphere_vol2(2,.005),ndigits=10) 3 round(8*sphere_vol3(3,.005),ndigits=10) for n in range(4,21): S=sphere_vol(1,n) S1=sphere_vol1(n,.005) S2=sphere_vol2(n,.005) S3=sphere_vol3(n,.005) n #Applies the formula discussed in the article for n>=4 round(1-(2^n*(1/2^n*S-binomial(n,1)/2^(n-1)*S1+binomial(n,2)/2^(n-2)*S2-binomial(n,3)/2^(n-3)*S3)),ndigits=10) ︡2052af80-635b-4bab-bd4e-321608a73206︡{"stdout":"2\n"}︡{"stdout":"0.3117"}︡{"stdout":"\n"}︡{"stdout":"3\n"}︡{"stdout":"0.014749"}︡{"stdout":"\n"}︡{"stdout":"4"}︡{"stdout":"\n-1.50103e-05\n5"}︡{"stdout":"\n0.0004225129\n6"}︡{"stdout":"\n0.004929251\n7"}︡{"stdout":"\n0.0223577271\n8"}︡{"stdout":"\n0.0637000021\n9"}︡{"stdout":"\n0.1358705469\n10"}︡{"stdout":"\n0.2374826083\n11"}︡{"stdout":"\n0.3592094101\n12"}︡{"stdout":"\n0.4876233401\n13"}︡{"stdout":"\n0.6097664557\n14"}︡{"stdout":"\n0.7163124905\n15"}︡{"stdout":"\n0.8026371296\n16"}︡{"stdout":"\n0.86823807\n17"}︡{"stdout":"\n0.9153590352\n18"}︡{"stdout":"\n0.9475507023\n19"}︡{"stdout":"\n0.9685741772\n20"}︡{"stdout":"\n0.9817546002\n"}︡ ︠a199a5fa-3bc9-4056-91a7-b95bb81fe038︠