Backup diff of Syntax vs current(No. 1)


  • The added line is THIS COLOR.
  • The deleted line is THIS COLOR.
// TODO: link to formal syntax written in BNF.
#author("2021-02-25T15:51:23+09:00","default:Uedalab","Uedalab")
#noattach
#mathjax
#norelated

* Basic Syntax [#r2da58d9]
- A basic hydLa program consists of definitions of constraints and declaration of constraint hierarchies.
* Syntax [#r2da58d9]
- The abstract syntax of HydLa is given in the following BNF.
//#ref(./HydLa_BNF.png, center);
#ref(./HydLa-syntax.png,center,80%);
~
- The concrete syntax uses the symbols in the following table.
#ref(./HydLa-symbols.png,center,50%);
~
- A HydLa program consists of '''definitions of constraints''' and '''declarations of constraint hierarchies''', each of which is described below.

** Definition [#s649ac18]
- One can define constraint using the operator " ''<=>'' ".
>
(name of the constraint) ''<=>'' (definition of constraint) .
<
- A definition allows us to define a named constraint with arguments using the operator "$\texttt{<=>}$".  It allows us to define a named constraint hierarchies   as well.
If the definition has no arguments, we can omit parentheses.

** Constraint [#a67e46ed]
*** Conjunction [#jd43749f]
>
~ (constraint1) ''&'' (constraint2) 
~ or
~ (constraint1) ''/\'' (constraint2)
<
*** Always [#e8fd1135]
- ''Always'' operator in temporal logic is denoted by " ''[]'' "
- This operator means the constraint is effective forever from the time when this constraint is in maximal module sets.
// TODO: link to maximal module set
>
''[]''( constraint )
<
*** Guard Condition [#tdd5bc86]
- The "''=>''" operator means the left-hand side is the guard condition of the right-hand side.
- The constraint on right-hand side is effective only when the left-hand side is entailed.
>
guard ''=>'' constraint
<
*** Derivative [#c106f801]
- The "'' ' ''" operator means a derivative of the variable with respect to time.
>
(variable | derivative of variable)'
<
*** Prev [#y9d604d8]
- The " - " operator means a left hand limit of a variable at each time point.
>
(variable | derivative of variable)'-'
<
*** exp [#r04a0562]
- In describing equality or inequality as the constraint, not only the '(differential) , -(prev) operators, but also the arithmetic operators (+,-(minus),*,/,^(power),**(power) )can be used.
- As the special values , Napier's constant "E" and Pi "Pi"(the ratio of circumference to diameter) can be used too.
*** ask [#b9a84175]
- In describing formula as guard condition, these (',-,arithmetic operators) , the relational operatprs (>,<,<=,>=,=,!=) and the logical operators (!(not),&(and),/\(and),|(or),\/(or)) can be used.
- The evaluation result of formula is boolean value.
** Hierarchy [#oc2bb594]
- Meaning of a HydLa program is a set of trajectories that satisfy  maximal consistent sets of candidate constraint modules sets. 
- Each candidate constraint set must satisfy conditions below.~
-- ∀M1, ∀M2(M1<< M2 ∧ M1 ∈ MS ⇒ M2 ∈ MS) 
-- ∀M(¬(∃S.M << S) ⇒ M ∈ MS) 
*** Equality [#i272cd72]
- The "," operator means that these two constraints(constraint1,constraint2) are equivalent.
>
constriant1 , constraint2
<
*** Superiority [#s5ec52f8]
- The "<<" operator means right-hand side constraint(constraint4) is superior to left-hand side constraint(constraint3)
- If there is contradictions between constraint3 and constraint4, constraint4 is adopted and constraint3 is excluded.
>
constraint3 << constraint4
<
 INIT <=> y = 0 & y' = 0.  // definition of a constraint for the initial state of a ball.
 FALL <=> [](y'' = -10).   // definition of a constraint for falling of the ball.
 BOUNCE(x) <=> [](x- = 0 => x' = -x'-).  // definition of a constraint for bouncing of the ball.
 BALL{FALL << BOUNCE}. // definition of a constraint hierarchy for the ball.

*** Precedence [#x04d90de]
- The "<<" operator has a higher precedence than the "," operator.
- Example:
>
constraint1 , constraint2 , constraint3 << constraint4.
<
- is equal to
>
constraint1 , constraint2 , (constraint3 << constraint4).
<
- not equal to
>
(constraint1 , constraint2 , constraint3) << constraint4.
<
- '''Constraints''' allow conjunctions of constraints and implications.
- The antecedents of implications are called '''guards'''.
- "$\texttt{[]}$" (called '''box''' or '''always''') is a temporal operator which means that the constraint always holds from the time point at which the constraint is enabled.
- A variable name ($\textit{vname}$) starts with a lowercase letter.
- The notation $\textit{vname}′$ means the derivative of $\textit{vname}$, and $\textit{vname}\verb|−|$ means the left-hand limit of $\textit{vname}$.

** Assert [#m5d52a83]
- The condition(ask) is described in the assert sentence.
- The condition(ask) must be always satisfied in the simulation of HydLa program.
- In the condition(ask), the always operator("[]") can't be used. But the condition is always judged for all the time of simulation.
- The condition is judged within simulating time and is not judged over simulating time.
>
ASSERT{ ask }.
<
* Example : Bouncing Particle [#haead636]
- This program is the model that a particle is falling down into floor, bounces at collision of particle and floor and repeat these movement.
- The variable "y" is the position(height) of the particle.
- The floor is at "y=0".
>
~ INIT <=> y=5 & y'=5.
~ FALL <=> [](y'' = -10).
~ BOUNCE <=> [](y- = 0 => y' = -4/5*y'-).
~ 
~ INIT, FALL << BOUNCE.
<
- INIT : The constraint about the beginning value of the particle.
- By "INIT", the position(y) of the particle is 5 and the speed(y') of the particle is 5 at the starting time.
>
INIT <=> y=5 & y'=5.
<
- FALL : The constraint about the falling movement of the particle.
- By "FALL", the acceleration(y'') of particle is -10 in that the time is over 0.
>
FALL <=> [](y'' = -10).
<
- BOUNCE : The constraint about the bouncing movement of the particle
- By "BOUNCE", in that the time is over 0, if the position(y) of the particle become 0, the speed(y') of the particle becomes the value of "-4/5*y'-".
- This is the bouncing movement. And the coefficient of rebound is 4/5.
>
BOUNCE <=> [](y- = 0 => y' = -4/5*y'-).
<
- The core part of HydLa program (constraint hierarchy)
- This part is describing the hierarchy of the constraints(INIT,FALL,BOUNCE).
- BOUNCE is superior than FALL, and INIT is equal to them.
- In other words, when the particle collide with the floor, not FALL but BOUNCE is adopted as the value of the variable y.
>
INIT, FALL << BOUNCE.
<
* Advanced syntax [#k8c62e97]
*** Definition using args [#j660a34c]
- The argument can be used in defining constraint.
- In constraint hierarchy, the constraint is called by applying arguments.
>
constraint_name(arg) <=> constraint_definition .
<
example : Define the constraint that The variables(x,y,z) in constant
>
~ CONST(a) <=> [](a'=0).
~ ...
~ CONST(x),CONST(y),CONST(z),...
<
example : Define the beginning values of the variables(x1,x2,x3) 
>
~ INIT(x,xh,xv) <=> x=xh & x'=xv.
~ ...
~ INIT(x1,1,0),INIT(x2,2,3),INIT(x3,0,10),...
<
example : Define the collision constraint of the particles(x1,x2,x3) in one dimension
>
~ COL(p,q) <=> []( (p- = q-) => p'=q'- & q'=p'- ).
~ ...
~ ... << ( COL(x1,x2),COL(x1,x3),COL(x2,x3) ).
<
*** Subprogram of Constraint Hierarchy [#zd88597b]
- The subprogram(the part of constraint hierarchy) can be used by naming program name.
- The argument can be used too.
- In describing the constraint hierarchy, this subprogram is called.
>
~ program_name { program } .
~ program_name(arg) { program } .
<
example : Make some constraint together.
>
~ INITS { INIT(x1), INIT(x2), INIT(x3) }.  
~ INITS, ...
<
example : Make the hierarchy of two constraint together
>
~ CONSTMOVE { CONST << MOVE }.
~ CONSTMOVE, ...
<
example : Define bouncing program of the particles(y1,y2,y3)
>
~ ...
~ BP(x,h,v) {INIT(x,h,v), FALL(x) << BOUNCE(x)}.
~ ...
~ BP(y1,1,1),BP(y2,2,3),BP(y3,3,5), ...
<
*** Set [#eea12551]
- The set of some variables can be used.
- The syntax of the set is some way.
>
set_name := set .
<
- Example of Defining
>
~ es := {e1, e2, e3, e4}.
~ ten := { i | i in {0..9} }.
~ xten := {x1..x10} .
<
- The calculation of sets
>
~  union := xten or es .
~  intersection := ten and xten .
<
- The element of sets
>
~ set[i] : The i'th element of the "set" (element is start 0)
~ sum(set) : The sum of the "set"
~ |set| : The number of the "set"
<
- Examples:
>
~  { constarint(set[i]) | i in {1..|set|} }
~  { (constarint1(set[i]) , constarint1(set[i]) ) << constraint2(set[i], set[j]) | i in {1..|set|-1} , j in {i+1..|set|} } 
~  { constraint(x) | x in set }
<
*** Special function [#w69ae32d]
- The trigonometric function
>
~ sin(x) 
~ cos(x)
~ tan(x) 
<
- inverse trigonometric function
>
~ asin(x)
~ acos(x)
~ atan(x) 
<
** Declaration of Constraint Hierarchies [#oc2bb594]
- A constraint can be given higher or lower priority than another.
- The declaration $A \mathrel{\texttt{<<}} B$ states that the constraint A is weaker (i.e., of lower priority) than B.  The relation $A \mathrel{\texttt{<<}} B$ is a strict partial order which is irreflexive, transitive and asymmetric.
-If we compose constraints with "$\texttt{,}$" instead of "$\texttt{<<}$", there is ordering between them.
- The operator "$\texttt{<<}$" has a higher precedence than "$,$", that is, $A, B \mathrel{\texttt{<<}} C$  is equivalent to $A, (B \mathrel{\texttt{<<}} C)$.
- The unit of constraints declared with a priority is called a '''module''' or a '''constraint module'''. 
- The meaning of a HydLa program is a set of trajectories that satisfy maximal consistent sets of candidate constraint modules sets at each time point. 
- Each candidate constraint set must satisfy the conditions below:~

\[\forall M_1, M_2((M_1 \ll M_2 \land M_1 \in {MS} \,) \Rightarrow M_2 \in {MS}\,)\]
\[\forall R  (\neg \exists M( R \ll M )  \Rightarrow R \in {MS} \,)\]

** List Comprehension [#eea12551]
- In the modeling of hybrid systems, we often come across necessity to introduce
multiple similar objects.
- HydLa provides list comprehention to describe models with multiple objects.
- A list can be defined by the operator "$\texttt{:=}$", like $\texttt{X := {x0..x9}.}$
- There are two types of lists: priority lists and expression lists.
*** Priority List [#rb9d66d1]
- The first type, priority lists, can be denoted by an extensional form
$\{\textit{MP}_1, \textit{MP}_2, ..., \textit{MP}_n\}$.

-- They also can be denoted intensionally as
$\{\textit{MP} \mid \textit{LC}_1, \textit{LC}_2, ..., \textit{LC}_n\}$.

-- For example, $\{\texttt{INIT(i)}\ |\ \texttt{i in \{1,2,3,4\}}\}$ is equivalent to $\{\texttt{INIT(1)}$, $\texttt{INIT(2)}$, $\texttt{INIT(3)}$, $\texttt{INIT(4)}\}$.
-- If a HydLa program includes declarations of priority lists, the elements of the lists are expanded, that is, a declaration of $\{A, B, C\}$
is equivalent to $A, B, C$.

*** Expression List [#c1744645]
- The second type, expression lists, are lists of arithmetic expressions.
--  We can denote an expression list in an extensional or intensional notation
as well as a priority list.
-- In addition, we can use range expressions of the form $\{\textit{RE} \texttt{..} \textit{RE}\,\}$, where $\textit{RE}$ is an arithmetic expression without variables or an arithmetic expression with a variable whose name terminates with a number such as $\texttt{x0}$ and $\texttt{y1}$.

*** Examples [#b3820221]
- An expression list $\verb|{1*2 + 1..5}|$ is equivalent to $\verb|{3,4,5}|$.
- An expression list $\verb/{j | i in {1,2}, j in {i+1..4}}/$ is equivalent to $\verb|{2,3,4,3,4}|$. 
- An expression list $\verb|{x1..x3}|$ is equivalent to $\verb|{x1,x2,x3}|$.

*** Other Notations [#mc029821]
- The $n$-th $(n > 0)$ element of a list $L$ can be accessed by $L\texttt{[}n\texttt{]}$.
-- The index allows an arbitrary expression that results in an integer.
- The size of a list $L$ is denoted by $\texttt{|}L\texttt{|}$, which can be used as a constant value in a HydLa program.
- $\texttt{sum(}L\texttt{)}$ is a syntactic sugar of the sum of the elements in an expression list $L$

** Built-in Constants and Functions [#jb66d45b]
- Napier's constant "$\texttt{E}$" and the ratio of circumference to diameter "$\texttt{Pi}$" can be used as constant values.
- The following mathematical functions are available.  Note that $\texttt{Sqrt(}x\texttt{)}$ and $\texttt{Exp(}x\texttt{)}$ are missing because they can be expressed as $x\verb|^(1/2)|$ and $\verb|E^|x$, respectively.

\begin{align}
&\texttt{Log(}x\texttt{)}\\
&\texttt{Sin(}x\texttt{)},  \texttt{Cos(}x\texttt{)}, 
\texttt{Tan(}x\texttt{)},    \texttt{Asin(}x\texttt{)}, 
\texttt{Acos(}x\texttt{),}  \texttt{Atan(}x\texttt{)}\\
&\texttt{Sinh(}x\texttt{)}, \texttt{Cosh(}x\texttt{)},
\texttt{Tanh(}x\texttt{)},   \texttt{Asinh(}x\texttt{)}, 
\texttt{Acosh(}x\texttt{)}, \texttt{Atanh(}x\texttt{)}\\
&\texttt{Floor(}x\texttt{)}
\end{align}

- Detailed syntax and semantics can be found in [https://doi.org/10.1007/978-3-030-41131-2_8 this comprehensive paper] and [http://www.ueda.info.waseda.ac.jp/~matsusho/public/dissertation.pdf this PhD thesis].