Epilog
What
versus
How
 

Vocabulary


Introduction

Epilog is a logic programming language that combines the strengths of view definitions with the power of transition rules for prescribing behavior. This document is a user guide for the predefined functions, the predefined relations, and the operators in Epilog. For information about the syntax and semantics of Epilog, see the description in Logic Programming.

Relations

same(expression,expression)

The sentence same(x,y) is true if and only if x and y are identical. For example, same(f(b),f(b)) is true.


distinct(expression,expression)

The sentence distinct(x,y) is true if and only if x and y are not identical. For example, same(f(a),f(b)) is true.


evaluate(expression,expression)

The sentence evaluate(x,y) is true if and only if the value of x is y. For example, evaluate(plus(2,3),5) is true.


member(expression,list)

The sentence member(x,l) is true if and only if x is a member of the list l. For example, member(b,[a,b,c]) is true.


true(sentence,expression)

The sentence true(p,d) is true if and only if the sentence p is true in the dataset named d. For example, if the dataset named mydataset contains the sentence p(a,b), then true(p(a,b),mydataset) is true.

Math Functions

abs(number) → number

The value of abs(x) is the absolute value of x. For example, the value of abs(-8) is 8.


acos(number) → number

The value of acos(x) is the inverse cosine of x. For example, the value of acos(1) is 0.


acosh(number) → number

The value of acosh(x) is the inverse hyperbolic cosine of x. For example, the value of acosh(1) is 0.


asin(number) → number

The value of asin(x) is the inverse sine of x. For example, the value of asin(0) is 0.


asinh(number) → number

The value of asinh(x) is the inverse hyperbolic sine of x. For example, the value of asinh(0) is 0.


atan(numbernumber

The value of atan(x) is the inverse tangent of x. For example, the value of atan(0) is 0.


atan2(number,number) → number

The value of atan2(x,y) is the inverse tangent of x/y. For example, the value of atan2(0,1) is 0.


atanh(number) → number

The value of atanh(x) is the inverse hyperbolic tangent of x. For example, the value of atanh(0) is 0.


cbrt(number) → number

The value of cbrt(x) is the cube root of x. For example, the value of cbrt(8) is 2.


ceil(number) → number

The value of ceil(x) is the smallest integer that is greater than x. For example, the value of cbrt(2.2) is 3.


clz32(number) → number

The value of clz32(x) is the number of leading zeros in the 32-bit representation of x. For example, the value of clz32(2147483647) is 1.


cos(number) → number

The value of cos(x) is the cosine of x. For example, the value of cos(0) is 1.


cosh(number) → number

The value of cosh(x) is the hyperbolic cosine of x. For example, the value of cosh(0) is 1.


exp(number) → number

The value of exp(x) is e to the power of x. For example, the value of exp(1) is ~2.718281828459045.


expm1(number) → number

The value of expm1(x) is e to the power of x minus 1. For example, the value of expm1(0) is 1.


floor(number) → number

The value of floor(x) is e is the largest integer less than x. For example, the value of floor(1.6) is 1.


fround(number) → number

The value of fround(x) is the nearest single precision floating point number to x.


hypot(number,...,number) → number

The value of hypot(x1,...,xk) is square root of the sum of the squares of x1,...,xk. For example, the value of hypot(3,4) is 5.


imul(number,number) → number

The value of imul(x,y) is the product of x and y as though they were 32 bit signed integers. For example, the value of imul(4294967295,-5) is 5.


log(number) → number

The value of log(x) is natural logarithm of x. For example, the value of log(1) is 0.


log1p(number) → number

The value of log1p(x) is natural logarithm of x+1. For example, the value of log1p(0) is 0.


log2(number) → number

The value of log2(x) is base 2 logarithm of x. For example, the value of log(8) is 3.


log10(number) → number

The value of log10(x) is base 10 logarithm of x. For example, the value of log(100) is 2.


max(number,...,number) → number

The value of max(x1,...,xk) is the maximum of x1,...,xk. For example, the value of max(3,4,1,2) is 4.


min(number,...,number) → number

The value of min(x1,...,xk) is the minimum of x1,...,xk. For example, the value of min(3,4,1,2) is 1.


minus(number,...,number) → number

The value of minus(x1,...,xk) is the difference of x1,..., xk. For example, the value of minus(9,4,3) is 2.


plus(number,...,number) → number

The value of plus(x1,...,xk) is the sum of x1,..., xk. For example, the value of plus(2,3,4) is 9.


pow(number,number) → number

The value of pow(x,y) is x raised to the power y. For example, the value of pow(2,3) is 8.


quotient(number,...,number) → number

The value of quotient(x1,...,xk) is the quotient of x1,..., xk. For example, the value of quotient(12,3,2) is 2.


random() → number

The value of random() is a random number between 0 (inclusive) and 1 (exclusive). For example, one possible value of random is 0.23.


round(number) → number

The value of round(x) is x rounded to the nearest integer. For example, the value of 1.6 is 2.

sin(number) → number

The value of sin(x) is the sine of x. For example, the value of sin(0) is 0.


sinh(number) → number

The value of sin(x) is the hyperbolic sine of i>x. For example, the value of sinh(0) is 0.


sqrt(number) → number

The value of sqrt(x) is the positive square root of x. Works for any non-negative number x. For example, the value of 4 is 2.


tan(number) → number

The value of tan(x) is the tangent of x. For example, the value of tan(0) is 0.


tanh(number) → number

The value of tan(x) is the hyperbolic tangent of x. For example, the value of tanh(0) is 0.


times(number,...,number) → number

The value of times(x1,...,xk) is the product of x1,..., xk. For example, the value of times(2,3,4) is 24.


trunc(number) → number

The value of trunc(x) is the integer part of x (removing any fractional component. For example, the value of trunc(2.3) is 2, and the value of trunc(-2.3) is -2.

String Functions

stringappend(string,...,string) → string

The value of stringappend(s1,...,sk) is the concatenation of s1, ..., sk. For example, the value of stringappend("Hello",", ","World","!") is "Hello, World!".


stringmin(string,...,string) → string

The value of stringmin(s1,...,sk) is the si that is lexicographically smallest among the specified strings. For example, the value of stringmin("def","abc","efg") is "abc".


matches(string,...,string) → string

If the string str matches the regular expression pat, the value of matches(str,pat) is the list consisting of the substring of str that matches pat and the substrings of str that match the parenthesized components of pat. For example, the value of matches("321-1245","(.)-(.)") is ["1-1","1","1"].


submatches(string,...,string) → string

The value of submatches(str,pat) is the a list of all substrings of str that match the regular expression pat. For example, the value of matches("321-1245",".2.") is ["321","124"].

List Functions

append(list,...,list) → list

The value of append(l1,...,lk) is the concatenation of l1, ..., lk. For example, the value of append([a,b,c],[d,e,f]) is [a,b,c,d,e,f].


revappend(string,string) → string

The value of revappend(l1,l2) is the result of concatenating the reverse of x onto y. For example, the value of revappend([a,b,c],[d,e,f]) is [c,b,a,d,e,f].


reverse(list) → list

The value of reverse([x1,...,xk]) is [xk,...,x1]. For example, the value of reverse([a,b,c]) is [c,b,a].


length(list) → numbmer

The value of length(l) is length of l. For example, the value of length([a,b,c]) is 3.

Arithmetic List Functions

maximum([number,...,number]) → number

The value of maximum([x1,...,xk]) is the maximum element in the specified list. For example, the value of maximum([3,4,1,2]) is 4.


minimum(list) → list

The value of minimum([x1,...,xk]) is the minimum element in the specified list. For example, the value of minimum([3,4,1,2]) is 1.


sum(list) → number

The value of sum([x1,...,xk]) is the sum of the elements in the specified list. For example, the value of sum([3,4,1,2]) is 10.


range(list) → number

The value of range([x1,...,xk]) is the range of the elements in the specified list, i.e. the difference between the maximum element and the minimum element. For example, the value of midrange([3,4,2,1]) is 3.


midrange(list) → number

The value of range([x1,...,xk]) is the midrange of the elements in the specified list, i.e. one half of the sum of the maximum element and the minimum element. For example, the value of midrange([3,4,2,1]) is 2.5.


mean(list) → number

The value of mean([x1,...,xk]) is the mean of the elements in the specified list. For example, the value of mean([3,4,2]) is 3.


median(list) → number

The value of median([x1,...,xk]) is the median of the elements in the specified list. For example, the value of median([3,14,2]) is 3.


variance(list) → number

The value of variance([x1,...,xk]) is the mean of the elements in the specified list. For example, the value of variance([3,4,2,1]) is 1.25.


stddev(list) → number

The value of stddev([x1,...,xk]) is the standard deviation of the elements in the specified list. For example, the value of stddev([3,4,2,1]) is ~1.118033988749895.

Conversion Functions

symbolize(string) → symbol

The value of symbolize(str) is the symbol consisting of only the letters, underscores, and digits in str in which all upper case letters have been converted to lower case. For example, the value of symbolize("Your name.") is yourname.


newsymbolize(string) → newsymbol

The value of newsymbolize(str) is the symbol consisting of only the letters, underscores, and digits in str in which all upper case letters have been converted to lower case and all spaces have been replaced by underscores. For example, the value of newsymbolize("Your name.") is your_name.


readstring(string) → expression

The value of readstring(str) is first expression that can be parsed from the characters in str. For example, the value of readstring("p(a) p(b)") is p(a).


readstringall(string) → expression

The value of readstring(str) is the list of all expressions that can be parsed from the characters in str. For example, the value of readstring("p(a) p(b)") is [p(a), p(b)].


stringify(expression) → string

The value of stringify(expression) is string representation of expression. For example, the value of stringify(p(a) & p(b)) is "p(a) & p(b)".


stringifyall(expression*) → string

The value of stringifyall([x1,...,x1]) is string representation of x1,...,x1. For example, the value of stringifyall([p(a), p(b)]) is "p(a) p(b)".


listify(expression) → list

The value of listify(expression) is the representation of expression as a list. For example, the value of listify(p(a,b)) is [p,a,b].


delistify(list) → expression

The value of delistify(l) is the representation of l as an expression. For example, the value of delistify([p,a,b]) is p(a,b).

Aggregates

setofall(expression,sentence) → list

The value of setofall([x,p]) is the list consisting of all distinct instances of x for which the corresponding instance of p is true. For example, given a dataset containing p(a,b), p(a,c), and p(a,d), the value of setofall(X,p(a,X)) is [b,c,d].


countofall(expression,sentence) → number

The value of countofall([x,p]) is the number of distinct instances of x for which the corresponding instance of p is true. For example, given a dataset containing p(a,b), p(a,c), and p(a,d), the value of countofall(X,p(a,X)) is 3.

Operators

nil

The symbol nil is another representation for the empty list, i.e. nil and [] are synonymous.


cons(expression,list)

The symbol cons is the primary operator used in Epilog lists. For example, the list [a,b,c] is equivalent to cons(a,cons(b,cons(c,nil))). Note that a!b!c!nil is another way of writing this expression.


not(sentence)

The symbol not is the primary operator in negations. For example the ~p(a) is equivalent to not(p(a)).


and(expression,...,expression)

The symbol and is the primary operator in conjunctions. For example, (p(X) & q(X)) is equivalent to and(p(X),q(X)).


or(expression,...,expression)

The symbol or is the primary operator in disjunctions. For example, (p(X) | q(X)) is equivalent to or(p(X),q(X)).


rule(expression,...,expression)

The symbol rule is the primary operator of rules in view definitions. For example, the rule r(X) :- p(X) & q(X) is equivalent to rule(r(X),p(X),q(X)).


definition(expression,expression)

The symbol definition is the primary operator of function definitions. For example, the definition f(X) := g(h(X)) is equivalent to definition(f(X),g(h(X))).


transition(expression,expression)

The symbol transition is the primary operator of transition rules. For example, the transition rule p(X) ==> q(X) is equivalent to transition(p(X),q(X)).


if(condition1, expression1, ..., conditionN, expressionN)

The symbol if is the primary conditional operator in function definitions. The value of if(condition1, expression1, condition2, expression2, ..., conditionN, expressionN) is expression1 is condition1 is true, else expression2 if condition2 is true ... else expressionN if conditionN is true. For example, the value of if(p(a),"yes",true,"no") if "yes" if p(a) is true else "no".

This builtin is a variadic - i.e., the number of arguments is not fixed.


choose(expression1, sentence)

The value of choose(expression, sentence) is a random member of the set {expression | sentence evaluates to true}. For example, for the dataset {r(a), r(b)}, the value of choose(f(X), r(X)) may either be f(a) or f(b).




Comments and complaints to genesereth@stanford.edu.