TÓM TẮT From a variety of sources and documents, this year's HKI 2019-2020 Discrete Structures exercise deals with the inverse Polish algorithm for logical expressions, from infix to po
Trang 1TỔNG LIÊN ĐOÀN LAO ĐỘNG VIỆT NAM TRƯỜNG ĐẠI HỌC TÔN ĐỨC THẮNG KHOA CÔNG NGHỆ THÔNG TIN
BÀI TẬP LỚN MÔN CẤU TRÚC RỜI RẠC
KÝ PHÁP BA LAN NGƯỢC CHO BIỂU THỨC LOGIC
Người hướng dẫn: GV NGUYỄN QUỐC BÌNH Người thực hiện: NGUYỄN VĂN LỘC – 518H0647
VÕ TUẤN LỘC – 518H0390
Lớp : 18H50302
Khoá : 22
Trang 3TỔNG LIÊN ĐOÀN LAO ĐỘNG VIỆT NAM
TRƯỜNG ĐẠI HỌC TÔN ĐỨC THẮNG
KHOA CÔNG NGHỆ THÔNG TIN
BÀI TẬP LỚN MÔN CẤU TRÚC RỜI RẠC
REVERSE POLISH NOTATION
FOR LOGIC EXPRESSION
Người hướng dẫn: GV NGUYỄN QUỐC BÌNH Người thực hiện: NGUYỄN VĂN LỘC – 518H0647
VÕ TUẤN LỘC – 518H0390
Lớp : 18H50302
Khoá : 22
THÀNH PHỐ HỒ CHÍ MINH, NĂM 2019
Trang 4LỜI CẢM ƠN
Thank you to the lecturer - Mr Nguyen Quoc Binh, for taking the time and effort to help and support us to complete this great exercise, he has answered and guided enthusiastically the necessary knowledge It is very useful and helpful to help this project complete as expected and bring value to Ton Duc Thang University with good projects And I also do not forget to thank the contributions and companionship of my friend Vo Tuan Loc - Student of Information Technology, Computer Science Department for taking time and effort to support
me to complete well and on time degree of this essay report Sincerely thank you
Trang 5TÓM TẮT
From a variety of sources and documents, this year's HKI (2019-2020) Discrete Structures exercise deals with the inverse Polish algorithm for logical expressions, from infix to postfix, postfix to truthtable The effect of this algorithm is that it will help the computer, calculate but the complex expression quickly The main function of the algorithm is
to calculate the value of the expression, the focus and mainly we
transfer the prime factor ( Infix) in suffix form (Postfix).We have been researching and learning about parallel Stack and List for the last time, and we also learn the logical operator functions used to convert Polish backwards and calculate and create a Truth Table based on the square That
Trang 7MỤC LỤC
LỜI CẢM ƠN ii
PHẦN XÁC NHẬN VÀ ĐÁNH GIÁ CỦA GIẢNG VIÊN ii
TÓM TẮT ii
MỤC LỤC 1
DANH MỤC KÍ HIỆU VÀ CHỮ VIẾT TẮT 2
CHƯƠNG 1 – GIỚI THIỆU 2
CHƯƠNG 2 – CƠ SỞ LÝ THUYẾT 2
2.1 Lý thuyết về Reverse Polish Notation (RPN) 2
2.2 Lý thuyết về logic cơ bản và sử dụng để tính bảng chân trị 2
CHƯƠNG 3 – THỰC NGHIỆM 2
CHƯƠNG 4 – KẾT QUẢ 4.1 Tài liệu tham khảo và cách trích dẫn 2
4.2 Qui định của Khoa Công nghệ thông tin 2
Trang 8CHƯƠNG 1 – GIỚI THIỆU
STT HỌ VÀ
TÊN
GIAN
ĐỊA ĐIỂM
1 Nguyễn
Văn
Lộc
518H0647 18H50302 - Phân chia việc làm cụ
thể của từng thành viên -Tìm hiểu và nghiên cứu phần”Infix to Postfix”
27/10/2019
31/10/2019
Quán trà sữa và nhà Văn Lộc
-Viết báo cáo và viết code
31/10/2019 -7/11/2019
2 Võ
Tuấn
Lộc
518H0390 18H0390 -Tim hiểu và nghiên
cưu phần ’Postfix to Truthtable”
27/10/2019 31/10/2019
Quán trà sữa và nhà bạn Văn Lộc
-Viết code, fix bug và làm báo cáo
31/10/2019
-7/11/2019
Trang 9CHƯƠNG 2 – CƠ SỠ LÝ THUYẾT
2.1 Reverse Polish Notation (RPN)
- Reverse Polish Notation - Polish notation
- It is a method of calculation proposed by the mathematician Jan Łukasiewicz around 1920 and it is a way of writing an algebraic expression which is very convenient for performing mathematical operations
- Help the computer easily calculate the complex expressions that people need to handle quickly
- Is the algorithm used to calculate the expression value, the focus is to bring the expression from the infix (infix) to the suffix form (postfix)
- The basic feature of this writing is that there is no need to use brackets and always perform from left to right
- A method to express expressions in which the operator notation is set after the arguments are run
- Basically, the algorithm can be divided into the following two main stages:
• Conversion: normal expression is converted into Polish Kpn form
• Calculation: use the logical operator to calculate the expression value based on the
Polish form of kpnđ
- Logical state: Logically, an entity exists only in one of two states (True or False, 0 or 1)
- Logical variables: used specifically for states of entities A logical variable is represented by
a symbol (word or sign) and it only accepts one of two values: 0 or 1
2.2 The theory of basic logic and use to calculate truth values
2.2.1 Unary Operators
Unary operators are the simplest operations because they can be applied
to a single True or False value
2.2.2.Identity
The identity is our trivial case It states that True is True and False is False.
2.2.3 Negation
Trang 10The negation operator is commonly represented by a tilde (~) or ¬ symbol It negates, or
switches, something’s truth value
We can show this relationship in a truth table A truth table is a way of organizing information
to list out all possible scenarios
We title the first column p for proposition In the second column we apply the operator to p, in this case it’s ~p (read: not p) So as you can see if our premise begins as True and we negate it,
we obtain False, and vice versa
Truth Table for Logical Negation in TF and 01 notations
2.2.4 Logical True and Logical False
These are kinda strange operations Logical true always results in True and logical false always results in False no matter the premise These operations are often referred to as “always true” and “always false”
Trang 11NOT
NOT
Trang 12CHƯƠNG 3 –Thức nghiệm
Our code works like this: First I wrote the PriorityOfOperator function to compare the order of operations In the Infix2Postfix function I will create a list and view it as a stack, perform a loop running on each element in Infix: -If the element is a letter, I will pass it into the Postfix string -If the element is in parentheses, then I will pass it on the stack -If the element is
enclosed in parentheses, then I will pop the rest of the stack until it meets the opening
parenthesis, stop by giving a while loop as long as the last element of the stack is not opening parenthesis -If the element is the operator, execute the while loop with the condition that the stack is not empty and the last element of the stack must not be parentheses, if the current operator is less than or equal to the operator at the end in the stack, pop the operator in the stack and pass it to Postfix then pass the current operator into the stack, otherwise only pass the current operator into the stack After performing the above loop, I write 1 more loop to pop all the remaining elements in the stack
Multifunctional Postfix2Truthtable singing, features you love our
In Postfix2Truthtable, you can create a count list of Postfix, a list, a list
Healthy and wonderful
List Em 1 1 List is a list of him and he sang Postfix, resulting in an upgraded version and a stack
Powerful 1 number 1 value and best value and list value (element) in list (element) in list (element) in list (element) in list of codes (charC, list (element)) The zip () function in Python answers and locks, is a tuple list iterator that combines elements and repetitive features Inside, focused, valuable, valuable, valuable, right, can be on the list
The rest of me
-If I'm a True / False value, overlap
Trang 13-If integrated I am a name:
+ If I am a person not (), meanwhile, he, the other person, after he sings the result
+ In other cases, create two value variables that pop out from the stack, perform logical calculations based on the CalculatePostfix function and then pass that value back onto the stack and the result
After performing the above two loops, I will add the result variable to the element at the index position of Truthtable
TÀI LIỆU THAM KHẢO
Tiếng Việt
1. https://vi.wikipedia.org/wiki/Reverse_Polish_notation
2 All the Lab on elit.tdt.edu.vn
Tiếng Anh
3.https://medium.com/i-math/intro-to-truth-tables-boolean-algebra-73b331dd9b94