New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[QUESTION] Bypass Math Overflow for Large Computations #66
Comments
Hello, Thank you for the compliments!
It depends. On the particular example you gave, my machine did not give the error. (I am running an The error happens in this case because For example, I started running the example calculation you gave seven hours ago, and it's still going. The other reason is that the exponent needs to be converted into an By the way, this is also the reason that exponents need to be integers. Anyway, one way to get around the limit would be to get a computer with a 64-bit As an example, here are the limits for my machine (found by the
There are two to notice:
However, if I tell my
Then the limits look different:
Now, there is still a way around it, but it requires some math knowledge. You must know one fact: In essence, if you multiply two powers of one number, the effect is the same as adding the exponents of those powers and then calculating the power from the sum of those exponents. Usually, you would want to just add the exponents and then calculate the power because multiplications would be much more expensive. However, in this case, we can do the opposite: split the exponent (13256118217109) into several numbers and then multiply all of those numbers together. Let's decide on one exponent to use, which I'll call It will all look like this (in
But even then, we can make it faster. Since we are just multiplying the value by itself many times, we can use power again. This time, the exponents (3086 and 6172) are back within limits, so we're safe. If we do that, we get:
And that should give us our answer. We should set those exponents as best as we can to make it as efficient as possible. I know that my So if I set one of the powers to An exponent of 6172 has the same amount of 1 bits as 3086 (it's just 3086 times 2), so it will require only one more multiply. However, That gives us this code:
I haven't tested the above code because it will take forever. If there are problems, please let me know.
My This is because my Also, since it's taken seven hours on my You may want a benchmark with a smaller exponent. |
First of all, I just want to let you know that you're really, really amazing. The passion that you've for your project(s) and for the people that interact with them is something that melts my heart. I hope one day I can be a programmer as good as you and also, more important, have the same amount of passion that you have. English is not my primary language, so this may not make any sense.
I'm using a x64 Windows Machine, that's the reason, so. I'll start compiling your
I knew that, but somehow I didn't think about it. Thanks for the recap.
Well, that's kinda "chinese" to me. I'm not as good as you to understand that low-level programming stuff
I'll. On another topic, I'm using your tool to keep track of my expenses. Before closing this issue, I would like to ask you if there is any way that I can use "import" statements in your I know that I can work with more than one file at the same time using the My goal (if that can help you answering it) is to have a single file with functions/operations and then a bunch of other files only with data (expenses and gains) - like a local mini database - that I can call in the "main" |
Thank you for your compliment! Just so you know, I have not always had this passion. But I firmly believe that software is meant to serve people. That's why I focus so much on helping others. It makes me really happy that you noticed!
Yeah, sorry about that. Windows is dumb in that they decided that the
I apologize. I'll try again. Under the hood, However, that is not optimal. I did that because Julia uses base 2. This means that each "digit" can store more, which means the numbers are smaller (in number of digits). And smaller numbers mean faster execution. I hope that made sense.
I admit that's terrifying to me. I mean, technically, it should be safe, as long as you don't do any division or modulus in your scripts. But I don't want to screw up your finances with I hope you remember there's no warranty. If there is a bug, I'll try to help, but I can't guarantee that your financial records will be correct in the presence of bugs. I will guarantee, though, that I know of no bugs. I have fixed all of the ones I am aware of.
Sort of.
Well, that's the only way. Actually, it's even simpler than that.
And This means that anything in This means that you can chain together scripts in a way that acts like import. Sort of. If you would only import at the top of a file. Basically, this would mean that if
at the top of I do this myself; I have a math research project, and when I get new ideas, I start a new script. But I have all of my common functions in a
This even works for global variables; if you set a variable So if I were you, I would have a
and so on. Then, in the last script, I would have the code to actually update the database, but instead of directly updating, I would have it print the new "version" of Then you would run it like this:
Then check that
To make the example more concrete, let's assume that you have a
Then perhaps you have a
Then you have a
Then running the following:
will print:
which if you redirect to
will make (While it may be safe to redirect straight to
I think I answered according to your goal. I hope that helps, but please come back with any questions you have. |
Hi. Sorry for the delay replying.
Of course. I'm lacking motivation for programming - even in my university project (I'm currently in my last year of my master degree) -, specially now with all the improvements made in the IA field, but reading your blog posts and messages like this one, somehow, gives me motivation to continue. I would like to suggest, if possible, a way to interact with you in your blog (like a comments section, for example).
It did. I studied it in my first year at university, but I didn't know that specifically, so thank you.
And that's all that matters for me. There is nothing that compares to the support that you offer.
You did. Thanks again for the time spent on this. I use a different set of files, but the information that you gave me is going to help me improve my system. So, thanks (one more time xD). |
No worries!
Oh, cool, what is your project? (I dropped out of a Master's; I'm kind of jealous.)
I have thought about this many times and have always rejected the idea due to the amount of spam-busting and moderation required, at least as told by other bloggers. Oh, and I don't want people to see a buggy site if they have JavaScript turned off as comments nearly always require JavaScript. However, your suggestion has made me look at it again, and I had an idea. One of the best pieces of software, at least for forums, is the software underpinning https://lobste.rs/. While I have been banned from that site, I appreciate the software for its moderation capabilities. This includes invite-only registration, which would help a lot to only allow people who want to interact with me and others in a good way. I've also always wanted to run a forum site where Free Speech was honored as much as possible because I think Free Speech is necessary to find the truth. So in response to your suggestion, if the lobste.rs software will work for my purposes, I'll spin up an instance at https://forum.gavinhoward.com/ (or something similar), and I'll send you an invite, along with anyone else whose opinions I trust. And every time I post something new, I'll put it on the instance and link to it from the post. That should allow me to have a "comments section" while not interfering with my current site. I think I'll also allow others to post stuff too. Maybe I'll make its theme to be anything that is intellectually stimulating. I don't know; I'm just spitballing here.
You're welcome!
Thank goodness!
You're welcome! And thank you. I am overjoyed to hear this, actually. I'm starting a business right now, and my product is support for Open Source software that I have written. I was wondering if that would be a good product, but if my support is good, it might work. So I'm thrilled that you think so! (Don't worry; I'll always support Full disclosure: this is also why I took your suggestion for a comments section more seriously; it would be a good way for me to network with potential clients. I apologize for having less than perfect motives. Also, to take it one step further, can I point to this interaction we had as an example of the support I will give? I think it would be great material to advertise with. No offense if you don't want that though; I know that's a selfish motive.
You're welcome! Glad I could help! |
You don't need to be. You seem to have the required knowledge to be a teacher on my university. I'm from Portugal, btw. My project is about telemetry. I'm building a telemetry solution using OpenTelemetry and multiple analysis backends for a health company. The problem is that such project is inside DevOps field and that's not my expertice or even the field that I want to work on. I want to be a programmer, a system programmer to be more precise.
That seems a good way to implement it. I didn't know about that specific website, but after a brief usage of it, I can say that I liked the way that it works.
That makes a lot of sense. I appreciate the consideration for my opinion xD When that instance is online, let me know, please.
I see.. something like the commercial support that Daniel Stenberg offers for cURL?
That's nice to read. I'm planning to use
It wasn't necessary to make that disclosure. You're too kind just for considering having to do it.
Of course you can. I'm flattered to be part of that.
You always do. Thanks (one more time)! |
Ouch. I feel for you, and I feel lucky. I know this may not help, but I have personally found that my system programming skills (dev) got better after I learned system admininstration (ops). System administration is important to me for another reason: without it, I can't host my code or the forum that I mentioned. Once you get your Master's, maybe you can try to do what I have done: build excellent system software and support it. That may give you the room you need to make it a career. If it is going to work for me, it will surely work for you too!
It's up at https://forum.gavinhoward.com/, but email is not working, so I need to wait. Please send me an email using the email listed at https://gavinhoward.com/contact/, and I'll send you an invite once email is working.
Yes, basically.
Thank you! |
Sorry for the delay replying (again).
I hope you're right.
I'm trying to learn Rust on my free time, but it's been hard - I know your opinion about Rust xD -, let's see.
The forum returns a 500 error code to me and the contact page shows me that your e-mail is
I see. Well, good luck for your new project. I'm pretty sure that people will love your support as much as I do. |
Remember that my Rust opinion is personal; Rust is pretty good in general.
I'm having trouble with the forum. In fact, it turns out that sending email just doesn't work. My email provider is blaming the lobste.rs software, but the software has the right settings, so... I'm probably just going to have to write my own forum software. Sorry for the delay. It may be a year or so.
That is the correct address. I've redacted it because I don't want it machine-readable (to avoid spam), but it is correct.
Thank you! |
I hope it is here to stay for the long run.
No problem. I'll put a reminder on my calendar, so. See you in a year (or so). Have a nice week! |
Hey, I realize that you asked this five months ago, but I just saw this and I wanted to chime in, because I love REALLLY BIG NUMBERS. Now, Gavin noted that How did I do this (and what is Julia probably doing under the covers)? The same way a slide rule works: logarithms. It is definitionally true that To follow along:
That should give you that exponent. Remember: the number we want is ten raised to this power. To get the leading digits, we extract the mantissa (the fractional portion of a logarithm), and then raise 10 to this power. This works because of what Gavin noted: we can separate
I want to point out two things: firstly, |
Hi, @TediusTimmy. Thank you for your explanation. It helped a lot. I didn't know some of that mathematic equivalences. Have a nice week. |
Hi, there,
I love your command line tool and your blog (I read all your posts). You're an amazing developer. I hope one day I can be like you.
I'm opening this issue to ask you if there is any way to bypass the
Math error: overflow: number cannot fit
error on your calculator. I would like to test it for benchmark purposes against Julia REPL (for example), but yourbc
gives me this error when the number has too many digits.Example Calculation:
((169287^137)^920)^13256118217109
.Regards,
STSM
The text was updated successfully, but these errors were encountered: