Archive for the Books Category

a very quick Riddle

Posted in Books, Kids, pictures, R with tags , , , , , , on January 22, 2020 by xi'an

A very quick Riddler’s riddle last week with the question

Find the (integer) fraction with the smallest (integer) denominator strictly located between 1/2020 and 1/2019.

and the brute force resolution

for (t in (2020*2019):2021){ 
   a=ceiling(t/2020)
   if (a*2019<t) sol=c(a,t)}

leading to 2/4039 as the target. Note that

\dfrac{2}{4039}=\dfrac{1}{\dfrac{2020+2019}{2}}

Laidlaw [book review]

Posted in Books, pictures, Travel with tags , , , , , , , , , on January 21, 2020 by xi'an

I read William McIlvanney’s Laidlaw [in planes last week] after I saw it recommended as a pre-Rankin novel. Which inspired the whole tartan noir literature. Including Rankin’s books, most obviously. The book is set in 1970’s Glasgow, which sounds rougher and grittier than when I was visiting the West End two decades later. The city is described as dominated by thugs, at least in the popular areas, with ultra-violent men running the criminal world, while still maintaining some Calvinist principles. Especially about the place of women and their abhorrence of homosexuality. Besides the very dark atmosphere of the novel, Laidlaw is one of the least conventional crime novels I have read, with more inner dialogues than conversations (an issue with some Rebus novels!) and a strong dose of metaphysics on the nature of crime and justice, guilt and punishment. The style is also much more elaborated, to the point I often had to re-read sentences (some of which eventually escaped my understanding) and not only for the phonetic rendering of the Glaswegian accents (which is much more readable than Irvine Welsh’s Trainspotting). The intellectual detective, Laidlaw, is sometimes drawn in heavy traits (like, why should he keep books by Kierkegaard or Camus and Unamuno in his drawer of his desk), prone to bouts of depression and migraine, and, like Rebus, facing a disintegrating marriage and an addiction to alcohol. Not to mention smoking as most characters are chain-smoking. (This aspect as well as the need to resort to phone booths sets the novel back in time.) His relations with the force are even worse than Rebus’, as his provocations of more traditional colleagues leave him mostly isolated and poorly appreciated by his superiors.

The central character may actually be Glasgow itself, so much do the characters move around it and add permanent descriptions of the feeling of the place(s). Far from pretty, it oozes fear and poverty, desperation and bigotry, but also some form of social link, strongly separated between sexes. The appalling status of women (at least of the women appearing in the novel) is subtly denounced by the novel, even though in an ambiguous way. All in all, an impressive book (and not “just” a crime novel).

Le Monde puzzle [#1127]

Posted in Books, Kids, R, Statistics with tags , , , , on January 17, 2020 by xi'an

A permutation challenge as Le weekly Monde current mathematical puzzle:

When considering all games between 20 teams, of which 3 games have not yet been played, wins bring 3 points, losses 0 points, and draws 1 point (each). If the sum of all points over all teams and all games is 516, was is the largest possible number of teams with no draw in every game they played?

The run of a brute force R simulation of 187 purely random games did not produce enough acceptable tables in a reasonable time. So I instead considered that a sum of 516 over 187 games means solving 3a+2b=516 and a+b=187, leading to 142 3’s to allocate and 45 1’s. Meaning for instance this realisation of an acceptable table of game results

games=matrix(1,20,20);diag(games)=0
while(sum(games*t(games))!=374){
  games=matrix(1,20,20);diag(games)=0
  games[sample((1:20^2)[games==1],3)]=0}
games=games*t(games)
games[lower.tri(games)&games]=games[lower.tri(games)&games]*
    sample(c(rep(1,45),rep(3,142)))* #1's and 3'
    (1-2*(runif(20*19/2-3)<.5)) #sign
games[upper.tri(games)]=-games[lower.tri(games)]
games[games==-3]=0;games=abs(games)

Running 10⁶ random realisations of such matrices with no constraint whatsoever provided a solution with] 915,524 tables with no no-draws, 81,851 tables with 19 teams with some draws, 2592 tables with 18 with some draws and 3 tables with 17 with some draws. However, given that 10*9=90 it seems to me that the maximum number should be 10 by allocating all 90 draw points to the same 10 teams, and 143 3’s at random in the remaining games, and I reran a simulated annealing version (what else?!), reaching a maximum 6 teams with no draws. Nowhere near 10, though!

an elegant sampler

Posted in Books, Kids, R, University life with tags , , , , , , , on January 15, 2020 by xi'an

Following an X validated question on how to simulate a multinomial with fixed average, W. Huber produced a highly elegant and efficient resolution with the compact R code

tabulate(sample.int((k-1)*n, s-n) %% n + 1, n) + 1

where k is the number of classes, n the number of draws, and s equal to n times the fixed average. The R function sample.int is an alternative to sample that seems faster. Breaking the outcome of

sample.int((k-1)*n, s-n)

as nonzero positions in an n x (k-1) matrix and adding a adding a row of n 1’s leads to a simulation of integers between 1 and k by counting the 1’s in each of the n columns, which is the meaning of the above picture. Where the colour code is added after counting the number of 1’s. Since there are s 1’s in this matrix, the sum is automatically equal to s. Since the s-n positions are chosen uniformly over the n x (k-1) locations, the outcome is uniform. The rest of the R code is a brutally efficient way to translate the idea into a function. (By comparison, I brute-forced the question by suggesting a basic Metropolis algorithm.)

Le Monde puzzle [#1120]

Posted in Books, Kids, pictures, R with tags , , , , on January 14, 2020 by xi'an

A board game as Le weekly Monde current mathematical puzzle:

11 players in a circle and 365 tokens first owned by a single player. Players with at least two tokens can either remove one token and give another one left or move two right and one left. How quickly does the game stall, how many tokens are left, and where are they?

The run of a R simulation like

od=function(i)(i-1)%%11+1
muv<-function(bob){
  if (max(bob)>1){
    i=sample(rep((1:11)[bob>1],2),1)
    dud=c(0,-2,1)
    if((runif(1)<.5)&(bob[i]>2))dud=c(2,-3,1)
    bob[c(od(i+10),i,od(i+1))]=bob[c(od(i+10),i,od(i+1))]+dud
  }
  bob}

always provides a solution

> bob
 [1] 1 0 1 1 0 1 1 0 1 0 0

with six ones at these locations. However the time it takes to reach this frozen configuration varies, depending on the sequence of random choices.

 

the secret Commonwealth [book review]

Posted in Books, Kids, Travel with tags , , , , , , , , , , on January 12, 2020 by xi'an

Now that I have read The secret Commonwealth over the X break, I cannot but wait eagerly for the third volume! The book is indeed quite good, much in the spirit of the first ones in His dark materials than of the previous La belle sauvage. When La belle sauvage was at its core an oniric and symbolic tale floating on the Thames, with some events on the side, The secret Commonwealth on the opposite is much more centred on adventures and quests and a real story (or rather make it three!) and a growing threat, with side philosophical musings. Quite the opposite of the first book, in short. Even the time localisation is reverted. While La belle sauvage was taking place ten years before His dark materials, making Lyra a very young baby, this book takes place ten years later with Lyra a young adult, growing very quickly in maturity through the pages of the book. The two are so incredibly different that they could have almost be written by different authors… The secret Commonwealth is also much more cosmopolitan than its older sibling as both Lyra and Pan leave Oxford, then England to travel through Europe and Middle East towards a most dangerous destination. The central theme of the book is whether or not Reason or Rationalism should guide one’s life. Given the magical realism of the novel, where the soul of each character is expressed as a companion expressed as a particular animal, a marten called Pan (short for Pantalaimon) for Lyra, it is somewhat an easy (easier than in our own World!) plot line to dismiss rationalist thinkers pretending they do no exist. And to paint the philosophers following this route as either shallow and more interested in rethorics (than philosophy) or fake and deluded. Since Lyra reading these authors is the reason for a widening split between her and Pan, I did not find this part the best in the plot, even though it seemed inevitable. But the resulting quest and the “chance” meetings of both central characters are gripping and well-written, as well as deeply poignant. All characters build some depth, esp. compared with La belle sauvage where they were mostly caricatures. As it is very rare that the second volume in a series brings so much pleasure and improvements, I strongly recommend it (even as a start, skipping La belle sauvage !)

the witcher

Posted in Books, Kids, pictures with tags , , , , , , , , , , , , , on January 11, 2020 by xi'an

As I read (some of) Andrzej Sapkowski‘s books, and then watched my son play the derived video game, I took the opportunity of the break to watch the eponymous Netflix series. Which I found quite decent and entertaining, given that the books were not unforgettable masterpieces but enjoyable and well-constructed. The New York Times was quite dismissive in its review of the show, seeing as a cheap copycat of Game of Thrones when the books were written earlier than Martin’s unfinished no-end-logy. The Blaviken battle scene in the first episode is certainly on a par with GoT most fighting moments, while lasting a few seconds. And the actor playing Geralt manages to convey much more in a few grunts than, say, Kit Harington’s permanent cocker spaniel sad face!!! The budget here is clearly not the same as HBO’s investment, with some exterior scenes looking a wee bit bare (just as in the BBC’s rendering of Jonathan Strange & Mr Norrel). But, again, nothing there to dim the appeal of the series (although they could have cut on the definitely gratuitous softporn moments!) and a plot gradually rising from the fragmented time line and the apparently unrelated subplots, which is also a feature of the books, made of short-stories vaguely glued together. I am hence looking for the second season, hoping the GoT curse does not extend to this series. (Tor.com also published a highly critical review of the show. And of the books, which are incidentally not published by Tor!)