## Monday, 18 June 2018

### Since neither democracy nor authoritarianism really works...

Perhaps representatives should be selected by random number generator as some kind of fair sampling of the population. If the person declines, just draw another one until a suitable number is met.

Never allow a single person to make any decisions, but instead have all decisions made by some set of representatives which are shuffled every now and them. To guarantee a majority decision, always use odd number of representatives.

--

TV-series I've recently enjoyed:

12 Monkeys
The Crossing
Marvels Agents of S.H.I.E.L.D.
Designated Survivor
Helix
Van Helsing
Blacklist

## Friday, 15 June 2018

### It's often better to do nothing at all than to take two steps back an only one step forward

According to the Holographic principle the number of "bits" associated with a horizon (such as the event horizon of a black hole or Hubble horizon of the observable universe where objects recede from us at the speed of light due to the expansion of space and which also limits the patch that is causally connected to us in the cosmos) is proportional to the area of the horizon (in Planck units).

If one assumes the total energy of such patch of cosmos is distributed evenly among the horizon degrees of freedom according to the thermodynamic equipartition theorem, there exists a corresponding force as a result of the tendency of the universe to increase its entropy (second law of thermodynamics). This mechanism may be responsible for both the tradiational forms of gravity and the cosmological constant.

Already a fairly naive calculation finds that the value of the cosmological constant (associated with dark energy) would be in the correct ballpark respect to the observations. If this mechanism is real then there might be no need for any special dark energy.
T = 13.8e9; % current age of the universe (in years)
G = 6.674e-11;
c = 299792458;
hbar = 1.0546e-34;
ly = 9.4607e15; % lightyear (in meters)
lp = sqrt(hbar*G/c^3); % Planck length

R = T*ly % radius of causally connected universe (in meters) or c/H (Hubble horizon)
r = R/lp % radius in Planck lengths
N = pi*r^2 % number of bits associated with the Hubble horizon

% btw. this value of N is approx. 2^407 which when interpreted (kind of) classically
% suggests that no quantum computer with more than 407 ideal qubits will work as expected
% but if these are qubits instead of bits then no such conclusion is true

% Schwarzschild radius of the Hubble sphere: rs = 2*G*M/c^2 =>

M = R*c^2/2/G         % SI units
m = M/sqrt(hbar*c/G); % in Planck units

% [arXiv:1001.0785v1]
% equipartition of energy among the horizon degrees of freedom: 0.5*kT = m/(pi*r^2)

kT = m/(pi*r^2)/0.5

% entropic force F = kT * gradient(N) =>

F = kT*2*pi*r;

% Second Friedmann equation: a''/a = -4*pi*(rho/3 + p) + Lambda/3
% Cosmic expansion: r''/r = F/(mr)

F/(m*r) % ~ 6e-122 so we are in the correct ballpark [arXiv:1105.3105v1]
4/r^2   % m is actually irrelevant if you model the universe this way, but
% you could also just take the directly observed values and arrive at similar lambda

% additionally by combining the Unruh temperature T = a*hbar/(2*pi*c*k),
% Newton's second law F = ma and area of holographic surface A = 4*pi*r^2,
% one arrives at the Newton's law of universal gravitation F = GmM/r^2

## Friday, 8 June 2018

### Some speculation on indeterministic experience in deterministic cosmos

The state of the observable universe is described accoring to the Bekenstein bound by the information contained in less than 10^123 bits (or qubits depending on your preferred interpretation). This particular number makes the corresponding wavefunction of the observable universe 10^123-dimensional (pi*c^3*r^2/G/hbar/log(2)). While that's huge, it's still only finite even if the cosmos itself might be infinite.

For an observer at the very edge of our observable universe, their observable universe is described by a different set of bits compared to ours. As we are still causally connected, we share some of those bits, but not all. Their Hubble sphere (causally connected part of space limited by the expansion of space at the speed of light 13.8 billion light years from here) is different from ours, yet they overlap partially. This is to some degree true for all observers so if one wanted to be poetic, one could say we share reality with other people, but our realities are not the same.

We may speculate that some of the bits constituting the observers Hubble sphere may be changed by accelerating. Or perhaps one should say what constitutes their Hubble sphere can move or change. A kind of corresponding phenomenon is called the Unruh-effect which causes accelerating observers to observe (thermal) radiation in vacuum where none used to be. There are a number of ways to justify this. One is to look at the Minkowski diagram of an accelerating observer and notice that there exists a (Rindler) horizon that separates a causally disconnected region of space from them and this leads to an effect that is essentially the same as Hawking radiation of a black hole. Another way is to consider what would happen to vacuum fluctuations under acceleration and notice they gain energy. Something similar happens in the dynamical Casimir effect.
However, on some very general level one might also think that this sort of radiation originates from outside of their initially causally connected region of space. If this is the case, then it is not surprising that nature of such fluctuations appear indeterministic to the observer.

Quantum indeterminism may be a result of previously causally disconnected information getting mixed into our reality in certain types of phenomena like acceleration. These types of phenomena are closely related to entanglement and according to ER=EPR conjecture the existence of space is basically a result of entanglement. This would suggest that entanglement is also related to expansion of the universe, the cosmological constant and dark energy. It would be kind of nice to get rid of indeterminism and dark energy all at once.

--

https://arxiv.org/pdf/1803.10454.pdf

Finally getting data that might assist with quantum gravity?

--

One may think one culture is superior to others even if it's shit. It's just less shit compared to the others (one is aware of). At least that's what I mostly think. Generally speaking I'm not a big fan of any culture. I'd like to think it's more important that a society is governed by scientific thinking, analytical problem solving and progressive explorative goals which aim to maximize personal freedom, physical well-being and long term sustainability.

Freedom of Speech: The right to tell people what they don't want to hear. Unfortunately this view doesn't seem particularly popular these days. Short of lying about personally harmful information, I'm pretty much in favor of absolute freedom of speech without exceptions.

--

I think it is ok for authors (please let's not call them creators, they are not gods) to ask for money for copies of their works (please let's not devalue these works by calling them content) in order to gain income (the term compensation falsely implies it is a matter of making up for some kind of damages).

— Richard Stallman

--

I wonder if I'd get more done if I were rich... oh well, I guess we'll never know.

## Thursday, 17 May 2018

### Government secrets are a threat to democracy

How PAL television carried color information...

visual = 52e-6;                 % visible line is 52 microseconds
t = linspace(0, visual, 768);   % horizontal
f = 4.43361875e6;               % color carrier

% instead of RGB, intensity Y and color information U and V was transmitted
% coefficients were chosen based on sensitivity of human eye
Y(y, :) = 0.299*R(y, :) + 0.587*G(y, :) + 0.114*B(y, :);
U(y, :) = 0.493*B(y, :) - 0.493*Y(y, :);
V(y, :) = 0.877*R(y, :) - 0.877*Y(y, :);

% Phase Alternating Line
s = (1-2*mod(y,2));

% IQ-modulated color signal was added to the intensity signal
I(y, :) = Y(y, :) + U(y, :).*sin(2*pi*f*t) + s*V(y, :).*cos(2*pi*f*t);

% color could be easily recovered from I
g = sin(2*pi*f*t);
h = cos(2*pi*f*t);
N = 2; % even with N this small the result is rather good
for x = N+1:768-(N+1)
U(y, 1+x) = mean(g(x-N:x+N).*I(y, x-N:x+N));
V(y, 1+x) = mean(sig*h(x-N:x+N).*I(y, x-N:x+N));
end
 Color was added on top of the intensity signal using IQ-modulation of 4.43361875 MHz carrier. Minor artifacts were introduced as a side effect of this mechanism. Mainly visible as color distortions such as the one seen here in the cats whiskers. The checker patter was a result of color carrier and phase alternating lines. Phase alternating lines were a mechanism used to combat phase drifts that would have resulted in distortion of colors.Color TVs mostly removed the pattern carrying the color information on top of the intensity signal by an agressive notch filter (basically removing part of the spectrum), but black and white TVs didn't have such a filter so they suffered from loss of quality in color transmissions. The interesting thing is that black and white recordings which were not designed to record color could still be used to extract the color as all the information was contained in the intensity. The effect is likely a bit exaggerated in this image. Also interlacing has its role to play that isn't captured by this progressive image.
`--`
```
```
 When a cavity forms, the power contained in the sinusoidal signal will get distributed among the available modes of the forming cavity. Depending on when and how fast the cavity formed, the formation could add or remove energy to or from the cavity.
 Even without a proper cavity, changing boundary condition like a moving ("pumped") mirror can cause energy transfer from the force responsible for the change of the boundary to the electromagnetic field. In this simulation the source "vnoise" corresponds to quantum vacuum (power proportional to frequency, represented by 0.5 photons in the figure). The bump corresponds to the power of generated entangled photon pairs. It can more typically be observed in a correlation measurement (symmetrically respect to the half of the pump frequency). This shape of the spectrum is characteristic of quantum noise. The effect is know as the dynamical Casimir effect (creation of entangled photon pair out of vacuum by a moving mirror). It is also essentially the same process as spontaneous parametric down-conversion. Cavities like the ones in parametric amplifiers can significantly enhance the number of generated photons.

## Sunday, 22 April 2018

### Softcore CPU, assembler and xorshift pseudorandom on an FPGA

I thought it might be nice to make some kind of simplistic 32-bit softcore CPU using an FPGA. The most natural opcodes (for me) would correspond to common C operations such arithmetic +, -, *, /, %, =, comparisons (and conditional jumps) <, >, <=, >=, !=, == and bit operations &, |, ^, ~, <<, >>. This is why I decided to call it CCPU. A simple assembler was written using C, a softcore CPU using verilog and a xorshift pseudorandom program using assembler.

 This all put together outputs white noise.
--

0 MOV A, 1     ; this program will do xorshift32
2 MOV B, 0     ; displayed as noise on CCPUs VGA out
4 MOV C, 1
6 MOV D, 13
8 MOV E, 17
10 MOV F, 5
12 MOV H, 256
14 MOV I, 64000
16 SHL G, A, D
17 XOR A, A, G  ; A ^= A << 13
18 SHR G, A, E
19 XOR A, A, G  ; A ^= A >> 17
20 SHL G, A, F
21 XOR A, A, G  ; A ^= A << 5
22 ADD B, B, C  ; B = B + 1
23 STO B, A     ; MEM[B] = A
24 JL B, I, 16  ; if(B==64000) goto 16;
26 JMP 2        ; goto 2;

--

 Lossless Rayleigh scattering (from things smaller than the wavelength of the light) from air makes laser beams visible if you have enough power. Approximately 1:100000 of the beam power will be scattered per meter at this frequency. Redder colors scatter less. This is the same mechanism which is responsible for the sky being blue. I don't know exactly what my power level here is, probably slightly above 50 mW. The beam is rather bright and when focused capable of lighting matches.
--

module xorshift(input clock, output VGA_HS, VGA_VS, VGA_B);

wire cpu_clock;
wire pixel_clock;

/* VGA 640x400 70Hz */
parameter H = 640;  /* width of visible area */
parameter HFP = 16; /* unused time before hsync */
parameter HS = 96;  /* width of hsync */
parameter HBP = 48; /* unused time after hsync */
parameter V = 400;  /* height of visible area */
parameter VFP = 12; /* unused time before vsync */
parameter VS = 2;   /* width of vsync */
parameter VBP = 35; /* unused time after vsync */
reg [9:0] h_cnt;    /* horizontal pixel counter */
reg [9:0] v_cnt;    /* vertical pixel counter */

reg hs, vs, pixel;
reg vmem [320*200-1:0];
reg [15:0] video_counter;

/* horizontal pixel counter */
always@(posedge pclk)
begin
if(h_cnt == H+HFP+HS+HBP-1) h_cnt <= 0;
else h_cnt <= h_cnt + 1;
if(h_cnt == H+HFP) hs <= 0;
if(h_cnt == H+HFP+HS) hs <= 1;
end

/* vertical pixel counter */
always@(posedge pclk)
begin
if(h_cnt == H+HFP)
begin
if(v_cnt == VS+VBP+V+VFP-1) v_cnt <= 0;
else v_cnt <= v_cnt + 1;
if(v_cnt == V+VFP) vs <= 1;
if(v_cnt == V+VFP+VS) vs <= 0;
end
end

/* RAMDAC */
always@(posedge pclk)
begin
if((v_cnt < V) && (h_cnt < H))
begin
if(h_cnt[0] == 1)
video_counter <= video_counter + 1;
pixel <= vmem[video_counter];
end else
begin
if(h_cnt == H+HFP)
begin
if(v_cnt == V+VFP)
video_counter <= 0;
else
if((v_cnt < V) && (v_cnt[0] != 1))
video_counter <= video_counter - 320;
end
pixel <= 0;
end
end

assign VGA_HS = hs;
assign VGA_VS = vs;
assign VGA_B = pixel;
/* VGA */

reg [31:0] mem[255:0];
reg [31:0] D;
reg [31:0] pc;
reg [31:0] cnt;
reg [31:0] r[31:0], data;
reg [7:0] o, a, b, c;
reg pclk, cclk;

initial
begin
pc = 0;
o = 0;
a = 0;
b = 0;
c = 0;
end

always @(posedge clock)
begin
cnt <= cnt + 1;
pclk <= ~pclk; /* 25 MHz */
cclk <= ~cclk;
end

always @(posedge cpu_clock)
begin
D <= mem[pc];
o <= D[31:24];
a <= D[23:16];
b <= D[15:8];
c <= D[7:0];
end

always @(negedge cpu_clock)
begin
data <= mem[pc+1];
case(o)
1:begin /* JMP */
pc <= data;
end
6:begin /* JL */
if(r[a]<r[b])
pc <= data;
else
pc <= pc + 1;
end
8:begin /* MOV */
r[a] <= data;
pc <= pc + 2;
end
11:begin /* STO */
vmem[r[a]] <= r[b];
pc <= pc + 1;
end
12:begin /* SHL */
r[a] <= r[b] << r[c];
pc <= pc + 1;
end
13:begin /* SHR */
r[a] <= r[b] >> r[c];
pc <= pc + 1;
end
17:begin /* XOR */
r[a] <= r[b] ^ r[c];
pc <= pc + 1;
end
r[a] <= r[b] + r[c];
pc <= pc + 1;
end
endcase
end

assign pixel_clock = pclk;
assign cpu_clock = cclk;

endmodule
--
#include <stdio.h>
#include <stdlib.h>

```/* Branching */
#define NOP  0
#define JMP  1
#define JE   2
#define JNE  3
#define JG   4
#define JGE  5
#define JL   6
#define JLE  7
#define MOV  8
#define LDA 10
#define STO 11
/* Logic */
#define SHL 12
#define SHR 13
#define NOT 14
#define AND 15
#define OR  16
#define XOR 17
/* Arithmetic */
int isOpcode(char *opc, char *cmp) {
int i, j = 0;
for(i=0; i<3; i++)
if(opc[i] == cmp[i])
j++;
if(j==3)
return 1;
else
return 0;
}
int main() {
FILE *in = fopen("xorshift.asm", "r");
FILE *out = fopen("ram.bin", "wb");
FILE *outh = fopen("ram.hex", "w");
unsigned char buf[256], nbuf[64], op[3], regs[3];
int i, j, k, line = 0;
while(fgets(buf, 256, in)!=NULL) {
/* find opcode */
for(i=0; i<3; i++)
op[i] = buf[i];
for(i=0; i<64; i++)
nbuf[i] = 0;
i = 3;
j = 0;
while(buf[i]!='\n' && buf[i]!=';') {
if(buf[i]>47 && buf[i]<58)
nbuf[j++] = buf[i];
i++;
}
j = atoi(nbuf);
/* find registers */
i = 3;
k = 0;
while(buf[i]!='\n' && buf[i]!=';') {
if(buf[i]>64 && buf[i]<91)
regs[k++] = buf[i]-'A';
i++;
}
/* handle opcodes */
if(isOpcode(op, "NOP")) {
i = (NOP<<24);
fwrite(&i, 4, 1, out);
printf("%d\tNOP\n", line);
fprintf(outh, "%.8x\n", &i);
line += 1;
}
if(isOpcode(op, "JMP")) {
i = JMP<<24;
fwrite(&i, 4, 1, out);
fwrite(&j, 4, 1, out);
printf("%d\tJMP %d\n", line, j):
fprintf(outh, "%.8x\n", i);
fprintf(outh, "%.8x\n", j);
line += 2;
}
if(isOpcode(op, "JE ")) {
i = (JE<<24)+(regs[0]<<16)+(regs[1]<<8);
fwrite(&i, 4, 1, out);
fwrite(&j, 4, 1, out);
printf("%d\tJE  %c, %c, %d\n", line, regs[0]+'A', regs[1]+'A', j);
fprintf(outh, "%.8x\n", i);
fprintf(outh, "%.8x\n", j);
line += 2;
}
if(isOpcode(op, "JNE")) {
i = (JNE<<24)+(regs[0]<<16)+(regs[1]<<8);
fwrite(&i, 4, 1, out);
fwrite(&j, 4, 1, out);
printf("%d\tJNE %c, %c, %d\n", line, regs[0]+'A', regs[1]+'A', j);
fprintf(outh, "%.8x\n", i);
fprintf(outh, "%.8x\n", j);
line += 2;
}
if(isOpcode(op, "JG ")) {
i = (JG<<24)+(regs[0]<<16)+(regs[1]<<8);
fwrite(&i, 4, 1, out);
fwrite(&j, 4, 1, out);
printf("%d\tJG %c, %c, %d\n", line, regs[0]+'A', regs[1]+'A', j);
fprintf(outh, "%.8x\n", i);
fprintf(outh, "%.8x\n", j);
line += 2;
}
if(isOpcode(op, "JGE")) {
i = (JGE<<24)+(regs[0]<<16)+(regs[1]<<8);
fwrite(&i, 4, 1, out);
fwrite(&j, 4, 1, out);
printf("%d\tJGE %c, %c, %d\n", line, regs[0]+'A', regs[1]+'A',j);
fprintf(outh, "%.8x\n", i);
fprintf(outh, "%.8x\n", j);
line += 2;
}
if(isOpcode(op, "JL ")) {
i = (JL<<24)+(regs[0]<<16)+(regs[1]<<8);
fwrite(&i, 4, 1, out);
fwrite(&j, 4, 1, out);
printf("%d\tJL  %c, %c, %d\n", line, regs[0]+'A', regs[1]+'A', j);
fprintf(outh, "%.8x\n", i);
fprintf(outh, "%.8x\n", j);
line += 2;
}
if(isOpcode(op, "JLE")) {
i = (JLE<<24)+(regs[0]<<16)+(regs[1]<<8);
fwrite(&i, 4, 1, out);
fwrite(&j, 4, 1, out);
printf("%d\tJLE %c, %c, %d\n", line, regs[0]+'A', regs[1]+'A', j);
fprintf(outh, "%.8x\n", i);
fprintf(outh, "%.8x\n", j);
line += 2;
}
if(isOpcode(op, "MOV")) {
i = (MOV<<24)+(regs[0]<<16);
fwrite(&i, 4, 1, out);
fwrite(&j, 4, 1, out);
printf("%d\tMOV %c, %d\n", line, regs[0]+'A', j);
fprintf(outh, "%.8x\n", i);
fprintf(outh, "%.8x\n", j);
line += 2;
}
if(isOpcode(op, "LDA")) {
i = (LDA<<24)+(regs[0]<<16)+(regs[1]<<8);
fwrite(&i, 4, 1, out);
printf("%d\tLDA %c, %c\n", line, regs[0]+'A', regs[1]+'A');
fprintf(outh, "%.8x\n", i);
line += 1;
}
if(isOpcode(op, "STO")) {
i = (STO<<24)+(regs[0]<<16)+(regs[1]<<8);
fwrite(&i, 4, 1, out);
printf("%d\tSTO %c, %c\n", line, regs[0]+'A', regs[1]+'A');
fprintf(outh, "%.8x\n", i);
line += 1;
}
if(isOpcode(op, "SHL")) {
i = (SHL<<24)+(regs[0]<<16)+(regs[1]<<8)+regs[2];
fwrite(&i, 4, 1, out);
printf("%d\tSHL %c, %c, %c\n", line, regs[0]+'A', regs[1]+'A', regs[2]+'A');
fprintf(outh, "%.8x\n", i);
line += 1;
}
if(isOpcode(op, "SHR")) {
i = (SHR<<24)+(regs[0]<<16)+(regs[1]<<8)+regs[2];
fwrite(&i, 4, 1, out);
printf("%d\tSHR %c, %c, %c\n", line, regs[0]+'A', regs[1]+'A', regs[2]+'A');
fprintf(outh, "%.8x\n", i);
line += 1;
}
if(isOpcode(op, "NOT")) {
i = (NOT<<24)+(regs[0]<<16)+(regs[1]<<8);
fwrite(&i, 4, 1, out);
printf("%d\tNOT %c, %c\n", line, regs[0]+'A', regs[1]+'A');
fprintf(outh, "%.8x\n", i);
line += 1;
}
if(isOpcode(op, "AND")) {
i = (AND<<24)+(regs[0]<<16)+(regs[1]<<8)+regs[2];
fwrite(&i, 4, 1, out);
printf("%d\tAND %c, %c, %c\n", line, regs[0]+'A', regs[1]+'A', regs[2]+'A');
fprintf(outh, "%.8x\n", i);
line += 1;
}
if(isOpcode(op, "OR ")) {
i = (OR<<24)+(regs[0]<<16)+(regs[1]<<8)+regs[2];
fwrite(&i, 4, 1, out);
printf("%d\tOR  %c, %c, %c\n", line, regs[0]+'A', regs[1]+'A', regs[2]+'A');
fprintf(outh, "%.8x\n", i);
line += 1;
}
if(isOpcode(op, "XOR")) {
i = (XOR<<24)+(regs[0]<<16)+(regs[1]<<8)+regs[2];
fwrite(&i, 4, 1, out);
printf("%d\tXOR %c, %c, %c\n", line, regs[0]+'A', regs[1]+'A', regs[2]+'A');
fprintf(outh, "%.8x\n", i);
line += 1;
}