<?xml version="1.0" encoding="UTF-8"?>
<TEI xml:space="preserve" xmlns="http://www.tei-c.org/ns/1.0" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://www.tei-c.org/ns/1.0 https://raw.githubusercontent.com/kermitt2/grobid/master/grobid-home/schemas/xsd/Grobid.xsd"
 xmlns:xlink="http://www.w3.org/1999/xlink">
	<teiHeader xml:lang="en">
		<fileDesc>
			<titleStmt>
				<title level="a" type="main">A Context Theory for Intensional Programming</title>
			</titleStmt>
			<publicationStmt>
				<publisher/>
				<availability status="unknown"><licence/></availability>
			</publicationStmt>
			<sourceDesc>
				<biblStruct>
					<analytic>
						<author>
							<persName><forename type="first">Kaiyu</forename><surname>Wan</surname></persName>
							<email>kywan@cse.concordia.ca</email>
							<affiliation key="aff0">
								<orgName type="department">Department of Computer Science and Software Engineering</orgName>
								<orgName type="institution">Concordia University Montreal</orgName>
								<address>
									<postCode>H3G 1M8</postCode>
									<region>Quebec</region>
									<country key="CA">Canada</country>
								</address>
							</affiliation>
						</author>
						<author>
							<persName><forename type="first">Vasu</forename><surname>Alagar</surname></persName>
							<email>alagar@cse.concordia.ca</email>
							<affiliation key="aff0">
								<orgName type="department">Department of Computer Science and Software Engineering</orgName>
								<orgName type="institution">Concordia University Montreal</orgName>
								<address>
									<postCode>H3G 1M8</postCode>
									<region>Quebec</region>
									<country key="CA">Canada</country>
								</address>
							</affiliation>
						</author>
						<author>
							<persName><forename type="first">Joey</forename><surname>Paquet</surname></persName>
							<email>paquet@cse.concordia.ca</email>
							<affiliation key="aff0">
								<orgName type="department">Department of Computer Science and Software Engineering</orgName>
								<orgName type="institution">Concordia University Montreal</orgName>
								<address>
									<postCode>H3G 1M8</postCode>
									<region>Quebec</region>
									<country key="CA">Canada</country>
								</address>
							</affiliation>
						</author>
						<title level="a" type="main">A Context Theory for Intensional Programming</title>
					</analytic>
					<monogr>
						<imprint>
							<date/>
						</imprint>
					</monogr>
					<idno type="MD5">15BD13C46DEB791820794888B9666197</idno>
				</biblStruct>
			</sourceDesc>
		</fileDesc>
		<encodingDesc>
			<appInfo>
				<application version="0.7.2" ident="GROBID" when="2023-03-24T21:05+0000">
					<desc>GROBID - A machine learning software for extracting information from scholarly documents</desc>
					<ref target="https://github.com/kermitt2/grobid"/>
				</application>
			</appInfo>
		</encodingDesc>
		<profileDesc>
			<textClass>
				<keywords>
					<term>Context</term>
					<term>Context Theory</term>
					<term>Intensional Programming</term>
				</keywords>
			</textClass>
			<abstract>
<div xmlns="http://www.tei-c.org/ns/1.0"><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></div>
			</abstract>
		</profileDesc>
	</teiHeader>
	<text xml:lang="en">
		<body>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="1">Introduction</head><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 <ref type="bibr" target="#b4">[5]</ref>, context includes the physical place of the user, the time constraints, and the system's assumption about users interests. In Ubiquitous computing <ref type="bibr" target="#b2">[3]</ref>, 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 <ref type="bibr" target="#b3">[4]</ref> 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 <ref type="bibr" target="#b6">[7]</ref> 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.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="2">Context in Intensional Programming Paradigm</head><p>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</p><formula xml:id="formula_0">• C.</formula><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><formula xml:id="formula_1">E = Ja Fe Mr Ap Ma Jn Jl Au Se Oc No De Montreal F F F F T T T T T F F F Ottawa F F F T</formula></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head>T T T T T F F F Toronto F F T T T T T T T T F F Vancouver F T T T T T T T T T T T</head><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 <ref type="bibr" target="#b6">[7]</ref>.</p><p>Lucid was a data-flow language and evolved into a Multidimensional Intensional Programming Language <ref type="bibr" target="#b0">[1]</ref>. 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.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="3">Context Theory in Lucx</head><p>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.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="3.1">Context Definition</head><p>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 = {d 1 , d 2 , . . . , d n } denote a finite set of dimension names. We associate with each d i ∈ DIM a unique enumerable tag set X i . Let TAG = {X 1 , . . . , X r } denote the set of tag sets. There exists functions f dimtotag : DIM → TAG, such that the function f dimtotag associates with every d i ∈ DIM exactly one tag X j in TAG. </p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head>Definition 1 Consider the relations</head><formula xml:id="formula_2">P i = {d i } × f dimtotag (d i ) 1 ≤ i ≤ n A context C, given (DIM, f dimtotag ),</formula><formula xml:id="formula_3">(s context), if (d i , x i ), (d j , x j ) ∈ C ⇒ d i = d j . A simple context C of degree 1 is called a micro (m context) context.</formula></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head>Example 1</head><p>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: <ref type="bibr" target="#b0">(1)</ref>.Sampling Time ST with index N; (2). Pressure P with index set {s 1 , . . . , s k }, where s 1 , . . . , s k are named sensory devices; and (3). Volume V with index set {m 1 , . . . , m q }, where m 1 , . . . , m q are named measuring devices. A context c = [ST : 1, P : s 2 , V : m 3 ] for one stream σ may be interpreted as a reference to the tuple t 1 , p 2 , v 3 , where at the first sampling time t 1 the value of volume measured by m 3 is v 3 and the value of pressure observed by the sensor s 2 is p 2 . Supposing t 1 , p 2 , v 3 ∈ 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 σ = p v t . Such a reference will produce the result p2 v3 t1 , which is the result of evaluating the expression σ with the substitution [t → t 1 ; p → p 2 ; v → v 3 ]. In this case, the domain for the entities in the stream σ is R.</p><p>Several functions on contexts are predefined in <ref type="bibr" target="#b1">[2]</ref>. 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.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="3.2">Context Operators</head><p>In <ref type="bibr" target="#b8">[9]</ref>, we have formally defined the following context operators: the override ⊕ is similar to function override; difference , comparison =, conjunction , and disjunction 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><formula xml:id="formula_4">Example 2 : Let c 1 = [X : 2, X : 3, Y : 4],c 2 = [X : 2, Y : 4, Z : 5], c 3 = [Y : 2], D = {Y, Z}, Then c 1 ⊕ c 2 = [X : 2, Y : 4, Z : 5], c 1 c 2 = [X : 3], c 1 ↓ D = [Y : 4], c 1 c 2 = [X : 2, Y : 4], c 1 c 2 = [X : 2, X : 3, Y : 4, Z : 5], c 2 ↑ D = [X : 2], c 2 c 3 = {[X : 2, Y : 2, Z : 5], [X : 2, Y : 3, Z : 5], [X : 2, Y : 4, Z : 5]}, c 3 c 2 = {[X : 2, Y : 2, Z : 5], [X : 2, Y : 3, Z : 5], [X : 2, Y : 4, Z : 5]}, c 2 / Y, 3 = [X : 2, Y : 3, Z : 5], c 2 c 3 = ∅</formula><p>In order to provide a precise meaning for a context expression, we have defined the precedence rules for all the operators in Figure <ref type="figure" target="#fig_0">1</ref>[a] (right column) (from the highest precedence to the lowest) and described a set of evaluation rules for context expressions in <ref type="bibr" target="#b8">[9]</ref>. 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 <ref type="figure" target="#fig_0">1</ref>[a](left column).</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="3.3">Box and Box Operators</head><p>A context which is not a micro context or a simple context is called a non-simple context. For example, context c 4 = [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 <ref type="bibr" target="#b1">[2]</ref>. 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 </p><formula xml:id="formula_5">Box[∆ | p]. syntax precedence C ::= c | C = C | C ⊇ C | C ⊆ C | C | C | C/C | C ⊕ C | C C | C C | C C | C C | C C | C ↓ D | C ↑ D 1. ↓, ↑, / 2. | 3. , 4. ⊕, 5. , 6. =, ⊆, ⊇ (a) Rules for Context Expression syntax precedence B ::= b | B | B | B B | B B | B B | B ↓ D | B ↑ D | B/ d, t 1. ↓, ↑, / 2. | 3.</formula></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head>, , (b) Rules for Box Expression</head></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head>. , k, and p is a predicate formula defined on the tuples of the relation</head><formula xml:id="formula_6">Π d ∈∆ f dimtotag (d). The syntax Box[∆ | p] = {s | s = [d i1 : x i1 , . . . , d i k : x i k ]}, where the tuple (x 1 , . . . , x k ), x i ∈ f dimtotag (d i ), i = 1, . .</formula></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head>. 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.</head><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:</p><formula xml:id="formula_7">B ↑ D = {c ↑ D | c ∈ B}, B ↓ D = {c ↓ D | c ∈ B}.</formula><p>However not all context operators have natural extensions. Instead, the following three operations (join), (intersection), and (union) are defined <ref type="bibr" target="#b1">[2]</ref> for sets of contexts introduced by Box.</p><formula xml:id="formula_8">Example 3 : Let DIM = {X, Y, Z}, f dimtotag (X) = f dimtotag (Y) = f dimtotag (Z) = N, B 1 = Box[X, Y | x, y ∈ N ∧ x + y = 5], B 2 = Box[Y, Z | y, z ∈ N ∧ y = z 2 ∧ z ≤ 3]. Then B 1 = {[X : 1, Y : 4], [X : 2, Y : 3], [X : 3, Y : 2], [X : 4, Y : 1]} B 2 = {[Y : 1, Z : 1], [Y : 4, Z : 2], [Y : 9, Z : 3]}. Hence B 1 B 2 = Box[X, Y, Z | x + y = 5 ∧ (y = z 2 ∧ z ≤ 3)] = {[X : 1, Y : 4, Z : 2], [X : 4, Y : 1, Z : 1]} B 1 B 2 = Box[Y | x + y = 5 ∧ (y = z 2 ∧ z ≤ 3)] = {[Y : 1], [Y : 4]} B 1 B 2 = Box[X, Y, Z | x + y = 5 ∨ (y = z 2 ∧ 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]}</formula><p>We define these three operators ( , , and ) have equal precedence and have semantics analogous to relational algebra operators. Let B be a box expression and D be a dimension set. A formal syntax for box expression B is defined in Figure <ref type="figure" target="#fig_0">1</ref>[b] (left column) and the precedence rules for box operators are defined in Figure <ref type="figure" target="#fig_0">1</ref>[b] right column.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="3.4">Context Category</head><p>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 <ref type="figure" target="#fig_1">2</ref>[a] shows two different context regions, which can be represented as follows:</p><formula xml:id="formula_9">B 1 = Box[X, Y, Z | x 2 + z 2 ≤ 16 ∧ x = 1 2 z ∧ z ≥ 0], B 2 = Box[X, Y, Z | x 2 + y 2 + z 2 ≤ 9 ∧ z ≥ 0]. Box B 1</formula><p>defines a cone, and Box B 2 defines the upper half of hemisphere with the radius 3. If we restrict to integer indices, then the set of contexts defined by Box B 1 consists of all the points with integer coordinates within the cone, and the set of contexts defined by Box B 2 consists of all the points with integer coordinates within the hemisphere. </p><formula xml:id="formula_10">1 = (0 &lt; v(c 1 )(x) &lt; 1) ∧ (0 &lt; v(c 2 )(y) &lt; v(c 1 )(x)</formula><p>) 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.</p><p>Nested Contexts Nested contexts define the meta relation between different contexts. This is similar to Guha's definition of nested context <ref type="bibr" target="#b3">[4]</ref>. In his definitions, nested context enables to nest ist(f , c) formulas, which define that formula f is true in context c, and ist(c i ist(c j , α)), ist(c k ist(c l . . . ist(c j α) . . .)) are all valid. In the former example ist(c i ist(c j , α)), context c i is outer or meta to context c j . 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></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head>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</head><p>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: </p><formula xml:id="formula_11">1. p(x 1 , . . . , x r ) xr+1 → q(x 1 , . . . , x r , x r+1 ) 2. p(x 1 , . . . , x r ) xr+1,...,xr+s −→ q(x 1 , . . . , x r , . . . , x r+s ) ∆ = p 0 (x 1 , . . . , x r ) xr+1 → p 1 (x 1 , . . . , x r , x r+1 ) xr+2 → p 2 (x 1 , . . . , x r+2 ) . . .</formula><formula xml:id="formula_12">2 ∈ B, b 1 = Box[∆ 1 | p 1 ], b 2 = Box[∆ 2 | p 2 ], b 1 b 2 iff ∆ 1 ⊂ ∆ 2</formula><p>and p 2 is an extension of the logic expression p 1 . It is easy to see that is an irreflexive partial order on B. We define a partially order chain b 1 b 2 . . . b k 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.</p><formula xml:id="formula_13">Definition 5 Let B = {b 1 , b 2 , . . .} be a finite set of boxes, b i = Box[∆ i | p i ],</formula><p>and E be an expression. Define the relation £ on the set {E@ * b 1 , E@ * b 2 , . . .} as follows:</p><formula xml:id="formula_14">E@ * b i £ E@ * b k iff for E ij = E@c ij , c ij ∈ b i , there exists E kj = E@c kj , c kj ∈ b k , such that c kj ↑ {∆ k − ∆ i } = c ij , and E kj = E ij @(c kj c ij ). Theorem If b 1 b 2 then E@ * b 1 £ E@ * b 2 . Proof Let b 1 = Box[∆ 1 | p 1 ], b 2 = Box[∆ 2 | p 2 ], ∆ 1 = {X 1 , X 2 , . . . , X k }, and ∆ 2 = {X 1 , X 2 , . . . , X k , X k+1 , . . . , X m }, ∃(a 1 , . . . , a k ), p 1 (a 1 , . . . , a k ) is true, then c 1j = [X 1 : a 1 , . . . , X k : a k ] ∈ b 1 . By property b 1 b 2 , ∃ a k+1 , . . . , a m such that p 2 (a 1 , . . . , a k , a k+1 , . . . , a m ) is true. Hence c 2j = [X 1 : a 1 , . . . , X k : a k , X k+1 : a k+1 , . . . , X m : a m ] ∈ b 2 .</formula><p>It is easy to verify that c 1j and c 2j satisfy</p><formula xml:id="formula_15">c 2j ↑ {∆ 2 − ∆ 1 } = c 1j and E 1j = E@c 1j , E 2j = E@c 2j satisfy E 2j = E 1j @(c 2j c 1j ). Hence it follows that E@ * b 1 £ E@ * b 2 . In general if b 1 b 2 .</formula><p>. . b k is a chain of nested contexts, we get a corresponding chain of cascading expressions:</p><formula xml:id="formula_16">E@ * b 1 £ E@ * b 2 . . . £ E@ * b k .</formula><p>This rule gives the base for the reasoning and reducing rules for constraint programming solver mentioned in <ref type="bibr" target="#b8">[9]</ref>.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head>Context Dependent Expressions</head><p>Contexts can be passed as parameters to functions.</p><formula xml:id="formula_17">Definition 6 Let B 1 = Box[∆ 1 | p 1 ], and B 2 = Box[∆ 2 | p 2 ]</formula><p>define the context regions in the space generated by the dimensions ∆ 1 ∪ ∆ 2 . The context-dependent expression E is defined differently in different regions:</p><formula xml:id="formula_18">λ •E =    E 1 in B 1 B 2 E 2 in B 2 B 1 E 3 in B 1 B 2 µ •E is defined to indicate corresponding context regions, namely, µ •E = {B 1 B 2 , B 2 B 1 , B 1 B 2 }</formula><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 <ref type="figure" target="#fig_1">2</ref></p><formula xml:id="formula_19">[a]. Hence µ •f = {B 1 B 2 , B 2 B 1 , B 1 B 2 }, and λ •f = {2x 3 + y − 6, x + y 2 , z 3 + y}.</formula><p>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 <ref type="bibr" target="#b8">[9]</ref>.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head>Dependent Context</head><p>We define context dependency analogous to the functional dependency in relational data models.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head>Definition 7</head><p>Let ∆ = {X 1 , . . . , X k } be a dimension set. If there exists a function φ ij : f dimtotag (X i ) → f dimtotag (X j ), 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><formula xml:id="formula_20">φ AB : Π Xi∈A f dimtotag (X i ) → Π Xj∈B f dimtotag (X j ).</formula><p>For a given functional dependency φ ij in ∆, we define dependent contexts as the set of contexts:</p><formula xml:id="formula_21">S ∆ = {c | dim(c) = ∆ ∧ ({X i , X j } ⊆ ∆ ⊆ ∆)} As an example, c = [X i : a, X j : φ ij (a)] ∈ S ∆ , a ∈ f dimtotag (X i ).</formula><p>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:</p><formula xml:id="formula_22">φ(m 1 ) = φ(m 2 ) = 1; φ(m 3 ) = φ(m 4 ) = 2.</formula><p>Hence context of this form [P : s 1 , V : m 3 , 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 <ref type="bibr" target="#b8">[9]</ref>, 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 ∆ k , where there is no dependency in S ∆ k and S ∆ k = b 1 b 2 . . . b k , each b i 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 b 1 , . . . , b k 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></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="4">Intensional Language Lucx</head><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></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head>Syntax and Semantics of Lucx</head><p>The syntax of Lucx is shown below.</p><formula xml:id="formula_23">E ::= id | E(E1, . . . , En) | if E then E else E | # | E @ E | [E 1 : E 1 , . . . , En : E n ] | E 1 , . . . , En E | select(E, E ) | E @ * S | E where Q S ::= {E 1 , . . . , Em} | Box[E | E ] Q ::= dimension id | id = E | id(id1, . . . , idn) = E | Q Q</formula><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, P E : v, which means that in the definition environment D, and in the evaluation context P , 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 <ref type="bibr" target="#b6">[7]</ref>. The evaluation context P , 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 <ref type="bibr" target="#b6">[7]</ref>. The new semantic rules for Lucx are given below. </p><formula xml:id="formula_24">D, P E d j : idj D(idj) = (dim) D, P Ei j : vj P = P0 † [id1 → v1] † . . . † [idn → vn] D, P [E d 1 : Ei 1 , E d 2 : Ei 2 , . . . , E dn : Ei n ] : P</formula><p>The evaluation rule for the navigation operator, E atc , which corresponds to the syntactic expression E @ E , evaluates E in context E , where E is a context defined in Section 3.1. The evaluation rule for the set navigation operator E ats , 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 E tupid evaluates a tuple as a finite stream whose dimension is explicitly indicated as E in the corresponding syntax rule E 1 , . . . , E n E. Accordingly, the semantic rule E select picks up one element indexed by E from the tuple E . The semantic rule E box evaluates a Box to a set of contexts according to the definition in Section 3.3. f p (tag(P i ) i=1..m ) is a boolean function. The rule E set evaluates {E 1 , . . . , E m } to a set of contexts.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head>Examples of Lucx Programs</head><p>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><formula xml:id="formula_25">Temp t+1,s+1 = k × Temp t,s − (1 − 2 × k) × Temp t,s+1 + k × Temp t,s+2</formula><p>Temp t,0 = 100 Temp 0,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 Temp @ [Time : t + 1, Space : s</p><formula xml:id="formula_26">+ 1] = k × Temp @ [Time : t, Space : s] −(1 − 2 × k) × Temp @ [Time : t, Space : s + 1] +k × Temp @ [Time : t, Space : s + 2]</formula><p>Temp@[Time : t, Space : 0] = 100 Temp@[Time : 0, Space : s + 1] = 0 end 2. Consider the problem of finding the solution in positive integers that satisfy the following constraints:</p><p>x 3 + y 3 + z 3 + u 3 = 100 x &lt; u x + y = z The Lucx program is given below:</p><p>Eval.B1, B2, B3 (x , y , z , u ) = N where N = merge ( merge( merge(x, y), z), u) @ B 1 B 2 B 3 ; where merge(x, y) = if (x &lt;= y) then x else y;</p><formula xml:id="formula_27">B 1 = Box [ X, Y, Z, U | x 3 + y 3 + z 3 + u 3 = 100, x ∈ X, y ∈ Y , z ∈ Z , u ∈ U ]; B 2 = Box [ X, U | x &lt; u, x ∈ X , u ∈ U ]; B 3 = Box [ X, Y, Z | x + y = z, x ∈ X , y ∈ Y , z ∈ Z ]; end end</formula><p>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 <ref type="bibr" target="#b5">[6]</ref>. 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 <ref type="bibr" target="#b8">[9]</ref>, we provide the translation rules for translating Lucx operators into Indexical Lucid operators. Combined with the translation rules for Indexical Lucid operators provided in <ref type="bibr" target="#b6">[7]</ref>, 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.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="5">Conclusion</head><p>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 <ref type="bibr" target="#b1">[2]</ref>. In addition, the use of the paradigm for real-time reactive programming is shown in <ref type="bibr" target="#b7">[8]</ref>. We are developing larger application programs that arise in constraint programming and in context-aware systems <ref type="bibr" target="#b8">[9]</ref>.</p></div><figure xmlns="http://www.tei-c.org/ns/1.0" xml:id="fig_0"><head>Fig. 1 .</head><label>1</label><figDesc>Fig. 1. Rules for Contex and Box Expressions</figDesc></figure>
<figure xmlns="http://www.tei-c.org/ns/1.0" xml:id="fig_1"><head>Fig. 2 .</head><label>2</label><figDesc>Fig. 2. Context Category</figDesc></figure>
<figure xmlns="http://www.tei-c.org/ns/1.0" xml:id="fig_2"><head>xr+s→Definition 4</head><label>4</label><figDesc>p s (x 1 , . . . , x r+s ), where p 0 ≡ p, p s ≡ q. We define a relation on a set of boxes B as follows: for b 1 , b</figDesc></figure>
<figure xmlns="http://www.tei-c.org/ns/1.0" xml:id="fig_3"><head>E</head><label></label><figDesc>at(c) : D, P E : P D, P E : v D, P E @E : v E# : D, P # : P E. : D, P E2 : id2 D(id2) = (dim) D, P E1.E2 : tag(E1 ↓ {id2}) Etuple : D, P E : id D †[id → (dim)] P †[id → 0] D, P Ei : vi D, P E1, E2, . . . , En E : v1 fby.id v2 fby.id . . . vn fby.id eod Eselect : E = [d : v ] E = E1, . . . , En d P = P † [d → v ] D, P E :v D, P select(E, E ) : v E at(s) : D, P S : {P1, . . . , Pm} D, Pi:1..m E : vi D, P E @ * S : {v1, . . . , vm} Eset : D, P Ew:1..m : Pm D, P {E1, . . . , Em} : {P1, . . . , Pw} Ebox : D, P E : ∆ ∆ = {v 1 , . . . , v n } = dim(P1) = . . . = dim(Pm) D(v k:1..n ) = (dim) D, P E : fp(tag(Pi:1..m)) = true D, P Box[E | E ] : {P1, . . . , Pm} Econtext :</figDesc></figure>
<figure xmlns="http://www.tei-c.org/ns/1.0" type="table" xml:id="tab_0"><head>is a finite subset of n i=1 P i . The degree of the context C is | ∆ |, where ∆ ⊂ DIM includes the dimensions that appear in C. A context is written using enumeration syntax</head><label></label><figDesc>, as [d 1 : x 1 , . . . , d n : x n ], where d 1 , . . . , d n are dimension names, and x i is the tag for dimension d i . We say a context C is simple</figDesc><table /></figure>
		</body>
		<back>

			<div type="funding">
<div xmlns="http://www.tei-c.org/ns/1.0"><p>This work is supported by grants from the Natural Sciences and Engineering Research Council of Canada.</p></div>
			</div>

			<div type="references">

				<listBibl>

<biblStruct xml:id="b0">
	<monogr>
		<title level="m" type="main">Multidimensional, Declarative Programming</title>
		<author>
			<persName><forename type="first">E</forename><surname>Ashcroft</surname></persName>
		</author>
		<author>
			<persName><forename type="first">A</forename><surname>Faustini</surname></persName>
		</author>
		<author>
			<persName><forename type="first">R</forename><surname>Jagannathan</surname></persName>
		</author>
		<author>
			<persName><forename type="first">W</forename><surname>Wadge</surname></persName>
		</author>
		<imprint>
			<date type="published" when="1995">1995</date>
			<publisher>Oxford University Press</publisher>
			<pubPlace>London</pubPlace>
		</imprint>
	</monogr>
</biblStruct>

<biblStruct xml:id="b1">
	<analytic>
		<title level="a" type="main">Intensional Programming for Agent Communication</title>
		<author>
			<persName><forename type="first">V</forename><forename type="middle">S</forename><surname>Alagar</surname></persName>
		</author>
		<author>
			<persName><forename type="first">J</forename><surname>Paquet</surname></persName>
		</author>
		<author>
			<persName><forename type="first">K</forename><surname>Wan</surname></persName>
		</author>
	</analytic>
	<monogr>
		<title level="m">Proceedings of DALT&apos;04</title>
				<meeting>DALT&apos;04<address><addrLine>New York</addrLine></address></meeting>
		<imprint>
			<publisher>Springer-Verlag</publisher>
			<date type="published" when="2004-07">July 2004</date>
		</imprint>
	</monogr>
	<note>proceeding will appear in Lecture Notes in Computer Science</note>
</biblStruct>

<biblStruct xml:id="b2">
	<analytic>
		<title level="a" type="main">Understanding and Using Context</title>
		<author>
			<persName><forename type="first">A</forename><forename type="middle">K</forename><surname>Dey</surname></persName>
		</author>
	</analytic>
	<monogr>
		<title level="j">Personal and Ubiquitous Computing Journal</title>
		<imprint>
			<biblScope unit="volume">5</biblScope>
			<biblScope unit="issue">1</biblScope>
			<biblScope unit="page" from="4" to="7" />
			<date type="published" when="2001">2001</date>
		</imprint>
	</monogr>
</biblStruct>

<biblStruct xml:id="b3">
	<monogr>
		<title level="m" type="main">Contexts: A Formalization and Some Applications</title>
		<author>
			<persName><forename type="first">R</forename><forename type="middle">V</forename><surname>Guha</surname></persName>
		</author>
		<imprint>
			<date type="published" when="1995-02-10">February 10,1995</date>
		</imprint>
		<respStmt>
			<orgName>Stanford University</orgName>
		</respStmt>
	</monogr>
	<note type="report_type">Ph.d thesis</note>
</biblStruct>

<biblStruct xml:id="b4">
	<analytic>
		<title level="a" type="main">Using Context as a Crystal Ball: Rewards and Pitfalls</title>
		<author>
			<persName><forename type="first">K</forename><surname>Cheverst</surname></persName>
		</author>
		<author>
			<persName><forename type="first">N</forename><surname>Davies</surname></persName>
		</author>
		<author>
			<persName><forename type="first">K</forename><surname>Mitchell</surname></persName>
		</author>
		<author>
			<persName><forename type="first">C</forename><surname>Efstratiou</surname></persName>
		</author>
	</analytic>
	<monogr>
		<title level="j">Personal Technologies Journal</title>
		<imprint>
			<biblScope unit="volume">3</biblScope>
			<biblScope unit="page" from="8" to="11" />
			<date type="published" when="2001">2001</date>
		</imprint>
	</monogr>
</biblStruct>

<biblStruct xml:id="b5">
	<analytic>
		<title level="a" type="main">The GIPSY Architecture</title>
		<author>
			<persName><forename type="first">J</forename><surname>Paquet</surname></persName>
		</author>
		<author>
			<persName><forename type="first">P</forename><surname>Kropf</surname></persName>
		</author>
	</analytic>
	<monogr>
		<title level="j">DCW</title>
		<imprint>
			<biblScope unit="page" from="144" to="153" />
			<date type="published" when="2000">2000</date>
		</imprint>
	</monogr>
</biblStruct>

<biblStruct xml:id="b6">
	<monogr>
		<title level="m" type="main">Intensional Scientific Programming Ph</title>
		<author>
			<persName><forename type="first">Joey</forename><surname>Paquet</surname></persName>
		</author>
		<imprint>
			<date type="published" when="1999">1999</date>
			<pubPlace>Quebec, Canada</pubPlace>
		</imprint>
		<respStmt>
			<orgName>Département d&apos;Informatique, Universite Laval</orgName>
		</respStmt>
	</monogr>
	<note type="report_type">D. Thesis</note>
</biblStruct>

<biblStruct xml:id="b7">
	<analytic>
		<title level="a" type="main">Real Time Reactive Programming Enriched with Context</title>
		<author>
			<persName><forename type="first">K</forename><surname>Wan</surname></persName>
		</author>
		<author>
			<persName><forename type="first">V</forename><forename type="middle">S</forename><surname>Alagar</surname></persName>
		</author>
		<author>
			<persName><forename type="first">J</forename><surname>Paquet</surname></persName>
		</author>
	</analytic>
	<monogr>
		<title level="m">IC-TAC2004</title>
		<title level="s">Lecture Notes in Computer Science</title>
		<meeting><address><addrLine>Guiyang, China</addrLine></address></meeting>
		<imprint>
			<publisher>Springer-Verlag</publisher>
			<date type="published" when="2004-09">September 2004</date>
			<biblScope unit="volume">3407</biblScope>
			<biblScope unit="page" from="387" to="402" />
		</imprint>
	</monogr>
</biblStruct>

<biblStruct xml:id="b8">
	<monogr>
		<title level="m" type="main">Lucx: An Intensional Programming Language Enriched With Contexts</title>
		<author>
			<persName><forename type="first">K</forename><surname>Wan</surname></persName>
		</author>
		<imprint>
			<date type="published" when="2005">2005</date>
			<pubPlace>Montreal, Canada</pubPlace>
		</imprint>
		<respStmt>
			<orgName>Department of Computer Science, Concordia University</orgName>
		</respStmt>
	</monogr>
	<note>Ph.d thesis(under preparation</note>
</biblStruct>

				</listBibl>
			</div>
		</back>
	</text>
</TEI>
