math

Any implementations of graph st-ordering or ear-decomposition?

I'm in the search for an implementation of an ear-decomposition algorithm (http://www.ics.uci.edu/~eppstein/junkyard/euler/ear.html). I examined networkx and didn't find one. Although the algorithm layout is vaguely in my mind, I'd like to see some reference implementation, too. I'm aware of Ulrik Brandes publication on a linear time E...

Adding to a bit array

In my program, I am using BitArrays to represent 160 bit numbers. I want to be able to add, subtract, increment and decrement these numbers, what is the algorithm for doing this? At the moment I'm not interested in multiplication and division, but I might be in the future so bonus points for that. I'm implementing in C#, but pseudocode...

Apache Commons Math optimization

Does anyone have any experience with the Apache Commmons Math optimization package? More specifically, the Nelder-Mead method implementation? Is it pretty high quality? ...

Java port of StrictMath.exp?

Did anybody port the C source code of StricMath.exp (OpenJDK) to Java and made it available online? I mean the port of http://hg.openjdk.java.net/jdk6/jdk6/jdk/file/7b641a18cf0b/src/share/native/java/lang/fdlibm/src/e_exp.c ...

How can you represent mathematical constant "e" as a value in JavaScript?

How can you represent mathematical constant "e" as a value in JavaScript? ...

Are there any example of Mutual recursion?

Are there any example for a recursive function that call an other one which calls the first one too ? example function1() { //do something f2(); //do something } function2() { //do something f1(); //do something } ...

Can my loop be optimized any more? (C++)

Below is my innermost loop that's run several thousand times, with input sizes of 20 - 1000 or more. This piece of code takes up 99 - 99.5% of execution time. Is there anything I can do to help squeeze any more performance out of this? I'm not looking to move this code to something like using tree codes (Barnes-Hut), but towards optimi...

Mapping a BigInteger to a circle

I have a C# system using 160 bit numbers, stored in a BigInteger. I want to display these things on a circle, which means mapping the 0->2^160 range into the 0->2Pi range. How would I do this? The approach that jumps instantly to mind is BigInteger number; angle = (number / pow(2, 160)) * TwoPi; However, that has complexities because...

linear algebra libraries for clusters

Hi all I need to develop applications doing linear algebra + eigenvalue + linear equation solutions over a cluster of pcs ( I have a lot of machines available ). I discovered Scalapack libraries but they seem to me developed long time ago. Do you know if these are other libs available that I should learn doing math & linear algebra in ...

Java: minimum number of operations for conjunctive inequalities?

I try to simplify conditionals in: for ( int t=0, size=fo.getPrintViewsPerFile().size(); t<size && t<countPerFile; t++) { // ... } , more precisely: t<s && t<c You need to compare two times, then calc the boolean value from them. Is there any simpler way to do it? If no, how can you prove it? I can simplify...

How to change handedness of coordinates?

How to convert from Euler's coordinates E1 = (x1, y1, z1, yaw1, pitch1, roll1) to E2 = (x2, y2, z2, yaw2, pitch2, roll2) where x, y, z are the coordinates of a point and yaw, pitch, roll the direction/orientation of a vector which origin is the point. yaw is around y, pitch around x, roll around z. They are performed in that ord...

Making pascal's triangle with mpz_t's

Hey, I'm trying to convert a function I wrote to generate an array of longs that respresents Pascal's triangles into a function that returns an array of mpz_t's. However with the following code: mpz_t* make_triangle(int rows, int* count) { //compute triangle size using 1 + 2 + 3 + ... n = n(n + 1) / 2 *count = (rows * (rows + 1)) / 2; m...

Express any number as the sum of 4 prime numbers [Doubts]

I was give a problem to express any number as sum of 4 prime numbers. Conditions: Not allowed to use any kind of database. Maximum execution time : 3 seconds Numbers only till 100,000 If the splitting is NOT possible, then return -1 What i did : using the sieve of eratosthenes, i calculated all prime numbers till the specified n...

Calculating a parabola: What am I doing wrong?

I was following this thread and copied the code in my project. Playing around with it turns out that it seems not to be very precise. Recall the formula: y = ax^2 + bx +c Since the first given point I have is at x1 = 0, we already have c=y1 . We just need to find a and b. Using: y2 = ax2^2 + bx2 +c y3 = ax3^2 + bx3 +c Solving the equ...

Fast ceiling of an integer division in C / C++

Given integer values x and y, C and C++ both return as the quotient q = x/y the floor of the floating point equivalent. I'm interestd in a method of returning the ceiling instead. For example, ceil(10/5) = 2 and ceil(11/5) = 3. The obvious approach involves something like: q = x / y; if (q * y < x) ++q; This requires an extra compar...

How to make scipy.interpolate give a an extrapolated result beyond the input range?

I'm trying to port a program which uses a hand-rolled interpolator (developed by a mathematician colleage) over to use the interpolators provided by scipy. I'd like to use or wrap the scipy interpolator so that it has as close as possible behavior to the old interpolator. A key difference between the two functions is that in our origina...

how to exit recursive math formula and still get an answer

i wrote this python code, which from wolfram alpha says that its supposed to return the factorial of any positive value (i probably messed up somewhere), integer or not: from math import * def double_factorial(n): if int(n) == n: n = int(n) if [0,1].__contains__(n): return 1 a = (n&1) + 2 ...

Looking for framework for plotting scientific data: 2d/3d ...

I need to visualize some scientific calculations. I generally prefer reusing code if there is already a good available instead of inventing wheels each time, that's why I am asking. I need a C# code to draw charts (just outputting a bitmap is ok) of 2d (y=f(x)) and 3d (z=f(x,y)) digital data sets (where any axis can be float, int or date...

Interview Q: find angle between hour and minute hands in an analog clock

I was given this interview question recently: Given a 12-hour analog clock, compute in degree the smaller angle between the hour and minute hands. Be as precise as you can. I'm wondering what's the simplest, most readable, most precise algorithm is. Solution in any language is welcome (but do explain it a bit if you think it's nece...

Is there a library for Visual C++ that renders math formulas?

I've been looking all over, but I can't find anything free that will let me simply display math formulas on a window. I found one for Visual C++.net, but no APIs. Are there any out there? ...