Program Logic Formulation Introduction

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 53

Program Logic Formulation

{ IT10
Two girls were born to the same
mother, on the same day, at the same
time, in the same month and year and
yet they’re not twins. How can this be?
Who killed #9?
What is a Program?
Noun:
A set of related measures or activities with a particular long-term

aim.
A series of coded software instructions to control the operation of a

computer or other machine.


Verb:
Provide (a computer or other machine) with coded instructions for

the automatic performance of a task.


Arrange according to a plan or schedule.
What is a Computer Program?

 A computer program is a collection of instructions that performs a


specific task when executed by a computer. Most computer devices
require programs to function properly.

 A computer program is usually written by a computer programmer


in a programming language.
What is Logic?

 The systematic study of the form of valid inference, and the most
general laws of truth.
 A valid inference is one where there is a specific relation of logical

support between the assumptions of the inference and


its conclusion.
What is Logic?

 A logic is a language. It has syntax and semantics. More A logic is a


language.
 A systematic way of reasoning that provides standard by which

valid reasoning can be recognized.


What is Logic?

 Syntax: the rules about how to form formulas; this is the rules about
how to form formulas; this is usually the easy part of a logic.
usually the easy part of a logic.
 Semantics: about the meaning carried by the formulas, about the

meaning carried by the formulas, mainly in terms of logical


consequences. mainly in terms of logical consequences.
 Inference Rules: describe correct ways to derive describe correct

ways to derive conclusions.


Aspects of Logic Programming

 Programs are written on the language of some logic.


 Execution of a logic program is a theorem proving process; that is,

computation is done by logic inferences.


 Prolog (PROgramming in LOGic) is a representative logic language.
Why Prolog is not as popular as C/Java?

 Mistaken at first some universal computer language.


 Not yet efficient as C.

 Support to Prolog takes effort, resources ; companies are not willing

to pay for it.


 Its value is not recognized by industry.
Use Logic to do Reasoning
 Example: Given information about fatherhood and motherhood,
determine grand parent relationship. grand parent relationship.

 E.g. Given the information called facts:


 John is the father of Lily

 Kathy is the mother of Lily

 Lily is the mother of Bill

 Ken is the father of Karen

 Who are grand parents of Bill?


 Who are grand parents of Karen?
Use Logic to do Reasoning

 In Prolog, we write the following for the given facts:


 father(john,lily)

 mother(kathy,lily)

 mother(lily,bill)

 Father(ken,karen)

 In logic, words like father, mother are called predicates predicates.

 A statement like father(john,lily) is called an atomic formula, ,

called an atom, stating a true fact


Program as Logic Formulas
 Express the grand parent relationship:
grandparent(X,Z) :- parent(X,Y), parent(Y,Z)
parent(X,Y) :- father(X,Y)
parent(X,Y) :- mother(X,Y)
 These are called conditional statements. Capital letters denote

variables, meaning “ “for any for any” ”.


 E.g., the first formula above reads:

For any X,Y,Z,


if X is a parent of Y, and Y is a parent of Z,
then X is a grand parent of Z.
A complete program
 Putting all together, we have a Prolog program:

Grandparent(X,Z) :- parent(X,Y), parent(Y,Z).


Parent(X,Y) :- father(X,Y).
Parent(X,Y) :- mother(X,Y).

Father(john,lily).
Mother(kathy,lily).
Mother(lily,bill).
Father(ken,karen).
Ask Prolog to do something

 Provide a query to Prolog:


?-grandparent(john,bill)
Prolog uses your program to do the reasoning and answer the query.
In this case the answer will be YES. Why?

 If you post your query as:


?-grandparent(Q,karen)
In this segment, it will answer NO.
Ask Prolog to do something

 Provide a query to Prolog: Who are the grand parents of Bill?


?-grandparent(Q,bill)

Prolog will answer:


Q = john
Q = kathy
Ask Prolog to do something

 Provide a query to Prolog: Who is the grand child of John?


?-grandparent(john,W)

Prolog will answer:


W = bill
Another example
 Given a list of integers, get the sum.

 We will define a predicate


sum(L,R)
Where L is a given list, and R will be used to hold the result.

Example Query:
?-sum([3,5,2]),Q)
Prolog should return the answer:
Q = 10.
What is Formulation?

 The action of devising or creating something.


 A term used in various senses in various applications, both the

material and the abstract or formal. Its fundamental meaning is the


putting together of components in appropriate relationships or
structures, according to a formula.
What is Program Logic Formulation?
 Usually defined as the process of coming up with the appropriate
methodology in developing a specific program logic that will
perform a prescribed computing task or solve a problem using the
computer.
Computer Software

 Refers to all computer programs or routines which direct and


control the computer hardware in the performance of its data
processing functions.

 2 Major Category of Software:


 Application Software
 System Software
Application Software
 A software that perform a specific task for computer users.

System Software
 A software that designed to help programmers or to control the
computer system.
Systems Analysis

 The computer age equivalent of the scientific method.


 In systems analysis, the problem is defined and analyzed and

solutions recommended to management.


 This process has been formalized and called Systems Analysis and

Design Method.
System Definition

 A collection of people, machines, & methods organized to


accomplish a set of specific functions.
 An integrated whole that is composed of diverse, interacting,

specialized structures and sub-functions.


 A group of sub-systems united by some interaction or inter-

dependence, performing many duties but functioning as a single


unit.
Computer-based IS
 A computer-based information system fits all three definitions. It
involves people, machines, and methods (procedures & data); it
behaves as an integrated whole; and most information systems are
composed of a group of subsystems.
General Systems Theory

• Provides another
way of defining a
system – as a
collection of inputs,
outputs, and
processor activities
with feedback, a
boundary, and an
environment.
System Analyst
• A person trained in the analysis of complex business system, which
typically involve a computer-based information system.
Systems Development Life Cycle (SDLC)

• SDLC is used to describe the steps or phases a system goes


through from the time it is conceived until it is phased out of
existence.
• The names and number of phases in a system life cycle vary with
different industries, organizations w/in industries,& systems
analysts.
Systems Development Life Cycle
(SDLC)
1. Problem identification, opportunities, objectives
2. Determining information requirements
3. Analyzing system needs
4. Designing the recommended system
5. Developing and documenting the software
6. Testing and maintaining the system
7. Implementing & evaluating the system
Notes on SDLC
• Identifying these phases provides a framework for controlling,
estimating, and observing the evolution of a system.
• Each phase produces documentation, w/c is written or pictorial
information that describes the system.
• This documentation in turn forms the basis of a management
review that determines whether the project should proceed to the
next phase.
Software Development Process

• In this process user needs are translated into software


requirements; software requirements are transformed into design;
the design is implemented in code; and the code is tested,
documented, and certified for use.
Notes on Software Development
• Top-down Software Design
– The process of designing a program by first identifying its
major components, which are called modules; then
decomposing them into lower level components.
Notes on Software Development
• Structured Program Walkthrough
– A method of program inspection wherein a segment of
design or code is presented for questioning; comments
about technique, style, possible errors, deviation from
standards, & other problems.
Notes on Software Development
• Alpha Test
– A program state during the structured code walkthrough.
Notes on Software Development
• Alpha Test
– A program state during the structured code walkthrough.
Notes on Software Development
• Beta Test
– The software is not certified or approved for routine use until it
has survived this type of test.
– Beta testing is done by users who accept the pioneer status
associated with being first-time users.
Documentation Categories

1. Design documentation
• Contains data flow diagrams; functional, performance, &
data storage requirements; & management reports.
2. Programming documentation
• Used by technical people to define the architecture of an
information system.
3. User documentation
• Consists of training, operations, & reference manuals that
describe how to use the system.
Installation Phase

• A phase in which a system is integrated into its operational


environment and is tested to ensure that it performs as
required.
• Putting the system into use by the people who must run
and maintain it.
• People must be trained, new procedures instituted, & the
system thoroughly “shaken down” to eliminate any error
or deficiencies.
Activity #1: Exercising Logical Thinking
related to real world situations
#1 Crossing the River

• Two people come to a river. There is a boat, however it can


carry one person only. How can they each get to the other
side of the river using the boat?
#2 Ping-Pong ball in a hole

• Your last good ping-pong ball fell down into a narrow metal
pipe down imbedded in a concrete one foot deep. How can
you get it out undamaged, if all tools you have are your
tennis paddle, shoe-laces, and your plastic water bottle,
which does not fit into the pipe? What will you do?
#3 A Man in an Elevator

• A man who lives on the tenth floor takes the elevator down
to the first floor every morning and goes to work. In the
evening, when he comes back; on a rainy day, or if there
are other people in the elevator, he goes to his floor directly.
Otherwise, he goes to seventh floor and walks up three
flights of stairs to his apartment. Can you explain why?
#4 The Ball

• How can you throw a ball as hard as you can and have it
come back to you, even if it doesn’t bounce off anything?
There is nothing attached to it, and no one else catches or
throws it back to you?
#5 Where is the Father?

• A mother is 21 years older that her child. In exactly 6 years


from now, the mother will be exactly 5 times as old as the
child. Where’s the father?
#6 Password

• Chris will sign-up to a website but in order for him to get


registered he needed a password with at least 6 characters
on it. He realized that he is a forgetful person that’s why he
wrote something in his sticky notes, statement that says
“You force heaven to be empty”. What password did Chris
used?
#6 Guy

• Alice’s mother died due to cancer. One day, at the funeral a


guy visited her mother’s remains. Alice fell in love at the
guy the first time they met. But after her mother’s funeral
ceremony, the guy left and she didn’t get the chance to
know the guy’s name. A few days later, she killed her sister.
Why?
#7 Sharks

• Imagine you are in a sinking boat surrounded by sharks.


How would you survive?
#8 Penguin

• Which one is correct? “Penguins flies” or “ A Penguin flies”


#9 Dark Room

• You are in a dark room. You have one match left. Which do
you light first? The newspaper, the candle or the lamp?
#10 Number Series
• January = 1017
• February = 628
• March = 1335
• April = 145
• May = 1353
• June = 1064
• July = 1074
• August = 186
• September = 1999
• THEN
• October = ???
• November = ???
• December = ???

You might also like