# Tag Info

Accepted

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

Two common cases to consider: Integer arithmetic Obviously if you are using integer arithmetic (which truncates) you will get a different result. Here's a small example in C#: public static void ...
• 26.6k
Accepted

### Why was the caret used for XOR instead of exponentiation?

Although there were older precursors, the influential French mathematician Rene Descartes is usually credited for introducing superscripted exponents (ab) into mathematical writing, in his work ...
• 1,306
Accepted

### What is the size of the number 65535 in bytes?

TL;DR The key takeaway here is that there is a world of difference between the number 65535 and a piece of text which represents the digits '6', '5', '5', '3' and '5'. It may look the same to you when ...
• 52.7k

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

There isn't any, and it's pretty arbitrary. The only useful distinction is between first class, and all others. Every case that's in the "other" bracket has its own distinct set of rules in each case ...
• 36.9k
Accepted

### Why is the norm of a complex number in the C++ complex library actually the square of the norm?

This is not a C++ library issue but a question of mathematical terminology. In mathematics, a norm can mean different things: What you call norm is the Euclidian norm, which is the distance to the ...
• 78.7k

### Is it possible to build a system to generate UUIDs where every UUID is guaranteed unique?

there is a finite number of ids which can fit into some structure Correct. If you have n bits in your structure, after you have generated 2^n IDs, the next one must be a collision; this is the ...
• 24.4k

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

I like your question as it potentially covers many ideas. On the whole, I suspect the answer is it depends, probably on the types involved and the possible range of values in your specific case. My ...
• 351

### Why is the norm of a complex number in the C++ complex library actually the square of the norm?

Christophe's post, whilst fully correct, does not actually answer the question why the terms look like they do. To give you definite answer for the reasons, you would have to ask someone from the C++...
• 210k

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

No. I'd probably call that premature optimization, in a broad sense, regardless of whether you're optimizing for performance, as the phrase generally refers to, or anything else that can be ...
• 15.1k

### Is it possible to build a system to generate UUIDs where every UUID is guaranteed unique?

You want version 1 UUIDs. They don't collide but they leak the generating computer's MAC address and require a monotonic clock. From RFC4122 we have this format 8 bytes time-low 2 bytes time-mid 2 ...
• 1,664
Accepted

### Why do computer scientists seem to avoid closed-form solutions to mathematical problems?

Why do we implement Fibonacci numbers naively using its definition instead of using the explicit formula https://brilliant.org/discussions/thread/the-explicit-formula-for-fibonacci-sequence/. We don'...
• 104k
Accepted

### Is it possible to store N bits of unique combinations, in N-1 bits? If not; why does MD5 get reprimanded for collissions?

Of course, the pigeonhole principle states that colisions are inevitable for hashing algorithms. The point of hashing algorithms is not to prevent colisions. But to make intentional collisions ...
• 37.5k

### Is it possible to build a system to generate UUIDs where every UUID is guaranteed unique?

Is it possible, when K different hosts are generating IDs? Yes. And we can do it with readily available libraries. ULIDs do a pretty good job already, but they're not collision free. It looks like the ...
• 7,600

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

Use whichever one is less buggy and makes more logical sense. Usually, division by a variable is a bad idea anyway, since usually, the divisor can be zero. Division by a constant is usually just ...
• 8,112
Accepted

### Swapping variable values without creating a new one

That is a longer and less efficient variant of XOR swap algorithm. I'll just reiterate most-commonly known solutions here from the wiki: # solution 1 A = A + B B = A - B A = A - B # solution 2 (^ is ...
• 304

### Is it possible to build a system to generate UUIDs where every UUID is guaranteed unique?

It is easy enough, but require some degree of coordination. The general scheme is relatively simple: partition the bit-space of the ID in two sections, one with a "generator ID" unique to ...
• 15.1k

### Interdependent variables

As you describe it, b is not a variable at all. Instead, it is a linear function of a. The solution is to create a method that computes the value for b from a and use it wherever you were going to ...
• 110k
Accepted

### Storing a straight line equation

The equations can be all rewritten into form : a*X + b*Y + c = 0 That means you can store three doubles a, b and c. This doesn't have a problem in representing an arbitrary slope. You can also ...
• 37.5k
Accepted

### Smallest Rubik's cube state representation

You can encode the 8! possible permutations of the corners in 16 bits, and the 12! possible permutations in 29 bits, by numbering the permutations from 1 to 8! (or 1 to 12!), and storing the number. I ...
• 210k
Accepted

### Integrating TeX into a Java desktop application

I have no experience with those specific libraries and tools, but since you asked this here on SE.SE, let me give you an answer on how to approach such an evaluation process as a software engineer. It ...
• 210k
Accepted

### Why is What Every Computer Scientist Should Know About Floating-point Arithmetic considered mandatory reading?

Why is this the case? What aspects of the article make it stand out as still being important to this day? This part all sounds terribly opinion-based. Upon my reading of it, I found that a lot of is ...
• 12.6k

### What is the viability of engineering an integral type with values ranging from -1 to 254? Do types like this even exist?

You're taking the use specifically of -1 too literally here. APIs like this didn't really pick -1; they're either picking any negative number, or they're picking an integer with all of its bits set (...
• 12k

### What is the size of the number 65535 in bytes?

There are likely several variables at play here, but 65535 is 5 characters. 1 byte per character = 5 bytes. Text editors don't have a notion of what a number is the same way that your code does, so ...
• 5,498

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

One reason might be simply that programmers are more used to decimal number representations, or that their arbitrary-precision library does not support rationals. Another reason might be an additional ...
• 227

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

Denotational Semantics provides a mathematic bases for describing how values and variables works in a programming language. It was explained so well in my Computer Sci Degree that I got a top mark ...
• 4,603
Accepted

### How do I unit test nuanced mathematical procedures?

Tests are always just examples – they can never prove correctness. But even if the test space is vast we can extract a lot of value a few from well-chosen examples. Many inputs are basically ...
• 135k
Accepted

### How a Proof Assistant Proves ∀ or ∃

In general, #2. The language takes the declared initial states and uses Boolean logic transitions to make sure that there are no contradictions in the interactions between all of the rules defined. ...
• 109k