How to create a 32-bit and 64-bit truth table?
5 views (last 30 days)
Show older comments
Srikant Beura
on 24 Jan 2019
Commented: John D'Errico
on 24 Jan 2019
I am using getcondvects function for generating truthtable. Upto 24 bit it can generate the truth table but after that it shows
"Out of memory. Type HELP MEMORY for your options."
Error in getcondvects (line 17)
condvects = false(i2,i);
I am using 4gb RAM.
In another system which is having 8gb Ram if I increase the Java heap memory from 384mb to 2000mb then upto 28 bit it can genetare the truth table but not more than that but my system got hang.
Please provide solution.
Thanks in advance
2 Comments
Guillaume
on 24 Jan 2019
Just because matlab has a setting with the word memory in it doesn't mean that increasing it will help with out of memory errors. In fact, increasing the java heap memory is more likely to result in less memory available to matlab to store arrays. Unless specifically told to increase the java heap memory, you should leave it as is, particularly with systems with only 4 or 8 GB of ram (which is a bit on the low side nowadays).
Accepted Answer
John D'Errico
on 24 Jan 2019
Edited: John D'Errico
on 24 Jan 2019
You can't. Be serious. An n-bit truth table has n*2^n elements in it. Even if one byte is assigned to each element, that should tell you how much memory is needed.
mem = @(n) n*2^n
mem =
function_handle with value:
@(n)n*2^n
mem(32)/2^30
ans =
128
mem(64)/2^30
ans =
1.0995e+12
So that 32 bit truth table will use 128 gigabytes of RAM. So vaguely possible, if you have a seriously souped up machine on your desk. You will need more memory than that of course, since you will surely need to make some copies of that table, plus some extra variables of a similar size. So a terabyte or two of RAM would be a good start. It will get way (8 times) worse if you start using doubles for some variables too.
That 64 bit truth table will cost you some serious money though. How are you fixed for cash? Do you have the money to buy on the order of one (or more) trillion one gigabyte ram chips? I could probably check the going rate for memory, but it will set you back just a wee bit. And then cramming them all into your computer will take some work too.
Just because your computer seems like it can do anything, it can't. Your computer has real, finite limits.
4 Comments
John D'Errico
on 24 Jan 2019
Computers are not infinitely large or infinitely fast. A common idea is to solve a problem using brute force, here that looks to be to just create a HUGE truth table. It works for small problems, so just keep doing what works, with no thought as to whether it makes any sense at all. Puch the envelope, until something breaks. Sorry, but something just broke.
You CANNOT solve the problem you are trying to solve, at least not in the way you are trying to solve it. Period. Not gonna happen. And if it did work, your next question would be the plaintive one of why cannot you create a 128 or 256 bit truth table.
Mathematics is all about how to NOT have to use brute force to solve what is sometimes an easy problem otherwise. And creating huge truth tables is a good example of using an atomic bomb to open a beer can. The result might be interesting for some people as long as they are standing a really long distance off, but you won't get anything useful out of it, and possibly just a wee bit of radiation poisoning.
So you need to step back. Rethink what you are doing. We have not been told any clue about why you are trying to do something that is computationally silly in the extreme. And that decision is really your choice anyway. Most likely, you need to talk to your teacher. Get some input on better approaches. And always remember to watch out for that fizz in your atomic beer.
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!