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
1answer
147 views

Big-O Notation and Calculus [closed]

I was wondering if there are any calculus relationships implicit in Big-O notation. For example, an algorithm linear according to Big-O notation reduces the size of the problem by a constant amount ...
72
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 >= ...
47
votes
1answer
40k views

Treating a 1D data structure as 2D grid

I am working with a native class that represents a 2D image as a 1D array. If you want to change one pixel, for example, you need to now how to derive the index from the x,y coordinates. So, let's ...
2
votes
1answer
102 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
126 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
81 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
114 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
4answers
5k 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 ...
51
votes
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 ...
2
votes
0answers
201 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 ...
59
votes
5answers
17k 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 ...
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 ...
1
vote
3answers
1k views

Randomized Hash function with no collisions

Related to the question Which hashing algorithm is best for uniqueness and speed? Is there a way to create a hash function, or find one, whose hash length depends completely on the input length, has ...
-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
91 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 ...
11
votes
5answers
2k views

Are there any formalized/mathematical theories of software testing?

Googling "software testing theory" only seems to give theories in the soft sense of the word; I have not been able to find anything that would classify as a theory in the mathematical, information ...
-1
votes
1answer
113 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
117 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 ...
22
votes
11answers
2k views

How is fundamental mathematics efficiently evaluated by programming languages?

As I get more and more involved with the theory behind programming, I find myself fascinated and dumbfounded by seemingly simple things.. I realize that my understanding of the majority of fundamental ...
6
votes
5answers
3k views

Which programming languages doesn't use operator precedence besides Lisp like languages? [closed]

And what do you think about operator precedences? Would be harder programming in a language where the operations are executed in sequential order? Ex.: 2 + 3 * 4 == 20 2 + (3 * 4) == 14 Ok, Lisp ...
-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, ...
1
vote
1answer
505 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 = ...
11
votes
5answers
1k views

Does any programming language use variables as they're in maths?

In maths, a variable means you can put any number there, and an equation will still be true: root(square(x)) = abs(x) In programming languages, this is not so: a var can change. In Python: y = (x**...
-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 ...
9
votes
1answer
477 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 unums....
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 #...
-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
126 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
163 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
288 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
671 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 ...
7
votes
4answers
9k views

TEA algorithm constant 0x9e3779b9 said to be derived from golden ratio, but the golden number is 1.618?

I'm trying to understand a constant 0x9e3779b9. What kind of data is this? It's not binary, not decimal, what is this? It's a constant used on the TEA algorithm. It says it's derived from the golden ...
1
vote
1answer
1k views

Best way to define 'snap points' between two arbitrary objects in 3D?

I'm working on a simple in-browser 3D model constructor using THREE.js. The user picks a plane body, and adds wings, cockpit, tail etc of their choice, choosing from multiple options. I need to be ...
0
votes
1answer
128 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 = ...
-3
votes
1answer
254 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 ...
2
votes
3answers
844 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 ...
15
votes
4answers
11k views

Handling extremely large numbers in a language which can't?

I'm trying to think about how I would go about doing calculations on extremely large numbers (to infinitum - intergers no floats) if the language construct is incapable of handling numbers larger than ...
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
326 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 ...
8
votes
1answer
1k views

How to modify ELO algorithm when number of games is low to reduce outliers

I've developed the standard ELO implementation that can be found here, but the problem I'm running into is that my players will only have between 10 and 40 games in a "season". Since my first season ...
3
votes
2answers
231 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
94 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 ...
24
votes
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 ...
3
votes
3answers
2k 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: ...
36
votes
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.)
3
votes
2answers
568 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) ...