Thursday, January 17, 2019

Installing z3py

The Z3 Python API requires the following environment variables to be set up.
  • The PATH or LD_LIBRARY_PATH variables needs to poin to the directory containing "libz3.dll" or "libz3.so"
  • The PYTHONPATH environment variable needs to point to the directory that contains "z3/z3.py"
If you obtained the Z3 distribution as part of our binary release zip files, which you unzipped into a directory called "MYZ3", then follow these instructions to update the environment variables:
Windows:
set PATH=%PATH%;MYZ3\bin
set PYTHONPATH=MYZ3\bin\python
Linux:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:MYZ3/bin
export PYTHONPATH=MYZ3/bin/python
On Ubuntu, even if you have installed z3py through `apt install python-z3`, you still need to manually setup the paths as follows:
export LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu
export PYTHONPATH=/usr/lib/python2.7/dist-packages/z3

Sunday, December 30, 2018

Adjusting video/audio sync with ffmpeg

If you need to delay video by 3.84 seconds, use a command like this:
ffmpeg.exe -i "movie.mp4" -itsoffset 3.84 -i "movie.mp4" -map 1:v -map 0:a -c copy "movie-video-delayed.mp4"
If you need to delay audio by 3.84 seconds, use a command like this:
ffmpeg.exe -i "movie.mp4" -itsoffset 3.84 -i "movie.mp4" -map 0:v -map 1:a -c copy "movie-audio-delayed.mp4"
Make sure, that your ffmpeg build is not too old, newer than 2012 will suffice.

Explanation
-itsoffset 3.84 -i "movie.mp4"
Offsets timestamps of all streams by 3.84 seconds in the input file that follows the option (movie.mp4).
-map 1:v -map 0:a
Takes video stream from the second (delayed) input and audio stream from the first input - both inputs may of course be the same file.
A more verbose explanation can be found here:
http://alien.slackbook.org/blog/fixing-audio-sync-with-ffmpeg/

Reference

https://superuser.com/questions/982342/in-ffmpeg-how-to-delay-only-the-audio-of-a-mp4-video-without-converting-the-au

Thursday, August 24, 2017

A note on rational vs regular vs automatic relations

In this post, all relations are over finite words with finite alphabets.

Automatic relations. A regular n-ary relation can is the set of n-tuples recognisable by a DFA over $\Sigma^n$. Hence all words related by a regular relation have the same length. Automatic relations are regular relations augmented with a special symbol $\bot$ that is used to indicate tail spaces. For example, a binary automatic relation $R$ relates two words $w$ and $w'$ iff $(w\bot^n,w'\bot^m)\in R$ for all $n,m\ge 0: |w|+n=|w'|+m$. In this way an automatic binary relation allows for the existence of an infinite sequence $w_0,w_1,...$ with $w_0\ R\ w_1\ R\ w_2...$ and $|w_0|<|w_1|<...$.
Examples. The following binary relations are automatic: lexicographic ordering, bitwise operations on binary strings, rational number ordering, "a subword of" over a unary alphabet, length ordering, and the edge relation of the configuration space of a TM.
Automatic structures. Recall that a structure $A$ is a tuple $(D; R_1, . . . , R_m)$ where $D$ is a non-empty set called the domain and $R_1,...,R_m$ are basic (or atomic) relations on $D$.
Theorem. (Hodgson 1982) The first-order theory of any automatic structure is decidable.
More precisely, there is an algorithm that given a FO formula $\phi(x_1,...,x_n)$ and an automatic structure $A$, produces a DFA $A_\phi$ recognising the tuples $(a_1,...,a_n)$ that satisfies the formula in $A$. This can be shown by induction on the structure of the formula, using the fact that automata recognisable relations are closed under the Boolean operations and the projection operations. This automata construction also indicates a connection between automatic structures and FO-definable structures, namely,
Corollary. A structure first-order definable in an automatic structure is automatic.

Rational & regular relations. Rational relations are language recognised by finite state transducers over alphabet $(\Sigma\cup\{\epsilon\})\times(\Sigma\cup\{\epsilon\}).$ Rational relations can encode computations of TMs. Regular relations are exactly the rational relations that preserve lengths.
Examples. The following relations are rational but not automatic: "a subword of", "a prefix of", etc.
Fact. Determinisation of transducer is not always possible and the result may not be unique. In fact it is undecidable as for whether a rational relation has a deterministic transducer.
Fact. Rational relations are not closed under complementation and intersection.
Fact. A rational relation can be recognised by a finite transducer on $(\Sigma_\epsilon)\times(\Sigma_\epsilon)$.

Resources

1. Uniformization in Automata Theory, Arnaud Carayol
2. Three Lectures on Automatic Structures, Bakhadyr Khoussainov and Mia Minnes.

Wednesday, June 14, 2017

While programs

Fact. Every while program can be simulated by while program with at most one while loop.

Harel's proof using structural induction
Kozen's proof using KAT
Kleene Algebra with Tests (KAT)
Kozen's lecture notes on KAT
Kozen's result about the complexity & decidability of KAT

Wednesday, May 17, 2017

Building a VS2013 C# project in a VS2015+ environment

Q: Warning about missing Nuget packages on compiling
A: Remove the error emitting lines in the csproj files as indicated here.

Q: ArgumentException: XXX.dll doesn't contain any UserControl types on execution
A: Mark the project containing the main program as the StartUp project.

Sunday, February 26, 2017

CTL vs LTL

  • Syntax. A quantifier in a CTL formula are in form of a path quantifier $A,E$ following by a state quantifier $F,X,G,U,W$. A quantifier in an LTL is a combination of state quantifiers.
  • States and paths. A CTL formula $\phi$ is a state formula, meaning that the temporal operators are state-based in structure: the derivation of a given formula is per-state and depends on the derivation of subformulas for subsequent states. For example, computing the set of states satisfying $AG\ φ$ relies on computing the set of states satisfying $φ$.
    In contrast, LTL formula $\psi$ is a path formula: the derivation of a given formula depends on the derivation of subformulas for suffixes of a path.
  • Entailments. We write $M,s \models \phi$ and $M,p \models \psi$ for state $s$ and path $p$. Given a set $I$ of the initial states of $M$, we shall write $M ⊨ φ$ if $M, s ⊨ φ$ for all $s ∈ I$, and write $M ⊨ ψ$ if $M, s ⊨ ψ$ for all paths starting from $I$.
  • LTL and CTL are incomparable. The reset property $AG (EF\ φ)$ (i.e. there is always a possibility that $\phi$ could hold, though it may never hold) cannot be expressed in LTL. The stability property $FG\ φ$ cannot be expressed in CTL.
  • Structure vs traces. CTL can characterize the structure while LTL only characterizes the traces. Consider the following two systems:
    $A:$ $(s_1,s_2),\ (s_1,s_3),\ (s_2,s_4),\ (s_3,s_5),\ (s_4,s_1),\ (s_5,s_1)$
    $B:$ $(s_1,s_2),\ (s_2,s_4),\ (s_2,s_5),\ (s_4,s_1),\ (s_5,s_1)$
    where $L(s_1)=a,\ L(s_2)=L(s_3)=b,\ L(s_4)=c,\ L(s_5)=d$. Both systems have traces $(ab(c+d))^\omega$ and thus cannot be distinguished in LTL. On the other hand, $B$ is a model of $AG(b\Rightarrow EX\ c)$ while $A$ isn't.
  • There is a lot of discussion of the best logic to express properties for software verification. LTL can express important properties for software system modelling (e.g. fairness) when the CTL must have a new semantics to express them. But CTL algorithms are usually more efficient and can use BDD-based algorithms.

    References

    1. Making prophecies with decision predicates
    2. Branching vs. Linear Time: Final Showdown

    Sunday, February 19, 2017

    Selected Topics in Design & Verification

    Model Checking and Synthesis with SMT

    1. Verifying system against LTL spec → checking emptiness for NBW → finding bad lassos in run graph → checking existence of ranking functions → SMT model checking
    2. Synthesizing system from LTL spec → using UF to represent transition relation and iterating through the possible numbers of states ($\le ~|B|^{|B|}$) → SMT model checking
    3. In 1989, Pnueli and Rosner solved the LTL synthesis problem (2EXPTIME-complete): LTL $\phi$ → NBW (~ $2^{|\phi|}$) → DPW (~ $2^{|\phi|^{|\phi|}}$) → solve the game (~ $2^{|\phi|^{|\phi|}}$)

    (DPW: deterministic parity word automata; NBW: nondeterministic Buchi word automata)

    Tuesday, November 8, 2016

    C# performance notes


    • for v.s foreach
      1. for loops on List are a bit more than 2 times cheaper than foreach loops on List.
      2. Looping on Array is around 2 times cheaper than looping on List.
      3. As a consequence, looping on Array using for is 5 times cheaper than looping on List using foreach.
      4. LinkedList only allows foreach loops, as it would take quadratic time to loop a LinkedList through indices.
      5. Looping overheads: for < foreach; Array ~ List < ArrayList < LinkedList
    • Everything stored in an ArrayList is an object. So be careful of the boxing/unboxing overhead.
    • String concatenation overheads are negligible outside loops. 

    Monday, May 9, 2016