# Thread: An Exercise In Logic

1. ## An Exercise In Logic

An Exercise In Logic. As a general overview you can look at as synthesizing a set of premises to support a conclusion. We start at the conclusion, the operation of an elevator, then work backwards to synthesize formal logic underneath the conclusion.

Consider an elevator. While the control system would be coded in a language like C, the decision making is done using a from of formal-symbolic logic. All computer lanmguages have some implementation of formal logic.

The task is to develop an algorithm using formal logic to determine the sequence of floor stops depending on the external call buttons and the buttons inside the elevator.

At any time an up or down button or the button fpr floors 1,2,3,4 can be pressed in the elevator.

There are logical hazards If the elevator is goind up headed towards the firs4 th floor and someone gets on at the third flor and presses 1, the elevator must go to 4 first. Another example, as people get on and off the elevator pessing the 2 anf 3 floor buttons the elevator can not get stuck going back and fothrt between the two floors.

Given are logical-Boolean variables.

Elevator call variables u. True if pressed false otherwise. When someone presses the button calling for an elevator the variable goes true. When the door opens at the floor the variable is returned to false.
F1_ Up
F2_Up
F2_Down
F3_Up
F3_Down
F4_Down

Floor indicators, tells you when a floor has been reacjed.
F1
F2
F3
F4

Up Down status.

Elevevator_Up
Elevator_Down

Elevator car buttons. Normally false, made true when pressed, and made false wham the floor is reached.

The algorithm must make the variables false when an operation is completed.

The algorithm will entail and ifnite loop.

START

…algorithm

Got TO START

When the algorithm starts it logically evaluates the buttons and determines the floor to go to. Paradoxes ot logical traps as outlined above are to be avoided. We all are familiar with elevators so the sequencing requirements should be obvious.

If the elevator is going up the Up vatribale is true. Down the Down variable is true.

Make use of logical contracts like if then else and while.

while(logical function){ logical stae,emts } executes the logical segments in the braces while the logical function is true.
If(logical function) { } same as above and so on.

If(logical function) { } else { }

Logical function is a variable or logical statement that evaluates to true or false. A logica; function could be if(F1_Up & F2_Up) ( …} If the function is true than excite the expressions in the braces. If false ignore.

It is a simplified version of a complete system. Simply properly sequence the elevator based on floor call buttons and elevator car buttons.

Something a little different than the usual syllogism. Applied logic.

https://en.wikipedia.org/wiki/Symbol..._(programming)

Some coding examples
https://en.wikipedia.org/wiki/List_of_logic_symbols
https://fresh2refresh.com/c-programm...cal-operators/
https://www.tutorialspoint.com/cprog...ical_operators

2. How will we judge whether our solutions are correct?

3. Originally Posted by A Toy Windmill
How will we judge whether our solutions are correct?
Because they work? You know, like to walk into the lift and hope for the best? I did something like that, being in the lift, myself.

Still, I think Steve isn't really talking about logic.

Rather, he seems to be talking about producing an algorithm, a model of the lift going up and down. Funny, I want to do that, but it's not logic.

Still, if this is really a thread about the logic of the lift, I want first a common lexis of the terms and symbols allowed, like, for example, ¬, ∧, ∨, ⊻, →, ⇔, ≡, ⊢ etc., complete with a short definition of each symbol.

And then, why not, an algorithm implementing the logic. Really implementing the logic.

But again, I want the language first, and preferably, something in widespread use, things like do while/loop, for i = 1 to 10/next i, etc.

Second, Steve will have to show his own solution.

OK, it's a start. What do you think?

Steve?
EB

4. Originally Posted by Speakpigeon
Because they work? You know, like to walk into the lift and hope for the best? I did something like that, being in the lift, myself.

Still, I think Steve isn't really talking about logic.

Rather, he seems to be talking about producing an algorithm, a model of the lift going up and down.
I say we're talking logic when we ask "how do we judge that the algorithm works independent of walking in and hoping for the best?"

5. Originally Posted by Speakpigeon
Still, if this is really a thread about the logic of the lift, I want first a common lexis of the terms and symbols allowed, like, for example, ¬, ∧, ∨, ⊻, →, ⇔, ≡, ⊢ etc., complete with a short definition of each symbol.
Ooh, can we have that anyway?

6. The judge will be your self. You can test the algorithm with a truth table, one common way.

Computer languages implement versions of formal logic with varying symbols. Pick you symbols and define them. You can invent your own if you like. If you work the problem work out symbols among you. Just like a real working group....

To actually work out the code would take me a full time 4 or 5 days and a few days for testing.

It is not a simple problem and it has a few pitfalls. First think of how an elevator works, develop a mental picture.

It is an exercise in imagination, reason, and logic combined. There may be no obvious solution at the start, how do you get to a starting point? Aristotelian logic is used, but there are no deterministic rules on how to apply it, that is what reason9ing is about.

Trial and error is part of it.

It is an exercise to gain understanding. Even if you get nowhere the effort can improve your logic and reasoning. Try an approach that fails. Evaluate and try again.

That is engineering and scince. And that is The Scientific Method'.

7. Originally Posted by steve_bank
The judge will be your self. You can test the algorithm with a truth table, one common way.
How do we test a while loop using a truth table?

8. Originally Posted by fast
Originally Posted by Speakpigeon
Still, if this is really a thread about the logic of the lift, I want first a common lexis of the terms and symbols allowed, like, for example, ¬, ∧, ∨, ⊻, →, ⇔, ≡, ⊢ etc., complete with a short definition of each symbol.
Ooh, can we have that anyway?
I guess we'll have to wait and see whether Steve can step up to the plate.
EB

9. OK, I guess we won't get Steve to step up. All talk, no action. Get a lift, man. Or call for help, there's a button.

Me, it definitely got me thinking. So, I'll do it, just because it's a good exercise and there are a few things to clarify.

Clearly, the way Steve presented the problem, he is confusing algorithms with logic. Typical of your average software practitioner. Some computer scientists even believe computers are logic itself. Whoa, some serious dogma there. Still, I don't think there's any difficulty in formalising the logic of lifts. I could even do a more general class of problems with lifts as a particular case. Ultimately, lifts are a restriction of reality as a whole. But, sure, we can simplify and limit ourselves to a small set of premises because life is short. The lift will go up and down. It will stop at a floor if requested by the occupant of the lift but only if there is no fire going on at the floor. There will be a call-for-help button. And a button to play muzak. For stopping the doors closing or for asking immediate closing. What else?

And only logic and nothing else.
EB

10. Originally Posted by steve_bank
To actually work out the code
No code needed, Steve. It's a logical problem.
EB

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•