Win a copy of Pro Spring MVC with WebFlux: Web Development in Spring Framework 5 and Spring Boot 2 this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

how to create a boolean truth table

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am rather confuse on truth tables or how to create them. Take for example the following code segement


okay this is something I need to understand for a college class. I took there code made a program out of it and added a,b,c,d as boolean so I could set them to true or false. But there has to be another way to figure this out and I am under the impression it has something to do with truth tables. Any help would be greatly appreciated....

Thanks,

Pete
 
Ranch Hand
Posts: 323
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i'm not really sure what you mean by a "truth table". i've always thought that was a piece of paper with a grid on it. along the sides of the grid, you'd write in the values of two different variables (one for each side), and inside the grid squares, you'd write in whether a third variable (a boolean) should be "true" or "false" when the other two variables had the values corresponding to that square's coordinates.

what you've got here seems like a four-dimensional grid, where each dimension is a boolean variable (a through d), and the values in the grid squares would be the strings "1" through "6". the only real complication seems to be in the cases where the variable c is false, or d is true; that's your first big "if" block near the top. all other cases seem more straight-forward.

actually writing out your truth table would take, hm, four actual grids if you keep to one variable per axis. if you compress it a bit (more than one variable per axis) you could shrink the piece(s) of paper you'll need, at the cost of making it a bit harder to read. it might prove useful, though.
[ May 15, 2005: Message edited by: M Beck ]
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I recall doing this in school with Karnaugh Maps and Gray Code. The combination allows you to find the minimum number of tests to cover a wide number of conditions. Google for them and see if you find anything interesting. HEre's one set of university notes that gets into it part way through:http://cms.brookes.ac.uk/modules/notes/258_u-lect5.ppt

I have some REXX code around from the 90s that will generate code (any language from templates) if you tell it which boxes are shaded in your Karnaugh map. Send private e-mail with your e-mail address if you're interested.
 
author and iconoclast
Posts: 24203
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah, Karnaugh maps. Fondly remembering P.J. Plauger's old "Programming on Purpose" column in Computer Language magazine. Those were the days.
 
Bartender
Posts: 1202
22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well if you want to make a truth table, just put a for loop around your big if/elseif/else block of logic and set a,b,c,&d at the start of the loop. Your existing println() calls will fill in the last table column.


It's been my experience tha truth tables and Karnaugh maps were usually used when the result of your fuction was a boolean, so that they were just filled with T's and F's. In this case you could either make six separate tables, one for each possible out put, or you caould make three separate ones, one for each bit in the output integer.

Ryan
 
Stan James
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The "Programming on Purpose" columns were collected into a fantastic little book by the same name. Highly recommended for the state of the art of design ... right before objects. The essays on design styles like Top Down, Bottom Up, Left to Right, Right to Left, Inside Out and Outside In are timeless. I became parted from my copy. Hope those were right!

One word of warning on using this kind of logic reduction ... the resulting code can be nearly impossible to translate back into business terms. I used it a couple times and kept the graph as a comment.

Here's one input to my little code generator showing all the possible rectangles in a Karnaugh map up to 4 variables and what they imply ...
 
And when my army is complete, I will rule the world! But, for now, I'm going to be happy with this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic