Full multiplication when you can only halve and double

  Рет қаралды 614

So Much Code

So Much Code

Күн бұрын

When I was shown this math trick as a child, little did I know that it would come in handy in the future for creating an esoteric programming language!
Support me on Patreon: / timwi
Page on Esolangs wiki: esolangs.org/wiki/Funciton
Interpreter on GitHub: github.com/Timwi/Funciton
00:00 A long time ago...
00:20 The multiplication trick
01:43 What Funciton operations can do this?
03:08 Planning the algorithm
04:48 Writing it in Funciton
06:36 The (perennial) problem with negative numbers
07:45 Writing the fix for negative numbers
09:14 New syntax: private functions
09:57 Testing
10:24 Exploring an alternative fix for negative numbers
11:28 Comparing the performance of both
12:09 Exploring a third fix for negative numbers
12:49 Responding to a comment on the Increment function
13:31 Why the trick works: comparing it with long multiplication
16:08 Why the trick works: mathematical proof
18:03 My challenge to you

Пікірлер: 11
@harinathrao1
@harinathrao1 16 күн бұрын
The video are great
@pinecubes
@pinecubes 15 күн бұрын
such a clear explanation and interesting problem :) im going to try to use this technique to implement multiplication on a redstone ALU
@MrSquares
@MrSquares 9 күн бұрын
Anyone else notice how he kind of looks like the Grinch? (Love the vids btw)
@gerocastano8
@gerocastano8 11 күн бұрын
I would write the division as: a / b = (0, a), if a < b else let q, r = (a-b)/b return (q+1, r)
@TimwiSoMuchCode
@TimwiSoMuchCode 11 күн бұрын
Interesting! At first glance I think your idea would give the correct answers. However, if I’m not mistaken, it would be an exponential-time algorithm. In my next video, I show an algorithm that relies on shift-right, thus ensuring linear time complexity.
@gerocastano8
@gerocastano8 11 күн бұрын
Why would it be exponential? The argument is always decreasing by at least 1 (we could separately implement division by zero errors and negative inputs), so it is at least linear time in the worst case. In general the time complexity would be O(a/b)
@TimwiSoMuchCode
@TimwiSoMuchCode 10 күн бұрын
@@gerocastano8 Yes, and O(a/b) is exponential time, because it’s in the ballpark of O(2ⁿ) where n is the number of bits in the input. My algorithm is linear time, that is O(n), where n is the number of bits in a. I did a brief summary of this in the subtraction video at this timestamp: kzbin.info/www/bejne/n3PQaaGgapaFopo
@gerocastano8
@gerocastano8 10 күн бұрын
@@TimwiSoMuchCode oh, you’re accounting also for the number of bits. In that case, yes, my algorithm is exponential. I was just assuming that subtracting numbers was a constant operation.
@TimwiTerby
@TimwiTerby 10 күн бұрын
@@gerocastano8 Your algorithm is still exponential even with that assumption. You are subtracting a/b times, and a/b is exponential in the number of bits in a.
How division and modulo are intricately linked
22:53
So Much Code
Рет қаралды 440
When subtracting numbers makes an INFINITE LOOP
20:20
So Much Code
Рет қаралды 350
Joven bailarín noquea a ladrón de un golpe #nmas #shorts
00:17
Can You Draw The PERFECT Circle?
00:57
Stokes Twins
Рет қаралды 80 МЛН
A programming language... made of BOXES?!
39:12
So Much Code
Рет қаралды 407
Binary Exponentiation
15:13
Errichto Algorithms
Рет қаралды 94 М.
Strings are integers
42:56
So Much Code
Рет қаралды 40
An Introduction to Mathematical Proofs
9:41
zeropercent
Рет қаралды 71 М.
Square & Multiply Algorithm - Computerphile
17:35
Computerphile
Рет қаралды 272 М.
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36
Sahil & Sarra
Рет қаралды 581 М.
ChatGPT Can Now Talk Like a Human [Latest Updates]
22:21
ColdFusion
Рет қаралды 510 М.
Как открыть дверь в Jaecoo J8? Удобно?🤔😊
0:27
Суворкин Сергей
Рет қаралды 1,6 МЛН
Fiber kablo
0:15
Elektrik-Elektronik
Рет қаралды 7 МЛН
Он Отказался от БЕСПЛАТНОЙ видеокарты
0:40
ЖЕЛЕЗНЫЙ КОРОЛЬ
Рет қаралды 2,1 МЛН
🤖Вернулись в ПРОШЛОЕ🤪
0:28
Demin's Lounge
Рет қаралды 111 М.