Programming in hybrid constraint languages 上田研究室 M2 中村 好一.

Slides:



Advertisements
Similar presentations
5.1 Real Vector Spaces.
Advertisements

Control Structures Any mechanism that departs from straight-line execution: –Selection: if-statements –Multiway-selection: case statements –Unbounded iteration:
Chapter 3 DATA: TYPES, CLASSES, AND OBJECTS. Chapter 3 Data Abstraction Abstract data types allow you to work with data without concern for how the data.
Lambda Calculus and Lisp PZ03J. Lambda Calculus The lambda calculus is a model for functional programming like Turing machines are models for imperative.
Introduction to CS Theory Lecture 2 – Discrete Math Revision Piotr Faliszewski
Constraint Logic Programming Ryan Kinworthy. Overview Introduction Logic Programming LP as a constraint programming language Constraint Logic Programming.
C. Varela; Adapted w/permission from S. Haridi and P. Van Roy1 Declarative Computation Model Single assignment store Kernel language syntax Carlos Varela.
1 Constraint Programming Maurizio Gabbrielli Universita’ di Bologna Slides by: K. Marriott.
10 November JavaScript. Presentation Hints What do YOU think makes a good presentation Some of my suggestions Don’t write full sentences on slides Talk,
Program Design and Development
1 Chapter 1: Constraints What are they, what do they do and what can I use them for.
Defining Polynomials p 1 (n) is the bound on the length of an input pair p 2 (n) is the bound on the running time of f p 3 (n) is a bound on the number.
Lecture , 3.1 Methods of Proof. Last time in 1.5 To prove theorems we use rules of inference such as: p, p  q, therefore, q NOT q, p  q, therefore.
PART 7 Ordinary Differential Equations ODEs
The Game of Algebra or The Other Side of Arithmetic The Game of Algebra or The Other Side of Arithmetic © 2007 Herbert I. Gross by Herbert I. Gross & Richard.
Symbol Table (  ) Contents Map identifiers to the symbol with relevant information about the identifier All information is derived from syntax tree -
Algebra Problems… Solutions Algebra Problems… Solutions © 2007 Herbert I. Gross Set 20 By Herbert I. Gross and Richard A. Medeiros next.
Introduction to Programming (in C++) Data and statements Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. of Computer Science, UPC.
A Review of Recursion Dr. Jicheng Fu Department of Computer Science University of Central Oklahoma.
Analysis of Algorithm Lecture 3 Recurrence, control structure and few examples (Part 1) Huma Ayub (Assistant Professor) Department of Software Engineering.
Reading and Writing Mathematical Proofs
Mathematics Review Exponents Logarithms Series Modular arithmetic Proofs.
1 Week 3 Questions / Concerns What’s due: Lab1b due Friday at midnight Lab1b check-off next week (schedule will be announced on Monday) Homework #2 due.
Modeling and simulation of systems Numerical methods for solving of differential equations Slovak University of Technology Faculty of Material Science.
DECIDABILITY OF PRESBURGER ARITHMETIC USING FINITE AUTOMATA Presented by : Shubha Jain Reference : Paper by Alexandre Boudet and Hubert Comon.
Conditional Statements For computer to make decisions, must be able to test CONDITIONS IF it is raining THEN I will not go outside IF Count is not zero.
Computer Science Department Data Structure & Algorithms Lecture 8 Recursion.
Section 4.3 – Riemann Sums and Definite Integrals
What does a computer program look like: a general overview.
Equations, Inequalities, and Mathematical Models 1.2 Linear Equations
CS 611: Lecture 6 Rule Induction September 8, 1999 Cornell University Computer Science Department Andrew Myers.
19 Aug 2002EXPRESS On the Expressive Power of Temporal Concurrent Constraint Programming Languages Mogens Nielsen, BRICS Catuscia Palamidessi, INRIA.
Looping and Counting Lecture 3 Hartmut Kaiser
Chapter 7 Selection Dept of Computer Engineering Khon Kaen University.
CSC 212 More Recursion, Stacks, & Queues. Linear Recursion Test for the bases cases  At least one base case needs to be defined If not at a base case,
CS 105 Perl: Data Types Nathan Clement 15 May 2014.
OPERATIONS WITH DERIVATIVES. The derivative of a constant times a function Justification.
Discrete Mathematical Structures 4 th Edition Kolman, Busby, Ross © 2000 by Prentice-Hall, Inc. ISBN
Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino
Sheng-Fang Huang. 1.1 Basic Concepts Modeling A model is very often an equation containing derivatives of an unknown function. Such a model is called.
Decisions in Python Boolean functions. A Boolean function This is a function which returns a bool result (True or False). The function can certainly work.
Types and Programming Languages Lecture 11 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Alice in Action with Java Chapter 4 Flow Control.
Language Find the latest version of this document at
1 Previous Lecture Overview  semaphores provide the first high-level synchronization abstraction that is possible to implement efficiently in OS. This.
Discrete Mathematics Lecture # 22 Recursion.  First of all instead of giving the definition of Recursion we give you an example, you already know the.
Types and Programming Languages Lecture 14 Simon Gay Department of Computing Science University of Glasgow 2006/07.
0 PROGRAMMING IN HASKELL Based on lecture notes by Graham Hutton The book “Learn You a Haskell for Great Good” (and a few other sources) Odds and Ends,
IBM Research: Software Technology © 2005 IBM Corporation Programming Technologies 1 Temporal Rules Vijay Saraswat IBM TJ Watson July 27, 2012.
1 CSC103: Introduction to Computer and Programming Lecture No 17.
Chad’s C++ Tutorial Demo Outline. 1. What is C++? C++ is an object-oriented programming (OOP) language that is viewed by many as the best language for.
Operational Semantics Mooly Sagiv Reference: Semantics with Applications Chapter 2 H. Nielson and F. Nielson
1 Vectors, binary search, and sorting. 2 We know about lists O(n) time to get the n-th item. Consecutive cons cell are not necessarily consecutive in.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Section Recursion 2  Recursion – defining an object (or function, algorithm, etc.) in terms of itself.  Recursion can be used to define sequences.
Section Recursion  Recursion – defining an object (or function, algorithm, etc.) in terms of itself.  Recursion can be used to define sequences.
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
1 Chapter 1: Constraints What are they, what do they do and what can I use them for.
Introduction to python programming
What are they, what do they do and what can I use them for.
Lecture # 2.
3.1 Polynomial & Exponential Derivatives
September 4, 1997 Programming Languages (CS 550) Lecture 6 Summary Operational Semantics of Scheme using Substitution Jeremy R. Johnson TexPoint fonts.
Data Structures Recursion CIS265/506: Chapter 06 - Recursion.
Algorithm design and Analysis
.Net Programming with C#
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Character Set Uppercase Alphabets A,
Logical Operations In Matlab.
Declarative Computation Model Single assignment store (VRH 2
Types, Truth, and Expressions
Presentation transcript:

Programming in hybrid constraint languages 上田研究室 M2 中村 好一

The relations between the cc languages cc cc Default cc Timed cc = cc + defaults = cc + time Timed default cc Hybrid cc Timed Default cc = cc + defaults = cc + defaults +cont.time + discrete time Hybrid cc

Hybrid cc z ハイブリッドシステムのモデリングと検証を行う言語と して考案された z 離散的・連続的な動作を表現できる Example: 部屋の温度を管理するエアコン ・部屋の温度は、連続的な微分方程式に従って変化する ・誰かが窓を開ける、中にいる人が出て行くなどの行動は 方程式を離散的に変化させる

The cc Programming Language 制約 store と Agent(tell,ask) から構成される計算モデルを持 つ Example program: x=10,x’=0,if x>0 then x’’=-10 X = 10 X’ = 0 if x>0 then x’’=-10 if y=0 then z=1 store x’ = 0 X = 10 if x>0 then x’’=-10 if y=0 then z=1 store x’ = 0, x = 10 if x>0 then x’’=-10 if y=0 then z=1 store x’ = 0, x = 10 x’’=-10 if y=0 then z=1 store x’ = 0, x =10, x’’ = -10 if y=0 then z=1 Basic combinators: c add constraint c to the store. if c then A if c is entailed by the store, execute subprogram A, otherwise wait. A, B execute subprograms A and B in independently. unless c then A if c will not be entailed in the current phase, execute A (default cc).

Hybrid cc – the language and its use c : tell the constraint c if d then A : if d holds,reduce to A if d else A : reduce to A unless d holds A,B : Parallel Composition new V in A : V is local to A hence A : execute A at every instant after now

t=0 t=0+ t= t=1.414 x=10,x'=0, hence{if x>0 then x''=-10, if x=0 then x' = -0.5*x'} Hcc Example1

Hcc Example2 #Prey & Predator(in Hcc)# py=8, //prey pd=2, //predator pd’=0.2, always py’=0.08*py – 0.04*py*pd //prey growth always { cont(pd) if(pd>=0.5*py) then pd’=-0.1*pd+0.02*py*pd else pd’=-0.06*pd+0.02*py*pd }, sample(pd), sample(py)

Prey&Predator Figure:Prey&Predator

Computational model プログラムにおける処理順序 1. Point Phase( 離散的変化が起こる時点 ) 2. Interval Phase( 連続的変化が起こる時点 ) ※ 1, 2 を交互に繰り返し行う

The Control Constructs and Execution of hcc zHcc の実行順序 1. Point Phase から始まる 2. Point Phase におけるすべての計算を行う 3. Interval Phase に移る 4. プログラム中の微分方程式の積分を行う (4th order Runge-Kutta 法 ) 5. 制約の状態が変化、制約の矛盾が発生、処理時間が経過した場合 に 積分を終える 6. 処理後、再び Point Phase に移る 同様に、 1 ~ 6 を繰り返す

Execution of hcc Example; X =0,hence{x’=1,if(x=2) then y=1} In the interval phase following x=0,x evolves continuously according to x’=1,through the interval(0,2) until x=2 is about to become true. At this point the set of constraints may change,so the next point phase is started.

Continuous Constraints ContConstr ::= Term RelOp Term | cont(LVariable)| lcont(LVariable) RelOp ::= = | >= | <= | := = Term ::= LVariableExpr | Constant | Term BinOp Term | UnOp(Term) | dot(Term,Num) | Term’| (Term) LVariableExpr ::= Lvariable | Uvariable.LVariableExpr BinOp ::= + | - | ※ | / |^ UnOp ::= - |log | exp | prev ・ Lvariables are strings which start with a lowercase character. ・ Constants are floating point numbers. ・ exp(x) is the exponential function e^x. ・ Term’ denotes the derivative of Term. ・ dot(Term, n ) denotes the n th derivative of Term( n is a natural number).

Ask Constraints (for Continuous Constraints) AContConstr ::= Term ARelOp Term ARelOp ::= = | >= | | !=

Non-arithmetic Constraints Dconstr ::= UVariableExpr | UVarExpr = Dexpr UVariableExpr ::= UVariable | UVariableExpr.UVariableExpr Dexpr ::= UVariableExpr | prev(UVariableExpr) | String |(VarList)HccAgent |(VarList)[VarList]HccAgent |UVariableExpr(VarList) [VarList]HccAgent VarList ::= Uvariable | Lvariable | VarList,VarLIst ・ Uvariable is a string starting with an uppercase character. ・ HccAgent is hcc Agent.

Closure & Class definition zClosure definition: X = (A,x) Agent zClass definition: X = (m,n)[A,m] Agent

Closure definition X = (A,x)Agent Example: P = (n,m,Q){ if n > 0 then new m1 in {Q(n-1,m1,Q), m:= m1*n} else m = 1 }, Fact = (n,m) {P(n,m,P)}, Fact(10,m)

Class Definition X = (m,n)[A,m] Agent Example: Planet = (initvx,initvy,initpx,initpy,m)[px,py,mass]{ px = initpx, py = initpy, px’= initvx, py’ = initvy, always{ mass=m, px’’:=sum(F.x,Force(F),F.Target = Self), py’’:=sum(F.x,Force(F),F.Target = Self) }

Boolean Constraints BoolConstr ::= Atom | StrConstr | ContConstr | Bool && BoolConstr | (BoolConstr) ABoolConstr ::= Atom | StrConstr | AContConstr | ABool && ABoolConstr ABoolConstr || ABoolConstr | (ABoolConstr)

Reduction Rules Tell : <(Γ, c),σ,next, default → <Γ,σ U {c},next, default} σ|- d Ask : → else : → Γ : denotes a set of Hybrid cc program fragments. σ : denotes the store. next : the set of program fragments to be run in the next phase. default : a set of suspended else statements. σ |- c : denotes entailment checking.

Reduction rules(for Hence) The rule for hence A differs in point and interval phases Hence Point : →, default> Hence Interval : → Γ : denotes a set of Hybrid cc program fragments. σ : denotes the store. next : the set of program fragments to be run in the next phase. default : a set of suspended else statements. σ |- c : denotes entailment checking.

The algorithm for interpreter 1. Run the reduction rules on the current, till no further reductions can take place. 2. If σ is inconsistent, return 0 (false). 3. If default is empty, return 1 (true). 4. Remove one statement from default – if c else A. If σ |- c, go to step Add A to Γ. Run the interpreter on the current state. If the result is 1 and σ |-/ c, return Undo the effects of the previous step by backtracking. Run the interpreter on the current state. If the result is 1 and σ |-/ c, return 1. Otherwise return 0.

A Hybrid cc program A is run as follows. 1. Run interpreter with Γ = A, and empty σ, next and default in the point phase. If the result is 0, abort. 2. Run the interval phase with Γ= next, as returned by the point phase. σ, next and default are again empty. If the result is 0, abort. Record all the tells, and also the ask constraints that were checked during the phase. 3. Integrate the arithmetic constraints that were told in the previous step,until one of the ask constraints changes status(i.e.goes from false to true or unknown, etc.). Go to step 1 with Γ= next.

Nonlinear equations zIndexicals zInterval splitting zThe Newton-Raphson method zThe Simplex method 上記の4つを組み合わせて、非線形型制約の充足処理を行 う

Indexicals z 与式 f(x,y)=0 を x=g(y) と書き換える方法 Example : x + y =0, x  [0,3], and y  [-1, -2]. Then the indexical x =-y is used to set to [1, 2].

Interval splitting z 区間 [a,b] を繰り返し分割する方法 za 1 :smallest number 0 ∈ f([a 1,b]) and a ≦ a 1. Hence,if 0 ∈ f([a,(a+b)/2]),then a 1 ∈ [a,(a+b)/2], otherwise a 1 ∈ [(a+b)/2,b] b 1 も同様に行う Example: x^2=1 and x  [-∞, ∞]. It follows that 0  [-∞, 0]. 0  / [-∞, -100]. a1 is determined to be in [-100, 0]. Eventually, a1 is determined to be –1.

The Newton-Raphson method z 方程式 f(x)=0 の近似解を求める方法 zInterval が狭い範囲で効果を発揮する 任意の関数 f(x) について、 f(x)=0 なる点 x を求める。 図のように適当な初期値 x0 において f(x) に接線を引けば、 接線の方程式は y-f(x 0 )=f’(x 0 )(x-x 0 ) である。したがって、 この接線と X 軸との交点 x 1 は y=0 とおいて、 x 1 =x 0 -f(x 0 )/f’(x 0 ) で与えられる。 次に x 1 での f(x) への接線と x 軸との交点を x 2 とする、という操作 を繰り返すと、交点は f(x)=0 の解に近づく。 i 番目の繰り返しで、 x i+1 =x i -f(x i )/f’(x i ) になるので、適当な ε を決めておき、 |x i+1 -x i |<ε になったら、 x i+1 を解とみなす。

Splitting & Newton-Raphson method zSplitting と Newton-Raphson method を組み合わせる (clp Newton) 。 Example: x^2=1 and x ∈ I=[-∞, ∞] 1. Split I recursively until I is split down to [-2,-1]. 2. Applying the N-R method=[-1,-1] is produced. 3. Similarly,[1,1] is produced. 4. Only –1 and 1 are solutions to the equation.

The Control Constructs and Execution of hcc zHcc の実行順序 1. Point Phase から始まる 2. Point Phase におけるすべての計算を行う 3. Interval Phase に移る 4. プログラム中の微分方程式の積分を行う (4th order Runge-Kutta 法 ) 5. 制約の状態が変化、制約の矛盾が発生、処理時間が経過した場合 に 積分を終える 6. 処理後、再び Point Phase に移る 同様に、 1 ~ 6 を繰り返す

Runge-Kutta algorithm ・ 4 次のルンゲクッタ法

Runge-Kutta algorithm (x i,y i ) (x i+1,y i+1 ) xixi x i+1/2 x i+1 k1k1 y(x) x k2k2 k3k3 k4k4 A B C D h/2 1. A 点における傾きから k 1 を計算 2. B 点 (x i +h/2,y i +k 1 /2) におけ る傾きから k 2 を計算 3. C 点 (x i +h/2,y i +k 2 /2) におけ る傾きから k 3 を計算 4. D 点 (x i +h,y i +k 3 ) における 傾きから k 4 を計算 5. k 1 ~k 4 の重み付き平均を 増分として、これを y i に加える ことにより y i+1 を求める k 1 =h(x i,y i ),k 2 =hf(x i +h/2,y i +k 1 /2), k 3 =hf(x i +h/2,y i +k 2 /2), k 4 =hf(t i +h,x i +k 3 ) y i +1=y i +(k 1 +2k 2 +2k 3 +k 4 )/6

Program Example ball.hcc /* A simple example of a ball bouncing on the floor. */ y = 10, y' = 0, // initial conditions hence { if y > 0 then y'' = -10, // free fall if y = 0 then // bounce if (prev(y') > ) then always y' = 0 // end of bouncing else y' = -0.5 * prev(y') }, sample(y)

ボールの軌道 (5 秒間 )

参考文献 zB.Carlson and V.Gupta.Hybrid cc with interval constraints. zV.Gupta,R.Jagadeesan,V.A.Saraswat,and D.Bobrow. Programming in hybrid concurrent constraint languages.In Panos Antsakis,Wolf Kohn,Anil Nerode,and Sankar Sastry,editors,Hybrid Systems Ⅱ,volume999 of Lecture Notes in Computer Science,1995 zV.Gupta,R.Jagadeesan,V.Saraswat,and D.Bobrow. Programming in hybrid constraint languages