Why do we need the score function in reinforcement learning?

Question: I have a hard time grasping the need for policy optimization and say the log kernel trick/score function. Instead of using the score function, why do you not simply optimize for the highest reward and choose $$\pi^*= \max(\text{all actions with discounted rewards})?$$
I am learning about reinforcement learning and have grasped the basics of value and policy iteration. I would appreciate if answers are intuitive (without math, if possible).
Answer:
Instead of using the score function, why do you not simply optimize for the highest reward and choose Policy*= Max(All actions with discounted rewards)?

You do not have the information in order to take that maximum at the start of learning. In order to know the expected return or discounted sum of future rewards, you need to of measured it whilst using an already optimal policy.
Iterating towards this goal with a policy based on best estimates so far, refining those estimates given the current policy (by acting in that policy and sampling results), then refining the policy based on better estimate is essentially how action-value-based methods work, such as Monte Carlo Control, SARSA or Q Learning. These are all RL solvers, but are not always the most efficient for a given problem.
The score function helps to calculate a sampled measure of the gradient of the expected return of a parametric policy with respect to its parameters. Which means you can use it to perform stochastic gradient ascent directly on a policy, increasing its performance (on average) without necessarily needing to know the action values. The REINFORCE algorithm does not use action values at all. However, algorithms which do, such as Actor-Critic, can be better, and still maintain benefits compared to using a pure action-value approach.
Which is better? It depends on the problem. Sometimes it is more efficient to express a policy as a parametric function of the state. A common example of this is when there are many actions, or action space is continuous. Getting action-value estimates for a large number of actions, and then finding the maximising action over them, is computationally expensive. In those scenarios, it will be more efficient to use a policy gradient method and the score function is needed to estimate the gradient.
Another common scenario where a direct policy refinement can be better is when the ideal policy is stochastic. E.g. in scissor/paper/stone game. Expressing this as maximising over action values is not stable - the agent will pick one action, until that is exploited against it, then pick another etc. Whilst an agent using policy gradient and a softmax action choice could learn optimal ratios in an environment like scissor/paper/stone - two such agents competing should converge in theory to the Nash equilibrium of equiprobable actions.
Conversely, sometimes action-value methods will be the more efficient choice. There might be a simpler relationship between optimal action value and state, than between policy and state. A good example of this might be a maze solver (with reward -1 per time step). The mapping between action value and state is just related to the distance to the exit. The mapping between policy and state has no obvious relation to the state, except when expressed as taking the action that minimises that distance.
Comment: I confused the return Gt which is the discouted sum of all the folowing rewards in that episode with R that is the retrun for that state, and the Q-value which is the return of the optimal action under the optimal policy.
Comment: Regarding the difference between the policy optimization and value iteration methods. For me it dawned that policy optimization is like directly parameterizing to the actions with the loss/objective function, while value iteration more parameterises to the value of each state. It is like either parameterize the outcome of what each movement of the N64 controllers does directly while playing Mario Kart, or in the value iteration case parameterize towards the value of each game frame for the objective function.
Comment: Thank you! It explains more, I will look more into how the gradient is sampled to make the policy accent possible. Is the information sampled for the direct policy refinement similar to say a one step TD look ahead, or how do you obtain the gradient for the accent ?
Comment: The simplest sampled policy gradient is the return $G_t$ times discounting factor $\gamma^t$ times the score function or $\gamma^t G_t \nabla_{\theta} ln(\pi(A_t|S_t, \theta))$. You can measure $G_t$ from an episode. The score function is the hard part, as you need to calculate it depending on your parametric function. If you have a specific policy function in mind (e.g. neural network with softmax action choice) and don't know how to do it for that, then I suggest ask a separate question.
Comment: Thanks again :)  And Return Gt is just the score shown from example an atari game? trying to understand it from the basic level and up to the the theory, such as with value iteration and the basic gridworld example. Probably it seems the next thing to do is, look into Maximum likelihood estimation to understand this further.
Comment: The return is the discounted sum of rewards received since time $t$. It might correspond to (the difference in) score in a game.


Entity Framework não edita FK

Question: Estou com algumas dificuldades em um projeto grande, e tentei fazer uma réplica bem simples para postar aqui de forma que alguém possa me ajudar. Uma das dificuldades que estou tendo e de como editar os campos com chave  estrangeira (FK). Tenho três entidades: Veiculo, Marca e Modelo. Como eu não sei como funciona as regras de chave estrangeira, eu não sei como fazer para alterar esses dados corretamente.
Os dados da entidade Veículo eu consigo editar normalmente, mas se eu tentar mudar a Marca ou Modelo que foi cadastrado eu não consigo, o Entity simplesmente não edita os dois campos que fazem relacionamentos com Marca e Modelo. Pesquisei aqui no forum posts de pessoas que tiveram o mesmo problema, mas a solução dada aos problemas não se aplicam ao meu.
No exemplo, estou tentando mudar a Marca=3 e Modelo=6 do veículo de Id=3, mas o Eentity Framework não faz atualiza a Marca e o Modelo:
Como poderia resolver o problema para que funcione?
Modelo

Principal
  class Program
    {
        static void Main(string[] args)
        {
            Veiculo veiculo = new Veiculo()
            {
                VeiculoId = 3,
                Nome = "Carro",
                Marca = new MarcaApplication().ListId(2),
                Modelo = new ModeloApplication().ListId(6)
            };

            VeiculoApplication apVeiculo = new VeiculoApplication();
            apVeiculo.EditTB(veiculo);
        }
    }

Camada Domain
public class Veiculo
{
    public int VeiculoId { get; set; }
    public string Nome { get; set; }
    public Modelo Modelo { get; set; }
    public Marca Marca { get; set; }
}

public class Modelo
{
    public int ModeloId { get; set; }
    public string ModeloDescricao { get; set; }
    public virtual IEnumerable<Veiculo> Veiculos { get; set; }
}

public class Marca
{
    public int MarcaId { get; set; }
    public string MarcaDescricao { get; set; }
    public virtual IEnumerable<Veiculo> Veiculos { get; set; }
}

Camada Application
public class VeiculoApplication
{
    public DBContext db { get; set; }

    public VeiculoApplication()
    {
        db = new DBContext();
    }

    public void AddTB(Veiculo tb)
    {
        db.Veiculos.Add(tb);
        db.SaveChanges();
    }

    public void EditTB(Veiculo tb)
    {
        db.Entry(tb).State = EntityState.Modified;
        db.SaveChanges();
    }
    public IEnumerable<Veiculo> ListAll()
    {
        return db.Veiculos.ToList();
    }
}

public class ModeloApplication
{
    public DBContext db { get; set; }

    public ModeloApplication()
    {
        db = new DBContext();
    }

    public Modelo ListId(int id)
    {
        return db.Modelos.Where(m => m.ModeloId == id).First();
    }

    public IEnumerable<Modelo> ListAll()
    {
        return db.Modelos.ToList();
    }
}

public class MarcaApplication
{
    public DBContext db { get; set; }

    public MarcaApplication()
    {
        db = new DBContext();
    }

    public void AddTB(Marca tb)
    {
        db.Marcas.Add(tb);
        db.SaveChanges();
    }

    public Marca ListId(int id)
    {
        return db.Marcas.Where(m => m.MarcaId == id).First();
    }

    public IEnumerable<Marca> ListAll()
    {
        return db.Marcas.ToList();
    }
}

Classe Veículo Alterada
public class Veiculo
{
    public int VeiculoId { get; set; }
    public string Nome { get; set; }
    public int ModeloId { get; set; }
    [ForeignKey("ModeloId")]
    [Column(Order = 1)]
    public Modelo Modelo { get; set; }

    public int MarcaId { get; set; }
    [ForeignKey("MarcaId")]
    [Column(Order = 2)]
    public Marca Marca { get; set; }
}

Comment: Com o Entity Framework é perfeitamente possível trabalhar em camadas, a forma como o "Cigano" está orientando a fazer é uma forma primitiva de trabalhar que contraria os padrões MVC. Não vi a aplicação de camadas no exemplo, sugiro que leia alguns artigos referente ao assunto no TI Selvagem e no Macoratti. http://www.tiselvagem.com.br/
http://www.macoratti.net/cshp_3c1.htm
http://www.macoratti.net/14/05/aspn_3cam.htm
Comment: Sim, eu vi alguns assuntos relacionados nos exemplos que postou e ajudou bastante. O exemplo do TI Selvagem é muito semelhante ao meu. Obrigada!
Comment: Você verificou as restrições do banco?
Comment: Sim Ivan, eu fiz essa verificação, o banco é gerado via código. Eu procurei em outros fóruns onde tinham pessoas com o mesmo problema, mas as soluções eram diversas, mas todos os exemplos que eu encontrava eram desenvolvidos em camadas de diferentes tipos. O William me passou um artigo que segue o mesmo modelo de camadas que o meu e estou tentando acompanhar o modelo. Você já teve problema semelhante?
Answer: Não vai funcionar porque você está fazendo mal uso do Entity Framework.
Nesta sentença:
Veiculo veiculo = new Veiculo()
{
    VeiculoId = 3,
    Nome = "Carro",
    Marca = new MarcaApplication().ListId(2),
    Modelo = new ModeloApplication().ListId(6)
};

Você está trazendo duas classes de dois contextos diferentes, e usando um terceiro contexto para disparar a atualização:
public void EditTB(Veiculo tb)
{
    db.Entry(tb).State = EntityState.Modified;
    db.SaveChanges();
}

A arquitetura do exemplo está totalmente incorreta. Não sei quem sugeriu isto pra você, mas sistemas feitos em Entity Framework não devem ser encapsulados em "aplicações", justamente porque o contexto tem que observar todas as três entidades, veículo, modelo e marca, envolvidas na atualização.
Ao separar, você cria três contextos que não se comunicam entre si, e que possivelmente devem disparar algum erro quando você verifica o EntityState do objeto dentro do contexto.
Assim sendo, a maneira correta de se trabalhar é da seguinte forma:
class Program
{
    static void Main(string[] args)
    {
        using (DBContext db = new DBContext())
        {
            Veiculo veiculo = new Veiculo()
            {
                VeiculoId = 3,
                Nome = "Carro",
                Marca = db.Marcas.FirstOrDefault(m => m.MarcaId == 2),
                Modelo = db.Modelos.FirstOrDefault(m => m.ModeloId == 6)
            };

            db.Entry(veiculo).State = EntityState.Modified;
            db.SaveChanges();
        }
    }
}

Comment: Não sei de que artigos você fala, mas se houver algum desses aqui, estão todos errados. Sobre este erro, ele quer dizer que você está usando uma chave estrangeira que não existe na tabela original, no caso, `Marca`.
Comment: Eu vi este modelo em artigos e alguns semelhantes a vídeos do Academy Live, nunca deu esse problema, inclusive eu cheguei a postar projetos aqui usando este padrão, isolando o contexto das demais classes passando só a classe modelo. Consegui resolver o problema determinando as chaves estrangeiras, porém, ao incluir a Marca, estou tendo outro erro. A referential integrity constraint violation occurred: The property value(s) of 'Marca.MarcaId' on one end of a relationship do not match the property value(s) of 'Veiculo.MarcaId' on the other end. Vou editar a minha pergunta com as modificações.

Entity Framework não edita FK


How to compute the cost of an mst graph.

Question: I'm working in C, using the igraph library. I need to get the minimum spanning tree of a given graph stores in a igraph_graph_t type (g). Also I have a igraph_vector containing the weight of each edge (w). The following is my call:
<code>igraph_minimum_spanning_tree_prim(&g, &mst, &w)
</code>
How I can get the weight of each edge in the mst graph? All I need is the cost of mst.
Thanks, Guillermo.
Answer: I think you should take the result graph(mst) and sum the weight of the edges.
Comment: I Irakis. Yes. I must sum the weight of the grap. The issue is how I should link the arc of the solution graph with the weight vector. Remember that the weigth vector is ordered following the order of the edges of input grapg. The order of the arc in the mst grapg is different to the arc orthe in the input graph (the graph witch i nidd to calculate the mst)


Does anything non-microtonal resolve to a neutral triad?

Question: I have been recently looking into neutral triads and trying to incorporate them into my music composition. However, there are very little online regarding composing with them. I am trying to use the twelve-tone equal temperament system making an exception only for neutral triads. I have gotten stuck trying to resolve to one within these constraints I have set.
That is why I ask: "Does anything non-microtonal resolve to a neutral triad?"
Comment: Why would there be any limitation on "resolving" to a neutral triad? For example, why can't a 12-TET G7 chord move to a C-neutral chord?
Comment: Why the downvote?
Comment: Is the G7 tuned in equal temperament or 5-limit or 7-limit just intonation, or something else?  How is the neutral third tuned, as the square root of 1.5, as the 7/24th root of 2, or as some just ratio that lies somewhere between 1.2 and 1.25?
Answer: This is sort of a definitional issue; in common parlance, anything that uses notes outside of the standard 12 is "microtonal"*. So no, music can't really resolve to a neutral triad and not be microtonal since a neutral triad is itself always microtonal. That doesn't mean neutral triads are unusable, I'm just making the point that using them will necessarily make your music microtonal.
So what does resolve to a neutral triad? That's a question of personal taste, and there are plenty of resources that would cover common (ahem) approaches towards using neutral chords in compositions. You can write it if it sounds good, and what does "sounds good" really mean anyway? Does G7 sound good resolving to C neutral? That's for the composer to answer, not the theorist.
If you're looking for a sort of modification to traditional western 12-TET music theory that incorporates neutral triads, you'd actually probably be better off looking for a different theory/system entirely that was designed for those chords (or microtones in general). Music of various cultures incorporates the neutral third interval, so maybe check that out. There's also 24-EDO temperaments to explore. Or come to your own understanding of how these chords work musically!
*Most musicians use "microtonal" pretty casually like this, some would even say a piece of music that's tuned a little off of A = 440Hz is microtonal. For me personally, I'd only count it as microtonal if it was possible to notice the different effect of the notes that aren't usually available, but to each their own.
Comment: @phoog yeah, I agree. I probably wouldn't call stuff that only perfect pitch people would recognize microtonal, but if it was presented in a context where that difference could be heard, sure? I don't want to get too far into the weeds there though, it's just a word.
Comment: "I'd only count it as microtonal if it was possible to notice...": This is rather subjective, though.  I know several people, untrained as musicians, who have trouble distinguishing between equal-tempered major thirds and 5-limit just thirds.  Similarly, someone with perfect pitch may hear a difference between two performances that differ only in being tuned 50 cents higher or lower, whereas few people without perfect pitch would be able to unless they heard them one right after the other.


Valores que podem ser inseridos como chave primária

Question: Eu tenho um código próprio da empresa do produto que é formado por duas letras e 4 números (exemplo: XX0000), é aconselhável usar esse código como chave primária ou criar um outra coluna com campo código e colocar unique para esse código?
Answer: Esse código é único e nunca será alterado para cada linha (entidade)? Se for assim é uma boa candidata para chave primária sim. Caso contrário eu sugeriria usar outra, alguma artificial (surrogate), um id de controle interno do banco de dados provavelmente auto-incrementada de alguma forma.
Toda chave primária deve ser obrigatoriamente única (e que não aceite nulos, até porque só poderia aceitar um para ser única mesmo) e idealmente que nunca seja trocada (por isso que CPF é uma chave primária ruim, nada garante que a pessoa terá o mesmo CPF para sempre, imagina e-mail, telefone e coisas do tipo).
Tome cuidado porque muita gente acha que um código nunca será mudado, mas nem sempre isso é verdade, já vi muitas situações que códigos que nunca iam mudar e um dia mudaram. As empresas reestruturam a forma de manipular seus produtos por diversas razões. Esse XX é uma preocupação, porque isso tem cara de ser um classificador e classificações mudam, é raro mas mudam. O problema não é ter letras, o problema é a estabilidade do dado.
Até pode fazer diferente, mas idealmente chaves primárias devem ser sempre crescentes. Tem banco de dados que obriga ser, não é o caso do MySQL.
Dou uma resposta que fala sobre mitos sobres dados.
Coloquei no GitHub para referência futura.
Answer: A chave primária deve ser um campo, ou conjunto deles, que identifiquem o registro.
Se o campo citado por você se enquadra nessa situação, ele poderá ser uma chave primária.
Apenas uma ressalva: este campo no formato XX0000 será representado por um varchar no seu banco. Talvez o uso de um campo numérico para representar a chave primária (uma coluna auto incremento, por exemplo) traga melhor performance, mas teria que ser avaliado. Se assim optar, poderia fazer de seu campo uma unique key para evitar duplicação de valores.


rsync a directory with its own descendant

Question: tl;dr: I want to rsync a directory to its own descendant, and then rsync the said descendant back to the original directory--including deletions and exclusions in both directions.
Before you ask the obvious question, "Why would you want to do that?" or point out how much better another approach would be, this is a business requirement. It's not my choice, and I'm aware of the risks, so just indulge me. I do not intend to justify the approach any further.
Details:
I want to rsync a directory to its own descendant--i.e., a directory "underneath" or "inside" it, like parent to parent/child, for example--and then sync changes to the descendant back to the original directory, e.g., parent/child to parent, including deletions and exclusions in both directions. Visually, I need to do this:
parent -> parent/child
parent <- parent/child

The difficulties are to...

Prevent infinite recursion when going from the ancestor to the descendant
Not delete the source files mid-operation when syncing the descendant back to its ancestor (manifested as "file has vanished" errors)
Respect the exclusions all the while
Answer: There are three parts to the solution. In order...

Exclude the descendant directory path relative to the ancestor, e.g., child when syncing from parent/child
Use the --delete-after flag instead of  --delete
Make all exclusion paths relative to the source, e.g., exclude.txt as opposed to /var/www/parent/exclude.txt

Here's a test script (with some special formatting for nicer output):
#!/usr/bin/env bash

clear

printf "\n\e[33mrsync version:\n"
printf "%s--------------\e[39m\n"

rsync --version | head -n 1
# rsync  version 2.6.9  protocol version 29

rm -r parent

mkdir -p parent

touch parent/original.txt \
      parent/delete-from-child.txt \
      parent/exclude-from-child.txt

printf "\n\e[33mOriginal state:\n"
printf "%s---------------\e[39m\n"

tree -a --noreport -- parent

printf "\n\e[33mrsync to child:\n"
printf "%s---------------\e[39m\n"

printf "rsync --archive \\n      --delete-after \\n      --exclude=exclude-from-child.txt \\n      "$PWD"/parent/ \\n      "$PWD"/parent/child\n\n"
rsync --archive \
      --delete-after \
      --exclude=exclude-from-child.txt \
      "$PWD"/parent/ \
      "$PWD"/parent/child

tree -a --noreport -- parent; echo

printf "\e[33mMake changes:\n"
printf "%s---------------\e[39m\n"

rm parent/child/delete-from-child.txt
printf "rm parent/child/delete-from-child.txt\n"
touch parent/child/create-in-child.txt
printf "touch parent/child/create-in-child.txt\n"
touch parent/child/exclude-from-parent.txt
printf "touch parent/child/exclude-from-parent.txt\n\n"

printf "\e[33mrsync back to parent:\n"
printf "%s---------------------\e[39m\n"

printf "rsync --archive \\n      --delete-after \\n      --exclude=child \\n      --exclude=exclude-from-child.txt \\n      --exclude=exclude-from-parent.txt \\n      "$PWD"/parent/child/ \\n      "$PWD"/parent\n\n"
rsync --archive \
      --delete-after \
      --exclude=child \
      --exclude=exclude-from-child.txt \
      --exclude=exclude-from-parent.txt \
      "$PWD"/parent/child/ \
      "$PWD"/parent

tree -a --noreport -- parent; echo
# Or `find parent -type f; echo`, if you don't have `tree`

printf "%s\n\e[33mFinal comparison:\n"
printf "%s-----------------\e[39m\n"

diff --exclude=child parent parent/child; echo

Output:
rsync version:
--------------
rsync  version 2.6.9  protocol version 29

Original state:
---------------
parent
├── delete-from-child.txt
├── exclude-from-child.txt
└── original.txt

rsync to child:
---------------
rsync --archive
      --delete-after
      --exclude=exclude-from-child.txt
      /var/www/parent/
      /var/www/parent/child

parent
├── child
│   ├── delete-from-child.txt
│   └── original.txt
├── delete-from-child.txt
├── exclude-from-child.txt
└── original.txt

Make changes:
---------------
rm parent/child/delete-from-child.txt
touch parent/child/create-in-child.txt
touch parent/child/exclude-from-parent.txt

rsync back to parent:
---------------------
rsync --archive
      --delete-after
      --exclude=child
      --exclude=exclude-from-child.txt
      --exclude=exclude-from-parent.txt
      /var/www/parent/child/
      /var/www/parent

parent
├── child
│   ├── create-in-child.txt
│   ├── exclude-from-parent.txt
│   └── original.txt
├── create-in-child.txt
├── exclude-from-child.txt
└── original.txt

Final comparison:
-----------------
Only in parent: exclude-from-child.txt
Only in parent/child: exclude-from-parent.txt

Answer: Another approach would be to set up bind mounts and thus make the two trees appear independent, then rsync as normal:
mkdir /mnt/parent
mkdir /mnt/child
mkdir /mnt/empty
mount --bind /path/to/parent/child /mnt/child
mount --bind /path/to/parent /mnt/parent
mount --bind /mnt/empty /mnt/parent/child

Now, when you do
rsync [args] /mnt/parent/. /mnt/child/.

the empty directory /mnt/empty will mask the real /path/to/parent/child directory; /mnt/parent/child will appear empty and will avoid infinite recursion.
When you do
rsync [args] /mnt/child/. /mnt/parent/.

the situation will be similar; /mnt/child/child/ will be empty (since you don't copy anything there in the first place), and /mnt/parent/child/ will also appear empty, so there is no risk of deleting anything from there.
This is perhaps less elegant than @TravisCarden's solution, but possibly more robust.
Comment: How interesting! Unfortunately, I can't count on my particular target audience having access to mount or I would try this, but thanks for the idea!


Conectar via SSH em outra máquina e executar script

Question: Estou automatizando tarefas e sou novo em Python, por isso gostaria da ajuda de vocês pois preciso rodar um script Shell em uma outra máquina e este comando eu preciso dar dentro de um código Python.
Pensei em usar algo como:
 #!/usr/bin/python

 # -*- coding: utf8 -*-
 import subprocess

 subprocess.call('ssh user@host', shell=True)

Mas fica por isso mesmo, pois não sei como implementaria o Login e a Senha (assim como o "yes" da criptografia).
Comment: Acho q vc vai ter que "estudar" um pouco mais. Se vc tem acesso as duas maquinas a melhor coisa a fazer é trabalhar com chaves `rsa` e configurar o arquivo `~/.ssh/config`, assim vc não precisa ficar movimentando senha, nome de usuario e nem mesmo endereço do host, ai para facilitar de vez a sua vida use o [Fabric](http://www.fabfile.org/) e seja feliz.
Comment: Esqueci de mencionar o [plumbum](https://pypi.python.org/pypi/plumbum/), caso vc queira ir pelo caminho aparentemente mais facil.
Answer: Eu imagino que você queira fazer uma conexão SSH  via python. Caso seja isso o módulo pxssh faz exatamente o que você deseja.
Por exemplo, para executar 'ls -l' e para imprimir a saída, você precisa fazer algo assim:
import pxssh
s = pxssh.pxssh()
if not s.login ('localhost', 'myusername', 'mypassword'):
    print "SSH falha no login."
    print str(s)
else:
    print "SSH sucesso no login"
    s.sendline ('ls -l')
    s.prompt()
    print s.before
    s.logout()

Alguns links úteis:
http://dsnra.jpl.nasa.gov/software/Python/site-packages/Contrib/pxssh.html
http://www.noah.org/wiki/pexpect
Comment: Fiz isso o que você falou e usei as chaves rsa. Realmente ajudou muito. A dificuldade agora é executar os comandos linux dentro da máquina que foi acessada. Meu código simples ficou assim:

##############################################
#!/usr/bin/python
# -*- coding: utf8 -*-

import subprocess

subprocess.call('echo Executando Shell dentro do Python', shell=True)
subprocess.call('ssh @', shell=True)
subprocess.call('echo Estou na ', shell=True)
#########################################

Ele acessa a máquina, mas dentro dela não o echo.


The context & motivation for the Tits alternative in combinatorial group theory

Question: The Details:

Definition 1: A class $\mathcal{G}$ of groups satisfies the Tits alternative if for any $G$ in $\mathcal{G}$ either $G$ has a free, non-abelian subgroup or $G$ has a solvable subgroup of finite index.
Example 1: The class of finitely generated linear groups satisfies the Tits alternative.

For my PhD, I plan to establish whether or not the Tits alternative holds for a certain class, $\mathcal{G}_0$ say, of cyclically presented groups. I'm new to this, however, since I'm only a few months into the PhD and I've had to change topics as, already, all of my previous topic has been subsumed by some yet-to-be-published work (as of $6^{\text{th}}$ Feb, $2018$) by someone else.
The Question(s):

What is the big picture for the Tits alternative is in terms of Combinatorial Group Theory (or wider)? What is the motivation for studying it?

Thoughts:
Classes of groups similar to $\mathcal{G}_0$ have been studied in terms of the Tits alternative before and, in some cases, it has been fully established, according to my supervisor, who said that the Tits alternative is quite an important property.
My guess is that what's going on is something similar to how exact sequences, by means of extensions, motivate the study & classification of solvable groups.
Please help :)
Comment: There are many reasons to study this type of questions, for instance, given a group it is natural to ask which subgroups does it have. It also provides a way of proving that a group is nonamenable.
Answer: The Tits alternative, first proven by Jacques Tits for linear groups, says the following:

If $G$ is a finitely generated subgroup of a linear group then $G$ is either virtually soluble* or contains a non-abelian free subgroup.

In geometric and combinatorial group theory, "being virtually-$\mathcal{P}$" for some property $\mathcal{P}$ is basically the same as "being $\mathcal{P}$". Now, a group cannot both have a non-abelian free subgroup and be virtually-soluble (why?). Therefore, the Tits alternative says that containing a free subgroup is the only obstruction to solubility which a finitely generated subgroup of a linear group can have.
The Tits alternative is considered a "nice", linear-like property. Therefore, showing that a class of groups satisfies the Tits alternative shows that you are dealing with a nice class of groups (and cyclically presented groups are weird! If they were also nice then this would be...nice.).
Why do we want to show linear-like properties? Well, as an example, it is a famous open question of Gromov whether or not hyperbolic groups are residually finite**. One way of showing this would be to prove that they are all linear (as linear groups are residually finite). So a first step towards proving linearity would be to prove that they satisfy the Tits alternative. And they do. Yay! On the other hand, Misha Kapovich proved that there are non-linear hyperbolic groups. So hyperbolic groups sit in a curious middle ground, along with $\operatorname{Out(F_n)}$ and mapping class groups... To add some fuel to the fire - Agol, Wise and others proved that masses of hyperbolic groups are indeed linear (basically, every hyperbolic group you've ever heard of apart from those synthetically cooked up by Kapovich to be non-linear). So hyperbolic groups are "mostly" linear, and are morally linear. Except they some are not linear. This is an (IMO, exteremly) interesting state of affairs.
*In American English, solvable.
**You may of course ask "residual finiteness: why do we care?"...
Comment: @Shaun Gotcha! It should have read "virtually soluble or contains a non-abelian free subgroup". The rest of the post remains unaffected by this typo. (Note that virtually soluble means precisely "contains a soluble subgroup of finite index".)
Comment: I believe it is considered open whether or not mapping class groups of surfaces are linear
Comment: @Paul Sorry, I was being sloppy and didn't check this. I think you are right though - it was claimed on the arxiv in 2003, but Farb stated that it was still open in 2006. I believe Farb... I will check the primer tomorrow (unless you have a copy to hand?)
Comment: I don't think the primer explicitly mentions it as an open problem (at least from my quick scan), but it certainly does not say it is linear, which they would mention. I get the feeling that the paper you mention isn't accepted by the community
Comment: Isn't it "contains a **solvable** subgroup  of finite index"?
Comment: @Shaun Soluble is British English, while solvable is American English. (I am British.)
Comment: @user1729: That's not the issue I wanted to raise. Look closer at what you typed in the answer.
Comment: @user1729: My definition of the Tits alternative and yours don't match. Are you sure of it?
Comment: @Shaun wrt your edit, I had got rid of the first "Now" as I used it to start two sentences in a row: "Now, in... . Now, a group..."


How to insert javascript in a block?

Question: I would like to insert a JavaScript code in block body but I cannot save it, after 2 or 3 minutes it stop (shows a message The connection has timed out). I want to add statcounter code to a block.
EDIT 1:
I can add JavaScript in local-host but I can't do in server (Linux server, VPS cPanel)
Comment: What text-format options are set for the block?
Comment: Input format is Full HTML.
Comment: Have you tried the module for statcounter? http://drupal.org/project/statcounter/
Comment: Yes I am using that module, but the same problem exist !!!!
Comment: Sounds like it's a server configuration issue. Can you insert a simple javascript test without having it error out? Something like:
    (function(){
        console.log('Hello World!');
})();
Comment: Yes i can insert **(function(){ console.log('Hello World!'); })();** it.
Answer: Create your own text filter which just does nothing which means it allows really "all" input without any filtering.
Please make sure that you allow only trusted people to use this filter since it would be easy to add XSS code.
Comment: Are you using a WYSIWYG editor? Sometimes they strip out script tags even if the filter allows them.
Comment: Thanks for your help, I tried your method but unfortunately the same error occurs!. What to do ?

How to insert javascript in a block?


Simple definition of Ordinal and Cardinal numbering

Question: Ordinal number
The index (position) to an element in a set or sequence.
Are ordinals just indices to some table or sequence? For example lets consider the sequence $A = {2,4,7,14,25,3,1,6,3}$. If I say that I want the third ordinal of that sequence is the result then = $14$ ? Since we $a_4 = 14$ ?
Cardinal number
Is a natural number $\mathbb{N}$ that measure the size of sets (that is not well-ordered?). So If I say that the cardinal of the set $A$ is $9$, it means that there are $9$ elements of the set $A$ above?
Im just wondering if I got these definitions right. I just want a general simple explanation without many other concepts. Thanks.
Comment: See [Ordinal number](https://en.wikipedia.org/wiki/Ordinal_number) : "an ordinal number is used to describe a way to arrange a collection of objects in order, one after another. Any finite collection of objects can be put in order just by the process of counting: labeling the objects with distinct whole numbers. Ordinal numbers are thus the "labels" needed to arrange collections of objects in order."
Comment: Thus, yes: in the *list* $A = (2,4,7,14,25,3,1,6,3)$ we have that the *first* element of $A$ is $2$, the *second* element of $A$ is $4$, and so on.
Comment: If we consider instead the *set* $A = \{ 2,4,7,14,25,3,1,6,3 \}$ we have no first, second, etc.elemnts, but only **nine** distinct elements. See [Cardinal number](https://en.wikipedia.org/wiki/Cardinal_number) : "cardinal numbers are used to measure the cardinality (size) of sets. The cardinality of a finite set is a natural number: the number of elements in the set."
Comment: @MauroALLEGRANZA: Ok good.
Answer: You have it pretty much right. Better on cardinals than on ordinals. The number $3$ is an ordinal when you think of it in position in the sequence $1,2,3, \ldots$ and a cardinal when you say there are $3$ elements in the set $\{5,7,11\}$. You wouldn't usually say an ordinal is an index into a sequence, but your intuition is right even though that usage is not standard.


Creating ZFS pool from liveCD with ashift=9 becomes ashift=12 when rebooted into new OS

Question: I have created a zpool while booted on a Linux Mint liveCD (with all the ZFS packages temp apt-installed) and created a zpool with command line containing ashift=9 because my ST4000NM0033 drives (8 each) have 512B sectors. Also created some ZFS filesystems on the pool while in LiveCD
While still running liveCD, I was then able to verify the pool was using ashift=9 by running zdb -e -C pool0 | grep ashift . I had to use the -e -C pool0 options because without them I was getting cannot open /etc/zfs/zpool.cache error
But once I installed and rebooted into the real OS, which is ZFS on root, and re-ran zdb | grep ashift it reports ashift=12
I am also using LUKS on under the vdevs. Each one has a detached header and keyfile and I boot the system from USB key with grub/efi/boot on it.
The zpool is a 2x stripped 4-drive RAIDZ1 arrangement.
zpool details:
click for detail pic. it would not paste correctly
Here's the results of zdb on running system
version: 5000
name: 'pool0'
state: 0
txg: 331399
pool_guid: 4878817387727202324
errata: 0
hostname: 'shop'
com.delphix:has_per_vdev_zaps
vdev_children: 1
vdev_tree:
    type: 'root'
    id: 0
    guid: 4878817387727202324
    children[0]:
        type: 'raidz'
        id: 0
        guid: 4453362395566037229
        nparity: 1
        metaslab_array: 138
        metaslab_shift: 36
        ashift: 12
        asize: 7996794994688
        is_log: 0
        create_txg: 4
        com.delphix:vdev_zap_top: 129
        children[0]:
            type: 'disk'
            id: 0
            guid: 17425041855122083436
            path: '/dev/mapper/luks_root_sda'
            whole_disk: 0
            DTL: 179
            create_txg: 4
            com.delphix:vdev_zap_leaf: 130
        children[1]:
            type: 'disk'
            id: 1
            guid: 14306620094487281535
            path: '/dev/mapper/luks_root_sdb'
            whole_disk: 0
            DTL: 178
            create_txg: 4
            com.delphix:vdev_zap_leaf: 131
        children[2]:
            type: 'disk'
            id: 2
            guid: 16566898459604505385
            path: '/dev/mapper/luks_root_sdc'
            whole_disk: 0
            DTL: 177
            create_txg: 4
            com.delphix:vdev_zap_leaf: 132
        children[3]:
            type: 'disk'
            id: 3
            guid: 542095292802891028
            path: '/dev/mapper/luks_root_sdd'
            whole_disk: 0
            DTL: 176
            create_txg: 4
            com.delphix:vdev_zap_leaf: 133
        children[4]:
            type: 'disk'
            id: 4
            guid: 14142266371747430354
            path: '/dev/mapper/luks_root_sde'
            whole_disk: 0
            DTL: 175
            create_txg: 4
            com.delphix:vdev_zap_leaf: 134
        children[5]:
            type: 'disk'
            id: 5
            guid: 9998698084287190219
            path: '/dev/mapper/luks_root_sdf'
            whole_disk: 0
            DTL: 174
            create_txg: 4
            com.delphix:vdev_zap_leaf: 135
        children[6]:
            type: 'disk'
            id: 6
            guid: 9268711926727287907
            path: '/dev/mapper/luks_root_sdg'
            whole_disk: 0
            DTL: 173
            create_txg: 4
            com.delphix:vdev_zap_leaf: 136
        children[7]:
            type: 'disk'
            id: 7
            guid: 16360862201213710466
            path: '/dev/mapper/luks_root_sdh'
            whole_disk: 0
            DTL: 172
            create_txg: 4
            com.delphix:vdev_zap_leaf: 137
features_for_read:
    com.delphix:hole_birth
    com.delphix:embedded_data

UPDATE: Seems checking ashift value directly on the device shows a expected ashift=9 value. Not sure why upper-level value is different
    zdb -l /dev/mapper/luks_root_sda
LABEL 0
version: 5000
name: 'pool0'
state: 0
txg: 2223
pool_guid: 13689528332972152746
errata: 0
hostname: 'shop'
top_guid: 8586701185874218688
guid: 11289841240384277392
vdev_children: 2
vdev_tree:
    type: 'raidz'
    id: 0
    guid: 8586701185874218688
    nparity: 1
    metaslab_array: 142
    metaslab_shift: 37
    ashift: 9
    asize: 15901962272768
    is_log: 0
    create_txg: 4
    children[0]:
        type: 'disk'
        id: 0
        guid: 11289841240384277392
        path: '/dev/mapper/luks_root_sda'
        whole_disk: 0
        create_txg: 4
    children[1]:
        type: 'disk'
        id: 1
        guid: 7916996642850715828
        path: '/dev/mapper/luks_root_sdb'
        whole_disk: 0
        create_txg: 4
    children[2]:
        type: 'disk'
        id: 2
        guid: 5366943858334839242
        path: '/dev/mapper/luks_root_sdc'
        whole_disk: 0
        create_txg: 4
    children[3]:
        type: 'disk'
        id: 3
        guid: 3110382675821028014
        path: '/dev/mapper/luks_root_sdd'
        whole_disk: 0
        create_txg: 4
features_for_read:
    com.delphix:hole_birth
    com.delphix:embedded_data
labels = 0 1 2 3

Comment: Can you issue `zdb -e -C pool0` (ie: not using cache file) on your running system and paste output here?
Comment: I get error `zdb: can't open 'pool0': File exists`
Comment: Someone else mentioned checking the `ashift` value on the devices directly by using `zdb -l /dev/DEVICE | grep ashift` commands.

When I do that, I see that each device does have an `ashift=9` value as expected.

Maybe the pool-level value of ashift can be different than the lower-level vdev value? Maybe the pool-level value is just the default value that will be used as new vdevs are created and not overridden by a command-line `-o ashift=9` option?
Answer: This problem was caused by a stale /etc/zfs/zpool.cache that was copied into place when I replaced the 8x1TB setup with the new 8x4TB array and copied the original / root back into place.
Seems ZFS did not update zpool.cache and zdb -l reads from that file whereas zdb -l /dev/DEVICE | grep ashift reads from the zdev directly and showed the expected ashift=9 value.
To correct the entire problem, I deleted zpool.cache and executed zpool set cachefile=/etc/zfs/zpool.cache pool0


Convert Outlook REST API item id to MAPI EntryID

Question: is there an officially supported way to convert item ids from the Outlook REST API into an MAPI EntryID?
I am talking about the "Id" field returned for items in the json response of an http GET on a mailbox endpoint like so:
https://outlook.office365.com/api/v2.0/me/messages
The Id field contains a base64 value. When I convert it to hex and compare it to the PR_ENTRY_ID value of the same item, e.g. with MFCMAPI, I can find the EntryID is contained in the hex version of the Id field.
Is there an official documentation how to convert between the id formats?
Or an API to call? Would prefer a local convert functions to avoid additional REST roundtrips.
Thanks for any hints
SvenC
Answer: Your query to the Microsoft Graph API can specify that you would like to include the PR_ENTRYID or other MAPI properties. Here is the official documentation for singleValueLegacyExtendedProperty from Microsoft.
For example, if you wanted to fetch a page of your messages and include the PR_ENTRYID, you could make a GET request to:
https://graph.microsoft.com/v1.0/me/messages?$expand=singleValueExtendedProperties($filter=id%20eq%20'Binary%200x0FFF')
Without URL encoding, the $expand statement reads:
$expand=singleValueExtendedProperties($filter=id eq 'Binary 0x0FFF')
There are three valid syntaxes to filter for MAPI properties:

'MapiPropertyType namespaceGuid Name propertyName'
'MapiPropertyType namespaceGuid Id propertyId'
'MapiPropertyType propertyTag'

Note that the example above uses #3, and that 0x0FFF is the propertyTag for PR_ENTRYID per the [MS-OXPROPS] Exchange Server Protocols Master Property List.
Answer:
is there an officially supported way to convert item ids from the Outlook REST API into an MAPI EntryID?

No, office.js API doesn't have anything to convert REST/EWS Id to PR_ENTRY_ID

Is there an official documentation how to convert between the id formats?

Obviously there is no documentation as of point above

Or an API to call? Would prefer a local convert functions to avoid additional REST roundtrips.

Yes, there are calls to retrieve (not convert) IMessage Id and this is exactly what you've done ... RESTful or EWS requests. With those requests you are able to get IMessage properties, including PR_ENTRY_ID. I just don't really understand what you are going to use it for? Any requests back to the message have to be done with EWS/REST Id anyway. Well, probably this is something to do with your message manipulation.
Comment: I see. Well, there is nothing for you, other than request it with EWS or REST and after send it to your service. Actually I meet the first time someone who use this approach. Would you mind to tell me what kind of work does your service? Of cause, if it's not business secret. I guess it looking for some property in the message set by add-in and do something to this message based on it? Also is it reliable and work for every single message? Do you have any hiccups for this service? I will be very appreciated.
Comment: The context is a Mail App which (roughly) sends the EntryID as email-body into a monitored server mailbox. A MAPI based service gets that EntryID and processes the item. With EWS we get MAPI properties by proptag. Could not find that for REST but the Id value looks almost usable. Do you have details to get PR_ENTRY_ID by REST? I found a promising syntax using query param $expand [link](https://msdn.microsoft.com/en-us/office/office365/api/mail-rest-operations). Seems missing in Exchange 2016 On-Prem (latest CU4 from dec 2016 installed) which responds to v2.0 REST calls.
Comment: Sorry - pressed  in hope for a line break and sent an incomplete comment - deleted and readded the comment. Maybe Ex2016 On-Prem REST API does less than Office365
Comment: Our service reads the message content, puts it into another storage system and marks the item as processed. Works reliable - only hickup is when a user of our  Mail App executes the App command and immediately moves or deletes the item which renders the EntryID. Not a typical user action for our customers.
Comment: "Do you have details to get PR_ENTRY_ID by REST?". Unfortunately I am not an expert with REST as our app uses EWS for communication and I just payed a bit with REST against our O365. But you are on the right track, as I saw many times ppl are using "$expand=SingleValueExtendedProperties" to get extended message props. The only thing as you mention is availability for Exchange on prem. Sorry, no help over here. Thanks for info, you provided ;)


Did Gosper or the Borweins first prove Ramanujans formula?

Question: In 1985, Gosper used the not-yet-proven formula by Ramanujan
$$\frac{ 1 }{\pi } = \frac{2\sqrt{2}}{99^2}\cdot \sum_{n=0}^\infty \frac{(4n)!}{(n!)^4}\cdot\frac{26390 n+1103}{99^{4n}}$$
to compute $17\cdot10^6$ digits of $\pi$, at that time a new world record.
Here (https://www.cs.princeton.edu/courses/archive/fall98/cs126/refs/pi-ref.txt) it reads:

There were a few interesting things about Gosper's computation. First, when he decided to use that particular formula, there was no proof that it actually converged to pi! Ramanujan never gave the math behind his work, and the Borweins had not yet been able to prove it, because there was some very heavy math that needed to be worked through. It appears that Ramanujan simply observed the equations were converging to the 1103 in the formula, and then assumed it must actually be 1103. (Ramanujan was not known for rigor in his math, or for providing any proofs or intermediate math in his formulas.) The math of the Borwein's proof was such that after he had computed 10 million digits, and verified them against a known calculation, his computation became part of the proof. Basically it was like, if you have two integers differing by less than one, then they have to be the same integer.

Now my historical question: Who was the first to prove this formula? Was it Gosper because he added the last piece of the proof, or was it the Borweins, afterwards? And was Gosper aware of this proof when he did his computation?
Comment: The [History of Science and Mathematics StackExchange](http://hsm.stackexchange.com) might be better-suited to addressing this as a historical question.
Comment: Ok, I don't think anyone has proved this formula without the aid of mathematical computation. But Ramanujan's work in this area was nearly complete and I firmly believe that he computed 1103 by hand. The reasons for this belief are the symbolic formulas which he gave in the same paper. Those symbolic formulas could not be guessed in 1914 (or earlier) rather they were obtained using algebraic manipulation. However Ramanujan does not give the symbolic formula related with this particular series in the question and no one has discovered it so far.
Comment: Also see my related question on MO: https://mathoverflow.net/q/163859/15540
Comment: @reuns: does your comment refer to my answer here or to my question on mathoverflow.net? As far as the answer here is concerned all relevant definitions are provided.
Comment: You're right! But I'm interested in what happened 1985-1987, especially the role of Gosper. Do you know something about that?
Comment: I don't see at all the point of listing 40 special functions without understanding how they are related. You need at the very least to separate into modular forms, modular functions, elliptic functions, elliptic integrals. @ParamanandSingh
Answer: What follows is taken directly from Borweins' Pi and the AGM.
Let $N$ be a positive number and $q_N=e^{-\pi\sqrt{N}}$ and $$k_N=\frac{\vartheta_{2}^{2}(q_N)}{\vartheta_{3}^{2}(q_N)},k'_N=\sqrt{1-k_N^2},G_N=(2k_Nk'_N)^{-1/12},g_N=\left(\frac{2k_N}{{k'} _N^{2}}\right)^{-1/12}\tag{1}$$ where $\vartheta _2,\vartheta_3$ are theta functions of Jacobi defined by $$\vartheta_{2}(q)=\sum_{n\in\mathbb {Z}} q^{(n+(1/2))^2},\, \vartheta_{3}(q)=\sum_{n\in\mathbb {Z}} q^{n^2}\tag{2}$$ Borwein brothers define another variable $$\alpha(N) =\frac{E(k'_N)} {K(k_N)} - \frac{\pi} {4K^2(k_N)}\tag{3}$$ where $K, E$ denote standard elliptic integrals $$K(k) =\int_{0}^{\pi/2}\frac{dx}{\sqrt{1-k^2\sin^2x}},\,E(k)=\int_{0}^{\pi/2}\sqrt{1-k^2\sin^2x}\,dx\tag{4}$$ It is well known that $k_N, k'_N, \alpha(N) $ are algebraic when $N$ is a positive rational number. We assume $N$ to be a positive integer unless otherwise stated.
Borweins present two class of series for $1/\pi$ based on Ramanujan's ideas which are of interest here: $$\frac{1}{\pi}=\sum_{n=0}^{\infty} \dfrac{\left(\dfrac{1}{4}\right)_n\left(\dfrac{2}{4}\right)_n\left(\dfrac{3}{4}\right)_n} {(n!)^{3}}d_n(N) x_N^{2n+1}\tag{5}$$ where $$x_N=\frac{2} {g_N^{12}+g_N^{-12}} =\frac{4k_N{k'} _{N}^{2}}{(1+k_N^2)^2}, \\ d_n(N) =\left(\frac{\alpha(N) x_N^{-1}}{1+k_N^2}+\frac{\sqrt{N} }{4}g_N^{-12}\right) +n\sqrt{N} \left(\frac{g_N^{12}-g_N^{-12}}{2}\right) \tag{6}$$ and $$\frac{1}{\pi}=\sum_{n=0}^{\infty} (-1)^n\dfrac{\left(\dfrac{1}{4}\right)_n\left(\dfrac{2}{4}\right)_n\left(\dfrac{3}{4}\right)_n} {(n!)^{3}}e_n(N) y_N^{2n+1} \tag{7}$$ where $$y_N=\frac{2} {G_N^{12}-G_N^{-12}} =\frac{4k_Nk'_{N}}{1-(2k_Nk'_N)^2}, \\ e_n(N) =\left(\frac{\alpha(N) y_N^{-1}}{{k'} _{N} ^{2}-k_N^2}+\frac{\sqrt{N} }{2}k_N^2G_N^{12}\right) +n\sqrt{N} \left(\frac{G_N^{12}+G_N^{-12}}{2}\right)\tag{8}$$ The series in question is based on $(5)$ with $N=58$. Another (not so famous but equally remarkable) series given by Ramanujan using $(7)$ with $N=37$ is as follows: $$\frac{4}{\pi}=\frac{1123}{882}-\frac{22583}{882^3}\cdot\frac{1}{2}\cdot\frac{1\cdot 3}{4^2}+\frac{44043} {882^5}\cdot\frac{1\cdot 3}{2\cdot 4}\cdot\frac{1\cdot 3\cdot 5\cdot 7}{4^2\cdot 8^2}-\dots\tag{9}$$ Borweins mention that the values of $\alpha(37),\alpha(58)$ (leading to $1123$ in series $(9)$ and $1103$ in series in question) were obtained by calculating $e_0(37)$ and $d_0(58)$ to high precision.
The details of these calculations are not revealed by Borwein Brothers. But it appears that using value of $\pi$ given by Gosper and the series in question (as well as series $(9)$) one can get the values of $d_0(58),e_0(37)$ to high precision. Further some amount of computation is needed to get the minimal polynomials for $\alpha(37),\alpha(58)$. And then one can get their values in closed form as radicals.
The procedure is similar to what you have done in one of your papers dealing with evaluation of coefficients in Chudnovsky formula but the analysis is probably more complicated because the functions involved here are not like the $j$ invariant taking integer values.

To sum up, Gosper role was important in this proof on two fronts. First is the computation itself and second is that his computation brought Ramanujan's formula into limelight. It was sitting there in his paper Modular equations and approximations to $\pi$ since 1914 and no one before Gosper even looked at it.
Also as most references indicate Gosper's computation was done earlier without any knowledge of Borwein's work which got published later. So Gosper was not aware of the proof of the formula and didn't know that his computation would someday be used as a part of the proof of the series which he computed.
Comment: Borwein's book is my primary reference. Apart from that this is discussed (but not with details) in *Pi Unleashed* by Jorg Arndt. You can also read the paper by Borwein http://www.cecm.sfu.ca/organics/papers/borwein/paper/html/node15.html (search for "it is less clear").
Comment: @L.Milla: My guess is that Ramanujan developed alternative theories of theta functions in great detail (some of it redeveloped in Bruce Berndt's books) and perhaps the calculations in his theories were simpler than those in  approach used by Borweins.
Comment: Wow, thank you! Do you have such references, as you wrote in the last section?
Answer: I asked Bill Gosper, and here is his response:

There was email on this at the time, which I may be able to dig up.  But, as I recall, when I began
  my computation, the Borwein brothers had proved that if Ramanujan's formula did not equal π,
  it differed from π by at least 10^-3000000, so that as my computation passed the 3000000 mark
  in agreement with Kanada's 16000000 digit AGM computation, it served to complete the Borwein
  proof.  But by the time my computation reached 17000000, the Borwein's resolved their ambiguity
  without my empirical confirmation.  Their completed proof is almost certainly in their Pi and the AGM
  book.  Tito Piezas and the Chudnovsky brothers have presumably put the matter to rest with their
  climactic series based on √163, the final Heegner number.
Just to clarify, I did not crank out π as a decimal string.  I resumably summed Ramanujan's series
  as an exact rational number on a Symbolics computer with unlimited integers, converting to decimal
  now and then for comparison with Kanada, but with the ultimate purpose of computing the
  {3,7,15,1,292,...} continued fraction, which is actually mathematically interesting, as opposed to
  useless decimal or binary, which is actually an encryption.  Regrettably, (almost) everybody ignored
  my continued fraction and wasted their time computing (eventually trillions of) useless digits.
Comment: That's cool. +1 Bill Gosper mentions that Borwein's resolved their ambiguity without Gosper's numerical confirmation. Perhaps they might have done more research to reduce the number of digits of $\pi$ to confirm their formula and used $\pi$ from previous computations. Anyway as my answer indicates Borwein's don't give details of the computation in their book *Pi and the AGM*.
Comment: @ParamanandSingh I've always been curious why Gosper mentioned my name in the same sentence as the Chudnovsky brothers, hehe. He probably came across stuff about $\mathbb{Q}\big(\sqrt{-163}\big)$ in my google sites when it was still online.
Comment: @TitoPiezasIII: believe it or not, but you are famous in the circle of people dealing with Ramanujan's work. I knew your work from the time when your pages were hosted on yahoo geocities (sample broken link http://www.geocities.com/titus_piezas/ramanujan.html).
Comment: @ParamanandSingh That is nice to hear! I'd almost forgotten about that geocities link. Work from another era.


Routing issue for SonicWall VPN client

Question: We presently have two sites connected via a nailed-up VPN connection. Site 1 (corporate office) has a SonicWall Pro 2040 Enhanced, and site 2 (a data center) has a SonicWall NSA 2400. The IP scheme at site 1 is 10.0.0.0/255.255.255.0, and at site 2 is 10.0.1.0/255.255.255.0.
The problem I'm having is that we have remote users that connect to site 1 via a GlobalVPN client, but because of how that VPN connection's routing is set up they can't access resources on the 10.0.1.0 network. I've tried manually adding static routes, but it appears that the SonicWall is preventing that VPN connection from making the jump to the other device.
One option is to duplicate the remote VPN users and settings at site 2, but that would require that we manually sync those users and that remote users make two separate VPN connections -- not ideal.
Do any SonicWall gurus out there know how I can configure the VPN connections to allow access to those site 2 resources?
Answer: It has to do with how the firewall identifies the remote VPN user's IP address internally.  With some VPN clients, the firewall identifies user X as being from their "real" IP address.  Which isn't a problem as long as firewall A is the gateway back to the internet for all the intended internal targets.  But if you route the packet across a VPN, you will almost certainly find return packets come back through a different NAT station than you intend.
Consider remote user X accessing firewall A which has a VPN to firewall B, behind which is server S that you want user X to access.  Servers behind firewall A see originating connections from X as their remote IP address.
In this scenario, the packet from X gets tunneled to A, which then VPNs it to B, which forwards it to S.  In order to close the loop and send information back, S needs to send a packet back to X.  To the packet goes to B.  Here's where the problem happens: B's route to X is direct across the internet -- not across the VPN, which is where it actually came from.  This packet will probably get NAT'd to some address of B's and sent direct across the internet.  So when the packet gets to X, it has IP addresses on it (and possibly ports) which don't relate to any conversation that X thinks it is actually trying to have, so X (should) discard it.  The loop never gets closed.
I saw this years ago with the 3Com SuperStack-3 firewalls, which I understand were related to the Sonicwalls of the day.  We encountered this problem with a site that had two SS3s VPN'd together.
We never solved it with that hardware.
VPN solutions we use now assign local IPs to the VPN clients, so as far as the internal network is concerned, the VPN clients are connected internally.  This means that in the example case firewall B sees X as originating through the VPN with fireall A, and routing works.
Comment: We actually use the DHCP server at site 1 to assign internal IPs to VPN clients. Those IPs are in the 10.0.0.x range, so I believe the requests to the servers at site 2 should see that IP. I'll check the VPN logs and see if I can't get some detailed info to determine if the NAT issue is what's happening.
Comment: You might also snoop traffic at a target at site 2 to ensure that the traffic is even getting there.  Also it occurs to me you might check your (client) VPN configuration to ensure that traffic bound for site 2 would even be tunnelled -- either explicitly through a rule (sometimes called split-tunnelling), or implicitly by capturing all outbound traffic from the client via the VPN.
Answer: I don't know about the Pro's, but when connecting to an NSA with the the Global VPN client, you have to specify which networks that user has access to (either individually or by the groups they belong to). For instance, I created an address group object (REMOTE_USER_ACCESS) containing all of the networks I want my VPN users to be able to access (Our setup is the exact same as yours.. an office and data center with a site-to-site VPN tunnel done by an NSA3500 on each side.. user's connect to VPN on site A but access resources from private network at site B). Then, I either go to the individual user's account (Users > Local Users) or the group (Users > Local Groups), edit the user, click on the VPN Access tab and add the REMOTE_USER_ACCESS object. The VPN user can now access any networks I've specified in that address object.
Like I said, that's for the NSA, but I'm guessing the Pro isn't going to be too much different.
Comment: I'll give that a try and report back

Routing issue for SonicWall VPN client


Retornar resultado de Query para uma variável - Asp Clássico

Question: É possível retornar o resultado de uma query para uma variável no asp clássico?
exemplo:
<%
    dim retorno as string
    set minha_conexao = dao.open()
    set rs = minha_conexao.execute("Select max(data) from minha_tabela")
%>

Nesse ponto o retorno da query será apenas um valor, como faço para atribuir essa informação para uma variável.
Tentei fazer o set retorno = rs(0), no entanto não está retornando.
Comment: Chegou a tentar o `rs.fields(0)`?
Comment: também não traz retorno
Comment: @LePy Tentou rs("NomeDaColuna")   ?
Answer: sugiro fazer assim:
set rs = minha_conexao.execute("Select max(data) as max_data from minha_tabela")
retorno = rs("max_data")

Assim você põe na variável retorno o valor do recordset que a query retorna. Deu pra entender? Abs! LC


not well-formed in firefox when parsing XML using jquery

Question: The following code writes a warning in Firefox console,  not in Chrome.
In both cases, the result is correct.
<code> $('status', $.parseXML("<root><status>1</status></root>")).text()
</code>
I just like to understand what is wrong. Any suggestion?
Comment: What does the warnig say?
Comment: it says 'mal formé' ('not well formed')
Answer: Use:
<code><?xml version="1.0"?>
</code>
At beginning of your XML.
Comment: $('status', $.parseXML("1")).text()
makes no differents, still 'not well formed'


how to implement https protocol between a web server and web browser?

Question: what are the requirements to implement https protocol? i know that i need a https server
Answer: Setting up SSL on Apache
Setting up SSL for IIS
You'll probably also want to get a registered SSL certificate: most modern web browsers throw an error if you use a "self-signed" certificate.


preprocess_node_webform is not working

Question: I wanted the error messages from the webform to be customised. So I wrote following piece of code in template.php of my theme.
<code>function sandesh_preprocess_node_webform(&$vars, $hook) {
 if ($vars['node']->nid == "41" && is_array($_SESSION['messages']['error']))   {
 $errors = &$_SESSION['messages']['error'];
 $find = 'email';

 for($idx = 0; $idx < count($errors); $idx++) {
  if (substr($errors[$idx], 0, strlen($find)) == $find) {
  $errors[$idx] = 'Please enter the email field';
  break;
   }
 }

}
}
</code>
But this is not working. Is there something wrong in the code? Or is there  any other method to get customized error message in the webforms ? Thank you
Answer: You don't need to code to do this. Have a look at the answers to this questions to find more information: How to modify user messages without hacking core user module?

preprocess_node_webform is not working


Why would I ever use a Chain of Responsibility over a Decorator?

Question: I'm just reading up on the Chain of Responsibility pattern and I'm having trouble imagining a scenario when I would prefer its use over that of decorator.
What do you think? Does CoR have a niche use?
Comment: please add kind of a task which you think is task for CoR but you solved it with decorator
Comment: Sure, I need to complete an order and in some cases I need to print a bill. My decorator solution is to have a core OrderCompleter wrapped in a OrderCompletionPrintDecorator which applies the conditional logic and prints. Works just as well as any chain.
Comment: Why couldn't you just have a method called "Print" inside OrderCompleter that can be used (or not) when you want (don't want) to print? In other words, I was wondering whether you could solve this task withOUT using any pattern at all? It doesn't seem to me like a complicated task with a real need for introducing abstraction and complexity. Or maybe what you said is just a oversimplified version of the problem.
Comment: @SonDo It depends - but yes, it's an oversimplified version. The question is, where does the logic go about what makes something print? If it's a simple decision it could go right into `OrderCompleter.Complete()` but it could instead be something like this: "If the printing service responds to a ping and this order or a parent order has not been printed yet and the client placing the order does not integrate directly with our system."
Answer: The fact that you can break the chain at any point differentiates the Chain of Responsibility pattern from the Decorator pattern. Decorators can be thought of as executing all at once without any interaction with the other decorators. Links in a chain can be thought of as executing one at a time, because they each depend on the previous link.
Use the Chain of Responsibility pattern when you can conceptualize your program as a chain made up of links, where each link can either handle a request or pass it up the chain.
When I used to work with the Win32 API, I would sometimes need to use the hooking functionality it provides. Hooking a Windows message roughly follows the Chain of Responsibility pattern. When you hooked a message such as WM_MOUSEMOVE, your callback function would be called. Think of the callback function as the last link in the chain. Each link in the chain can decide whether to throw away the WM_MOUSEMOVE message or pass it up the chain to the next link.
If the Decorator pattern had been used in that example, you would have been notified of the WM_MOUSEMOVE message, but you would be powerless to prevent other hooks from handling it as well.
Another place the Chain of Command pattern is used is in game engines. Again, you can hook engine functions, events, and other things. In the case of a game engine, you don't want to simply add functionality. You want to add functionality and prevent the game engine from performing its default action.
Comment: IMO In the CoR pattern, we can have many (or all) handler (link) objects could contribute to each request's handling / building a response.
Comment: So you are saying it could be a replacement for a nested if...else statement, except there will no else section at the end?
Comment: @Rishi, it's easy to imagine that, but the GoF does not mention it. In their CoR pattern, each request is handled once or not at all.
Comment: @DiponRoy, yes, but, the critical point of the CoR pattern is the decoupling. In an if...else block the caller sees every branch. In a CoR the caller doesn't even know the chain exists.
Answer: I'd say that a Chain of Responsibility is a particular form of Decorator.
Comment: One line explains everything
Answer: Chain

Avoid coupling the sender of a request
  to its receiver by giving more than
  one object a chance to handle the
  request. Chain the receiving objects
  and pass the request along the chain
  until an object handles it.

vs
Decorator

Attach additional responsibilities to
  an object dynamically. Decorators
  provide a flexible alternative to
  subclassing for extending
  functionality.

I'd say its around the order in which things will happen.  If you chain them, the will be called along the chain.  With a decorator you're not guaranteed this order, only that additional responsibilities can be attached.
Comment: You can attach in different order, no?
Comment: If we're talking from the POV of a class consumer you're absolutely correct, if we're talking from the POV of the class designer however, you can certainly guarantee this as much as a chain could.
Answer: Decorator is used when you want to add functionality to an object.
COR is used when one of many actors might take action on an object.
A particular Decorator is called to take an action, based on the type; while COR passes the object along a defined chain until one of the actors decides the action is complete.
COR might be used when there are multiple levels of escalation to different handlers -- for instance, a call center where the customer's value to the company determines if the call goes to a particular level of support.
Comment: But a decorator is a different pattern -- with COR, the object is passed from actor to actor until one says that it's completed the action; with decorator, the action is going to be performed on one particular class's implementation.
Comment: Ok, but my point is that you can use a decorator with just as much if not less effort.  So why the heck even involve CoR?
Answer: Well I can think of 2 situations:

You don't have a core object, i.e. you don't know what to do with the request after it passed all the layers/filters. (something like an aspect like interceptor chains that don't really care where the request ends).
You need to selectively apply some pre or post processing to the request. Not in a general enhancement form as the decorator does. i.e. Filters may or maynot handle a specific request but adding a decorator always enhances your object with some functionality.

Can't think of any more right now, would love to hear more in this topic.
Answer: I agree that from structural standpoint this two patterns are very similar. My thought is about the final behavior:
In the classic interpretation of CoR element which handles the request breaks the chain.
If any element in decorator breaks the chain then it will be wrong implementation of decorator, because base part of behavior will be lost. And the idea of decorator is transparent addition of new behavior when the base behavior remains untouched.
Answer: Decorator

Decorator pattern allows behaviour to be added to an individual object dynamically.
It provides a flexible alternative to sub classing for extending functionality. Even though it uses inheritance, it inherit from Lowest Common Denominator ( LCD ) interface.

UML diagram for Decorator

Consequences:

With decoration it is also possible to remove the added functionalities dynamically.
Decoration adds functionality to objects at runtime which would make debugging system functionality harder.

Useful links:
When to Use the Decorator Pattern?
Decorator_pattern from wikipedia
decorator from sourcemaking
Chain of responsibility:

Chain-of-responsibility pattern is a design pattern consisting of a source of command objects and a series of processing objects. Each processing object contains logic that defines the types of command objects that it can handle; the rest are passed to the next processing object in the chain

UML Diagram

This pattern is more effective when:

More than one object can handle a command
The handler is not known in advance
The handler should be determined automatically
It's wished that the request is addressed to a group of objects without explicitly specifying its receiver
The group of objects that may handle the command must be specified in a dynamic way

Useful links:
Chain-of-responsibility_pattern from wikipedia
chain-of-responsibility-pattern from oodesign
chain_of_responsibility from sourcemaking
Real world example : In a company, a designated role have particular limits to process purchase request. If person with a designated role does not have enough power to approve purchase bill, he will forward the command/request to his successor, who have more power. This chain will continue until the command is processed.
Answer:
keyword 'extends' - static extension.
Decorator pattern - dynamic extension.
Chain Of Responsibility pattern - just processing of a command object with
    a set of processing objects and those objects don't know each other.
Answer: After reading the Gang of Four definitions, I'm not convinced there's a real difference. (included for convenience)

Decorator: Allows for the dynamic wrapping of objects in order to modify their existing responsibilities and behaviours
Chain of Responsibility: Gives more than one object an opportunity to handle a request by linking receiving objects together

Wikipedia fleshes them out a little, but some of it's kinda arbitrary.

Decorator is typically implemented as a Linked List. But I think that's too low-level to be considered "part" of the pattern.
Chain of Responsibility links only handle data if it's their responsibility; but determining responsibility and data handling are both part of behavior. Decorators can do this just as easily.
Decorator requires you to call the delegate.
A "pure" CoR link should only call the delegate if it doesn't handle the data.

The first two attributes don't really distinguish the patterns. The second two do, but the way Decorator and CoR are usually implemented don't enforce those attributes--the designer just hopes no one writes a Decorator that breaks the chain or a CoRLink that continues the chain after handling the data.
To actually implement these attributes, you'd need something like the following.
Enforced Decorator:
abstract class Decorated {

public Decorated delegate;

public final Object doIt(Object args) {
    Object returnVal = behavior(arg);
    if(delegate != null) returnVal = delegate.doit(returnVal);
    return returnVal;
}

protected abstract Object behavior(Object args); //base or subclass behavior
}

Enforced Chain of Responsibility:
abstract class Link {

public Link delegate;

public final Object processIt(Obect args) {
    Object returnVal = args;
    if(isMyResponsibility) returnVal = processingBehavior(returnVal);
    else returnVal = delegate.processIt(returnVal);
    return returnVal;
}

protected abstract Boolean isMyResponsibility(Object args);

protected abstract Object processingBehavior(Object args);
}

(Alternately, you could just add a line to the javadoc, if all you want is to absolve yourself of the responsibiity in case someone else screws up your design--but why leave it to chance?)
Answer: I think the situations to apply these two patterns are different. And by the way, for decorator pattern, the decorator should know the component which it wrapped. And for CoR, the different interceptors could know nothing of each other.
Comment: The decorator only needs to know the interface, not any implementation.


Java Constraint Programming

Question: How do I express a quadratic objective function in Constraint Programming? In Cplex, I write it as follows:
IloLQNumExpr objfn = model.lqNumExpr()

but it is not the same in CP.
Answer: very simple with CP Optimizer.
For example:
cp2.add(cp2.le(cp2.prod(Germany,Germany),4));

in
IloCP cp2 = new IloCP();
            IloIntVar Belgium = cp2.intVar(0, 3);
            IloIntVar Denmark = cp2.intVar(0, 3);
            IloIntVar France = cp2.intVar(0, 3);
            IloIntVar Germany = cp2.intVar(0, 3);
            IloIntVar Luxembourg = cp2.intVar(0, 3);
            IloIntVar Netherlands = cp2.intVar(0, 3);

            cp2.add(cp2.neq(Belgium , France));
            cp2.add(cp2.neq(Belgium , Germany));
            cp2.add(cp2.neq(Belgium , Netherlands));
            cp2.add(cp2.neq(Belgium , Luxembourg));
            cp2.add(cp2.neq(Denmark , Germany));
            cp2.add(cp2.neq(France , Germany));
            cp2.add(cp2.neq(France , Luxembourg));
            cp2.add(cp2.neq(Germany , Luxembourg));
            cp2.add(cp2.neq(Germany , Netherlands));

            cp2.add(cp2.le(cp2.prod(Germany,Germany),4));

            if (cp2.solve())
                {
                   System.out.println();
                   System.out.println( "Belgium:     " + (int)cp2.getValue(Belgium));
                   System.out.println( "Denmark:     " + (int)cp2.getValue(Denmark));
                   System.out.println( "France:      " + (int)cp2.getValue(France));
                   System.out.println( "Germany:     " + (int)cp2.getValue(Germany));
                   System.out.println( "Luxembourg:  " + (int)cp2.getValue(Luxembourg));
                   System.out.println( "Netherlands: " + (int)cp2.getValue(Netherlands));
                }

if I change a bit the very simple color.java example
Comment: Thank you for the answer. I want to define an expression for the objective function. Lets call the objective function as W=x^2+2x, and i want to maximize W. How to declare W?
Comment: Hi, cp2.add(cp2.eq(w,cp2.sum(cp2.prod(x,x),cp2.prod(2,x)))); will do that

Java Constraint Programming


Can you be offside from a goal kick?

Question: Can you be offside from a goal kick? Looking for official FIFA laws.
Answer: No. Law 11 Offside, part 3 No offence makes explicit exception:

There is no offside offence if a player receives the ball directly from:

a goal kick

a throw-in

a corner kick

even if the player is otherwise in an offside position.
Once ball is touched by another player, Law 11 applies as normal.

Can you be offside from a goal kick?


IPTables isn't forwarding anything

Question: I currently have set up IPTables on my server to forward certain ports on a specific interface (venet0:1) to a second server, at a different IP. My config file looks like this:
# Generated by iptables-save v1.4.12 on Sat Jun  8 08:36:54 2013
*mangle
:PREROUTING ACCEPT [480:39372]
:INPUT ACCEPT [480:39372]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [339:44328]
:POSTROUTING ACCEPT [339:44328]
COMMIT
# Completed on Sat Jun  8 08:36:54 2013
# Generated by iptables-save v1.4.12 on Sat Jun  8 08:36:54 2013
*nat
:PREROUTING ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A PREROUTING -i venet0:1 -p tcp -m state --state NEW,RELATED,ESTABLISHED -m tcp --dport 51315 -j DNAT --to-destination 76.xxx.xxx.xxx
-A PREROUTING -i venet0:1 -p tcp -m state --state NEW,RELATED,ESTABLISHED -m tcp --dport 27015:27020 -j DNAT --to-destination 76.xxx.xxx.xxx
-A PREROUTING -i venet0:1 -p tcp -m state --state NEW,RELATED,ESTABLISHED -m tcp --dport 25565:25570 -j DNAT --to-destination 76.xxx.xxx.xxx
-A PREROUTING -i venet0:1 -p tcp -m state --state NEW,RELATED,ESTABLISHED -m tcp --dport 7777 -j DNAT --to-destination 76.xxx.xxx.xxx
COMMIT
# Completed on Sat Jun  8 08:36:54 2013
# Generated by iptables-save v1.4.12 on Sat Jun  8 08:36:54 2013
*filter
:INPUT ACCEPT [86:6572]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [66:6912]
-A INPUT -i venet0:1 -j LOG
-A INPUT -i venet0:1 -p tcp -m tcp --dport 51315 -j ACCEPT
-A INPUT -i venet0:1 -p tcp -m tcp --dport 27015:27020 -j ACCEPT
-A INPUT -i venet0:1 -p tcp -m tcp --dport 25565:25570 -j ACCEPT
-A INPUT -i venet0:1 -p tcp -m tcp --dport 7777 -j ACCEPT
COMMIT
# Completed on Sat Jun  8 08:36:54 2013

(IP addresses concealed)
I've made sure that IPv4 forwarding is enabled, however when I do a lsmod, nothing at all shows up.
I've also tried using modprobe to add the iptables kernel modules, but nothing is found.
Could it be that the IPTables modules simply aren't installed, and that I need to recompile the kernel to install them?
When I try to connect on those ports, the connection is refused, as if iptables isn't even running.
I'm running Ubuntu 12.04 LTS on an OpenVZ VPS (hostname isn't actually hostname).
Linux hostname 2.6.32-042stab076.7 #1 SMP Thu Apr 25 13:35:47 MSK 2013 x86_64 x86_64 x86_64 GNU/Linux

EDIT: OK, at the suggestion of one of the answers, I changed venet0:1 to venet0. The behavior is still the same. A tcpdump of the port shows the following:
23:15:34.940437 IP 76.yyy.yyy.yyy.53802 > 192.xxx.xxx.xxx.51315: Flags [S], seq 3804882566, win 65535, options [mss 1460,nop,wscale 0,nop,nop,sackOK], length 0
23:15:34.940485 IP 76.yyy.yyy.yyy.53802 > 76.xxx.xxx.xxx.51315: Flags [S], seq 3804882566, win 65535, options [mss 1460,nop,wscale 0,nop,nop,sackOK], length 0

In the above, 76.yyy.yyy.yyy is the computer I am using to test the connection, 192.xxx.xxx.xxx is the IP of the server, and 76.xxx.xxx.xxx is the address of the server it's supposed to forward to. It seems to be forwarding the traffic somehow, except that the packets are zero-length and never get replied to. I also ran tcpdump on the receiving machine, and nothing showed up.
Comment: What is the problem you are having?
Comment: As is in the title and the end of the question, IPTables isn't forwarding anything I have configured it to forward.
Comment: Can you add the output for `ip link show` and `iptables -nvL -t nat`?
Answer:
I've made sure that IPv4 forwarding is enabled, however when I do a lsmod, nothing at all shows up.

lsmod only show the loaded modules. This has little to nothing to do with iptables. iptables automatically loads the modules it needs during rule insertion, and if it fails, it informs you with a beautiful error message.  If your rules are loaded successfully, iptables is running and no modules are missing.
Also, it is perfectly fine to have lsmod shows nothing: it means that the functionality is compiled builtin into the kernel. so the output of lsmod is completely irrelevant here.

When I try to connect on those ports, the connection is refused, as if iptables isn't even running.
-A PREROUTING -i venet0:1 -p tcp -m state --state NEW,RELATED,ESTABLISHED -m tcp --dport 51315 -j DNAT --to-destination 76.xxx.xxx.xxx

The problem here is most likely venet0:1, which does not exist. iptables has this limitation that it accept any interface name, even not existent ones or strings that do not even look like an interface name (you can even put IP addresses, just for fun, it won't work). If there is no interface matching the given name, the rule will simply not match. This is useful when your network interfaces are not yet ready, or if your network interfaces are hot-plugged, but most of the time, it's a pain to not being able to validate that the interface name actually exist. it's so easy to make a typo.
instead, use:

-A PREROUTING -i venet0 -p tcp -m state --state NEW,RELATED,ESTABLISHED -m tcp --dport 51315 -j DNAT --to-destination 76.xxx.xxx.xxx

Now, you will likely reply "but venet0:1 exist, ifconfig shows it !".
Except ifconfig is wrong. The reason ? Linux's ifconfig is old, deprecated, obsolete and sucks. Use ip addr instead. Same for route, netstat and brctl and probably others. ip replace all of them.
ip addr do not fake or hide any information from the kernel. What you see is the real state of the network stack. Now you can see that there is no such venet0:1 interface. Instead, venet0 has several IP addresses.  This is something that have been supported since the Linux 2.2 days.
But ifconfig (or actually, the BSD API it uses to communicate with the kernel) do not support that an interface has several IP addresses. So instead you have this old BSD trick called "interface aliases" where you can use ifconfig venet0:1 to configure an additional IP address for venet0, and it will show up as a venet0:1 interface.  Except venet0:1 is not an interface. Not even close.
Actually, ip addr will show you that venet0:1 is a label for an IP address, with the manual page telling you:
In order to preserve compatibility with Linux-2.0 net aliases, this string
must coincide with the name of the device or must be prefixed with the
device name followed by colon.

And the iptables manual page used to tell you to not use interface aliases or anything with a colon in it, but that line must have been disappeared.
Comment: OK, I've changed it from `venet0:1` to `venet0`, and it still has the same behavior. None of the forwarded ports seem to be getting to the host they are supposed to be forwarded to. I've put some more info in the original post
Answer: About the nat table
You can read this in the iptables man page:

This table is consulted when a packet that creates a new connection is encountered.

So you don't have to check the state of your connection there as this table is checked only for NEW connections.
Let's talk about your problem
OpenVZ is a "virtualization" technology based on namespaces.
Basically, your virtual machine is a simple folder in which a Linux system tree has been set up and contained to give you the illusion of being in a truly independent system. The originality of this virtualization method is that all containers are running one and only one Linux kernel instance, the host's one.
Now you have a problem because as you don't run your own kernel instance, you don't have full control and this explains a lot of things.

lsmod is empty because for safety reasons, they won't let you know which modules are running the system and of course, they won't let you change the system configuration by adding new modules. Imagine each client modifying the same kernel running other clients.
Even though you can allow the use of iptables for the containers, nat may haven't been enabled.

IPTables isn't forwarding anything


Probability such that at least one of the two balls drawn from an urn is red

Question:
Question: Two balls are drawn from an urn containing $2$ white, $3$ red and $4$ black balls one by one without replacement.
What is the probability  that at least one ball is red?

Attempt: probability that exactly one ball is red (red-any ball + any ball-red ball) + probability that both balls are red
$$\left[\frac 39\times\frac 68 + \frac 69\times\frac 38\right]+ \left[\frac 39\times\frac 28\right] $$
This gives the answer as $\frac 7{12}$, which is right but the book has used conditional probability formulas while solving the example. Is my thinking correct here?
Comment: Your method is fine.  An alternate method, possibly easier, is to work from the complement.  The probability that neither is red is $\frac 69\times \frac 58=\frac 5{12}$.
Answer: Your method is indeed correct - you've done
\begin{align}
P(\text{at least one red ball}) &= P(1^{\text{st}}\text{red},2^{\text{nd}}\text{not red}) + P(1^{\text{st}}\text{not red},2^{\text{nd}}\text{red}) + P(1^{\text{st}}\text{red},2^{\text{nd}}\text{red}) \\&= \frac{3}{9}\frac{6}{8} + \frac{6}{9}\frac{3}{8} + \frac{3}{9}\frac{2}{8} \\&= \frac{7}{12}
\end{align}
which accounts for all possibilities involving at least 1 red ball.
I imagine the conditional probabilities you are referring to are:
\begin{align}
P(\text{at least one red ball}) =& P(1^{\text{st}}\text{red})\times P(2^{\text{nd}}\text{not red}|1^{\text{st}}\text{red})\\& + P(1^{\text{st}}\text{not red})\times P(2^{\text{nd}}\text{red}|1^{\text{st}}\text{not red})\\& + P(1^{\text{st}}\text{red})\times P(2^{\text{nd}}\text{red}|1^{\text{st}}\text{red})
\end{align}
which is just the same as above just written differently.


App Engine Adding custom domain verification failed despite main site ownership verified

Question: I am trying to veryfy a subdomain to configure a server side GTM container.

The property is verified on the search console

However when I click refresh domain, I still get "Your domain hasn't been verified yet. Finish all the steps in Search Console  and then return to this page."
If I remove the property and start again, it is automatically verified as the main domain is also verified.
But there are no changes in the custom domain section. I cannot configure it to accept my A and AAAA records
EDIT
If I only validate the main domain, the A and AAAA records are not validated in Google App Engine DCustom Domains

What can I do here?
Comment: I have a similar issue, I hope you get a solution for this (I need it too)
Comment: You only need to verify the root domain. Does the subdomain actually have NS records (delegated zone)?
Comment: @JohnHanley when I only validate the main domain, the A and AAAA records are not created correctly in the custom domain section. For another website I was able to verify the subdomain but don't know why it's nor working here
Comment: I suspect the issue is with the refresh functionality, because it does not remove domains which one removes from the search console either.
Answer: To resolve issues with subdomain verification in Google App Engine after verifying the main domain in Google Search Console, follow these steps or refer to this link: Map a subdomain to your app

Go to App Engine > Settings > Custom Domains in the Google Cloud Console.
Add a custom domain.
Select the verified domain or verify a new domain.
Complete the verification steps in Webmaster Central.
Remove the www. subdomain in the "Point your domain to [project-ID]" section and save the mappings.

Additionally, troubleshoot the issue using these steps:

Ensure the necessary DNS records are added for your subdomain. Double-check DNS records.
Allow up to 24 hours for DNS changes to propagate before re-verifying the subdomain.
Confirm that you are using the correct verification method.
Retry the verification process.

Additional Reference:
Custom Domain Configuration
Set up server-side tagging with App Engine
Host a Google App on your Domain
Comment: this does not work, as you can see from my screenshot, I am the certified owner of the property on google search console but the domain appears as not verified in google cloud custom domains
Answer: Using the gcloud CLI solved this exact issue for me:
gcloud app domain-mappings create 'myvanitydomain.com' --certificate-management=AUTOMATIC
The CLI utility responses with a CNAME record to give to your registrar.
Comment: Note that the certificate activation time was pretty long for me, counted in hours. I checked two days later and it was ok


Combinatorics problem involving multinomial theorem

Question: here is my problem:

4 digits are picked randomly (from 0 to 9), in how many combinations can you have only 2 different digits? Meaning that I would have let us say 2,2,4,4 or 5,5,5,8.

So the way I wanted to do this was imagining that the digits were actually like 4 oranges going to 10 children and how many possibilities are there for only 2 children getting oranges. So I figured this would be separating the groups first so
10 choose 8 choose 1 choose 1 x 4 choose 2 choose 2

for the possibilities where both children get 2 oranges. And now for the possibilities where 1 of the children gets 3 and the other gets 1, would be
10 choose 8 choose 1 choose 1 x 4 choose 3 choose 1.

Unfortunately this gives me $$\frac{10!}{8!}\times \frac{4!}{2!2!}+\frac{10!}{8!}\frac{4!}{3!} = 900$$ possibilities whereas the right answer is $630.
Can anyone help me out please! and with this type of solving the problem preferably as I am trying to figure out the subtleties of the multinomial theorem!
Comment: See [math notation guide](http://math.stackexchange.com/help/notation).
Answer: As you point out, we can have a $2$-$2$ split or a $3$-$1$ split.
For $2$-$2$ splits, we choose $2$ numbers from $10$. There are $\binom{10}{2}=45$ ways to do this.  For each choice, there are $\binom{4}{2}$ ways of arranging them in a row, total $270$.
For $3$-$1$ splits, the number we have $3$ of can be chosen in $10$ ways, and the number we have $1$ of can be chosen in $9$ ways.  Then the digits can be arranged in $4$ ways, total $360$.
Remark: If we are not interested in counting ordered arrangements, then the total is $135$. To produce $630$, we need to take order into account.


how to SSH to Wireguard server from Windows client with active VPN connection?

Question: I have Wireguard server on Rocky 8.7, when I connect to the server I route all client traffic through Wireguard
this is quotes from setup script, of course all variables is set (and all works good)
config for Wireguard server:
cat << EOF | sudo tee -a /etc/wireguard/${WG_INTERFACE}.conf
[Interface]
PostUp = wg set %i private-key /etc/wireguard/${WG_INTERFACE}.pk
Address = 10.0.0.1/32
ListenPort = ${WG_PORT}
[Peer]
PublicKey = ${WG_CLIENT_PUBLIC_KEY}
AllowedIPs = 10.0.0.2/32
EOF

config for Wireguard client:
cat << EOF >> ~/wg_client.conf
[Interface]
PrivateKey = ${WG_CLIENT_PRIVATE_KEY}
Address = 10.0.0.2/32
DNS = 18.104.22.168
[Peer]
PublicKey = ${WG_SERVER_PUBLIC_KEY}
Endpoint = ${SERVER_IP}:${WG_PORT}
AllowedIPs = 0.0.0.0/0
PersistentKeepalive = 25
EOF

server settings for traffic redirection and firewall:
echo 'net.ipv4.ip_forward=1' | sudo tee -a /etc/sysctl.conf 1>/dev/null
sudo firewall-cmd --zone=public --add-port=${WG_PORT}/udp --permanent
sudo firewall-cmd --zone=internal --add-interface=${WG_INTERFACE} --permanent
sudo firewall-cmd --zone=public --add-rich-rule='rule family=ipv4 source address=10.0.0.0/24 masquerade' --permanent

the question is: how to SSH to Wireguard server from Windows client with active VPN connection?
Answer: currently I have one working solution, which seems not optimal
on client config instead AllowedIPs = 0.0.0.0/0 i put other line, where I subtract from 0.0.0.0/0 IP address of Wireguard server
why solution seems not optimal? because after IP subtraction I get a very long line that is inconvenient to read
for example my server IP address is: 188.8.131.52
for IP subtraction I must use special subnet calculator (for example: https://www.procustodibus.com/blog/2021/03/wireguard-allowedips-calculator/) to get result looking like this:
AllowedIPs = 0.0.0.0/2, 188.8.131.52/3, 220.127.116.11/6, 220.127.116.11/10, 188.8.131.52/11, 18.104.22.168/14, 220.127.116.11/17, 188.8.131.52/18, 126.96.36.199/21, 18.104.22.168/25, 220.127.116.11/26, 220.127.116.11/29, 18.104.22.168/32, 184.108.40.206/31, 188.8.131.52/30, 126.96.36.199/28, 220.127.116.11/27, 18.104.22.168/24, 184.108.40.206/23, 220.127.116.11/22, 220.127.116.11/20, 184.108.40.206/19, 184.108.40.206/16, 126.96.36.199/15, 22.214.171.124/13, 220.127.116.11/12, 22.214.171.124/9, 22.214.171.124/8, 184.108.40.206/7, 18.104.22.168/5, 184.108.40.206/4, 184.108.40.206/1

do you know other, more simple solution?
Comment: That line may actually be wrong.  You're getting that because the calculator can't guess what your real netmask is.  Pick from that line the one that corresponds to your actual netmask.
Comment: with netmask /32 (126.96.36.199/32) line the same
Comment: for 188.8.131.52/24 line is also long
Comment: You probably only need 18.104.22.168/24 and not the rest of what is on that line, assuming that's your actual netmask.  It sounds like you need to study what netmask does to understand how to set this correctly.  Feeding random stuff to ipcalc isn't going to help.
Comment: I need to access all Internet with VPN, and also, with active VPN connection, access to server via SSH