Programming questions that are significantly affected or best defined by the underlying mathematics of the problem.

learn more… | top users | synonyms

-6
votes
0answers
32 views

How to get precise Math.exp() in j2me [closed]

I am using j2me and I need to get quite precise exp() for values up to 4. Problem with the j2me is that it's Math library doesn't have pow() and exp() method. To solve this, I just used this method to ...
0
votes
1answer
110 views

Are there compilers which optimize the use of mathematical functions?

Today while programming I stumbled upon the following question - are there any compilers which optimize based on mathematical assumptions? For instance in cases like unsigned int i,b; (i,b not ...
7
votes
2answers
129 views

Should `Vector<float>.Equals` be reflexive or should it follow IEEE 754 semantics?

When comparing floating point values for equality, there are two different approaches: NaN not being equal to itself, which matches the IEEE 754 specification. NaN being equal to itself, which ...
1
vote
1answer
43 views

How to handle user created expressions in application

In our application users can enter custom expressions to calculate certain things. For instance they can specify an invoice and define a number of lines for cost calculation. Example for a course ...
2
votes
2answers
74 views

From a set of rules, derive the implications? [closed]

I've only just become interested in this domain, so sorry if I'm not using the correct terminologies. What I want is the following: Say I have a set of rules (or constraints), I want to derive some ...
2
votes
0answers
78 views

Program to select N integers with constraints [closed]

I need to write a program which takes 4 inputs as follows N = The number of integers to be generated (10 < N < 10000) Start = The minimum value of the integers (100 < Start) End = The ...
1
vote
1answer
533 views

Number of parallel lines in a given set of lines [closed]

I am given N lines, i.e, I am given a,b,c for N lines. And each line is of the form ax + by + c = 0. I need to find out the maximum number of lines that are parallel to each other. For this, first I ...
17
votes
1answer
2k views

Why does Math.min work with a one element array

According to MDN Math.min accepts only numbers, and if one of the arguments is not a number, it'll return NaN. It's true that if we pass an array with multiple numbers we get NaN, like this: ...
4
votes
2answers
90 views

Should a generic vector class allow non-finite doubles as values?

I am currently writing an immutable multipurpose vector class in Java that essentially wraps a double[]. The class will be part of a game library, used to calculate entity positions, physics, pixel ...
29
votes
10answers
7k views

Why is Math.Sqrt() a static function?

In a discussion about static and instance methods, I always think, that Sqrt() should be a instance method of number types instead of a static method. Why is that? It obviously works on a value. // ...
3
votes
2answers
141 views

C# Abstract math classes from libraries

I'm currently writing a library that abstracts 3D rendering and uses SharpDX and OpenTK as graphics libraries. The problem is that OpenTK and SharpDX have their own implementations of Vector2, Matrix, ...
2
votes
2answers
159 views

What are the advantages of matrix multiplication over individual variables (graphics)?

I am learning OpenGL and the tutorials (1, 2) I'm reading teach me that to scale/rotate/translate an object you have to know matrix multiplication. Why? Instead of 3x3 matrix you can use 6 floats: ...
2
votes
3answers
168 views

How does google calculate travel distance/time

I've been working for quite a while now on a service that generates optimal routes for a given set of addresses and vehicles (Vehicle routing problem / traveling salesman problem). Now it's all ...
2
votes
4answers
152 views

What is the best data model to represent mathematical range (in database, xml, json…)?

For example, greater or equal to 50 and smaller than 100 (>=50 && < 100) smaller than 10 or greater than 40 (<10 || >40) I have been thinking about how to represent ...
-2
votes
1answer
60 views

Computer Algorithms for Polynomial Regression [closed]

Given a data set of arbitrary size, what algorithm would be appropriate for performing the polynomial regression on the data set such that the highest degree of the polynomial is n? If there are ...
1
vote
1answer
44 views

How an add vertex operation could be performed in constant time for a graph represented using adjacency list?

Adding a vertex in a graph that is represented using an adjacency list takes O(1) time complexity according to http://bigocheatsheet.com/ (graph operation > adjacency list > add vertex). It is said ...
3
votes
1answer
140 views

why adding a vertex in a graph represented using an adjacency matrix takes O(|v|^2) time complexity?

Adding a vertex in a graph that is represented using an adjacency matrix takes O(|v|^2) time complexity according to http://bigocheatsheet.com/ (graph operation > adjacency matrix > add vertex). But ...
16
votes
1answer
510 views

In what programming language did the use of the percent sign (%) to mean modulo/remainder originate?

In what programming language did the use of the percent sign (%) to mean modulo/remainder originate? This previous post1 explains that the symbol % was likely chosen because it includes a slash, ...
4
votes
1answer
197 views

Why does Java define BigInteger / BigDecimal values of 10?

Question perhaps slightly left of field - but I'm curious as to the logic behind why Java's BigInteger/BigDecimal classes feel the need to define a constant of TEN? Example taken from ...
0
votes
1answer
37 views

Error handling in math library functions

When writing a library function, such as double getAvg(double[]); how should one handle the empty array? (Note that, mathematically speaking the avg of an empty set is undefined.)
3
votes
0answers
320 views

Fast fixed-size (256 bit) integer modulo/division

What is the fastest way to divide two 256-bit integers? They are represented as an array of 26-bit words, each stored in 32-bit integers. I have access to a 64-bit type if that's useful. It seems ...
3
votes
1answer
198 views

When writing a math library, will operator overloading maintain OOP?

I want to make a fairly complicated mathematical library for a personal project and then have a visualization/GUI to go along with it to demonstrate the maths - nothing hardcore like topology but just ...
6
votes
5answers
276 views

Hamming Distance using a dictionary

First time poster. I'm currently programming a hamming distance program using a dictionary. So if we start with the word "cat" and we want to transform it into "dog", the sequence is ...
2
votes
2answers
205 views

Algorithm and data structure to match groups of users (1-5 each) into 2 balanced sets of 5 users

I'm building a matchmaking queueing service for a 5v5 team-based game. I have a large set of users that are grouped into unique lobbies comprised of 1-5 users each. Each user has an integer based ...
0
votes
0answers
76 views

BCMath vs MySQL: performance

Scenario I am working on a web application that handles financial transactions, and my code will need to be reusable for everything from consumer carts to manufacturer/distributor shipments. The ...
4
votes
0answers
165 views

How can unums emulate IEEE's negative zero?

I am currently reading "The End of Error - Unum Computing" by John Gustafson (Youtube). What I am still not sure about is how the cases handled in IEEE by negatively signed zero are handled with ...
0
votes
1answer
59 views

Count amount of points for XY options (in poll) where options dont have equal amount of points

I have a code where I want to avoid using a for/each loop to count the amount of points options in poll have together. Reason is, every option has different ammount of points and I want to get number ...
0
votes
1answer
27 views

Generating New Media Content From Binary Patterns

At the most basic level, a digital media file (document, song, video, etc) is just a rather large pattern of 1's and 0's. We can say that for any given piece of digital media, there corresponds a ...
0
votes
1answer
83 views

Changing coordinate systems in python

I am working on a visual python program that is meant to model the orbit of an electron around the core of a Hydrogen atom. In order to avoid the singularity at r = 0 in the equation for coulomb ...
2
votes
2answers
216 views

How to iterate between these elements

I have an array of elements: int[] elem = new int[] {A, B, C}; I need to calculate the sum of ALL the combinations of those elements, where only some of the elements can be optionally selected. I ...
33
votes
4answers
914 views

Why is negative zero important?

I'm confused about why we care about different representations for positive and negative zero. I vaguely recall reading claims that having a negative zero representation is extremely important in ...
0
votes
1answer
94 views

Vector API, naming for element-wise multiply [closed]

I'm helping develop a 3D Vector class, which has common operations such as: v = v1.cross(v2) v = v1 * v2 - infix multiply for dot product. v = v1 + v2 - infix addition. v = v1.slerp(v2) - spherical ...
-1
votes
1answer
183 views

How to selecting Teams with Minimum Difference between Knowledge Levels

For the below challenge from a programming site, I am bit confused. Problem Statement: A Professor of Physics gave projects to the students of his class. The students have to form a team of two for ...
1
vote
1answer
31 views

System for deducting velocity against sources pf gravity

Say I have a particle-based physics engine (which I do) that uses lots of particles with a x and y coordinate and velocity. These particles can also have a mass, which means that these particles (with ...
0
votes
1answer
72 views

Convert x and y velocity to x and y velocity relative to another point

The question I asked probably isn't very clear, so I'll explain. If I have an x and y velocity, where the y goes towards the bottom of the screen, and the x goes towards the right of the screen, how ...
1
vote
2answers
189 views

Line intersection detection algorithm

I'm trying to detect if a line drawn by the user intersects itself. I'm using a line intersection detection algorithm that goes through each waypoint of the line and checks if intersects with any ...
0
votes
0answers
71 views

Domain analysis for discrete values - ON and OFF points in these cases

Following my previous question (with great answer from Bart van Ingen Schenau), I noticed a discrepancy I could not wrap my head around: Bart mentioned that: The point ON the boundary is by ...
-1
votes
1answer
108 views

Algorithm to 'segment' a number into blocks of n?

I'm not sure how to word the title properly, but the problem goes something like this: I have 5 nodes, and node 0 is the "master". User inputs a number, e.g. 100 to the master. master "splits" the ...
1
vote
3answers
340 views

Domain analysis - why OFF points are inside of the domain when the border is open

I have asked on a few other sites, no response but it must be something silly as many authors mention in their books. Here is the best text I found: My ultimate question is: Why the OFF point lies ...
1
vote
4answers
468 views

What is the “correct” way to store functions in a database?

Note: Yes, I know that storing functions in databases should be punishable by law. We are developing a financial web application using PostgreSQL, Sinatra and AngularJS. As you may have guessed, a ...
3
votes
3answers
438 views

Why is the “period of a (pseudo)random number generator” important?

I've been trying to understand (pseudo)random number generator code from various sources and the concept of the period continues to elude me. To satisfy the minimum level of understanding, I've tried ...
2
votes
1answer
276 views

Well defined mathematical operations for bearing (angle) class

I have written a class to represent bearings (angles with a nautical theme, and a specific normalisation range). In the program, it is necessary to perform some mathematical operations on them, so ...
4
votes
1answer
347 views

Transpose a matrix without a buffering one

How is it possible to transpose a MxN matrix without using a "buffering" matrix? In the latter case it's easy and quite the "classic" approach... Given a matrix[M][N], I would like to put it into a ...
4
votes
1answer
121 views

Mathematically correct A* heuristic / distance estimator for a latitude / longitude graph

I have a graph in which each node is a geographical point on the surface of the earth, defined by it's latitude / longitude coordinates. Correct ways to calculate the distance between two such points ...
0
votes
3answers
386 views

How do deal with angle wraparounds when comparing them?

Angle A is a degree angle that keeps increasing by increments and Angle B is the stopping point of Angle A (think 'Spin-the-bottle' where Angle A is the current angle of the bottle Angle B is the ...
1
vote
1answer
106 views

Algorithm to find the fewest number of values (from a set of values) where the sum equals a value (+ one more condition)

The simplest way to explain this is with an example. You're given then number 19 and you have a set of numbers to choose from: 1, 2, 3, 4, 6 When choosing values from the list (which can be ...
1
vote
1answer
88 views

Program to find Orthogonal Matrices

I have been trying to find orthogonal matrix of order n where first row will be given as 1/√n, 1/√n, .... n times. The second row will be a vector such that dot product of it with the row above and ...
0
votes
5answers
851 views

Given a number which is power of 2, check if it is even power or odd power

I am given a number n , which is always a power of 2. I want to check whether n is odd power of 2 or even power of 2. For example: n=4 , ans= even n=8, ans=odd (because 8 is 2^3) n=1024 , ans=even. ...
6
votes
2answers
251 views

When should a trig function, with a degree argument, return -0.0?

In creating trig functions my_sind(d), my_cosd(d), my_tand(d), that used a degree argument rather than a radian one and provided exact answers at multiples of 90, I noticed that the result was ...
17
votes
7answers
2k views

What can one do to improve readability of math-oriented code in C#, Java, and similar? [closed]

As both a C programmer and a C# programmer, one of the things I don't like about C# is how verbose math functions are. Every time you would have to use a Sin, cosine, or power function for example, ...