30 de diciembre de 2020

(Near) total eclipse of December 14, 2020


A few days ago there was a partial eclipse here in Buenos Aires (79% <<<< 100%). It was a total eclipse about 600mi from here, but due to the pandemic and work we could not go to see it.

It was almost at noon. It was weird because everything looked normal but in low light. The sky had the normal light blue color, it was not gray like a cloudy day or reddish like a sunset. Everything had normal coloring, but in low light.

I did not had time to build a homemade camera obscura, but the leaves of the trees form small holes that have the same effect, and you can see the image of the Sun in the shape of a crescent (moon) on the ground. (It is a very strange combination of words.) With the wind the little holes move, appear and disappear, so there are dancing crescents. The effect is very nice.

Photo of shadows during the eclipse.

For comparison, I tried to take a few additional photos three days later at the same time, because it's always good to have something as close to a control group as possible. I didn't find a photo of the previous spot, but I like the it anyway. So here are two photos comparing a nearby site.

Photo of shadows during the eclipse.

 


Photo of shadows during the eclipse.

Eclipse (casi) total del 14 de diciembre de 2020

Hace unos días hubo un eclipse parcial acá en Buenos Aires (79%<<<<100%). Fue un eclipse total a unos 1000km de acá, pero por la pandemia y el trabajo no pudimos ir a verlo.

Fue casi al mediodía. Era raro porque todo se veía normal pero con poca luz. El cielo tenía el color celeste normal, no era gris como un día nublado ni rojizo como en un atardecer. Todo tenía la coloración normal, pero con poca luz.

No llegué a armarme una cámara oscura casera, pero las hojas de los árboles forman pequeños agujeritos que tienen el mismo efecto, y se ven en el suelo la imágen del Sol con forma de media luna. (Es una combinación de palabras muy extraña.) Con el viento los agujeritos se mueven, aparecen y desaparecen, así que hay media lunas danzantes. Es muy lindo el efecto.

 Foto de la sombre durante el eclipse.

Para comparar, saqué otras fotos tres días después a la misma hora, porque siempre es bueno tener lo más parecido a un grupo de control que uno pueda conseguir. No encontré una foto del lugar anterior, pero me gusta cómo salió. Así que estas son dos fotos que comparan un lugar cercano.

Foto de la sombre durante el eclipse.
 

 
Foto del mismo lugar tres días después.

25 de junio de 2020

Equations system with a black rectangle in LaTeX

A friend sent me a file in LaTeX that she had received. When compiling it, one of the equations had a strange black rectangle:
The file was about 20 pages long. After minimizing and minimizing the file, I got this simplified version:

\documentclass[12pt]{article}

\usepackage[table]{xcolor}



\begin{document}

\centering


Some initial text.



\[

  \begin{array}{c}

    \rowcolor{red}

      1 + 2 = 3 \\

    \rowcolor{green}

      1 + 2 = 3 \\

    \rowcolor{blue}

  \end{array}

\]




Some random two pages of text here \\

just to make debugging difficult.



\[

  \left\{

    \begin{array}{rrrrrrr}

       2x &+& y &+& 4z &=& 0\\

        x &+& 6y &+& 7z &=& 0\\

    \end{array}

  \right.

\]



Some final text.



\end{document}


Can you spot the error? In case you can't mentally compile LaTeX, the result is:

Now, is it easier to find the error?

[spoiler alert]

Well, the problem is in the previous table, it has the declaration of the color of the “last” row that does not exist. In the original version, it was a commented row, making it more difficult to spot. Moreover, between one table and the equations system there were one or two pages, making it more difficult to see that the error was actually caused by something that was much earlier than the position where it appeared.
\[

  \begin{array}{c}

    \rowcolor{red}

      1 + 2 = 3 \\

    \rowcolor{green}

      1 + 2 = 3 \\

    \rowcolor{blue}    % <---- the error is here

  \end{array}

\]



The strangest thing is that you get a black rectangle instead of a blue rectangle. I suppose some flag is set that says that there is something interesting in the next cell, but  the color is reset and that is why it is black. I've been looking at the xcolor package code, but my LaTeX-Fu is not strong enough. (It is not even clear to me if this is classified as a bug or not.) And furthermore, there is a workaround that is not to write LaTex with errors.


Bonus: The error is in the first part, so with a trivial change in the second part we can get a matrix or table with a strange black cell.
\begin{center}

  \begin{tabular}{|c|c| c|}

     \hline

      a  &  b  &  c  \\

     \hline

     $1$ & $2$ & $3$ \\

     \hline

  \end{tabular}

\end{center}

Sistema de ecuaciones con un rectángulo negro en LaTeX

Una amiga me pasó un archivo en LaTeX que había recibido. Al compilarlo una de las ecuaciones tenía un extraño rectángulo negro:
El archivo tenía unas 20 páginas. Después de minimizar y minimizar el archivo, llegué a esta versión simplificada:
\documentclass[12pt]{article}

\usepackage[table]{xcolor}



\begin{document}

\centering


Some initial text.



\[

  \begin{array}{c}

    \rowcolor{red}

      1 + 2 = 3 \\

    \rowcolor{green}

      1 + 2 = 3 \\

    \rowcolor{blue}

  \end{array}

\]




Some random two pages of text here \\

just to make debugging difficult.



\[

  \left\{

    \begin{array}{rrrrrrr}

       2x &+& y &+& 4z &=& 0\\

        x &+& 6y &+& 7z &=& 0\\

    \end{array}

  \right.

\]



Some final text.



\end{document}


¿Podés encontrar el error? Por si no podés compilar LaTeX mentalmente, el resultado es:
¿Ahora es más fácil encontrar el error?

[spoiler alert]

Bueno, el problema está en la tabla anterior, tiene declarado el color de la “última” fila que no existe. En la versión original, era una fila comentada, lo que hacía que sea más difícil notarla. Es más, entre una tabla y el sistema de ecuaciones había una o dos páginas, por lo que era más difícil ver que el error en realidad era causado por algo que estaba mucho antes de la posición en la que se veía
\[

  \begin{array}{c}

    \rowcolor{red}

      1 + 2 = 3 \\

    \rowcolor{green}

      1 + 2 = 3 \\

    \rowcolor{blue}    % <---- the error is here

  \end{array}

\]



Lo más extraño es que aparece un rectángulo negro en vez de un rectángulo azul. Supongo que queda seteado un flag de que hay algo interesante en la próxima celda, pero el color se resetea y por eso es negro. Estuve viendo el código del paquete xcolor, pero mi LaTeX-Fu no es lo suficientemente fuerte. (Ni siquiera me queda claro si esto se clasifica como un bug o no.) Y además hay una solución que es no escribir LaTex con errores.


Bonus: El error está en la primera parte, así que con un cambio trivial en la segunda parte podemos obtener una matriz o una tabla con una extraña celda negra.
\begin{center}

  \begin{tabular}{|c|c| c|}

     \hline

      a  &  b  &  c  \\

     \hline

     $1$ & $2$ & $3$ \\

     \hline

  \end{tabular}

\end{center}

30 de abril de 2020

Coquitos for quarantine

We are still in quarantine, but we had a bit of grated coconut and we made coquitos:
  • 200g grated coconut
  • 200g sugar
  • 2 eggs
  • I have no idea how hot the oven was.
We shaped them by hand, so they got with some very nice burnt stripes on the sides.

Coquitos: Some are already missing in the photo

(We tried a second time, but the mixture was very dry and after cooking they crumbled. It is very strange. Maybe it depends on the humidity of the grated coconut?)

Coquitos para la cuarentena

Seguimos de cuarentena, pero teníamos un poco de coco rayado e hicimos coquitos:
  • 200g de coco rayado
  • 200g de azucar
  • 2 huevos
  • No tengo idea qué tan caliente estaba el horno.
Les dimos forma a mano, así que les quedaron a los costados unas rayas quemaditas muy simpáticas.

 Coquitos: En la foto ya faltan algunos

(Probamos una segunda vez, pero la mezcla quedó muy seca y después de cocinarlos se desmenuzaban. Es muy extraño. ¿Quizás dependa de la humedad del coco rayado?) 

30 de marzo de 2020

About the AR$5 bill in Argentina

[Quarantined]

[I should have written this a month ago, because with the Covid-19 quarantine the situation changed a lot, and most of this doesn't make sense now. Anyways, this seems to be a story that deserves to be told and I have some free time.] [We are fine for now. Thanks for asking.]

Once upon a time, during February ...

The effective exchange rate of the (US) dollar is approximately AR$80, so according to the estimate in the article on the AR$1 coin, the AR$2 coin should fall into disuse. (Surprisingly, it took less time than expected.)
This is not a strict rule, but it is a custom in Argentina. Recently (January-February), I was already seeing that we started to round the prices to pay to a multiple of AR$5. For example, if we must be pay AR$102, it was likely that no one would demand the AR$2 coin.


We had AR$5 bills and AR$5 coins in circulation, but the bills were old and they recently were taken out of circulation. They can be exchanged in a bank, but they cannot be used in a business.


The problem is that the amount of coins of AR$5 is approximately 1/4 or 1/5 of the amount of bills! So, when the AR$5 bills stop circulating, nobody had enough AR$5 coins.

If there are no coins ...

The solution is then to use the AR$2 coins and even rummage through the drawers and dust off the AR$1 coins that had already practically fallen into disuse. I think I have seen more coins of AR$1 in the last days (February) than in the last months. In general, when paying the coins are combined to form a multiple of AR$5 because many of the prices of discrete products are already rounded. (Although there are exceptions such as candies that are worth AR$3 and are a problem.)


My proposal (in February) is to stick with Superglue two coins of AR$2 and one coin of AR$1 and get a combo of AR$5. It would be much easier than searching and choosing the coins one by one (although perhaps illegal). However, after a few days, surely someone will replace the middle coin with a fake one to obtain a 40% profit.

[Current situation]

[Due to the current situation, we are trying to do only one or two weekly purchases at the supermarket. It is a large purchase and we pay with a credit card, so nobody cares if there are coins or not.]

Sobre el billete de AR$5 en Argentina

[En cuarentena]

[Debería haber escrito esto hace un mes, porque con lo de la cuarentena por el Covid-19 la situación cambió mucho, y la mayor parte de esto no tiene sentido ahora. Igualmente me parece una historia que merece ser contada y tengo algo de tiempo libre.] [Por ahora estamos bien. Gracias por preguntar.]

Érase una vez, durante el mes de febrero …

El cambio efectivo del (US)dólar está a aproximadamente AR$80, así que siguiendo las estimaciones del artículo sobre la moneda de AR$1, las monedas de AR$2 deberían caer en desuso. (Sorprendentemente tardó menos de lo esperado.)
Esta no es una regla estricta, si no que es una costumbre en Argentina. En el último tiempo (enero-febrero), ya estuve viendo que empezamos a redondear los precios a pagar a un múltiplo de AR$5. Por ejemplo, si había que pagar AR$102, era probable que nadie exigiera la moneda de AR$2.


Teníamos en circulación billetes de AR$5 y monedas de AR$5, pero los billetes estaban medio viejos y recientemente salieron de circulación. O sea que se los puede cambiar en un banco, pero no se los puede usar en un negocio.
¡El problema es que la cantidad de monedas de AR$5 es aproximadamente1/4 ó 1/5 de la cantidad de billetes! Entonces al dejar de circular los billetes de AR$5 nadie tiene suficientes monedas de AR$5.

Si no hay monedas …

La solución es entonces usar las monedas de AR$2 y hasta revolver los cajones y desempolvar las de AR$1 que ya habían caído prácticamente en desuso. Creo haber visto más monedas de AR$1 en los últimos días (de febrero) que en los últimos meses. En general, al pagar las monedas se combinan para formar un múltiplo de AR$5 porque muchos de los precios de productos discretos ya están redondeados. (Aunque hay excepciones como los caramelos que valen AR$3 y son un problema.)
 


Mi propuesta (en febrero) es entonces pegar con La Gotita dos monedas de AR$2 y una moneda de AR$1 y obtener un combo de AR$5. Sería mucho más cómodo que andar buscando y eligiendo las monedas de a una (aunque quizás ilegal). Sin embargo, a los dos días seguro aparece uno que reemplaza la moneda del medio por una trucha para obtener un 40% de ganancia.

[Situación actual]

[Por la situación actual, estamos tratando de hacer sólo una o dos compras semanales en el supermercado. Es una compra grande y la pagamos con tarjeta de crédito, así que a nadie le importa si hay o no hay monedas.]

4 de febrero de 2020

Quantumly Generated Random Bytes in Racket

Let’s get the bytes

Last week I read about the project Quantum RNG for OpenQu that is a “quantum random numbers as a service”. The idea is to use it to get some random numbers in Racket, using the net/hhp-client and json modules.

This function creates a bytestring of length n using the service.

#lang racket

(require net/http-client
         json)

(define (quantum-random-bytes n)
  (define-values (status headers content)
    (http-sendrecv "random.openqu.org"        
                   (string-append "/api/randint"
                                  "?size=" (number->string n)
                                  "&min=0"
                                  "&max=255")))
  (list->bytes (hash-ref (read-json content) 'result)))

(quantum-random-bytes 5) ; ==> #"\2\353<\223\346"
(quantum-random-bytes 5) ; ==> #"\240\200\242\364\25"
(quantum-random-bytes 5) ; ==> #"\201\370\367\32\25"

Other random-bytes functions

For comparison, we can use the crypto-random-bytes function and we also can write our own random-bytes function that uses the build-in pseudorandom number generator.

(require racket/random) ; for crypto-random-bytes
(define (random-bytes n)
  (list->bytes
   (for/list ([i (in-range n)])
    (random 256))))

(random-bytes 5)         ; ==> #"E\31\366\4\333"
(crypto-random-bytes 5)  ; ==> #"b\345\207\315\""
(quantum-random-bytes 5) ; ==> #"\30`\325\3377"

(require file/sha1) ; for bytes->hex-string

(bytes->hex-string (quantum-random-bytes 5)) ; ==> "00b7c4d6db"
(bytes->hex-string (crypto-random-bytes 5))  ; ==> "662b108fd2"
(bytes->hex-string (random-bytes 5))         ; ==> "da25419554"

As expected, the result of all of them look like similar random nonsense. But it looks nicer as hexadecimal random nonsense.

The first is deterministic, but it uses the initial time of the program as a seed, so you will get different results in each run. Its’s good enough to for a game or simulation, and you can use random-seed to get the same sequence.

The second use the operative system random number generator and is cryptographically secure. The operative system mix many sources of entropy, but all (most?) of them are classic source. (It’s like rolling a dice, it’s difficult to predict but it’s not truly random.)

The third uses a quantum system to produce the random numbers. These numbers are truly random (if quantum mechanics is correct). But remember that you can’t use them for a password and other security applications because the server owner may have a copy (or be lying and sending the digits ofpi). Or someone could be wiretapping your internet connection (this use http, not https!).

(Note that this are not qbits. The “q” part is killed in the generation, long before they are sent through the wire.)

I guess you can use it for a nice truly random quantum choice of numbers, like the starting position of a solitaire game. It’s “better” that just shuffling the cards, but probably undistinguishable for the player. For the secure version, you should buy the hardware version (and verify that it works as intended).

Testing the numbers

In a previous article, I used Random Sanity that is a service that does a minimal check of the random numbers. It may have false positives, and it may not detect fake random numbers, so do it’s only useful to detect very bad implementations of (pseudo) random numbers generators.

Using the functions defined in that article to contact the service, we get:

(test-random-bytes (random-bytes 64))         ; ==> #t ;probably
(test-random-bytes (crypto-random-bytes 64))  ; ==> #t
(test-random-bytes (quantum-random-bytes 64)) ; ==> #t
(with-random-seed 1234567890
  (test-random-bytes (random-bytes 64)))      ; ==> #f

The first is almost always true, but it may be false if we all keep trying and sending the numbers created by the pseudorandom number generator. Using the birthday paradox, with 38 persons starting the program in the same second, we have a 50% chance to get a collision. (Or melt the server, whatever happens first.) The last one is false because it is using a fixed seed, and I already tested it and the server detects the collision now.

Note that now that the bytes have been tested, they are even less secure because yet another person has a copy.

Some ideas to try

  • There is an API call to get some bytes in the base64 format. I tried to use it, but I get an error message. It may work later. It may be useful base64-decode.
  • Without any good reason I’m generating a random byte string instead of a single random number. With small modifications, it’s simple to make function that is a replacement of (random n). Note that the max value of the interval in the service may be included in the results, so remember to subtract 1 before sending the request. I don’t know how big can be max.
  • There is another API call to get floating point numbers, which can be used to write a function that is a replacement of (random). Just note that the roundtrip on the network may take longer than tolerable for an interactive program.

Bonus: Another similar service

While looking for more info I found a few similar services, but most of them require some kind of registration. One that is easy to use is the ANU Quantum Random Numbers Server. Let’s use it too:

(define (other-quantum-random-bytes n)
  (define-values (status headers content)
    (http-sendrecv "qrng.anu.edu.au"        
                   (string-append "/API/jsonI.php"
                                  "?length=" (number->string n)
                                  "&type=uint8")))
  (list->bytes (hash-ref (read-json content) 'data)))

(other-quantum-random-bytes 5) ; ==> #"\25\n1\236K"
(other-quantum-random-bytes 5) ; ==> #"\271\375'\272\205"
(other-quantum-random-bytes 5) ; ==> #"\23\362\324\271\\"
(bytes->hex-string (other-quantum-random-bytes 5)) ; ==> "9366b3f8d2"
(test-random-bytes (other-quantum-random-bytes 64)) ; ==> #t

The link to the API is difficult to find, but this server only support int8, int16 and bytes strings in some hexadecimal format. On the other hand, it supports https, but that part is left as an exercise for the reader.