algebra

Linear Combination C++ in modulus

爱⌒轻易说出口 提交于 2019-12-23 05:20:14
问题 I want to compute an LU decomposition of a matrix and extract the linear combinations out of it. I first asked a question using the library Armadillo here but as pointed out by one comment, Armadillo is not able to deal with modulus computation. Thus I started to develop an LU using prime modulus from scratch, here is what I obtain but there is still a bug that I am not able to see. Here is the code that I have for now. (Do not think too much about the class Matrix, it is just a way to

Solving simultaneous equations in Sage

萝らか妹 提交于 2019-12-23 04:26:42
问题 In Sage (using the Sage terminal in Sage Cloud), I expected the following to yield the result [t == (1/2)] . However, it yields the result [] . sage: var('x1 y1 x2 y2 t') (x1, y1, x2, y2, t) sage: eq1 = x1==t sage: eq2 = y1==t sage: eq3 = x2==t sage: eq4 = y2==1-t sage: solve([eq1,eq2,eq3,eq4,x1==x2,y1==y2],t) [] The following reformulation doesn't help: sage: eq5 = x1==x2 sage: eq6 = y1==y2 sage: solve([eq1,eq2,eq3,eq4,eq5,eq6],t) [] Where am I going wrong? 回答1: If you write solve([eq1,eq2

Calculate multinomial coefficient

廉价感情. 提交于 2019-12-21 20:25:47
问题 I want to calculate multinomial coefficient mod 1e9 + 7. It equals: n! / (k0! * k1! * k2 * ... * km!) In my case m = 3, k0 + k1 + k2 = n, so it would be: n! / (k0! * k1! * k2!) My code for this: .... long long k2 = n - k1 - k0; long long dans = fact[n] % MOD; long long tmp = fact[i] % MOD; tmp = (tmp * fact[j]) % MOD; tmp = (tpm * fact[k]) % MOD; res = (fact[n] / tmp) % MOD; // mb mistake is here... cout << res; fact[i] - factorial of i mod 1e9+7 It does not work on big tests 回答1: I hope I'm

Calculating 1^X + 2^X + … + N^X mod 1000000007

徘徊边缘 提交于 2019-12-20 17:30:12
问题 Is there any algorithm to calculate (1^x + 2^x + 3^x + ... + n^x) mod 1000000007 ? Note: a^b is the b-th power of a. The constraints are 1 <= n <= 10^16, 1 <= x <= 1000 . So the value of N is very large. I can only solve for O(m log m) if m = 1000000007 . It is very slow because the time limit is 2 secs. Do you have any efficient algorithm? There was a comment that it might be duplicate of this question, but it is definitely different. 回答1: You can sum up the series 1**X + 2**X + ... + N**X

How to draw a line using y = mx +b in java?

拜拜、爱过 提交于 2019-12-20 07:28:20
问题 So I have a program that solves a system of linear equations, but that is not relevant. So what happens is that my program pass two linear equations in the form of: y = mx +b. I do not know how I would graph this using Graphics2D, I am having some trouble figuring it out. Right now I have no idea so I have no code that I could show you, but I can tell you that: That my program correctly converts Ax + By = C into y = mx + B That it would be helpful to show an example in some code possibly

How to draw a line using y = mx +b in java?

雨燕双飞 提交于 2019-12-20 07:28:20
问题 So I have a program that solves a system of linear equations, but that is not relevant. So what happens is that my program pass two linear equations in the form of: y = mx +b. I do not know how I would graph this using Graphics2D, I am having some trouble figuring it out. Right now I have no idea so I have no code that I could show you, but I can tell you that: That my program correctly converts Ax + By = C into y = mx + B That it would be helpful to show an example in some code possibly

I'm making a PEMDAS solver and don't know what to write

血红的双手。 提交于 2019-12-20 06:03:01
问题 I am trying to make a PEMDAS solver where the user types in a PEMDAS problem. For example, they would type in 4(4 + 2) - 5 and the program would solve it for them. is there any code that would make python solve the input that the user enters. something like: problem = input() solve(problem) print(problem) I obviously know that "solve" is not a real command in python. 来源: https://stackoverflow.com/questions/13182459/im-making-a-pemdas-solver-and-dont-know-what-to-write

Java/Scala library for algebra, mathematics [closed]

百般思念 提交于 2019-12-18 10:24:36
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . Can you advise me some flexible and powerful, yet fast library which could cover SciPy (both in performance and functionality). I found SciPy very expressive - but I want to try something in Scala. I read a little about Scala - but is not as featured as SciPy. Any alternatives? Maybe Java library? 回答1: The

Calculating the boundary of irregular shape in Cartesian Coordinate 2D

青春壹個敷衍的年華 提交于 2019-12-13 14:25:29
问题 I'm looking for a solution to calculate the boundary of an irregular shape. Lats take a look at Square example: if i have Minimum x and y and Maximum x and y like: MaxX = 5 MinX = 1 MaxY = 5 MinY = 1 in python language: #Python Code X = {"Min":1, "Max":5} # is Dictionary of x Axis Y = {"Min":1, "Max":5} # is Dictionary of y Axis I can check if any coordinate is in the square boundary or not, simpley by comparing the axis against min and max of square boundary. now let's look at these 2

Modulo Arithmetic in Modified Geometric Progression

谁说胖子不能爱 提交于 2019-12-13 10:44:09
问题 We know that sum of n terms in a Geometric Progression is given by Sn = a1(1-r^n)/(1-r) if the series is of the form a1, a1*r, a1*r^2, a1*r^3....a1*r^n. Now i have modified geometric progression where series is of the form a1, (a1*r) mod p , (a1*r^2) mod p, (a1*r^3) mod p.....(a1*r^n)mod p where a1 is the initial term, p is prime number and r is common ratio. Nth term of this series is given by: (a1 * r^n-1) mod p. I am trying to get summation formula for above modified GP and struggling very