discrete-mathematics

Finding the closest fibonacci numbers

对着背影说爱祢 提交于 2019-12-03 08:03:55
问题 I am trying to solve a bigger problem, and I think that an important part of the program is spent on inefficient computations. I need to compute for a given number N, the interval [P, Q], where P is the biggest fibonacci number that is <= to N, and Q is the smallest fibonacci number that is >= to N. Currently, I am using a map to record the value of the fibonacci numbers. A query normally involves searching all the fibonacci numbers up to N, and it is not very time efficient, as it involves a

count of distinct acyclic paths from A[a,b] to A[c,d]?

梦想与她 提交于 2019-12-03 07:24:56
问题 I'm writing a sokoban solver for fun and practice, it uses a simple algorithm (something like BFS with a bit of difference). now i want to estimate its running time ( O and omega). but need to know how to calculate count of acyclic paths from a vertex to another in a network. actually I want an expression that calculates count of valid paths, between two vertices of a m*n matrix of vertices. a valid path: visits each vertex 0 or one times. have no circuits for example this is a valid path:

Algorithm to detect redundant rules

不羁的心 提交于 2019-12-03 06:53:11
I am looking for an algorithm to detect redundant rules. Rules have a fixed number of input parameters and each parameter has a distinct domain. Consider three rule parameters Color, Material and Size: Color : Red, Green, Blue Material : Wood, Glass, Aluminium Size : Small, Medium, Large Each rule can match on multiple values of a parameter or match on any value. The first rule that matches all parameters values is selected. There are no negation rules, but the domain is fixed, so a negation can be achieved by added all others. +--------------------------------------------------++-------------

Fastest modular exponentiation in JavaScript

丶灬走出姿态 提交于 2019-12-03 05:59:26
问题 My problem is to compute (g^x) mod p quickly in JavaScript, where ^ is exponentiation, mod is the modulo operation. All inputs are nonnegative integers, x has about 256 bits, and p is a prime number of 2048 bits, and g may have up to 2048 bits. Most of the software I've found that can do this in JavaScript seems to use the JavaScript BigInt library (http://www.leemon.com/crypto/BigInt.html). Doing a single exponentiation of such size with this library takes about 9 seconds on my slow browser

Why is squaring a number faster than multiplying two random numbers?

末鹿安然 提交于 2019-12-03 01:43:12
问题 Multiplying two binary numbers takes n^2 time, yet squaring a number can be done more efficiently somehow. (with n being the number of bits) How could that be? Or is it not possible? This is insanity! 回答1: There exist algorithms more efficient than O(N^2) to multiply two numbers (see Karatsuba, Pollard, Schönhage–Strassen, etc.) The two problems "multiply two arbitrary N-bit numbers" and "Square an arbitrary N-bit number" have the same complexity. We have 4*x*y = (x+y)^2 - (x-y)^2 So if

Is it possible to implement bitwise operators using integer arithmetic?

自古美人都是妖i 提交于 2019-12-03 00:29:31
问题 I am facing a rather peculiar problem. I am working on a compiler for an architecture that doesn't support bitwise operations. However, it handles signed 16-bit integer arithmetics and I was wondering if it would be possible to implement bitwise operations using only: Addition ( c = a + b ) Subtraction ( c = a - b ) Division ( c = a / b ) Multiplication ( c = a * b ) Modulus ( c = a % b ) Minimum ( c = min(a, b) ) Maximum ( c = max(a, b) ) Comparisons ( c = (a < b), c = (a == b), c = (a <= b)

count of distinct acyclic paths from A[a,b] to A[c,d]?

十年热恋 提交于 2019-12-02 22:16:39
I'm writing a sokoban solver for fun and practice, it uses a simple algorithm (something like BFS with a bit of difference). now i want to estimate its running time ( O and omega). but need to know how to calculate count of acyclic paths from a vertex to another in a network. actually I want an expression that calculates count of valid paths, between two vertices of a m*n matrix of vertices. a valid path: visits each vertex 0 or one times. have no circuits for example this is a valid path: alt text http://megapic.ir/images/f1hgyp5yxcu8887kfvkr.png but this is not: alt text http://megapic.ir

Finding the closest fibonacci numbers

↘锁芯ラ 提交于 2019-12-02 20:44:31
I am trying to solve a bigger problem, and I think that an important part of the program is spent on inefficient computations. I need to compute for a given number N, the interval [P, Q], where P is the biggest fibonacci number that is <= to N, and Q is the smallest fibonacci number that is >= to N. Currently, I am using a map to record the value of the fibonacci numbers. A query normally involves searching all the fibonacci numbers up to N, and it is not very time efficient, as it involves a big number of comparisons. This type of queries will occur quite often in my program, and I am

Fastest modular exponentiation in JavaScript

左心房为你撑大大i 提交于 2019-12-02 18:30:15
My problem is to compute (g^x) mod p quickly in JavaScript, where ^ is exponentiation, mod is the modulo operation. All inputs are nonnegative integers, x has about 256 bits, and p is a prime number of 2048 bits, and g may have up to 2048 bits. Most of the software I've found that can do this in JavaScript seems to use the JavaScript BigInt library ( http://www.leemon.com/crypto/BigInt.html ). Doing a single exponentiation of such size with this library takes about 9 seconds on my slow browser (Firefox 3.0 with SpiderMonkey). I'm looking for a solution which is at least 10 times faster. The

Why is squaring a number faster than multiplying two random numbers?

六眼飞鱼酱① 提交于 2019-12-02 17:07:40
Multiplying two binary numbers takes n^2 time, yet squaring a number can be done more efficiently somehow. (with n being the number of bits) How could that be? Or is it not possible? This is insanity! There exist algorithms more efficient than O(N^2) to multiply two numbers (see Karatsuba, Pollard, Schönhage–Strassen, etc.) The two problems "multiply two arbitrary N-bit numbers" and "Square an arbitrary N-bit number" have the same complexity. We have 4*x*y = (x+y)^2 - (x-y)^2 So if squaring N-bit integers takes O(f(N)) time, then the product of two arbitrary N-bit integers can be obtained in O