Questions tagged [math]
Programming questions that are significantly affected or best defined by the underlying mathematics of the problem.
285 questions
6
votes
4
answers
491
views
Why is there (practically) no 6-byte integer in common usage?
In Postgres, it used to be quite common to use a 4-byte integer auto field for primary keys, until it started becomming somewhat common to run into the 2147483647 limit of 4-byte integers. Now, it's ...
17
votes
11
answers
17k
views
Is it possible to build a system to generate UUIDs where every UUID is guaranteed unique?
Is it possible to design a distributed system to generate unique ids where there is a requirement that every generated id is guaranteed to be unique with no possibility of collision?
I didn't think ...
1
vote
1
answer
144
views
Ranking results from a Question and Answer game
I have a question and answer trivia game app which randomly picks questions from a database and prompts the user to answer the question correctly. The total number of correct answers, the total number ...
8
votes
7
answers
9k
views
What is the size of the number 65535 in bytes? [closed]
As I got to know there are 256 possible combinations to get for 1 byte. If I understand it correctly, it should mean that you can display any number out of numbers 0-255 and this very number would use ...
0
votes
1
answer
138
views
Understand implementation of exponential moving average (in case of unix load average)
The UNIX load average gives 3 numbers over 1/5/15 minute time intervals. It's supposed to be an indicator of how busy a UNIX machine is. The global load average is an exponentially decaying average of ...
2
votes
2
answers
131
views
Design a function that indicates significant deviations in response times
I'd need some feedback on how to approach the design of a function that highlights parts of a time series chart. The chart shows the response time of an application, in particular the 90th percentile, ...
4
votes
3
answers
256
views
Is it possible to store N bits of unique combinations, in N-1 bits? If not; why does MD5 get reprimanded for collissions?
Regarding cryptography and the issue of collisions, I posed a question as to whether it was ever possible to store every single possible combination of a bit array of a particular size, in a bit array ...
2
votes
6
answers
610
views
What is the viability of engineering an integral type with values ranging from -1 to 254? Do types like this even exist?
In software engineering, often developers will utilize three different states of a signed integer, as a trilean:
This tends to be quite typical:
-1 - Represents something akin to a null pointer, as in ...
2
votes
2
answers
879
views
How to use chebyshev polynomials to calculate exponents (antilogs)?
I am trying to write an algorithm to accurately calculate exponents (antilogs) for a variable precision floating point library I am working on. The base is not relevant since I can convert between ...
0
votes
5
answers
2k
views
Why is What Every Computer Scientist Should Know About Floating-point Arithmetic considered mandatory reading? [closed]
What Every Computer Scientist Should Know About Floating-point Arithmetic is widely considered absolutely mandatory reading for every programmer. Why is this the case? What aspects of the article make ...
7
votes
2
answers
630
views
some misunderstanding in concept of Huffman algorithm
What is difference between Average length of codes and Average length of codewords in Huffman Algorithm? is both the same meaning? I get stuck in some facts:
I see a fact that marked as False:
for a ...
2
votes
0
answers
218
views
What algorithm can I use to spread a workload between two processor with fixed resources?
I need to write an algorithm to allocate x number of tasks to 2 processors per day.
I know the following:
Exact amount of time it will take to complete each task
The exact amount of time available ...
-1
votes
1
answer
615
views
Is there a term for "shift towards zero"?
In pseudo code: given numbers x and y, if x is greater than zero, subtract the magnitude of y from x, otherwise add the magnitude of y to x. It's ok if x goes from being positive to negative or vice ...
-1
votes
5
answers
2k
views
Why is converting 0-indexed code to 1-indexed code non-trivial?
The disadvantages of 1-indexing are well-known. However, our hand is sometimes forced by our choice of language and we have to convert algorithms that were intended for a 0-indexed language to being 1-...
4
votes
3
answers
688
views
Why do computer scientists seem to avoid closed-form solutions to mathematical problems?
There are many instances of software developmet where we seem to solve problems differently than from a mathematical perspective. For instance, consider the classical example of calculating Fibonacci ...
1
vote
4
answers
1k
views
Is using multiple UUIDs decrease chance of collisions exponentially?
For example if you have a single UUID with a collision probability of x, if you concatenate 2 UUIDs, does the collision probability become x^2?
val0 = generate_uuid()
val1 = generate_uuid()
final_val ...
3
votes
1
answer
212
views
Integrating TeX into a Java desktop application
Looking to integrate TeX equations in a TeX-agnostic fashion, suitable for either ConTeXt or LaTeX, into a Java-based desktop Markdown editor. The possibilities are numerous, but I'm not sure what ...
4
votes
2
answers
1k
views
How to show fluctuating data smoothly and accurately?
I am working on a project in which I have to read data from liquid level sensor installed in tank which measures fluid level and sends output in millivolt. The device has predefined ranges of voltage ...
-3
votes
1
answer
62
views
Should absolute value functions be overloaded to give the norm of vector-like data structures?
The absolute value function is an instance of the norm function in one dimension. I've seen instances of libraries where the absolute value function is overloaded to also take the norm of higher ...
-5
votes
1
answer
83
views
What is the difference between BigInt and "Computer Algebra System" integers?
Obviously I imagine a CAS does more than BigInt does. But I'm wondering if there is a difference in implementation between BigInt integers and CAS integers (whatever they may be, symbols?).
Wondering ...
0
votes
2
answers
139
views
How to minimize size of data given the need for a null pointer?
So I don't know how to formulate this clearly, as it's quite confusing. Hence the reason for asking this question, to overcome the confusion.
I will do my best to make it clear, but part of the ...
1
vote
2
answers
57
views
Suitable way to round results returned by any function of a class
Assume there is a class Shape. The class has two functions area() and perimeter().
Let's say Circle and Square inherit from Shape and override these methods. Obviously the results are going to be ...
-1
votes
1
answer
56
views
Resolving Dependencies and Incompatibilities Deterministically
Problem Description
I'm working in Python and I've been having a problem designing something to handle the following (abstracted) system:
I have some objects (lets call them Nodes) that can be in ...
2
votes
3
answers
137
views
Is there a way to specify a two-way relationship between variables?
Let's say we have two variables, eta and phi related by eta = cos(phi).
Is there a way to link these variables in any programming language such that there's no need for two different functions, ...
1
vote
2
answers
1k
views
Loan Amortization Schedule - Precision and rounding
I have been playing around making amortization schedules in PHP. My php.ini currently has the precision set to 14. I understand going into this that there will be rounding errors however I am hoping ...
25
votes
4
answers
6k
views
Why is the norm of a complex number in the C++ complex library actually the square of the norm?
In the C++ complex library, the method norm() of a complex number actually returns the square of what I have learned is usually called the "Norm".
Reference: std::norm
For example, std::norm() of (3,...
7
votes
1
answer
636
views
Smallest Rubik's cube state representation
I'm trying to determine what is the fewest number of bits I need to represent the state of a Rubik's cube. (EDIT: I am assuming the cube is a valid Rubik's cube that has not been altered and only ...
4
votes
3
answers
498
views
How to do grid systems with floats given precision causes problems
I've been trying to create a grid system that can use any grid size and start at any given anchor point rather than always at 0,0.
The problem however is imprecision makes it impossible, even the ...
-3
votes
2
answers
1k
views
How can I calculate the radius of an arc given by a series of points
Given a series of points, I need to assert that the plotted points form an arc (with a certain level of confidence), and I need to approximate the radius of the arc.
For example, the following points ...
-3
votes
2
answers
138
views
Seeking appropriate design pattern(s) to describe most function-based mathematical problems
I have been looking for a good, general design pattern to implement simple mathematical structures where functions have the following properties:
know which parameters they contain, parameters are "...
2
votes
1
answer
295
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 ...
2
votes
1
answer
341
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 ...
2
votes
3
answers
690
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
1
answer
1k
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
1
answer
76
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
1
answer
311
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
0
answers
1k
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....
4
votes
4
answers
280
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
1
answer
98
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
1
answer
956
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
1
answer
1k
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
1
answer
141
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
1
answer
83
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 ...
0
votes
1
answer
57
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, ...
75
votes
10
answers
30k
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
2
answers
271
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
3
answers
234
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
2
answers
246
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
1
answer
990
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
1
answer
2k
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 ...