Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [math]

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

2
votes
1answer
92 views

Generic way to describe data synchronization between systems?

Is there a generic way (useful formalisms) to think about data synchronization between two systems, especially in the case of slightly asymmetric roles (eg, one system contain master data, another one ...
3
votes
3answers
124 views

What effects does memory space have on bitwise shifts?

It is true that the bitwise left shift operation (shl) doubles the value of the integer being shifted. However, when constrained to a finite space, such as 8 bits for example, left shift will begin to ...
0
votes
1answer
60 views

Gerstner Wave equation from tessendorf paper, mesh penetrates itself

I have been learning to create water waves in a mesh from a paper commonly known as the Tessendorf paper. Which is quite well known. But those who don't know this is the equations it mentions in the ...
0
votes
1answer
62 views

Best way to encode a queryable number to another unique queryable number? (database outsourcing)

So lets say you want to outsource your database to a third party and be able to query on it on their server but you want to "encode" the salary column of the users on their server, aka hide the real ...
0
votes
1answer
105 views

Find two horizontal lines to minimize distance to scattered points

I am having trouble with a coding question that I found practicing for a interview: A scatter graph of points on a page, draw two horizontal lines (these lines are parallel) across the page such that ...
2
votes
0answers
179 views

Division by zero Java [closed]

The behavior of Java is explained in this topic. But, is Infinity useful for something? Float: public class DivisionByZeroFloat{ public static void main(String[] args) { System.out....
3
votes
4answers
136 views

How to properly decide what is the appropriate rounding off error for a mathematical function?

In the space of 3D geometry, I need to compute the magnitude of the cross product of two Line3D because I want to check whether these two Lines are "parallel" to each other. Line3D is consisted of 4 ...
-2
votes
1answer
87 views

Where are mathematical equations applied in the application stack [closed]

Say I have a program using Java or C, that will interface with a hardware device and either read streaming data or write it to a database before applying a few complex mathematical equations to this ...
1
vote
1answer
82 views

How do I create a comparable checksum of a number sequence?

Sorry if the title is confusing, but here's an example to illustrate what I'm trying to accomplish. I would like to create a 'checksum' or ID grouping of similar number sequences, so that when you ...
-1
votes
1answer
102 views

Interdependent variables

Let's say there are two variables a & b, both a & b would have a value between a predefined range. a = x1 to y1 (range) b = x2 to y2 (range) Variable a & b are interdependent, if the ...
0
votes
1answer
116 views

How a Proof Assistant Proves ∀ or ∃

Wondering how a proof assistant such as Coq proves forall or exists. For example: Three aspects: If you were to give it a huge set of items like a million, wondering if it would actually iterate ...
-3
votes
1answer
67 views

Identify sets differing by one

I have a set of objects with different attributes; e.g. a set of cars with colors, brand etc. I choose subsets by virtue of a specific set of attributes. Now I want to identify pairs of such subsets ...
1
vote
1answer
43 views

Algorithm: Identify same Outlets / Supermarkets

We have a database with stores Outlets / Supermarkets (mainly in germany but other countries are also possible). We store some informations of this outlets / supermarkets like name, street, ...
68
votes
9answers
14k views

Is it good practice to replace division with multiplication when possible?

Whenever I need division, for example, condition checking, I would like to refactor the expression of division into multiplication, for example: Original version: if(newValue / oldValue >= ...
-3
votes
2answers
260 views

How to model infinite non-linear combination? [closed]

Let L be an ordered set of positive integers (for example, the set of all primes). Here, #L = infinity, and N is a positive number serving as an upper limit. Goal is to list the following set M: M =...
0
votes
3answers
121 views

Use case, design, and how to append to an immutable object in functional programming

This is not (supposed to be) an opinion question, but it is a newbie question, so if there is just a resource I haven't found that I need to read, point me there :) I am in the design stages of a ...
2
votes
2answers
162 views

Handling behavior of non-finite numbers

Without using big int classes in C++, what's a good way to handle arithmetic on large numbers? For instance, writing a Vector class that deals with dot products and cross products using large ...
0
votes
1answer
255 views

Round robin, balanced home/away, multiple locations with multi-team options

This is my first question on this forum, have tried to exhaust every possible research option I could think of or find. Actually this is the first time I've posted for help with this anywhere, so ...
-3
votes
1answer
624 views

What's the needed math for building algorithms? [closed]

What's the needed math for building algorithms? Because I was reading a book and I can't understand much. It says I need simple math from high school. I don't want to learn all the math that exist ...
-3
votes
1answer
240 views

I loved developing a 2D game(C++ SDL), but i am not good at maths/physics [closed]

I developed 2 games in C++ using SDL. Without using any wrappers. I literally loved and enjoyed every part of the journey. Complex algorithms, how 2D works, rendering, audio, input etc. But i am not ...
-6
votes
1answer
71 views

Set of items closest to the mean? [closed]

Given a set of N objects with assigned weights, how would we find the set of K objects that is closest to the average? The average being sum(weights) / N. Also, how could we compute the next set ...
0
votes
1answer
120 views

Memoization in case of recursive interdefined functions in Haskell/Functional Programming?

I was reading Memoization with recursion which tells how for a recursively defined function fun we can do memoization by: -- Memoization memoize f = (map f [0 ..] !!) -- Base cases g f 0 = 0 g f 1 = ...
2
votes
3answers
811 views

In Java, why does Integer.MIN_VALUE == -Integer.MIN_VALUE

Quite simply, I was aghast when I discovered one of my unit tests was failing because -Integer.MIN_VALUE == Integer.MIN_VALUE! Why would the language designers choose this, what is the mathematical ...
0
votes
1answer
79 views

How is the problem NOVICE43 on Sphere Online Judge(SPOJ) related to Bell Numbers?

Problem Statement : When I first learned backtracking I made a program to find all the permutations of the English alphabets in lexicographically increasing. Filled with elation I showed the ...
6
votes
3answers
323 views

What's the proper class hierarchy to use for matrices?

I'm working with particular classes of matrices which admit fast operations without resorting to dense linear algebra. To keep the heierarchy simple, I'm currently doing the following (greatly ...
3
votes
2answers
212 views

How do I unit test nuanced mathematical procedures?

I'm writing some code for a scientific simulation and I'd really like to use this as an opportunity to get some unit testing practice under my belt. I understand the idea of tests in theory, but I ...
2
votes
1answer
92 views

Find transformation function for point on an image

I am trying to develop an algorithm, but I barely can describe it so I'm not sure what to look for. I have two images img_A and img_B. img_A is the original, while img_B is an image of the same item ...
1
vote
1answer
484 views

Algorithm for windowed online covariance

I'm trying to adapt an algorithm to calculate covariance to work over a rolling window on the data. Wikipedia has an algorithm for online covariance: def online_covariance(data1, data2): mean1 = ...
19
votes
6answers
5k views

What is the mathematics foundation for first/second/third class values in programming languages?

Added Just found two related questions https://math.stackexchange.com/q/1759680/1281 https://stackoverflow.com/a/2582804/156458 In programming languages, from Michael Scott's Programming Language ...
30
votes
1answer
2k views

Why was the caret used for XOR instead of exponentiation?

Not that it's really a problem for anyone that has faced this syntactic issue before, but I see a wild amount of confusion stemming from the use of the caret (^) as the XOR operation in lieu of the ...
0
votes
1answer
410 views

Calculate largest square in rectangle with a given vertex

There are two points (x1, y1) and (x2, y2), each of which can be any real integer pair. These define a rectangle R with vertices {(x1, y1), (x2, y2), (x1, y2), (x2, y1)}. The rectangle exists in a ...
0
votes
1answer
106 views

Return random item by its weight, advanced level

There are many typical questions like Return random `list` item by its `weight` Imagine more advanced problem. You have N sources of pair (item_id, weight) information. Let's call them Shards. ...
-1
votes
1answer
237 views

C++ Basic Rotation Question

I've got a problem and I haven't yet found an explained solution to get it drilled into my head: I want my object to make a basic rotation TOWARDS the mouse cursor, not the lock-on. I know it must be ...
0
votes
1answer
534 views

How can I create a set of pixel coordinates for a line in Python?

I've got some code that's searching pixel by pixel from a starting point, at a certain angle, until it finds a pixel (a non-white pixel) It only has to search around 300 pixels: I'm currently using ...
4
votes
4answers
1k views

Why are arbitrary-precision decimals used over rational numbers in practice?

The basic arithmetic a computer chip can do only works on numbers(integers or floating point) of a fixed size. There are many algorithms that could be extended to work on numbers of arbitrary size (...
-3
votes
3answers
1k views

How to use units for a slope calculation?

Simple question: is the result of a slope calculation in Python (say, stats.linregress() function) in units of radians, or unitless (e.g. what's 18 deg or 0.314 rad would be equivalent to 0.2 in the ...
2
votes
4answers
993 views

Storing a straight line equation

How to store a straight line (infinite length, not a line segment) efficiently? This is not a duplication of How to represent a geometric line programmatically?, because the linked question is about ...
1
vote
0answers
124 views

Choose “representative” subset out of a set of points

So I have a set of given locations (i.e. two-dimensional points) G, a set of wanted locations W and a natural number N. Assume |W| < N. I want to choose N elements of G such that the elements of W ...
1
vote
2answers
136 views

Can I find the remainder more efficiently?

Here : https://github.com/gnufinder/prime-factor I submitted a contribution with the goal to find a prime factor of the number 2222+3333. The number has 3,638,334,640,025 digits, so ECM will take ...
4
votes
1answer
1k views

Swapping variable values without creating a new one

Recently, I was faced with a question that asked me to swap variable values without creating an extra variable. i.e. A = 10, B = 20. How store 20 to A and 10 to B? The solution is: A = A + B #...
2
votes
1answer
212 views

Optimizing the exponential smoothing of a big array

I have a large set of values (let's say 1M entries) where I need to apply an exponential smoothing algorithm, but only incrementing one value at a time (all others decay to zero). The trivial ...
0
votes
1answer
273 views

Achieving permutation using recursion [closed]

Though I like recursions and understand it, I fail to master it! I am stuck with a problem which I know that recursion can solve, but I do not know how. I have an array of strings like: "hundred", "...
-2
votes
3answers
2k views

How to create an algorithm for a raffle, where each raffle guarantees a winning ticket?

I am looking for an algorithm to create a raffle, where each participant is assigned a ticket with a random series of numbers. Each raffle hast N participants, and there should exist same amount of ...
3
votes
2answers
503 views

How to improve timeout value dynamically?

I'm working on an application where I want to keep a timeout value computed dynamically using a moving average of say 100 previous response times for service A. This value + some buffer (~3 seconds) ...
7
votes
4answers
4k views

Convert version string to integer

I need to be able to convert a version string to an integer. I've decided I will follow semantic versioning so version strings will be of the type x.y.z. Initially I thought a simple algorithm like ...
1
vote
1answer
133 views

Question about the uses of matrices in games and 3D graphics [closed]

So I know that matrices are used extensively in the field of games and 3D graphics, for example, you need to know how to do matrix multiplication if you want to understand how scaling an object works, ...
1
vote
1answer
104 views

Simplistic non-secure example of public key encryption

I'm giving a lecture to novice developers on security and would like to explain ssl and the basics of certificates. For this I would like to convey a vague intuitive understanding of asymmetric key ...
59
votes
5answers
16k views

Will a computer attempt to divide by zero?

We all know 0/0 is Undefined and returns an error if I were to put it into a calculator, and if I were to create a program (in C at least) the OS would terminate it when I try to divide by zero. But ...
0
votes
1answer
187 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 ...
9
votes
2answers
400 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 ...