how to find inverse of a matrix in $\Bbb Z_5$

Question: how to find inverse of a matrix in $\Bbb Z_5$
please help me explicitly how to find the inverse of matrix below, what I was thinking that to find inverses separately of the each term in $\Bbb Z_5$ and then form the matrix?
$$\begin{pmatrix}1&2&0\\0&2&4\\0&0&3\end{pmatrix}$$
Thank you.
Comment: Since the determinant is $1$ modulo $5$, there is no work to do after you compute the subdeterminants.
Comment: I think you can just use Cramer's rule as usual because you're still in a field.
Comment: The same way you do it over any other field. Elementary row operations. [Here's a walkthru example](http://math.stackexchange.com/a/86367/11619) over $\mathbb{Z}_{29}$. The arithmetic in $\mathbb{Z}_5$ is a bit easier if anything.
Answer: Perhaps the easiest way here (though not the easiest way in general) is to write $$A^{-1} = \left( \begin{array}{ccc} a & b & c \\ d & e & f \\ g & h & i \end{array}\right)$$
and then do the multiplication $A \cdot A^{-1} = I$.  Some nice cancellation happens (which does not occur in general), and there is your inverse.
More generally speaking, you can always do row operations to find your matrix.  You do need to be a bit careful since, say, division by $2$ is not defined, though multiplication by $3$ is defined.  Row operations are permitted in general, though not every element in $\mathbb{Z}_n$ is invertible.  Since $n = 5$ is prime, then $\mathbb{Z}_5$ is a field, and hence every nonzero unit is invertible.
Comment: "$c\, e\, d$" ??? I guess any permutation of any nine different letters works. ;-) +1 for the slick answer though...made possible by the upper triangularity of the matrix in question.
Comment: @FixedPoint Thanks. Yes, I suppose any permutation of nine distinct symbols would work (:
Comment: Your nice approach put mine in a shadow. +100 ;-)
Comment: @BabakSorouh: Thanks!
Answer: Remember that you can compute the inverse of a matrix by reducing it to row echelon form. I mean set the $3\times 6$ matrix  $ (A \vert I)$, where $A$ is the matrix you want to invert and $I$ the unit matrix. When you have finished the process, you'll get a matrix like $(I\vert A^{-1})$ and the matrix on the right, yes!, is the inverse of $A$. (For more about this approach see Hoffman and Kunzi). I prefer this way personally. The point we should care about it is that: When you are doing the way, whenever we need to multiply a number to another one, we consider the operation in $\mathbb Z_5$. For example, if we want to multiply the row $$(1~~2~~0)$$ by 3, we, indeed, have $$3(1~~2~~0)=(4~~0~~3)$$ because $3\times 1=3+1=4$ and $3\times 2=3+2=5=0$.
Comment: Very well put and exemplified! +1
Answer: Hint: Use the adjugate matrix.
Answer: The cofactor matrix of $A$ comes
$\color{grey}{C_A=
\begin{pmatrix}
+\begin{vmatrix} 2 & 4 \\ 0 & 3 \end{vmatrix} & -\begin{vmatrix} 0 & 4 \\ 0 & 3 \end{vmatrix} & +\begin{vmatrix} 0 & 2 \\ 0 & 0 \end{vmatrix} \\
-\begin{vmatrix} 2 & 0 \\ 0 & 3 \end{vmatrix} & +\begin{vmatrix} 1 & 0 \\ 0 & 3 \end{vmatrix} & -\begin{vmatrix} 1 & 2 \\ 0 & 0 \end{vmatrix} \\
+\begin{vmatrix} 2 & 0 \\ 2 & 4 \end{vmatrix} & -\begin{vmatrix} 1 & 0 \\ 0 & 4 \end{vmatrix} & +\begin{vmatrix} 1 & 2 \\ 0 & 2 \end{vmatrix}
\end{pmatrix}=
\begin{pmatrix}
6 & 0 & 0 \\
-6 & 3 & 0 \\
8 & -4 & 2
\end{pmatrix}=}
\begin{pmatrix}
1 & 0 & 0 \\
-1 & 3 & 0 \\
3 & 1 & 2
\end{pmatrix}.$
Therefore the adjugate matrix of $A$ is
$\color{grey}{\text{adj}(A)=C_A^T=
\begin{pmatrix}
1 & 0 & 0 \\
-1 & 3 & 0 \\
3 & 1 & 2
\end{pmatrix}^T=}
\begin{pmatrix}
1 & -1 & 3 \\
0 & 3 & 1 \\
0 & 0 & 2
\end{pmatrix}$.
Since $\det{(A)}=1$, it follows that $A^{-1}=\text{adj}(A)=
\begin{pmatrix}
1 & -1 & 3 \\
0 & 3 & 1 \\
0 & 0 & 2
\end{pmatrix}$.
And we confirm this by multiplying them matrices:
$\begin{pmatrix} 1 & -1 & 3 \\ 0 & 3 & 1 \\ 0 & 0 & 2\end{pmatrix}
\begin{pmatrix} 1 & 2 & 0 \\ 0 & 2 & 4 \\ 0 & 0 & 3\end{pmatrix}=
\begin{pmatrix} 1 & 0 & 5 \\ 0 & 6 & 15 \\ 0 & 0 & 6\end{pmatrix}=
\begin{pmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1\end{pmatrix}$.
Answer: "I was thinking that to find inverses separately of the each term in Z5 and then form the matrix?" The way I interpret that sentence you are saying that $(a_{ij})^{-1}=(a_{ij}^{-1})$ which is not true.
To find the inverse of a matrix you can't just take the inverse of each element. Now to answer the question, it depends on how/what can you use to compute the inverse. If you are doing it by hand, then just make a quick addition and multiplication table of $\mathbb{Z_5}$ and just find the inverse exactly as how you would with real numbers except that all addition, subtraction, multiplication, and division should be done in $\mathbb{Z_5}$.
If you are using Matlab for example, then (in general) just take the "normal" inverse (over the reals), multiply every entry in the matrix by the (real) determinant which would turn all entries into integers if you had any decimals/rationals. Then multiply all of the entries in the matrix by the multiplicative inverse of the determinant in $\mathbb{Z_5}$ to "undo" the real multiplication you did. You still have all integers. Then you reduce mod 5 and done.
In your case, the determinant in reals is 6 meaning the determinant over $\mathbb{Z_5}$ is 1. General rule, if the determinant is invertible in whatever number system you working in, the matrix will be invertible too. So in this case your matrix is invertible AND you don't have to do the last two steps where you multiply by the determinant and then its inverse.


What are some good resources to review basic university calculus, years later?

Question: So, I have reason to be returning to school, many years (5+) after my last attendance; and although I took (and passed, barely, after much strife) Calculus 1 and 2 at my previous university, I am very not secure in my knowledge of those topics.
What are some resources for me to self-review that material, outside of an academic framework? I have my old text-book, but I don't recall it being particularly accessible; and more importantly, I'd really like an accelerated approach that assumes prior knowledge of the material. (Books, websites welcome … I'm not a fan of video lecturing or similar, it seems a very slow way to consume information, but if you've a great resource, I suppose I'd take that too :P)
Comment: Khan academy is pretty good for early Calculus, even though it's pretty informal (and they're video lectures). Playing the videos at x1.25 speed makes it ok.

Perhaps you want to expand what topics you need to review (I'm guessing sequences, integration, series, line integrals and such?).
Comment: Presumably you're going to need some math for whatever you intend to do or this wouldn't come up. You say you just barely passed calculus five years ago. My advice is not to think about "reviewing" calculus, instead you should take the course again and _learn_ it this time. Students who've just barely passed calculus are _not_ ready for courses that depend on calculus, even if they took calculus the previous year. In your case it's going to be worse. Honest. Every time I teach differential equations I advise some students to retake calculus first. They never do. And they never pass DE.
Comment: While not a great help to answer your question, I recommend laying out the learning objectives clearly. This will help you identify the breadth and depth you want to go to.
Comment: I would possibly suggest *E-Z Calculus* by Douglas Downing, although this doesn't answer your question exactly, because it's not for people who already know calculus.
Comment: It would be helpful if you could clarify certain points. How much do you know already? Do you value rigour?
Comment: This is all good information! I was very solid in precalc; MS1122, I highly value rigor (I've been working as a professional programmer for many years; and I still *love* math), it's only specifically material *at the calculus level* I had trouble with, later~
Comment: David: Although I'd already made the decision before reading your advice, so I can't credit you with any great influence … this is exactly what I've decided to do. =) Due partially to a heavy class-load elsewhere, and partially to a desire for aforementioned rigor, I opted to sign up for Calc I for the … sixth? seventh? time in my life. Here's hoping a little age and maturity lends itself to success. Wish me luck!
Answer: I would say that for exercises, almost any calculus book should do. For reviewing fundamental concepts I think that Mathematics: From the Birth of Numbers by Jan Gullberg is a fairly good reference, just because it includes so many topics. If calculus was a struggle for you last time you went to school it might be good to review some of the pre-calculus material that is also included in this book. Also if you search this board I'm sure you will find many posts asking for the same advice, perhaps you will find what you are looking for among the answers to those questions.
Comment: Check out e.g. William Chen's [lecture notes](https://rutherglen.science.mq.edu.au/~maths/Chen-notes/ln.html)
Answer: I would definitely check out Khan Academy. Although the website is based around video lecturing, the websites most effective feature are the exercises that are provided on every topic. You get immediate feedback on what you know and don't know. This can save you a lot of time. Then you only watch the lecture you need too. You can also speed the lectures up.
Here is a link to the website:
https://www.khanacademy.org/math/algebra2
More importantly, If you had a difficult time at Calculus 5+ years ago, you maybe should start with Algebra II or similar, then work through Trigonometry, Precalculus, then Calculus. Although, this seems like a lot of work, by utilizing Khan Academy's practice exercise feature you may find that you remember the material and are able to spend less time on skills that you already know. This will allow you to identify skills that you are deficient in and allow you to study more effectively.
Comment: A week in, I have to say: Khan Academy is *exactly* what I needed, despite having some video content. Great suggestion!


Invoking JavaScript Self Executing Function with Parameters

Question: I am reading and trying some examples of self executing JavaScript function. I found a few examples on how to call them, but I am still a little confused as to the proper way to create and call them. For example, If I have a foo method inside this self executing function that takes 2 parameters, param1 and param2. How do I call this method? You can pass global objects such as window, document, etc. What about parameters that are not global but need in order for the function to perform some action?
Here is an example:
foo.js
(function (window, document, $, undefined) {
    function foo(param1, param2) {
        //do stuffs here
    }
})(window, document, jQuery);

index.html:

Comment: You've not defined a `Foo`. The `foo` you did define is not referenceable through the global namespace so you can't use it externally (you would need to set up some reference first). _undefined_ is _non-configurable, non-writable_ in the global namespace, creating it as a property like this makes it writable so can be considered bad practice.
Answer: Not having functions inside global scope is whole point of having IIFE as called by Ben Alman. Point of them is invoke some code without affecting global scope. You can create as many counters as you want and they will not affect each other as they are in separate "scope".
If insist to use Foo in global scope with using IIFE, you want to update your example and need to assign it to window parameter you passed it inside IIFE.
(function (window, document, $, undefined) {
    window.Foo = foo;
    function foo(param1, param2) {
        //do stuffs here
    }
})(window, document, jQuery);

This way you will have Foo in global scope and thus you can use new Foo(param, param)


Resgatar texto HTML do banco de dados MySQL com o EJS (Node.js)

Question: Estou desenvolvendo um portal de notícias em Node.js onde salvo os posts em um banco de dados MySQL. Como template engine, uso o EJS.
Uso o plugin Tinymce para formatar o texto dos posts (usar negrito, italico e etc). O Tinymce é um editor visual para páginas da Internet robusto escrito completamente em JavaScript.
Este plugin salva no banco de dados o texto já formatado em HTML. Por exemplo:
negrito e
texto em paragrafo

O problema está na hora de apresentar este conteúdo. Faço a consulta no banco de dados e retorna com as tags, e não o texto formatado. Estou chamando o tinymce da maneira correta:

E está salvando certo no banco. Mas quando realizo a consulta para visualizar, ele mostra assim:

O código da view é este:

                    <%= noticia[0].autor %>
                    <%= noticia[0].titulo %>
                    <%= moment(noticia[0].data_criacao).format('DD/MM/YYYY') %>

                        <%= noticia[0].noticia %>

Alguém pode dar uma luz?
Answer: Precisas que o EJS mostre esse HTML sem o escapar. Olhando para a documentação o comando para isso é <%-, assim podes fazer:

    <%- noticia[0].noticia %>

Comment: Meu amigo Sergio, muito obrigado. Tenho quebrado a cabeça com isso já há algum tempo... Confesso que não conhecia o lance de escapar e não escapar o HTML, então, quando olhei a documentação, não achei a solução. Muito, mas muito obrigado mesmo cara.
Comment: @RodrigoZandonadi otimo poder ajudar. Se quiseres podes clicar e marcar a resposta como aceite.
Comment: Sergio, eu tentei, mas como sou usuário novo meu voto não é computado... sorry
Comment: @RodrigoZandonadi para aceitar não precisas de pontos. É um simbolo por baixo das setas de votar e da pontuação da resposta.
Comment: @RodrigoZandonadi https://pt.meta.stackoverflow.com/q/1078/129


Random Forests- Out of Bag Error Calculation

Question: I was learning about the Out of Bag error in random forests and I did not understand a point about the error calculation. Assume we have N bootstraps and there are a number of Out-Of-Bag samples for each one of these bootstraps.We can have a sample, say for instance sample x, appear in Out-Of-Bag part of multiple bootstraps. In such a case, do we consider these multiple x's as a single test sample or we will consider each one of them separately and say we have , for instance 5, test samples ( all being x),  ? Thanks in advance.
Answer: I asked the question to the professor of the course I am taking. It turns out that when you have the Out-Of-Bag sample in multiple bootstraps, you only consider that sample once. For instance, the sample x occurred in Out-Of-Bag part of multiple bootstraps. When calculating the test set size , you consider these multiple x's as a unique (1) test sample.


Tips for remote work?

Question: I'm about to start full-time telecommuting.  I would like to save myself some trouble and learn from everyone's experience.
I'm pretty much an IT generalist in a small office, but I focus more on SQL Server and the business intelligence side of things.
I'm moving to a different city (5 hours away), with laptop and cell phone as my mobile office.
What tips do you have for me?
What pitfalls should I look out for?
Answer: Well, first of all, I hope whatever company you will be working for is going to both provide you with VPN access, as well as pay for your home internet, since it is now a business requirement.  Once that stuff is out of the way...
Ensure your workspace is both comfortable and void of too many distractions.  It is very easy to be either 10x more productive when working remotely, and also 100x less productive.  You will have to learn to manage your time very well.
It can also be hard to get used to not working in collaborative environment, so make sure the proper communication mediums are present.  Invest in a quality phone with either a good speakerphone, a comfortable headset, or both.  One thing I hated when I worked remotely was long conference calls on a crappy phone.
Depending on how mobile you will be, since you mentioned a laptop and cell phone as your mobile office, I would suggest setting yourself up with some sort of semi-permanent home office with the above prescribed phone setup, which you can set your cell phone to forward to, as well as a proper keyboard-mouse-monitor and a quality laptop docking station.
The biggest pitfalls are avoiding the distractions, staying connected, and staying visible.
When the boss is considering who to promote, since he doesn't see your face around the office every day, you might not be at the top of the list.
Make sure your presence is known.
Answer: Techical aspects aside, telecommuting requires a lot of trust, especially in the begining. Make sure you're reachable by phone, email at all time during work hours. If you're to take a short break from the computer, send a reminder to your manager.
Answer:
Setup VPN access (e.g., using Hamachi or other) to the office
install a remote boot device on the server(s) if their admin is your responsibility
if using Terminal Server set it up so that you can disconnect from your session and it will keep running (e.g., set a very long, or no, timeout)
if doing development work, setup a local copy of SQL Server, etc., so that you can work for the most part without connection to the office for much better speed. Then, connect when you need to deploy.
Answer: I worked from home a couple days a week for a year or so to help lower the amount of commuting days I had.  I agree with the first post, make sure to have a seperate comfortable room in the house to work out of to eliminate distractions.  Working at the kitchen table has to many distractions.
I found having my own designated office with a door was nice.  I used my laptop at home, but used a terminal services session to work off of a lot.  We had a terminal services server, so I loaded Microsoft Office and other software I needed on it.  Created my profile on it and mostly worked off of that for the speed.  It was like working in the office.
We also had VOIP in the office, so I had a cisco phone on my desk at home with my work extension on it.  Being I had a firewall in my home with a site to site tunnel the one phone worked great.  Users calling me had no idea I was in my home office.
Between those three items, I was in serious good shape.  However sometimes there were those occasions where I would have needed to be in front of the server, but then I just called one of my counterparts.
Oh, if your office uses citrix at all, that is a great tool for remote working.
Good luck, hope all goes well.
Comment: re: office with a door.  It must have 4 walls and be devoted solely to work in order to claim it on taxes in the US.  Might look into it ahead of time if Canada does anything similar.
Answer: Brent Ozar had a few good blog posts about it. I read all of them, and I am never going to get to telecommute.
Comment: you beat me on posting Brent's link. +1 vote for your reward ;-)
Answer: Other people have talked about the need to manage time, setup a separate area and so forth, but the one thing that I generally missed / needed off site is what I call "office culture".
You can have all the phone conversations, email theads or IM'ing as you want, but for some things you just can't beat physical face-to-face contact, even if it is to talk up your football team's exploits on the weekend.
Aim to have some office time reasonably regularly to maintain physical contact. One negative aspect of you not being in the office (unless everyone else does it too) is that when you're not seen in the office, you might not be seen to be doing work by your co-workers.
Comment: Absolutely agree with this- I've made an effort to join the local nerd meetups, just to get some human contact with other professionals. Definitely worth looking into finding the local pack of geeks and joining them for drinks, lunches, etc.
Answer: Test your VPN connection before you go.  Too many things are changing at once.  You want to have a baseline before you move 5 hours away.
Answer:
Laptops die easily- make sure you have a really really robust backup system running, preferably with your backups going offsite. Drobo, Carbonite, Mozy, etc.
Buy a really good quality phone headset.
Spend money on a good chair if you'll be in the home office for any length of time.
Buy a subscription to O'reilly's Safari service to act as the technical library that you can't get to at work any more.

Tips for remote work?


Golang: why does the word "hello" loop 5 times while the word "world" loops only 4?

Question: package main

import (
    "fmt"
    "time"
)

func say(s string) {
    for i := 0; i < 5; i++ {
        time.Sleep(1000 * time.Millisecond)
        fmt.Println(s)
    }
}

func main() {
    go say("world")
    say("hello")
}

Run the code, the output is:
hello
world
hello
world
hello
world
hello
world
hello

In first 4 loops,every 100ms, a "hello" will be printed followed by a "world". and only a "hello" will be printed in the last loop.
Is there anybody can explain What's the execution sequence of the code?
Comment: Likely the program terminates before the last `world` gets printed.
Comment: Also related: [Goroutine does not execute if time.Sleep included](http://stackoverflow.com/questions/28307783/goroutine-does-not-execute-if-time-sleep-included)
Comment: What @DavidSchwartz points out is likely correct, can you add a 2 second sleep to the end of the main method and report the result?
Comment: Considering this exact example came up before, where is its source? Maybe there is a bug in the source documentation we can report.
Answer: Likely the program terminates before the last world gets printed. –  David Schwartz
Go programs don't wait for all goroutines to finish before exiting.  If you want to wait for the "world"s to finish printing, you can use a WaitGroup.
e.g.
Add "sync" to your imports, and call it with:
func main() {
    var wg sync.WaitGroup
    wg.Add(1)
    go func() {
        defer wg.Done()
        say("world")
    }()
    say("hello")
    wg.Wait()
}


Prove the following function is injective/surjective

Question: I have the following problem using notation and terms I do not fully understand.
Let f: X $\to$ Y be a function. Prove that:
If there exists a function g: Y$\to$X such that g$\circ$f = 1$_X$, then f: X$\to$Y is injective
If there exists a function h: Y$\to$X such that f$\circ$h = 1$_Y$, then f: X$\to$Y is surjective
My problem starts with understanding what injective and surjective. These terms haven't been used in class, so I am not sure what the question is ultimately asking.
Secondly, I do not know what 1$_Y$ is equivalent to, or what it is in reference to.
Lastly, the prof gave us this bit of information that I do not fully understand:
f: X$\to$Y. If there exists g:Y$\to$X and h:Y$\to$X $\in$ g$\circ$f  then  f:X$\to$Y is bijective.
What makes this true? What does it mean for something to be bijective? I would assume that it means both subjective and surjective, but I cannot be certain.
Comment: The functions $g$ and $h$ are respectively [left and right inverse functions](https://en.wikipedia.org/wiki/Inverse_function#Left_and_right_inverses) for $f$. The functions $1_X$ and $1_Y$, usually denoted by $\operatorname{id}_X$ and $\operatorname{id}_Y$, are [identity functions](https://en.wikipedia.org/wiki/Identity_function) on $X$ and $Y$ respectively. A function $f:X\to Y$ is said to be injective (or one-to-one) if for all $x,x'\in X$, $f(x)=f(x')$ implies $x=x'$...
Comment: ... It is said to be surjective if for every $y\in Y$ there exists an $x\in X$ such that $f(x)=y$. A function is said to be bijective if it is both injective and surjective. It is a theorem that if $f$ has a left and a right inverse then $f$ is bijective (and indeed it is a consequence of the two propositions you want to show).
Comment: Look at the links in the comment here: http://math.stackexchange.com/questions/553186/left-inverse-iff-injective-right-inverse-iff-surjective
Comment: This sounds like a case for asking your instructor, who will know exactly what you need for this course, not for getting random advice from the internet.
Answer: There are colloquial terms often used for "injective" and "surjective". They are "one-to-one" and "onto" respectively. "Bijective" just means "both injective and surjective", or "one-to-one and onto".
To understand them, we need to back up and look again at the definition of a function. Recall that a function actually consists of 3 objects $(f, A, B)$. $A$ is a set, called the domain of the function, $B$ is a set, called the codomain of the function, and $f$ itself is a rule that matches each $a \in A$ with exactly one $b$ in $B$. If $a$ is matched to $b$, then we use the symbolry $f(a)$ to mean $b$.
Some important things to note about that definition:

$f$ is required to match every element of $A$ with something in $B$.
$f$ is NOT required to match every element of $B$ with anything in $A$.
for each $a \in A$, there is only one $b \in B$ that is matched to it.
for each $b \in B$, $b$ may be the match of any number (including zero) of different $a\in A$.

So for example I can define $f : \{1,2,3\} \to \{4, 5, 6, 7\}$ by $f(1)=4, f(2) = 6, f(3) = 6$. This is a function. $1, 2, 3$ are each carried to only one element of the codomain. But $f(2) = f(3)$, while $4$ and $7$ are not the image of anything under $f$. The codomain of $f$ is actually bigger than is needed. This is allowed in our definition of function, because there are many times when such functions are useful. For example, $f : \Bbb R \to \Bbb R, f(x) = x^2$ would not count as a function if we did not allow these.
The terms Injective, surjective and bijective are introduced for those times when we don't want to allow this to happen. They are further conditions on functions that forbid it:

A function $f : A \to B$ is injective if for every $x, y \in A$, if $x \ne y$, then $f(x) \ne f(y)$. An equivalent way of stating this is: for every $x, y \in A$, if $f(x) = f(y)$, then $x = y$. So no element of $A$ is matched to more than one element of $B$ (because $f$ is a function) and no element of $B$ is matched to more than one element of $A$ (because $f$ is injective). So this condition is also called "one-to-one".
A function $f : A \to B$ is surjective if for every $b \in B$, there is some $a \in A$ such that $f(a) = b$. Surjective just means the codomain $B$ isn't any bigger than it needs to be. There is nothing in it that is missed by $f$. Thus $f$ is said to be "onto $B$".
A function is bijective if it is both one-to-one and onto.

On any set $A$, $1_A$ denotes the identity function: $1_A : A \to A : a \mapsto a$. That is, for each $a \in A, 1_A(a) = a$.

Now, you are given a function $f:X\to Y$.
The first question is:

Show that if there exists $g : Y \to X$ such that $g\circ f = 1_X$, then $f$ is injective.

Translated: you are given that there is a $g : Y \to X$ such that for all $x \in X, g(f(x)) = x$. From this, prove that for all $x \in X, r \in X$, if $f(x) = f(r)$, then $x = r$.
The second question is:

Show that if there exists $h : Y \to X$ such that $f \circ h = 1_Y$, then $f$ is surjective.

Translated: you are givent that there is an $h : Y \to X$ such that for all $y \in Y, f(h(y)) = y$. From this, prove that for all $y \in Y$, there is an $x \in X$ such that $f(x) = y$.

Finally, your last statement is incomplete. It should be: If there exists $g : Y \to X, h : Y \to X$ such that $g \circ f = 1_X$ and $f \circ h = 1_Y$, then $f$ is bijective.
This follows automatically from the previous statements.
If you think about each of these statements, you will see that $g$ "undoes" $f$, so it can be used to prove that $x = r$. And $h(y)$ provides you with the value $x$ you need for $f(x) = y$.
(And once you get those, see if you can go one step farther and prove that if $f$ is bijective, then $g = h$.)


Why would drush sql-sync fail to work?

Question: I have a development server set up in my drush aliases as @dev, and a UAT server set up as @uat.  I can successfully execute drush commands locally on both servers, and I can execute remote commands from UAT to the development server (e.g. drush @dev cc all or drush @dev upc or whatever).  However, when from the UAT server I execute
drush sql-sync @uat @dev

it appears to work, but when I first make a change on UAT and then sync and then check the same page on dev is has not changed.   I have tried drush @dev cc all afterward to make sure there is no caching problem, but this doesn't help.
What could I be missing?  Or what could be failing?  How can I troubleshoot this?
UPDATE (corrected): If I log into @dev and execute the same command (in other words, having @dev pull data from @uat rather than having @uat push data to @dev) it works.   But I'd still like to get it working when executed from @uat.
Answer: There's not enough here to tell what's wrong, but there are a couple of things you can do to isolate the problem. Start with drush @uat sql-conf and drush @dev sql-conf; this is what Drush will use to look up the database records for the two sites.  If one of these fails to print the right information, that could cause sql-sync to fail.  Next, try drush sa --with-db @uat and again for @dev, and see if the database record matches what you saw with sql-conf.  If, for example, you copied a database record into your @dev alias and specified the wrong database (one different than the one specified in settings.php), then sql-sync might be successfully copying your production database to some other db on the dev machine.
If neither of these things work, you can try adding first -v (verbose output) and then -d (debug mode -- really a lot of output) and see if there is anything there that might help you find the problem.
Update: Did you make a typo in your update?  drush sql-sync @dev @uat pushes dev to uat, which seems like the opposite operation.  If drush sql-sync @uat @dev works on dev and not on uat, I would recommend carefully comparing your alias files on the two machines and see if there are any differences.  Especially check your 'databases' record in your alias definition, if you have any, and run the diagnostic tests I recommend above.  As a workaround, from uat you could run drush @dev sql-sync @uat @dev, which would remotely run drush sql-sync @uat @dev on the dev machine.
Comment: Yes, sorry.  I corrected the error in my update now.
Comment: I'll try your suggestions soon...
Comment: You're right, there were errors in the aliases file on @dev... all fixed now.
Comment: To add to Greg's answer, I also ran into this just last night when the path to drush on my server had changed. e.g. from /usr/bin/drush to /usr/local/bin/drush - I found it, however, using his sql-conf trick. Thanks Greg!
Answer: I had the same problem.
My solution was to add the ending '--no-cache'
drush sql-sync @dev @local --no-cache
If you don't do that, drush takes the last saved sql-dump.
Cheers Stefan
Answer: I've solved my problem with sql-sync after I updated the drush version on my localhost. It was 5.7 on localhost and 6.0-rc4 on server.
After update the drush version on localhost is 7.0-dev. sql-sync works well!
Answer: I had the same weird problem and after cleared @dev cache it worked.
Answer: When I encountered this issue, I used verbosity (--verbose) to find that I was getting a MYSQL error 2013 "Lost connection to MySQL server during query" in the last stage of the synch.
Turns out my packet size was too small so my end couldn't finish the job.
That is not necessarily meant to be a double entendre.
So I edited the my.cnf (mine was in /etc/mysql) and cranked it from 16M to 128M.
Also, had to use --no-cache.

Why would drush sql-sync fail to work?


Estimate for derivative of a function

Question: I'm self studying analytic number theory and I wonder how the proof goes for this problem: If $f (x) $ satisfies $f (x)=x^2+O (x) $, and $f $ is differentiable with nondecreasing derivative $f'(x) $ for sufficiently large $x $, then $f'(x)=2x+O (\sqrt{x}) $.
I have a proof but I did not use the fact that $f'$ is nondecreasing so I bet that my proof is wrong. Any help will be greatly appreciated.
It can be shown that for sufficiently large x, $f'(x)=2x+O (1) $. Basically, I just used the hypothesis and the limit definition of the derivative. So now, by dividing by $\sqrt {x} $, we obtain $\dfrac {f'(x)}{\sqrt{x}}=2\sqrt {x}+O \left(\dfrac {1}{\sqrt {x}}\right)=2\sqrt {x}+O (1) $. So multiplying by $\sqrt {x} $ we get the desired result. But I'm pretty sure that there is a flaw in my proof.
Comment: If you show us your proof, we might tell you where it goes wrong (if it does).
Answer: It holds $$x^m = \mathcal{O}(x^n),\qquad m≤n, \qquad x→∞,$$
because of $$\frac{x^m}{x^n} = x^{m-n} →\begin{cases}0 &m≤n\\1 & m=n \\ ∞ &m≥n\end{cases}\quad \text{for } x→∞.$$
Therefore if $g(x)=\mathcal{O}(1)=\mathcal{O}(x^0)$ it follows $g(x)=\mathcal{O}(x^{\frac{1}{2}})$ for $x→∞$.
This should help you proof the desired result, with what you already have done so far.
The information $f'$ to be nondecreasing is an information, which is not necessary for the proof. IMO that can be best seen by the following argument, instead of a rigorous proof.
If $f(x)=x^2+\mathcal{O}(x)$, then it is $f'(x)=x+\mathcal{O}(1)$. Let $f'(x)=h(x)+g(x)$, with $h(x)=x$ and $g$ being that function that behaves like $\mathcal{O}(1)$.
This means
$$\frac{g(x)}{1}→c∈ℝ,\qquad x→∞.$$
And that means, that the governing part of $f'$ is $h(x)=x$, because $g$ can not grow as fast as $h$ does. So for sufficiently large $x$ the behaviour of $f'$ will be like $h$, and $h$ is nondecreasing.

Edit:
I somehow missed the last equation of your proof. What you did is correct, since you used what I stated in this answer, in your last "="-step.
Comment: Woah thanks for enlightening me about the information about $f'$. I just realized that in studying these estimates, I really have to understand what is going on. Thank you very much!

Estimate for derivative of a function


Enabling mod_session_crypto hangs apache 2.4

Question: I want to try using session crypto on my apache installation so I uncomment the following line.
<code>   #LoadModule session_crypto_module modules/mod_session_crypto.so
</code>
I restart apache and it gives me no errors. Then I browse to the site and I get nothing, just error.

"Unable to make a secure connection to the server. This may be a
  problem with the server, or it may be requiring a client
  authentication certificate that you don't have. Error code:
  ERR_SSL_PROTOCOL_ERROR"

The site is SSL only. Adding the comment back to my httpd.conf for mod_session_crypto returns the site to working order.
I am also receive the following error (repeatedly) in my error log when I load the crypto module.
<code>[core:notice] [pid 16959:tid 139988902364992] AH00052: child pid 16971 exit signal Segmentation fault (11)
</code>
When unloaded the error goes away. I'm using mod_auth_form and mod_session_cookie to authenticate a login, but I need crypto because the session cookie stores the username and password in plain text right in the browser cookie!
Why is crypto making my server halt?  I'm merely loading it, not even setting any of the additional variables required to make it work at this point.  How can I resolve this problem?
Answer: Well after over a week I managed to come to a conclusion on the why part of my problem. Apache needs to be configured with --enable-session-crypto, in order for mod_session_crypto to work, as it is just an experimental package and not enabled by default. One would assume that since the module is available in the /modules folder that loadmodule would suffice but apparently it does not and apache needs to be rebuilt and re-installed to get this option.


Complex Numbers and Hyperbolic Functions

Question: How would you evaluate: $\mathfrak{R}\left[(1+i)\sin\left(\dfrac{(2+i)\pi}{4}\right)\right]$?
I know that $\cos x = \dfrac{e^{ix}+e^{-ix}}{2}$ and $\sin x = \dfrac{e^{ix}-e^{-ix}}{2i}$.
I have also tried expanding the $\sin\left(\dfrac{(2+i)\pi}{4}\right)$ part to $\sin\left(\dfrac{\pi}{2}\right)\cos\left(\dfrac{i\pi}{4}\right)+\cos\left(\dfrac{\pi}{2}\right)\sin\left(\dfrac{i\pi}{4}\right)$ using the addition formula for $\sin$ angle.
Answer: We know that
$$
\sin\left(\dfrac{(2+i)\pi}{4}\right)=\sin\left(\dfrac{\pi}{2}+\frac{i\pi}{4}\right)=\cos\left(\frac{i\pi}{4}\right),
$$
then
$$
\begin{align}
(1+i)\sin\left(\dfrac{(2+i)\pi}{4}\right)&= (1+i)\cos\left(\frac{i\pi}{4}\right)\\
&=(1+i)\left(\dfrac{e^{i\frac{i\pi}{4}}+e^{-i\frac{i\pi}{4}}}{2}\right)\\
&=(1+i)\left(\dfrac{e^{-\frac{\pi}{4}}+e^{\frac{\pi}{4}}}{2}\right)\\
&=\left(\dfrac{e^{-\frac{\pi}{4}}+e^{\frac{\pi}{4}}}{2}\right)+i\left(\dfrac{e^{-\frac{\pi}{4}}+e^{\frac{\pi}{4}}}{2}\right).
\end{align}
$$
Comment: Use this $\cos x = \dfrac{e^{ix}+e^{-ix}}{2}$ and take $x=\dfrac{i\pi}{4}$.
Comment: yeah got it. Thanks.
Comment: so that makes it Re[(1+i)cos(pi/4)i]. HOw do i separate the imaginary term from the real term?
Answer: $$\sin\frac{(2+i)\pi}4=\sin\left(\frac\pi2+\frac\pi4i\right)=\cos\frac\pi4i$$
But
$$\cos\frac\pi4i=\frac12\left(e^{-\frac\pi4}+e^{\frac\pi4}\right)\implies$$
$$(1+i)\sin\frac{(2+i)\pi}4=\ldots$$
Comment: Look at the value of $\;\cos\frac{\pi}4i=\cosh\frac\pi4\in\Bbb R\;$...!
Comment: so that makes it Re[(1+i)cos(pi/4)i]. HOw do i separate the imaginary term from the real term?


Why am I seeing more notes than allowed to be in a bar?

Question: Consider:

Quarter notes + 4 32nd notes + 8th note.
In a 3/8 time signature, there should be no space for the 8th note. What am I not seeing?
Comment: Note that the "extra" notes are printed in smaller type.
Comment: I added the picture for you. You do not need to host pictures on third party sites
Answer: That seems to be a turn. It is indicated in front of the note so as to tell you to play the ornament before the pulse. Those will be played very quickly as not to take away too much from the pulse.
These are just like the cherry on the cake, embellishment, little extra ways in which music is made interesting.
Comment: @BioPipeRex Rather than posting lots of "thanks" messages, just upvote any answers that you find helpful (even on other people's questions), and check the green box to "accept" one if it solves your question.
Comment: Thanks a bunch Neil, need to "Thank" since you all gave me nice answers ha :)
Edit: Just saw stack telling me not to thank in posts, what happened to morals, thanking everyone here i guess :)
Answer: The little notes in this bar  (little as in "smaller noteheads and beams") are called grace notes. They don't count towards the total, and how they are played depends on the context. Your example might be played like this:
Answer: You are seeing, and counting, an ornament. See it play it, but it has no extra count in this bar.This is called a turn and is usually played so that it starts at the moment when that last quaver would be played. Here, it appears to be wanted to be played so the last quaver is on time.Sometimes these are written out in full, using smaller dots than the rest of them, sometimes just with a sign. There are various different ornaments, all being named separately, and the timing can and does vary.
Comment: Thanks a bunch for this explanation, i was wondering if you by any chance would know how i would write that turn in GP6?
Comment: There's probably (should be!) a list of ornaments to write in, but I use a much earlier Guitar Pro, so sorry, can't help.
Comment: I don't use Guitar Pro.. but I would also call these Grace notes.. maybe they're indicated like that in GP?  I found the following in GP6 documentation `Grace-note before the beat: A Grace note is an ornamentation that consists in a very short note played before another one. In
Guitar Pro, you can add a grace note for each string. However, it is not possible to set several grace
notes on the same string. A grace note does not count for the bar duration and for the rhythm
display.`
Comment: @Greg - Grace notes, ornaments, yes. On guitar, hammers, pull-offs, taps, slides. This appears to be an appoggiatura, one extra note on the same string (expected). Perhaps the facility's not available. These grace notes came about to relieve the tedium of same volume playing on harpsichords, etc.
Comment: @Tim: GIven that the notes are printed smaller than everything else, I would regard them as grace notes which are supposed to be played immediately before the following note, which should land on the beat.
Comment: @supercat - in this case, certainly, probably why they're written in. But I think there is some debate as to exactly when 'grace notes' *are* played, depending on period, composer and style.
Comment: @Tim: What "immediately before" means would depend upon context, and if a part contains an ornamental phrase which is supposed to start on a beat it may be unclear how to notate that *if there is no other part to line it up with*.  If one accepts the principle that simultaneous notes should be aligned vertically, however, I think that would imply that the ornaments in this case should entirely precede the beat.
Answer: Even though they are joined with beams, the 32nd notes are printed smaller than the surrounding notes.  To my eye, that would suggest that they should be interpreted as grace notes.  While grace notes are typically printed with a single flag and a slash, a run of such notes would make music hard to read, as would a run of non-beamed sixteenth or thirty-second notes.  I would thus regard the triple beams not as an indicating that the smaller notes should each have a duration equal to one thirty-second note, but rather merely as a means of making a group of grace notes more readable.
Answer: The 32nd notes are just there to denote a flourish, almost like a pick up to the next note.


Mean Distance on a 3-sphere?

Question: What is the (analytical) mean geodesic distance between a set of randomly chosen points on a 3-sphere?
Comment: Can you show an attempt to solve the problem?
Comment: Symmetry (in arbitrary dimension) resolves the question Very Easily.... :)
Answer: The volume element of a $(n-1)$-sphere is given by
$$d_{S^{n-1}}V = \sin^{n-2}(\phi_1)\sin^{n-3}(\phi_3)\cdots\sin(\phi_{n-2}) d\phi_1d\phi_2\cdots d\phi_{n-1}$$
and the admissible range for $\phi_i$ is $[0,\pi]$ for $1 \le i \le n-2$ and $[0,2\pi]$
for $i = n-1$.
So for a 3-sphere, the average distance is just
$$\frac{\int_0^{\pi} \phi \sin^2(\phi) d\phi}{\int_0^{\pi} \sin^2(\phi) d\phi} \tag{*}$$
Notice
$$\sin^2(\phi) = \sin^2(\pi - \phi) \quad\implies\quad
\int_0^{\pi} \phi \sin^2(\phi) d\phi = \int_0^{\pi} (\pi - \phi) \sin^2(\phi) d\phi$$
It is then clear the average in $(*)$ is just $\frac{\pi}{2}$.
Alternatively, one can pick a point $p$ on $S^n$ as origin. The reflection of $S^n$ in the direction of $p$ in the ambient space $\mathbb{R}^{n+1}$:
$$S^n \ni \vec{x}\quad\longrightarrow\quad 2 (\vec{p}\cdot\vec{x}) \vec{p} - \vec{x} \in S^n$$
is an isometry of $S^n$ and sends a point at a distance $r$ from $p$ to a distance $\pi - r$ from $p$.
Averaging over this sort of pairs always give us $\frac{\pi}{2}$.

Mean Distance on a 3-sphere?


De Morgan's Laws and Boolean Simplification

Question: I have a computer science exam soon, and apparently we are supposed to learn De Morgan's Laws as well as Karnaugh Maps for Boolean simplification. However, I can breeze through Karnaugh maps, but I just don't understand what De Morgan's Laws are and how they are used for Boolean simplification.
If anyone could guide me to a helpful web page or explain his laws, it will be much appreciated. Thanks
Comment: https://en.wikipedia.org/wiki/De_Morgan%27s_laws
Answer: DeMorgan's identities, better known as DeMorgan's Theorems, are extremely powerful and heavily used properties of Boolean logic. In essence, they say that and OR gate can be swapped with an AND gate (and vice-versa) without changing the logic function being implemented provided that ALL of the inputs and outputs to the gate are inverted as well.
Read this for proofs and stuff.


About priority_queue in c++ using comparator

Question: class Node {

public:
    char character;
    int frequency;
    Node *left, *right;

};

class ComparisonClass {

public:
    int operator()(Node *a, Node *b)
    {
        return a->frequency - b->frequency;
    }
};

    priority_queue<Node*, vector<Node*>, ComparisonClass> queue;

I want to this:
Example)
Node A : priority 20
Node B : priority 4
Node C : priority 6
Node D : priority 7
after sorting...
Node A(queue's 1st) : priority 20
Node D(queue's 2nd) : priority 7
Node C : priority 6
Node B : priority 4
Such this, I want to arrange priority in descending order.
But error -> Expression: invalid operator<
I can't solve this problem.
How should i fix this code??
this is my overall code
class Node {

public:
    char character;
    int frequency;
    Node *left, *right;

};

class ComparisonClass {

public:
    int operator()(Node *a, Node *b)
    {
        return a->frequency - b->frequency;
    }
};

class huffman {

public:
    priority_queue<Node*, vector<Node*>, ComparisonClass> queue;
    hash_map<char, string> *idc = new hash_map<char,string>();

/*
    Node* huffmanCoding(int n) // incomplete code
    {
        for (int i = 0; i < n - 1; i++)
        {
            Node *z = new Node();
            z->right = queue.top();
            queue.pop();
            z->left = queue.top();
            queue.pop();
            z->frequency = z->right->frequency + z->left->frequency;
            queue.push(z);
        }

        return queue.top();
    }
*/
};

int main()
{
    string str = "AAAAAAABBCCCDEEEEFFFFFFG";

    hash_map<char, int> dictionary;

    for (int i = 0; i < str.length(); i++)
    {
        char temp = str.at(i);

        if (dictionary.find(temp) != dictionary.end())
            dictionary.find(temp)->second++;

        else
            dictionary.insert(hash_map<char,int>::value_type(temp,1));
    }

    huffman *huf = new huffman();
    int number = 0;

    for (hash_map<char, int>::iterator iter = dictionary.begin();
        iter != dictionary.end(); ++iter)
    {
        Node *temp = new Node();

        temp->character = iter->first;
        temp->frequency = iter->second;

        huf->queue.push(temp); <- error point
        number++;
    }

}

Comment: Please show the code that has the error.
Comment: i included my overall code and check the error point(huf->queue.push(temp);)
Answer: Your comparator is incorrect. It has to return boolean. This should work:
class ComparisonClass
{
public:
    bool operator()(Node *a, Node *b)
    {
        return a->frequency frequency;
    }
};


How to add Product in Cart in Prestashop 1.6.7

Question: I am trying to add product in Cart in Prestashop 1.6.7.
But it doesn't working.
Below is my code:
$context=Context::getContext();//new Cart();

$id_cart=$context->cookie->__get('id_cart');
$lan_id = $this->context->language->id;
$cur_id = $this->context->currency->id;

$products_ids=16571;
$cart=new Cart($id_cart);
$cart->id_currency=$cur_id;
$cart->id_lang=$lan_id;
$cart->updateQty(1,$products_ids, null, false);

But above code is not working.
Answer: Somehow i manage my code as per below:
global $context;

$context=Context::getContext();//new Cart();

$id_cart=$context->cookie->__get('id_cart');
$lan_id = $context->cookie->__get('id_lang');
$cur_id = $context->cookie->__get('id_currency');

$products_ids=16571;
$cart=new Cart($id_cart);
$cart->id_currency=$cur_id;
$cart->id_lang=$lan_id;
$this->context->cart->update();
$cart->updateQty(1,16571);

But there is one error for carrier
There are no carriers available that deliver to this address.
Answer: I add some static Carrier ID in
classes/Cart.php

in getPackageList function at line no. approx. 1892
if (empty($product['carrier_list'])) {
    $product['carrier_list'] = array(
                                '0' => 10,
                                '1' => 11
                               );
}

Answer: Try adding the following code at the end of your code.
        $this->context->cart->save();
        $this->context->cookie->id_cart = (int)$this->context->cart->id;
        $this->context->cookie->write();
        $this->context->cart->autosetProductAddress();
        Hook::exec('actionAuthentication');
        CartRule::autoRemoveFromCart($this->context);
        CartRule::autoAddToCart($this->context);


Loading xslx file causes "NoneType object not iterable" error

Question: I want to read xlsx file but i am getting error
My code :
from openpyxl import load_workbook
wb = load_workbook(filename = 'F:\123.xlsx', use_iterators=True)

Error :
Traceback (most recent call last):
  File "<pyshell#4>", line 1, in <module>
    wb = load_workbook(filename = '123.xlsx', use_iterators=True)
  File "C:\Python27\lib\site-packages\openpyxl-2.3.0b1-py2.7.egg\openpyxl\reader\excel.py", line 202, in load_workbook
    parsed_styles = read_style_table(archive)
  File "C:\Python27\lib\site-packages\openpyxl-2.3.0b1-py2.7.egg\openpyxl\reader\style.py", line 181, in read_style_table
    p.parse()
  File "C:\Python27\lib\site-packages\openpyxl-2.3.0b1-py2.7.egg\openpyxl\reader\style.py", line 53, in parse
    self.parse_named_styles()
  File "C:\Python27\lib\site-packages\openpyxl-2.3.0b1-py2.7.egg\openpyxl\reader\style.py", line 109, in parse_named_styles
    names = self._parse_style_names()
  File "C:\Python27\lib\site-packages\openpyxl-2.3.0b1-py2.7.egg\openpyxl\reader\style.py", line 128, in _parse_style_names
    for _name in node:
TypeError: 'NoneType' object is not iterable

how it can be solved?
Comment: Even I am getting this error any ideas how to solve it ?
Comment: This works perfectly on linux. Still no solution for windows
Comment: I am getting this error on Mac , Linux and Windows it has something to do with the excel itself , currently the xm/stlye.xml is missing the cellStyle entry hence the error came.
Answer: This is a bug in openpyxml library, fortunately it was fixed and your issue can be solved by upgrading to 2.3.1 or newer. See my answer: https://stackoverflow.com/a/35669067/170918
Comment: Thank you. I will try :)


2-tier o 3-tier: Which is safer?

Question: I'm reading about architecture and found the following expression:
For instance, in a 2-tier Windows Forms or ASP.NET application, the machine running the interface code must-have credentials to access the database server. Switching to a 3-tier model in Which the data access code runs on an application server machine running the Means That code no longer the interface Needs Those credentials, making the system Potentially more secure. (Rockford Lhotka)
I can not Realize why i should use 3-tier app.
Answer: In a three-tier application, the middle tier (the application server) controls all access to data, so it is possible to specify very fine and specific access control rules (in code), much more than the database itself offers. Whatever an end-user wants to do, has to go through your code (in a two-tier application, the end-user "directly" talks to the database).
OTOH, if you stop using the database access protections, securing the data is now entirely up to your application and coding errors can create huge security holes.

2-tier o 3-tier: Which is safer?


What priors are typically used for the correlation parameter in a bivariate normal?

Question: The Bivariate normal distribution contains a correlation parameter. I want to implement an MCMC sampler to sample from the posterior distribution of the parameters of the bivariate normal distribution. I have already selected the priors for the mean and variance parameters. However, I was not sure how to choose the prior for $\rho\in(-1,1)$, the correlation parameter.
Are there any standard choices such as the Jeffreys prior or other noninformative priors? If so, what are they?
Comment: This [master thesis](https://ntnuopen.ntnu.no/ntnu-xmlui/handle/11250/2786134) considers a large number of priors for $\rho$.
Comment: See: https://stats.stackexchange.com/questions/304684/why-lkjcorr-is-a-good-prior-for-correlation-matrix Obviously, this is a little simpler, when you just have a bivariate normal rather than more dimensions.
Comment: @Björn Very interesting. Too bad they do not give the prior on $\rho$ explicitly.
Comment: @JarleTufto Perfect. I will accept it as an answer if you post it as such.
Comment: @Priorian "Link-only" answers are discouraged, see https://stats.meta.stackexchange.com/q/2487/77222, so the above comment will have to do for now.
Comment: @JarleTufto You could add a screenshot of the list of priors in page 32, but I respect your choice. So, no accepted answer for this question. Thanks!
Comment: Wikipedia has a [handy table of conjugate priors](https://en.wikipedia.org/wiki/Conjugate_prior#When_likelihood_function_is_a_continuous_distribution)
Comment: Have you considered representing $\rho$ with the Fisher transformation?  Because it will be approximately Normally distributed, you could use a standard conjugate prior.
Comment: @JarleTufto, "link-only" answers are discouraged unless there is context and there is no potential chance of link rot. While I agree with you, if you wish, you can briefly provide the context as well as any summary along with the archived link (which won't die) as an answer.
Answer: The Wishart distribution is the conjugate prior to the inverse of the covariance matrix of a multivariate normal distribution (it as a distribution over positive semi-definite matrices).
So instead of using separate priors for the variance and correlation, you can use it as a prior for the entire (inverse of) covariance matrix.
Comment: In the link you can find the marginal distributions of the matrix elements in the bivariate case - from that you can get an expression for $\rho$ as a (complicated) function of $\chi^2$ and normal random variables. I doubt however if this is useful in practice, and I'm not familiar with other useful priors for $\rho$.


JunOS Regular Expressions for AS Path

Question: I want to write a regex in Juniper MX960 router for BGP including 3 AS paths with first element is constant, second and third are wildcard. I found that we can put as numbers manually like this:
"9121+  (one|two|three|...) (one|two|three|...)". This doesn't work for me cause i don't know whole as numbers in second and third level. They can be anything. I want them to be "any".
"9121+ any+ any+" « I need this.
Thank you.
Comment: Need clarification. Must exactly two ASes follow 9121? Or do you want 9121 followed by zero or more ASes? Please be specific.
Comment: I need 3 ASes. First is 9121+ second and third can be anything. But the array must be consists of 3 ASes.
Answer: Assuming you want to match on any AS path that consists of exactly 3 AS numbers, with the first being 9121, you would want this:
9121 .+ .+
Comment: For the OP's edification, I'll point out that JUNOS regexes differ from Unix regexes in signficant ways such as the basic unit of matching is an AS rather than a character.
Comment: Firstly, doesn't it need to be end with ".$"?

I also need it to include bgp prepends. "+" is represent prepends in Juniper. I mean it can be multiple occurences of the same AS element such as:

"9121+ 34927+ 8685+" can represent:
"9121 34927 34927 8685" or "9121 9121 9121 34927 8685 8685".

I need 3 unique ASes after all. First is 9121 with prepend.
Comment: .+ can only match a single AS and the regex does not qualify a partial match, it must cover the entire path. so no, $ should not be necessary (although equally, it won't do any harm)
Comment: Ok then i will try "9121+ .+ .+" and will inform you. By the way how about this? "9121+ [0-65536]+ .$"
Comment: no, that's invalid, firstly, AS numbers nowadays are 32 bit, not 16 bit, and secondly, even if they were 16 bit, it'd only go to 65535

JunOS Regular Expressions for AS Path


select option from centralised list

Question: I have a select option list which is repeated many times over a number of pages. Is there a method of referring out to have one list that all the references use?
<select name="staff_member[]">
<option value="'.$row->staff_member.'">'.$row->staff_member.'</option>
<option value="adam">adam</option>
<option value="ben">ben</option>
<option value="clive">clive</option>
<option value="etc etc etc"..
</select>

I have a long list of staff members and it rotates regularly, so I'd like to have this list in one place and just refer to it in the html / php. For menus, I've been using 'php include' but I haven't found a way of doing the same with that here as the code sits within a while loop which has multiple switch / case statements to format the page. just inserting an 'include' statement doesn't work (although it may just be the way I've formatted it).
I'd be grateful of any pointers please?
Comment: Write a function for this, (including the query), and call it when you need.
Comment: @lolka_bolka That's a good thought. I hadn't considered a function. Thank you.
Answer: I ended up solving this by creating a table with the staff members is, and referring to this table in the select / option as follows:-
<select name="staff_member[]">
<option value="'.$row2->staff_member.'">'.$row2->staff_member.'</option>';
$repairer= mysql_query("SELECT DISTINCT staff_member FROM staff");
while($row= mysql_fetch_assoc($staff_member)) {
echo '<option value="'.$row[staff_member].'">'.$row[staff_member].'</option>' ;
}
echo '</select>

I had to break in and out of php / html (hence the echo statements) as this part of the code exists within a while loop and I didn't know how else to do it, however it works now and as the staff rotate, I only have to update the one table. Much easier.
I did consider the Function option suggested, however I needed the fastest option and will have to save learning more about functions for another time. I expect that there will be loads of benefit once I get my head around them though :)

select option from centralised list


Version list not displayed after pushing next version of ruby gem

Question: I have created a Ruby gem and pushed in rubygem org (version 1.0.0)
then i did some changes and again i pushed the next version (version 2.0.0)
After that,
 I opened the gem home page, the previous versions list is not displayed only the recent version number is displayed.
Ruby dependency, runtime dependency all are displayed
but Version is not enabled
Also dono how to add source code link,
my gemspec file as
Gem::Specification.new do |s|
  s.name        = 'xxx'
  s.version     = xxx::VERSION
  s.date        = '2014-04-28'
  s.summary     = "Hola!"
  s.description = "A simple hello world gem"
  s.authors     = ["xxxxx"]
  s.email       = 'email@example.com'
  s.files       = ["lib/xxx.rb"]
  s.homepage    =
    'https://github.com/xxx/xxx.git'
  s.license       = 'MIT'

  s.add_runtime_dependency 'rails', ['>= 3', '< 5']

  s.add_development_dependency 'rspec-rails', '2.13.0'

end

Answer: Have you changed the version in the version.rb file? You need to specify the current version using the VERSION constant in the file lib/{gem_name}/version.rb like this:
module GemName
  VERSION = "2.0.0"
end

The version.rb file is loaded by the Gem Specification file to specify the version for the gem specification. Before releasing a new version of the gem the version number needs to be changed.This tells Rubygems about the new version.
Comment: i have added those file, from there only the version number is updating..  is there any other problem


Infinite limit of an infinite sequence

Question: Given the following infinite series:
$$f(x) =\sum_{n=1}^\infty \frac{(-1)^{n-1} x^{2n-1}}{(n-1)!(2n-1)} = x - \frac{x^3}{1!\cdot 3}+\frac{x^5}{2!\cdot 5} - \frac{x^7}{3!\cdot 7}+ \dots$$
How does one take the limit of of such a series as $x$ tends to infinity?
That is, how do you calculate:   $\lim_{x\to \infty} f(x)$
According to WolframAlpha, the answer is $\frac{\sqrt{\pi}}{2}$. Their solution, however, involves some error function they defined which is foreign to me. Is there any other way to compute this?
Answer: Note that $f'(x)=e^{-x^2}$, hence
$$\lim_{x\to \infty} f(x)=\lim_{x\to \infty} (f(x)-f(0))=\int_0^{\infty}f'(x) dx
=\int_0^{\infty}e^{-x^2} dx=\frac{\sqrt{\pi}}{2}.$$
As regards the last step you can take a look here: Is there really no way to integrate $e^{-x^2}$?
Comment: I know. The reason I actually want to compute this limit is in order to compute that integral. I know there are alternatives, but I'm exploring this one.
Comment: @Jean-Jacq du Plessis Ouch! In this case I am not able to help you. Sorry.
Comment: @Jean-Jacq du Plessis Have you seen this  http://math.stackexchange.com/questions/965378/how-to-int-e-x2-dx

Infinite limit of an infinite sequence


Create navigation through taxonomy

Question: We have an taxonomy with "news" and "articles" parent terms and structure with different child terms.
What we need, is simple navigation through this taxonomy without menus, but with pages: so at the "Article" page are presented child terms of "Article", once an term is selected user is redirected to the page with child terms of this term and list of items in current term + path to this term (like Articles > Child term 1 > Child term 2 etc for easier navigation).
Such navigation system is typical for many CMSs, but I couldn't find nothing like this in Drupal 7.
Is there a module or guide to implement such navigation?
Comment: I'm trying to understand exactly what you want to achieve but is not clear for me. Can you elaborate more your question woith a detailed example?
Comment: Let's say we have an "Articles" in the navigation menu. It links to a page (node) where in the main region are presented both taxonomy terms of "Articles" (as links) and (below) content of currently selected term. So when I click to any term I'm redirected to another page with the same links but another content (of the term I selected). The current term in term list is marked with bold or in other way.
Answer: Taxonomy menu module suits your need.

Transforms your taxonomy vocabularies into menus with ease!
Comment: Not exactly. Taxonomy menu provides menu, but it doesn't provide navigation itself - just links to term pages with teasers, does it? We need a way to tie the links with content displayed on the page, so it wouldn't provide just a link to term page, but node with both links (implemented right into main area, not in menu anywhere in the layout) and the content.
Answer: The only way we found to do this:

Use Taxonomy menu block module to create multiple blocks based on taxonomy. Not Taxonomy menu module since it doesn't allow to create multiple blocks per one vocabulary.
Set Pathauto to generate taxonomy pages by the template [term:root:url:path]/[term:name], where "url:path" is the alias manually entered for every parent term.
Override taxonomy pages with views.
Show Taxonomy menu blocks in main region of pages filtered by taxonomy pages url:path aliases.
Some CSS to place the blocks in right place.

This method is good enough, however it doesn't allow any connection between Taxonomy menu block and the content: feature we really need. For example, it's impossible to mark with bold the item in Taxonomy menu block displayed at this moment. We plan to rewrite the whole taxonomy pages template with our own php code to implement the menu and additional conditions of the currrently displayed content (may be with ajax) in future.
Thanks for no good answer.

Create navigation through taxonomy


How do I analyze the correlation of set of points to this complicated parametric equation?

Question: I am trying to quantify the correlation of a given set of points to the set of points defined by a parametric equation, as well as find the best $l$ to fit the points. However, I am unsure of how to go about doing this.
The parametric equation I am working with is
$$x(a)=a\ln \left(\frac{l+\sqrt{l^2+a^2}}{a}\right)$$
$$y(a)=\sqrt{l^2+a^2}-a.$$
I have found $l\approx.373$. The range of the parameter $a$ is $0\lt a \lt \infty$.
The set of points I am trying to analyze is
\begin{array}{c|c}
 \style{font-family:inherit}{x} & \style{font-family:inherit}{\text{y}}\\\hline
 .372 & .017  \\\hline
 .343 & .125  \\\hline
 .308 & .184  \\\hline
 .267 & .232  \\\hline
 .234 & .262  \\\hline
 .192 & .293  \\\hline
 .147 & .320  \\\hline
 .110 & .338  \\\hline
 .065 & .356  \\\hline
 .030 & .367  \\\hline
 .003 & .372
\end{array}
A plot of the parametric equation and the set of points suggests a strong correlation for $l\approx.373$. Here is a graph on Desmos showing this: parametric equation and plotted points (The parametric equation is in red and the data points are plotted in black).
Typically, when finding the correlation between a function and a plot of points, the plot is linearized as the function indicates and a linear regression is run to evaluate the correlation. Unfortunately, I have found no way to linearize the set of points. Are there any other ways to find the parametric curve of best fit?
Comment: Welcome to Math.SE! Did you try the mean squared error? Why does/doesn't that work? **Edit:** I suppose calculating the residuals, and thus the mean squared error, ultimately involves choosing some statistical model for the points (e.g. maybe observed $\hat{x}$ is equal to $x(a) + \varepsilon_a$ with $\varepsilon_a$ independent random variables). Also I feel like you might get better answers on https://stats.stackexchange.com/ , but it might make sense to wait a week here before reposting there, to avoid getting downvoted or yelled at in the comments.
Comment: Thanks for taking a look at my question! My original question wasn't so clear. I also wanted to find $l$ that best fits the points, but Claude Leibovici has answered this adequately.
Answer: Plotting the data, just as you did, reveals the strong relation between $x$ and $y$.
Now, what I suspect is that they want you to find the best value of $l$ to improve the fit.
It is impossible to get rid of the parametrization in order to have $y=f(x)$. However, you can do the opposite.
Eliminate $a$ from $y$
$$a=\frac{l^2-y^2}{2 y}\qquad \implies \qquad x=\frac{(l^2-y^2) }{2 y}\,\log \left(\frac{l+y}{l-y}\right)$$
Using the starting value you gave, a basic nonlinear regression gives
$$\begin{array}{clclclclc}
 \text{} & \text{Estimate} & \text{Standard Error} & \text{Confidence Interval} \\
 l & 0.372631 & 0.000115 & \{0.37237,0.372892\} \\
\end{array}$$ and you can notice that $0.373$ is not in the confidence interval (even if very close to it).
For sure, this introduces a bias in the problem since what has been measured is $y$ and not $x$.
To compensate, I think that I should use orthogonal regression (total least squares).


when was the product placement introduced in sports?

Question: I know product placement is a good marketing technique used in almost every sports, but

When was the product placement introduced in sports?
Which was the first sport introduced product placement?
Why not separate ads rather than product placement?
Comment: The picture shows branding and sponsoring rather than product placement.  Product placement would be if you had one or more members of the team smoking their Marlboro's.  A good example of product placement would be Gatorade coolers on the sidelines, or drivers drinking their Coca-Cola in victory lane.
Comment: @Chad,Accepted!!
Answer: The first sportsman could be considered to be the Arenas of the Roman Empire.  Merchants and Nobles would sponsor gladiators or fights to help enhance their standing.
Modern advertising known as branding evolved in the 1800's and I would suspect that sporting events were quickly identified as targets for this marketing strategy.  Early teams in professional baseball and american football were sponsored by companies. The Chicago bears started out as the Decatur Staleys in 1919.

A. E. Staley was a Decatur, Illinois based processor of corn founded
  in 1898 - Source

Update after question edit:
The earliest product placement I can find would be the tobacco companies providing their products to Professional baseball players as early as the 1870.  American Tobacco Company included some of the first baseball cards with some of their products.  Honus Wagner was a superstar of the day and made quite a fuss as he was against the use of tobbacco products and refused to allow his name and picture to be used to promote the product.
Other Notes:

Jesse Owens received free shoes in the 1936 Berlin Olympics from Adidas

and

The 1970s included several important evolutionary events in sports
  marketing. Sponsorships of products by athletes emerged as a trend.
  Joe Namath became a sex symbol and used that image to sell pantyhose,
  of all things. By the end of the decade the Pittsburgh Steelers
  defensive tackle "Mean" Joe Green starred in one of the most acclaimed
  advertisements ever for Coke.
Comment: @MichaelMyers The Green Bay Packers owe their name to the Indian Packing Company.
Comment: Naming the whole team after a company? That's crazy. Nobody would do that nowadays. Except maybe the [New York Red Bulls](http://en.wikipedia.org/wiki/New_York_Red_Bulls).
Comment: Or the team in the Welsh Premier League known as "Total Network Solutions F.C"


Chord progression analysis

Question: In the song "If You Have To Ask" by the Red Hot Chili Peppers there is this instrumental funk interlude with a bunch of seventh and ninth chords and I want to understand this progression more by analysing it.
So the song is mainly in G natural minor, and the chords in the interlude are: G9 Gb9 F9 C7 Ebmaj9 Bb7 D7#9.
I've already figured out that it has the form of I I(b) VII IV VI III V (If we'd stick to the G minor key) and the guitarist keeps switching between G mixolydian, G natural minor and something that seems like G major with an augmented sixth.
I've figured out that G9 and F9 are in G mixolydian, C7 seems minorish, Bb7 is in G phrygianand D7#9 seems like G major with an augmented sixth
Am I going the right way? And if so, can someone help me connect the dots? Is this a common funk progression and could someone hint how these chords/modes are related?
Comment: Take a step back. There's a lot of errors in your info and assumptions that are wrong with the biggest being the "key" of the song is not G minor, but D minor and a lot of these chords like the Gb9 don't necessarily function, but are used in passing from one chord to another .
Comment: The rest of the song just uses different variants  of D minor and [sheet music](http://www.sheetmusicdirect.com/se/ID_No/78632/Product.aspx) for it shows the key signature as D minor. The interlude is only one small section of of the song. This section may not be specifically in D minor or any one key, but the song itself is very well described by D minor.
Comment: @Dom I know that Gb is a passing chord, but what makes you think it's D minor? G9 F9 and C7 mostly fit C major (G mixolydian). Ebmaj9 fits G minor. Only Bb7 and C7 as well would fit D minor as far as I see. Besides that D7#9 seems like a pretty clear dominant chord with the F# leading to the G and the E# leading to the F in the G9 chord
Answer: I love this song. Dom is correct that the key is D harmonic minor (major 7.) The instrumental interlude is sort of dancing around within the main chord...
Numbering the notes within the octave, and looking at it from the bass' perspective (root notes,) the progression goes 5 (A), flat 5 (Ab), 4 (G), 1 (D), 3 (F), 7 (Db), 2 (E).
The flat 5 is certainly a passing note from the 5 to 4. The use of the 7 (it is the 3 in relation to the 5 of the D) and the 2 (the 5 in relation to the 5 of the D) is to mimic the very traditional use of the dominant seven chord in order to create the illusion of pull back to the 1.

Chord progression analysis


Double.ToString is loosing the precision of double value

Question: I just wanted to know why the following code
Convert.ToDouble("866666666.6666666666666666667")

gives output:

866666666.66666663

And
Convert.ToString(Convert.ToDouble("866666666.6666666666666666667"))

gives output :

866666666.666667
Comment: Well why don't you try `Convert.ToString("866666666.6666666666666666667")` and you'll find out
Comment: whoever is downvoting, could you give little hint why this is happening. I know it's because of precision loss but not able to understand why convert.tostring causing precision loss
Comment: [1)](https://msdn.microsoft.com/en-us/library/zh1hkw6k(v=vs.110).aspx) "Using the ToDouble(String) method is equivalent to passing value to the Double.Parse(String) method.", [2)](https://msdn.microsoft.com/en-us/library/fd84bdyt(v=vs.110).aspx): "Ordinarily, if you pass the Double.Parse method a string that is created by calling the Double.ToString method, the original Double value is returned. However, because of a loss of precision, the values may not be equal."
Comment: I think it's because of this: The string representation of a double is in base-10, so there's naturally a loss of precision. If the string representation simply showed the base-2 32 bits as 1's and 0's then you wouldn't lose any precision, in a sense. The loss of precision is from the change of base.
Comment: @AlfieGoodacre it gives same value.
Comment: @Quantic basically second code is converting value 866666666.66666663 to string, no? ideally it should give this value only.
Comment: Are you sure.  I don't get the same results as you.
Comment: @Paparazzi please check the value in watch. I have just added screenshot.
Comment: @Mukund Look, Whenever the you use `Convert.ToDouble` the value have to be stored in an eight-byte place named variable although it is inside the scope of the method and temporal. The mentioned 8-bytes can store a number of predefined values. Think of 10.1 and 10.2. There are _finite_ values between these values. A small portion of these values can be shown. And there is also another thing which is named rounding. When a floating point number can not be shown as it is, this concept is used for showing that number.
Comment: But your the two writeline give the same value.   Somehow ToString() to not write out he full precision.  And precision of double is not perfect.
Comment: @Paparazzi would you edit. Although English may not be your first language, I can not read
Comment: @Paparazzi yes because writeline first convert the value into string then writes it on console. I am trying to understand the behavior of Double.ToString method but not able to understand it properly.
Comment: Your question is not clear on this is a string formatting versus imprecise precision.
Comment: @Paparazzi String is using it's default formatiing
Answer: This appear to be a string formatting issue
With "R" and "G20" I get the same as what you see in watch
The 20 is total number of digits
{0:F20} was not correct - it just added a bunch of zeros
Double.ToString
Double d = Convert.ToDouble("866666666.6666666666666666667");
Debug.WriteLine(d);
Debug.WriteLine(d.ToString("G"));
Debug.WriteLine(d.ToString("G20"));
Debug.WriteLine(d.ToString("R"));
Debug.WriteLine(String.Format("{0:F20}", d));
string s = Convert.ToString(Convert.ToDouble("866666666.6666666666666666667"));
Debug.WriteLine(s);


Standard for setting properties of existing object with PDO

Question: I have a class in the model part that picks a data mapper, in my case I am concerned about an sql database and setting properties of an existing object.
So currently I am doing this to make my organization class
Controller
class controller
{
    public function invoke()
    {
    $organization = $this->model->organization($id);
    //pick view
    }
}

Model
class model
{
public $database
//construct $database connection

public function organization($id)
{
    $organization = $this->database->get_by_id($id, 'organizations', 'organization');
    //$organization = new organization();
    $organization->stakeholder = $this->database->join_one('stakeholders', 'stakeholder_category', 'stakeholder_id', '1', 'entity_id', $id);
    $organization->document['document_affiliated_organization'] = $this->database->join_one('documents', 'authors', 'document_id', 1, 'author_id', $id);
    $organization->document['document_audience_organization'] = $this->database->join_one('documents', 'document_audience', 'document_id', 1, 'audience_id', $id);
    //people that are members of this organization
    $organization->membership['organization_membership_person'] = $this->database->join_one('people', 'membership', 'member_id', 0, 'organization', $id);
    //organizations that are members of this organization
    $organization->membership['organization_membership_organization'] = $this->database->join_one('organizations', 'membership', 'member_id', 1, 'organization', $id);
    //organizations that this organization is a member of
    $organization->membership['member_of'] = $this->database->join_one('organizations', 'membership', 'organization', 1, 'member_id', $id);
    $organization->event['event_affiliated_organization'] = $this->database->join_one('events', 'event_organizer', 'event', 1, 'organizer', $id);

    return $organization;
}
}

class organization//extends model if I were to add the funcion discussed below
{

//database table values
public $model_type = 'Organization';
public $id;//organization table
public $name;//organization table
public $stakeholder;//organization table join with stakeholder table (array)
public $membership;//organization table join with membership table fetchall (array)
public $document;//organization table join with document table fetchall (array)
public $event;//organization table join with event table fetchall (array)

What are your thoughts on a function in this organization class?
public function organization($id)
{
    $organization = $this->database->get_by_id($id, 'organizations', 'organization');
    //$organization = new organization();
    $organization->stakeholder = $this->database->join_one('stakeholders', 'stakeholder_category', 'stakeholder_id', '1', 'entity_id', $id);
    $organization->document['document_affiliated_organization'] = $this->database->join_one('documents', 'authors', 'document_id', 1, 'author_id', $id);
    $organization->document['document_audience_organization'] = $this->database->join_one('documents', 'document_audience', 'document_id', 1, 'audience_id', $id);
    //people that are members of this organization
    $organization->membership['organization_membership_person'] = $this->database->join_one('people', 'membership', 'member_id', 0, 'organization', $id);
    //organizations that are members of this organization
    $organization->membership['organization_membership_organization'] = $this->database->join_one('organizations', 'membership', 'member_id', 1, 'organization', $id);
    //organizations that this organization is a member of
    $organization->membership['member_of'] = $this->database->join_one('organizations', 'membership', 'organization', 1, 'member_id', $id);
    $organization->event['event_affiliated_organization'] = $this->database->join_one('events', 'event_organizer', 'event', 1, 'organizer', $id);

    return $organization;//End of proposed function which I am not currently using
}

This is my database class function called above
public static function get_by_id($id,$table,$class)
{
    try
    {
                    $core = self::getInstance();
        $core->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $sql = "SELECT * FROM $table where id = :id limit 1";
        $statement = $core->dbh->prepare($sql);
        $statement->bindParam(':id', $id, PDO::PARAM_INT);

        if (!isset($class))
        {
            $class = '__CLASS__';
        }
        $statement->setFetchMode(PDO::FETCH_CLASS, $class);
        $statement->execute();

        $result = $statement->fetch();

Optionally I was thinking I might be better off doing a PDO::FETCH_INTO,$class
// Return results
        return $result;
    }
    catch (PDOException $exception)
    {
        die($exception->getMessage());
    }
}
public static function join_one($table1,$table2,$join_column_id,$person_or_organization,$where_column_id,$id)
{
    $sql = "SELECT $table1.name, $table1.id
    FROM $table1
    JOIN $table2 ON $table1.id=$table2.$join_column_id
    WHERE $table2.person_or_organization=$person_or_organization AND $table2.$where_column_id=$id";
    return self::get_by_sql($sql);
}

This works for me. Here are some of the things I am wondering what I should do.
My properties right now work like this Main object (organization) with properties set by the one fetch and then objects set into certain properties which are type (array) of the existing organization class. What are your thoughts on the typecasting (objects vs array in object)? Where should I be putting what logic?
Answer: I'm not sure why no one else hasn't replied to you...I'm going to take a stab a it. Lets start with a little terminology, a class is a class, a function in a class is a method.
There are a lot of ways to implement an MVC system but I don't think your way is one of them.  You don't create a model class, you create a class called organization that is your model.  The general methods are
index/list
show/data
new/create
edit
update
destroy
You controller handles the page logic, the goal is keep it at thin as possible. I'm not sure if you can have a controller be entirely a class...it maybe possible but I usually have mine as flat file. The view handles the output. You really should do more reading to MVC...there are tons of good writes up on it. You should also look into a PDO wrapper class. I can recommend http://www.imavex.com/php-pdo-wrapper-class/.  You should also read up on why singleton patterns are bad and how dependency injection is good.
So anyway....let me give you some quick code...its not going to be pretty or work but it should get the general idea across....looks like you want to display an org, in functional programmings you would probably code something like org.php?id=123....the better approach would be a REST setup /org/view/123...either way the codes the same but the way you call the code changes...
So the controller goes something like
$Org = new Org($dbClass);
if (isset($_REQUEST["id"]){
    $orgData = $Org->data($_REQUEST["id");
}

Now the model would be..
class Org
{
    public $dbClass; //stores db class

    public function __construct($dbClass){
         //its usually good form to type hint the db class interface
         $this->dbClass = $dbClass;
    }

    public function data($id){
        return $this->dbClass->run("SELECT * FROM org WHERE orgID = $id");
        // NOTE THIS IS VERY INSECURE
    }
}

And finally your view
foreach ($orgData as $key=>$value){
echo $key." : ".$value."
";
}

Comment: I did create a model class, it's called model (my formatting above may be confusing). My model class has methods that call a data model class, in this case a database class (of which there are two for seperate mysql users insert vs update). I also use DOM and flatfile. In the database class I set the attribute (PDO::FETCH_CLASS,'organization') so now my organization class is made but not fully made. The model class method continues to fill my created organization with arrays associatied with that organization (person) but I could fill them with person objects instead?
Comment: Sorry for the delay, I'm not clear what you are asking.  My response above is what I consider the best way to implement an MVC.  I don't really understand your approach but I don't think it will hold up once you start handling a large number of resources.


W3Schools Slides same height

Question: I added text to a modified slideshow from w3schools. My problem now is, that the text divs are not equally in height. I want the text divs be as big as the biggest text div of the 3 slides and I don't want to set a specific height to the text div, because that will make the responsiveness hard to manage (meaning a lot of work with media queries and even with that not 100% perfect). I looked through many posts here about the same topic, but i couldn't come up with a solution for me. Code is below or here. Appreciate any help.

var slideIndex = 1;
showSlides(slideIndex);

function plusSlides(n) {
  showSlides(slideIndex += n);
}

function currentSlide(n) {
  showSlides(slideIndex = n);
}

function showSlides(n) {
  var i;
  var slides = document.getElementsByClassName("mySlides");
  var dots = document.getElementsByClassName("dot");
  if (n > slides.length) {slideIndex = 1;}
  if (n < 1) {slideIndex = slides.length;}
  for (i = 0; i < slides.length; i++) {
      slides[i].style.display = "none";
  }
  for (i = 0; i < dots.length; i++) {
      dots[i].className = dots[i].className.replace(" active", "");
  }
  slides[slideIndex-1].style.display = "block";
  dots[slideIndex-1].className += " active";
}
@import url('https://fonts.googleapis.com/css2?family=Assistant&display=swap');
@import url("https://use.typekit.net/yoj6eqg.css");

* {box-sizing: border-box}
body {
  font-family: Assistant, sans-serif;
  margin: 0;
}

/* Slideshow container */
.slideshow-container {
  display: flex;
  position: relative;
  background: #f1f1f1f1;
  width: 100%;
  margin: auto;
}

/* Slides */
.mySlides {
  display: flex;
  position: relative;
  padding: 30px 0px 30px 0px;
  text-align: center;
  width: 92%;
  max-width: 1200px;
  margin: auto;
  }

  /* text color */
.text {
  color: #333333;
  text-align: left;
  font-family: "Assistant", sans-serif;
  font-style: normal;
  font-weight: 400;
  padding: 1vh 0 0 0;
  flex-grow: 1;
}

.heading {
  text-align: center;
  color: #90bd49;
  font-size: 30px;
  font-family: "p22-underground", sans-serif;
  font-weight: 600;
  font-style: normal;
  padding: 10px;
  padding: 1.5vh 0 0 0;
}

/* Prev Button Position and Properties */
.prev {
  position: absolute;
  cursor: pointer;
  top: 50%;
  left: -5.9%;
  transform: translateY(-50%);
  padding: 30px;
  color: #888;
  font-weight: bold;
  font-size: 20px;
  border-radius: 3px 0 0 3px;
  user-select: none;
}

/* Next Button Position and Properties */
.next {
  position: absolute;
  border-radius: 0 3px 3px 0;
  cursor: pointer;
  top: 50%;
  right: -5.9%;
  transform: translateY(-50%);
  padding: 30px;
  color: #888;
  font-weight: bold;
  font-size: 20px;
  user-select: none;
}

/* On hover, add a black background color with a little bit see-through */
.prev:hover, .next:hover {
  background-color: rgba(0,0,0,0.8);
  color: white;
}
.image
{
position: relative;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
height: 60vh;
}

/* The dot/bullet/indicator container */
.dot-container {
    text-align: center;
    padding: 20px;
    background: #ddd;
}

/* The dots/bullets/indicators */
.dot {
  cursor: pointer;
  height: 15px;
  width: 15px;
  margin: 0 2px;
  background-color: #bbb;
  border-radius: 50%;
  display: inline-block;
  transition: background-color 0.6s ease;
}

/* Add a background color to the active dot/circle */
.dot:hover {
  background-color: #90bd49;
}
.active {
  background-color: #90bd49;
}

@media screen and (max-width:767px) {
  .heading {
    font-size: calc(22px + 0.390625vw);
  }

  .text {
    font-size: calc(14px + 0.390625vw);
    padding: 1vh 3vw 0 3vw;
  }

  .prev {
    font-size: 15px;
    border-radius: 0 0 0 0;
    padding: 20px;
    left: 0;
    background-color: rgba(0, 0, 0, 0.8);
    color: white;
  }
  .next {
    font-size: 15px;
    border-radius: 0 0 0 0;
    padding: 20px;
    right: 0;
    background-color: rgba(0, 0, 0, 0.8);
    color: white;
  }

  .mySlides {
    display: none;
    width: 100%;
    padding: 30px 0px 30px 0px;
  }
  .image {
    height: 350px;
  }
}

@media (min-width:768px) and (max-width:1200px) {
  .heading {
    font-size: calc(20px + 0.390625vw);
  }

  .text {
    font-size: calc(12px + 0.390625vw);
    padding: 1vh 2vw 0 2vw;
  }

  .prev {
    font-size: 15px;
    border-radius: 0 0 0 0;
    padding: 20px;
    left: 0;
    background-color: rgba(0, 0, 0, 0.8);
    color: white;
  }
  .next {
    font-size: 15px;
    border-radius: 0 0 0 0;
    padding: 20px;
    right: 0;
    background-color: rgba(0, 0, 0, 0.8);
    color: white;
  }

  .mySlides {
    display: none;
    width: 92%;
    max-width: 1200px;
    padding: 30px 0px 30px 0px;
  }
}

@media (min-width:1201px) and (max-width:1300px) {
  .heading {
    font-size: calc(18px + 0.390625vw);
  }

  .text {
    font-size: calc(10px + 0.390625vw);
    padding: 1vh 2.5vw 0 2.5vw;
  }

  .prev {
    font-size: 15px;
    border-radius: 0 0 0 0;
    padding: 20px;
    left: 0;
    background-color: rgba(0, 0, 0, 0.8);
    color: white;
  }
  .next {
    font-size: 15px;
    border-radius: 0 0 0 0;
    padding: 20px;
    right: 0;
    background-color: rgba(0, 0, 0, 0.8);
    color: white;
  }

  .mySlides {
    display: none;
    width: 92%;
    max-width: 1200px;
    padding: 30px 0px 30px 0px;
  }
}

@media (min-width:1301px) and (max-width:1650px) {
  .heading {
    font-size: calc(18px + 0.390625vw);
  }

  .text {
    font-size: calc(10px + 0.390625vw);
  }
}

@media (min-width: 1651px){
.heading {
  font-size: calc(16px + 0.390625vw);
}
.text {
  font-size: calc(8px + 0.390625vw);
}

}

  ❮ ❯

Lorem ipsum

But man is not made for defeat. A man can be destroyed but not defeated.But man is not made for defeat. A man can be destroyed but not defeated.But man is not made for defeat. A man can be destroyed but not defeated.But man is not made for defeat. A man can be destroyed but not defeated.But man is not made for defeat. A man can be destroyed but not defeated.But man is not made for defeat. A man can be destroyed but not defeated.

  ❮ ❯

Lorem ipsum

Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum

  ❮ ❯

Lorem ipsum

But man is not made for defeat. A man can be destroyed but not defeated.But man is not made for defeat. A man can be destroyed but not defeated.But man is not made for defeat. A man can be destroyed but not defeated.But man is not made for defeat. A man can be destroyed but not defeated.But man is not made for defeat. A man can be destroyed but not defeated.But man is not made for defeat. A man can be destroyed but not defeated

Answer: You are changing the display property, so you need to set the container to a height that is equal to the largest height of the slides.

window.onload = setSliderHeight;
window.onresize = setSliderHeight;

function setSliderHeight() {
  let maxSlideHeight = 0;
  const container = document.querySelector('.slideshow-container');
  container.style.removeProperty('height');
  document.querySelectorAll('.mySlides').forEach(el => maxSlideHeight = el.offsetHeight > maxSlideHeight ? el.offsetHeight : maxSlideHeight);
  container.style.height = maxSlideHeight + 'px';
}

/* your code is below */

var slideIndex = 1;
showSlides(slideIndex);

function plusSlides(n) {
  showSlides(slideIndex += n);
}

function currentSlide(n) {
  showSlides(slideIndex = n);
}

function showSlides(n) {
  var i;
  var slides = document.getElementsByClassName("mySlides");
  var dots = document.getElementsByClassName("dot");
  if (n > slides.length) {slideIndex = 1;}
  if (n < 1) {slideIndex = slides.length;}
  for (i = 0; i < slides.length; i++) {
      slides[i].style.display = "none";
  }
  for (i = 0; i < dots.length; i++) {
      dots[i].className = dots[i].className.replace(" active", "");
  }
  slides[slideIndex-1].style.display = "block";
  dots[slideIndex-1].className += " active";
}
@import url('https://fonts.googleapis.com/css2?family=Assistant&display=swap');
@import url("https://use.typekit.net/yoj6eqg.css");

* {box-sizing: border-box}
body {
  font-family: Assistant, sans-serif;
  margin: 0;
}

/* Slideshow container */
.slideshow-container {
  display: flex;
  position: relative;
  background: #f1f1f1f1;
  width: 100%;
  margin: auto;
}

/* Slides */
.mySlides {
  display: flex;
  position: relative;
  padding: 30px 0px 30px 0px;
  text-align: center;
  width: 92%;
  max-width: 1200px;
  /* changed */
  margin: 0 auto;
  }

  /* text color */
.text {
  color: #333333;
  text-align: left;
  font-family: "Assistant", sans-serif;
  font-style: normal;
  font-weight: 400;
  padding: 1vh 0 0 0;
  flex-grow: 1;
}

.heading {
  text-align: center;
  color: #90bd49;
  font-size: 30px;
  font-family: "p22-underground", sans-serif;
  font-weight: 600;
  font-style: normal;
  padding: 10px;
  padding: 1.5vh 0 0 0;
}

/* Prev Button Position and Properties */
.prev {
  position: absolute;
  cursor: pointer;
  top: 50%;
  left: -5.9%;
  transform: translateY(-50%);
  padding: 30px;
  color: #888;
  font-weight: bold;
  font-size: 20px;
  border-radius: 3px 0 0 3px;
  user-select: none;
}

/* Next Button Position and Properties */
.next {
  position: absolute;
  border-radius: 0 3px 3px 0;
  cursor: pointer;
  top: 50%;
  right: -5.9%;
  transform: translateY(-50%);
  padding: 30px;
  color: #888;
  font-weight: bold;
  font-size: 20px;
  user-select: none;
}

/* On hover, add a black background color with a little bit see-through */
.prev:hover, .next:hover {
  background-color: rgba(0,0,0,0.8);
  color: white;
}
.image
{
position: relative;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
height: 60vh;
}

/* The dot/bullet/indicator container */
.dot-container {
    text-align: center;
    padding: 20px;
    background: #ddd;
}

/* The dots/bullets/indicators */
.dot {
  cursor: pointer;
  height: 15px;
  width: 15px;
  margin: 0 2px;
  background-color: #bbb;
  border-radius: 50%;
  display: inline-block;
  transition: background-color 0.6s ease;
}

/* Add a background color to the active dot/circle */
.dot:hover {
  background-color: #90bd49;
}
.active {
  background-color: #90bd49;
}

@media screen and (max-width:767px) {
  .heading {
    font-size: calc(22px + 0.390625vw);
  }

  .text {
    font-size: calc(14px + 0.390625vw);
    padding: 1vh 3vw 0 3vw;
  }

  .prev {
    font-size: 15px;
    border-radius: 0 0 0 0;
    padding: 20px;
    left: 0;
    background-color: rgba(0, 0, 0, 0.8);
    color: white;
  }
  .next {
    font-size: 15px;
    border-radius: 0 0 0 0;
    padding: 20px;
    right: 0;
    background-color: rgba(0, 0, 0, 0.8);
    color: white;
  }

  .mySlides {
    display: none;
    width: 100%;
    padding: 30px 0px 30px 0px;
  }
  .image {
    height: 350px;
  }
}

@media (min-width:768px) and (max-width:1200px) {
  .heading {
    font-size: calc(20px + 0.390625vw);
  }

  .text {
    font-size: calc(12px + 0.390625vw);
    padding: 1vh 2vw 0 2vw;
  }

  .prev {
    font-size: 15px;
    border-radius: 0 0 0 0;
    padding: 20px;
    left: 0;
    background-color: rgba(0, 0, 0, 0.8);
    color: white;
  }
  .next {
    font-size: 15px;
    border-radius: 0 0 0 0;
    padding: 20px;
    right: 0;
    background-color: rgba(0, 0, 0, 0.8);
    color: white;
  }

  .mySlides {
    display: none;
    width: 92%;
    max-width: 1200px;
    padding: 30px 0px 30px 0px;
  }
}

@media (min-width:1201px) and (max-width:1300px) {
  .heading {
    font-size: calc(18px + 0.390625vw);
  }

  .text {
    font-size: calc(10px + 0.390625vw);
    padding: 1vh 2.5vw 0 2.5vw;
  }

  .prev {
    font-size: 15px;
    border-radius: 0 0 0 0;
    padding: 20px;
    left: 0;
    background-color: rgba(0, 0, 0, 0.8);
    color: white;
  }
  .next {
    font-size: 15px;
    border-radius: 0 0 0 0;
    padding: 20px;
    right: 0;
    background-color: rgba(0, 0, 0, 0.8);
    color: white;
  }

  .mySlides {
    display: none;
    width: 92%;
    max-width: 1200px;
    padding: 30px 0px 30px 0px;
  }
}

@media (min-width:1301px) and (max-width:1650px) {
  .heading {
    font-size: calc(18px + 0.390625vw);
  }

  .text {
    font-size: calc(10px + 0.390625vw);
  }
}

@media (min-width: 1651px){
.heading {
  font-size: calc(16px + 0.390625vw);
}
.text {
  font-size: calc(8px + 0.390625vw);
}

}

  ❮ ❯

Lorem ipsum

But man is not made for defeat. A man can be destroyed but not defeated.But man is not made for defeat. A man can be destroyed but not defeated.But man is not made for defeat. A man can be destroyed but not defeated.But man is not made for defeat. A man can be destroyed but not defeated.But man is not made for defeat. A man can be destroyed but not defeated.But man is not made for defeat. A man can be destroyed but not defeated.

  ❮ ❯

Lorem ipsum

Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum

  ❮ ❯

Lorem ipsum

But man is not made for defeat. A man can be destroyed but not defeated.But man is not made for defeat. A man can be destroyed but not defeated.But man is not made for defeat. A man can be destroyed but not defeated.But man is not made for defeat. A man can be destroyed but not defeated.But man is not made for defeat. A man can be destroyed but not defeated.But man is not made for defeat. A man can be destroyed but not defeated

W3Schools Slides same height