discrete-mathematics

Generating Random Permutation Uniformly in Java

假如想象 提交于 2020-01-01 19:20:36
问题 Anyone know of a fast/the fastest way to generate a random permutation of a list of integers in Java. For example if I want a random permutation of length five an answer would be 1 5 4 2 3 , where each of the 5! possibilities is equally likely. My thoughts on how to tackle this are to run a method which generates random real numbers in an array of desired length and then sorts them returning the index i.e. 0.712 0.314 0.42 0.69 0.1 would return a permutation of 5 2 3 4 1 . I think this is

Theory of Object Oriented databases [closed]

隐身守侯 提交于 2020-01-01 12:12:23
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . Please recommend some material about implementing Object-Oriented Databases for dynamic languages (interested in Ruby). I realise that

Finding the minimal subgraph that contains all negative cycles

会有一股神秘感。 提交于 2020-01-01 06:14:25
问题 I'm stuck at the following problem: Given a weighted digraph G, I'd like to construct the minimal subgraph of G that contains all negative (simple) cycles of G. I do know how to find a negative cycle using Bellman-Ford, and I know that the number of simple cycles in a directed graph is exponential. One naive way to approach the problem would be to simply iterate all simple cycles and pick those that are negative, but I have the feeling that there might be a polynomial-time algorithm. Most

how to minimize a function with discrete variable values in scipy

被刻印的时光 ゝ 提交于 2019-12-29 06:57:50
问题 I'm trying to optimize a target function that has multiple input variables (between 24 and 30). These variables are samples of three different statistical variables, and target function values are t-test probability values. An error function represents the error (sum of squares of differences) between the desired and the actual t-test probabilities. I can only accept solutions where the error is less than 1e-8, for all of the three t-tests. I was using scipy.optimize.fmin and it worked great.

De Bruijn-like sequence for `2^n - 1`: how is it constructed?

那年仲夏 提交于 2019-12-29 02:51:07
问题 I'm looking at the entry Find the log base 2 of an N-bit integer in O(lg(N)) operations with multiply and lookup from Bit Twiddling hacks. I can easily see how the second algorithm in that entry works static const int MultiplyDeBruijnBitPosition2[32] = { 0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9 }; r = MultiplyDeBruijnBitPosition2[(uint32_t)(v * 0x077CB531U) >> 27]; which calculates n = log2 v where v is known to be a

Turning A premise into Code? [closed]

送分小仙女□ 提交于 2019-12-27 06:16:40
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago . I have this assignment that requires me to turn a premise statement into code. The idea is that i need to print out the truth table for a premise statement. This is the premise: (((P v Q) ^ (Q -> R)) XOR (P v R)) <-> (R ^ Q) I can create a manual Truth table Truth Table for the

Turning A premise into Code? [closed]

眉间皱痕 提交于 2019-12-27 06:15:51
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago . I have this assignment that requires me to turn a premise statement into code. The idea is that i need to print out the truth table for a premise statement. This is the premise: (((P v Q) ^ (Q -> R)) XOR (P v R)) <-> (R ^ Q) I can create a manual Truth table Truth Table for the

Integer multiplication in 5T(n/3)

霸气de小男生 提交于 2019-12-25 14:46:35
问题 x and y has n bits x=x0*(10^2n/3)+x1*10^n/3+x2 y=y0*(10^2n/3)+y1*10^n/3+y2 x*y=x2y2+(x2y1+x1y2)10^n/3+(x2y0+x1y1+x0y2)10^2n/3+(x1y0+x0y1)10^n+x0y0*10^4n/3 now 9 multiplication of n/3 bit numbers running time 9T(n/3) which is O(n^2) with little trick like Karatsuba's multiplication first calculate x0y0, x1y1 and x2y2 this is 3 multiplication of n/3 bit numbers then use x0y0, x1y1 and x2y2 to calculate the others follow: x2y1+x1y2=(x1+x2)(y1+y2)-x1y1-x2y2 ->> 1 multiplication of n/3 bit number

Integer multiplication in 5T(n/3)

北慕城南 提交于 2019-12-25 14:46:08
问题 x and y has n bits x=x0*(10^2n/3)+x1*10^n/3+x2 y=y0*(10^2n/3)+y1*10^n/3+y2 x*y=x2y2+(x2y1+x1y2)10^n/3+(x2y0+x1y1+x0y2)10^2n/3+(x1y0+x0y1)10^n+x0y0*10^4n/3 now 9 multiplication of n/3 bit numbers running time 9T(n/3) which is O(n^2) with little trick like Karatsuba's multiplication first calculate x0y0, x1y1 and x2y2 this is 3 multiplication of n/3 bit numbers then use x0y0, x1y1 and x2y2 to calculate the others follow: x2y1+x1y2=(x1+x2)(y1+y2)-x1y1-x2y2 ->> 1 multiplication of n/3 bit number

Custom permutation, Equal distribution of equal size groups

老子叫甜甜 提交于 2019-12-24 18:53:03
问题 I made a post a few months ago here Custom permutation, Equal distribution of pairs. I wanted to generate pairs unique to each other while never containing the same pair. I got an excellent answer from Thierry Lathuille on here with this code. def pairs(n): for diff in range(1, n): starts_seen = set() index = 0 for i in range(n): pair = [index] starts_seen.add(index) index = (index+diff) % n pair.append(index) yield pair index = (index+diff) % n if index in starts_seen: index = (index+1) % n