# Questions tagged [math]

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

255 questions
Filter by
Sorted by
Tagged with
1answer
1k views

### Python — Time complexity of built-in functions versus manually-built functions in finite fields

Generally, I'm wondering about the advantages versus disadvantages of using the built-in arithmetic functions versus rolling your own in Python. Specifically, I'm taking in GF(2) finite field ...
4answers
3k views

### Documenting mathematical logic in code

Sometimes, although not often, I have to include math logic in my code. The concepts used are mostly very simple, but the resulting code is not - a lot of variables with unclear purpose, and some ...
2answers
5k views

### Array Multiplication and Division

I came across a question that (eventually) landed me wondering about array arithmetic. I'm thinking specifically in Ruby, but I think the concepts are language independent. So, addition and ...
2answers
3k views

### Does learning to play an instrument improve programming ability? [closed]

I've seen plenty of questions asking if listening to music boosts productivity, etc. but I haven't been able to find one about performing music. Learning to play the piano has been on my to-do list ...
1answer
319 views

### Finding maximum number of congruent numbers

Let's say we have a multiset (set with possible duplicates) of integers. We would like to find the size of the largest subset of the multiset such that all numbers in the subset are congruent to each ...
0answers
313 views

### Optimization algorithm, how to develop this problem

I have a situation where I would like your input and think over / solve algorithm. The specs There are inventories with a specified amount of capacity. 'X (width) and Y (time)' creates ...
1answer
1k views

### What is the difference between a combinator and function chaining?

So from what I've read about combinators I can't quite tell how they're different from simply chaining function calls. I know I must be missing something but I'm not figuring out what I'm missing. I ...
1answer
582 views

### Pairwise testing, not possible to say which combinations is faulty?

Let's say I have 4 (A,B,C,D) parameters with 3 possible values, also 81 unique combinations. With e.g. orthogonal array, I will end up with 9 test cases, each combining 3 pairs. But that means that if ...
4answers
136 views

### Find how the data has been processed

Well this has been a question I have puzzled about for a long time: Suppose I have a dictionary of input:output like: This {2: 6, 5: 15, 20: 60, 26: 78, ... 982: 2946, 997: 2991} where ...
2answers
2k views

### Transform math formula into code (line-line intersection)

I'm having hard times transforming a math formula to code. I can solve it on the paper easily, but it's hard for me to bring it into code form. Is it generally possible to bring a math formula ...
4answers
6k views

### Is there such a thing as truly random? [closed]

I saw a video about random numbers and how the programmer in that video was talking about computers generating pseudo random numbers and that they are not really random. I knew about this. Then he ...
3answers
1k views

### algorithm to create all possible column vectors of size N containing only ones and zeroes [closed]

I am a mathematics student and am just starting to learn about programming. I am stuck on a particular program I am trying to write for fun. I want to find an algorithm to create all possible column ...
2answers
13k views

### Closest Point of Approach (CPA) mathematical formula in ship radar

I was recently searching for the mathematical formula to find closest point of approach (CPA) between one ship and another ship. I need to apply the formula in my radar ship program and I can't find ...
3answers
307 views

### Customer Requirements Contains Equations that Cancel to Nothing

I have a project where the customer requirement specifies a report and contains mathematical equations for the contents of some of the columns on that report. One of the columns on this report is a ...
7answers
1k views

### Is (1/(1/x)) always a perfect round trip?

Is the following guaranteed to return true for all numerical and non-zero values of x? bool IsRoundTrip(double x) { double y = 1 / (1 / x); return x == y; } What conditions would cause a ...
2answers
261 views

### Tracking scientific error when working with floating-point numbers

Background I hate the way .Net/IEEE-754 handles equality of floating-point numbers (FPNs) (i.e. double, float). It requires the programmer to be prescient with respect to the yet-to-be-determined ...
3answers
28k views

### what is a efficient way to find repeating decimal

I am trying to find a efficient algorithm in Java to find the repeating decimal part of two integers a and b where a/b. eg. 5/7 = 0.714258 714258.... I currently only know of the long division ...
3answers
519 views

### strategies for dealing with machine epsilon

Say you have a situation where you divide and then multiply a float, and you need to guarantee that it survives macheps (ie multiplication output equals division input). What are known strategies for ...
1answer
352 views

### I'm trying to create a visual representation of something, but I don't know what words to use, so I'll try to describe it

My project team is making a site that will use reddit style voting to track users' opinions on various issues, and use the data to create a "heat map". I say heat map in quotes because I'm not sure ...
2answers
159 views

### Randomness of wrapped RNG

There are plenty of questions around regarding random number generation, but I couldn't find anything that exactly matched my question. Apologies if I missed one. Most random number generators in ...
1answer
1k views

### Algorithm to detect a CLICK within Square range

It might be a simple question but I am looking for optimal solution. I will have numbers printed on a screen and I will be aware of coordinates. Numbers/Symbols will have 4 points(Square) to define ...
5answers
929 views

### Interview puzzle on traveling on a line segment

On a number line of length M, where 0 < M <= 1,000,000,000, you given N (1 < N <= 100,000) integer pairs of points. In each pair, the first point represents where an object is currently ...
1answer
128 views

### Turning n-dim points into m-dim where m<n and where point-to-point distance deviation is minimized

I want to apply k-means clustering to a (sparse) adjacency graph. For this I need to assign the nodes to a position in an euclidean space. Trivially I can do this by having a space with as many ...
1answer
183 views

### How to do scalar multiplication and matrix inverse when variables are of size 1000 bits?

I am doing arithmetic operations on really huge numbers. For example, I am given six variables, a_{11}, a_{12}, a_{21}, a_{22}, x_1, and x_2. Although the above are math terms, these six variables ...
1answer
3k views

### Randomly Generate Points in a Spiral Motion using Javascript

So I have a javascript program that currently gets random points, it generates a random x,y,z value around the center point, within the radius r var maxArms = 3; var i = 0; var color = []; ...
1answer
7k views

### How to get audio spectrum analysis? [closed]

I need to find or create a tool that analyzes the audio spectrum of a sound file (like a .wav or .mp3). I need to output the "volume" or power of x number of frequency bands and output the data as ...
2answers
11k views

### Find the new coordinates using a starting point, a distance, and an angle

Okay, say I have a point coordinate. var coordinate = { x: 10, y: 20 }; Now I also have a distance and an angle. var distance = 20; var angle = 72; The problem I am trying to solve is, if I want ...
3answers
2k views

### Date calculation algorithm

I'm working on a project to schedule a machine shop, basically I've got everything covered BUT date calculations, I've got a method called schedule (working on PHP here): public function schedule(\$...
4answers
1k views

### Separating merged array of arithmetic and geometric series [closed]

Given an array of positive integers in increasing order. Separate them in two series, an arithmetic sequence and geometric sequence. The given array is such that a solution do exist. The union of ...
3answers
4k views

### Calculating 3d rotation around random axis

This is actually a solved problem, but I want to understand why my original method didn't work (hoping someone with more knowledge can explain). (Keep in mind, I've not very experienced in 3d ...
10answers
42k views

### How to check if 4 points form a square?

Assume I have 4 points (they are 2-dimension), which are different from each other, and I want to know whether they form a square. How to do it? (let the process be as simple as possible.)
3answers
2k views

### how to programtically build a grid of interlocking but random sized squares

I want to create a two dimensional layout of rectangular shapes, a grid made up of random sized cubes. The cubed should fit together and have equal padding or margin (space between). Kind of like a ...
4answers
5k views

### Can you use Pi as a crude random number generator?

I recently saw this question over at math.SE. It got me thinking. Could Pi be used as a crude random number generator? I mean the results are well known(how long has pi been computed to now?) but, Pi ...
16answers
7k views

### Why use other number bases when programming

My coworkers and I have been bending our minds to figuring out why anyone would go out of their way to program numbers in a base other than base 10. I suggested that perhaps you could optimize longer ...
4answers
919 views

### Should Equality be commutative within a Class Hierachy?

It is easy to define the Equals operation in ways that are not commutative. When providing equality against other types, there are obviously situations (in most languages) were equality not being ...
1answer
376 views

### What's the normal way machine-learning algorithms are integrated into normal programs?

I'm currently taking a machine learning course for fun, and the course heavily focuses on Matlab/Octave to write the code. One thing mentioned in the course is that, while Matlab/Octave are great for ...
3answers
137 views

### Working with vectors and transformations

I am going to write an graphical 2D application that allows user to create polygons and transform them through transformation such as rotation an so on. I was hoping someone can give pro and cons ...
3answers
4k views

### Algorithm to calculate trajectories from vector field

I have a two-dimensional vector field, i.e., for each point (x, y) I have a vector (u, v), whereas u and v are functions of x and y. This vector field canonically defines a set of trajectories, i.e. ...
2answers
50k views

### How important is Discrete Mathematics for a Computer Scientist? [closed]

As the title says, How important is Discrete Mathematics for a Computer Scientist? Background: I'm pursuing a Master's degree with a focus on fundamentals such as Algorithms, Complexity and ...
2answers
385 views

### Dealing with units in arithmetic operations (multiplication and division)

I need to design a function to perform the basic arithmetic operations that are addition (+), subtraction (-), multiplication (x), and division (/) between 2 numbers. That function takes 3 arguments: ...
2answers
2k views

### Fractional and Cartesian Coordinates

I have a set of fractional coordinates. I also have a rotation matrix that operates on cartesian coordinates. Does anyone know how I could convert my rotation matrix so I can operate on the ...
3answers
2k views

### What Discrete Mathematics topics should the average computer science student know?

I know that Discrete Mathematics is a pretty broad topic that's used in a number of fields but I was just wondering what are some of the topics from it that you would expect an average computer ...
2answers
806 views

### 1 to 1 Comparison and Ranking System

I'm looking to create a comparison and ranking system which allows users to view 2 items, click on the one that they feel is the better one and then get presented with 2 more random items and continue ...
1answer
8k views

### Can one edit a built-in Python module?

I'm currently learning Python and I'm at the point in the book about using the Math library. I looked on the Python website and noticed the library was a bit scarce and am writing some more useful ...
2answers
371 views

### why is a naturally ordered set generated at 9 but not 10 digits

code found at: https://softwareengineering.stackexchange.com/q/158606/44933 Presuming that the problem indicated above is due to the test app and not due specifically to method generateRandomDigits()....
8answers
5k views

### How can calculus and linear algebra be useful to a system programmer? [closed]

I found a website saying that calculus and linear algebra are necessary for System Programming. System Programming, as far as I know, is about osdev, drivers, utilities and so on. I just can't figure ...
2answers
437 views

### Layout of mathematical views (iOS)

I am trying to figure out the right way to encapsulate graphical information about mathematical objects. It is not simple. For example, a matrix can include square brackets around its entries, or ...
5answers
40k views

### get weighted random item

I have, for example, this table +-----------------+ | fruit | weight | +-----------------+ | apple | 4 | | orange | 2 | | lemon | 1 | +-----------------+ I need to return a random ...
5answers
814 views

### Long term plan of attack to learn math? [closed]

I am a web-developer with a desire to expand my skill-set to mathematics relevant to programming. As 2nd career, I am stuck in college doing some of the requirements while working. I was hoping the ...
11answers
10k views

### Where is the application of Calculus (of continuous quantities) in Computer Science or programming [closed]

I am a Software Engineer professional. I have studied calculus as a core course in my graduation studies. I want to ask question, that what/where is the implementation of calculus in computer science?