Combinatorial identity: summation of stars and bars

Question: I noticed that the following identity for a summation of stars and bars held for specific $k$ but I was wondering if someone could provide a general proof via combinatorics or algebraic manipulation. I wouldn't be surprised if this is a known result; it looks very similar to the Hockey Stick identity.
$$\sum_{i=0}^k {d+i-1 \choose d-1} = {d+k \choose k}$$
The left can be immediately rewritten as $\sum_{i=0}^k {d+i-1 \choose i}$ if it helps inspire intuition.
Comment: If you replace the RHS with $\binom{d+k}d$, then this is literally the Hockey Stick identity.
Answer: Consider the set $S=\{1,2,\ldots,d,d+1,\ldots,d+k\}$. The right hand side gives us the number of ways selecting a subset of $S$ of $d$ elements.
If we choose such a subset $X$ of $S$ of $d$ elements, the highest element of $X$ can be $d,d+1,\ldots,d+k$. If the highest element of $X$ is $d+i$ then we can find $d-1$ more elements of $X$ from $\{1,2,\ldots,d+i-1\}$. The number of ways that we can do that is ${d+i-1\choose d-1}$. By running $i$ from $0$ to $k$ we have the left hand side of the identity.
Answer: $\newcommand{\bbx}[1]{\,\bbox[15px,border:1px groove navy]{\displaystyle{#1}}\,}
 \newcommand{\braces}[1]{\left\lbrace\,{#1}\,\right\rbrace}
 \newcommand{\bracks}[1]{\left\lbrack\,{#1}\,\right\rbrack}
 \newcommand{\dd}{\mathrm{d}}
 \newcommand{\ds}[1]{\displaystyle{#1}}
 \newcommand{\expo}[1]{\,\mathrm{e}^{#1}\,}
 \newcommand{\ic}{\mathrm{i}}
 \newcommand{\mc}[1]{\mathcal{#1}}
 \newcommand{\mrm}[1]{\mathrm{#1}}
 \newcommand{\pars}[1]{\left(\,{#1}\,\right)}
 \newcommand{\partiald}[3][]{\frac{\partial^{#1} #2}{\partial #3^{#1}}}
 \newcommand{\root}[2][]{\,\sqrt[#1]{\,{#2}\,}\,}
 \newcommand{\totald}[3][]{\frac{\mathrm{d}^{#1} #2}{\mathrm{d} #3^{#1}}}
 \newcommand{\verts}[1]{\left\vert\,{#1}\,\right\vert}$

$\ds{\sum_{i = 0}^{k}{d + i - 1 \choose d - 1} =
{d + k \choose k}:\ {\LARGE ?}}$.

\begin{align}
&\bbox[10px,#ffd]{\sum_{i = 0}^{k}{d + i - 1 \choose d - 1}} =
\sum_{i = 0}^{k}{d + i - 1 \choose i}
\\[5mm] = &\
\sum_{i = 0}^{k}{-\bracks{d + i - 1} + i - 1 \choose i}
\pars{-1}^{i} =
\sum_{i = 0}^{k}\pars{-1}^{i}{-d \choose i}
\\[5mm] = &\
\sum_{i = 0}^{k}\pars{-1}^{i}\bracks{z^{i}}\pars{1 + z}^{-d} =
\bracks{z^{0}}\pars{1 + z}^{-d}
\sum_{i = 0}^{k}\pars{-\,{1 \over z}}^{i}
\\[5mm] = &\
\bracks{z^{0}}\pars{1 + z}^{-d}\,
{\pars{-1/z}^{k + 1} - 1 \over \pars{-1/z} - 1}
\\[5mm] = &\
\bracks{z^{0}}\pars{1 + z}^{-d}\,
{z \over z^{k + 1}}\,{\pars{-1}^{k + 1} - z^{k + 1} \over -1 - z}
\\[5mm] = &\
\bracks{z^{k}}\pars{1 + z}^{-d - 1}\,
\bracks{z^{k + 1} - \pars{-1}^{k + 1}} =
\pars{-1}^{k}\bracks{z^{k}}\pars{1 + z}^{-d - 1}
\\[5mm] = &\
\pars{-1}^{k}{-d - 1 \choose k} =
\pars{-1}^{k}\braces{%
{-\bracks{-d - 1} + k - 1 \choose k}\pars{-1}^{k}}
\\[5mm] = &\ \bbx{d + k \choose k} \\ &
\end{align}
Answer: Starting from
$$\sum_{q=0}^k {d+q-1\choose d-1}$$
we get
$$\sum_{q\ge 0} {d+q-1\choose d-1} [[0\le q\le k]]
= \sum_{q\ge 0} {d+q-1\choose d-1} [z^k] \frac{z^q}{1-z}
\\ = [z^k] \frac{1}{1-z} \sum_{q\ge 0} {d+q-1\choose d-1} z^q
= [z^k] \frac{1}{1-z} \frac{1}{(1-z)^d}
\\ = [z^k] \frac{1}{(1-z)^{d+1}}
= {d+k\choose k}.$$


Getting raw XML response from Java web service client

Question: I am trying to get the raw XML response from a web service, instead of the usual set of POJOs.
I am using a webservice client that I generated (so I have access to the client's code) from a WSDL and some schemas. The client is generated in RAD 7.5, I think using JAX-WS. I've been looking at the client code itself, but I'm not even sure if the client code ever handles raw XML or if it passes it off to other libraries.
Answer: You can do it using
javax.xml.ws.handler.soap.SOAPHandler<javax.xml.ws.handler.soap.SOAPMessageContext>

you can simply get message using SOAPMessageContext#getMessage() and convert message to String using method
   public static String getXmlMessage(SOAPMessage message) throws Exception
   {
         ByteArrayOutputStream os = new ByteArrayOutputStream();
         message.writeTo(os);
         final String encoding = (String) message.getProperty(SOAPMessage.CHARACTER_SET_ENCODING);
         if (encoding == null)
         {
             return new String(os.toByteArray());
         }
         else
         {
            return new String(os.toByteArray(), encoding);
         }
   }

Also you can read here about SOAP handler on client side
Article
Comment: That's going to be a little awkward in my situation. Is there a more graceful way of doing it?
Comment: Ok, though I'm not sure how I can return this string back to my main application.
Comment: I am using this construction in my project for print request/response in logs.
Comment: You can create global variable ArrayList, and put all String to it
Answer: It's not widely documented, but you can use the Dispatch interface to implement JAXWS clients which work directly w/ the XML.  Here and here are some articles for getting started.
Comment: Two last links like broken.


Is it always true that $P(X| Y \text{ OR } Z) \le P(X|Y)$?

Question: Consider the following argument:
If $(X| Y \ \text{OR} \ Z)$ is true, $(X| Y)$ must be true.
For example, if $f(t)=10 $ when $  t=1  $ or $ \ t=0$ is true, then $f(t)=10 $ when $ t=1$ must be true as well.
Therefore, the set of $X$ that make $(X|Y,Z)$ true is a subset of the set of $X$ that make $(X|Y)$ true.
Therefore, $P(X|Y,Z) \le P(X|Y)$
Is this argument correct?
Comment: Welcome Dr. Who. I have edited your question to display math as math, you should check that I have not introduced any errors.
Answer: I assume that in your notation "P(X|Y)" is a conditional probability and that "<=" is an inequality and not an implication. Otherwise, please forget my answer, clarify the question and edit the tags.
I'll give a simple counterexample.
Let's suppose we take a random animal from a hen house with 50 chickens and 50 rabbits, and let's define the following events:
X=The animal has wings.
Y=The animal is a rabbit.
Z=The animal is a chicken.
P(X|Y) = P(X and Y)/P(Y) = (0/100)/(50/100) = 0/50 = 0
P(X|Y or Z) = P(X and (Y or Z))/P(Y or Z) = (50/100)/(100/100) = 50/100 = 0.5
Then P(X|Y or Z) = 0.5 > 0 = P(X|Y)
Comment: I'm afraid it's false, too. Let's see the experiment of taking a random number from the set {1,2,3,4}. X={2,4}, Y={1,2}, Z={1,4}. P(X|Y)=P(X|Z)=1/2 but P(X|Y or Z)=2/3.
Comment: You are right. You win :)
Comment: Thanks for the counterexample! After some thoughts, I think the following altered statement may be true. P(X|Y OR Z) is always smaller than or equal to  the max of  P(X|Y) and P(X|Z). What do you think?


VSCode: Keyboard shortcuts for modifying user settings

Question: I like the idea of CodeLens, VSCode's plugin that tells you reference counts on all your functions & variables. However, when I'm scanning code, the extra vertical margin added to include the "X references" line annoys me enough that I've disabled it. This is a shame, because it's useful information.
I'd like to be able to control whether CodeLens is active via keyboard shortcut. There seem to be no "editor.action.toggleCodeLens" in the keybindings, though, and trying
{ "key": "ctrl+l", "command": "editor.codeLens = false" }
or
{ "key": "ctrl+l", "command": "editor.codeLens = !editor.codeLens" }
produces the error command 'editor.codeLens = false' not found. Is there a way to do this?
Comment: Possible duplicate of [Code Lens Toggle Shortcut?](http://stackoverflow.com/questions/18466475/code-lens-toggle-shortcut)
Comment: I created an extension called [Setting Toggle](https://marketplace.visualstudio.com/items?itemName=Ho-Wan.setting-toggle) which lets me turn the codeLens on and off easily. My extension also lets you toggle up to 3 VS Code settings. You can then assign the "Setting Toggle" command to a keybinding by opening "Keyboard shortcuts".
Answer: Try this extensions: https://marketplace.visualstudio.com/items?itemName=rebornix.toggle
It allows you to setup custom keybindings to toggle any VSCode setting


Como não gravar dados duplicados no MySQL com PHP?

Question: Estou aprendendo PHP e, para começar, estou fazendo um projeto de agenda telefônica, com nome, DDD e telefone.
No entanto, antes dos novos dados ser inserido, como faço para conferir se o mesmo número de telefone já está cadastrado?
Comment: Preferi não responder pois essa lógica fere uma lógica básica desse tipo de negócio. Uma pessoa pode mudar de endereço, e outra ocupar o local e geralmente terá o número de telefone transferido para seu nome. O dono original terá outro número em outro local.. A coisa complica ainda mais se for números móveis pois nem precisa mudar de endereço.. Pessoas trocam de celular constantemente.. vc pode até verificar se o número já existe, porém, impedir um cadastro com base nesse critério acaba engessando o modelo de negócio.
Answer: Para fazer isso basta verificar se o dado que se pretende inserir já existe no banco de dados ou não, eis um exemplo básico.
<?php
if(!$conect=mysqli_connect('localhost','root','','tabela_')) die ('erro ao conectar');
#Recolhendo os dados do formulário
$dado1 = mysqli_real_escape_string($_POST['dado1']);
$dado2 = mysqli_real_escape_string($_POST['dado2']);
# Verificando apenas um campo, no caso dado1.
$sql = $conect->query("SELECT * FROM tabela_ WHERE dado1='$dado1'");
if(mysqli_num_rows($sql) > 0){
echo "Este usuário já existe";
exit();
} else {
 if(!$conect->query("INSERT INTO tabela_ (dado1,dado2) VALUES ('$dado1','$dado2')")) die ('Os dados não foram inseridos');
 echo "Dados inseridos com sucesso";
}

Nesse exemplo se o valor do campo dado1 do formulário já existir nessa linha da tabela ele não é novamente adicionado.
Isso também pode ser resolvido ao criar a tabela.
 CREATE TABLE IF NOT EXISTS tabela_(
  dado1 VARCHAR(255) NOT NULL,
  UNIQUE KEY(dado1) # Aqui especificamos que a linha dado1 será única, e não poderá ter outra de igual valor nessa mesma tabela.
 );

Answer: Existe também uma maneira de se executar diretamente uma query no MYSQL que só inserirá o registro caso o mesmo não exista. É um Insert Condicional.
Exemplo:
$query = "INSERT INTO usuarios(login, senha)
    SELECT '$login_que_nao_pode_duplicar', 123456
    FROM DUAL
    WHERE NOT EXISTS(SELECT login FROM usuarios WHERE login = '$valor_que_nao_pode_duplicar')";

No caso, os valores do primeiro SELECT são os valores que vão ser inseridos.
Já o valor do segundo SELECT é o valor que é verificado se já existe.
Essa query, quando executada, retornará UMA linha afetada caso o valor passado no segundo SELECT (que tem que ser o mesmo do primeiro SELECT) não exista ainda na sua tabela.
Tanto é que, se você executá-la novamente essa mesma query, retornará ZERO linhas afetadas.
Outro exemplo com PDO:
  $pdo = new PDO('mysql:host=localhost;dbname=test', 'root', '');

   $nome = 'Wallace';
   $stmt = $pdo->prepare("INSERT INTO usuarios(login, senha) SELECT '$nome', '123456' FROM DUAL WHERE NOT EXISTS(SELECT login FROM usuarios WHERE login = '$nome')");
   $stmt->execute();

   print_r($stmt->rowCount());

Quando abro a página, o print_r exibe "1". Quando atualizo a página, ele exibe "0".
Ao trocar o nome da variável $nome, você obteria $1 novamente.
Isso significa que a query só inseriu o registro quando eles não existiam. :)
Assim, você poderá fazer a execução dessa query tranquilamente; e, caso retorne "0", você poderá exibir uma mensagem de alerta para o usuário, por exemplo.
Comment: Mesmo utilizando `mysql_*` é possível capturar exceptions e usar a constraint do banco de dados, o paradigma não influencia.
Comment: Não é mais simples capturar a exception de duplicate constraint então ?
Comment: Quando o sistema é todo orientadinho a objeto, sim, @gmsantos
Answer: Você também pode colocar o campo que você não quer repetição como UNIQUE:
ADD UNIQUE INDEX `campo_da_tabela_UNIQUE`

Answer: Crie uma CONSTRAINT.
ALTER TABLE table ADD CONSTRAINT cunique_table_customer_primary UNIQUE (column1, column2)


Error: No such function: sqlcipher_export on iOS

Question: I have installed SQLCipher via pod. but I am getting this error saying No such function: sqlcipher_export. I was using FMDB and for SQLCipher I am using the subspec of it i.e. FMDB/sqlcipher. I have added
<code>#import <SQLCipher/sqlite3.h>
</code>
below is my code:
<code>NSString *docsDir;
NSArray *dirPaths;
dirPaths = NSSearchPathForDirectoriesInDomains
(NSApplicationSupportDirectory, NSUserDomainMask, YES);
docsDir = dirPaths[0];

databasePath = [[NSString alloc] initWithString:[docsDir stringByAppendingPathComponent: @"MyDB.db"]];

NSString *encryptDB = [docsDir stringByAppendingPathComponent:@"MyDB_enc.db"];

const char* sqlQ = [[NSString stringWithFormat:@"ATTACH DATABASE '%@' AS MyDB_enc KEY 'test123';",encryptDB] UTF8String];

//sqlite3 *unencrypted_DB;

if (sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {

    // Attach empty encrypted database to unencrypted database
    sqlite3_exec(database, sqlQ, NULL, NULL, NULL);

    // export database
    sqlite3_exec(database, "SELECT sqlcipher_export('MyDB_enc');", NULL, NULL, NULL); //gives error

    // Detach encrypted database
    sqlite3_exec(database, "DETACH DATABASE MyDB_enc;", NULL, NULL, NULL);

    sqlite3_close(database);
}
else {
    sqlite3_close(database);
    NSAssert1(NO, @"Failed to open database with message '%s'.", sqlite3_errmsg(database));
}

databasePath = [docsDir stringByAppendingPathComponent:@"MyDB_enc.db"];
</code>
can anyone guide me on how to fix this issue
Answer: I was experiencing this issue with POD installation but when I used the sqlite3.h file after compiling the binary it was working fine.


when running gdb get python exceptions

Question: When I try to run gdb, i see below python exceptions.
wanted to know
1. what these python exceptions mean
2. will it impact anyway in gdb debugging or bt analysis.
3. How to resolve these errors.
Traceback (most recent call last):
  File "/usr/share/gdb/python/gdb/__init__.py", line 144, in auto_load_packages
    __import__(modname)
  File "/usr/share/gdb/python/gdb/function/strfns.py", line 105, in <module>
    _MemEq()
  File "/usr/share/gdb/python/gdb/function/strfns.py", line 33, in __init__
    super(_MemEq, self).__init__("_memeq")
LookupError: no codec search functions registered: can't find encoding

Python Exception <type 'exceptions.LookupError'> no codec search functions registered: can't find encoding:
Python Exception <type 'exceptions.LookupError'> no codec search functions registered: can't find encoding:
Python Exception <type 'exceptions.LookupError'> no codec search functions registered: can't find encoding:
Traceback (most recent call last):
  File "/usr/share/gdb/python/gdb/__init__.py", line 144, in auto_load_packages
    __import__(modname)
  File "/usr/share/gdb/python/gdb/command/prompt.py", line 65, in <module>
    _ExtendedPrompt()
  File "/usr/share/gdb/python/gdb/command/prompt.py", line 44, in __init__
    self.value = ''
LookupError: no codec search functions registered: can't find encoding

GNU gdb (GDB) 7.11.1
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "arm-none-linux-gnueabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...

Comment: What is the origin of this GDB? Did you build it yourself?
Comment: @Employed Russian, GDB is built as part of our yocto build for custom embedded board
Answer:
what these python exceptions mean

GDB (when compiled with --enable-python (default)) loads certain builtin embedded Python scripts. This loading fails, because either the GDB make install wasn't performed, or (more likely here) the Python install is incomplete.

will it impact anyway in gdb debugging or bt analysis.

Yes: GDB relies on a lot of embedded Python functionality, and it's likely that you will get these exceptions for almost every command.

How to resolve these errors.

Make sure that you copied complete installation (including data subdirectories and .pyc files) for both the GDB and Python to the system on which you are running GDB.
Alternatively, configuring GDB with --disable-python should clear these errors as well.

when running gdb get python exceptions


The variance of $\left(\frac{kX}{1+kX}\right)$ when $X$ is lognormal

Question: I was wondering if $X$ is lognormal, and $k$ is "small enough", can we conclude that $var\left(\frac{kX}{1+kX}\right)$ is negligible? Notice that
$$var\left(\frac{kX}{1+kX}\right)=k^2var\left(\frac{X}{1+kX}\right).$$
I guess this would depend if it's reasonable to assume that $var\left(\frac{X}{1+kX}\right)$ is bounded or does not go wild when $k\to 0.$ Any thoughts? Thanks!
Answer: If you are asking if $$\lim_{k \to 0^+} \mathrm{Var} \left( \frac{kX}{1+kX} \right) = 0 $$ then this is true. To see this, observe that for $k > 0$, $$\mathrm{Var} \left( \frac{X}{1+kX} \right) = \inf_{c \in \mathbb{R}} \mathbb{E}\left[\left( \frac{X}{1+kX} - c \right)^2\right] \leq \mathbb{E}\left[\left( \frac{X}{1+kX} \right)^2\right] \leq E(X^2) < \infty$$
Hence, it follows that $$\mathrm{Var} \left( \frac{kX}{1+kX} \right) = k^2 \mathrm{Var} \left( \frac{X}{1+kX} \right) \to 0$$
Comment: Will the same hold if $X$ is normal?
Comment: @Heisenberg This argument won't hold as the second-to-last inequality assumed $X \geq 0$. You may be able to prove it for normal $X$ by a direct computation. Intuitively, it should hold, as $kX$ concentrates at zero and $1+kX$ concentrates at $1$.
Answer: Second moment is explicitly $\frac{k^2}{\sigma\sqrt{2\pi}}\int\limits_0^\infty\frac{x}{(1+kx)^2}e^{-\frac{(lnx-\mu)^2}{2\sigma^2}}dx\to 0$, as $k\to 0$.  Therefore variance $\to 0$.
Comment: Will the same hold if $X$ is normal?
Comment: If $X$ is normal, it can be negative so $1+kX$ can be $0$, possibly leading to infinities for mean and variance.  It needs to be checked.


Code Igniter select active record in model not working

Question: I want to select and then var_dump the database rows, but I cant since var_dump is returning the bool(false).
My model: (players.php).
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Players extends CI_Model
{
    private $table_name = 'players';

    function __construct()
    {
        parent::__construct();
    }

    function get($id = FALSE)
    {
        $this->db->select();
        $this->db->where('ban <', time());
        if ( $id )
            $this->db->where('id =', $id);

        $query = $this->db->get($this->table_name);
        return $query->num_rows() == 0;
    }
}

/* End of file test.php */
/* Location: ./application/models/test.php */

My player.php controller:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Player extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();

        $this->load->helper(array('form', 'url'));
        $this->load->library('form_validation');
        $this->load->library('tank_auth');
    }

    public function index()
    {
        $this->load->model('players');
        $this->load->view('template/header');
        $this->load->view('default');
        var_dump($this->players->get());
        $this->load->view('template/footer');
    }
}

/* End of file player.php */
/* Location: ./application/controllers/player.php */

Have you any solutions for that?
Answer: $this->db->where('id =', $id);

is incorrect
$this->db->where('id', $id);

is correct. You don't need the = operand with a normal WHERE =; use operands for <, >, !=
Also,
return $query->num_rows() == 0;

will return bool false if you have more than 0 rows (i.e. if you have any users with ban < time(). Try returning just $query and var_dump'ing that.
Comment: Thanks for your reply. When I just return the `$query` the result looks like this: `object(CI_DB_mysql_result)#21 (8) { ["conn_id"]=> resource(9) of type (mysql link persistent) ["result_id"]=> resource(19) of type (mysql result) ["result_array"]=> array(0) { } ["result_object"]=> array(0) { } ["custom_result_object"]=> array(0) { } ["current_row"]=> int(0) ["num_rows"]=> int(1) ["row_data"]=> NULL }`
Comment: Never mind, just forgot to add `$query->result()`. Thank you :)


Follow-up question: When should you center your data & when should you standardize?

Question: I have a follow up question to MånsT's reply to the "When should you center your data & when should you standardize"-question. ( I cannot leave a comment as I am below the magic "50 reputation".) He says that

In addition to the remarks in the other answers, I'd like to point out that the scale and location of the explanatory variables does not affect the validity of the regression model in any way.
Consider the model $y=\beta_0+\beta_1x_1+\beta_2x_2+…+ϵ $.
The least squares estimators of $\beta_1,\beta_2$,… are not affected by shifting. The reason is that these are the slopes of the fitting surface - how much the surface changes if you change $x_1,x_2$,… one unit. This does not depend on location. (The estimator of $\beta_0$, however, does.)
By looking at the equations for the estimators you can see that scaling $x_1$ with a factor $a$ scales $\beta_1$ by a factor 1/$a$. To see this, note that
$\hat{\beta_1}(x_1)=\frac{\sum_{i=1}^n (x_{1,i}−\bar{x_1})(y_i−\bar{y})}{\sum_{i=1}^n(x_{1,i}-\bar{x_1})^2}.$
Thus
$$ \hat{\beta_1} (ax_1)=\frac{\sum_{i=1}^n (ax_{1,i}−ax_1)(y_i−\bar{y})}{\sum_{i=1}^2(ax_{1,i}−a\bar{x_1})^2}=\frac{a\sum_{i=1}^n (x_{1,i}−\bar{x_1})(y_i−\bar{y})}{a^2\sum_{i=1}^n(x_{1,i}-\bar{x_1})^2}=\frac{\hat{\beta_1}(x_1)}{a}.$$
By looking at the corresponding formula for $\beta_2$ (for instance) it is (hopefully) clear that
this scaling doesn't affect the estimators of the other slopes.

It is clear to me that $\hat{\beta_1}$ is given by the provided expression above. However, this is the $\beta_1$ in the model: $y=\beta_0+\beta_1x.$, as MånsT has clarified by writing $\hat{\beta_1} (x_1)$. Will this argument still hold in the general linear model, given by
$y=\beta_0+\beta_1x_1+\beta_2x_2+…+ϵ $??
Since, in the general linear model, the $\beta$s are given by the normal equations: $\vec{\beta}=(X^t X)^{-1}X^t \vec{y}$  (full rank of $X^t X$ assumed).
So: It is not clear to me that the $\beta_1$ in the model with only one predictor will be the same as the corresponding $\beta_1$ in $\vec{\beta}$. According to http://data.princeton.edu/wws509/notes/c2.pdf, pages 21-24, there is a difference (the author makes the distinction between gross and net effects (gross: $\beta_1$ in one predictor model, net: $\beta_1$ in general linear model)). How will the scale-invariance argument be for the general linear model?
Answer: Suppose a model of the form
$$\mathbb{E}(Y) = f(\beta_0 + \beta_1 x_1 + \cdots + \beta_d x_d)$$
with parameters $(\beta_0, \beta_1, \ldots, \beta_d)$ is fit to data $((x_{i1}, x_{i2}, \ldots, x_{id}, y_i))$ by optimizing some measure of discrepancy between the $y_i$ and the corresponding $\mathrm{x}_i$, as is done (for instance) with least squares, generalized least squares, and maximum likelihood estimators for generalized linear models. Further suppose the optimum is unique.  Write its value as $\hat{\beta} = (\hat{\beta}_0, \hat{\beta}_1, \ldots, \hat{\beta}_d)$.  Then, for any nonzero constants $\sigma_1, \ldots, \sigma_d$ and any constants $\mu_1, \ldots, \mu_d$, it is immediate (by plugging in the values) that
$$\hat{\alpha}_0 = \hat{\beta}_0 - \hat{\beta}_1\mu_1/\sigma_1 - \cdots - \hat{\beta}_d\mu_d\sigma_d$$
and
$$(\hat{\alpha}_1, \ldots, \hat{\alpha}_d) = (\hat{\beta}_1/\sigma_1, \ldots, \hat{\beta}_d/\sigma_d)$$
is the unique optimum for the model
$$\mathbb{E}(Y) = f(\alpha_0 +\alpha_1 z_1 + \cdots + \alpha_d z_d)$$
with parameters $(\alpha_1, \ldots, \alpha_d)$ and new (affinely) transformed variables
$$z_i = \sigma_i x_i + \mu_i.$$
Even when the optimum is not unique, any optimum for the first model is still converted to some optimum for the second model.  It just might not be the same optimum returned by a computer program.  This can happen when the parameters are not identifiable, for instance.
When the constant term $\beta_0$ is not included in the model, it is no longer possible to carry out this reasoning unless all the $\mu_i=0$. Even then, the estimated coefficients $\hat{\beta}_i$ still transform contravariantly with respect to rescaling of the variables $x_i$.
Comment: Thanks, whuber, very much appreciated. Just to be 100 % sure, you say that $$f(\alpha_0 +\alpha_1 z_1 + \cdots + \alpha_d z_d)=f(\beta_0 + \beta_1 x_1 + \cdots + \beta_d x_d),$$ since unique minimum is assumed, $ \alpha_0 +\alpha_1 z_1 + \cdots + \alpha_d z_d=\beta_0 + \beta_1 x_1 + \cdots + \beta_d x_d$ and you then identify the different coefficients "term-wise" (coefficients in front of the $x_1$s must be the same, etc)?


Prove by induction $ \sin x + \sin 2x + ... + \sin nx = \frac {\sin (\frac {n + 1} {2} x)} {\sin \frac{x}{2}} \sin \frac{nx}{2} $

Question:
Prove by induction
  $$ \sin x + \sin 2x + ... + \sin nx = \frac {\sin (\frac {n + 1} {2} x)} {\sin \frac{x}{2}} \sin \frac{nx}{2} $$

What I have for now:
$$  \frac {\sin (\frac {n + 1} {2} x)} {\sin \frac{x}{2}} \sin \frac{nx}{2} + \sin(n + 1)x =  \frac {\sin (\frac {n + 2} {2} x)} {\sin \frac{x}{2}} \sin \frac{(n + 1)x}{2}$$
Letting $y = \frac {(n + 1)x} {2} $
$$\frac {\sin y} {\sin \frac{x}{2}} \sin (y - \frac{x}{2}) + \sin2y =
\frac {\sin (y + \frac {x} {2} )} {\sin \frac{x}{2}} \sin y $$
Then I used $\sin (\alpha + \beta)$ and $\sin (\alpha - \beta)$ formulas, bit they didn't help.
Answer: You are almost there, but use $\sin 2y = 2\sin y\cos y$, considering your left hand side we get:
$$\frac {\sin y} {\sin \frac{x}{2}} \sin (y - \frac{x}{2}) + \sin2y  =
\frac {\sin y} {\sin \frac{x}{2}} \sin (y - \frac{x}{2}) + 2\sin y\cos y = $$
$$\left(\frac {\sin (y-\frac{x}{2})} {\sin \frac{x}{2}} +2\cos y\right)\sin y = \left(\frac {\sin (y-\frac{x}{2}) +2\cos y\sin\frac{x}{2}} {\sin \frac{x}{2}}\right)\sin y =$$
Now use the subtraction of angles formula $\sin (\alpha-\beta)$:
$$=\left(\frac {\sin y\cos \frac{x}{2} - \cos y \sin \frac{x}{2} +2\cos y\sin\frac{x}{2}} {\sin \frac{x}{2}}\right)\sin y = \left(\frac {\sin y\cos \frac{x}{2} +\cos y\sin\frac{x}{2}} {\sin \frac{x}{2}}\right)\sin y =$$
And lastly use the addition of angles formula $\sin(\alpha+\beta)$:
$$=\left(\frac {\sin (y+ \frac{x}{2}) } {\sin \frac{x}{2}}\right)\sin y $$
Which is what you had on your right hand side, and thus the induction is done.
Answer: You can also see that
\begin{align}
\sum_{k=0}^{n}\sin kx & =\Im \sum_{k=0}^{n}\mathrm{e}^{\mathrm{i}kx}\\
& = \Im \sum_{k=0}^{n}\left(\mathrm{e}^{\mathrm{i}x}\right)^k\\
& = \Im\frac{\left(\mathrm{e}^{\mathrm{i}x}\right)^{n+1}-1}{\mathrm{e}^{\mathrm{i}x}-1}\\
& = \Im\frac{\mathrm{e}^{\mathrm{i}(n+1)x}-1}{\mathrm{e}^{\mathrm{i}x}-1}\\
& = \Im\frac{\mathrm{e}^{\mathrm{i}\frac{n+1}{2}x}}{\mathrm{e}^{\mathrm{i}\frac{x}{2}}}\frac{\mathrm{e}^{\mathrm{i}\frac{n+1}{2}x}-\mathrm{e}^{-\mathrm{i}\frac{n+1}{2}x}}{\mathrm{e}^{\mathrm{i}\frac{x}{2}}-\mathrm{e}^{-\mathrm{i}\frac{x}{2}}}\\
& = \Im\mathrm{e}^{\mathrm{i}\frac{nx}{2}}\frac{\sin\left(\frac{n+1}{2}x\right)}{\sin\left(\frac{x}{2}\right)}\\
& = \sin\left(\frac{nx}{2}\right)\frac{\sin\left(\frac{n+1}{2}x\right)}{\sin\left(\frac{x}{2}\right)}.
\end{align}
Comment: This is not induction, but a direct (maybe easier) way to derive the equality.
Comment: Also we can obtain the same result for the cos.
Comment: @HamedBaghalGhaffari Indeed! This is also a way to compute the Dirichlet's kernel, in particular used for Fourier's series.
Comment: Yes it is which is not good kernel. My master's thesis had some kernels like this.


Issues with custom redirect url using tokens when form field is empty

Question: I am trying to use Drupal webforms with tokens to build out a redirect url for my form submissions. Everything works great when all fields are populated, but if a field is left empty the redirect does not happen. Promo code is an optional field. This is with Webform 6.x-3.14
Redirect URL: <code>%value[app_url]/user/new?email=%value[email_address]&first_name=%value[first_name]&last_name=%value[last_name]&promo_code=%value[promo_code]</code>
Answer: I ended up writing a custom module to do the post using the following code as a starting point
http://www.midwesternmac.com/blogs/jeff-geerling/integrate-webform-3x-paypal


What is a basis for the common equational identities of $(\mathbb{R};*,0)$, $(\mathbb{R};*,1)$, and $(\mathbb{R};*,-1)$?

Question: Consider the three algebraic structures $(\mathbb{R};*,0)$, $(\mathbb{R};*,1)$, and $(\mathbb{R};*,-1)$, where $*$ denotes multiplication. What is a basis for the equational identities those structures have in common? I conjecture that these identities are enough: $x*y=y*x$, $x*(y*z)=(x*y)*z$, and $r*(r*r)=r$, where $r$ is the constant symbol. Is this true, or do we need more?
Answer: Yes, this is correct.
Via the associative and commutative identities, any term can be thought of as having the form $$\left(\prod_{i\in I}x_i^{a_i}\right)\cdot r^b$$ for some finite set of variable indices $I$, some choices of positive integer powers $a_i$ ($i\in I$), and some nonnegative integer power $b$.
Now suppose I have two terms of the above form, $$t=\left(\prod_{i\in I}x_i^{a_i}\right)\cdot r^b\quad\mbox{and}\quad t'=\left(\prod_{i\in I'}x_i^{a_i'}\right)\cdot r^{b'}.$$ It's easy to see that $t=t'$ holds in $(\mathbb{R};*,-1)$, and this latter condition holds iff we have $I=I'$ and $a_i=a_i'$ for all $i\in I$ and $b\equiv_{mod\, 2} b'$ (apologies for nonstandard notation, but the standard notation is quite inconvenient in my opinion). Meanwhile, if exactly one of $b,b'$ is zero, then $t=t'$ fails in $(\mathbb{R};*,0)$, and if both $b$ and $b'$ are nonzero then $t=t'$ holds in $(\mathbb{R};*,0)$ if $t=t'$ holds in $(\mathbb{R};*,-1)$.
Putting all of the above together, the common equational theory of the three structures in question consists of the commutativity and associativity equations plus all equations of the form $t=t'$ for $t,t'$ as above with either $b=b'=0$ or $b\not=0\not=b'$. Since this can be deduced from the theory you've written (exercise), your guess is correct.


Probability of drawing a number smaller than the previous one in a urn of n balls

Question: Anne is playing the following game: She draws balls from an urn containing n balls labeled from 1 to n. The balls are drawn without replacement and with equal probability. The game ends as soon as she draws a ball with a smaller number than the previous one. Anne earns 1 Euro for each ball drawn.
(a) Let Xk be the indicator variable for 1 ≤ k ≤ n defined as follows: Xk = 1 if Anne wins at least k Euros, and 0 otherwise. Determine the density of Xk.
Solution proposal:
Let Ek be the event that Anne wins at least k Euros. We consider the sequence of n numbers that would result if Anne were to draw all the remaining balls from the urn even after the game ends. For such a sequence to yield a win of at least k Euros, the first k - 1 numbers must be sorted in ascending order. There are n choose (k-1) ways to select the set of the first k - 1 numbers, and for each selection, the order is uniquely determined. However, the remaining n - k + 1 numbers can be arranged in any order, which corresponds to (n - k + 1)! permutations.
Since all n! sequences are equally likely, the probability of Ek, denoted as Pr[Ek], can be calculated as follows:
Pr[Ek] = (n choose (k-1)) * (n - k + 1)! / n!
Simplifying the expression, we have:
Pr[Ek] = n! / ((k-1)! * (n - k + 1)! * n!) = 1 / (k-1)!
The density of the indicator variable fXk(x) is:
fXk(x) = 1 / (k-1!) for x = 1
fXk(x) = 1 - (1 / (k-1)!) for x = 0
0 otherwise.
I have the solution but I dont really understand how they have calculated it. Doesnt nCk-1 represent unordered set possibilities? Why do they have to be ascending?  Can anyone give me a intutive explanation? And also suggestions to find similar problems like these to practice? Is there any other ways to solve this problem?
Comment: *Why do they have to be ascending?* Because you want the probability that Anne wins at least $k$ Euros. If the first $k-1$ were not ascending, the process would have ended earlier, preventing Anne from winning $k$ Euros.
Comment: For some basic information about writing mathematics at this site see, *e.g.*, [here](/help/notation), [here](//math.meta.stackexchange.com/q/5020), [here](//meta.stackexchange.com/a/70559) and [here](//math.meta.stackexchange.com/q/1773).
Answer: Pick k numbers in a sequence. In order that each number is larger than the previous one, all k numbers must be sorted. There are k! arrangements so the probability is 1 / k!.
Anne wins exactly k euros if the first k-1 numbers are sorted but the last one is not the largest one, the probability is 1/(k-1)! * (k-1)/k or (k-1) / k!. The exception is k=n where she cannot draw an n+1st number, so the probability is k/k! instead.
Note that all the n-k numbers that are not drawn are irrelevant to the calculation.
Careful addition shows that Anne wins at least k euros with probability 1 / (k-1)!, this is easily shown by calculating the probability of at least k in the order k=n, k=n-1 etc.


Shopify outputs multiple tags when looping

Question: I have a product with about 10 tags and I'm trying to check if a product tag equals 'OurPrice' and if it does display Our Price otherwise display Sale. Im using this code:
<code>{% for tag in product.tags %}
 {% if tag == 'OurPrice' %}Our Price:
 {% else %}Sale:
 {% endif %}
{% endfor %}
</code>
I'm only wanting it to display one or the other, currently i'm getting Sale:Sale:Sale:Sale:Sale:Sale:Sale:Sale:Sale:Sale:Sale:Our Price:Sale:
Is there a way to fall check for this?
EDIT: I now have:
<code>{% assign isOurPrice = False  %}
{% for tag in product.tags  %}
 {% if tag == 'OurPrice' %}Our Price:{% assign isOurPrice = True  %}
 {% endif %}
{% endfor %}
{% if isOurPrice == False %}Sale:
{% endif %}
</code>
which displays Our Price: Sale: which is displaying Sale when it shouldn't. Any ideas?
Answer: <code>{% $isOurPrice = False;  %}
{% for tag in product.tags  %}
 {% if tag == 'OurPrice' %}Our Price:
 {% $isOurPrice = True; %}
 {% endif %}
{% endfor %}
{% if $isOurPrice == False %}Sale:
{% endif %}
</code>
Very easily you can remove the 'Sale:' from the <code>{ else</code>}. To output if it's a sales price only.
Comment: i tried this, better but im still getting Our Price: Sale: any idea why?
Comment: @Alex.. cDima has not mentioned the line to flip `$isOurPrice` to `true`.
Comment: @AlexMurray - fixed a line, please try again
Answer: Turns out shopify offer code for this - 'contains'
<code>{% if product.tags contains "OurPrice" %}
  Our Price:
{% else %}
  Sale:
{% endif %}
</code>


adding to my arraylist with out overriding it in vb

Question: i just asked a question and i modified my my code accordingly. Something is very wrong  with the way im writting my page load. my aim is to initialize the array only the first time and then to keep on incrementing it. can you help?
This is the code I used:
Imports AjaxControlToolkit
Imports System.Data.SqlClient
Imports System.Configuration

Partial Class Shtick

    Inherits System.Web.UI.Page
    Dim conn As SqlConnection
    Dim comm As SqlCommand
    Dim reader As SqlDataReader
    Dim purimConnection As String = ConfigurationManager.ConnectionStrings("Purim").ConnectionString
    Dim ItemSelect As New ArrayList()

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If ItemSelect.Count >  0 Then
            ItemSelect = New ArrayList()
            Session("itemInCart") = ItemSelect
        End If

        If Not IsPostBack Then
            FillShtickList()

        End If

    End Sub

    Protected Sub FillShtickList()

        Dim conn As SqlConnection
        Dim comm As SqlCommand
        Dim reader As SqlDataReader
        Dim purimConnection As String = ConfigurationManager.ConnectionStrings("Purim").ConnectionString
        conn = New SqlConnection(purimConnection)
        comm = New SqlCommand("SELECT RTRIM(ProductPrice) AS Price, ProductName, ProductImage, ProductID, ProductDescription FROM Products", conn)

        Try
            conn.Open()
            reader = comm.ExecuteReader()
            ShtickDataList.DataSource = reader
            ShtickDataList.DataBind()
            reader.Close()

        Finally
            conn.Close()

        End Try
    End Sub

    'Protected Sub ShtickDataList_ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewItemEventArgs) Handles ShtickDataList.ItemCreated
    '    'If e.Item.ItemType = ListItemType.Item Then
    '    '    Dim pce As ModalPopupExtender = e.Item.FindControl("PopupControlExtender1")
    '    '    Dim behaviorID As String
    '    '    behaviorID = "pce_" & e.Item.DataItemIndex
    '    '    pce.BehaviorID = behaviorID
    '    '    Dim img As Image = e.Item.FindControl("PI")

    'item select = which item was selected

    Dim Quantities As New ArrayList()
    Dim itemQtyOrdered As Integer

    Public Sub ShtickDataList_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.ListViewCommandEventArgs) Handles ShtickDataList.ItemCommand

        If e.CommandName = "ViewCart" Then
            Response.Redirect("~/ShoppingCart.aspx")
        End If

        If e.CommandName = "addToCart" Then
            Dim itemQuantity As DropDownList = e.Item.FindControl("QuantityDropDown")
            itemQtyOrdered = itemQuantity.SelectedValue
            ItemSelect.Add(e.CommandArgument)
            Quantities.Add(itemQtyOrdered)

            Session("itemInCart") = ItemSelect
            Session("quantities") = Quantities

            viewInvoice()

        End If

    End Sub

    Protected Sub viewInvoice()

        Dim itemSelected As ArrayList = DirectCast(Session("itemInCart"), ArrayList)
        Dim QuantityofItem As ArrayList = DirectCast(Session("quantities"), ArrayList)

        Dim conn As SqlConnection
        Dim comm As SqlCommand
        Dim reader As SqlDataReader
        Dim purimConnection2 As String = ConfigurationManager.ConnectionStrings("Purim").ConnectionString
        conn = New SqlConnection(purimConnection2)

        comm = New SqlCommand("SELECT ProductName FROM Products WHERE ProductID = @ProductID", conn)

        'Dim i As Integer
        'For i = 0 To ItemSelect.Count - 1
        comm.Parameters.Add("@ProductID", Data.SqlDbType.Int)
        comm.Parameters("@ProductID").Value = (ItemSelected.Count - 1)

        'Next

        Try
            conn.Open()
            reader = comm.ExecuteReader()
            ViewCartlink.Text = "View Cart: (" & ItemSelected.Count & ")"

        Finally
            conn.Close()
        End Try
    End Sub

End Class

 End Try
    End Sub

End Class

 = CType(Session("itemInCart"), ArrayList)
            'al.Add(SS)
            'Session.Add("itemInCart", al)

            viewInvoice()

        End If

    End Sub

    Protected Sub viewInvoice()

        'Dim itemSelected As ArrayList = DirectCast(Session("itemInCart"), ArrayList)
        'Dim QuantityofItem As ArrayList = DirectCast(Session("quantities"), ArrayList)

        Dim conn As SqlConnection
        Dim comm As SqlCommand
        Dim reader As SqlDataReader
        Dim purimConnection2 As String = ConfigurationManager.ConnectionStrings("Purim").ConnectionString
        conn = New SqlConnection(purimConnection2)

        comm = New SqlCommand("SELECT ProductName FROM Products WHERE ProductID = @ProductID", conn)

        Dim i As Integer
        For i = 0 To ItemSelect.Count - 1
            comm.Parameters.Add("@ProductID", Data.SqlDbType.Int)
            comm.Parameters("@ProductID").Value = ItemSelect(i)

        Next

        Try
            conn.Open()
            reader = comm.ExecuteReader()
            ViewCartlink.Text = "View Cart: (" & ItemSelect.Count & ")"

        Finally
            conn.Close()
        End Try
    End Sub

End Class

M(ProductPrice) AS Price, ProductID, ProductName FROM Products WHERE ProductID = @ProductID", conn)
        comm = New SqlCommand("Insert into orders (UserID, ProductID, quantity) values (1, @ProductID, @Quantity)", conn)
        comm.Parameters.Add("@ProductID", Data.SqlDbType.Int)
        comm.Parameters("@ProductID").Value = item
        comm.Parameters.Add("@Quantity", Data.SqlDbType.Int)
        comm.Parameters("@Quantity").Value = qty

        'Dim i As Integer
        'For i = 0 To ItemSelect.Length - 1
        '    comm.Parameters.Add("@ProductID", Data.SqlDbType.Int)
        '    comm.Parameters("@ProductID").Value = ItemSelect(i)
        'Next
        Try
            conn.Open()
            comm.ExecuteNonQuery()
            'reader = comm.ExecuteReader()
            'ShoppingList.DataSource = reader
            'ShoppingList.DataBind()
            'reader.Close()
        Finally
            conn.Close()
        End Try
    End Sub

Comment: Please ask a more specific question and give a far more concise example.
Comment: this is my exact code. I am trying  to make my itemSelect array initialize the first time I click the button and it should increment evertime therafter
Comment: All of that code is necessary to increment a variable?
Comment: Even if it was all relevant to your problem, the second half of it is all messed up, so it's unreadable.
Comment: What exactly do you mean by incrementing an `ArrayList`?  I understand what incrementing an integer is, but incrementhing a list doesn't make sense--at least not without further explanation.
Comment: ok. I want to add an item to my arraylist every time I call the function.
Comment: Also if your not constrained to .net 3.5 or less you may want to use the lazy(of t) class to handle the initialisation.
Comment: Ann consider using the list(of t) class insted of arraylist
Comment: Lazy(of t) will initialise the value the first time you access its value property, list(of t) constrains the values to a type
Comment: how do i do it. I never heard of the list(of t)
Comment: @user2120280 is a generic replacement for the arraylist, see http://msdn.microsoft.com/en-gb/library/6sh2ey19.aspx
Answer: In the code:
If ItemSelect.Count >  0 Then
    ItemSelect = New ArrayList()
    Session("itemInCart") = ItemSelect
End If

You have a more than where you should have a less than. The arraylist only initialises when there is an item in the array. So you only initialise the array after it is initialised. WHat you need is:
If ItemSelect.Count >  0 Then
    ItemSelect = New ArrayList()
    Session("itemInCart") = ItemSelect
End If


Defining a "messagle handler" in Postfix

Question: We are using Postfix for mail delivery and I am trying to make a shell script handle an email sent to firstname.lastname@example.com.
Is there a way to do this and how?
I am trying to create an email-based front-end for a bulletin board. The users have split into two factions: those who would like to use the forum and those who prefer using mailing list. The idea is to create a solution that would please both groups by sending an email notification about the new post (this is the easy part) and also allowing people to post via email, where the metadata (such as topic id) would be encoded in the email address.
Answer: in /etc/aliases
you should be able to alias to a script like so
<code>firstname.lastname@example.com: |"/path/to/ScriptOrExecutableHere"
</code>
I did this with my Trac installation and it worked like a charm...
EDIT: Oh...i didn't realize you were going to be aliasing dynamic addresses...I think you'd need a script to alias the e-mail addresses as forum threads are created...
EDIT2:  Actually you might be able to use the catchall for something like this...
I haven't done it but you would alias "@example.org" to the command.  See here for more
Comment: is it possible to have a regexp alias?
Answer: If the example.org email is only used for discussions you could forward whole @example.org to your script. Or you could use @discussions.example.org.
Answer: Postfix's Before-Queue Content Filter can help:
http://www.postfix.org/SMTPD_PROXY_README.html
I wrote a post about how you can use it but you can easily adapt it to your needs:
http://returnbooleantrue.blogspot.com/2011/10/google-apps-split-delivery-for-email.html


How to get autocompletion like Stack Overflow

Question: I am trying to implement an autocompletion like Stack Overflow does for tag completion.  however, I tried to view the source and its minified
I am trying to get features like letting the user add any tag, if it exists in the list then fine, or else add it to the database.
Are there examples out there that would show how to get something like this done? or can I somehow view the non minified version of the source?
Comment: They use a modified version of the [jQuery autocomplete plugin](http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/) I believe, but since that is deprecated you should be using jQuery UI autocomplete like what Frederic says
Answer: You can look into jQuery UI Autocomplete.
The complete source code is available in their Git repository.
Comment: i looked into jquery UI autocomplete examples however, there is no example that shows adding elements that don't already exist in the list.  Furthermore, user has to click up down arrow or select the item from the list.  meaning as you type, the item is not already preselected
Comment: hmm looking at multiple, remote example http://jqueryui.com/demos/autocomplete/#multiple-remote I guess I can send the whole list to backend and loop through it, if it does not exist then add it. however, still would like preselection as the user types rather than user having to click on the item they want
Comment: @curtis, that's why I thought you wanted a link to the unminified source, i.e. to understand it and add the behavior you want to implement. The code of StackOverflow is customized in the same way.
Answer: I don't know exactly how to do it, but. .. .
if you look into this answer: jQueryUI: how can I custom-format the Autocomplete plug-in results?
you can see there's a way to fiddle with jQuery's rendering  logic to change how the menu items appear. There's also an internal jQuery function called renderMenu that actually presents the choices.
I haven't tried this but I suppose that by opening up that black box, and either replacing or rejiggering renderMenu and its related functions, you'd be able to do what you want - render just one item, in the actual textbox.
That is where I would start, anyway.

EDIT
I looked into the autocomplete stuff again in jQuery UI. It seems pretty straightforward to replace the menu display logic by inserting a custom response() function.
Here's what I did:
// display the first item in the list of possible completions
var myResponse =  function( items ) {
    var itemToSuggest, p1, p2;
    if (items.length === 0) {return;}
    itemToSuggest = items[0];
    this.element.val( itemToSuggest );
    p1 = this.term.length;
    p2 = itemToSuggest.length;
    setSelectionRange(this.element[0], p1, p2);
};

var oldFn = $.ui.autocomplete.prototype._response;
$.ui.autocomplete.prototype._response = myResponse;

Working example
Comment: thats interesting but why it is not showing all the items that are available?
Comment: I built on top of your working example and had a new question: http://stackoverflow.com/questions/6165647/jqueryui-items-getting-erased-when-adding-an-item-that-doesnt-exist
Comment: sorry, curtis I misunderstood the question. I thought you wanted a one-word completion in the text box, *instead of* the drop down menu.  Maybe what you want is a a suggestion in the text box *in addition to* the dropdown menu.
Answer: Probably something like Chosen would do the job nicely
http://harvesthq.github.com/chosen/
Answer: Use the autofocus of the jQuery UI Autocomplete. This should automatically focus on the first found item in the list.
Auto focus


How to cancel an order transition if failure is detected in Commerce 2 / State Machine

Question: I'm trying to plug into order transitions in order to send my order to a custom fulfillment system.
I have a transition called "send_to_fulfillment", and order states "reviewing" and "sent_to_fulfillment".
I'm hooking into the commerce_order.send_to_fulfillment.pre_transition event. What I can't figure out is how to cancel the transition if the process fails. I can certainly just throw an exception and let the site die, but I'd prefer to be able to elegantly stop the transition and inform the user of the error.
Any tips? I've tried WorkflowTransitionEvent::stopPropagation which didn't do it, and I can't seem to find it documented anywhere.
Answer: We don't have a "cancel" or "reverse" feature right now, but it would be worth a feature request in the State Machine queue. The main thing you / we'll need to overcome is what to do in the event a transition in progress has already saved data, triggered 3rd party services, etc. Presumably, there are certain things that should prevent a transition from being reversed (e.g. I've refunded a payment card and therefore must move the order to a canceled or at least unpaid state). However, other things may fall somewhere in the middle ... be allowable and not prevent reversal.
Lisa had a great idea, too, in that you could define the reverse transition explicitly yourself and trigger it in the event that you had a failure condition in your active transition. That would allow you to encode your own logic for checking / reversing transition side effects.
Comment: Thanks for the response Ryan. I hadn't really considered the complications and structured my application a bit differently where this isn't required. I did create an issue on the project, if anyone finds this that is where any discussion will probably be in the future: https://www.drupal.org/project/state_machine/issues/3016752


Find all sequences $x_1,x_2,\dots,x_n$ of distinct positive integers such that $\frac{1}{2}=\frac{1}{x_1^2}+\frac{1}{x_2^2}+\dots+\frac{1}{x_n^2}$

Question:
Find all sequences $x_1,x_2,\dots,x_n$ of distinct positive integers such that $$\frac{1}{2}=\frac{1}{x_1^2}+\frac{1}{x_2^2}+\dots+\frac{1}{x_n^2}\tag{1}.$$

This is 3rd problem from 1st day of 16-th Hungary–Israel Binational Mathematical Competition 2005. How to solve this?
I couldn't find official solution, only couple of posts on AoPS with no complete solution, such as aops1 and aops2. Some examples of $(x_1,x_2,\dots,x_n)$ found there are
$$
(2,3,4,5,7,12,15,20,28,35),\\
(2,3,4,6,7,9,12,14,21,36,45,60),\\
(2,3,4,5,8,10,15,20,24,30,40,60,120)
$$
Since $\sum_{i=3}^{\infty} \frac{1}{i^2}<\frac{1}{2}$, we know $\frac{1}{2^2}$ will be always in the sum. Also multiplying out $(1)$ to get rid of fractions and inspecting modulo $x_i^2$, we see $2(x_1\cdots x_{i-1}x_{i+1}\cdots x_n)^2 \equiv 0 \pmod{x_i^2}$, so divisors of each of $x_i$ must "split" among other $x_j$'s (and $2$), but I don't think that helps much.
Edit: As noted by WhatsUp in comments, there is relevant problem in Project Euler. There is actually also one that is almost identical, but with limited search range, specifically https://projecteuler.net/problem=152. So it might help to think about this problem in similar manner, letting $x_n \leq M$ and then characterize solutions with these constrains. Caution, the following spoils the above mentioned Project Euler problem.

 We can convert this to more computationally manageable diophantine equation by multiplying $(1)$ by $2\text{lcm}(x_1,x_2,\dots,x_n)^2$ instead of $2(x_1x_2\cdots x_n)^2$. For example considering $\text{lcm}(2,3,4,5,7,12,15,20,28,35)=420$, first example can be written as $$420^2=2(210^2+140^2+105^2+84^2+60^2+35^2+28^2+21^2+15^2+12^2).$$ Then by the construction, all the squares on the right are divisors of the square on the left. Also, square on the left is just square of one of divisors of $\text{lcm} (2,3,\dots,M)$, if we have $M \geq 35$. This leads to following reformulation of the problem:Find all sequences $y_1,y_2,\dots,y_n$ of distinct positive integers such that $$m^2=2(y_1^2+y_2^2+\dots+y_n^2)\tag{2},$$ where $m=\text{lcm}(y_1,y_2,\dots,y_n)$.So in principle, for fixed $M$ and $x_i \leq M$, we can find $\text{lcm}(2,3,\dots,M)$, and then enumerate its divisors effectively using prime factorization (using that its prime factors will be $p \leq M$). Then additionally, we can notice that not all primes $p$ can be present in these numbers. Indeed, if we have $p> M/2$, then by earlier observation, it would have to divide at least two $x_i$'s. Smallest of them can be $x_i=p$, with next smallest $x_j=2p>M$, impossible. In similar way, lots of other primes can be ruled out for $M=80$, by realizing they would require to be split among at least $3$ of $x_i$'s (try $37$).While these ideas allow us to significantly speed up the search, it is still hard to say which factorizations will satisfy $(2)$ without actually checking the values...
Comment: In addition to requiring 2, you need either 3 or 4 since $\sum_{i=5}^{\infty} 1/i^2 < 1/4$.
Comment: This Project Euler problem is also relevant: https://projecteuler.net/problem=689
Comment: Other sequence was found.
$s=2 \times3 \times4 \times11 \times13 \times17.$
$[2, 3, 4, 6, 8, 11, 12, 13, 17, 22, 24, 33, 34, 39, 44, 51, 52, 68, 88, 102, 104, 132, 136, 143, 156, 187, 204, 221, 264, 286, 312, 374, 408, 429, 442, 561, 572, 663, 748, 858, 884, 1122, 1144, 1326, 1496, 1716, 1768, 2244, 2431, 2652, 3432, 4488, 4862, 5304, 7293, 9724, 14586, 19448, 29172, 58344]$
Comment: @WhatsUp You've reminded me of another old project euler problem which actually matches closely to this problem, I've updated the post, maybe ideas to solve that problem could lead to this (but I doubt it).
Comment: @Tomita Very nice, how the hell did you find it?
Comment: My method is same as below link's one.
https://artofproblemsolving.com/community/c6h141121p798082

$(1+(\frac{1}{2})^{2})(1+(\frac{1}{3})^2)(1+(\frac{1}{4})^2)(1+(\frac{1}{11})^2)(1+(\frac{1}{13})^2)(1+(\frac{1}{17})^2)-1-\frac{1}{2}=\frac{1379}{736164}=(\frac{1}{26})^2+(\frac{1}{66})^2+(\frac{1}{78})^2$
Exclude $1$, $26$, $66$ and $78$ from the set all divisors of $s=2 \times3 \times4 \times11 \times13 \times17$, then we get a solution.
Comment: Other sequence was found.
$s=2 \times3 \times4 \times7 \times11 \times13.$
$[2, 3, 4, 6, 8, 11, 12, 14, 21, 22, 24, 26, 28, 33, 42, 44, 52, 56, 77, 78, 84, 88, 91, 104, 132, 143, 154, 156, 168, 182, 264, 273, 286, 308, 312, 364, 429, 572, 616, 728, 858, 924, 1001, 1092, 1144, 1716, 1848, 2002, 2184, 3003, 3432, 4004, 6006, 8008, 12012, 24024]$
Answer: I found this paper:
R.Graham, On finite sums of unit fractions.
One of the main corollaries of that paper says the following:

A rational number $p/q$ can be expressed as a finite sum of reciprocals of distinct squares of integers if and only if $$\frac p q \in \left[0,\frac{\pi^2}6 - 1\right)\cup \left[1, \frac{\pi^2}6\right).$$

If this result is correct, then we may conclude that your original problem has infinitely many solutions (just repeatedly write the last term, $\frac 1{x^2}$, as $\frac 1{(x + 1)^2} + r$, where $r < \frac 1{(x + 1)^2}$ and $r$ can again be written as such a sum, by the above result).
Therefore I doubt whether there is a nice answer to this question.
There are only three possibilities:

The proof of Graham contains an error. I consider this unlikely, but I cannot guarantee the correctness, since I haven't thoroughly read the proof (it's quite complicated). This wiki page also cites this result.

The answer to this question somehow describes infinitely many solution, i.e. one should give a pattern of the solutions, rather than a finite list. This also doesn't look probable to me.

The question is problematic and cannot be answered properly. As it was published as a binational competition problem, it again sounds unlikely; but I think it's the most probable among the three.

I do want to know, whether the error belongs to the paper of Graham or the design of the problem. If anyone knows how to find the official solution to this problem, please do share it!
Comment: @Sil That answer only writes the number as an infinite sum, which is much easier. Here we do need a finite sum.
Comment: I thought about point 3. and I suspect that might be the case, though I still hope for 2. (for example some kind of pattern in terms of divisors of some arbitrary number or something). Interesting article by the way. +1
Comment: Hm similar result as in the article seems to be already on the site, in https://math.stackexchange.com/questions/1007424/finding-the-positive-integer-numbers-to-get-frac-pi-29/1007730#1007730, only it states it is for infinite sums.
Answer: Other sequences were found.
My method is same as below link's one.
https://artofproblemsolving.com/community/c6h141121p798082
Case :$s=2 \times3 \times4 \times11 \times13 \times17.$
\begin{align}
&(1+\frac{1}{2^2})(1+\frac{1}{3^2})(1+\frac{1}{4^2})(1+\frac{1}{11^2})(1+\frac{1}{13^2})(1+\frac{1}{17^2})-1-\frac{1}{2}\\
&=\frac{1379}{736164}\\
&=\frac{1}{26^2}+\frac{1}{66^2}+\frac{1}{78^2}\\
\end{align}
Exclude $1$, $26$, $66$ and $78$ from the set all divisors of $s=2 \times3 \times4 \times11 \times13 \times17$, then we get a solution.
$(2, 3, 4, 6, 8, 11, 12, 13, 17, 22, 24, 33, 34, 39, 44, 51, 52, 68, 88, 102, 104, 132, 136, 143, 156, 187, 204, 221, 264, 286, 312, 374, 408, 429, 442, 561, 572, 663, 748, 858, 884, 1122, 1144, 1326, 1496, 1716, 1768, 2244, 2431, 2652, 3432, 4488, 4862, 5304, 7293, 9724, 14586, 19448, 29172, 58344)$
Similarly, we get below sequences.
Case :$s=2 \times3 \times4 \times7 \times11 \times13.$
$(2, 3, 4, 6, 8, 11, 12, 14, 21, 22, 24, 26, 28, 33, 42, 44, 52, 56, 77, 78, 84, 88, 91, 104, 132, 143, 154, 156, 168, 182, 264, 273, 286, 308, 312, 364, 429, 572, 616, 728, 858, 924, 1001, 1092, 1144, 1716, 1848, 2002, 2184, 3003, 3432, 4004, 6006, 8008, 12012, 24024)$
Case :$s=2 \times3 \times4 \times11 \times13 \times17.$
$(2, 3, 4, 6, 8, 11, 12, 13, 17, 22, 24, 26, 34, 44, 51, 52, 68, 78, 88, 102, 104, 132, 136, 156, 187, 204, 221, 264, 312, 374, 408, 442, 561, 572, 663, 748, 884, 1122, 1144, 1326, 1496, 1716, 1768, 2244, 2431, 2652, 3432, 4488, 4862, 5304, 7293, 9724, 14586, 19448, 29172, 58344)$
Case :$s=2 \times3 \times4 \times7 \times11 \times19.$
$(2, 3, 4, 6, 8, 11, 12, 14, 19, 21, 22, 24, 28, 33, 44, 56, 76, 84, 88, 132, 133, 152, 154, 168, 209, 228, 231, 264, 266, 308, 399, 456, 532, 616, 627, 798, 836, 924, 1064, 1254, 1463, 1596, 1672, 1848, 2508, 3192, 4389, 5016, 5852, 8778, 11704, 17556, 35112)$
Case :$s=2 \times3 \times4 \times11 \times13 \times19.$
$(2, 3, 4, 6, 8, 11, 12, 13, 19, 22, 24, 26, 33, 38, 44, 52, 57, 66, 76, 88, 104, 114, 132, 143, 152, 156, 209, 228, 247, 264, 312, 418, 429, 456, 572, 627, 741, 836, 988, 1144, 1482, 1672, 1716, 1976, 2508, 2964, 3432, 5016, 5928, 8151, 10868, 21736, 32604, 65208)$
Case :$s=2 \times3 \times4 \times7 \times11 \times23.$
$(2, 3, 4, 6, 8, 11, 12, 14, 21, 22, 23, 24, 28, 33, 42, 44, 56, 69, 77, 84, 88, 92, 132, 138, 154, 161, 168, 184, 231, 253, 264, 276, 308, 462, 483, 552, 616, 644, 759, 924, 1012, 1288, 1771, 1848, 1932, 2024, 3036, 3542, 3864, 6072, 7084, 14168, 21252, 42504)$
Case :$s=2 \times3 \times4 \times7 \times19 \times29.$
$(2, 3, 4, 6, 7, 8, 12, 24, 28, 38, 42, 56, 58, 76, 84, 114, 116, 133, 152, 168, 174, 203, 228, 232, 266, 348, 406, 456, 532, 551, 609, 696, 812, 1064, 1218, 1596, 1624, 1653, 2204, 2436, 3192, 3306, 3857, 4408, 4872, 6612, 7714, 11571, 13224, 15428, 23142, 30856, 46284, 92568)$
Case :$s=2 \times3 \times4 \times7 \times23 \times29.$
$(2, 3, 4, 6, 7, 8, 12, 24, 28, 29, 56, 58, 69, 84, 92, 116, 138, 161, 168, 174, 184, 203, 232, 276, 348, 483, 552, 644, 667, 696, 812, 1218, 1288, 1334, 1624, 1932, 2001, 2436, 2668, 3864, 4002, 4669, 4872, 5336, 8004, 14007, 16008, 18676, 28014, 37352, 56028, 112056)$
Case :$s=2 \times3 \times4 \times7 \times19 \times31.$
$(2, 3, 4, 6, 7, 8, 12, 24, 28, 31, 56, 57, 62, 76, 84, 114, 124, 133, 152, 168, 217, 228, 248, 266, 372, 399, 456, 532, 651, 744, 798, 868, 1064, 1596, 1736, 1767, 2356, 2604, 3192, 3534, 4123, 4712, 5208, 7068, 8246, 12369, 14136, 16492, 24738, 32984, 49476, 98952)$
Case :$s=2 \times3 \times4 \times7 \times29 \times31.$
$(2, 3, 4, 6, 7, 8, 12, 24, 28, 31, 42, 56, 84, 87, 93, 116, 124, 168, 174, 217, 232, 248, 348, 372, 406, 434, 609, 651, 696, 744, 812, 868, 899, 1302, 1624, 1736, 1798, 2436, 2604, 2697, 3596, 4872, 5208, 5394, 6293, 7192, 10788, 21576, 25172, 50344, 75516, 151032)$
Case :$s=2 \times3 \times4 \times7 \times19 \times37.$
$(2, 3, 4, 6, 7, 8, 12, 24, 28, 38, 42, 56, 57, 74, 76, 84, 148, 152, 168, 222, 228, 259, 266, 296, 399, 444, 456, 518, 532, 703, 777, 798, 888, 1036, 1064, 1406, 1554, 1596, 2072, 2109, 2812, 3108, 3192, 4921, 5624, 6216, 8436, 9842, 16872, 19684, 29526, 39368, 59052, 118104)$
Case :$s=2 \times3 \times4 \times7 \times23 \times37.$
$(2, 3, 4, 6, 7, 8, 12, 24, 28, 37, 42, 56, 69, 74, 84, 92, 111, 138, 148, 161, 168, 184, 259, 276, 296, 322, 444, 483, 552, 644, 777, 888, 1036, 1288, 1554, 1702, 1932, 2072, 3108, 3404, 3864, 5106, 5957, 6216, 6808, 10212, 17871, 20424, 23828, 47656, 71484, 142968)$


smarty convert string to Integer/Float

Question: I have some string value, like  $value = "123.45";.
Since I have to compare this $value with Integer, I need to convert  $value's type to float.
How can I convert String to Integer/Float in smarty language?
Thanks.
Answer: you can use php's functions floatval / intval in smarty:
{$value = $value|floatval}
{$value = $value|intval}

Multiplying by 1 would also work:
{$value = $value*1}

smarty convert string to Integer/Float


Add Exception to firewall on Mac either during installation of application or when application is launched

Question: I have a client - server application, where I want to add a exception to firewall so that my applications can communicate properly.
I want to add add an exception to the firewall (without changing the setup for the other firewalls options).
I am using Carbon, Qt, C++. However, I feel this has more to do with some install time settings.
Comment: Consider posting also in superuser.com. I won't request closing the question as 'belongs on superuser.com' but you have better chances of getting installation time settings there.
Answer: I'm not sure this is would be good practice without notifying the user or asking the user for permission. Since osx has a built in system for creating application signing and the user must explicitly enable this level of security.
That being said, you should have a look at
<code>/usr/libexec/ApplicationFirewall/socketfilterfw
</code>
and
<code>/usr/libexec/ApplicationFirewall/com.apple.alf.plist
</code>
OS X also use ipfw and I'm pretty sure it supersedes any rules set by the application filter. So you could make an ipfw rule as well.
Answer: in my opinion, if you`re opening a socket, your Mac-firewall will automatic give you the chance to allow or deny the connection.... did you try it?
Comment: Sorry, I think missed a detail there, that it should not be user interactive. This all should happen in background.
Comment: I tried what you suggested. I want set firewall to always allow incoming connections
Comment: Why shouldn't it be user interactive? You are trying to change the security of the system. If your application isn't malicious then why is there a problem with using the system behaviour?
Comment: Yes, usually the user is asked when the connection attempt is being made, and then the user can allow it once, allow always, or deny it.


Differential equation solved by even monomials

Question:
Suppose that for every $h=1, \dots, k-1$ the monomial $x^{2h}$ is solution of the following differential equation $$ a_1^{(k)} \left( x^{2h} \right)' + a_2^{(k)} x \left( x^{2h} \right)'' + \cdots + a_{k-1}^{(k)} x^{k-2} \left( x^{2h} \right)^{(k-1)} + x^{k-1} \left( x^{2h} \right)^{(k)} = 0.$$ Find the coefficients $a_j^{(k)}$, $j=1,\dots,k-1$, for every $k$.

In my attempt I've computed all the derivatives and found the equation
$$ 0 = a_1^{(k)}+(2h-1)a_2^{(k)}+(2h-1)(2h-2)a_3^{(k)} + \dots + (2h-1)\cdots(2h-k+2) a_{k-1}^{(k)} + (2h-1) \cdots (2h-k+1) $$
equivalent to
$$
0=a_1^{(k)}+(2h-1)\left[a_2^{(k)}+(2h-2)\left[a_3^{(k)}+...+(2h-k+2)\left[a_{k-1}^{(k)}+(2h-k+1)\right]...\right]\right].
$$
If you put $h=1$, it gives $a_2^{(k)}=-a_1^{(k)}$, for $h=2$ it gives $a^{(k)}_4=-a^{(k)}_3+a^{(k)}_1/3$ and so on. But I cannot find the general expression.

Motivation
Let $f,g$ be two functions related by $f(x):=g(x^2)$, then $f'(x)=2xg'(x^2)$ and so $$g'(x^2)=\frac{1}{2x}(f'(x)).$$
In the same way, $f''(x)=2g'(x^2)+4x^2g''(x^2)$, so $$g''(x^2)=\frac{1}{4x^3}(xf''(x)-f'(x))$$
and $f^{(3)}(x)=4x^2g^{(3)}(x^2)+12xg''(x^2)$, so $$g^{(3)}(x^2)=\frac{1}{8x^5}(x^2f^{(3)}(x)-3xf''(x)+3f'(x))$$
and so on. I hoped that $g^{(k)}(x^2)=0$ if and only if $g$ is a polynomial of degree $\leq k-1$, so I was interested in finding the coefficients of the equation solved only by even monomials.
Answer: Let $D$ be the derivative operator.
Note that $(xD-k)x^k=0$ and since $xD$ as an operator commutes with itself and $1$, we have $(xD-a)$ commutes with $(xD-b)$. This motivates us to consider $xD(xD-2)(xD-4)\dots (xD-(2(k-1))$. Applying this operator to any $x^{2i}$ for $i$ in $0,1,\dots k-1$ gives 0 and it has degree $k$ with leading coefficient $1$, so this is the polynomial we want.
Note that we can use that $Dx=xD+1$. For example $(xD)^2=x(xD+1)D=x^2D^2+xD$ and more generally $xD(x^nD^n)=x^{n+1}D^{n+1}+nx^nD^n $.
We can either expand the polynomial in terms of $xD$ and then simplify each term $(xD)^i$ into a sum of terms of the form $x^iD^i$ (the coefficients are Stirling numbers) or we can work iteratively. Let's demonstrate that.
We have $xD(xD-2)=x^2D^2-xD$ giving initial coefficients of $1,-1$.
Multiplying by $(xD-4)$ gives:
$$(xD-4)(x^2D^2-xD)=(x^3D^3+2x^2D^2)-(x^2D^2+xD)-4(x^2D^2-xD)=x^3D^3-3x^2D^2+3xD$$
Thus, the next set of coefficients are $1,-3,3$.
Looking closely at the coefficients through these multiplications, we can derive a recursive formula for the coefficients: $$a_i^{(k)}=a_{i-1}^{(k-1)}-(2k-i-2)a_i^{(k-1)}$$
If we wasn't an explicit formula, we can use the fact that the coefficients of $x(x-1)\dots(x-(k-1))$ are the signed Stirling numbers of the first kind and that the coefficients of $(xD)^k$ in terms of $x^iD^i$ are Stirling numbers of the second kind to get an explicit formula.
By https://en.m.wikipedia.org/wiki/Stirling_numbers_of_the_first_kind, we can write using signed Stirling coefficients of the first kind:
$$(x)_k=x(x-1)\dots(x-(k-1))=\sum_{i=0}^k s(k,i)x^i$$
Substituting $x/2$ and multiplying by $2^k$ gives:
$$x(x-2)\dots(x-2(k-1))=\sum_{i=0}^k 2^{k-i} s(k,i)x^k$$
From https://mathworld.wolfram.com/DifferentialOperator.html, it's a known fact that for Stirling numbers of the second kind $S(a,b)$ we have:
$$(xD)^a=\sum_{b=0}^a S(a,b) x^bD^b$$
Combining these two formula gives us that
$$\sum_{j=0}^k a_j^{(k)} x^jD^j=xD(xD—2)\dots(xD-2(k-1)$$
$$=\sum_{i=0}^k 2^{k-i} s(k,i)(xD)^i$$
$$=\sum_{i=0}^k 2^{k-i} s(k,i)\sum_{j=0}^i S(i,j)x^j D^j$$
$$= \sum_{j=0}^k (\sum_{i=j}^k 2^{k-i} s(k,i) S(i,j)) x^j D^j$$
Thus, $a_j^{(k)}=\sum_{i=j}^k 2^{k-i} s(k,i) S(i,j)$.
For example the $5th$ row is $1,-10,45,-105,105$, so we should have that $a^{(5)}_3=45$.
Double checking the formula, we get $45$ as desired:
$$a^{(5)}_3=4 s(5,3)S(3,3)+2 s(5,4)S(4,3)+ s(5,5)S(5,3)$$
$$=4 \cdot 35 \cdot 1+2\cdot  (-10) \cdot 6 +  1 \cdot 25=140-120+25=45$$
Comment: Thank you for your help and the relation with Stirling numbers is very interesting. After your answer, in which you found the relation $a_j^{(k)}=a_{j-1}^{(k-1)}-(2k-i-2)a_j^{(k-1)}$, I asked also for the generating function of that sequence:https://math.stackexchange.com/questions/4745931/generating-functions-of-recursive-sequence-with-two-parameters/4746376#4746376. That is an explicit formula that compute $a_j^{(k)}=\frac{(2n-k-1)!}{(k-1)!\,(n-k)!\,(-2)^{n-k}}$.
Comment: Should be. You have $k$ independent solutions (including $1$) to a degree $k$ equation. I could imagine there might be diff solutions on the left and right side of $0$ since the leading term becomes 0 at $x=0$ though.
Comment: Thank you very much. Is it possible to deduce a formula for the $a_j^{(k)}$, which is not recursive? Since, I don't think the coefficients are the Stirling numbers.
Comment: The coefficients of $x(x-2)(x-4)\dots(x-2k)$ are Stirling numbers of the first kind times a power of $2$, and the coefficients of $(Dx)^n$ are Stirling numbers of the second kind, so substituting $Dx$ into the first gives you an explicit formula as a double sum of Stirling numbers of the first kind times those of the second time times a power of 2. I have no idea if that can be simplified further.
Comment: I'm sorry, but I don't know much about Stirling numbers. For example, if $k=3$ you have $x(x-2)(x-4)(x-6)=x^4-12x^3+44x^2-48x$, giving coefficient 1,-12,44,48 and these don't seem to be Stirling numbers.
While, for the coefficients $a_j^{(5)}$ my computations agree with your formula giving coefficients 1,-10,45,-105,105, but again these don't seem to be Stirling numbers or power of 2 of Stirling numbers. Is there something I'm missing?
Comment: Maybe, if we split the formula $a_i^{(k)}=a_{i-1}^{(k-1)}+ia_i^{(k-1)}-2(k-1)a_i^{(k-1)}$ the first part resemble the formula for Stirling numbers, but the last part ruins everything, right?
Comment: https://en.m.wikipedia.org/wiki/Stirling_numbers_of_the_first_kind

4th row is 1 6 11 6. Multiplying by $2^n$ (since you're using even numbers in the polynomial) gives $1,12,44,48$ as you've computed.
Comment: $(xD)^3=xD(x^2D^2 +xD)=x^3D^3+3x^2D^2+xD$ is the third row of Stirling numbers of second kind, $1,3,1$  https://en.m.wikipedia.org/wiki/Stirling_numbers_of_the_second_kind
Comment: Plug $xD$ into the polynomial and expand
Comment: But what about $1,-10,45,-105,105$, these are the coefficients with $k=5$. How do they come from Stirling numbers and power of $2$? Some of them aren't even even numbers.
Comment: I just added my formula to the solution itself.  That should make it clear that the $a's$ are not Stirling numbers but sums of them.
Comment: And is the converse also true? Namely, that if a function satisfies that differential equation, then it is a polynomial with only even power?
Comment: You mean that I can write the equation above as $F(x,y(x),y'(x),...,y^{(k)}(x))=0$, with $F=\sum_{j=1}^ka_j^{(k)}x^{j-1}y^{(j)}(x)$ real analytic, then the space of solutions has dimension $k$ and a basis is $\{1,x^2,...,x^{2(k-1)}\}$?
Answer: Hint.
$$
\sum_{k=0}^n a_k^h x^k\left(x^{2h}\right)^{(k+1)} = 2hx^{2h-1}\sum_{k=0}^n{a_k^h\prod}_{\nu=2h-1}^{\nu=2h-k}\nu = 0
$$
and so for $h=1,\cdots,n$
For $n=3$ and $h=1,\cdots,3$ we have
$$
\cases{
h=1\to a_0+a_2=0\\
h=2\to a_0+3a_1+6a_2+6a_3 = 0\\
h=3\to a_0+5a_1+20a_2+60a_3=0
}
$$
giving the polynomial
$$
p_3(x) = \left(1 + x-\frac{2 x^2}{5}+\frac{x^3}{15}\right)a_0
$$
Calling $\pi(k,j) = \prod_{i=k}^{i=j}i$ we have to solve for $p_n$ determination, the linear system
$$
M a = B a_0
$$
where
$$
a = (a_1,\cdots,a_n)'\\ B=-(1,\cdots,1)'
$$
and
$$
M = \{m_{ij}\}=\pi(2i-j,2i-1)
$$
Comment: And can you find the general $p_k(x)$?
Comment: I added a way to compute $p_k(x)$
Comment: I got a slightly different result, namely that $0=\sum_{j=1}^ka_j\pi(2h-j+1,2h-1)$. Btw, is $M$ invertible, is $M^{-1}$ explicitly given? Because, I would like a nice formula for the coefficient $a_k^{(k)}$ if there is one.


3 sequences which are convergent

Question:
Let $a_0, b_0, c_0\in \mathbb{R}$ and $k>0$. If
  \begin{align}
a_{n+1}=\frac{1}{k+1}b_n+\frac{k}{k+1}c_n\\
b_{n+1}=\frac{1}{k+1}c_n+\frac{k}{k+1}a_n\\
c_{n+1}=\frac{1}{k+1}a_n+\frac{k}{k+1}b_n
\end{align}
  Prove that $(a_n), (b_n),(c_n)$ are convergent.

I know that they are all convergent to $\frac{a_0+b_0+c_0}{3}$ and I have a geometrical solution.
However, I'm interested in a purely analytical one. I got that $(a_n+b_n+c_n)$ is constant and then I tried to get a relation only in terms of say $(a_n)$, but this worked only when $k=1$.
Comment: Only an idea: Put $u_n=a_n+b_n+c_n$, and with $j=\exp(2i\pi/3)$, $v_n=a_n+jb_n+j^2c_n$, $w_n=a_n+j^2b_n+jc_n$. Then $u_{n+1}=u_n$, $v_{n+1}=\frac{kj+j^2}{1+k} v_n$, and $w_{n+1}=\frac{j^2k+j}{k+1}w_n$. So you can compute $u_n, v_n,w_n$ easily, and use that $u_n+v_n+w_n=3a_n$, $u_n+j^2v_n+jw_n=3b_n$, $u_n+jv_n+j^2w_n=3c_n$.
Answer: This proof is inspired by the geometrical intuition that each iteration of the sequence involves a weighted average of the points of the previous iteration.
Let $M_n = \max(a_n, b_n, c_n)$ and $m_n = \min(a_n, b_n, c_n)$. Let $I_n$ be the point intermediate to these two (if two or more points coincide, simply choose one to be $I_n$).  Let $\alpha = \max(1/(k+1), k/(k+1))$. Then we have
$$ \begin{align} M_{n+1} &\leq I_n + \alpha(M_n - I_n) \leq M_n\\
m_{n+1} &\geq m_n + (1-\alpha)(I_n - m_n) \geq m_n \end{align} $$
Since $M_n$ is a decreasing sequence bounded below (by $m_0$, say), it converges to $M$. Similarly, $m_n$ converges to $m$. $I_n$ is a sequence bounded by $m_0$ and $M_0$ and so by Bolzano-Weierstrass has a convergent subsequence. Let $n_j$ correspond to this subsequence, and $I$ its limit. We know that $n_{j+1} \geq n_j+1$, so we can write the above inequalities as
$$ \begin{align} M_{n_{j+1}} &\leq I_{n_j} + \alpha(M_{n_j} - I_{n_j})\\
m_{n_{j+1}} &\geq m_{n_j} + (1-\alpha)(I_{n_j} - m_{n_j})\end{align} $$
We can now freely take the limit $j \to \infty$ to yield
$$ \begin{align} M &\leq I + \alpha(M-I) \\
m &\geq m + (1-\alpha)(I - m)\end{align}$$
Rearranging these gives $M \leq I$ and $m \geq I$. This is only possible if $M = I = m$. Hence $a_n, b_n, c_n$ converge.
Answer: It's possible to use linear algebra to find the closed form of each sequence.  First write your three equations as a matrix equation
$$\begin{pmatrix} a_{n+1} \\ b_{n+1} \\ c_{n+1} \end{pmatrix} =
\begin{pmatrix}
0 & \frac{1}{k+1} & \frac{k}{k+1} \\
\frac{k}{k+1} & 0 & \frac{1}{k+1} \\
\frac{1}{k+1} & \frac{k}{k+1} & 0 \end{pmatrix}
\begin{pmatrix} a_n \\ b_n \\ c_n \end{pmatrix}
  $$
Let's call the matrix above $A$.  One might notice that $A$ has nice properties, for instance, it is doubly stochastic.  Computing the characteristic polynomial of $A$ yields
$$ \operatorname{char}(A) = \det(A - xI) = x^3 - \frac{3k}{(k+1)^2}x - \frac{k^2 - k + 1}{(k+1)^2} $$
Notice that one of the roots of this polynomial is $x=1$.  To find the other two roots we can do polynomial division
$$ \frac{\operatorname{char}(A)}{x-1} = x^2 + x + \frac{k^2 - k + 1}{(k+1)^2} $$
and the quadratic formula with some simplifying gives us the other two roots
$$ x = \frac{-1}{2} \pm \frac{i \sqrt{3}}{2} \left( \frac{k-1}{k+1} \right)$$
These roots are the eigenvalues of $A$.  For simplicity let's call the two complex roots $w$ and $\overline{w}$.  Solving for the eigenvectors of $A$ we have
$$A \begin{pmatrix}1 \\ 1 \\ 1 \end{pmatrix} = 1 \begin{pmatrix}1 \\ 1 \\ 1 \end{pmatrix}$$
just like you pointed out earlier.
Now for the other two eigenvectors there are two cases.  The easier one is when $k=1$, which means
$$A \begin{pmatrix} -1 \\ 0 \\ 1 \end{pmatrix} = -\frac{1}{2}\begin{pmatrix} -1 \\ 0 \\ 1 \end{pmatrix}
\hspace{.15 in} \text{and} \hspace{.15 in}
A \begin{pmatrix} 0 \\ -1 \\ 1 \end{pmatrix} = -\frac{1}{2}\begin{pmatrix} 0 \\ -1 \\ 1 \end{pmatrix}
$$
Thus we can diagonalize $A$ as
$$A = \begin{pmatrix} 1 & -1 & 0 \\ 1 & 0 & -1 \\ 1 & 1 & 1 \end{pmatrix}
\begin{pmatrix} 1 & 0 & 0 \\ 0 & -\frac{1}{2} & 0 \\ 0 & 0 & -\frac{1}{2} \end{pmatrix}
\begin{pmatrix} 1 & -1 & 0 \\ 1 & 0 & -1 \\ 1 & 1 & 1 \end{pmatrix}^{-1}$$
and computing the inverse of the last matrix means
$$\begin{pmatrix} a_n \\ b_n \\ c_n \end{pmatrix} = \frac{1}{3}\begin{pmatrix} 1 & -1 & 0 \\ 1 & 0 & -1 \\ 1 & 1 & 1 \end{pmatrix}
\begin{pmatrix} 1 & 0 & 0 \\ 0 & (-\frac{1}{2})^n & 0 \\ 0 & 0 & (-\frac{1}{2})^n \end{pmatrix}
\begin{pmatrix} 1 & 1 & 1 \\ -2 & 1 & 1 \\ 1 & -2 & 1 \end{pmatrix}
\begin{pmatrix} a_0 \\ b_0 \\ c_0 \end{pmatrix}$$
and computing all the matrix multiplication yields
\begin{align*}
a_n &= \frac{1}{3}(a_0 + b_0 + c_0 - (-\frac{1}{2})^n(-2a_0 + b_0 + c_0)) \\
b_n &= \frac{1}{3}(a_0 + b_0 + c_0 - (-\frac{1}{2})^n(a_0 - 2b_0 + c_0)) \\
c_n &= \frac{1}{3}(a_0 + b_0 + c_0 - (-\frac{1}{2})^n(a_0 + b_0 - 2c_0))
\end{align*}
It gets a little trickier when $k \not = 1$.  Recall that we called the two complex eigenvalues $w$ and $\overline{w}$.  A little complex algebra will give us
$$A \begin{pmatrix} -\left(\frac{k+1}{k-1}\right)w - \frac{k}{k-1} \\ \left(\frac{k+1}{k-1}\right)w + \frac{1}{k-1} \\ 1 \end{pmatrix} = w \begin{pmatrix} -\left(\frac{k+1}{k-1}\right)w - \frac{k}{k-1} \\ \left(\frac{k+1}{k-1}\right)w + \frac{1}{k-1} \\ 1 \end{pmatrix}$$
and
$$A \begin{pmatrix} -\left(\frac{k+1}{k-1}\right)\overline{w} - \frac{k}{k-1} \\ \left(\frac{k+1}{k-1}\right)\overline{w} + \frac{1}{k-1} \\ 1 \end{pmatrix} = \overline{w} \begin{pmatrix} -\left(\frac{k+1}{k-1}\right)\overline{w} - \frac{k}{k-1} \\ \left(\frac{k+1}{k-1}\right)\overline{w} + \frac{1}{k-1} \\ 1 \end{pmatrix}$$
Our calculations will look a little simpler if we use $z = -\left(\frac{k+1}{k-1}\right)w - \frac{k}{k-1}$ and note that $\overline{z} = \left(\frac{k+1}{k-1}\right)w + \frac{1}{k-1}$.  Then we can diagonalize $A$
$$A = \begin{pmatrix} 1 & z & \overline{z} \\ 1 & \overline{z} & z \\ 1 & 1 & 1 \end{pmatrix}
\begin{pmatrix} 1 & 0 & 0 \\ 0 & w & 0 \\ 0 & 0 & \overline{w} \end{pmatrix}
\begin{pmatrix} 1 & z & \overline{z} \\ 1 & \overline{z} & z \\ 1 & 1 & 1 \end{pmatrix}^{-1}$$
and computing the inverse of the last matrix means
$$\begin{pmatrix} a_n \\ b_n \\ c_n \end{pmatrix} = \frac{1}{3} \begin{pmatrix} 1 & z & \overline{z} \\ 1 & \overline{z} & z \\ 1 & 1 & 1 \end{pmatrix}
\begin{pmatrix} 1 & 0 & 0 \\ 0 & w^n & 0 \\ 0 & 0 & \overline{w}^n \end{pmatrix}
\begin{pmatrix} 1 & 1 & 1 \\ \overline{z} & z & 1 \\ z & \overline{z} & 1 \end{pmatrix}
\begin{pmatrix} a_0 \\ b_0 \\ c_0 \end{pmatrix}$$
and computing all the matrix multiplication yields
\begin{align*}
a_n &= \frac{1}{3}(a_0 + b_0 + c_0 + zw^n(\overline{z}a_0 + zb_0 + c_0) + \overline{z}\overline{w}^n(za_0 + \overline{z}b_0 + c_0))\\
b_n &= \frac{1}{3}(a_0 + b_0 + c_0 + \overline{z}w^n(\overline{z}a_0 + zb_0 + c_0) + z\overline{w}^n(za_0 + \overline{z}b_0 + c_0))\\
c_n &= \frac{1}{3}(a_0 + b_0 + c_0 + w^n(\overline{z}a_0 + zb_0 + c_0) + \overline{w}^n(za_0 + \overline{z}b_0 + c_0))
\end{align*}
Since
$$|w| = \sqrt{\frac{k^2-k+1}{k^2 + 2k + 1}} < 1$$
We have $\lim\limits_{n \to \infty} w^n = \lim\limits_{n \to \infty} \overline{w}^n = 0$, thus
\begin{align*}
\lim\limits_{n \to \infty} a_n &= \frac{a_0 + b_0 + c_0}{3}\\
\lim\limits_{n \to \infty} b_n &= \frac{a_0 + b_0 + c_0}{3}\\
\lim\limits_{n \to \infty} c_n &= \frac{a_0 + b_0 + c_0}{3}\\
\end{align*}
Note: If $k \leq 0$, then
$$|w| = \sqrt{\frac{k^2-k+1}{k^2 + 2k + 1}} \geq 1$$
which is why the sequences diverge for $k \leq 0$.
Comment: Wow, now I see why the general term forms were so hard to get!

3 sequences which are convergent


Why won't the message edit embed send when a message is edited? (discord.py)

Question: My log embed isn't sending when a message is edited. Does anyone see why?
@client.event
async def on_message_edit(before, after):
    with open('logchannel.json', 'r') as f:
        logs = json.load(f)

    logchannel = discord.utils.get(logs)
    embed = discord.Embed(color=0x0000ff, title="Message Edited", description=f"{before.author.mention} edited a message.")
    embed.add_field(name="Original Message", value=before.content, inline=True)
    embed.add_field(name="Edited Version", value=after.content, inline=True)
    await logchannel.send(embed=embed)

Comment: Your code should work fine, are you getting any errors, have you tried debugging?
Answer: discord.utils.get is for getting an element with specified attributes from an iterable. You're looking for discord.Client.get_channel.
Also, r mode and inline=True are unnecessary. They are implied.
@client.event
async def on_message_edit(before, after):
    with open('logchannel.json') as f:
       logs = json.load(f)

    logchannel = client.get_channel(logs)
    embed = discord.Embed(color=0x0000ff, title='Message Edited', description=f'{before.author.mention} edited a message.')
    embed.add_field(name='Original Message', value=before.content)
    embed.add_field(name='Edited Version', value=after.content)
    await logchannel.send(embed=embed)

Comment: I did all that and now I have this error:

Ignoring exception in on_message_edit
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/discord/client.py", line 343, in _run_event
    await coro(*args, **kwargs)
  File "asmusic.py", line 204, in on_message_edit
    break
AttributeError: 'NoneType' object has no attribute 'send'
Comment: @TheSuperRobert2610 What is the content of `logchannel.json`?
Comment: It has the guild ID, and the selected channel ID
Comment: @TheSuperRobert2610 Not enough context. I need the actual content, if you don't want to share the IDs you can replace them with like `guild_id` and `channel_id`
Comment: Ok, here it is: `"797921708861423640": 797921708861423643`
Comment: Try changing it to just `797921708861423643`. The could should work then
Comment: The guild ID is in quotation marks, and the channel ID isn't
Comment: This is a .json file, not a .txt, and it says it needs a colon next to the channel ID
Comment: Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/233850/discussion-between-makonede-and-thesuperrobert2610).


How to automating install software on 40+ virtual machine on ESXi

Question: Now I am managing a Free ESXi 5.1 Server and I often create new virtual machine in linked clone for developer to testing. The number of VMs is about 40. I have to log in to these VMs and install software for all of them.
You guys have any ideas to install software automatically by using script on esxi. Most of my VMs on Windows platform.
Comment: The free esxi is not really scriptable. I'd look for an outside solution.
Answer: It sounds question isn't really specific to vSphere ESXi, but really is just "How can I automate software installation on a bunch of Windows machines (that just happen to be virtual)?"
The are a ton of ways to do this, from built-in functionality (chaining scripts onto the Windows installation process), the Windows Automated Installation Kit, Active Directory Group Policy, add-on Microsoft software (the System Center Configuration Manager product), and third-party commercial and free products.
Personally, I'd start looking at the built-in functionality in Windows and working toward offerings that have a monetary cost associated.


ubuntu KVM guest with no network connection after configuring network bridge

Question: I am trying to add KVM guest (Ubuntu 18.04) to local network like other real servers in the network. I configured KVM bridge interface in the host system (Ubuntu 18.04) and it works fine with connection. Host system is reachable over the local network to other servers.
netplan config for the host system:
$ cat 01-netcfg.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
  version: 2
  renderer: networkd
  ethernets:
    eno1:
      dhcp4: false
  bridges:
    br0:
      interfaces: [eno1]
      addresses: [192.168.1.105/24]
      gateway4: 192.168.1.1
      nameservers:
        addresses: [x.x.x.x, x.x.x.x]
      dhcp4: false

ip a output showing bridge interface :
    10697: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 62:cb:37:3c:c0:70 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.105/24 brd 192.168.1.255 scope global br0
       valid_lft forever preferred_lft forever
    inet6 fe80::60cb:37ff:fe3c:c070/64 scope link
       valid_lft forever preferred_lft forever

I created KVM network interface using the bridge br0
virsh net-edit br0 output:
<network>
  <name>br0</name>
  <uuid>d277e3d1-b34e-4b1f-ae69-6a3c8f75626c</uuid>
  <forward mode='bridge'/>
  <bridge name='br0'/>
</network>

developer@serv31:~$ virsh net-list
 Name                 State      Autostart     Persistent
----------------------------------------------------------
 br0                  active     yes           yes
 default              active     yes           yes

interface info of the KVM guest domain:
    <interface type='network'>
      <mac address='52:54:00:14:dc:af'/>
      <source network='br0'/>
      <model type='rtl8139'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
    </interface>

In the guest VM I configured netplan to give it a static IP. It did boot with the configured IP.
$ cat 50-cloud-init.yaml
network:
  version: 2
  ethernets:
    ens3:
      addresses: [192.168.1.50/24]
      gateway4: 192.168.1.1
      nameservers:
        addresses: [x.x.x.x, x.x.x.x]
      dhcp4: false

guest VM ip a output:
$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 52:54:00:14:dc:af brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.50/24 brd 192.168.1.255 scope global ens3
       valid_lft forever preferred_lft forever
    inet6 fe80::5054:ff:fe14:dcaf/64 scope link
       valid_lft forever preferred_lft forever

Guest VM is able to reach (ping, telnet) host system, Host system can reach guest VM.
But no other server in the network can reach guest VM, and guest VM cannot access internet too.
Please help me fixing this. Do let me know if you need more info.
EDIT :
ip link output :
:~$ ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq master br0 state UP mode DEFAULT group default qlen 1000
    link/ether 00:21:9b:9a:f2:be brd ff:ff:ff:ff:ff:ff
3: eno2: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/ether 00:21:9b:9a:f2:c0 brd ff:ff:ff:ff:ff:ff
4: eno3: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/ether 00:21:9b:9a:f2:c2 brd ff:ff:ff:ff:ff:ff
5: eno4: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/ether 00:21:9b:9a:f2:c4 brd ff:ff:ff:ff:ff:ff
6: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN mode DEFAULT group default
    link/ether 02:42:b3:0f:d6:24 brd ff:ff:ff:ff:ff:ff
9: virbr0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000
    link/ether 52:54:00:56:08:1e brd ff:ff:ff:ff:ff:ff
10: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc fq_codel master virbr0 state DOWN mode DEFAULT group default qlen 1000
    link/ether 52:54:00:56:08:1e brd ff:ff:ff:ff:ff:ff
19219: vnet0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel master br0 state UNKNOWN mode DEFAULT group default qlen 1000
    link/ether fe:54:00:14:dc:af brd ff:ff:ff:ff:ff:ff
8744: vnet1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel master virbr0 state UNKNOWN mode DEFAULT group default qlen 1000
    link/ether fe:54:00:6f:20:0f brd ff:ff:ff:ff:ff:ff
10950: vnet2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel master virbr0 state UNKNOWN mode DEFAULT group default qlen 1000
    link/ether fe:54:00:c1:0e:86 brd ff:ff:ff:ff:ff:ff
10697: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000
    link/ether 62:cb:37:3c:c0:70 brd ff:ff:ff:ff:ff:ff
10971: vnet3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel master br0 state UNKNOWN mode DEFAULT group default qlen 1000
    link/ether fe:54:00:a4:13:1c brd ff:ff:ff:ff:ff:ff

iptable rules containing virbr0 and br0
:~$ sudo iptables-save | grep br0
-A POSTROUTING -o virbr0 -p udp -m udp --dport 68 -j CHECKSUM --checksum-fill
-A POSTROUTING -o br0 -j MASQUERADE
-A INPUT -i virbr0 -p udp -m udp --dport 53 -j ACCEPT
-A INPUT -i virbr0 -p tcp -m tcp --dport 53 -j ACCEPT
-A INPUT -i virbr0 -p udp -m udp --dport 67 -j ACCEPT
-A INPUT -i virbr0 -p tcp -m tcp --dport 67 -j ACCEPT
-A FORWARD -d 192.168.122.0/24 -o virbr0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -s 192.168.122.0/24 -i virbr0 -j ACCEPT
-A FORWARD -i virbr0 -o virbr0 -j ACCEPT
-A FORWARD -o virbr0 -j REJECT --reject-with icmp-port-unreachable
-A FORWARD -i virbr0 -j REJECT --reject-with icmp-port-unreachable
-A FORWARD -i br0 -o virbr0 -m state --state RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -i virbr0 -o br0 -j ACCEPT
-A OUTPUT -o virbr0 -p udp -m udp --dport 68 -j ACCEPT

Comment: Please add an `ip link` output on host *while* the VM is running: that's to double check a tap interface was set as bridge port on br0. Also, please try again without any firewall, including ufw or iptables. The reason why on Linux iptables can affect a bridge is documented [here](http://ebtables.netfilter.org/documentation/bridge-nf.html) and [there](http://ebtables.netfilter.org/br_fw_ia/br_fw_ia.html#section7).
Comment: Hey thanks for responding, ufw is inactive on the host.
Answer: sudo iptables -t nat -A POSTROUTING -o br0 -j MASQUERADE
sudo iptables -A FORWARD -i br0 -o virbr0 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i virbr0 -o br0 -j ACCEPT
sudo iptables -I FORWARD 1 -i br0 -o br0 -j ACCEPT

above rules fixed the problem.


Basic question about partially ordered sets.

Question: Let $(X,\le)$ be a partially ordered set. Let $x,y,z \in X$. Suppose $x \le y$ and $x \le z$. Then are $y$ and $z$ comparable?
Answer: Not necessarily. Consider the set $X=\mathscr{P}(\{1,2,3\})$ partially ordered by $\subseteq$, then $\{1\}\subseteq\{1,2\}$ and $\{1\}\subseteq\{1,3\}$ but $\{1,2\}$ and $\{1,3\}$ are not comparable. What we do usually say in this case is that $\{1,2\}$ and $\{1,3\}$ are compatible.


Full screen background image with max-width

Question: I'm using the first technique described here to create a "full screen" background image that scales proportionally with the browser.
My CSS for the image container is:
.fs-img {
    position: fixed;
    top: 4.5em;
    right: 0;
    bottom: 0;
    left: 0;
    background: url('image.jpg') no-repeat center center fixed;
    background-size: cover;
}

However I'd like to set a max-width on the my site of 1200px. Of course applying this to the body element has no impact on the image due to it being position: fixed.
So is there an alternative way of having a full screen image with a maximum width while still maintaining fixed to the bottom?
Here's the demo site I'm testing with.
Answer: I think you can achieve what you want using the following styles:
.fs-img {
    position: fixed;
    top: 4.5em;
    right: 50%;
    bottom: 0;
    left: 50%;
    margin:0 -600px;
    background: url(image.jpg) no-repeat center center;
    background-size: cover;
}

Example
Comment: left and righ 50% and negative half of the overall width margins = smart ;)


Why is the Z score not universally agreed upon?

Question: I'm trying to compute a 95% confidence interval for a problem but it seems that multiple sources are saying different things of what the Z score should be. Some claim that it is 1.65 and some claim that it is 1.96. Which one is it really?
1.96 Table
Boston University uses 1.96 for this table
Boston University uses 1.65 for this table on the same website
1.65 Table
I'm just really confused why there is a disagreement / inconsistency here? Aren't we all talking about the same thing? How could this not be standardized / universally agreed upon?
Comment: It is about counting tails
Comment: You may find better answers at https://stats.stackexchange.com
Answer: For a random variable $Z$ with a standard normal distribution and with mean $0$ and standard deviation $1$, you can say

$\mathbb P(Z \le 1.645) \approx 0.95$

and

$\mathbb P(-1.96 \le Z \le 1.96) \approx 0.95$

so the critical values depend on whether you are trying to give a one-tailed or two-tailed hypothesis test or confidence interval.
By contrast $\mathbb P(-1.645 \le Z \le 1.645) \approx 0.9$ and $\mathbb P(Z \le 1.96) \approx 0.975$, so in a sense this matters.
It is worth remembering that the reason $95\%$ is such a common test is that Ronald Fisher's practical experience at Rothamsted Experimental Station had led him to the empirical view that two standard deviations was enough to justify making further investigations.  He then calculated the $95\%$ as a round version of $\mathbb P(-2 \le Z \le 2) \approx 0.9545$; if he had concentrated on one-tailed tests then he might have recommended a different number for the typical confidence.
Answer: A $1$-tailed test has $5\%$ significance at $p=0.95$, i.e. $z=1.65$. A $2$-tailed test has $5\%$ significance at $p=0.975$ (because this is the probability to the left of the $2.5\%$-probability right-hand tail), i.e. $z=1.96$.


postgres password error : Please enter the password for the user 'postgres' to connect the server - "PostgreSQL 13"

Question: I having issue connection to postgres, I am installing at windows 10 via the EDB installer (version 13.2) . I follow all the steps it install fine however when I try to enter the default database using pgadmin   it I always get stuck at this error :

Please enter the password for the user 'postgres' to connect the server - "PostgreSQL 13"

during instalation postgres ask me to specify my master Password. then when instalation finish and I open my pgadmin it again ask me to enter the master password so I did and I was able to successfully login but when I try to open the default database that when it ask me to enter password for posgres  user , I try to use the my master password but it did not work
I installed and uninstall it many time with no success. I also tried this solution so I did change the Method in pg_hba.config from  scram-sha-256 to trust however when I executed this command psql -U postgres it again asked me for the password
any help please
Comment: Your description is very vague. That makes it very hard to determine what you did wrong. You should try harder: What operation system? How exactly did you install PostgreSQL? What choices did you make during the installation process? What are the exact steps you did when you messed with `pg_hba.conf`? etc, etc.
Comment: When you installed Postgres using the EDB installer(I presume) it asked you to create an admin password. That is the password you need to use for the `postgres` user.
Comment: @AdrianKlaver  during instalation yes exacttly it ask me to specify my master Password. then when instalation finish and I open my pgadmin it again ask me to enter the master password so I did and I was able to successfully login but when I try to open the default database that when it ask me to enter password for `posgres ` user , I try to use the my master password but it did not work
Comment: Are you confusing the password that was requested here [EDB Installer](https://www.enterprisedb.com/docs/supported-open-source/postgresql/installer/02_installing_postgresql_with_the_graphical_installation_wizard/01_invoking_the_graphical_installer/) with the one for opening `pgAdmin`?
Comment: no I am not confusing them.  the password in EDB installer is master password I already used it and I was alble to enter `pgadmin` , the password requested is the password for 'postgres' user
Comment: Per the link I posted the password you created via the installer is for the `postgres` user. So either you are not remembering the password correctly or you are connecting to a Postgres instance that was not set up by the installer and uses a different password.
Comment: @Youssef, I'm in the same boat: I've installed PostGreSQL and PGAdmin4 every which way I can think of, and nothing is working, and I'm getting the exact same issue: during installation, you are prompted to set a Master password. When you first open PGA4, you have to put in your master password. Having successfully remembered it from 22 seconds earlier, I can get into PGA4, but then get prompted for the password for user 'postgres' as soon as I touch the default instance, and no, the master password does NOT work.
Answer: You made the same mistake I did: you installed pgAdmin4 without installing postGreSQL server itself. The server installation does indeed set the Master password and the postgres user password at the same time, as the commenters were trying to point out. JUST installing pgAdmin sets a master password for the Admin environment. I don't really understand how there's not a more useful error for trying to connect to a server instance that doesn't actually exist, but here we are.
Answer: try it. it resolves for me
step 1

step2


Find date after a given weeks(months) in ASP.NET

Question: I want to find a date after a give weeks(months).
For example, I want to find the date after 2 week from today or find the date after 4 month from today.
Thanks
Answer: do you want like ?
DateTime dt = DateTime.Now.AddDays(14);
DateTime dt1 = DateTime.Now.AddMonths(4);

Answer: DateTime.Now.AddDays(14)

to get the date 2 weeks from now
or
DateTime.Now.AddMonths(4)

to get the date 4 months from now
NB: This has nothing to do with ASP.NET.  DateTime is part of the .NET BCL.
Answer: Two weeks after today:
DateTime.Now.Date.AddDays(2*7)

Four months after today:
DateTime.Now.Date.AddMonths(4)

Use DateTime.Date if you want only the date without current time (as in the sample).
Comment: Thanks :)  2*7 will be optimised by compiler but for a human reading the code is a bit easier to understand, especially if there should be something like 13 weeks