Bitbucket in Russia


Bitbucket in Russia fell innocent victim of random wars the russian government is waging in Internet. The connection to Bitbucket was worsening for months and is nearly broken now. I’ve found the currently working solution here (in Russian). It boils down to editing /etc/hosts file, for example

sudo -i nano /etc/hosts

adding the line

and rebooting.

It worked for me, but I am thinking now of making backup repository on Github.


FastMM4 FullDebugMode Setup Guide

  1. Download the latest FastMM4 release; currently it is version 4.992
  2. Copy the precompiled FullDebugMode dll’s from the downloaded archive to the folders where Windows can find them. I recommend to do the following:
    • Manually create ‘c:\Software’ folder (or name the folder as you like);
    • Create ‘c:\Software\DLL’ subfolder (for 32-bit dll’s) and ‘c:\Software\DLL64’ subfolder (for 64-bit dll’s);
    • Add the paths ‘c:\Software\DLL’ and ‘c:\Software\DLL64’ to the system PATH variable (open Start menu, begin typing ‘environment …’ and choose ‘Edit the system environment variables’)
    • Copy ‘FastMM_FullDebugMode.dll’ to ‘c:\Software\DLL’
    • Copy ‘FastMM_FullDebugMode64.dll’ to ‘c:\Software\DLL64’
  3. Create FastMM4 folder; let it be ‘c:\Software\FastMM4’
  4. Copy ‘*.pas’ files and ‘’ from the main folder of the downloaded archive to ‘c:\Software\FastMM4’; do not copy the subfolders of the archive, they are just not needed here
  5. Enable FullDebugMode (open ‘’, find {.$define FullDebugMode} entry and remove the dot, {.$define FullDebugMode} –> {$define FullDebugMode})

Now the system-wide setup is completed, and we can test apps.

Delphi 10.2 Tokyo:

  • Create new console project and open ‘Project Options’ dialog;
  • Select ‘All configurations’ target;
  • Add ‘c:\Software\FastMM4’ to the search path and click ‘OK’.
  • Add ‘FastMM4’ as the first item in the ‘uses’ clause and add a simple memory leak
program Project1;

{$R *.res}


procedure MemLeak;
var P: PByte;

  GetMem(P, 10);

    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
//  Readln;

If you run the app you get FastMM4 error message

Lazarus 1.8.4:

  • Unfortunately FastMM4 does not support FPC on Windows and even a simplest code example does not compile.

Linux Mint 18 and UEFI boot manager


Recently I was installing Linux Mint on a new Acer laptop with UEFI boot manager. The laptop came with preinstalled “Endless OS” which turned out to be useless because of absence of a package manager. I’ve created Linux Mint 18.3 bootable USB using Rufus, and chosen “GPT partition scheme for UEFI”. I did not make any BIOS changes before installation, and the installation procedure worked fine; I’ve chosen “Erase the entire disk” option during installation. After the installation, when I tried to launch the newly installed OS, I’ve got “No Bootable Device” screen. After several “try and error” iterations I came with the following solution:

  • During installation, do not check “Install 3rd party drivers …” option – the drivers will not be installed anyway; they can be installed later using Driver Manager.
  • After the installation is over, boot into BIOS settings (on Acer laptops by pressing F2 key after switching power on) and set the EFI file created during installation as trusted. The procedure is written in much detail here, only in my case the file turned out to be grubx64.efi
  • The system should boot now, but without some drivers. The worst thing in my case appeared after installing Oracle’s Virtual Box – Virtual Box installs it’s own kernel driver, and Virtual Box did not work because the driver did not work. So you need to enable driver installation now, and it is done by disabling “Secure Boot” option in BIOS.

Crosscompiling with Lazarus 1.8 on Linux Mint 18.3


Suppose you installed Lazarus 1.8 on Linux Mint 18.3 as described before and want to build Windows binaries (well we don’t like Windows, but the users do 🙂 ). I’ve found the useful piece of information about crosscompiling here and started to adopt it to my 32-bit Linux system.

The first step is to build and install the crosscompiler. For the demonstration purposes I decided to build Win32 crosscompiler (the Win64 case should not be much different).

Lazarus 1.8 uses FPC version 3.0.4, so to perform the first step open up Terminal and execute following commands:

# Navigate to the fpc source folder.
cd /usr/share/fpcsrc/3.0.4

# Compile the cross-compiler.
sudo make clean all OS_TARGET=win32 CPU_TARGET=i386

# Install the cross-compiler.
sudo make crossinstall OS_TARGET=win32 CPU_TARGET=i386 INSTALL_PREFIX=/usr

# Link the cross-compiler and place the link where Lazarus can see it.
sudo ln -sf /usr/lib/fpc/3.0.4/ppcross386 /usr/bin/ppcross386

Now let us open Lazarus and create a simple GUI project. I dropped a button on the form and written OnClick handler:

procedure TForm1.Button1Click(Sender: TObject);
  ShowMessage('Hello World!');

I created subfolder /Projects/Lazarus/HelloWorldGUI in my home folder and saved the project under the name HelloW. You can build and run the project and see it works.

Now time to configure the project for Win32 crosscompiling. Open Project Options dialog (Ctrl-Shift-F11). You should see this:


Check Build Modes checkbox:


and click the ellipsis button; a new dialog appears:


Click plus button to create a new build mode, and name it Win32:


Now we should tell Lazarus to compile Win32 code for this build mode. Select Config and Target on the left panel and select Win32 as target OS:


Now you can build the project. I simply clicked green Run button and obtained the warning window:


Well I guess one can’t expect to debug Win32 binary on Linux. Still the work was done, and I’ve found HelloW.exe file in the project folder. To be sure I’ve copied the file on 64-bit Windows 10 system, and It Works!


Installing Lazarus 1.8 on Linux Mint 18.3


Yesterday I come across my old 32-bit Celeron laptop with 2Gb memory and broken battery and decided to install Linux on it. First I tried Centos 7.5, then Ubuntu 16.04, and finally settled down on Mint 18.3 Cinnamon which I liked most. After playing a little with the OS I decided to install the brand new Lazarus 1.8. I spent a couple of hours searching for a clear installation guide in Internet; I scanned tons of outdated nonsense before I finally found what I was looking for.

My Linux Mint installation was fresh, and I need not purge it from previous fpc/lazarus installations. So I started from downloading three 32-bit .deb packages from sourceforge.

After downloading my Downloads folder looked so:


The next recommended step is to check hashes of the files. I launched Terminal and changed to Downloads directory:


Now time to install the packages. As recommended in the linked guide, I typed in Terminal

sudo apt install ./fpc_3.0.4-1_i386.deb
sudo apt install ./fpc-src_3.0.4-1_i386.deb
sudo apt install ./lazarus-project_1.8.0.0_i386.deb
sudo apt-mark hold fpc fpc-src lazarus lazarus-project

And that is all! After opening the Cinnamon menu I’ve found this:


Yet another surprise from Delphi compiler


Build and run the following console app:

program ItWorks;



  TTest = record
    FData: Integer;

procedure DoTest(const S: string);

    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);

I tested in Delphi XE and Delphi 10.1 Berlin, it compiles and even works!

CHSH game in detail


CHSH (John Clauser, Michael Horne, Abner Shimony, and Richard Holt) game is another view on the Bell’s inequalities, showing that under the hood our world is not classical. The game is played by Alice and Bob, and proceeds as follows:

  • a referee generates two independent uniformly chosen random bits (x and y, also called “questions”) and sends x bit to Alice and y bit to Bob
  • After receiving the questions, Alice and Bob send their answers back to the referee; an answer is one bit too (a for Alice and b for Bob)
  • Alice and Bob win if x \cdot y = a \oplus b, where \oplus stands for xor operation.

The game is cooperative – Alice and Bob do not play against each other, their goal is to get the highest winning probability together. Before the game starts, Alice and Bob can communicate and decide on the strategy they will use; after the game started, Alice and Bob are not allowed to communicate anymore; Alice doesn’t know what question the referee sent to Bob, and Bob doesn’t know what question the referee sent to Alice.

In the classical world, Alice and Bob have 16 possible deterministic strategies – both Alice and Bob have two possible answers for each of two possible questions, combining them we get 2^2 \cdot 2^2 = 16 possible strategies. Since the probability of x \cdot y = 0 is 75%, it can be easily seen that there exists 75%-winning strategy – Alice and Bob simply ignore the questions and answer identically – either by bit 0 both or by bit 1 both; it seems natural that this is the best strategy, and it is indeed so, as can be formally shown by checking all 16 possible strategies.

In the quantum world, Alice and Bob have additional degree of freedom – before the game starts, they share an entangled bipartite state, for example two-qubit EPR state:

|\Psi_{AB}\rangle = \frac{1}{\sqrt{2}}(|0\rangle_A\otimes|0\rangle_B + |1\rangle_A\otimes|1\rangle_B)

Now, Alice and Bob choose the measurement bases according to the questions they receive from the referee, and answer by measuring their qubits in the chosen bases.

Let us denote the basis vectors as \nu_i(\theta):

|\nu_0(\theta)\rangle = \cos \theta |0\rangle + \sin \theta |1\rangle
|\nu_1(\theta)\rangle = \sin \theta |0\rangle - \cos \theta |1\rangle

Alice uses \theta_{A0} on receiving the question 0, and \theta_{A1} on receiving the question 1; Bob uses \theta_{B0} on receiving the question 0, and \theta_{B1} on receiving the question 1.

If the referee sends questions x = 0, y = 0, Alice and Bob win if they answer identically a = 0, b = 0 or a = 1, b = 1. The correspondent probability of winning (given x = 0, y = 0) is:

P(win|x=0,y=0) =
|\langle_A\nu_0(\theta_{A0})|\otimes\langle_B\nu_0(\theta_{B0})|\Psi_{AB}\rangle|^2 + |\langle_A\nu_1(\theta_{A0})|\otimes\langle_B\nu_1(\theta_{B0})|\Psi_{AB}\rangle|^2

Substituting |\nu_i(\theta)\rangle we get
P(win|x=0,y=0) =
|(\cos\theta_{A0} \langle_A 0| + \sin\theta_{A0} \langle_A 1|) \otimes (\cos\theta_{B0} \langle_B 0| + \sin\theta_{B0} \langle_B 1|)|\Psi_{AB}\rangle|^2 +
|(\sin\theta_{A0} \langle_A 0| - \cos\theta_{A0} \langle_A 1|) \otimes (\sin\theta_{B0} \langle_B 0| - \cos\theta_{B0} \langle_B 1|)|\Psi_{AB}\rangle|^2

Substituting |\Psi_{AB}\rangle we get
P(win|x=0,y=0) =
\frac{1}{2}|\cos\theta_{A0} \cos\theta_{B0} + \sin\theta_{A0} \sin\theta_{B0}|^2 + \frac{1}{2}|\sin\theta_{A0} \sin\theta_{B0} + \cos\theta_{A0} \cos\theta_{B0}|^2

P(win|x=0,y=0) = \cos^2 (\theta_{A0} - \theta_{B0})

The cases x = 0, y = 1 and x = 1, y = 0 are similar to x = 0, y = 0: Alice and Bob win if they answer identically:

P(win|x=0,y=1) =
|\langle_A\nu_0(\theta_{A0})|\otimes\langle_B\nu_0(\theta_{B1})|\Psi_{AB}\rangle|^2 + |\langle_A\nu_1(\theta_{A0})|\otimes\langle_B\nu_1(\theta_{B1})|\Psi_{AB}\rangle|^2 =
|(\cos\theta_{A0} \langle_A 0| + \sin\theta_{A0} \langle_A 1|) \otimes (\cos\theta_{B1} \langle_B 0| + \sin\theta_{B1} \langle_B 1|)|\Psi_{AB}\rangle|^2 +
|(\sin\theta_{A0} \langle_A 0| - \cos\theta_{A0} \langle_A 1|) \otimes (\sin\theta_{B1} \langle_B 0| - \cos\theta_{B1} \langle_B 1|)|\Psi_{AB}\rangle|^2

P(win|x=0,y=1) = \cos^2 (\theta_{A0} - \theta_{B1})

P(win|x=1,y=0) =
|\langle_A\nu_0(\theta_{A1})|\otimes\langle_B\nu_0(\theta_{B0})|\Psi_{AB}\rangle|^2 + |\langle_A\nu_1(\theta_{A1})|\otimes\langle_B\nu_1(\theta_{B0})|\Psi_{AB}\rangle|^2=
|(\cos\theta_{A1} \langle_A 0| + \sin\theta_{A1} \langle_A 1|) \otimes (\cos\theta_{B0} \langle_B 0| + \sin\theta_{B0} \langle_B 1|)|\Psi_{AB}\rangle|^2 +
|(\sin\theta_{A1} \langle_A 0| - \cos\theta_{A1} \langle_A 1|) \otimes (\sin\theta_{B0} \langle_B 0| - \cos\theta_{B0} \langle_B 1|)|\Psi_{AB}\rangle|^2

P(win|x=1,y=0) =\cos^2 (\theta_{A1} - \theta_{B0})

In the last case x = 1, y = 1 Alice and Bob win if they answer differently, so:

P(win|x=1,y=1) =
|\langle_A\nu_0(\theta_{A1})|\otimes\langle_B\nu_1(\theta_{B1})|\Psi_{AB}\rangle|^2 + |\langle_A\nu_1(\theta_{A1})|\otimes\langle_B\nu_0(\theta_{B1})|\Psi_{AB}\rangle|^2=

|(\cos\theta_{A1} \langle_A 0| + \sin\theta_{A1} \langle_A 1|) \otimes (\sin\theta_{B1} \langle_B 0| - \cos\theta_{B1} \langle_B 1|)|\Psi_{AB}\rangle|^2 +
|(\sin\theta_{A1} \langle_A 0| - \cos\theta_{A1} \langle_A 1|) \otimes (\cos\theta_{B1} \langle_B 0| + \sin\theta_{B1} \langle_B 1|)|\Psi_{AB}\rangle|^2=

\frac{1}{2}|\cos\theta_{A1} \sin\theta_{B1} - \sin\theta_{A1} \cos\theta_{B1}|^2 + \frac{1}{2}|\sin\theta_{A1} \cos\theta_{B1} - \cos\theta_{A1} \sin\theta_{B1}|^2

P(win|x=1,y=1) = \sin^2 (\theta_{A1} - \theta_{B1})

Putting it all together:

P(win) = \frac{1}{4}(P(win|x=0,y=0) + P(win|x=0,y=1)+ P(win|x=1,y=0)+ P(win|x=1,y=1)) =
\frac{1}{4}(\cos^2 (\theta_{A0} - \theta_{B0})+\cos^2 (\theta_{A0} - \theta_{B1})+\cos^2 (\theta_{A1} - \theta_{B0})+\sin^2 (\theta_{A1} - \theta_{B1}))

if Alice and Bob choose \{\theta_{A0}=0, \theta_{A1}=\frac{\pi}{4}, \theta_{B0}=\frac{\pi}{8}, \theta_{B1}=-\frac{\pi}{8}\}, then

P(win) = \frac{3}{4} \cos^2 \frac{\pi}{8} + \frac{1}{4} \sin^2 \frac{3\pi}{8}= \cos^2 \frac{\pi}{8} = \frac{1+cos \frac{\pi}{4}}{2}= \frac{1}{2} + \frac{1}{2\sqrt{2}}\approx 0.85355

and we obtain the winning probability above 85%, which is significantly better than classical 75%.