In the previous example we used statements as propositions. Computer logic is accomplished by using logic gates as building blocks. A logic gate is a physical circuit which has electrical inputs and usually a single output.
Used in truth tables, we label each input and use truth values to represent weather or not an input is on or off.
We use the value true , T , 1 to represent on and false , F , 0 to represent off.
Sometimes, On is refered to as a high voltage and off is referred to as a low or no voltage.
The most common gates are shown in the table below:
Gate
AND
OR
NOT
NAND
NOR
XOR
Symbol
Inputs
A
B
Q=AB
Q=A+B
Q = A
Q=AB
Q= A+B
Q= A ⊕ B
0
0
0
0
1
1
1
0
0
1
0
1
1
0
1
1
0
0
1
0
1
0
1
1
1
1
1
0
0
0
Description
Outputs 1 when all inputs are 1
Outputs 1 when ANY input is a 1
Inverts the input
Outputs 0 where all inputs are 1
Outputs 1 then both inputs are 0
Outputs 1 when exactly one input is 1
Outputs 0 otherwise
Outputs 0 otherwise
Outputs 1 otherwise
Outputs 0 otherwise
Outputs 0 otherwise
Typing the mathematical notation into most word processors can be challenging. Sometimes these worded expressions or symbols are used :
Warning: I wrote to following paper to maintain a high level of precision when considered formally under the disciplines of mathematical logic and computer science. This allows for the proper consideration of semantics in future discussions.
This writing may lead you to believe that you are taken along a platitude of truism devoid of axiomatic purpose that amounts to a march of banality unrivaled in the history of human thought.
Let us begin.
Definition : A truth table lists all possible unique inputs to a logic function accompanied by each output value.
A truth table uses the veracity of propositions. Veracity refers to truthfulness, whether the statement is true or false. A proposition is a statement.
e.g. let P be the proposition ‘it is raining’.
We can assign 2 values to P. That is,
P = true
meaning that ‘the statement P is true’
P = false
meaning ‘the statement P is false.
NOTE: We can use the following symbols for truth values:
VALUE
SYMBOL
True
True, T, 1
False
False, F, 0
In the above example, the proposition for P can be written as the following table:
P
True
False
Note, the proposition has no meaning when taken by itself. Here we only see the possible circumstances described by the statement as it can be used as an input to a logical scenario or taken s the output of a scenario.
I now introduce…
Truth tables in computer science
In this context, Truth tables can be used to represent the voltages that are applied as input to a circuit and the resulting output.
Though it may seem trivial, we consider a simple circuit with one input or switch , a battery, and a one output or lightbulb:
Approaching this physical construct of discrete possible events using mathematical logic we say:
Let the input be called I , and we use the convention that a value of 1 means that a high voltage is applied to the bulb and a 0 being the falsehood of “a high voltage is applied to the bulb ” or rather we can say a high voltage is not applied to the bulb or simply no voltage is applied to the bulb.
Another school as thought would describe I having a value 1 as the switch is onand I having a value of 0 as the switch is off.
Let the output of the circuit be O using the convention that a value of 1 means that the bulb is lit and a value of 0 means the falsehood of “the bulb is lit” or rather we can say the bulb is not lit or simply the bulb is unlit.
Yet another school of thought would describe O having a value of 1 as a high voltage was observed at the output and O having a value of 0 aslow orno voltage observed at the output
Now we are ready to consider these discrete events devoid of timing to form an enumeration or superposition of sorts that is a truth table.
We arrive at the following truth table which list all possible inputs to the “circuit” and the observed outputs:
I
O
1
1
0
0
This table tells us,
For an input of 1:
If a high voltage is applied to the bulb , the bulb is lit
If a high voltage is applied to the bulb then the statement “the bulb is lit” is True
If a high voltage is applied to the bulb , a high voltage was observed at the output.
If the switch is on, the bulb is lit
For an input of 0
If a high voltage is not applied to the bulb, the bulb is unlit
If no voltage is applied to the bulb, then the statement “the bulb is lit” is False
If no voltage is applied to the bulb , low or voltage was observed at the output.
If the switch is off, the bulb is unlit.
Our truth table allows for us to perform an abstraction on our circuit so that we no longer consider the events that physically occur in the circuit, rather the ideas on how the circuit’s output behaves given discrete inputs.
We no longer care about how the circuit is physically implemented; rather we only consider the logical implications of using the particular type of circuit as a building block in other circuits.
First Come First Serve or Non-pre-emptive Scheduling.
The CPU can run processes in the process queue (in ready state) one at a time for a “burst” at a time in a first come first serve fashion. This is known as non pre-emptive scheduling, since no determination is made into the most efficient order to run processes on the CPU.
It should be noted that the amount of time that a process might stay on the CPU could be very long when compared to others in the queue. This is because a “burst” might a sequence of CPU and IO instructions the process executes without interruption form the CPU scheduling algorithm . The process is only moved from execution on the CPU when a I/O operation occurs that causes the process to be put in wait mode, or, it terminates.
Having other processes wait exceedingly long is not desirable, and todays modern operating systems do not implement FCFS.
FCFS scheduling does have the advantage of being easier to program and implement; but this advantage does not outweigh the performance of an efficient process scheduler.
FCFS scheduling is also prone to race conditions, where 2 processes need to read from the same section in memory and end up producing inconsistent data. See here for a good explanation:
This scheduling algorithm examines each process to determine the length of time that is needed for on the CPU. The algorithm then places processes with the shortest estimated time to be executed as priority.
Round Robin Scheduling
This is very similar to FCFS scheduling , only this time each process is given a fixed maximum time to be executed on the CPU. If the process exceeds the time, it is put in wait mode and added to the end of the queue.
Previously we have seen an implementation for a library catalog ( Mini IA Example – A library catalog). That implementation used binary files.
In this class video, we anticipate the scenario where will upgrade the library catalog to store information about people. We explore this implementation using plain text files. Plain text has the advantage that the datafile is easily viewable and editable.
Both examples use the strategy to load ALL DATA AT THE START of the program. Whenever any new data is added to the system, we save all data in structure arrays by calling our save() functionswhich OVERWRITE the older files.
In real world practice, overwriting files on every data addition would not be as efficient , however this strategy is the easiest to manage at our introductory level. Other strategies appends the data to the end of the file which involve testing for the end of file or managing sentinel file values.