Questions tagged [math]

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

Filter by
Sorted by
Tagged with
-2
votes
0answers
11 views

How to efficiently move the decimal point in a number until reaching some threshold [migrated]

Say I have a double x, whose value is > 0 and < 1 million. I want to move its decimal point left until it is > 1 million and < 10 million. So for example, 23.129385 becomes 2313938.5. What I'm ...
2
votes
1answer
98 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
65 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
109 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
190 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
138 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
86 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
107 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, ...
71
votes
10answers
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
261 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
124 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
266 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
648 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
243 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
124 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
827 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
80 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
219 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
93 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
492 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 ...
31
votes
1answer
3k 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
428 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
107 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
238 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
541 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
997 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
125 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
137 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
216 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
274 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
534 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
135 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
106 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
188 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 ...