Sunday, 18 January 2009

Atoms and Numbers

Atoms and variable examples:
Upper case letters: A,B,…,Z
Lower case letters: a,b,…,z
Digits: 0,1,…,9
Special characters: +,-,<,>,/,*,=,:,.,_,~

Atoms can be constructed in three ways:
String of letters,digits and the underscore character starting with a lower case letter:
anna
x25
x_
x__y


Strings of special characters:

.:.
::=
String of characters enclosed in single quotes:
‘Tom’
‘South_America’
‘Sarah Jones’

Numbers used in Prolog include integer numbers and real numbers.
1
-97
-0.035
Using real numbers may cause numerical errors due to rounding, because of this they are not used very often.


Error example in real numbers:
sum(X,Y,Z):-Z is X+Y.

?- sum(2,0.3,C).
C = 2.3 ;
No
?- sum(200,0.0003,C).
C = 200.0 ;
No
The evaluation of the expression “10000+0.0001-10000 “ may result in 0 instead of the correct result 0.0001

No comments:

Post a Comment