Logic Programming

Logical programing adalah jenis paradigma program yang berdasarkan formal logic. Formal logic ini berkerja seperti logika matematika dimana penerapan konsep matematika diekspresiakan melalui system logika umum. Prolog, answer set programing(ISP), dan datalog termasuk dalam logical programing.

  • Prolog adalah bahasa pemrograman logika atau di sebut juga sebagai bahasa non-procedural.
  • Answer set programing(ASP) merupakan suatu program dekraratif yang berorientasi pada search problem yang sulit.
  • Datalog merupakan deklarasi logical program dimana deklarasi tersebut termasuk dalam subset prolog.

Dalam suatu logical programing terdapat symbol-simbol logika yang biasa disebut symbolic logic. Simbolic logic ini bisa digunakan untuk:

  • Mengekspresikan proposisi
  • Mengekspresikan hubungan proposisi
  • Menyatakan bagaiman proposisi baru dapat diganggu oleh proposisi lain

Beberapa symbolic logic yang digunakan untuk programing logical disebut predicate calculus.

Proposisi suatu logical programing language terdiri atas object dan hubungan object. Suatu proposisi (proposition) adalah suatu pernyataan (statement) yang memiliki nilai kebenaran true (benar, T) atau false (salah, F) tetapi tidak kedua-duanya pada saat dinyatakannya.

Contoh:

Pernyataan berikut adalah proposisi:

(a)                    Jakarta adalah ibu kota Indonesia.

(b)                    Penang adalah ibu kota Malaysia.

(c)                    5 + 6 = 11.

(d)                   25 + 2 = 26.

Proposisi (a) dan proposisi (c) bernilai true, sedangkan proposisi (b) dan proposisi (d) bernilai  false.

Dalam sebuah proposisi terdapat objek yang dapat dinyatakan dalam:

  • Constant :sebuah simbol yang dapat menyatakan objek.
  • Variable :sebuah simbol yang dapat menyatakan objek yang berbeda di setiap waktu yang berbeda.

Dalam suatu logical programing terdapat atomic proposisi dimana prosisi tersebut terdiri dari compound term. Compound terms merupakan suatu elemen dari mathematic relation yang ditulis seperti mathermatic function. Bagian-bagian compound:

  • Functor: function symbol yang merupakan nama relation
  • Tuple(order list parameter)

Contoh:

student(jon)

            like(seth, OSX)

            like(nick, windows)

            like(jim, linux)

Proposisi terdapat 2 bentuk:

  • Fact: proposisi dianggap benar
  • Query: kebenaran suatu proposisi ditentukan

Arithmetic Operators

Operator Description Example
+ (Addition) Adds values on either side of the operator. A + B will give 30
– (Subtraction) Subtracts right-hand operand from left-hand operand. A – B will give -10
* (Multiplication) Multiplies values on either side of the operator. A * B will give 200
/ (Division) Divides left-hand operand by right-hand operand. B / A will give 2
% (Modulus) Divides left-hand operand by right-hand operand and returns remainder. B % A will give 0
++ (Increment) Increases the value of operand by 1. B++ gives 21
— (Decrement) Decreases the value of operand by 1. B– gives 19

Relational Operators

Operator Description Example
== (equal to) Checks if the values of two operands are equal or not, if yes then condition becomes true. (A == B) is not true.
!= (not equal to) Checks if the values of two operands are equal or not, if values are not equal then condition becomes true. (A != B) is true.
> (greater than) Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true. (A > B) is not true.
< (less than) Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true. (A < B) is true.
>= (greater than or equal to) Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true. (A >= B) is not true.
<= (less than or equal to) Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true. (A <= B) is true.

 

 

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *