TyRuBa Library

The following are predicates included in libraries loaded automatically in TyRuBa. If you would not like these predicates added to the rulebase, run TyRuBa with the -noinit option.

In some argument descriptions, there is an "=" before a type. It indicates that the type is a strict type. For a description on strict types, look at the TyRuBa tutorial.


append(?list1, ?list2, ?list3)

Arguments: ?list1 :: [?x]
?list2 :: [?x]
?list3 :: [?x]
Bound: ?list1          Free: ?list3
?list2
?list3 = list consisting of elements from ?list1 followed by elements of ?list2
e.g. append([1,2],[3,4],?x) ---> ?x = [1,2,3,4]
Bound: ?list3          Free: ?list1
?list2
?list1, ?list2 = ways to split ?list3 into two lists
e.g. append(?x,?y,[1,2,3,4]) ---> ?x = [], ?y = [1,2,3,4]

capitalize(?string, ?String)

Arguments: ?string :: =String
?String :: =String
Bound: ?string         Free: ?String
?String = ?string with the first character capitalized
e.g. capitalize(abcd,?x) ---> ?x = Abcd

convertToType(?from, ?to)

Arguments: ?from :: Type
?to :: =Type
Bound: ?from         Free: ?to
The convertToType predicate serves the purpose of converting an object's static type to an exact (=Type) type. This is useful sometimes for being able to pass arguments to predicates which expect exact types, when they are being used in a context where the static type is not exact.

Example:

:- member(?x,[1,a,2]),String(?x),string_append(?x,"_foo",?foo).
##QUERY : member<?x,[1,a,2]>, String<?x>, string_append<?x,_foo,?foo>
Type or Mode Error: Incompatible types: Object, =String
in string_append<?x,_foo,?foo>
in member<?x,[1,a,2]>, String<?x>, string_append<?x,_foo,?foo>

Although the above query may appear type correct, it is not, because the type checking algorithm tries to ensure type correctness without assuming in what order the queries will get executed (the mode system may decide to change the order!). Thus from the type checker's point of view, it is possible that the string_append could get executed before the String(...) test, this would pass elements of a broader type than String to string_append (i.e. it could pass numbers 1 and 2). Since string_append has an "exact" =String type, it would probably crash the implementation of string_append (i.e. internally, some string relalted Java methods would get invoked on Integer objects). To work around this you can use convertToString predicate, like so:

:- member(?x,[1,a,2]),convertToString(?x,?stringx),
string_append(?stringx,foo,?foo).
##QUERY : member<?x,[1,a,2]>, convertToString<?x,?stringx>, string_append<?stringx,foo,?foo>
inferred types: TypeEnv( ?stringx==String ?x=Object ?foo==String )
converted to Mode: member<?x,[1,a,2]>{(F,B) IS NONDET}, convertToString<?x,?stringx>{(B,F) IS SEMIDET}, string_append<?stringx,foo,?foo>{(B,B,F) IS DET}
.....H
| ?stringx=a ?x=a ?foo=afoo |H.
##END QUERY

In this example ?stringx will be bound to the same value as ?x in all cases where ?x is of the correct type (String). The predicate fails if ?x is not of the correct type (anything not a String). Thus the type of ?x will be narrowed to String by this operation (but not exact, since it still depends on execution time!) and the type of ?xString will be =String since it only gets bound in such cases where ?x is of the correct type. Thus, ?stringx can be safely passed as an argument to string_append.

Note: We are considering integrating the type checker into the mode system so that restrictions based on "should be correct in any execution order" can be lifted and replaced by "should be correct in one of the possible, mode-correct, execution orders". THe latter is expected to produce more intuitive and relaxed type checking constraints. This change would make the concvertToType predicates obsolete.

debug_print(?msg)

Arguments: ?msg :: Object
Bound: ?msg            Free: none
always return true; print the string representation of ?msg to System.err

decapitalize(?String, string)

Arguments: ?String :: =String
?string :: =String
Bound: ?String         Free: ?string
?string = ?String with the first character decapitalized
e.g. decapitalize(Abcd,?x) ---> ?x = abcd

equals(?x,?y)

Arguments: ?x :: ?t
?y :: ?t
Bound: ?x              Free: ?y
?y = ?x
e.g. equals(1,?x) ---> ?x = 1
Bound: ?y              Free: ?X
?x = ?y
e.g. equals(?x,1) ---> ?x = 1

false( )

Arguments: none
this predicate always fails

fileseparator(?fs)

Arguments: ?fs :: =String
Bound: none           Free: ?fs
?fs = file separator of the system
e.g. fileseparator(?fs) ---> ?fs = \ (for Windows OS)

greater(?num1, ?num2)

Arguments: ?num1 :: =Integer
?num2 :: =Integer
Bound: ?num1           Free: none
       ?num2
return true if ?num1 > ?num2

hash_value(?ob, ?hash)

Arguments: ?ob   :: =Object
?hash :: =Integer
Bound: ?ob             Free: ?hash
?hash = hash value of ?ob

Integer(?int)

Arguments: ?int :: Integer
Bound: ?int            Free: none
return true if ?int is bound to an integer

length(?list, ?length)

Arguments: ?list   :: [?x]
?length :: =Integer
Bound: ?list           Free: ?length
?length = number of elements in ?list
e.g. length([1,2,a,c],?length) ---> ?length = 4

list_ref(?pos, ?list, ?elem)

Arguments: ?pos  :: =Integer
?list :: [?x]
?elem :: ?x
Bound: ?pos            Free: ?elem
?list
?elem = element of list ?list at position ?pos
e.g. list_ref(1,[a,b],?elem)
list_ref(2,[1],?elem)
---> ?elem = b
---> FAILURE
Bound: ?list           Free: ?pos
?elem
?pos = position of ?elem in ?list (there can be multiple results)
e.g. list_ref(?pos,[a,b,c],a)
list_ref(?pos,[a,b,a],a)
--->
--->
?pos = 0
?pos = 0
?pos = 2

member(?elem, ?list)

Arguments: ?elem :: ?x
?list :: [?x]
Bound: ?list           Free: ?elem
?elem = an element of ?list
e.g. member(?elem,[1,2,a]) ---> ?elem = 1
?elem = 2
?elem = a

mul(?num1, ?num2, ?num3)

Arguments: ?num1 :: =Integer
?num2 :: =Integer
?num3 :: =Integer
Bound: ?num1           Free: ?num3
?num2
?num3 = ?num1 * ?num2
e.g. mul(2,3,?x) ---> ?x = 6
Bound: ?num1           Free: ?num2
?num3
?num2 = ?num3 / ?num1
e.g. mul(2,?x,6) ---> ?x = 3
mul(2,?x,7) ---> FAILURE
Bound: ?num2           Free: ?num1
?num3
?num1 = ?num3 / ?num2
e.g. mul(?x,2,6) ---> ?x = 3
mul(?x,2,7) ---> FAILURE

permutation(?list1, ?list2)

Arguments: ?list1 :: [?x]
?list2 :: [?x]
Bound: ?list1          Free: ?list2
?list2 = permutation (rearrangement) of ?list1
e.g. permutation([1,2,3],?list2) ---> ?list2 = [1,2,3]
?list2 = [1,3,2]
?list2 = [2,1,3]
?list2 = [2,3,1]
?list2 = [3,1,2]
?list2 = [3,2,1]

permutation([],?list2) ---> ?list2 = []
Bound: ?list2          Free: ?list1
?list1 = permutation (rearrangement) of ?list2
e.g. permutation(?list1,[1,2,3]) ---> ?list1 = [1,2,3]
?list1 = [1,3,2]
?list1 = [2,1,3]
?list1 = [2,3,1]
?list1 = [3,1,2]
?list1 = [3,2,1]

permutation(?list1,[]) ---> ?list1 = []

range(?lo, ?high, ?num)

Arguments: ?lo   :: =Integer
?high :: =Integer
?num :: =Integer
Bound: ?lo             Free: ?num
?high
?num = any ?x such that ?lo <= ?x < hi
e.g. range(1,5,?num) ---> ?num = 1
?num = 2
?num = 3
?num = 4

range(5,1,?num) ---> FAILURE

regexp(?RE)

Arguments: ?RE :: org.apache.regexp.RE
Bound: ?RE             Free: none
return true if ?RE is an instance of org.apache.regexp.RE

re_match(?RE, ?string)

Arguments: ?RE     :: =org.apache.regexp.RE
?string :: =String
Bound: ?RE             Free: none
       ?string
return true if ?string can be matched by the regular expression ?RE
e.g. re_match(/c*/,ccc)
re_match(/a/,ccc)
---> SUCCESS
---> FAILURE

reverse(?list,?tsil)

Arguments: ?list :: [?x]
?tsil :: [?x]
Bound: ?list           Free: ?tsil
?tsil = list with elements of ?list in reverse order
e.g. reverse([a,b,c,d],?x)
reverse([],?x)
---> ?x = [d,c,b,a]
---> ?x = []
Bound: ?tsil           Free: ?list
?list = list with elements of ?tsil in reverse order
e.g. reverse(?x,[d,c,b,a])
reverse(?x,[])
---> ?x = [a,b,c,d]
---> ?x = []

selection(?select, ?list)

Arguments: ?select :: [?x]
?list :: [?x]
Bound: ?list           Free: ?select
?select = a selection of ?list
e.g. selection(?x,[1,2,3]) ---> ?x = []
?x = [1]
?x = [2]
?x = [3]
?x = [1,2]
?x = [2,3]
?x = [1,2,3]

selection(?x,[]) ---> ?x = []

String(?str)

Arguments: ?str :: String
Bound: ?str            Free: none
return true if ?str is bound to a string

string_append(?first, ?second, ?result)

Arguments: ?first  :: =String
?second :: =String
?result :: =String
Bound: ?first          Free: ?result
?second
?result = ?first concat ?second
e.g. string_append(ab,cd,?result) ---> ?result = abcd
Bound: ?result         Free: ?first
?second
?first concat ?second = ?result
e.g. string_append(?first,?second,abcd)
      
---> ?first = empty string, ?second = abcd
?first = a, ?second = bcd
?first = ab, ?second = cd
?first = abc, ?second = d
?first = abcd, ?second = empty string

string_index_split(?pos, ?string, ?first, ?second)

Arguments: ?pos    :: =Integer
?string :: =String
?first :: =String
?second :: =String
Bound: ?pos            Free: ?first
?string ?second
?first = substring of ?string from position 0 to ?pos ?second = substring of ?string from ?pos
e.g. string_index_split(3,abcdefg,?s1,?s2)
string_index_split(3,ab,?s1,?s2)
---> ?s1 = abc, ?s2 = defg
---> FAILURE

string_length(?string, ?length)

Arguments: ?string :: =String
?length :: =Integer
Bound: ?string         Free: ?length
?length = length of ?string
e.g. string_length(abc,?length) ---> ?length = 3

string_repeat(?num, ?string, ?result)

Arguments: ?num    :: =Integer
?string :: =String
?result :: =String
Bound: ?num            Free: ?result
?string
?result = ?string repeated ?num of times
e.g. string_repeat(3,abc,?result)
string_repeat(0,abc,?result)
string_repeat(-1 abc,?result)
---> result = abcabcabc
---> result = empty string
---> FAILURE

string_replace(?r1, ?r2, ?s1, ?s2)

Arguments: ?r1 :: =String
?r2 :: =String
?s1 :: =String
?s2 :: =String
Bound: ?r1             Free: ?s2
?r2
?s1
?s2 = ?s1 with all occurences of ?r1 replaced by ?r2
e.g. string_replace(a,b,ananan,?s2) ---> ?s2 = bnbnbn
string_replace(a,b,cncncn,?s2) ---> ?s2 = cncncn
Bound: ?r1             Free: ?s1
?r2
?ss
?s1 = ?s2 with all occurences of ?r2 replaced by ?r2
e.g. string_replace(a,b,?s1,bnbnbn) ---> ?s1 = ananan
string_replace(a,b,?s2,cncncn) ---> ?s1 = cncncn

string_split_at_last(?sep, ?string, ?first, ?second)

Arguments: ?sep    :: =String
?string :: =String
?first :: =String
?second :: =String
Bound: ?sep            Free: ?first
?string ?second
?first
?second
=
=
substring of ?string from position 0 to the last occurence of ?sep
substring of ?string from the last occurence of ?sep
e.g. string_split_at_last(".",abc.def,?s1,?s2) ---> ?s1 = abc, ?s2 = def

string_split_at_last(":",abc.def,?s1,?s2) ---> ?s1 = abc.def, ?s2 = empty string
Bound: ?sep            Free: ?string
?first
?second
?string = ?first concat ?sep concat ?second
e.g. string_split_at_last(".",?string,abc,def) ---> ?string = abc.def

sum(?num1, ?num2, ?sum)

Arguments: ?num1 :: =Integer
?num2 :: =Integer
?num3 :: =Integer
Bound: ?num1           Free: ?sum
?num2
?sum = ?num1 + ?num2
e.g. sum(2,4,?x) ---> ?x = 6
Bound: ?num1           Free: ?num2
?sum
?num2 = ?sum - ?num1
e.g. sum(2,?x,6) ---> ?x = 4
Bound: ?num2           Free: ?num1
?sum
?num1 = ?sum - ?num2
e.g. sum(?x,4,6) ---> ?x = 2

sumList(?list,?sum)

Arguments: ?list :: [=Integer]
?sum :: =Integer
Bound: ?list           Free: ?sum
?sum = sum of all the elements of ?list
e.g. sumList([1,2,3],?sum)
sumList([],?sum)
---> ?sum = 6
---> ?sum = 0

throw_error(?msg)

Arguments: ?msg :: =String
Bound: ?msg            Free: none
always return false; throw error with message ?msg

to_lower_case(?STRING, ?string)

Arguments: ?STRING :: =String
?string :: =String
Bound: ?STRING         Free: ?string
?string = ?STRING to lower case
e.g. to_lower_case(ABCDEF,?string) ---> ?string = abcdef
to_lower_case(AbCdEF,?string) ---> ?string = abcdef

to_upper_case(?string, ?STRING)

Arguments: ?string :: =String
?STRING :: =String
Bound: ?string         Free: ?STRING
?STRING = ?string to upper case
e.g. to_upper_case(abcdef,?string) ---> ?string = ABCDEF
to_upper_case(aBCdeF,?string) ---> ?string = ABCDEF

true( )

Arguments: none
this predicate always succeed

write_file(?filename, ?content)

Arguments: ?filename :: =String
?content :: =String
Bound: ?filename       Free: none
       ?content
return true if ?content has been written to file with file name ?filename

write_output(?msg)

Arguments: ?msg :: =String
Bound: ?msg            Free: none
always return true; print ?msg to System.err

zip(?list1,?list2,?result)

Arguments: ?list1  :: [?x]
?list2 :: [?y]
?result :: [<?x,?y>]
Bound: ?list1          Free: ?result
?list2
?result = list of <Ai,Bi>
    
where Ai is the ith element of ?list1 and
Bi is the ith element of ?list2
e.g. zip([1,2,3],[a,b,c],?result) ---> ?result = [<1,a>,<2,b>,<3,c>]
zip([1,2,3],[a,b],?result) ---> FAILURE
Bound: ?result         Free: ?list1
?list2
?list1 = list of the first subterms in each element (tuple) of ?result
?list2 = list of the second subterms in each element (tuple) of ?result
e.g. zip(?list1,?list2,[<1,a>,<2,b>,<3,c>]) ---> ?list1 = [1,2,3], ?list2 = [a,b,c]