Length of comprehensions in Python -


new @ python, please...

just came across comprehensions , understand going possibly ramify perhaps dot products or matrix multiplications (although fact result set makes them more interesting), @ point want ask whether there formula determine length of comprehension such as:

{x * y x in {3, 4, 5} y in {4, 5, 6}}.

evidently don't mean particular one:

len({x * y x in {3, 4, 5} y in {4, 5, 6}}) = 8, of general operation of type element-wise multiplication of 2 sets, , taking result set of resultant integers (no repetitions), for given length of x , y, consecutive integers, , known x[1] , y[1].

i understand question @ crossroads of coding , math, asking here on off chance happened common, or well-known computational issue, since have read comprehensions used. in sense interested in question. base on comments far, sense not case.

edit:

for instance, here pattern: if x = {1, 2, 3} len(x * y) comprehensions equal 9 provided y[1] = or > 3. example, len({x * y x in {1, 2, 3} y in {1111, 1112, 1113}}) = 9. tentatively, length = length(x) * length(y), provided there no overlap in elements of x , y. work 4-element sets? sure: len({x * y x in {1, 2, 3, 4} y in {1111, 1112, 1113, 1114}}) = 16. in fact, integers don't need consecutive, just not overlap: len({x*y x in {11,2,39} y in {3,4,5}}) = 9.

and, yes, doesn't work... check out:

{x * y x in {0, 1, 3} y in {36, 12, 4}} = {0, 4, 12, 36, 108}

no, impossible length of inputs. can use math determine length computing common prime factors, work involved not improve upon computing results , taking len of that, , requires knowledge of set contents, not length.

after all, length, {2, 3} multiplied {2, 3} (producing {4, 6, 9}) couldn't distinguished {2, 3} multiplied {10, 11}, produce entirely unique outputs (four total). makes simple proof contradiction; knowing input lengths alone insufficient determine length of output, no single operation on (2, 2) can possibly produce both 3 , 4 without additional inputs.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -