Monday, February 1, 2016

Apache Server configuration in Docker with Supervisor

While I was working on configuring Adobe Experience Manager solution for a complex skeleton I faced a problem to create a network composed of many Apache Servers, dispatchers and a load balancer.

To realize this configuration, I decided to create Virtual Machines for each server instance but this will result a failure when resources that are necessary is considered.

So I decided to use Docker instead of Virtual Machines.

Basically Docker is working like a VM but it creates an image that is composed of minimal OS and the required modules. When it is run, it uses the shared system resources(not like dedicated resources for Virtual Machines). When an image is run then it creates a container to run the image inside. It is possible to run the same image with another container which makes it easier to create clones of required services.

Here I'll explain how to create a docker image that has Apache Server configured.

Theory and Application

In theory, you need to create an OS image with the module that you require. To do this there are two ways. One is to create a Docker file and the other is to create the base instance and install the packages on the instance. Here I'll be concentrating on how to do it via a Docker file.

I'll explain the process step-by-step. mainly it is only possible to run one process within a container. For example you can install Apache Server inside the image and run this server within the container but it is not possible to run another process inside this container. There is a way to run more than one process inside the container and it is the Supervisor. With the help of supervisor we will be creating an image that contains both Apache Server and SSH server.

First create a folder to store the necessary files.

Dockerfile Creation:

Inside this folder create a Dockerfile(filename:Dockerfile). This file should contain:
1) State which base OS distribution will be used:
    FROM ubuntu:15.10
2) Docker supervisor is added to the docker file
6) Set environment variables
    ENV NOTVISIBLE "in users profile"
    ENV PATH  $PATH:/usr/local/bin
7) Copy process executable files to bin folder
    COPY httpd-foreground /usr/local/bin/
    RUN apt-get update && apt-get install -y openssh-server apache2 supervisor
3) Create necessary folders for installations:
    RUN mkdir -p /var/lock/apache2 /var/run/apache2 /var/run/sshd /var/log/supervisor
4) Make it possible to connect with root password by changing the initial password
    RUN echo 'root:password' | chpasswd
    RUN sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/' /etc/ssh/sshd_config
*There is a fix for SSH login. please add this line to the Dockerfile:
    RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
5) Copy the configuration files to the image
    COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
8) Expose the required ports
    EXPOSE 22 80
9) Execute the command to run in the container start
    CMD ["/usr/bin/supervisord"]

Create Configuration Files

It is required to create executable file when you consider a docker image creation, so it will be good to create a file to execute Apache Server start script httpd. This file will be a shell script to be executed so shell scripting rules apply. See below:
    #!/bin/bash
    set -e
    rm -f /usr/local/apache2/logs/httpd.pid #Just in case there is a leftover pid file
    exec httpd -DFOREGROUND

Another file required is the one for supervisord configuration. Remember we already initiated the supervisord with a CMD command on the Dockerfile. A sample configuration for supervisord.conf is:
    [supervisord]
    nodaemon=true
    [program:sshd]
    command=/usr/sbin/sshd -D
    [program:apache2]
    command=/bin/bash -c "source /etc/apache2/envvars && exec /usr/sbin/apache2 -DFOREGROUND"

Lastly, when you are going to run Apache server you need to update configuration files.
Also if there exists any modules that doesn't come out of the box modules you need to copy the resources to the apache folders and make the necessary configurations. It is better to store all of these files inside the same folder that we created for the docker image creation.

Build the image and Run the Container

Now you are ready with your folder structure. Here is the commands that you need to execute to create&run this docker instance.

First build the docker image:
    sudo docker build -t docker-apache1 .
[Change the configuration and create another image]
    sudo docker build -t docker-apache2 .
Add the IP addresses to the list of IPs that will be available for access with the command below:
    sudo iptables -I DOCKER -i ext_if ! -s <HOST_IPADDRESS> -j DROP
Enable IP forwarding:
    sudo sysctl net.ipv4.conf.all.forwarding=1
or
    sudo echo 1 > /proc/sys/net/ipv4/ip_forward
Run the docker instances with port forwarding attributes for 80 ports and ssh connectivity on 20:
    sudo docker run -p 22 -p 8080:80 -i docker-apache1
    sudo docker run -p 22 -p 8081:80 -i docker-apache2

Now you can "ps -ef | grep apache" to see your apache servers running in docker containers which are using local resources.

Wednesday, December 30, 2015

Adobe Experience Manager on Ubuntu

I have just installed Ubuntu 15 and now I am going to use it for development environment for Adobe Experience Manager 6.1.

First of all we require to have some basic environmental requirements.

1) JDK installation above 1.7(java version "1.7.0_91")
2) Eclipse SE for Java Developer(eclipse-jee-mars-1-linux-gtk-x86_64.tar.gz)
3) Brackets (Brackets.1.5.Extract.64-bit.deb)

To have JDK installed we can use apt-get:
sudo apt-get install default-jdk

Eclipse is straight forward, just to extract the zip file(if you would like to use Nuna you need to remove .metadata folder from your workspace in case "Install New Software" dialog doesn't open)

For Brackets we need to install 2 libraries first. libgcrypt11_1.5.0-5+deb7u3_amd64 and libgpg-error-dev_1.19-2_amd64 since these libraries are not included in Ubuntu 15 by default.
so download these files and install it with Ubuntu Software Center or compile it by yourself according to the README files included in the zipped folders.

Open the Eclipse and "Install New Software" by adding AEM Dev Tools - https://eclipse.adobe.com/aem/dev-tools/ as a new location.

Prepare maven settings file to include adobe profile. Below profile should be added to the ~/.m2/settings.xml:

Create your AEM project from latest archetype.
You can create your own server from this wizard or you can open your server externally and bind it to your instance. I prefer the second option.

At the end you have your AEM sample project and tools ready.

How to access MacOS files from Ubuntu

Lately, I changed my working OS from MacOS El Capitan to Ubuntu. I extracted my SSD and used is as an external HDD via USB.

I have encountered the problem of accessing data that are stored in the MacOS file system HFS.

Here are the steps that I used to overcome this problem. I haven't tried it but it is possible that the solution applies for different linux systems.

Basically there are 3 steps:
1) Create a temporary admin user
2) Change current users uid from this temporary admin user
3) Enable your user to be visible on login

Here are the list of commands that I have used:

id
sudo adduser tmp
sudo adduser tmp sudo
sudo passwd tmp
[Logout] -> [Login] tmp
sudo usermod -u 501 <username>
[Logout] -> [Login] <username>

Now it is possible to access to the files in your hard drive.



Tuesday, January 6, 2015

Conjunctive Grammars

Introduction

This time we will talk about a strong grammar named as Boolean Grammars which is a derivation of Context-Free Grammars. By introducing set-theoretic intersection and logical negation to Context-Free Grammars, we can form the Boolean Grammars. The last derivation of Context-Free Grammars will be Boolean Grammars which is the last objective of the paper.

According to our studies until now, we leaned that there exists language recognizers and language generators. In this section we are going to make an entrance to the language generators, specifically Context-Free Language generators. The following sections will improve this generators by adding new operators such as conjunction and negation in order.

When a person is capable of understanding whether a sentence is correct or not, he is acting as a  language recognizer. However this is not our concern in this paper. The main objective is to generate  legal sentences, language generating.

The regular languages are closed under a variety of operations that regular languages may be  specified either by regular expressions or by deterministic or Non-Deterministic Finite Automata. These  facts, used singly or in combinations, provide a variety of techniques for showing languages to be  regular.

Theorem 1:
Let L be a regular language. There is an integer n≥1 such that any string w∈ L with |w|≥n can be  rewritten as w = xyz such that y ≠ e, |xy| ≤ n, and xyiz ∈ L for each i ≥ 0.
(This theorem is one of a general class called pumping theorems, because they assert the existence of  certain points in certain strings where a substring can be repeatedly inserted without affecting the  acceptability of the string.)
The problem about regular languages is that they don't accept some specific languages.
Example 1:
Consider a grammar(Context-Free) G=(V,Σ,R,S), where V={S,a,b}, ={a,b} and R={(S→aSb), (S→e)}. A possible derivation of this grammar is
S ⇒ aSb ⇒ aaSbb ⇒ aabb
In the first two st we used the first rule of R and in the last one the second. It is observable that L(G)={anbn | n≥0}. And it can be easily inferred that this language is not regular but it is Context-Free.

Definition 1:
A Context-Free Grammar is a quadruple G = (V,Σ,R,S) where:
  • V is an alphabet,
  • Σ is a finite set of terminal symbols where it is a subset of V,
  • R is a finite set of rules which is a finite subset of (V-Σ)×V*
  • S is the starting symbol where S∈ V-Σ
The members of V-Σ are called as non-terminals. For any A∈V-Σ and u ∈ V*, we write A→Gu whenever (A,u)∈R. For any strings u,v∈V*, we write u ⇒G v if and only if there are strings x,y∈ V*, and A∈V-Σ such that u = xAy, v = xv'y, and A⇒Gv'. The relation ⇒*G is reflexive, transitive closure of ⇒G. The  language generated by G is L(G)={w∈ Σ* | S⇒*Gw}; which means G generates each string in  L(G). With respect to these conditions, a language is said to be Context-Free Language if L=L(G) for  some Context-Free Grammar G.
A language L is said to be a Context-Free Language (CFL) if its grammar is Context-Free. More precisely, it is a language whose words, sentences and phrases are made of symbols and words from a Context-Free Grammar. Usually, CFL is of the form L=L(G).

Theorem 2:
For every Context-Free Grammar G=(Σ,N,P,S) there exists a Pushdown Automata M=(K,Σ,Г,Δ,s,F) that recognizes it, where
  • K is a finite set of states
  • Σ is an alphabet(the input symbols)
  • Г is an alphabet(the stack symbols)
  • s∈ K is the initial state,
  • F⊆K is the set of final states, and(V-Σ)
  • Δ is a finite subset of (K×(Σ∪{e})×Г×(K×Г*).
Pushdown Automata is a very important aspect for Context-Free Grammars because:

Theorem 3:
The class of languages accepted by Pushdown Automata is exactly the class of Context-Free Languages.

Conjunctive Grammars

As in the formal language theory, conjunctive grammars are a class of formal grammars. They extend the Context-Free Grammars with a conjunction operation. Conjunctive Grammars allow implicit disjunction represented by multiple rules for a single non-terminal symbol, which is the only logical connective expressible in Context-Free Grammars. Conjunction can be used, in particular, to specify intersection of languages. A further extension of Conjunctive Grammars known as Boolean Grammars additionally allows explicit negation, which we will consider in the following sections of the paper. The rules of a conjunctive grammar are of the form

A→α1&..&αn
where A is a non-terminal and α1...αm are strings formed of symbols in Σ and N. Informally, such a rule asserts that every string w over Σ that satisfies each of the syntactical conditions represented by α1...αm therefore satisfies the condition defined by A.

Two equivalent formal definitions of the language specified by a conjunctive grammar exist. One definition is based upon representing the grammar as a system of language equations with union, intersection and concatenation and considering its least solution. The other definition generalizes Chomsky's generative definition of the Context-Free Grammars using rewriting of terms over conjunction and concatenation.

Though the expressive means of conjunctive grammars are greater than those of Context-Free Grammars, Conjunctive Grammars retain some practically useful properties of the latter, such as efficient parsing algorithms.

Definition 2:
A Conjunctive Grammar is a quadruple G = (Σ,N,P,S) where:
  • Σ is a finite set of terminal symbols
  • N is a finite set of non-terminal symbols
  • P is a finite set of grammatical rules(productions) which formally defined as an ordered pair (A,{α1...αn}) of a non-terminal and a finite set of strings over Σ∪N and written in the form A→α1&..&αn in which the order of s are fixed.α
  • S is the starting symbol where S∈ N
  • N∩ = Σ∅
Let V = Σ∪N with respect to this we can form V'=V∪{“(”,”&”,”)”}, it is assumed that none of the characters “(“,”&”,”)” are in V.
For each rule A→α1&..&αn ∈ P and for each i (1≤i ≤ n), a pair of the form (A,αi) is called a conjunct; in cases where that will not cause confusion with productions, a conjunct (A,αi) will be denoted as A→αi.

Definition 3:
Let G = (Σ,N,P,S) be a Conjunctive Grammar:
•Any string over V is a conjunctive formula
•If A and B are formulae, then AB is a formula
•If A1...An (n≥1) are formulae, then (A1&..&An) is a formula.

Definition 4:
  • Let G=(Σ,N,P,S) be a Conjunctive Grammar. Define ⇒G as a relation of immediate derivability on the set of conjunctive formulae:A non-terminal can be written by the body of some rule enclosed in parentheses ,i.e. for all s1.s2∈V', and for all A∈ N, if s1As2 is a formula, then for all A→α1&..&αn∈ P :

s1As2⇒Gs1(α1&..&αn)s2
  • Conjunction of several identical terminal strings enclosed in parentheses can be replaced by one such string, i.e. for all s1,s2∈ V'*, for all w∈Σ* and for all 1≤n, if s1(w&...&w)s2 is a formula with n number of w's,then
  s1(w&...&w)s2 ⇒G s1ws2
So let ⇒*G be the reflexive, transitive closure of ⇒G.
By the help of these rules we can reform the rules and compose a smaller version of the grammars which are conjunctive.


Definition 5:
Let G=(Σ,N,P,S) be a grammar and let A be a formula. The language generated by A is a set of all strings over Σ derivable from A:
LG(A) = {w | w∈Σ, A⇒*G w}
The language generated by the grammar is the set of all strings over Σ derivable from its start symbol: L(G)=LG(S). A language L is called a conjunctive, if it is generated by some Conjunctive Grammar. Let L& be the set of all Conjunctive Languages.
Aforementioned, we have Pushdown Automata for Context-Free Languages. As mentioned in Theorem 2, the classes of both Pushdown Automata and Context-Free Languages are the same. There is a similar case for conjunctive grammars but we need to make some clarifications over the grammar because we need a specific Conjunctive Grammar which is in linear normal form to use the automaton which can accept the grammar.

Example 2:
Let's try to define a language {ba2ba4b...ba2n-2ba2nb | n ≥ 0}. This language is has a super-linear growth, which can also be represented as an intersection of two Context-Free Languages. However instead of using a grammar with a single conjunction on top, which would probably require many non-terminals, let us give a more compact solution:

S → Sab&Cb
S → b
A → aA
A → ℇ
C → bCaa
C → aC
C → baa

Every next string ba2bab...ba2n-2ba2n+2b is generated out of the previous string ba2ba4b...ba2n-2ba2nb by right-concatenating twice as many a's as there are b's spread a × the previous string; this behavior is directed by the rule S → SA&Cb, where Sab generates Sa*b and thus adds some number of a's and then b, while the non-terminal C ensures that the number of a's added is correct. The rule S → b forms the induction thesis.

As we saw from the example, if we consider all the strings that a Context-Free Grammar as a set, the set conjunction of two Context-Free Grammar gives us the exact set of the Conjunctive Grammar where both of these Context-Free Grammar rules are satisfied.

With this example it is now obvious that Conjunctive Grammars are more powerful when compared to Context-Free Grammars.

Example 3:
A Conjunctive Grammar for the language {anbncn n | n ≥ 0} :
S → AB&DC
A → aA
A → ℇ
B → bBc
B → ℇ
C → cC
C → ℇ
D → aDb
D → ℇ
It is obvious that A,B,C and D generate the languages {ai i | i ≥ 0},{bjcj j | j ≥ 0},{cl | l ≥ 0} and {akbk k | k ≥ 0}, respectively. Therefore S generates:

{aibjcj | i,j ≥ 0}∩{akbkcl | k,l ≥ 0} = { anbncn | n ≥ 0}

This language can't be implemented by a Context-Free Grammar because we can't count the number of three variables. We can use a version of pumping lemma to prove that this language is not Context-Free .

Theorem 4:
Let G = (Σ,N,P,S) be a Conjunctive Grammar. Let A1...An,B be formulae, let A∈N, let u ∈Σ*. Then,
LG((A1&...&An)) = ∩ nk=1 LG(Ak)
LG(AB) = LG(A) ● LG(B)
LG(A) =∪ Ak→a1∧...∧am∈P LG(a1∧...∧am)
LG(a) = {a}
LG(ℇ) = {ℇ}

This shows that one can obtain a certain system of language equations by using the explicit union, intersection and concatenation. We can refer that there exists a vector of languages as the solution of this system.

Definition 6:
A Conjunctive Grammar is said to be in the linear, if each rule in P is of the form:
  • A → u1B1v1&...& umBmvm (uivi ∈Σ*,Bi∈ N)
  • A → w (w ∈Σ*)
Definition 7:
Let G = (Σ,N,P,S) be a Conjunctive Grammar. A conjunct of the form A → ℇ, where A∈N, is called an epsilon conjunct.
We can for every Conjunctive Grammar an equivalent grammar without epsilon conjuncts.

Theorem 5:
For any Conjunctive Grammar G = (Σ,N,P,S) there exists a Conjunctive Grammar G' = (Σ,N,P',S'), free of epsilon conjuncts such that
L(G') = L(G) \ {ℇ}

Definition 8:
Let G = (Σ,N,P,S) be a Conjunctive Grammar. A conjunct of the form A → B, where A,B∈N is called an unit conjunct.

Lemma 1:
Let G = (Σ,N,P,S) be a Conjunctive Grammar. Let
A→α1&..&αk-1&B&αk&..&αm (m ≥ 1, 1 ≤ k ≤ m, αi∈Σ*)
be some rule for A that contains a unit conjunct.
B→ β1l &..&β1l
...
B→ βr1 &..&βrlk
be all rules for B that do not contain the unit conjunct B → B (βij ≠ B), if A ≠ B, then the rule in Lemma 1 can be replaced with the collection of rules:
A→ α1&..&αk-1&βr1 &..&βrlk&αk&..&αm (1 ≤ i ≤ r)
without altering the language generated by the grammar.
If A=B, then the rule in Lemma 1 may be just removed.

Definition 9: 

A linear Conjunctive Grammar G = (Σ,N,P,S) is said to be in the linear normal form, if each rule in P is of the form
  • A → bB1&..&bBm& C1c&..&Cnc (m+n ≥ 1; A,Bi,Cj ∈ N; b,c∈Σ )
  • A → α(A∈N, α∈Σ)
  • S → ℇ, only if S doesn't appear in right parts of rules
There is a way to convert every Linear Conjunctive Grammar to linear normal form. If one removes all the ℇ and unit conjuncts, cuts the long conjuncts until all of them are of the form A→ α, A→bB and A→ cC and removing the rules with contradicting conjuncts,which clearly can't be used in a successful derivation, the process of converting a linear conjunctive grammar to linear normal form will be finished.

Definition 10:
A treillis automaton is a sex-tuple M=(Σ,Q,I,ℊ,F,e), where:
  • Σ is the input alphabet,
  • Q is a finite nonempty set of states(of processing units),
  • I:Σ→Q is a function that sets the initial states(loads values into the bottom processors),
  • ℊ:Q × Q→Q is the transition function(the function computed by processors),
  • F∈Q is the set of final states(effective in the top processor),
  • e∈{0,1} determines whether ℇ is accepted or rejected.
Given a nonempty string α1...αn (αi∈Σ, n ≥ 1), every node of trellis corresponds to a certain substring α1...αn (1 ≤ i ≤ j ≤ n) of symbols on which its value depends. The value of a bottom node corresponding to one symbol of the input is I(αi); the value of a successor of two nodes is ℊ of the values of these ancestors. Denote the value of a node corresponding to αi...αj as Δ(I(αi...αj))∈Q: here I(αi...αj) is a string of states (the bottom row of the trellis), while Δ denotes the result (a single state) of triangular computation starting from a row of states. By definition :
Δ(I(αi)) = I(αi) and Δ(I(αi,...,αj)) = (Δ(I(ℑαi,..,αj-1 j-1)),Δ(I( αi+1 ,..,αj))).
Now define language generated by M as
L(M) = {w ∈Σ+ | Δ(I(w)) F} {∈∪ℇ | if e = 1}
These relationships such as Context-Free Grammars with Pushdown Automata and Conjunctive Grammars with trellis automaton resembles the relationship between regular expressions and Deterministic Finite Automatas. To be precise, the left sides are for humans and the right sides are for implementations.

References
Conjunctive Grammars, Journal of Automata, Languages and Combinatorics, Alexander Okhotin, 2001
An overview of conjunctive grammars, Alexander Okhotin, 2003
Elements of the Theory of Computation (2nd ed.), H.R. Lewis,C.H. Papadimitriou, 1998

Boolean Grammars

Boolean grammars are a class of formal grammars studied in formal language theory. They extend the basic type of grammars, the Context-Free Grammars, with conjunction and negation operations. Like Context-Free Grammars to conjunctive grammars, Boolean Grammars is a derivation of conjunctive grammars where there is a new operation as negation. Conjunction and negation can be used, in particular, to specify intersection and complement of languages. An intermediate class of grammars known as Conjunctive Grammars allows conjunction and disjunction, but not negation.

A→α1&..&αm&β1&..&βn

where A is a non-terminal, m+n≥1 and α1..αm and β1..βn are strings formed of symbols in Σ and N. Informally, such a rule asserts that every string w over Σ that satisfies each of the syntactical conditions represented by α1..αm and none of the syntactical conditions represented by β1..βn therefore satisfies the condition defined by A.

There exist several formal definitions of the language generated by a Boolean grammar. They have one thing in common: if the grammar is represented as a system of language equations with union, intersection, complementation and concatenation, the languages generated by the grammar must be the solution of this system. The semantics differ in details, some define the languages using language equations, some draw upon ideas from the field of logic programming. However, these nontrivial issues of formal definition are mostly irrelevant for practical considerations, and one can construct grammars according to the given informal semantics. The practical properties of the model are similar to those of conjunctive grammars, while the descriptional capabilities are further improved. In particular, some practically useful properties inherited from Context-Free Grammars such as efficient parsing algorithms, are retained.

Definition 11:
A Boolean Grammar is a quadruple G = (Σ,N,P,S) where:

  • Σ is a finite set of terminal symbols
  • N is a finite set of non-terminal symbols
  • P is a finite set of rules written in the form A→α1&..&αn&¬β1&..&¬βm where (m+n≥1 and αi,βi∈(Σ∪N)*)
  • S is the starting symbol where S∈ N
  • N∩ = Σ∅
For each rule every object like A→αi A→¬βj (1≤i ≤ n, 1≤j ≤m) are called positive and negative conjuncts, respectively. A conjunct with an unknown sign is denoted as A→±ℑ where it can be A→ℑ or A→¬ℑ. We can name the set of all conjuncts as conjuncts(P) and also we can form uconjuncts(P)={ A→ℑ | A→±ℑ∈conjuncts(P)}.

From these definitions we can refer to the conclusion that when there is no negation in a Boolean Grammar, it is only a Conjunctive Grammar. Also it is obvious that if there is no conjunction in a Conjunctive grammar, it is a context free grammar. We will make a conclusion about this hierarchy in the following pages.

Example 4:
Let Σ = {a,b,c} and N = {S,A,C,D,E}, and consider the following st of rules :
S → AD&¬EC
A → aA
A → ℇ
C → cC
C → ℇ
D → bDc
D → ℇ
E → aEb
E → ℇ
This grammar generates the language L = {ambncn | m,n ≥ 0, m ≠ n}.

Indeed, the non-terminals A,C,D and E have only Context-Free rules and hence are assumed to generate the languages a*, c*, {bici | i ≥ 0} and {aibi | i ≥ 0}, respectively, and then the rule for S specifies the language

                               ____________
a* ● {bici | i ≥ 0} ∩ ({/aibi:i≥0)}● cx) = {ambncn | m,n ≥ 0, m ≠ n}

When we omit the negation, the grammar become a Conjunctive Grammar which produces the language {anbncn | n ≥ 0}.

Definition 12:
Let G=(Σ ,N,P,S) be a boolean grammar. The system of language equations associated with G is a system over Σ in variables N={A1,..,An},resolved with respect to these variables and containing the following equations:
                                                                          m             n
Ak =                             ∪                               [  ∩  ai ∩   ∩ bj   ]      (for all Ak ∈A)
               Ak→a1&..&am&¬b1&..&¬bn ∈P              i=1            j=1

vector of languages L=(L1,..,Ln) is a solution of this system if a substitution of  Lk for  Ak for all k turns each equation in this formula into an equality.

Example 5:
The grammar from example 4 has the following system:

              __
S = AD ∩ EC
A = aA {∪ℇ}
C = cC {∪ℇ}
D = bDc {∪ℇ}
E = aEb {∪ℇ}


The unique solution of this system is S = {ambncn | m,n ≥ 0, m ≠ n}, A = a*, C = c*, D = {bici | i ≥ 0}, E = {aibi | i ≥ 0}.

As a result, the logical connectives makes Context-Free Grammars more powerful. Also these logical connectives can be interpreted as explicit set operations. The existence of some automatons like Pushdown and trellis, we can understand if a grammar is in the set of Context-Free or conjunctive. If we need to make a generalization over the three grammars that we achieved in this paper, the outer shell of these grammars is the Boolean Grammars, in the middle shell Conjunctive Grammars are present and in the center there is Context-Free languages as in Figure 1.

The most interesting thing to do about Conjunctive and Boolean Grammars after this introduction can be working on the parsing algorithms and their efficiencies. This topic may be one of the most important points of these kind of grammars. There exists some algorithms, which have been found before both Conjunctive and Boolean Grammars, and they have been introduced and then put into practice with them.

Another possibility to work on is like the Stochastic Context-Free Grammars which is also known as Probabilistic Context-Free grammars can be a good lead to deal with newly introduced Conjunctive and Boolean Grammars.

References
Elements of the Theory of Computation (2nd ed.), H.R. Lewis,C.H. Papadimitriou, 1998
Boolean Grammars. Developments in Language Theory, Alexander Okhotin, 2003
Generalized LR Parsing Algorithm For Boolean Grammars, Alexander Okhotin, 2006

Pushdown Automata(Bonus)

Pushdown Automata Example:
For a Context-Free Language L={wcwR : w ∈{a,b}*}, let M be a Pushdown Automata M=(K,Σ,Г,Δ,s,F) where K={s,f}, Σ={a,b,c},Г={a,b},F={f} and Δ contains:
  1. ((s,a,e),(s,a))
  2. ((s,b,e),(s,b))
  3. ((s,c,e),(s,e))
  4. ((f,a,a),(f,e))
  5. ((f,b,b),(f,e))

Fuzzy MultiCriteria and MultiAttribute Decision Making

According to recent developments in Artificial Intelligence field, Multiple Criteria Decision Making (MCDM) is one of the outstanding and lead off topics in computer science. There exist four distinct groups of methods: the outranking, the value and utility theory based, the multiple objective programming, and group decision and negotiation theory based methods. In this paper Multi-Criteria
and Multi-Attribute Decision Making (MCDM) in stochastic domains is going to be considered.

Since early 1970s Multiple Criteria Decision Making was the forthcoming important and promising field in Computer Science Paradigm. There are many theories and models which are still being used as a basis for Multiple Criteria Decision Making problems in some of the domains. Decision process is obviously older than most of the known science branches. The Aristotelian or Boolean logic is the first approach to solve the decision making problem. The reason for Fuzzy Logics' invention is the missing points in the answers of Boolean Logic. When Zadeh, and a few years later Zimmermann, introduced fuzzy sets into the field, they cleared the way for a new family of methods to deal with problems which had been inaccessible to and unsolvable with standard MCDM techniques.

The discipline of MCDM can be broadly divided into two categories in this respect: Multiple-attribute decision making (MADM), and multipleobjective decision making (MODM). However, often the terms MADM and MCDM are used to mean the same class of category. MADM studies problems where decision space is discrete. That means these problems have a limited number of alternatives and is normally used in problems associated with assessment and selection. Whereas the MODM method concentrates on problems where the alternatives are not predetermined, i.e. MODM assumes continuous solution spaces. In a general way it could be said that MADM selects the best alternative among a finite number, unlike MODM designs the best alternative.

There are four major families of methods in MCDM: (i) the outranking approach (ii) the value and utility theory (iii) the largest group is the interactive multiple objective programming approach with pioneering work done by P.L.Yu, Stanley Zionts, Milan Zeleny, Ralph Steuer and a number of others; the MOLP family has been built around utility theorybased trade offs among objectives, with reference point techniques, ideal points, etc and the models have had a number of features including stochastic and integer variables; (iv) group decision and negotiation theory introduced new ways to work explicitly with group dynamics and with differences in knowledge, value systems and objectives among group members.

The first category contains a number of ways to find a ranking: degree of optimality Hamming distance, comparison function, fuzzy mean and spread, proportion to the ideal, left and right scores, centroid index, area measurement, and linguistic ranking methods. The second category is built around methods which utilize various ways to assess the relative importance of multiple attributes: fuzzy simple additive weighting methods, analytic hierarchy process, fuzzy conjunctive / disjunctive methods, fuzzy outranking methods, and max-min methods.

Lastly, the category with the most frequent contributions is, of course, fuzzy mathematical programming. The approach in this papers practical work is combine first and second category in one application to get better results comparing to individual ones.

Decision Making Process
In reality, from a decision making perspective, we need not be stuck with the alternatives that present themselves to us; in fact, good decision making includes active creation of new and useful alternatives. Moreover, the very process of decision analysis provides an excellent basis for developing creative new alternatives.

Creating a decision model requires three fundamental steps. First is identifying and structuring the values and objectives. Structuring values requires identifying those issues that matter to the decision maker. Simply listing objectives, however, is not enough; we also must separate the values into fundamental objectives and means objectives, and we must specify ways to measure accomplishment of the objectives.

The second step is structuring the elements of the decision situation into logical framework. To do this there exist two tools: influence diagrams and decision trees. These two approaches have different advantages for modeling difficult decisions. Both approaches are valuable and, in fact, complement one another nicely. Used in conjunction with a carefully developed value structure, we have a complete model of the decision that shows all of the decision elements; relevant objectives, decisions to make, uncertainties, and consequences.

The final step is the refinement and precise definition of all of the elements of the decision model. For example we must be absolutely clear on the precise decisions that are to be made and the available alternatives, exactly what the uncertain events are, and how to measure the consequences in terms of the objectives that have been specified. Although many consequences are easily measured on a natural scale, non-quantitative objectives such as increasing health or minimizing environmental impact are more problematic.

The decision making process for a human is easier than programming a computer to make a decision for the given state and conditions. The absurdity of the idea is that the computer needs to be guided to make a decision, but the guidance is not an interactive on time guiding, it is like a forecasting. The rules and definitions must be general and specific at the same time which is possible in some situations.

Before design, we need to think of some facts which can also be used as a guide to design the agent.

Firstly, the agent must be able to operate in uncertain and imprecise conditions. The environment data that agent is going to use is incomplete and uncertain. Moreover it can be changing by time. To cope with it, an agent must consider the situation that when a new event, which is not foreseen, is happened it needs to reconsider the further decision it is going to make.

Secondly, the agent must be able to accomplish the objectives under the circumstances. The agent must be also able to corporate these goals into purposive procedures.

Lastly, the agent must consider multiple effects of the environment with the percepts it has. There may be multiple constraints in the environment that will effect the state of the agent. The major point here is designing an agent that includes both the combination of goal specific strategies and resolution of conflicts between multiple objectives.

According to Zadeh[Fuzzy Sets, 1965], we can talk of fuzzy logic in a narrow sense or in a wide sense. Taken in its narrow sense, fuzzy logic refers to the study of formal logical systems, equipped with syntactic and semantic apparatus, where propositions admit partial degrees of truth. Very few systems of this kind have been proposed in the literature on autonomous robotics, and most occurrences of the expression “fuzzy logic” in this field take it in its wider sense; this sense encompasses any technique based on the theory of fuzzy sets. Loosely speaking, any formalism which is grounded in set theory can be fuzzified by replacing subsets and individual elements by fuzzy sets, and set-theoretic operations by fuzzy operations [Alessandro Saffiotti,The Uses of Fuzzy Logic in Autonomous Robot Navigation, 1997].

The second term we need to clarify is “uncertainty”. Strictly speaking, uncertainty is not a property of information, but rather a property of an agent. An agent may be uncertain about the existence of an object the value of a property, the truth proposition, or the action to perform. We maintain that what is actually meant by this is information which is weak in some respect, thus inducing a state of uncertainty in the agent. Consider an agent in a world which has several obstacles and the goal is finding some special place in the world. “There is an obstacle” is a weak information for the goal. This case can be named as imprecise information.  “The obstacle is in the center” is also weak information. This case is named as vague information. “The obstacles are used to be in this specific location” is an unreliable information. The uncertainty of the information is because of the agent’s percepts. The state of the world is not changing during the agent’s precept gets the information.

One of the good extensions can be a planner based approach. An Iterative Partial Order Planner can be a good start to make this planner-based approach. While IPOP will be definitely perform inefficient for some types of problems that need a probabilistic planner, it also performs considerably well when constrained values are in its range. When the grid world is relatively small, the distribution probability is high and the leaves density is small, we can observe that IPOP performs well enough. The IPOP algorithm can be refined to find the optimal partial order plan in each step by converting the depth first searches in the choose and fail parts of the Partial Order Planning(POP) algorithm but this is one of the classical trade offs between the time and cost.

The IPOP algorithm can be further be analyzed by comparing it with a probabilistic planner such as the BURIDAN planning algorithm which is described in Nicholas Kushmerick, Steve Hanks and Daniel Weld’s “An Algorithm for Probabilistic Least Commitment Planning*” 1994.

References
Fuzzy Multiple Criteria Decision Making, Robert Fuller and Christer Carlsson, 1996
The Uses of Fuzzy Logic in Autonomous Robot Navigation, Alessandro Saffiotti, 1997
Using Fuzzy Logic For Mobile Robot Control, Enrique H. Ruspini, Alessandro Saffiotti and Kurt Konolige, 1999
Artificial Intelligence :A Modern Approach, Stuart Russel and Petar Norvig, 1995
Fuzzy Sets, L.A. Zadeh, 1965
Reflection on What is a Membership Function, Enric Trillas and C. Alsina, 1999

Monday, January 5, 2015

Temporal Logic - Conclusion

In this series, we have concentrated on the model checkers, their syntax and semantics. These model checker systems are widely used by the companies all over the world. There is a great advantage in being able to verify the correctness of computer systems, whether they are hardware, software or a combination. This is most obvious in the case of safety critical systems, but also applies to those that are commercially critical, such as mass-produced chips, mission critical solutions and more. Formal verification methods have quiet recently become usable by industry and there is a growing demand for professionals able to apply them. For an example the chip company Intel has lost millions of dollars because of this type of mistake they made when they have produced Pentium processors with "FDIV" error.

In CTL we can use explicit quantification over paths which gives us more expressive power than LTL. However, LTL allows selecting a range of paths by describing with a formula which CTL can't.

After concentrating on temporal logic, CTL and LTL, we can improve our skills on model checker algorithms and extensions of the systems (CTL and LTL) like trying to omit deadlock situations and inserting the past operators to them after this we can find new base sets of operators for CTL and LTL.

Also probabilistic model checking seems to have potential in the micro and macro economy because these types of approaches(LTL and CTL) can help experts in multiple criteria decision making.

In reality, from a decision making perspective, we need not be stuck with the alternatives that present themselves to us; in fact, good decision making includes active creation of new and useful alternatives. Moreover, the very process of decision analysis provides an excellent basis for developing creative new alternatives.

Creating a decision model requires three fundamental steps. First is identifying and structuring the values and objectives. Structuring values requires identifying those issues that matter to the decision maker. Simply listing objectives, however, is not enough; we also must separate the values into fundamental objectives and means objectives, and we must specify ways to measure accomplishment of the objectives.

For the second step if we use a probabilistic model checker which also uses past operators our decision process can be implemented and verified more easily than before. Because in a simple decision making algorithm one of the important things to implement is to give the current and past data to the agent and making him interpret these values. By the help of the languages CTL and LTL we can do it very easily and efficiently.

Lastly, there exists another system CTL* which is an extension of both CTL and LTL. Both of them are subsets of this system and ,as we can infer, its expressive power is more than both LTL and CTL.

REFERENCES
Logic in Computer Science: Modeling and Reasoning about Systems, Michael Huth & Mark Ryan
An AutomataTheoretic Approach to Automatic Program Verification, Pierre Wolper & Moshe Y. Vardi, 1986
The Model Checker SPIN, Gerard J. Holzmann, 1997
An improvement in Formal Verification, Gerard J. Holzmann & Doron Peled
www.cs.cmu.edu/~modelcheck/

Friday, January 2, 2015

Temporal Logic - Base Set of Operators in CTL


Just like LTL there exists some extra connectives to make the formulas simpler to understand, read and write. In CTL with A and E connectives we had universal and existential quantifiers but it is clear that G and F is also acing as universal and existential quantifiers along a path. So it is expected that we had DeMorgan rules on these connectives:

  ⌝AF⌽ = EG⌝⌽
  ⌝EF⌽ = AG⌝⌽
  ⌝AX⌽ = EX⌝⌽

Others are:

  AFβ = A[⊤Uβ]
  EFβ = E[⊤Uβ]

To find the base set, we first consider that we can implement A with E and E with A. so we only need one of these operators. By the help of the equalities above and the theorem 3.17(Huth&Ryan216) we can infer that to form a base set for CTL we need to have one of {AX,EX} and one of {EG,AF,AU}.
Some Important Features of A Model Checker Just like operating systems a model checker can be deadlocked. To get rid of this there are some features:
  • Safety : There must be only one state in its critical section at a moment.
  • Liveness : If a process wants to go into the critical session it will be permited.
  • Nonblocking : Every process can request to go into its critical session.
  • No Strict Sequencing : There is no strict sequence for a process to be in its critical section.
  • Fairness : A process mustn't stay in its critical section forever.
Also it is clear that both CTL and LTL is based on future. We can include past operators in these systems. For example NuSMV which is a model checker there exists past state operators like Y,S,O and H as 'yesterday', 'since','once','historically'. Also there are past operators for CTL. AY and ES which are not supported by NuSMV.

Friday, December 26, 2014

Types of Temporal Logic - BranchingTime Temporal Logic


Branching time temporal logics' one of the most known type is CTL(Computation Tree Logic). In this type if we treat time as a tree and every path over this tree refers to different possible future.

In CTL we can see some familiar operators like X, U, F and G. These operators also has the same meaning with LTL. In addition to these operators, there exists two important connectives, A “inevitably” and E “possibly”. The difference between LTL and CTL is like the one between propositional logic and predicate logic. After this remark, we should know that the symbols X,F,G,U can't be used without paired by A or E. It is the same way for the reverse.

Semantics and Syntax of Computation-Tree Logic

Huth&Ryan pg211
CTL formulas are interpreted over transition systems. Let μ = (S,→,L) such a model, s∈S and a CTL formula. The definition of whether M,s ⊃ ⌽ holds is recursive on the structure of ⌽, and can be roughly understood as follows:
  • If ⌽ is atomic, satisfaction is determined by L
  • If the top level connective of ⌽ (i.e. the connective occurring topmost in the parse tree of ⌽) is a boolean connective then the satisfaction question is answered by the usual truth table definition and further recursion down ⌽.
  • If the top level connective is an operator beginning A, then satisfaction holds if all paths from s satisfy the 'LTL formula' resulting from removing the A symbol.
  • Similarly, If the top level connective begins with E, then satisfaction holds if all paths from s satisfy the 'LTL formula' resulting from removing the A symbol.
In the last two cases, the result of removing A or E is not strictly an LTL formula, for it may contain further As or Es below. However, these will be dealt with the recursion.

Definition(Huth&Ryan pg211):Let M = (S,→,L) be a model for CTL, s in S, ⌽ a CTL formula. The relation M,s⊃⌽ is defined by structural induction on ⌽.

  • M,s ⊃⊤
  • M,s ⊅ ⊥
  • M,s ⊃ p iff p ∈ L(s)
  • M,s ⊃ ⌝⌽ iff M,s⊅ ⌽
  • M,s ⊃ ⌽1 ∧ ⌽2 iff M,s ⊃ ⌽1 or M,s ⊃ ⌽2
  • M,s ⊃ ⌽1 ∨ ⌽2 iff M,s ⊃ ⌽1 or M,s ⊃ ⌽2 
  • M,s ⊃ ⌽1 → ⌽2 iff M,s ⊅ ⌽1 or M,s ⊃ ⌽2
  • M,s ⊃ AX⌽ iff for all s1 such that s→ s1 we have M,s1 ⊃ ⌽. Thus, EX says 'in some next state'. E is dual to A – in exactly the same way that  Ǝ is dual to ∀ in predicate logic.
  • M,s ⊃ AG⌽ holds iff, for all paths s1 → s2 → ...where s1 equals s, and all si along the path, we have M,si ⊃ ⌽. Mnemonically: for All computation paths beginning in s the property ⌽ holds Globally. Note that 'along all path' includes the path's initial state s.
  • M,s ⊃ EG⌽ holds iff, there is a path s1 → s2 → ... where s1 equals s, and all si along the path, we have M,si ⊃ ⌽. Mnemonically: there exists a path beginning in s such that ⌽ holds Globally.
  • M,s ⊃ AF⌽ holds iff, for all paths s1 → s2 → ... where s1 equals s, and all si there is some s,such that M,si ⊃ ⌽. Mnemonically: for All computation paths beginning in s there will be some future state where ⌽ holds.
  • M,s ⊃ AF⌽ holds iff, for all paths s1 → s2 → ... where s1 equals s, and for some si along the path, we have M,si ⊃ ⌽. Mnemonically: there Exists computation path beginning in s such that ⌽ holds in some Future state.
  • M,s ⊃ A[⌽1U⌽2] holds iff, for all paths s1 → s2 → ... where  s1 equals s, that path satisfies ⌽1U⌽2 i.e. there is some si along the path, such that M,s ⊃ ⌽2, and for each j<i, we have M,s ⊃ ⌽1. Mnemonically: for All computation paths beginning in s satisfy that ⌽1 U ⌽2 holds on it.
  • M,s ⊃ A[⌽1U⌽2] holds iff, there is a path s1 → s2 → ... where  s1 equals s, and that path satisfies ⌽1U⌽2 as specified in 13. Mnemonically: there Exists a computation path beginning in s such that ⌽1U⌽2 holds on it.

Thursday, December 25, 2014

Types of Temporal Logic - LinearTime Temporal Logic

Thinking about temporal logic we can think of too many types. 'time' variable makes us divide these whole into two main part:
• LinearTime logic
• BranchingTime logic

LinearTime Temporal Logic

The naming of this type gives us the clue about the approach. It treats time with states which are going to infinity.
Future can be implemented with this type.
Let's talk about how we can implement future:
*X : short hand for 'next state', it means the state after present state. This is an unary operator.
*F : short hand for 'future', it means some state after present state. This is an unary operator.
*G : short hand for 'future', it means all states after present state. This is an unary operator.
**U : short hand for 'until', it means a until some formula there is another formula true all states after present state. This is a binary operator.
**W : short hand for 'weak until', it means almost same with until with a difference of the second formulas' being true for a period. This is a binary operator.
**R : short hand for 'release', it is the dual of U. This is a binary operator. The formulas are composed of these operators and ⌝(not),⋏(and),⋎(or),→ (implies),⊥(bottom),⊤(top).

Remark: Precedence of unary operators are bigger than binary ones.

Semantics and Syntax of LTL

Let's model LTL as a transition system:
Definition(Huth&Ryan pg178):A transition system M = (S,→,L) is a set of states S endowed with a transition relation → (a binary relation on S), such that every s∈S has some s'∈S with s→s', and a labeling function L:S→P(Atoms).
At this point we need to remark that this definition leads us to a very similar thing like  nondeterministic finite state automatas. Nondeterminism is one of the key points of this approach because there are infinitely many paths(the state sequences) that the checker can try.

Definition(Huth&Ryan pg180): Let M = (S,→,L) be a model and μ=s1→... be a path in M. Whether μ satisfies a LTL formula is defined by the satisfaction relation ⊃ as follows:
  1. μ ⊃ ⊤
  2. μ ⊅ ⊥
  3. μ ⊃ p iff p ∈ L(s)
  4. μ ⊃ ⌝⌽ iff μ⊅⌽
  5. μ ⊃ ⌽1∧⌽2 iff μ ⊃ ⌽1 or μ ⊃ ⌽2 
  6. μ ⊃ ⌽1∨⌽2 iff μ ⊃ ⌽1 or μ ⊃ ⌽2 
  7. μ ⊃ ⌽1→⌽2 iff μ ⊃ ⌽2 whenever μ ⊃ ⌽2 
  8. μ ⊃ X⌽ iff μ2 ⊃ ⌽
  9. μ ⊃ G⌽ iff,  for all i >= 1, μi ⊃ ⌽
  10. μ ⊃ F⌽ iff there is some i >= 1 such that μ1 ⊃ ⌽
  11. μ ⊃⌽Uβ iff there is some i >= 1 such that μ2 ⊃ β and for all j = 1,..., i1 we have μj ⊃ ⌽
  12. μ ⊃ ⌽Uβ iff either there is some i >= 1 such that μ2 ⊃ β and for all j = 1,..., i1 we have μj ⊃ ⌽; or for all k >= 1 we have μk ⊃⌽
  13. μ ⊃ ⌽Uβ iff either there is some i >= 1 such that μ2 ⊃ ⌽ and for all j = 1,..., i1 we have μj ⊃ β; or for all k >= 1 we have μk ⊃ β

After giving out the definition of LTL, we can clearly observe that using LTL we can extend our classical logic understanding. Still our approach is not completed because we need to make sure that every path starting from a specific state must satisfy the formula we are trying to verify. So we can say every execution path starting from a state must accept the same formula.

Base Set of Operators in LTL

Like most of the logical structures in computer science uses some extra operators which can be composed by using other operators to make the syntax easier to read and understand. For example the meaning of p→q has the same meaning with ⌝p⋎q. Another thing that we can consider is duality of the operators. Like “some” and “every” operators in predicate logic.

LTL is one of those logical structures. Let's give out the equivalences between LTL formulas. Same meaning examples:
Fβ=⊤Uβ
Gβ=⊥Rβ

Duality examples:
⌝Gβ=F⌝β and reverse,
⌝(βU⌽)=⌝βR⌝⌽ and reverse,
With the help of this knowledge we can infer that there is a minimum set of operators in LTL.Let's find out that set.
  • Using U we can find formulas that are equal to the ones which we compose with W and R. The solution about these are below:
    • βR⌽=⌝(⌝βU⌝⌽) and βW⌽=⌽R(β(∨)⌽) so that
    • βW⌽=⌝(⌝⌽U⌝(β(∨)⌽)
  • Using W we can find formulas that are equal to the ones which we compose with U and R. The solution about these are below:
    • βU⌽=⌝(⌝βR⌝⌽) and βR⌽=⌽W(β(∧)⌽) so that
    • ⌝(⌝⌽U⌝(β(∨)⌽)=⌝(β∨⌽)W(⌝(⌝(⌝⌽∨⌽)∧⌽)
  • Using R we can find formulas that are equal to the ones which we compose with U and W. The solution about these are below:
    • βR⌽=⌝(⌝βU⌝⌽) and βW⌽=⌽R(β∨⌽) so that
    • βW⌽=⌝(⌝⌽U⌝(β∨⌽)
Lastly we observe that X(next state) is not used for defining or converting an operator to another. This means X is an element of our set for sure. To sum up, we can use one of the operators R,W,U and X to form the base set of LTL where:
  • G for always (globally) 
  • F for eventually (in the future) 
  • R for release 
  • W for weakly until