FacebookTwitter
Hatrack River Forum   
my profile login | search | faq | forum home

  next oldest topic   next newest topic
» Hatrack River Forum » Active Forums » Books, Films, Food and Culture » Cousin Hobbes explains Boolean Algebra

   
Author Topic: Cousin Hobbes explains Boolean Algebra
Hobbes
Member
Member # 433

 - posted      Profile for Hobbes   Email Hobbes         Edit/Delete Post 
Boolean is really very, very simple math so hopefully this will be a decently short Cousin Hobbes, if not… then it’s long. [Wink]

In Boolean algebra there are only two possible values: off and on. They are almost universally represented as 1s and 0s, and that’s how I will do it to so that when you see this some point in the future it will be easier to apply. HOWEVER ‘1’ does not equal the number 1! Nor does ‘0’ equal 0 in Boolean algebra. This is very important, the 1 and 0 simply stand for on and off (respectively). So when I say 1 + 1 = 1 don’t get confused and thinking I messing up the simplest of addition. [Smile]

There are two major operators in Boolean, addition (also known as “union” and “or”) and multiplication (also known as “intersection” and “and”). Once again it is important to not mistake them for normal addition and normal multiplication, they have unique functions in Boolean algebra.

The Boolean addition operator (‘+’) takes each number and says “is either of these on?” If either (or both) is then it results in an on. But if both are off (‘0’) then it returns an off.
Since only ‘on’ and ‘off’ are possible to put into this equation, it is a simple matter to write out all possible combinations:

code:
0 + 0 = 0
1 + 0 = 1
0 + 1 = 1
1 + 1 = 1

It’s probably easiest to think of this concept in terms of electric circuits, either they carry current or they don’t. When you put too current carrying wires together, what do you get? One continuous current carrying wire. This is Boolean addition, 1 + 1 = 1. One current carrying wire put together with one that does not have a current, turns into one continuous wire carrying current. 1 + 0 = 1 (and 0 + 1 = 1). Two wires neither of which are carrying current form one wire which is not carrying current either.

Boolean multiplication (‘*’), asks the question “Are both of these on?” If the answer is yes, then it returns ‘on’, if either one or both of the operands (in the equation 1 * 0, both 1 and 0 are operands of the ‘*’) are off then it return an ‘off’ value. Once again, writing out all possible combinations is quite simple.

code:
0 * 0 = 0
1 * 0 = 0
0 * 1 = 0
1 * 1 = 1

These two functions (addition and multiplication) are the two big tenets of Boolean algebra. However, there are a few other functions that I will explain; “exclusive or” being perhaps the most used function behind addition and multiplication.

An “Exclusive Or” function asks the question “Are both operands the same or are they different?” If they’re different then it will return ‘on’ (since it’s exclusive, it only wants one of a kind), if they’re the same it will return ‘off’. Different symbols are used for exclusive or, I will use the C++ symbol for it: ‘^’.

code:
0 ^ 0 = 0
1 ^ 0 = 1
0 ^ 1 = 1
1 ^ 1 = 0

The only other function commonly used in Boolean, is an inversion (normally written as ‘!’). This one’s very simple and only takes one value. It simply reverses the condition of the value, if it’s on it return off, if it’s off it returns on.

code:
!0 = 1
!1 = 0

Once you know this you know the basics of Boolean algebra, just as once you know addition, subtraction, multiplication and division you know the basics of normal algebra. That’s the thing to keep in mind, I used the phrases “Boolean addition”, and “Boolean Multiplication” a lot to remind you that these define Boolean algebra the way normal addition and multiplication define normal algebra.

Algebra and Boolean algebra are just a collection of rules to follow when dealing with specific values. The above 4 functions are the basic rules of Boolean algebra from which the rest is built.

(As a final note, FYI kind of thing, the equations I showed in the code statements are known as truth tables, though they’re often written a little differently).

Hobbes [Smile]

[ December 02, 2003, 07:33 PM: Message edited by: Hobbes ]

Posts: 10602 | Registered: Oct 1999  |  IP: Logged | Report this post to a Moderator
T_Smith
Member
Member # 3734

 - posted      Profile for T_Smith   Email T_Smith         Edit/Delete Post 
Here's some quick boolean algebra shorthand that I had to memorize for a test last week:

A * A = A
A * !A = 0
A * 0 = 0
A * 1 = A
A * (A + B) = A
A * (!A + B) = A * B

A + A = A
A + !A = 1
A + 1 = 1
A + 0 = A
A + (A * B) = A
A + (!A * B) = A + B

!(A + B) = !A * !B
!(A * B) = !A + !B

I also gave an example of boolean algebra in practicle terms in the Cousin Hobbes Binary thread.

Posts: 9754 | Registered: Jul 2002  |  IP: Logged | Report this post to a Moderator
Maethoriell
Member
Member # 3805

 - posted      Profile for Maethoriell   Email Maethoriell         Edit/Delete Post 
I'll stick with my Algebra 2.
Posts: 4628 | Registered: Jul 2002  |  IP: Logged | Report this post to a Moderator
Youth ap Orem
Member
Member # 5582

 - posted      Profile for Youth ap Orem   Email Youth ap Orem         Edit/Delete Post 
So, what is Boolean Algebra for?
Posts: 290 | Registered: Aug 2003  |  IP: Logged | Report this post to a Moderator
Eruve Nandiriel
Member
Member # 5677

 - posted      Profile for Eruve Nandiriel   Email Eruve Nandiriel         Edit/Delete Post 
Math! Aaaaaahhh! [Angst]
Posts: 4174 | Registered: Sep 2003  |  IP: Logged | Report this post to a Moderator
Hobbes
Member
Member # 433

 - posted      Profile for Hobbes   Email Hobbes         Edit/Delete Post 
Boolean algebra is fundemental for dealing with circuts. People who tell you that computers work on binary numbers are at best telling a half truth. Fundementally all computers run on Boolean, circuits and switches make for a distinct boolean representation.

I'm hoping at some point to get up enough energy to do a "Cousin Hobbes how computers work" series. When I do get that written the importance of Boolean will become much clearer.

Hobbes [Smile]

Posts: 10602 | Registered: Oct 1999  |  IP: Logged | Report this post to a Moderator
T_Smith
Member
Member # 3734

 - posted      Profile for T_Smith   Email T_Smith         Edit/Delete Post 
I'm in an Electric Class right now, Hobbes. Tons of fun. Love it.

Again, the best example that I can give is a process to add binary together.

C - Carry

1 = 00001 - A
3 = 00011 - B
---------
4 = 00100 - I

(A + B) = D

(A * B) = E

(!E * D) = F

(C + F) = G

(C * F) = H

(!H * G) = I

(E + H) = C

Sum = I
Carry = C

So first time around:

A = 1 and B = 1 and C = 0

(A + B) = D
(1 + 1) = 1

(A * B) = E
(1 * 1) = 1

(!E * D)= F
(0 * 1) = 0

(C + F) = G
(0 + 0) = 0

(C * F) = H
(0 * 0) = 0

(!H * G)= i
(1 * 0) = 0

(E + H) = C
(1 + 0) = 1

Sum = i = 0
Carry = C = 1

Second time around:

A = 0 and B = 1 and C = 1

(A + B) = D
(0 + 1) = 1

(A * B) = E
(0 * 1) = 0

(!E * D) = F
(1 * 1) = 1

(C + F) = G
(1 + 1) = 1

(C * F) = H
(1 * 1) = 1

(!H * G) = i
(0 * 1) = 0

(E + H) = C
(0 + 1) = 1

Sum = i = 0
Carry = C = 1

Third time around:

A = 0 B = 0 C = 1

(A + B) = D
(0 + 0) = 0

(A * B) = E
(0 * 0) = 0

(!E * D) = F
(1 * 0) = 0

(C + F) = G
(1 + 0) = 1

(C * F) = H
(1 * 0) = 0

(!H * G) = i
(1 * 1) = 1

(E + H) = C
(0 + 0) = 0

Sum = i = 1
Carry = C = 0

Put the 3 sums in a row and you get

1 0 0 = 4 in binary

[ December 02, 2003, 09:43 PM: Message edited by: T_Smith ]

Posts: 9754 | Registered: Jul 2002  |  IP: Logged | Report this post to a Moderator
luthe
Member
Member # 1601

 - posted      Profile for luthe   Email luthe         Edit/Delete Post 
What's it for? Anything you want. What is normal math for?

quote:
People who tell you that computers work on binary numbers are at best telling a half truth. Fundementally all computers run on Boolean, circuits and switches make for a distinct boolean representation.
This strikes me as splitting hairs. All digital circuits, run on boolean algerbra as that is what makes them digital, two distinct states. A computer is differs mostly by the elaborate hoop jumping used to run stored programs, rather than building a new circuit for each problem.

Is 10001 a string of boolean values or 17 represented in base 2?

Posts: 1458 | Registered: Feb 2001  |  IP: Logged | Report this post to a Moderator
ana kata
Member
Member # 5666

 - posted      Profile for ana kata   Email ana kata         Edit/Delete Post 
You can say all computers run on boolean, but what I think is that all computers run on electricity in circuits.

One other cool thing: Boolean AND is like elements in series. Boolean OR is like elements in parallel. Here is C = A AND B (C=A*B) shown as a circuit diagram. Now using the word AND makes sense, because C is energized only if both A AND B are energized.
code:
 
hot neutral
| A B C |
+------||-----------||---------()-------+
| |

This is called a ladder diagram, and we are doing ladder logic. This is the way programs are written for the industrial computers that control factories. Here the A and B are shown as relay contacts for relays A and B, and C is the coil for a third relay we have named C. The vertical line down the left is the conductor that carries the positive power supply, and the vertical line on the right is the neutral or return line. The horizontal lines across the middle are the current carrying conductors. If relay A is on (if its coil has power) then the contact (shown as two vertical lines side by side) will be closed and power will pass to the right. If relay B is also on, then its contact will be closed and power will pass all the way to the coil of relay C, activating that relay and closing its contacts wherever else they might occur in the logic.

Here is the ladder logic for C = A OR B (C=A+B). C is energized if either A OR B are energized, or both.
code:
 
hot neutral
| A C |
+------||---------+------------()-------+
| | |
| B | |
+------||---------+ |

In this case if relay A is energized, its contact will close and power will pass to the coil of relay C. If relay B is energized, or if both A and B are energized, then the same thing will happen. If neither of them is energized (their coils will appear presumably in other rungs of the circuit (or lines of the code, however you want to look at it)) then the coil of relay C will have no power and it will not fire.

[ December 03, 2003, 01:36 AM: Message edited by: ana kata ]

Posts: 968 | Registered: Sep 2003  |  IP: Logged | Report this post to a Moderator
ana kata
Member
Member # 5666

 - posted      Profile for ana kata   Email ana kata         Edit/Delete Post 
code:
 
hot neutral
| |
| |
| A A |
+------|\|-----------------------()-------+
| |
| |
| |

The last thing that you need to know is that the contact symbol with the slash in the middle represents a "normally closed", or NC contact (the other one, with two vertical lines only, is a "normally open" or NO contact.) A NC contact will pass power when its coil is NOT energized, and it won't pass power when its coil IS energized. It's just the opposite of a NO contact which passes power only when its coil IS energized. It is analogous to the Boolean symbol !. So a NC contact of relay A is like saying !A.

Can anyone tell me what this circuit does? Realize that there is a 50ms delay between putting power onto (or removing power from) the coil and the change of state of the contacts.

Can you design a ladder circuit that will perform the function "exclusive or"?

[ December 03, 2003, 01:42 AM: Message edited by: ana kata ]

Posts: 968 | Registered: Sep 2003  |  IP: Logged | Report this post to a Moderator
fugu13
Member
Member # 2859

 - posted      Profile for fugu13   Email fugu13         Edit/Delete Post 
Looks like it pulses.

edit: ok, that was for the last circuit you had up.

[ December 03, 2003, 01:47 AM: Message edited by: fugu13 ]

Posts: 15770 | Registered: Dec 2001  |  IP: Logged | Report this post to a Moderator
fugu13
Member
Member # 2859

 - posted      Profile for fugu13   Email fugu13         Edit/Delete Post 
Of course, so does this one.
Posts: 15770 | Registered: Dec 2001  |  IP: Logged | Report this post to a Moderator
MyrddinFyre
Member
Member # 2576

 - posted      Profile for MyrddinFyre           Edit/Delete Post 
Boolean!
Posts: 3636 | Registered: Oct 2001  |  IP: Logged | Report this post to a Moderator
Richard Berg
Member
Member # 133

 - posted      Profile for Richard Berg   Email Richard Berg         Edit/Delete Post 
So is it a half-truth to talk about computers without Kirchoff's Laws? [Smile]

Boolean gates are kind of boring on their own. My favorite low-level circuit is the flip-flop.

Posts: 1839 | Registered: May 1999  |  IP: Logged | Report this post to a Moderator
ana kata
Member
Member # 5666

 - posted      Profile for ana kata   Email ana kata         Edit/Delete Post 
fugu, yes! I just simplified the first one because I realized that it didn't make sense to do it the way I did at first. It does pulse as rapidly as the relay will respond. You might use a circuit like this to test your relay to failure and see how many times it will actuate before the coil dies. They claim millions of actuations. Another contact might be run in to a counter circuit somewhere so you will know how many cycles it lasted.

I will show the circuit for "exclusive OR" this evening, if nobody has answered yet. [Smile]

Richard, Kirchoff's laws, if you want to ignore all the quantum effects, I guess. [Smile] Seriously, though, I find that knowledge of at least one level beneath the level on which you are logically working can come in very handy, because odd effects sometimes bleed upward in idea-space.

Yeah, flip flops are very cool! Cousin Hobbes is planning a flip flop thread in this series, I just bet. [Smile]

I find it fascinating that before there were computers, they could do very complex logic in factories using nothing but relays. It's a totally different paradigm of programming, the original version of "event driven" code. And very robust in the real world. Never has to be rebooted. <laughs>

[ December 03, 2003, 07:42 AM: Message edited by: ana kata ]

Posts: 968 | Registered: Sep 2003  |  IP: Logged | Report this post to a Moderator
fugu13
Member
Member # 2859

 - posted      Profile for fugu13   Email fugu13         Edit/Delete Post 
Lessee ---

code:
hot                          neutral
| |
| A B |
+-----||-----|\|-----+---------+
| | |
| B A | |
+-----||-----|\|-----+ |
| |
| |


Posts: 15770 | Registered: Dec 2001  |  IP: Logged | Report this post to a Moderator
Ron Lambert
Member
Member # 2872

 - posted      Profile for Ron Lambert   Email Ron Lambert         Edit/Delete Post 
Boolean algegra does have a place in computer programming. For example in BASIC, here is a way to do a word count by counting spaces (which have an ASCII value of 32) in text:

10 FOR X=1 TO LEN($TEXT)
20 IF ASC($TEXT(X)) = 32 THEN WORDCOUNT=WORDCOUNT + 1
30 NEXT X
40 PRINT "Total wordcount is " WORDCOUNT
50 END

Using Boolean logic, you do it this way:

10 FOR X=1 TO LEN($TEXT)
20 WORDCOUNT = WORDCOUNT + (ASC($TEXT(X))=32)
30 NEXT X
40 PRINT "Total wordcount is " WORDCOUNT
50 END

Boolean logic is used in line 20. It works the same as the IF-THEN statement in line 20 of the first example. If the statement enclosed in parentheses that the ASCII value of the text character equals 32 evaluates as true, then WORDCOUNT is incremented by 1.

Most computers evaluate a "true" Boolean logic statement by assigning a "1" to the statement, and a "0" if it is false. So if the character being checked is not a space (ASCII 32), then you are adding 0 to the wordcount. If it is a space, then you are adding 1 to the wordcount.

One thing I had to watch out for years ago when programming for 64K Apples, Ataris, Commodores, and others was that some computers for some inexplicable reason evaluated a true statement by assigning it a "-1" (minus one) which would make your word count look a little funny. You could, however, use the "ABS" (short for absolute) function to get rid of the minus sign.

[ December 03, 2003, 05:14 PM: Message edited by: Ron Lambert ]

Posts: 3742 | Registered: Dec 2001  |  IP: Logged | Report this post to a Moderator
fugu13
Member
Member # 2859

 - posted      Profile for fugu13   Email fugu13         Edit/Delete Post 
Most languages choose one of the two sensible routes wrt boolean logic: either there is a set of false values (which are all empty sets, zeroes, and similar) and everything else is true, or there are explicitly true and false values in a boolean type.

I used to prefer the former practice, but now I strongly prefer the latter practice in most cases, though I know how both can be useful in different situations.

Anything else is asking for trouble, because it violates type safety (the first approach maintains type safety in an odd way -- by not guaranteeing the value that will be assigned to true or false it requires one to use explicitly boolean checks) and furthermore promotes obscure programming practices such as you're advocating.

Also, what you're doing isn't boolean algebra, its math that makes assumptions about the relation of boolean values to integral values. Of course, a boolean value doesn't map onto a base ten value at all. Binary values do, but boolean != binary.

[ December 03, 2003, 05:37 PM: Message edited by: fugu13 ]

Posts: 15770 | Registered: Dec 2001  |  IP: Logged | Report this post to a Moderator
ana kata
Member
Member # 5666

 - posted      Profile for ana kata   Email ana kata         Edit/Delete Post 
fugu, yes! You got it right, only you need a coil in the circuit ---()---. Call it C. Or else when the condition is true you will dead short your hot to your neutral and trip the breaker. [Smile]
Posts: 968 | Registered: Sep 2003  |  IP: Logged | Report this post to a Moderator
ana kata
Member
Member # 5666

 - posted      Profile for ana kata   Email ana kata         Edit/Delete Post 
Oh, and obscure programming practices are rather cool. I know they are often opaque but you can add a few obscure comments to illuminate them, if needed. They are just cool. That's all. I'm sorry. Don't try to convince me otherwise.
Posts: 968 | Registered: Sep 2003  |  IP: Logged | Report this post to a Moderator
fugu13
Member
Member # 2859

 - posted      Profile for fugu13   Email fugu13         Edit/Delete Post 
Yes, forgot my c. It was implied [Wink] .

And the programming practice that Ron illustrated is unfortunately fairly common. I say unfortunately because the performance gain it involves (usually very, very small) is not worth the great loss of maintainability and expandability from the approach. Sound programming practices treat booleans as booleans, and not as integers.

Posts: 15770 | Registered: Dec 2001  |  IP: Logged | Report this post to a Moderator
Hobbes
Member
Member # 433

 - posted      Profile for Hobbes   Email Hobbes         Edit/Delete Post 
In case anyone is wondering, AK is an electrical engineer, and in response to the fact that she clearly is more knowledgable about this than I can hope to be I have one link: HAH!. [Wink] [Wink] [Smile]

Hobbes [Smile]

[ December 04, 2003, 01:11 AM: Message edited by: Hobbes ]

Posts: 10602 | Registered: Oct 1999  |  IP: Logged | Report this post to a Moderator
Richard Berg
Member
Member # 133

 - posted      Profile for Richard Berg   Email Richard Berg         Edit/Delete Post 
In a language like C++ the gain is negative. All compilers I've worked with recently will issue a performance warning if you implicitly cast bool -> int. Not that that should stop potential IOCCC contestants from practicing their technique.
Posts: 1839 | Registered: May 1999  |  IP: Logged | Report this post to a Moderator
fugu13
Member
Member # 2859

 - posted      Profile for fugu13   Email fugu13         Edit/Delete Post 
Yeah, c++ was spot on in using explicit booleans.

I like Haskell, myself [Smile] .

Posts: 15770 | Registered: Dec 2001  |  IP: Logged | Report this post to a Moderator
ana kata
Member
Member # 5666

 - posted      Profile for ana kata   Email ana kata         Edit/Delete Post 
Hobbes: <laughs> You are taunting me! Just wait until I am aiming asteroids around the solar system! I will show you fireworks!

fugu: I told you not to try to convince me. Yes, you are right about sound programming practice, BUT.... C only ever caught on to begin with, and unix too, because of cool stuff like the way it let you write nifty clever opaque beautiful code snippets like that. So don't try to make its greatest virtue into a flaw. If you want a transparent programming language that forces you to do things in a standard way, why aren't you still programming in COBOL? <laughs>

-aka, former programmer in COBOL, C, Pascal, PL/1, Fortran, Basic, dBASE, C++, Clarion, Lisp, and two or three assembly languages, (to name a few) [Big Grin]

[ December 04, 2003, 01:44 AM: Message edited by: ana kata ]

Posts: 968 | Registered: Sep 2003  |  IP: Logged | Report this post to a Moderator
fugu13
Member
Member # 2859

 - posted      Profile for fugu13   Email fugu13         Edit/Delete Post 
No, C caught on because it was a way for people to be able to play with the code of the latest greatest operating system, unix, which was freely distributed in code form to university students. That was the entire reason it was invented, to offer a high level programming language with good direct memory control for the programming of unix.

It had little to do with its opaquity, and in fact had much to do with its comparative transparency to assembly language.

</lecture> [Wink]

Of course things like the Duff's Device are just plain cool, but it should only be used in cases of need for the particular performance boost it gives.

Posts: 15770 | Registered: Dec 2001  |  IP: Logged | Report this post to a Moderator
ana kata
Member
Member # 5666

 - posted      Profile for ana kata   Email ana kata         Edit/Delete Post 
Well, no, actually, fugu, you see, I remember when C caught on. I was around then. <laughs> It was because it LET you do all the cool things that other languages prevented you from doing. C was fundamentally different in that it assumed you knew what you were doing. It was like this huge freedom to use the full power of the machine was suddenly yours. And it made an enormous boost in the coolness factor, the geekiness factor, of programming. It's true that in machine language and assembly language you could always do those things, but those were so unweildy. Not fast and terse and beautiful like C. C was an instant hit with programmers because it spoke to who we were. <laughs>
Posts: 968 | Registered: Sep 2003  |  IP: Logged | Report this post to a Moderator
Richard Berg
Member
Member # 133

 - posted      Profile for Richard Berg   Email Richard Berg         Edit/Delete Post 
Oh boy, another Haskell loony [Wink] You should go commiserate with newton_meter. He's one of my favorite posters in the programming forum, often coming up with things like this in response to "simple" questions. His knowledge of language history is as good as his grasp of their semantics, but in his absence I'll pose my mini-theory: C became popular because it hit a sweet spot where on one hand it was very easy to implement a compiler on every architecture known to man, and on the other hand let you construct big data structures without having to think too much once you got used to ***foo.
Posts: 1839 | Registered: May 1999  |  IP: Logged | Report this post to a Moderator
fugu13
Member
Member # 2859

 - posted      Profile for fugu13   Email fugu13         Edit/Delete Post 
I think Mr. Berg has more of the right of it than either of us. Or is it more of the right of it from each of us?

I came upon Haskell at a good time in my learning of programming languages. I pulled all sorts of tricks in my early programs, such as RL pointed out, preferring to program in C. I played a bit with functional languages, such as Scheme and a non-implemented generic Lisp implementation (programming on paper [Smile] ). Lately I'd been playing with python and ruby (perl had never really appealed to me), and there'd been stops at a dozen or so other languages along the way. I had recently come into the realization that types were Very Important. A type was an abstract model for manifesting an idea, not some shorthand for memory registers as I treated them while programming C. However, I was in danger of becoming a template disciple. I say in danger because, while I still find some fascinating problems in template programming, it still seems as it did then a matter to me of working in order to be able to write a program.

Then I found Haskell. In haskell, types are a very pure abstraction, which I love. And user defined types are on the same playing field, unlike in languages such as C and C++, and even python and ruby, where user defined types always seem to play second fiddle.

I still quite enjoy other languages, particularly python, and the somewhat limited libraries in Haskell prevent me from using it on many projects, but Haskell is a very very expressive language that I enjoy using more than the others I've tried.

And I found that thread very interesting. Reminded me of when I was giving lectures on types and other basic programming concepts in hatrack chat [Smile] .

Posts: 15770 | Registered: Dec 2001  |  IP: Logged | Report this post to a Moderator
Richard Berg
Member
Member # 133

 - posted      Profile for Richard Berg   Email Richard Berg         Edit/Delete Post 
If you made it from top to bottom (no skimming!) in the time between our posts, I take my hat off to you, sir. And probably eat it, too.
Posts: 1839 | Registered: May 1999  |  IP: Logged | Report this post to a Moderator
ae
Member
Member # 3291

 - posted      Profile for ae   Email ae         Edit/Delete Post 
<<runs screaming from thread>>
Posts: 2443 | Registered: Apr 2002  |  IP: Logged | Report this post to a Moderator
Ron Lambert
Member
Member # 2872

 - posted      Profile for Ron Lambert   Email Ron Lambert         Edit/Delete Post 
Actually, "C" was invented in the first place by Dennis Richie to enable himself and Ken Thompson to develop the "UNIX" operating system, which in turn they developed to enable them to deal with the speed and memory limitations of the MULTICS operating system on which they had been trying to develop a computer game called "Space Travel" (which ironically, never amounted to much).

The value of C as a programming language and UNIX as an operating system were recognized by many others, and over the years contributions to the development of both have been made by a multitude of people. As one who has used both, I am impressed by the conceptual insight that led to their development. I just think it is such a delightful irony that something so purely geeky as trying to come up with a new computer game led to the development of C and UNIX as by-products.

C is a structured language, that imposes a healthy (some say healthy, anyway) discipline on programmers. The drawback of BASIC had long been that it did not impose structure on programmers, but rather permitted you to wind up with backwards GOTOS and GOSUBS, and RETURNS all over the place, producing "spaghetti code" that could be horribly difficult to debug.

Probably the most challenging aspect of C and its more recent variants, C+ and C++ (which make extensive use of logic assemblies called "structs") is the capability for nested recursive subroutines. I always enjoyed C+ as a programmer, but the recursive stuff sometimes gave me headaches.

Getting back to Boolean algebra, it is inherent in the ONGOTO and ONGOSUB commands in BASIC, and also in the "case" and similar functions in C, which evaluate whether a condition is true or not to determine how the program should branch.

By the way, not to get off on yet another tangent, but I must confess that as a programmer, I never, ever used a flowchart even once on the job. Are there any programmers out there who use or ever used flowcharts? I have a suspicion that flowcharting programs is about as useful as diagramming sentences.

Posts: 3742 | Registered: Dec 2001  |  IP: Logged | Report this post to a Moderator
ana kata
Member
Member # 5666

 - posted      Profile for ana kata   Email ana kata         Edit/Delete Post 
Never flowcharted ever.

I use pseudocode quite a bit, though, when working out routines.

Posts: 968 | Registered: Sep 2003  |  IP: Logged | Report this post to a Moderator
ana kata
Member
Member # 5666

 - posted      Profile for ana kata   Email ana kata         Edit/Delete Post 
Y'all should try programming in a language whose very simplest structures are represented by enormous pictures of circuit diagrams. It's really bizarre. Finally some of the better implementations of PLC ladder logic are letting you use text code (which of course it really is just the same as, anyway), but they don't do it in a way that makes it truly useful to work with. For instance, in Rockwell Automation's RSLogix500, you can type in your code lines like this "BST XIC A XIO B NXB XIO A XIC B BND OTE C", but when you edit it or print it out in that form, it has translated the A B and C symbols (that mean something to the programmer) into hardware level addresses which are meaningless. So it comes really close to being useful but just isn't quite.

XIC = eXamine If Closed = a NO contact or -||-
XIO = eXamine If Open = a NC contact or -|\|-
BST = Branch STart = a sort of left bracket for things that will be in an OR group, wired in parallel
NXB = NeXt Branch = right bracket then left bracket for closing one and starting the next bunch of things to be OR'd together or wired in parallel
BND = Branch eND = last right bracket ending the OR group
Operators written one after the next are AND'ed together or wired in series.
OTE = a coil or the target of the assignment statement (=).

So the line of code above just means "C = A ^ B".

[ December 04, 2003, 02:31 PM: Message edited by: ana kata ]

Posts: 968 | Registered: Sep 2003  |  IP: Logged | Report this post to a Moderator
fugu13
Member
Member # 2859

 - posted      Profile for fugu13   Email fugu13         Edit/Delete Post 
Ron my friend, I highly suggest you never try a functional language if you found C recursion confusing.

Boolean algebra is not inherent in those routines. They are jumps conditioned on an integer value, which happens to be interpreted in a boolean manner. Also known as primitive if statements. Boolean algebra, as the tutorial above points out, is a completely different beast. There are no jumps in boolean algebra. The only statements in BASIC that are really similar to boolean algebra are AND, OR and NOT (some BASIC flavors have a couple more), but these are only "boolean" in the sense they can be used to simulate boolean operations. These are actually bitwise operations, done on each bit of the input(s), and clearly do not operate on any boolean type or behave in a consistently boolean manner despite the nonexistence of a boolean type (as the boolean operations do in some language without boolean types).

As for flowcharting, I think you'll find for most enterprise architecture there's a fair amount of diagramming done of a number of kinds: see UML. This includes flowchart diagramming, though thats one of the least used parts of UML in my experience.

I am unfamiliar with C+. I found several references to C+- and C+@, but C+ eluded me. Indeed, foldoc has no mention of it: http://wombat.doc.ic.ac.uk/foldoc/index.html . Do you have a website detailing any of it?

Richard Berg: (btw, how do you prefer your name abbreviated?), I did not read fully that thread in between the posts. I did read fully over it afterwards, which was very interesting.

Posts: 15770 | Registered: Dec 2001  |  IP: Logged | Report this post to a Moderator
Richard Berg
Member
Member # 133

 - posted      Profile for Richard Berg   Email Richard Berg         Edit/Delete Post 
I know. It was just a nudge to finish what you'd obviously started, because I think it's cool.

People call me all sorts of things, but if you're a programmer you'll probably prefer the brief "RB."

Posts: 1839 | Registered: May 1999  |  IP: Logged | Report this post to a Moderator
fugu13
Member
Member # 2859

 - posted      Profile for fugu13   Email fugu13         Edit/Delete Post 
Hmmm. I think I shall go design a type system for describing hatrack.
Posts: 15770 | Registered: Dec 2001  |  IP: Logged | Report this post to a Moderator
Ron Lambert
Member
Member # 2872

 - posted      Profile for Ron Lambert   Email Ron Lambert         Edit/Delete Post 
Fugu13, C+ and C++ are most commonly written with the + signs as superscripts. That may be confusing your browser. But I was able to enter C++ on Yahoo, the search engine I normally use first, and got 8,070,000 hits.

C+ is what the C language was called after they added "structs," and then C++ is what the language was called when they improved on that to give you "superstructs." Basically the idea of structs is to create your own library of groups of variables.

UNIX of course was written in C, and Windows was originally written in C. (The UNIX utility programming codes "AWK" and "NAWK" are very C-like.)

The thing that bothers me about recursion is that it could theoretically go on forever. The human brain is really not designed to handle recursion well.

Posts: 3742 | Registered: Dec 2001  |  IP: Logged | Report this post to a Moderator
fugu13
Member
Member # 2859

 - posted      Profile for fugu13   Email fugu13         Edit/Delete Post 
Ron, I am quite familiar with C++. See my earlier posts in this thread. And you are clearly wrong on the definition of C+. For proof, see here: http://www.lysator.liu.se/c/bwk-tutor.html

Its a tutorial from 4 years before the first edition of The C Programming Language (essentialyl the first standard for C), and a very early version of C. It is clearly called C. It has structs.

Also, while a struct can be treated as a sort of primitive namespace construct, it is hardly their primary usage. The primary usage of structs is the creation of user defined types, and the use of them as a primitive namespace construct strikes me as an extraordinarily bad programming practice.

By super-structs I'm going to assume you mean classes. Which are definitely not primarily used as a primitive namespace construct, but as user defined types.

[ December 04, 2003, 06:09 PM: Message edited by: fugu13 ]

Posts: 15770 | Registered: Dec 2001  |  IP: Logged | Report this post to a Moderator
fugu13
Member
Member # 2859

 - posted      Profile for fugu13   Email fugu13         Edit/Delete Post 
*shrug*

I've never had a particular problem handling recursion, but I'm hardly normal. And recursion is a decently popular programming practice with a good sized number of people, so it can't be all that bad.

Posts: 15770 | Registered: Dec 2001  |  IP: Logged | Report this post to a Moderator
Ron Lambert
Member
Member # 2872

 - posted      Profile for Ron Lambert   Email Ron Lambert         Edit/Delete Post 
Fugu13, the way you define C, C+ and C++ makes you sound like the kind of guy who writes user manuals that nobody can use. I appreciate your desire to be accurate and precise, but since there are likely very few C programmers in this forum, I feel it is more important to make explanations simple and accessible. I have also written user and tech manuals, and I make it a practice never to use a word new to the typical reader without defining it in a clear and understandable way.

You said in your post of Dec. 4, 4:11pm: "I am unfamiliar with C+." Then in your more recent post you say you are familiar with C++ and think I did not define C+ correctly. Sorry, I was just trying to answer the question it looked like you were asking because you did not know.

Anyway, C+ is what they called the language when I got my CIS degree nine years ago. They started referring to C++ a few years after that, when basically they developed the struct functionality further, something I saw as a linear development, not as a quantum leap.

Boolean Algebra is only useful to me up to the level at which I use it in programming. I think it is sufficient to introduce people to the essential idea of it, unless you are talking to mathematicians. Otherwise you are not communicating, you are just showing off.

Posts: 3742 | Registered: Dec 2001  |  IP: Logged | Report this post to a Moderator
Ron Lambert
Member
Member # 2872

 - posted      Profile for Ron Lambert   Email Ron Lambert         Edit/Delete Post 
Ana kata, it sounds like you are talking about what we used to call "Assembler Language," which was one step up from "Machine Language." I didn't think anybody used either any more. In the past I have done a little machine language programming for subroutines to be called from BASIC, but I never worked with assembler language.

Many companies have their own proprietary specialized program modules, and their own protocols for using them. Maybe yours just resembles assembler language.

Posts: 3742 | Registered: Dec 2001  |  IP: Logged | Report this post to a Moderator
fugu13
Member
Member # 2859

 - posted      Profile for fugu13   Email fugu13         Edit/Delete Post 
Ron, I believe you that C+ was what you were told it was called. However, that it had to do with the addition of structs is clearly not the case -- that page I linked to clearly indicates structs have been part of the language since the earliest days of C, and it certainly has an authoritative author [Smile] . My guess would be the C+ you are referring to was a set of extensions to C implemented in some compiler, and I am almost certain that there was no general understanding of what C+ was -- foldoc doesn't miss much.

As for the user manuals no one can use bit, I'm assuming here that I'm talking with someone with a decent knowledge of programming, so I use somewhat technical terminology and assume at least a basic grasp of things like type theory. I have successfully taught several people the basics of programming in a number of languages, so I submit that my ability to teach is not in question.

I think you have missed my points regarding your examples so far. It has not been that they aren't used in programming, or aren't useful at times, but they just aren't examples of boolean algebra. BASIC doesn't even HAVE true boolean algebra, though of course one could implement it (it is Turing complete, after all). Its not a questions of usefulness, its a question of definition and accuracy.

Also, I think you will find if you do a quick investigation of modern programming languages that the practices I have advocated here as good programming practices are encouraged and even required in current languages, and by industry programmers, and the practices I have called bad or unsafe are discouraged and often forbidden in current languages, and by industry programmers. I haven't said anything particularly outrageous, in fact pretty much all of it has been advocating boolean type safeness or the use of structs as type definitions/constructors, both practices that have been considered best practices for well over a decade.

C++ classes can be seen as a mere enhancement of structs, and in terms of implementation certainly are, however the revolution that C++ brought to C wasn't the in the technicality, but the way of thinking about a program. Object oriented programming principles can be followed in an imperative language such as C, but C++ syntax and structure promote and enable their use in ways that C itself could not.

Posts: 15770 | Registered: Dec 2001  |  IP: Logged | Report this post to a Moderator
ana kata
Member
Member # 5666

 - posted      Profile for ana kata   Email ana kata         Edit/Delete Post 
Ron, do you mean ladder logic? No, it is the standard way that industrial computers (called PLCs) for factories are programmed. There are numerous brands of PLCs (Allen Bradley, Siemens, Modicon, GE Fanuc, etc.) whose code (with variations) looks essentially the same. It arose out of relay logic, which is how factories were controlled before the advent of PLCs. The ladder logic picture can be thought of as a circuit diagram, because if you wired up relays in a circuit like that, it would perform the same way.

It has the advantage of being event-driven by nature, and also simple and bulletproof, allowing the machines to run for weeks, months, or years unattended. I never realized how much office PCs (on a hardware and software level both) require constant operator intervention (to reboot and so on) until I found out how unworkable that is on a factory floor.

Posts: 968 | Registered: Sep 2003  |  IP: Logged | Report this post to a Moderator
Dagonee
Member
Member # 5818

 - posted      Profile for Dagonee           Edit/Delete Post 
This is why programmers make good lawyers. (Note the converse is not necessarily true.) Nitty gritty precision in language is a requirement in both professions.

It's the same reason MBA's make bad programmers, from my experience.

My favorite part was always data modeling and ontologies. Circuits (software or otherwise) drove me nuts.

Posts: 26071 | Registered: Oct 2003  |  IP: Logged | Report this post to a Moderator
Richard Berg
Member
Member # 133

 - posted      Profile for Richard Berg   Email Richard Berg         Edit/Delete Post 
quote:
Ana kata, it sounds like you are talking about what we used to call "Assembler Language," which was one step up from "Machine Language." I didn't think anybody used either any more.
Avisynth has several thousand lines of MMX and SSE, and will probably have a lot more before I'm done with it. Blame compiler vendors for not including vectorized primitives (though I suppose using them would still be darn close to programming in raw x86).

I'm a language junky, and I've never heard of C+. There exist the relatively obscure C+@ and C+-, but I doubt that's what you're talking about. Maybe it was a school-specific thing, the way high-school students used <apvector.h> instead of STL <vector> when the latter first came out?

[ December 07, 2003, 04:29 AM: Message edited by: Richard Berg ]

Posts: 1839 | Registered: May 1999  |  IP: Logged | Report this post to a Moderator
JonnyNotSoBravo
Member
Member # 5715

 - posted      Profile for JonnyNotSoBravo   Email JonnyNotSoBravo         Edit/Delete Post 
Wow, ana kata, I gained a lot of respect for you from all your posts in this thread! Having worked with PLCs and ladder logic before, I have to say you're 100 percent correct. Especially about the PLCs vs. PCs part. PLCs usually have only one piece of software, and don't have to be rebooted because they're dealing with very simple inputs. The machines that required PCs had to be rebooted at least once a week (and sometimes more when problems cropped up) to be sure they continued working correctly, although their calculations were a bit more complicated than the PLCs'.
Posts: 1423 | Registered: Sep 2003  |  IP: Logged | Report this post to a Moderator
ana kata
Member
Member # 5666

 - posted      Profile for ana kata   Email ana kata         Edit/Delete Post 
Cool, Johnny! Where did you encounter PLCs? Did you work at a plant or mill at some point? Are you in engineering?

Though at first I found the programming interface for PLCs incredibly crude and clunky, I came to appreciate the beauty and simplicity of ladder logic. The programming interfaces still leave much to be desired, the best probably being Rockwell Automation's RSLogix series, which is used with Allen Bradley PLCs, with the others trailing far behind.

I used to think that PCs would take over the industrial world, eventually, because you get so much more machine for so much less money. But now I don't think that will ever happen. I've not been very happy with the performance of PCs in industrial applications where I have seen them used. They just aren't reliable enough, their hardware or software either one. Like you said, you have to reboot once a week, and their hardware is much less tolerant of dirt, heat, and vibration. There are some industrial PCs that are built much tougher, of course, but they're much more expensive as well. And they still have the software problems.

Posts: 968 | Registered: Sep 2003  |  IP: Logged | Report this post to a Moderator
JonnyNotSoBravo
Member
Member # 5715

 - posted      Profile for JonnyNotSoBravo   Email JonnyNotSoBravo         Edit/Delete Post 
I was working with PLCs (as an electrician) at a manufacturing plant called Crown Photo Systems in Washington state(Marysville) and at Northwest Hardwoods (a mill owned by Weyerhauser). I worked with SLC 05/04s and SLC 100 and 150s. It's amazing how much better the software got for the newer PLCs, how you can get the timing down to ten thousands of a second, and check your ladder logic, and there are bright colors to tell you when things are firing or not(i.e. true or not).

I have a pet theory about why PCs need to reboot so often, but I need time to write it up and this is finals week for me [Frown] .

[ December 08, 2003, 11:11 PM: Message edited by: JonnyNotSoBravo ]

Posts: 1423 | Registered: Sep 2003  |  IP: Logged | Report this post to a Moderator
Alucard...
Member
Member # 4924

 - posted      Profile for Alucard...   Email Alucard...         Edit/Delete Post 
In my best Keanu Reeves imitation, "Whoa".

I have to go drill a hole in my forehead to relieve the pressure now...

Posts: 1870 | Registered: Mar 2003  |  IP: Logged | Report this post to a Moderator
   

   Close Topic   Feature Topic   Move Topic   Delete Topic next oldest topic   next newest topic
 - Printer-friendly view of this topic
Hop To:


Contact Us | Hatrack River Home Page

Copyright © 2008 Hatrack River Enterprises Inc. All rights reserved.
Reproduction in whole or in part without permission is prohibited.


Powered by Infopop Corporation
UBB.classic™ 6.7.2