<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>A Context Theory for Intensional Programming ?</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Kaiyu Wan</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Vasu Alagar</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Joey Paquet</string-name>
          <email>E@cij0</email>
          <email>E@ckj</email>
          <email>paquet@cse.concordia.ca</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Department of Computer Science and Software Engineering Concordia University Montreal</institution>
          ,
          <addr-line>Quebec H3G 1M8</addr-line>
          ,
          <country country="CA">Canada</country>
        </aff>
      </contrib-group>
      <abstract>
        <p>In this paper, we give an overview of our current work on introducing context as first-class objects in Lucid. It allows us to write programs in Lucx (Lucid enriched with context) in a high level of abstraction which is closer to the problem domain. We include a discussion on context theory, representation of context aggregations, and the syntax and semantic rules of Lucx. The implementation of Lucx in GIPSY, a platform under development for compiling Lucid family of languages, is also discussed.</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>1 Introduction</title>
      <p>
        Context is a rich concept and is hard to define. The meaning of “context” is tacitly
understood and used by researchers in diverse disciplines. In modelling human-computer
interaction [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ], context includes the physical place of the user, the time constraints, and
the system’s assumption about users interests. In Ubiquitous computing [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ], context
is understood as both situated and environmental. In natural language processing,
contexts arise as situations for interpreting natural language constructs. In imperative
programming languages, context introduces index, constants, and pointers. In functional
languages, static context introduces definitions and constraints, and dynamic context
processes the executable information for evaluating expressions. In Artificial
Intelligence(AI), the notion of context was introduced by McCarthy and later used by Guha [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ]
as a means of expressing assumptions made by natural language expressions. Hence, a
formula, which is an expression combining a sentence in AI with contexts, can express
the exact meaning of the natural language expression. Intensional logic [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ] is a branch
of mathematical logic which is used to describe precisely context-dependent entities. In
Intensional Programming(IP) paradigm, which has its foundations in Intensional Logic,
the real meaning of an expression, called intension, is a function from contexts to
values, and the value of the intension at any particular context, called the extension, is
obtained by applying context operators to the intension. Although the notion of context
was implicit in Lucid, an Intensional Programming Language, context cannot be
explicitly declared and manipulated in Lucid. By introducing context as a first class object in
Lucid, we remove this limitation. The language, thus extended, is called Lucx(Lucid
extended with contexts).
      </p>
      <p>The goal of this paper is to illustrate how context is formally defined and introduced
as first class objects in Lucx and as a result, how Lucx can be used for programming
diverse application domains. The context theory that we are developing provides a
semantic basis for context manipulation in Lucx. The paper is organized as follows: In
Section 2 we review briefly contexts in Intensional Programming Paradigm. Section 3
discusses the context theory applied in Lucx. In Section 4 we discuss the syntax and
semantics of Lucx. An example of Lucx programming and implementing Lucx are also
illustrated. We conclude our work in Section 5.
2</p>
      <p>Context in Intensional Programming Paradigm
Intensional Logic, a family of mathematical formal systems that permits expressions
whose value depends on hidden context, came into being from research in natural
language understanding. Basically, intensional logics add dimensions to logical
expressions, and non-intensional logics can be viewed as constant in all possible dimensions,
i.e. their valuation does not vary according to their context of utterance. Intensional
operators are defined to navigate in the context space. In order to navigate, some
dimension tags (or indexes) are required to provide place holders along dimensions. These
dimension tags, along with the dimension names they belong to, are used to define the
context for evaluating intensional expressions. For example, we can have an expression:
E: the average temperature this month here is greater than 0◦C.</p>
      <p>This expression is intensional because the truth value of this expression depends on
the context in which it is evaluated. The two intensional natural language operators in
this expression are this month and here, which refer respectively to the time and space
dimension. If we evaluate the expression in different cities in Canada and in the months
of a particular year, the extension of the expression varies. Hence, we have the following
valuation for the expression:</p>
      <p>Ja Fe Mr Ap Ma Jn Jl Au Se Oc No De</p>
      <p>Montreal F F F F T T T T T F F F
E0 = Ottawa F F F T T T T T T F F F</p>
      <p>Toronto F F T T T T T T T T F F</p>
      <p>Vancouver F T T T T T T T T T T T</p>
      <p>The intension of the expression is the above whole table; and the extension of the
expression in the time point Ap and in the space point Ottowa is T.</p>
      <p>
        Intensional programming paradigm has its foundations on intensional logic. It
retains two aspects from intensional logic: first, at the syntactic level, are context-switching
operators, called intensional operators; second, at the semantic level, is the use of
possible worlds semantics [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ].
      </p>
      <p>
        Lucid was a data-flow language and evolved into a Multidimensional Intensional
Programming Language [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ]. In extending Lucid with contexts we preserve the
intensionality in Lucx. Moreover, contexts exist independent of any objects in the system.
That is, one context may be used to evaluate different expressions, at the same time
expressions can also be evaluated at different contexts. This feature distinguishes the
language Lucx from other imperative languages or functional languages, where index
(for imperative languages) or evaluation environment(for functional language) are
always bound to statements or expressions. Because of the separation of the definition of
expressions from contexts, Lucx has provided more power of representing problems in
different application domains and given more flexibility of programming.
3
      </p>
      <p>Context Theory in Lucx
Context theory provides a semantic basis for Lucx programs. A context in the theory
need not be finite. However, context in Lucx has a finite number of dimensions and
along each dimension is associated a tag set, which is enumerable. This is in contrast
to Guha’s notion, wherein contexts are infinite, rich, and generalized objects. We are
motivated by Guha’s work. However not all contexts studied by Guha can be dealt
within our language. On the other hand, every context that we can define in Lucx is
indeed a context in Guha’s sense, but restricted to well-formed Lucx expressions.
3.1</p>
      <p>Context Definition
In Intensional Programming context is a reference to the representation of the
“possible worlds” relevant to the current discussion. The “possible world” is a
multidimensional space enclosing all possible information pertaining to the discussion.
Motivated by this, we formalize contexts as a subset of a finite union of relations. The
relations are defined over dimension and tag sets. Let DIM = {d1, d2, . . . , dn} denote a
finite set of dimension names. We associate with each di ∈ DIM a unique enumerable
tag set Xi. Let TAG = {X1, . . . , Xr} denote the set of tag sets. There exists functions
fdimtotag : DIM → TAG, such that the function fdimtotag associates with every di ∈ DIM
exactly one tag Xj in TAG.</p>
      <p>Definition 1 Consider the relations</p>
      <p>Pi = {di} × fdimtotag(di) 1 ≤ i ≤ n
A context C, given (DIM, fdimtotag), is a finite subset of Sn
i=1 Pi. The degree of the context
C is | Δ |, where Δ ⊂ DIM includes the dimensions that appear in C.
A context is written using enumeration syntax, as [d1 : x1, . . . , dn : xn], where d1, . . . , dn
are dimension names, and xi is the tag for dimension di. We say a context C is
simple (s context), if (di, xi), (dj, xj) ∈ C ⇒ di 6= dj. A simple context C of degree 1 is
called a micro (m context) context.</p>
      <p>Example 1 As an example consider a system in which computations involve pressure,
volume, and time, where pressure is observed by different sensors, volume is
measured by different devices, and the sampling frequencies are different. The three
distinguished dimensions are: (1).Sampling Time ST with index N; (2). Pressure P with
index set {s1, . . . , sk}, where s1, . . . , sk are named sensory devices; and (3). Volume V
with index set {m1, . . . , mq}, where m1, . . . , mq are named measuring devices. A
context c = [ST : 1, P : s2, V : m3] for one stream σ may be interpreted as a reference
to the tuple ht1, p2, v3i, where at the first sampling time t1 the value of volume
measured by m3 is v3 and the value of pressure observed by the sensor s2 is p2. Supposing
t1, p2, v3 ∈ R, the domain for the entities in the stream σ is R × R × R. The same
context may also be used as a reference to another possible world containing the
expression σ0 = p?tv . Such a reference will produce the result p2?v3 , which is the result of
t1
evaluating the expression σ0 with the substitution [t 7→ t1; p 7→ p2; v 7→ v3]. In this
case, the domain for the entities in the stream σ0 is R.</p>
      <p>
        Several functions on contexts are predefined in [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ]. The basic functions dim and tag
are to extract the set of dimensions and their associate tag values from a set of
contexts. Since we are still developing the Lucx language, the set of predefined functions
is not exhaustive. Functions on contexts using functions already defined in Lucx can be
introduced.
3.2
      </p>
      <p>
        Context Operators
In [
        <xref ref-type="bibr" rid="ref9">9</xref>
        ], we have formally defined the following context operators: the override ⊕ is
similar to function override; difference , comparison =, conjunction u , and disjunction
t are similar to set operators; projection ↓ and hiding ↑ are selection operators;
constructor [ : ] is used to construct an atomic context; substitution / is used to substitute
values for selected tags in a context; choice | accepts a finite number of contexts and
nondeterministically returns one of them; undirected range and directed range *
produce a set of contexts.
      </p>
      <p>Example 2 illustrates an overall example for some of those operators.</p>
      <sec id="sec-1-1">
        <title>Example 2 :</title>
        <p>Let c1 = [X : 2, X : 3, Y : 4],c2 = [X : 2, Y : 4, Z : 5], c3 = [Y : 2], D = {Y, Z},
Then c1 ⊕ c2 = [X : 2, Y : 4, Z : 5], c1 c2 = [X : 3], c1 ↓ D = [Y : 4],
c1 u c2 = [X : 2, Y : 4], c1 t c2 = [X : 2, X : 3, Y : 4, Z : 5], c2 ↑ D = [X : 2],
c2 c3 = {[X : 2, Y : 2, Z : 5], [X : 2, Y : 3, Z : 5], [X : 2, Y : 4, Z : 5]},
c3 * c2 = {[X : 2, Y : 2, Z : 5], [X : 2, Y : 3, Z : 5], [X : 2, Y : 4, Z : 5]},
c2/hY, 3i = [X : 2, Y : 3, Z : 5], c2 * c3 = ∅</p>
        <p>
          In order to provide a precise meaning for a context expression, we have defined the
precedence rules for all the operators in Figure 1[a] (right column) (from the highest
precedence to the lowest) and described a set of evaluation rules for context expressions
in [
          <xref ref-type="bibr" rid="ref9">9</xref>
          ]. Parentheses will be used to override this precedence when needed. Operators
having the same precedence will be applied from left to right. The formal syntax of
context expressions is shown in Figure 1[a](left column).
3.3
        </p>
        <p>
          Box and Box Operators
A context which is not a micro context or a simple context is called a non-simple
context. For example, context c4 = [X : 3, X : 4, Y : 3, Y : 2, U : blue] is a non-simple
context. In general, a non-simple context is equivalent to a set of simple contexts [
          <xref ref-type="bibr" rid="ref2">2</xref>
          ]. In
several applications we deal with contexts that have the same dimension set Δ ⊆ DIM
and the tags satisfy a predicate formula p. The short hand notation for such a set is
Box[Δ | p].
        </p>
        <p>syntax</p>
        <p>precedence
C ::= c | C = C
| C ⊇ C | C ⊆ C
| C | C | C/C
| C ⊕ C | C C
| C u C | C t C
| C C | C * C
| C ↓ D | C ↑ D
1. ↓, ↑, /
2. |
3. u, t
4. ⊕,
5. , *
6. =, ⊆, ⊇
(a) Rules for Context Expression
syntax</p>
        <p>precedence
B ::= b | B | B
| B B | B B
| B B | B ↓ D
| B ↑ D | B/hd, ti
1. ↓, ↑, /
2. |
3. , ,
(b) Rules for Box Expression
Definition 2 Let Δ = {d1, . . . , dk}, where di ∈ DIM i = 1, . . . , k, and p is a
predicate formula defined on the tuples of the relation Πd ∈Δ fdimtotag(d). The syntax</p>
        <p>Box[Δ | p] = {s | s = [di1 : xi1 , . . . , dik : xik ]},
where the tuple (x1, . . . , xk), xi ∈ fdimtotag(di), i = 1, . . . k satisfy the predicate formula
p, introduces a set S of contexts of degree k. For each context s ∈ S the values in tag(s)
satisfy the predicate formula p.</p>
        <p>
          The context operators projection (↓), hiding (↑), choice (|), and substitution (/)
introduced in Section 3.2 can be naturally lifted to sets of contexts, in particular for Boxes.
As an example : ↑ and ↓ can be lifted for Box B: B ↑ D = {c ↑ D | c ∈ B},
B ↓ D = {c ↓ D | c ∈ B}. However not all context operators have natural
extensions. Instead, the following three operations (join), (intersection), and (union)
are defined [
          <xref ref-type="bibr" rid="ref2">2</xref>
          ] for sets of contexts introduced by Box.
        </p>
      </sec>
      <sec id="sec-1-2">
        <title>Example 3 :</title>
        <p>Let DIM = {X, Y , Z}, fdimtotag(X) = fdimtotag(Y ) = fdimtotag(Z) = N,</p>
        <p>B1 = Box[X, Y | x, y ∈ N ∧ x + y = 5], B2 = Box[Y , Z | y, z ∈ N ∧ y = z2 ∧ z ≤ 3].
Then B1 = {[X : 1, Y : 4], [X : 2, Y : 3], [X : 3, Y : 2], [X : 4, Y : 1]}</p>
        <p>B2 = {[Y : 1, Z : 1], [Y : 4, Z : 2], [Y : 9, Z : 3]}.</p>
        <p>Hence B1 B2 = Box[X, Y , Z | x + y = 5 ∧ (y = z2 ∧ z ≤ 3)]</p>
        <p>= {[X : 1, Y : 4, Z : 2], [X : 4, Y : 1, Z : 1]}
B1 B2 = Box[Y | x + y = 5 ∧ (y = z2 ∧ z ≤ 3)] = {[Y : 1], [Y : 4]}
B1 B2 = Box[X, Y , Z | x + y = 5 ∨ (y = z2 ∧ z ≤ 3)] = {[X : 1, Y : 4, Z : 1..3],
[X : 2, Y : 3, Z : 1..3], [X : 3, Y : 2, Z : 1..3], [X : 4, Y : 1, Z : 1..3],
[X : 1..3, Y : 1, Z : 1], [X : 2..4, Y : 4, Z : 2], [X : 1..4, Y : 9, Z : 3]}
We define these three operators ( , , and ) have equal precedence and have
semantics analogous to relational algebra operators.</p>
        <p>Let B be a box expression and D be a dimension set. A formal syntax for box
expression B is defined in Figure 1[b] (left column) and the precedence rules for box
operators are defined in Figure 1[b] right column.
3.4</p>
        <p>Context Category
Context Regions A context region is a finite subset of a multidimensional space
generated by a set of dimensions. Boxes can be used to represent different context regions.
For example, Figure 2[a] shows two different context regions, which can be
represBe2nte=d aBsofxo[lXlo,wYs,:ZB1| x=2 +Byo2x+[Xz,2Y,≤Z 9 | ∧x2z +≥ z02]. ≤Box1B61 ∧dexfin=es a12 zco∧ne, zan≥d B0o]x,
B2 defines the upper half of hemisphere with the radius 3. If we restrict to integer
indices, then the set of contexts defined by Box B1 consists of all the points with integer
coordinates within the cone, and the set of contexts defined by Box B2 consists of all
the points with integer coordinates within the hemisphere.</p>
        <p>B1</p>
        <p>B2
(a)
ent
Regions</p>
        <p>DifferContext</p>
        <p>
          In timed systems having continuous time model, clock regions which are
equivalence classes of clock valuations arise when several clocks are used. These clock
regions are treated as context regions, and can be represented as boxes [
          <xref ref-type="bibr" rid="ref8">8</xref>
          ]. As an
example, consider clocks c1 and c2 when the maximum duration that can elapse in the
clocks are m1 = 4, and m2 = 6. This gives rise to 59 clock regions, as shown in
Figure 2[b]. The clock regions corresponding to a set of clocks is represented as a set
of Boxes. Each Box is defined by the dimension set Δ = {c1, . . . , ck}, and a
constraint on the clock valuations. For example, Box[Δ | p1], where Δ = {c1, c2} and
p1 = (0 &lt; v(c1)(x) &lt; 1) ∧ (0 &lt; v(c2)(y) &lt; v(c1)(x)) refers to the region α1. The tag
sets for clocks are reals. For discrete time modelled by multiple clocks the tag sets are
integers, and regions become lattice points, vertices of convex regions.
Nested Contexts Nested contexts define the meta relation between different contexts.
This is similar to Guha’s definition of nested context [
          <xref ref-type="bibr" rid="ref4">4</xref>
          ]. In his definitions, nested
context enables to nest ist(f , c) formulas, which define that formula f is true in context c,
and ist(ci ist(cj, α)), ist(ck ist(cl . . . ist(cj α) . . .)) are all valid. In the former example
ist(ci ist(cj, α)), context ci is outer or meta to context cj. Guha also provides entering
and exiting actions to migrate the interpretation of formulas from contexts. Similarly,
we provide @∗ operator to navigate the evaluation of expressions between nested
contexts.
        </p>
        <p>Definition 3 Let p(x, y) and q(x, y, z) be two predicate formulas. If ∀ a, b for which
p(a, b) is true, and if ∃ c such that q(a, b, c) is true, then we call p(x, y) as a projection
of the predicate formula q(x, y, z) and write p(x, y) =↓z q(x, y, z). Conversely, we say
q(x, y, z) is a simple extension of p(x, y) and write p(x, y) →z q(x, y, z). In general, a
predicate formula extended with s &gt; 1 arguments can be inductively defined as follows:
x→r+s ps(x1, . . . , xr+s), where p0 ≡ p, ps ≡ q.
1. p(x1, . . . , xr) xr+1 q(x1, . . . , xr, xr+1)</p>
        <p>→
2. p(x1, . . . , xr) xr+1,...,xr+s q(x1, . . . , xr, . . . , xr+s)</p>
        <p>−→
=Δ p0(x1, . . . , xr) x→r+1 p1(x1, . . . , xr, xr+1) x→r+2 p2(x1, . . . , xr+2) . . .</p>
        <p>Definition 4 We define a relation @ on a set of boxes B as follows: for b1, b2 ∈ B,
b1 = Box[Δ1 | p1], b2 = Box[Δ2 | p2], b1 @ b2 iff Δ1 ⊂ Δ2 and p2 is an extension of
the logic expression p1. It is easy to see that @ is an irreflexive partial order on B. We
define a partially order chain b1 @ b2 . . . @ bk to be nested, and refer to the boxes in
the chain as nested contexts.</p>
        <p>We want to study the relationship between nested contexts and sets of expressions
obtained by evaluating a given expression E at the boxes in the nested chain.
Definition 5 Let B = {b1, b2, . . .} be a finite set of boxes, bi = Box[Δi | pi], and E be
an expression. Define the relation on the set {E@∗b1, E@∗b2, . . .} as follows:</p>
        <p>
          This rule gives the base for the reasoning and reducing rules for constraint programming
solver mentioned in [
          <xref ref-type="bibr" rid="ref9">9</xref>
          ].
        </p>
        <p>Context Dependent Expressions Contexts can be passed as parameters to functions.
Definition 6 Let B1 = Box[Δ1 | p1], and B2 = Box[Δ2 | p2] define the context
regions in the space generated by the dimensions Δ1 ∪ Δ2. The context-dependent
expression E is defined differently in different regions:
λ ·E =
 E1 in B1 B2</p>
        <p>E2 in B2 B1
 E3 in B1 u B2
μ ·E is defined to indicate corresponding context regions, namely,
μ ·E = {B1 B2, B2 B1, B1 u B2}</p>
        <p>An application of Definition 6 is to use contexts as parameters in a function
definition. Let f : X × Y × Z × C → W, where C is a set of contexts; and f (x, y, z, c), x ∈
X, y ∈ Y, z ∈ Z, c ∈ C, be defined such that for different context values, the function’s
definitions are different. For example, function f (x, y, z, c) is defined according to
different context regions shown in Figure 2[a]. Hence μ ·f = {B1 B2, B2 B1, B1 u B2},
and λ ·f = {2x3 + y − 6, x + y2, z3 + y}. The evaluation of functions f varies depending
on the actual context value given as input when f is called.</p>
        <p>
          Given contexts as input, context-dependent functions can be used to produce a new
context as a result to achieve adaptation in context-aware system [
          <xref ref-type="bibr" rid="ref9">9</xref>
          ].
        </p>
        <p>Dependent Context We define context dependency analogous to the functional
dependency in relational data models.</p>
        <p>Definition 7 Let Δ = {X1, . . . , Xk} be a dimension set. If there exists a function φij :
fdimtotag(Xi) → fdimtotag(Xj), we say φij is a functional dependency in the set Δ.
In general, a functional dependency exists in Δ, if A ⊂ Δ, B ⊂ Δ, A ∩ B = ∅, and
there exists a function :</p>
        <p>φAB : ΠXi∈Afdimtotag(Xi) → ΠXj∈Bfdimtotag(Xj).</p>
        <p>For a given functional dependency φij in Δ, we define dependent contexts as the set of
contexts:</p>
        <p>SΔ = {c | dim(c) = Δ0 ∧ ({Xi, Xj} ⊆ Δ0 ⊆ Δ)}
As an example, c = [Xi : a, Xj : φij(a)] ∈ SΔ, a ∈ fdimtotag(Xi). This definition is easy to
generalize for the general functional dependency φAB.</p>
        <p>Dependent context effectively reduces the possible worlds that are relevant to
evaluate expressions. As an example, let a function φ: V → ST be defined as follows:
φ(m1) = φ(m2) = 1; φ(m3) = φ(m4) = 2. Hence context of this form [P : s1, V :
m3, ST : 1] need not be considered for evaluating expressions in the example.</p>
        <p>
          Moreover, dependent contexts also help to represent context sets compactly. In [
          <xref ref-type="bibr" rid="ref9">9</xref>
          ],
we proved the following: starting with a set SΔ of contexts, whose dimensions are
subsets of Δ and a finite set of functional dependencies on Δ, we can represent SΔ
as an expression SΔ = SΔk SΔ0k , where there is no dependency in SΔk and SΔ0k =
b1 b2 . . . bk, each bi is a Box representing one dependency. Since a box has a
compact representation, the representation for SΔ given above is a compact way to
manage the contexts in this SΔ. The substitutions for tags in b1, . . . , bk are subject
to dependencies. However, those tags corresponding to dimension in SΔk can be done
freely. This is analogous to substitution principle in functional languages.
        </p>
      </sec>
    </sec>
    <sec id="sec-2">
      <title>4 Intensional Language Lucx</title>
      <p>Lucx is a conservative extension of Lucid, with context becoming a first-class object
in the language. This way, contexts can be manipulated, assigned values and passed as
parameters dynamically.</p>
      <p>Syntax and Semantics of Lucx The syntax of Lucx is shown below.</p>
      <p>E ::= id S ::= {E1, . . . , Em}
| E(E1, . . . , En) | Box[E | E0]
| if E then E0 else E00 Q ::= dimension id
| # | id = E
| E @ E0 | id(id1, . . . , idn) = E
| [E1 : E01, . . . , En : E0n] | Q Q
| hE1, . . . , EniE
| select(E, E0)
| E @∗ S
| E where Q</p>
      <p>
        The difference between Lucx and original Lucid is highlighted in bold in the above
syntax rules. The symbols @ and # are context navigation and query operators. The
non-terminals E and Q respectively refer to expressions and definitions. The abstract
semantics of evaluation in Lucx is D, P0 ` E : v, which means that in the definition
environment D, and in the evaluation context P0 , expression E evaluates to v. The
definition environment D retains the definitions of all of the identifiers that appear in
a Lucid program. Formally, D is a partial function D : Id → IdEntry, where Id is
the set of all possible identifiers and IdEntry has five possible kinds of value such as:
Dimensions, Constants, Data Operators, Variables, and Functions[
        <xref ref-type="bibr" rid="ref7">7</xref>
        ]. The evaluation
context P0, is the result of P †c, where P is the initial evaluating context, c is the defined
context expression, and the symbol†denotes the overriding function.
      </p>
      <p>
        A complete operational semantics for Lucid is defined in [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ]. The new semantic
rules for Lucx are given below.
      </p>
      <p>Eat(c) : D, P ` E0 : P0 D, P0 ` E : v</p>
      <p>D, P ` E @E0 : v
E# :</p>
      <p>D, P ` # : P
E. : D, P ` E2 : id2 D(id2) = (dim)</p>
      <p>D, P ` E1.E2 : tag(E1 ↓ {id2})
Etuple : D, P ` E : id D†[id 7→ (dim)] P †[id 7→ 0] D, P ` Ei : vi</p>
      <p>D, P ` hE1, E2, . . . , EniE : v1 fby.id v2 fby.id . . . vn fby.id eod</p>
      <p>D, P ` E : Δ
Ebox : D(v0k:1..n) = (dim)</p>
      <p>D, P ` Edj : idj
Econtext : D, P ` Eij : vj</p>
      <p>D(idj) = (dim)</p>
      <p>P0 = P0 † [id1 7→ v1] † . . . † [idn 7→ vn]</p>
      <p>D, P ` [Ed1 : Ei1 , Ed2 : Ei2 , . . . , Edn : Ein ] : P0</p>
      <p>The evaluation rule for the navigation operator, Eatc , which corresponds to the
syntactic expression E @ E0, evaluates E in context E0, where E0 is a context defined in
Section 3.1. The evaluation rule for the set navigation operator Eats , which corresponds
to the syntactic expression E @∗ S, evaluates E in a set of contexts S. Hence, the
evaluation result should be a collection of results of evaluating E at each element of S.
Semantically speaking, the symbol # is a nullary operator, which evaluates to the
current evaluation context P. And the symbol . is a binary operator, whose left operand
is an expression and the right operand is a single dimension. The semantic rule Etupid
evaluates a tuple as a finite stream whose dimension is explicitly indicated as E in the
corresponding syntax rule hE1, . . . , EniE. Accordingly, the semantic rule Eselect picks
up one element indexed by E from the tuple E0. The semantic rule Ebox evaluates a
Box to a set of contexts according to the definition in Section 3.3. fp(tag(Pi)i=1..m) is a
boolean function. The rule Eset evaluates {E1, . . . , Em} to a set of contexts.
Examples of Lucx Programs We give two examples.</p>
      <p>1. The example models the problem of heat transfer in a solid. There is a metal rod
which initially has temperature 0 and whose left-hand end touches a heat source with
temperature 100. As the heat is transfered, the temperature at the various points of the
rod changes. That is, the temperature depends on the time point and the spatial position
on the rod. The following equations illustrate the temperature of the rod as a function
of time and space (where k is a small constant related to the physical properties of the
rod):</p>
      <p>Tempt+1,s+1 = k × Tempt,s − (1 − 2 × k) × Tempt,s+1 + k × Tempt,s+2
Tempt,0 = 100</p>
      <p>Temp0,s+1 = 0
The Lucx program that models the above equations and queries the temperature at the
space 10 at time 10 is the following:</p>
      <p>Temp @ [Time : 10, Space : 10]
where</p>
      <p>Temp @ [Time : t + 1, Space : s + 1] = k × Temp @ [Time : t, Space : s]
−(1 − 2 × k) × Temp @ [Time : t, Space : s + 1]
+k × Temp @ [Time : t, Space : s + 2]
Temp@[Time : t, Space : 0] = 100</p>
      <p>
        Temp@[Time : 0, Space : s + 1] = 0
end
Implementing Lucx in GIPSY The GIPSY is an Intensional Programming
investigation platform under development which allows the automated generation of compiler
components for the different variants of the Lucid family of languages [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ]. Currently,
the compiler for Indexical Lucid, a variant of Lucid, has been implemented
successfully in the GIPSY. Lucx is a conservative extension of Lucid. We will provide the Lucx
parser and Lucx AST(Abstract Syntax Tree) translator as a Lucx front end to GIPSY.
Lucx parser can be automatically generated using the JavaCC tool as the Indexical
Lucid parser being obtained. In [
        <xref ref-type="bibr" rid="ref9">9</xref>
        ], we provide the translation rules for translating Lucx
operators into Indexical Lucid operators. Combined with the translation rules for
Indexical Lucid operators provided in [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ], we achieve a two-pass Lucx AST translator.
Once these two models are integrated into GIPSY, the programs written in Lucx will be
compiled and run in GIPSY.
5
      </p>
      <p>Conclusion
The notion of context is the cornerstone of the intensional programming paradigm. The
previous versions of Lucid were merely using the notion of context of evaluation. They
provided a single operator for the navigation in the context of evaluation, but did not
provide a mechanism to represent and manipulate contexts as first class values.</p>
      <p>
        The use of contexts as first class values increases the expressive power of the
language by an order of magnitude. It allows the definition of aggregate contexts, which
are a key feature to achieve efficiency of evaluation through granularization of the
manipulated data. It also allows us to use the paradigm for agent communication by
allowing the sharing and manipulation of multidimensional contextual information among
agents [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ]. In addition, the use of the paradigm for real-time reactive programming is
shown in [
        <xref ref-type="bibr" rid="ref8">8</xref>
        ]. We are developing larger application programs that arise in constraint
programming and in context-aware systems [
        <xref ref-type="bibr" rid="ref9">9</xref>
        ].
      </p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          1.
          <string-name>
            <given-names>E.</given-names>
            <surname>Ashcroft</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Faustini</surname>
          </string-name>
          ,
          <string-name>
            <given-names>R.</given-names>
            <surname>Jagannathan</surname>
          </string-name>
          ,
          <string-name>
            <given-names>W.</given-names>
            <surname>Wadge</surname>
          </string-name>
          . Multidimensional,
          <string-name>
            <given-names>Declarative</given-names>
            <surname>Programming</surname>
          </string-name>
          . Oxford University Press, London,
          <year>1995</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          2.
          <string-name>
            <given-names>V. S.</given-names>
            <surname>Alagar</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J.</given-names>
            <surname>Paquet</surname>
          </string-name>
          ,
          <string-name>
            <given-names>K.</given-names>
            <surname>Wan</surname>
          </string-name>
          .
          <article-title>Intensional Programming for Agent Communication</article-title>
          .
          <source>Proceedings of DALT'04</source>
          , New York,
          <year>July 2004</year>
          , post proceeding will appear
          <source>in Lecture Notes in Computer Science</source>
          , Springer-Verlag.
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          3.
          <string-name>
            <given-names>A.K.</given-names>
            <surname>Dey</surname>
          </string-name>
          . Understanding and
          <string-name>
            <given-names>Using</given-names>
            <surname>Context</surname>
          </string-name>
          .
          <source>Personal and Ubiquitous Computing Journal</source>
          <volume>5</volume>
          (
          <issue>1</issue>
          ).pp.
          <fpage>4</fpage>
          -
          <lpage>7</lpage>
          .
          <year>2001</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          4.
          <string-name>
            <given-names>R. V.</given-names>
            <surname>Guha</surname>
          </string-name>
          .
          <article-title>Contexts: A Formalization and Some Applications</article-title>
          .
          <source>Ph.d thesis</source>
          , Stanford University,
          <year>February 10</year>
          ,
          <year>1995</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          5.
          <string-name>
            <surname>Cheverst</surname>
            ,
            <given-names>K.</given-names>
          </string-name>
          ,
          <string-name>
            <given-names>N.</given-names>
            <surname>Davies</surname>
          </string-name>
          ,
          <string-name>
            <given-names>K.</given-names>
            <surname>Mitchell</surname>
          </string-name>
          and
          <string-name>
            <given-names>C.</given-names>
            <surname>Efstratiou</surname>
          </string-name>
          .
          <article-title>Using Context as a Crystal Ball: Rewards and Pitfalls</article-title>
          .
          <source>Personal Technologies Journal</source>
          , Vol.
          <volume>3</volume>
          No5, pp.
          <fpage>8</fpage>
          -
          <lpage>11</lpage>
          ,
          <year>2001</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          6.
          <string-name>
            <given-names>J.</given-names>
            <surname>Paquet</surname>
          </string-name>
          ,
          <string-name>
            <given-names>P.</given-names>
            <surname>Kropf</surname>
          </string-name>
          .
          <source>The GIPSY Architecture. DCW</source>
          <year>2000</year>
          ,
          <volume>144</volume>
          -
          <fpage>153</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          7.
          <string-name>
            <given-names>Joey</given-names>
            <surname>Paquet</surname>
          </string-name>
          .
          <source>Intensional Scientific Programming Ph.D. Thesis</source>
          , De´partement d'Informatique, Universite Laval, Quebec, Canada,
          <year>1999</year>
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          8.
          <string-name>
            <given-names>K.</given-names>
            <surname>Wan</surname>
          </string-name>
          ,
          <string-name>
            <given-names>V.S.</given-names>
            <surname>Alagar</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J.</given-names>
            <surname>Paquet</surname>
          </string-name>
          .
          <article-title>Real Time Reactive Programming Enriched with Context</article-title>
          .
          <source>ICTAC2004</source>
          , Guiyang, China,
          <year>September 2004</year>
          , Lecture Notes in Computer Science,
          <volume>3407</volume>
          ,Page 387-402, Springer-Verlag.
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          9.
          <string-name>
            <given-names>K.</given-names>
            <surname>Wan. Lucx</surname>
          </string-name>
          :
          <article-title>An Intensional Programming Language Enriched With Contexts</article-title>
          ,
          <source>Ph.d thesis(under preparation)</source>
          , Department of Computer Science, Concordia University, Montreal, Canada,
          <year>2005</year>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>