• Starting today August 7th, 2024, in order to post in the Married Couples, Courting Couples, or Singles forums, you will not be allowed to post if you have your Marital status designated as private. Announcements will be made in the respective forums as well but please note that if yours is currently listed as Private, you will need to submit a ticket in the Support Area to have yours changed.

  • CF has always been a site that welcomes people from different backgrounds and beliefs to participate in discussion and even debate. That is the nature of its ministry. In view of recent events emotions are running very high. We need to remind people of some basic principles in debating on this site. We need to be civil when we express differences in opinion. No personal attacks. Avoid you, your statements. Don't characterize an entire political party with comparisons to Fascism or Communism or other extreme movements that committed atrocities. CF is not the place for broad brush or blanket statements about groups and political parties. Put the broad brushes and blankets away when you come to CF, better yet, put them in the incinerator. Debate had no place for them. We need to remember that people that commit acts of violence represent themselves or a small extreme faction.
  • We hope the site problems here are now solved, however, if you still have any issues, please start a ticket in Contact Us

Computers and Logic

DoubtingThomas29

Senior Member
Mar 4, 2007
1,358
79
✟24,402.00
Faith
Atheist
Marital Status
Single
I don't know that much about computers. I have had a programming class on C++, but really I didn't understand too much stuff in there. I am hoping to get a bachelor degree in computer science and really learn how these things work.

I remember hearing that once we could describe if then statements that was when computers took off.

If X Then Y. If not X Then Not Y.

So I don't know how computers do logic, anyone care to explain?
 

Eudaimonist

I believe in life before death!
Jan 1, 2003
27,482
2,738
59
American resident of Sweden
Visit site
✟134,256.00
Gender
Male
Faith
Atheist
Marital Status
Private
Politics
US-Libertarian
So I don't know how computers do logic, anyone care to explain?

I'm a professional computer programmer.

Okay, let's start at the beginning. I'll try to keep things very simple. I'll probably oversimplify, but that's what you need at the moment.

You've heard of computer memory, right? The basic unit of memory is the bit, which can equal 1 or 0. (From the hardware perspective, this means on or off.)

Most PCs these days have a 32-bit processor. This means that each series of 32-bits may be read by the processor as an explicit instruction for it to do something. This is not something you "see" at the level of programming languages such as C++. It turns out that when you compile your C++ program, the compiler generates all those low level instructions for you. This is a good thing, because it is tedious to write programs using those instructions. (I know, because I have done this. Those instructions are called Assembly Language.)

Among those instructions are various "branches" based on a comparison. For instance, a particular instruction may cause the CPU to check that the numbers stored in two distinct memory locations are identical (which it handles through hardware wiring), it might "branch" by causing the next instruction to be processed to be at some specified location, instead of immediately following the instruction in memory.

These branching instructions are involved in your compiled C++ program where there are "if" statements.

Is this what you wanted to know?


eudaimonia,

Mark
 
Upvote 0

ArnautDaniel

Veteran
Aug 28, 2006
5,295
328
The Village
✟29,653.00
Faith
Other Religion
Marital Status
Married
Politics
US-Others
I don't know that much about computers. I have had a programming class on C++, but really I didn't understand too much stuff in there. I am hoping to get a bachelor degree in computer science and really learn how these things work.

I remember hearing that once we could describe if then statements that was when computers took off.

If X Then Y. If not X Then Not Y.

So I don't know how computers do logic, anyone care to explain?

Computers basically use little things called "transistors" to do simple logic operations like you are talking about.

You can look them up on Wikipedia, I'm sure, but basically a transistor is something that let's a signal A through when a particular signal B is applied to it, and doesn't let A through when B isn't applied.

From 4 or 5 of these one can build up a logical gate that does something more resembling formal logic.
 
Upvote 0
N

Nathan45

Guest
I think he's more interested in the software level than the hardware level...

I don't know that much about computers. I have had a programming class on C++, but really I didn't understand too much stuff in there. I am hoping to get a bachelor degree in computer science and really learn how these things work.

I remember hearing that once we could describe if then statements that was when computers took off.

If X Then Y. If not X Then Not Y.

So I don't know how computers do logic, anyone care to explain?

Well, the simplest type of program is just a basic linear program.

Linear programs just do a bunch of stuff in order.

for a basic program, the programming file is just a text file with a bunch of programming commands, that are executed in order. The programming commands are defined by whoever wrote your programming language or whoever wrote your third party function librarires to go with your programming language.

So you'll have a list of stuff for your program to do, from top to bottom, selected from your personal collection of functions and commands written by other people. So you're building on whatever they wrote, but you get to choose the order to execute it in. ( unless you want to build your program out of whole cloth, this is the way to go ).

You'll have various logic statements such as if statements, and loops. You also have variables. Generally you'll have an "If" statment, which checks the value of some variable. If the variable is equal to the value it's checking against, it will execute a block of code associated with the "If" statement. Included in the block of code can be other statements which can changes the values of whatever other variables you want to change.

here's an example of an IF statement
// note, in code anything behind a "//" is a comment for
// the reader and not actual executed code.
// at least in c style languages...


Code:
If ( 50 == x ) 
{  
    DoSomething();
}
NextStatement();

...

The command "DoSomething()" ( inside the {} ) will only be executed if the value of the variable "x" is 50. If it isn't 50, then nothing will be done. and it will move on to the next statement.

Then you have loop statements, which are blocks of code that continuously execute again and again, until the loop breaks. the loop breaks on a condition, usually by checking a variable.

For example, a loop ( in pseudocode ):

Code:
int x = 0; // sets the starting value of x to zero. 
Loop
{
   // Code goes here to execute a bunch of stuff
   x = x + 1  // this line increases the value of the variable "x" by 1. ) 
   if ( x == 10 )  break; // the loop exits once x is 10, so it loops 10 times. 
}

So this code will loop through everything between the { } 10 times. Because after

...

Later, past simple programs, you'll get to "event based" programs, with multiple threads.

Here, you have one ( or more ) page which describes what your user interface looks like. ( an example of this type of page is HTML code for a web site, or instructions for a windows-form application )

Then you have a bunch of buttons on your form or web application. Each button will cause an "event" ( defined in a separate code file ) which will run a linear program. So you have a bunch of little programs inbedded in a user interface, and clicking a button fires an "event" which creates a new thread and produces a particular action, which is defined in your event handler which is associated with that button/action.

You also have data storage... the simplest type of datastorage is just writing stuff to a notepad file, and then reading it later in the program or reading it by some other program. Or just storing it.

More complicated data storage can involve 3rd party database software ( such as microsoft SQL server ), designed to organize your data for use in your programs.

You also have Methods ( also called functions ), which are blocks of code that can be run anytime the function is called.

So, in the middle of your code, you'll put a line that says:

DoSomething();

and then later down at the bottom of your code, you define what "DoSomething();" does.

so you'll have a definition:

Code:
void DoSomething()
{
   // Put code in here to define what DoSomething() does. 
}

So if you have this definition at the bottom, then anywhere else in your code where you write "DoSomething()" it will execute the above block of code.

Also, all the code you write, will either be simple arithmatic, loops, or if logic, with variables you create, while calling functions.

Many functions are pre-made by some third party or someone else in your office, you don't write them yourself, they're written either by whoever created the programming language you are writing with, or they're created by some third-party vendor, or some guy downstairs... You build on what other people have written... for example, someone may have written a graphics program, which is designed to do graphics and design forms, text editors and all kinds of stuff. You don't really do anything with the manual pixels you simply call functions they've already made.

You use premade stuff so you don't have to reinvent the wheel by manually changing pixels everytime you want your program to display some image.

To call other people's functions, you need to associate your program with the various precompiled .dll files that you will obtain from third party sources. Note, that other people don't usually let you see their programming code, they simply give you the compiled version stored in the .dll file. ( actually .dll stuff is specific to microsoft stuff, but other types programers have different ways of doing this. some video game programmers make everything from scratch... you'll have one guy designing hte gameplay, scenarios, etc, another guy builds a graphical user interface from scratch... the lower level guy will design the graphics engine ( which consists of functions used by the higher level guys to draw cool 3d things ), also there be a game engine for each game, which will idealy be flexable and reusable in later games. )

Basically all programming is made up of premade functions and operators coded by other people, until you get to the very bottom 0s and 1s. So there's "lower level stuff" and "higher level stuff", layered on top of eachother... a windows application would be a higher level program... below that you have "windows forms" which is a premade library and interface used to make windows applications, written by microsoft...

...
next up parameters:

since i was talking about functions, You can also pass "parameters" to these functions, which are variables, and functions can return values. So, for example, you could have a function called "multiply", with two parameters, being the two values you multiply. When you called the function, it would multiply the values together, and "return" the result.


so the code might look like this:

Code:
x = Multiply(5,10); // this sets the variable x to 50, which is 5 * 10 
Print(x); // this displays 50 for the user. 
 
// ... and then the definition for "Multiply" ...
 
int multiply(int a, int b)
{
return a * b; // this "returns a times b. 
}

The above is pointlessly simple, but you get the idea... ( do you ? )
...

also, later you'll get into stuff called "Object oriented programming" where you have all of the above, except wrapped in "classes" and "objects" to organize it all better, or to make it all pointlessly complicated. But that's more advanced stuff, best to learn the above first.

If you want to get started programming, you'll probably want to download an IDE. You can get a free one from microsoft, google "Microsoft Visual Studios Express Edition" for info on that. Also there will be all kinds of training and instructional stuff that you can find for visual studios. ( and you can pick your programming language... i do most of my stuff in C#, but people use all kinds of languages ). It's a good idea to start learning how to use IDE's, cause half the job of programming is knowing how to make full use of the tools in these kinds of applications that help you write code.

Also there are a bunch of programming languages but they're basically all mostly the same, just different syntax. Once you learn one language you can learn the rest pretty easily.
 
Upvote 0

Eudaimonist

I believe in life before death!
Jan 1, 2003
27,482
2,738
59
American resident of Sweden
Visit site
✟134,256.00
Gender
Male
Faith
Atheist
Marital Status
Private
Politics
US-Libertarian
If you want to get started programming, you'll probably want to download an IDE. You can get a free one from microsoft, google "Microsoft Visual Studios Express Edition" for info on that. Also there will be all kinds of training and instructional stuff that you can find for visual studios. ( and you can pick your programming language... i do most of my stuff in C#, but people use all kinds of languages ). It's a good idea to start learning how to use IDE's, cause half the job of programming is knowing how to make full use of the tools in these kinds of applications that help you write code.

Yes, I definitely recommend C# as a training language. It has a smoother syntax than C++ and has many good features, and the .NET Framework provides a fantastic library of functions to work with.


eudaimonia,

Mark
 
Upvote 0

DoubtingThomas29

Senior Member
Mar 4, 2007
1,358
79
✟24,402.00
Faith
Atheist
Marital Status
Single
Thank you everyone for showing up and explaining programming to me. I heard from my uncle that programming jobs are done over seas now and there are still things that have to be done on site. However, judging from what I have read here on this thread, and from my experience in C++ it is going to be difficult for me to learn Computer science. I do need to learn some tools too, such as Excell, SAS, and Access. I plan to get a Ph.D. in mathematics, and a Ph.D. in Satistics, you can get paid and go to school to to get those degrees, like twenty thousand a year. So I definitely want to do that, but I can't keep learning math, and know almost nothing about computers, all I'll be able to do is teach, and I love teaching, but I keep getting jerks in my classes, and that is not something I want to have to deal with, I mean e adminstrators are not backing me up. It is like they see me, and I have four years of teaching experience, from college to high school to middle school, and even some elementary. And me trying to secure employment as a teacher, is almost as hard as if I was trying to be a ballerina at three hundred twenty pounds. Or doing tap dance, it is like I am trying to make a living doing tap dance, and trust me that is beyond my ability, I hope after getting a double doctorate, an a computer scinece degree and perhaps some training in biostatistics, I can finally get hired as a mathematician or statistician. Teaching is not my cup of tea, it is just been so problamatic and I give up. I tried I really tried, but I quit it is too hard trying to keep a job as a teacher.

To all you teachers out there, good luck to you, you need it.
 
Upvote 0

StrugglingSceptic

Regular Member
Dec 26, 2003
291
13
42
✟22,986.00
Faith
Atheist
I'll offer a different perspective on the question.

Humans have always been able to describe "If then statements", or conditionals, and the study of logic goes back at least to Aristotle in the 4th century BC, before anyone could dream of a computer. Conditionals alone are insufficient for describing computers. But surprisingly, you don't need a whole lot more, and a mathematical definition of a computer can be built in so-called "First-Order Predicate Logic", which you'll no doubt encounter if you do a degree in mathematics or computer science. This logic was invented fairly recently by a German mathematician, Gottlob Frege, at the end of the 19th century. Using it, we can talk, not merely about conditionals and negations, but also properties and objects. And once we can say things like

"for every x, it is the case that x satisfies some property"

and talk about functions and operations, thus being able to say

"for every x and y, x + y = y + x"

it is possible to define what it means to compute something.

But that's not really how it all started. It started by observing that a computer is actually a very simple device. I can define one now, though it won't be mechanical or electronic. So imagine you have an arbitrarily long street with an infinity of postboxes, numbered with addresses from 0 upwards, each containing a slip of paper on which is written the number 0. Suppose I give you a list of numbered instructions. Each instruction takes one of the following forms:

1) Go to the postbox at address m. Remove the paper inside it and replace it with another piece of paper on which is written the number 0.
2) Go to the postbox at address m. Check the number on the paper inside, and replace it with a piece of paper on which is written that number plus 1.
3) Swap the pieces of paper at the postboxes with addresses m and n.
4) Check the pieces of paper at the postboxes m and n. If the same number is written on both, carry on from the instruction numbered p. Otherwise, continue as normal.

Even in such a simple setting, I could, in principle, give you a set of instructions which would have you carry out any computation that any modern computer could carry out. I still find this an astonishing fact. And indeed, some microprocessors are not much more complicated than this scenario I just described.

This discovery (a somewhat empirical one, going by the name of the Church-Turing Thesis), came about when many logicians and mathematicians were coming up with ways to define what it meant to compute something. It turned out that all of their formulations were in some sense equivalent, and nobody could find a sensible way of defining computability that went beyond any of the others. It is around this time that computers started to take off, on the basis of a solid theoretical foundation of what it meant to be a computer. Alan Turing himself worked with code-breaking computers during the Second World War.

So this is not strictly about logic, although logic and computing are entwined by some deep theoretical results in mathematics. The fact that there are certain things that cannot be proven in a formal logic relates closely to the fact that there are certain computations that a computer cannot, even in principle, carry out. I would be happy to elaborate on this, though it gets technical very quickly.

Logic and computing are also entwined by their historical development. While Alan Turing and others worked on the theoretical concept of a computer that would later become the basis of modern processors and imperative languages, Alonzo Church was busy in logic.

Church was attempting to come up with a logic for all of mathematics, based on his own formalism called the "Lambda Calculus". This calculus is kind of like a fun game with symbols, but extraordinarily, an enormous number of mathematical operations can be expressed using it. Church's logic turned out to be inconsistent and he had to scrap it, but his Lambda Calculus was retained.

Like the postboxes scenario above, it can be shown that any operation you can express in the Lambda Calculus corresponds to a computer program, and vice versa. That means that the Lambda Calculus is, in some sense, equivalent to a computer.

Many, many computer languages exist nowadays, and many of them are so different that it requires a whole new understanding of programming to move between them. For this reason, it is often recommended that you learn as many different languages as possible in order to become a good programmer, so that your mind is trained to the different ways of thinking. Broadly, we can separate all computer languages into two types: functional languages and imperative languages. This divide is largely unfair now, because many modern languages incorporate features from both sides of the water (including C++), and there are styles of programming, such as Object-Oriented Programming and styles of concurrent programming which probably belong on their own. However, imperative languages and functional languages is where it all started.

In an imperative language, a programmer describes a sequence of actions that will lead to some result. Turing machines and their ilk could be said to have given birth to these sorts of languages, and in fact, computers themselves work internally along these lines. But it was the Lambda Calculus, and therefore, in some sense, logic which gave us the functional languages. Indeed, John McCarthy explicitly used the Lambda Calculus when he invented LISP, which has inspired every other functional language since.

Computing has also been important to logicians. It has long been assumed that a truly rigorous mathematical argument is one that can be translated into symbols and then checked by a dumb machine, a machine which has no understanding of what those symbols actually mean. So one important feature required of formal logics is that a machine should be able to determine whether or not any sequence of statements in such a logic constitutes a valid proof. This idea itself must be expressed mathematically, and naturally, mathematicians favour a functional notion of computability rather than an imperative one, typically using so-called "General Recursive Functions."

If you are interested in mathematics, I recommend learning a functional language such as Haskell (named, incidentally, after a logician). Such languages have a much more logical and mathematical character than imperative languages. Broadly speaking, writing functional code involves describing the mathematical relationships of a computation and then letting the results take care of themselves. You'll find that many of the ideas in a language like Haskell complement ideas you learn in mathematics, and so the two disciplines will reinforce one another.

By the way, you should not be thinking about getting a doctorate because you want to get a good job. You do a phD because you want to do research.
 
Upvote 0

Eudaimonist

I believe in life before death!
Jan 1, 2003
27,482
2,738
59
American resident of Sweden
Visit site
✟134,256.00
Gender
Male
Faith
Atheist
Marital Status
Private
Politics
US-Libertarian
By the way, you should not be thinking about getting a doctorate because you want to get a good job. You do a phD because you want to do research.

That's definitely true. If you want to make money, a bachelor's degree in Computer Science is ideal. Advanced degrees are for people who truly love research.


eudaimonia,

Mark
 
Upvote 0