#A version of hw11 Problem 3 done with automated OEIS search #OEIS search proc URLpath := "https://oeis.org/": Search := proc() option cache; local argsin, i, j, oeis_json, parsed_value, searchstring; parsed_value := Array(1..0): if type( [ args ], 'list'('integer') ) = true and nargs < 6 or ( type( [ args ], 'list'('integer') ) = false and not type( args, 'string') ) then error "6 or more integers required"; elif type( [ args ], 'list'('integer') ) = true then argsin := :-map( :-convert, [ args ], ':-string' ); searchstring := cat( argsin[1], seq( op( [",", argsin[i]] ), i = 2..numelems( argsin ) ) ); elif type( args, 'string') then argsin := [args]; searchstring := StringTools:-SubstituteAll(op(argsin), " ", "%20"); else error "in arguments, expected integer sequence or string; received", op( [ args ] ); end if; oeis_json := URL:-Get( cat( URLpath, "search?fmt=json&q=", searchstring ) ); parsed_value(1) := eval( JSON:-ParseString( oeis_json ) ); if type(parsed_value[1][1]["number"],integer) then return parsed_value[1][1]["number"]; else return -1; end if; end proc: #Supporting code from hw11 with(combinat): GenCompsGF:=proc(a,b,A,B,x): local f, i, j: f:=add(x^i, i in A)/(1-x^a): normal(add(f^j, j in B)/(1-f^b)); end proc: CountNuCompsClever:=proc(a,b,A,B,N): local x, i: [seq(coeff(taylor(GenCompsGF(a,b,A,B,x),x=0,N+3),x,i),i=1..N)]; end proc: RandASubset:=proc(n): local i, S; S:={}: while S={} do for i from 1 to n do if rand(0..1)()=1 then S := S union {i}; end if; end do; end do; S; end proc: RandBSubset:=proc(n): local i, S; S:={}: while S={} do for i from 0 to n-1 do if rand(0..1)()=1 then S := S union {i}; end if; end do; end do; S; end proc: ABGen:=proc(n): local a, b, A, B, L, S: S:={}: for a from 1 to n do for b from 1 to n do L:=[a,b,RandASubset(a),RandBSubset(b)]: S:=S union {L}: end do; end do; S; end proc: #New Code P3:=proc(n): local s, S, k: S:={}: for s in ABGen(n) do k:=Search(op(CountNuCompsClever(s[1],s[2],s[3],s[4],20))): if k<>-1 then S:=S union {[op(s),k]}; end if; end do; S; end proc: #P3 returns n^2 sequences generating parameters (with a,b <= n and A,B uniform rand) and their corresponding A values #P3(4); #Sample Output: #{[1, 1, {1}, {0}, 79], [1, 2, {1}, {1}, 11782], [1, 3, {1}, {0, 1}, 24493], [1,4, {1}, {1, 2}, 38504], [2, 1, {1}, {0}, 45], [2, 2, {1}, {0, 1}, 45], #[2, 3, {1}, {0}, 291217], [2, 4, {1, 2}, {2, 3}, 38505], [3, 1, {2}, {0}, 931], [4, 1, {1}, {0}, 3269], [4, 4, {3}, {0, 1, 2, 3}, 127838]} #[2, 3, {1}, {0}, 291217] can be read as [2, 3, {1}, {0}] generates A291217, let's verify this is true #CountNuCompsClever(2,3,{1},{0},20); #Output: 0, 0, 1, 0, 3, 1, 6, 6, 11, 21, 24, 57, 66, 138, 194, 330, 546, 827, 1452, 2175 #It can be verified manually this is indeed A291217