Theory of Computation (Regular/Non-Regular proof)

Question: <code>Suppose that L0, L1, L2 are languages over the same alphabet and that

L0 ⊆ L1 ⊆ L2.

Is it true that if L0 and L2 are regular, then L1 must be regular as well?
</code>
By regular = the set of alphabet is accepted by the machine
Suppose
L0 = { $a^{\textrm{n}}$ | n = 2}
L2 = { $a^{\textrm{n}}$ | n => 0}
how can i find a set for L1 that is NOT Regular when there are no parameters or syntax on what the machine accepts or not?
I'm thinking
L1 = { $a^{\textrm{n}}$ | n = prime number }
but i don't know how to prove it.
Answer: I think this is classical for Pumping Lemma.
Suppose $L_1$ is regular, then there exists integer $p$ and a long enough string $w=a^k$ that could be written as $$w = xyz, \lvert xy \rvert \leq p, \lvert y \rvert \geq 1,$$
such that $xy^nz \in L_1$ for every $n$.
Take $n = \lvert xz \rvert$, then $\lvert xz \rvert$ divides $\lvert xy^nz \rvert$. Which contradicts the definition of $L_1$.
Comment: So i guess there's no other way to prove it aside from pumping lemma?
Answer: Here's an example where it may be easier to see:
$L_0$ = { $ab$ }, $L_1$ = { $a^nb^n$ | $n > 0$ }, $L_2$ = { $a^+b^+$ }
Comment: What does this say though?
Comment: I mean what's the point of this?
Comment: $L_1$ is shown in Wikipedia as not Regular!
Answer: The existence of a non-regular language between the languages $L_0=\{aa\}$ and $L_2=a^*$ can also be proved without the pumping lemma.
There are only countably many regular expressions over the alphabet $\{a\}$, because each of these regular expressions is a word in the alphabet $\{ ),(,+,\cdot,^*,\emptyset,a\}$.
On the other hand, there are uncountably many languages between $L_0$ and $L_2$ (because there are uncountably many subsets of $\mathbb{N}$ and each such subset $K$ yields a language $L_1=L_0 \cup \{a^{i+3} \mid i \in K\}$).
This proves that there exists a non-regular language $L_1$ between $L_0$ and $L_2$, but does not provide any particular language $L_1$.


How do render swagger.json content in reactjs

Question: I am trying to create a document portal for my API's with Express and reactJs. Basically, I get the JSON content(swagger.json) from the Express server and I want to pass it to swagger UI on the client to display
In the docs (https://www.npmjs.com/package/swagger-ui-react), I only see an option to display the URL.
render() {
        return <SwaggerUI url="https://petstore.swagger.io/v2/swagger.json" />;
      }

I have the JSON content. Is there another method to pass the JSON content and have it displayed in Swagger UI?
Comment: "In the docs," what docs? Can you be more precise about your actual code? Are you using https://www.npmjs.com/package/swagger-ui-react? If so, then you can use the [`spec`](https://www.npmjs.com/package/swagger-ui-react#user-content-spec-proptypesobject) props to pass direct data instead of URL
Comment: Sorry. Yes I am using npmjs.com/package/swagger-ui-react and I have the json string not a link.
Answer: According their docs, you can pass content directly using the spec props:

spec: PropTypes.object
An OpenAPI document respresented as a JavaScript object, JSON string, or YAML string for Swagger UI to display.
⚠ Don't use this in conjunction with url - unpredictable behavior may occur.

Example:
<SwaggerUI spec={jsonData} />


How to define an empty array of DataFrames in Julia?

Question: I want to generate an empty array of dataframes that will be filled later in the code, but I have not figured out how to do it.  Any help would be appreciated!
I have tried a standard way of defining an empty array.
julia> df = Array{DataFrame}(undef,10)
10-element Array{DataFrame,1}:
 #undef
 #undef
 #undef
 #undef
 #undef
 #undef
 #undef
 #undef
 #undef
 #undef

julia> println(typeof(df[1]))
ERROR: UndefRefError: access to undefined reference
Stacktrace:
 [1] getindex(::Array{DataFrame,1}, ::Int64) at ./array.jl:729
 [2] top-level scope at none:0

I'd expected typeof(df[1]) to say DataFrame, but it fails with an error message.
Answer: Try:
df_vector = [DataFrame() for _ in 1:10]

or
map(_ -> DataFrame(), 1:10)

Comment: e.g. `[df[:, 3] for df in df_vector]` or `getindex.(df_vector, :, 3)`.
Comment: I was able to do `df_vector = DataFrame[]`, which is an empty array of DataFrame types, or `Vector{DataFrame}`. I added dataframes in a loop with `push!(df_vector, df1)` and so on. Now what I don't know how to do is access column 3 in each of the dataframes in my vector...
Answer: What you have is correct, for your understood definition of 'empty'.
Once you have your first result, you can proceed to fill it with dataframes as normal.
It is indeed a DataFrame array, since if you try to assign any other type to its elements you will get an error.
Note that "an empty array of dataframes" is not the same as "a (non-empty) array of empty dataframes".
If what you actually want is the latter, Bogumil's answer is the way to go.
Comment: an "empty array of `DataFrame`s" is `DataFrame[]`, as this is what "empty" means by `isempty` function. But I think this is not what @JPi wanted. Now we have a distinction between "uninitialized array of `DataFrame`s" vs. "array of empty `DataFrames`" as @Tasos rightly pointed out. Now the key thing is that you probably want all `DataFrame`s to be distinct objects (not - the same object repeated multiple times) - and this what my solution does. You could repeat the same `DataFrame` 10 times using `fill(DataFrame(), 10)` but this is probably not what you want.
Comment: @JPi yes, but that's probably mostly a "C++" accident, and probably less desirable behaviour in any case. All other non-primitive objects will behave like dataframe. (try `Dict` for example, or even `Array`!)
Comment: ah, you're right of course.....  Though there's an asymmetry in that Array{Float64}(undef,10) would not have the same issues.
Comment: @JPi in fact, this historical accident may be the very reason there's an `isnothing` and an `ismissing` command, but no `isundef` one ...


Open Latest File

Question: I'm having a little trouble and hope someone here can help me out.
The code below copies the latest version of a file to my target directory. I'm wanting to also open the latest file that was copied into my target directory.
The filename isnt constant, so it needs to be able to find the most recent file to open.
@echo off
set source="N:\Project\c1662\shareddata\3d-Model-Index"
set target="C:\NWD"

ECHO Copying files..........please weait

FOR /F "delims=" %%I IN ('DIR %source%\*.nwd /A:-D /O:-D /B') DO COPY
%source%\"%%I" %target% & echo %%I & GOTO :END
:END

start "" "C:\Users\nortonjl\Desktop\Navisworks Simulate 2015.lnk"
???

:End

Comment: Are you wanting to open the file you've just copied to the target directory? or the latest file in the target directory after the latest file from the source directory has been copied?
Comment: The latest file in the target directory.
Answer: You want to open the latest file found from the for loop. Here is a way you can do this:
@echo off
set "source=N:\Project\c1662\shareddata\3d-Model-Index"
set "target=C:\NWD"

echo Copying files..........please weait

for /f "delims=" %%I IN ('dir %source%\*.nwd /A:-D /O:-D /B') do (
     copy "%%~fI" %target%
     set "latest_file=%%~nxI"
     echo %%I
)
goto END

:END
start "" "C:\Users\nortonjl\Desktop\Navisworks Simulate 2015.lnk"
start "" "%target%\%latest_file%"

Comment: Thank you. The only issue now is its not copying the file.

Open Latest File


Kusto logstash update syslogs in real time

Question: I hope everyone is doing great.
I do have a question about azure data explorer and logstash.
I followed this Microsoft tutorial to configure a azure data explorer with Kusto and logstash.
https://learn.microsoft.com/en-us/azure/data-explorer/ingest-data-logstash
I created a azure data explorer, created a table for the data. on the other side I pinned up a virtual machine, installed logstash and configured all the minimum required to forward syslogs to azure data explorer.
Everything works just fine and I don't have any problem, but there is one step that is bugging me a bit and would like some clarifications.
I wanted to test this project with real time syslogs coming from my virtual machine.
so I configured conf file for logstash as follow:
input {
  tcp {
    port => 514
 }
}
output {
  kusto {
    path => "/tmp/kusto/%{+YYYY-MM-dd-HH-mm-ss}.txt"
    ingest_url => "my-ingest-url"
    app_id => "app-id"
    app_key => "secret"
    app_tenant => "tenant"
    database => "db"
    table => "table"
    json_mapping => "mapping"
 }
}

To test this I installed kiwi syslogs generator, and start sending data once a second. Everything works fine but data-explorer takes up to 10min to show those syslogs.
Based on my understanding and configuration file. for each syslog forwarded, kusto creates a file in tmp folder, writes that syslog and than closes the file.
path => "/tmp/kusto/%{+YYYY-MM-dd-HH-mm-ss}.txt"

after this process it takes 10min before to see it visualised in my data-explorer.
This is an issue for me because what I would like to do, is to have a azure function that triggers every 12hrs and targets all the data since that specific moment without leaving any data outside because is still in pending.
I don't know if I explained my problem properly, but please if you have any question don't hesitate to ask.
Answer: For the 10 minutes it takes to show up in Kusto, this is likely due to the ingestionbatching policy on the table where the default batching period is five minutes. If you want the data to show up faster you can set the MaximumBatchingTimeSpan to less than this, where 10 seconds is the minimum, please note that having too small of a batching window may have an adverse impact on the cluster performance.
I am not sure how the Azure function relates to the scenario can you please clarify?
Comment: Sorry for the basic question. How can I set the MaximumBatchungTimeSpan?. The azure function will run a python sdk code to query this syslog and output a csv file to a database. That's all what this azure function has to do. But when I run it, the logs  outputted to the csv file doesn't match the actual one on data-source, due to the delay as I mentioned. Thank you so much for replying
Comment: Avnera, Thank you so much for your advice. I used the Maximumbatching and in fact  now it does refresh every 5sec. Thank you again


What is the difference between ITT and ATE?

Question: I am having trouble understanding the different estimators that can be used in an impact evaluation. I know that the intention-to-treat (ITT) estimator compares differences between eligible individuals without the program, and eligible individuals with the program, regardless of compliance. However, I thought the average treatment effect (ATE) also measured the same thing. However, it seems that the ATE takes into consideration the compliance. Therefore, it compares outcomes between those eligible and taking up treatment with those who are not eligible. Is this correct?
Answer: Suppose that I am a doctor and I tell everyone in a treatment group to go home and exercise for an hour per day and tell the control group nothing. After a month, I evaluate the difference in their blood pressure. If I just compare the difference in mean blood pressures between the two groups, I get the intention to treat estimator. This doesn't tell me the causal effect of exercise on blood pressure, but the causal effect of telling people to exercise on blood pressure. We would presume that this estimate would be smaller than the treatment effect of exercise per se, as only a (small!) fraction of people in the treatment group would follow my advise. You need to take this difference into account.
A prime example is instrumental variables. This procedure aims to recover the ATE from the ITT. See, for example,
Joshua D. Angrist; Guido W. Imbens; Donald B. Rubin. 1996. "Identification of Causal Effects Using Instrumental Variables." JASA 91(434): 444--455.
Comment: I love Charlie's answer. It's very clear and helpful to understand the difference between ATE and ITT. However, I doubt his statement that "IV aims to recover the ATE from the ITT", since IV is LATE not ATE. See this website,
https://scholar.harvard.edu/files/apassalacqua/files/section8_ATE_vs_LATE.pdf
Answer: For pedagogical purposes, it's actually much better to think about three quantities:
ITT: Intent to Treat Effect -- effect of treatment ASSIGNMENT on outcome (for everybody)
LATE: Local Average Treatment Effect -- effect of treatment no outcome FOR COMPLIERS
ATE: Average Treatment Effect -- effect of treatment on outcome FOR EVERYBODY
The ITT is the most straightforward. If we randomize some individuals into treatment and some into control, we can certainly recover the causal effect of assignment into treatment. That's the ITT.
The LATE is a bit more complicated, but the measure most often gleaned via instrumental variables / two stage least squares, etc. Assuming we're not in a lab setting, even if we assign some folks to treatment (T = 1) and assign some to control (T = 0), people will do what they will do! Some will takeup treatment (D = 1) and some will not takeup treatment (D = 0). We can imagine that some people are just willing to comply with our assignments. We may want to know what kind of person everybody in our data is -- are they the type of person who will do what we say, who will rebel, who will always takeup, who will never takeup? To know this without making any assumptions, we would actually need to know, for each person, what they would do if assigned to treatment and what they would do if assigned to control. Let's imagine Fred, for example. In one universe, we assign Fred treatment. He takes it up! In an alternate universe, we assign Fred control. He doesn't take up treatment! Fred has complied! Thus:

compliers are those that would takeup treatment only if assigned to treatment, and would not takeup treatment only if assigned to control. They would comply with our assignment.
Always takers would takeup treatment whether assigned to it or not.
Never takers would not takeup treatment whether assigned to it or not. And
defiers would do the opposite of what we assign them to do (i.e. would not takeup treatment if assigned treatment, would takeup treatment if assigned control).

We can't actually glean the type of person each of the folks in our data is, unfortunately. We live in one universe... but if we make an assumption (monotonicity) we can use folks ACTUAL behavior to glean their "type." Once we've done that, we can make a few more assumptions (exclusion restriction, valid randomization, no SUTVA violations on D or Y, relevancy) to calculate the average effect of treatment FOR COMPLIERS. This is the LATE. It's called a "local" average treatment effect b/c it doesn't calculate the treatment effect "globally" (i.e. for all) but instead calculates the effect of treatment "locally" (i.e. for some, specifically, for compliers). It's also sometimes called the CATE or Complier Average Treatment Effect for that reason.
Now we get to the mythical ATE! The ATE is the Average Treatment Effect -- the average effect of treatment for everybody, regardless of the type of person they are. Alas! Our assumptions will not allow us to recover the ATE! Even with them, we can only recover the treatment effect for compliers, or the LATE!  The most straightforward way to recover the ATE is to ensure there is no non-compliance. Then your complier average treatment effect IS the Average Treatment Effect becuase everybody is a complier!
So there you have it!

ITT -- effect of ASSIGNMENT on outcome.
LATE -- effect of treatment on outcome FOR COMPLIERS.
ATE -- effect of treatment on outcome for EVERYBODY.
Comment: This is great, Where does ATT come into play?
Comment: ATT (Average Treatment Effect on the Treated): $E[Y_1 - Y_0| D=1]$ where $Y_1, Y_0$ are potential outcomes under treatment and no treatment, and $D$ is treatment dummy. It comes into play when you don't have a control group (like in an RCT). The Identification strategy then tries to get an estimate for $E[Y_0|D=1]$ because this won't be observed.
Answer: I think your problem is an ambiguity in language. I have always seen "Average Treatment Effect" with Intent-to-Treat as a subset of ATE.
For example:
ITT analysis is estimating the ATE among those in the treatment arm of a trial. "Treatment of treated" is estimating the ATE among those actually treated.
Comment: as such, ATE among actually treated is the same as LATE (local ATE), right ?


Couldn't connect to service inside docker container

Question: I try to run command inside docker container like this:
openssl s_client  -connect 127.0.0.1:4443
CONNECTED(00000003)

in the next step I try to detect ip for docker image from /etc/hosts:
172.18.0.2  aaf6fa11bc88

then I try to connect inside containers to this IP and got:
openssl s_client  -connect 172.18.0.2:4443
connect: Connection refused

not sure why I could connect to 127.0.0.1 and couldn't connect by IP  172.18.0.2 which has been placed in /etc/hosts file  in Docker container?
I have flashed iptables:
iptables -F and iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

There is ifconfig output:
ifconfig
eth0      Link encap:Ethernet  HWaddr 02:42:ac:12:00:02
          inet addr:172.18.0.2  Bcast:172.18.255.255  Mask:255.255.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:9028 errors:0 dropped:0 overruns:0 frame:0
          TX packets:5038 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:12755512 (12.1 MiB)  TX bytes:278694 (272.1 KiB)
lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:48 errors:0 dropped:0 overruns:0 frame:0
          TX packets:48 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1
          RX bytes:5332 (5.2 KiB)  TX bytes:5332 (5.2 KiB)

app is running inside container:
ps ax
  PID TTY      STAT   TIME COMMAND
    1 ?        Ss     0:01 python db_adapter.py
  284 pts/0    Ss     0:00 /bin/bash
  315 pts/0    R+     0:00 ps ax

I couldnt connect to db_adapter using ip like 172.18.0.2 but could connect to 127.0.0.1 (maybe problem with db_adapter?)
There is output :
docker-compose ps
       Name                      Command               State           Ports
-------------------------------------------------------------------------------------
docker_db-adapter_1   python db_adapter.py             Up      0.0.0.0:4443->4443/tcp

There is docker-compose file:
version: '2'
services:
  fake-s3:
    image: fake-s3

  db-adapter:
    image: db-adapter
    ports:
    - "4443:4443"
  mail:
    image: mail
    volumes:
    depends_on:
      - fake-s3
      - db-adapter
    links:
      - db-adapter

volumes:
    mailproxy:

Comment: yes app is running inside container
Comment: Can you provide your Dockerfile?
Comment: seems problem with app :
Comment: netstat -a shows only 127.0.0.1:4443 for some reason
Answer: Your python application db-adapter binds only to localhost. That's why you can access it only via 127.0.0.1:4443 and only inside a container. You need to find a way to bind it to 0.0.0.0. After that you can access it on 172.18.0.2:4443 inside container and by 127.0.0.1:4443 from host.


How can I modify the values in variable table using phpmyadmin?

Question: I modify the site name in variable table using phpmyadmin as below.
s:21:"firstname.lastname@example.com";  to  s:21:"email@example.com";
But then when I run cron I get the follwoing message.

Warning: Cannot modify header information - headers already sent by (output started at /public_html/includes/bootstrap.inc:566) in /public_html/includes/bootstrap.inc on line 739

This is just a examle, but if I change something in variable table using phpmyadmin I always get the same error.
When I modify variable table do I need to modify also other tables at the same time ?
Comment: Not sure if those are related to each other. Are you sure you didn't modify any core files with `print` etc?
Comment: Beebee seems right, if length of string stays unchanged, it should be OK. If it is changed, change number between `s:` and `:"`. Oh, and please use http://example.com and http://example.net as example domains. my-site.com is someone's private site, you know, and my-site.net is commercial. I bet neither is in any way related to you or this problem.
Comment: Yes, the string length must match, else change the number of chars value (21). Also, worth truncating the cache table to clear the variable cache after updating the table manually. However, at the end of the day, much better to use `variable_set` or `drush vset` to set variables.
Comment: Oh sorry the example wasn't good so I just edited. I didn't know that the number between s: and :" stands for the string length and it must match. I just tried it again with correct number of the string length and the errors is gone. Thank you. I'll also have a look at variable_set.
Answer: As stated in comments serialized string variable lenght must match the integer prefixed, eg
s:20:"email@example.com";

drush vset is alot better for this kind of adjustements.
That beeing said, for users with drush 4.5 where modifying more complex variables is not available (use variable-set with arrays and objects. Accept JSON via STDIN like cache-set), direct access to database can be handy way to tweak the system. Remember to clear caches after.


How can I start playing bagpipe?

Question: I am going to start bagpipe (either Galician, Scotish or Ireland one), but I have not clue what is the best beginning to play it.
Any tips for this instrument, in terms of music technique, please?
Thanks in advance! :)
Answer: You can start out with a practice chanter, which is just the melodic part of the pipes, to begin working on your notes and technique, and is much less expensive than a full set of pipes. Some people start off with the Penny whistle to get started on basic finger technique.
There is a type of bagpipe called the "Parlor Pipes" or "smallpipes" that is a smaller and quieter version that is often used for indoor playing and practicing.
Choosing what type to play after that, either Highland, Galician, Uilleann, Gaida or one of the other types will be influenced by what style of music you want to play, as each has its own distinct sound, and different methods/techniques of playing.
Answer: I am not an expert. I am open to correction.
Irish pipes are called  uilleann pipes. They are much quieter than Scottish bagpipes. They also impose much less strain on the player because they are inflated only by the elbow rather than by blowing. Galician pipes are similar to the Scottish ones - but they have the harshest sound of all.
If you want to annoy the neighbours, choose Scottish or Galician. These are most suited to playing out of doors and can be heard the other side of town.
Bagpipes often play together in a marching band and they may be combined with a brass band.
If you prefer to retain your hearing into old age and stay friends with your neighbours, uilleann pipes are your best bet. They are played in a sitting position and are often used indoors.
If you wish to play with other people who have different instruments then again choose uilleann pipes - they are still loud but not deafening at close quarters. You can learn traditional Irish music and play along with fiddle (violin), guitars, flutes and whistles, bodhran (hand drum) and other instruments.
As for learning, I suggest you search online for instructional videos. I searched for uilleann Pipes and found this video immediately.

Uilleann Pipes Lesson 1 [The Basics] Get Started

Finally (you may have detected some bias on my part!) uilleann pipes are much more expressive than the others. They can play vibrato and 'bend' notes.

Irish traditional music : "The Chieftains" play " O'Sullivan's March"

Galician Bagpipes in Santiago de Compostela Spain

Band of HM Royal Marines, Scotland and Scots Guards Pipes Drums
Answer: A friend who plays one told me that you start with the chanter, which is the part you play the melody on and can be played independently of the drones and the bag, making it quieter and easier to handle.

How can I start playing bagpipe?


Probability of taking water from a bottle and pouring back

Question:
We have a bottle with 1 liter of water. We take out $X\sim Uni(0,1)$ water and then put $Y\sim (0,1)$ water. $X$ and $Y$ and independent. Find how the water in the bottle is distributed at the end.

What I did:
Lets denote $Z$ to be the water at the end. We want to find $F_Z(z)$. We can see that:
$$
Z=1-X+Y
$$
where $z\in(0,2)$. Also we can see that:
$$
F_{Z}(z)=P\left(Z\leq z\right)=P\left(1-X+Y\leq z\right)=P\left(Y-X\leq z-1\right)
$$
Lets denote $U=Y-X$ where $u\in(-1,1)$. If $X\sim Uni(0,1)$ then $-X\sim Uni(-1,0)$. Using convolusion:
$$
f_{U}(u)=\int_{-\infty}^{\infty}f_{Y,X}(y,u-y)dy
$$
$X$ and $Y$ are independent so $f_{X,Y}(x,y)=f_{X}(x)f_{Y}(y)$. This means that:
$$
\begin{align*}
f_{U}(u)&=\int_{-\infty}^{\infty}f_{Y,X}(y,u-y)dy=\int_{-\infty}^{\infty}f_{Y}(y)f_{X}(u-y)dy\\&=\int_{-\infty}^{\infty}1\mathbb{I}_{\{0<y<1\}}1\mathbb{I}_{\{-1<u-y<0\}}dy\\&=\int_{-\infty}^{\infty}\mathbb{I}_{\{0<y<1\}}\mathbb{I}_{\{u<y<u+1\}}dy=\int_{-\infty}^{\infty}\mathbb{I}_{\{0<y<u+1\}\cup\left\{ u<y<1\right\} }dy\\&=\int_{0}^{u+1}dy+\int_{u}^{1}dy=u+1+(1-u)=2
\end{align*}
$$
This part I'm not sure about. I believe that I'm wrong because then I don't get $\int_{-1}^1f_U(u)=1$.
But if I'm wrong here, as  I understand I should get something like:
$$
F_{U}(u)=\int_{-\infty}^{u}tdt=\begin{cases}
0 & u<-1\\
1.5u^{2} & -1<u<1\\
1 & u>1
\end{cases}
$$
I figured that $F_U(u)$ is like so because I know that $u\in(-1,1)$ and I need $\int_{-1}^1g(u)du=1$ so I guessed that $g(u)=1.5u^2$.
Then I can say that:
$$
F_{Z}(z)=P\left(Y-X\leq z-1\right)=P\left(U\leq z-1\right)=1.5\left(z-1\right)^{2}
$$
But the solution is - for $z\in(0,1)$ it should be $F_Z(z)=z-0.5$ and for $z\in(1,2)$ it should be  $F_Z(z)=-0.5z^2+2z-1$. How did they got here?
Comment: @Vessi any questions / comments / reaction to my answer?
Answer: Assuming the bottle can hold two liters of water,
$Z = 1 - X + Y = 1 - (X-Y) = 1 + (Y-X)$
So we can either find the distribution of $X-Y$ (or $Y-X$) first and then it is straightforward to find distribution of $Z$ or we can directly find distribution of $Z$. I will take the second approach.
$F_Z(z) = P(Z \leq z) = P(Y - X \leq z - 1)$
For ease of understanding, see the sketch.

When $X \geq Y, 0 \lt Z \leq 1$ and when $Y \gt X, 1 \lt Z \lt 2$
For $X \geq Y$, see the shaded area in grey.
$ \displaystyle F_Z(z) = \int_{1-z}^1 \int_0^{x+z-1} ~ dy ~ dx = \frac{z^2}{2}, ~0 \lt z \leq 1$
For $Y \gt X$, it is easier to evaluate $P(Y-X \gt z - 1) $ and subtract from $1$. See the shaded area in light yellow.
$ \displaystyle F_Z(z) = 1 - \int_{0}^{2-z} \int_{x+z-1}^1 ~ dy ~ dx$
$ \displaystyle = 1 - \frac{(2-z)^2}{2}, ~1 \lt z \lt 2$


How do I change HOSTNAME on an Ubuntu server?

Question: I'm attempting to change the hostname on my shared server with Slicehost so I can setup Postfix as a null client.
I edited /etc/hosts
and after reboot, the hostname is still incorrect.
What am I doing wrong?
username@mail Fri Jul 01 13:01:32 ~
$ sudo cat /etc/hostname
mail.domain1.com

username@mail Fri Jul 01 13:01:45 ~
$ cat /etc/hosts
127.0.0.1     localhost localhost.localdomain
220.127.116.11  mail.domain1.com

username@mail Fri Jul 01 13:02:13 ~
$ hostname -f
pop.where.secureserver.net

I also intend to add another domain to this server, how do I configure this correctly.
Answer: Try setting the second line in hosts to 22.214.171.124  mail.domain1.com mail. Also, rebooting is not necessary: the FQDN isn't stored anywhere, it's looked up on-the-fly.
I believe that the FQDN is found by doing a DNS query on the server's IP address, then taking the first response, which is why this works. It should be possible to set the FQDN without modifying hosts by using only DNS (or NIS, or LDAP, or wherever else nsswitch.conf looks for hosts) but if it's in the hosts file there's no need for network traffic that might time out or otherwise cause problems in an emergency.
More information
Here's everything that happens (this is Linux-only, other OSes may and will do things somewhat differently):
hostname uses the gethostname(2) function specified in unistd.h to obtain the hostname. This function is implemented as a call to uname(2), where the nodename field of the structure is extracted and returned. This will have been set earlier in the boot process with the corresponding sethostname(2) call, since the kernel has no other way of knowing the host's name. In your case, it will be mail. (By the way, this is what you should have in /etc/hostname).
This is then resolved using the standard system resolver, which will be either getaddrinfo(3) or gethostbyname(3) depending upon the vintage of your system utils. The field h_name, defined as "official name of host", gets returned. I believe this corresponds to the first name listed in a hosts file.
As for your multiple domains question, hostname is not able to deal properly with multiple names. Every interface (even virtual ones) can have its own IP and sometimes even multiple physical interfaces can share an IP.
You should ensure that each IP attached to your host resolves via reverse-IP lookups to the appropriate name and configure your mail server properly.


A matroid problem inspired by a linear algebra problem

Question: Let $V$ be a finite-dimensional vector space over $\mathbb{R}$. Let $A = (v_{ij})$, with $1 \leq i \leq m$ and $1 \leq j \leq n$, be an $m$ by $n$ array of elements of $V$ (so that for each $i$, $j$ as above, $v_{ij} \in V$). Let us also assume that $m \geq n$.
Consider the following operation. Select from each row (resp. column) of $A$ an element, and then calculate the rank of the $m$ (resp. $n$) chosen elements of $A$, which means the maximal number of these $m$ (resp. $n$) elements which are linearly independent. Define the row-rank (resp. column-rank) of $A$, to be the maximum of all these ranks, as you go over all possible choices of $m$ (resp. $n$) elements of $A$, with one from each row (resp. column) of $A$.
Let $J \subseteq \underline{n}:= \{1,\ldots,n\}$ be a non-empty subset. Define $A^J$ to be the $m$ by $|J|$ subarray of $A$ whose columns are precisely the columns of $A$ indexed by elements of $J$.
Hypothesis: $\operatorname{row-rank}(A^J) \geq |J|$ for any non-empty subset $J \subseteq \underline{n}$.
Question: does it follow from the setup and hypothesis above that $\operatorname{column-rank}(A) = n$?
This post is inspired by Need help to prove the existence of set of linearly independent vectors. Indeed, if one can answer positively my question, then it would imply the statement found in this linked post. Roughly speaking, the elements of the $j$-th column of $A$ belong to the vector space $S_j$. I can explain more why a positive solution of this problem gives a solution to the problem in the linked post if someone is interested.
Remark: the problem extends almost as is to matroids. Instead of assuming that the $v_{ij}$ belong to a vector space, one may instead assume that they belong to a matroid $M$. The rest of the post remains the same.
Comment: I answered your similar question here: https://math.stackexchange.com/a/3487800/646723. I didn't check the differences between the questions to see if the answer can be extended, but it should help in any case.
Comment: @A.B., yes, I have a feeling a modification of your other answer should work here. I will try to modify your proof to see if it works for this case too also. Thank you again!
Comment: @A.B., note also that, if the proof can be extended/modified to this setting, then this would also give a proof of the linear algebra problem linked to in my post, which is what inspired me to ask these 2 problems anyway.
Comment: Are you implicitly assuming that $m\geq n$? Also, how can column-rank(A) > n happen? (It seems equality is the maximum if I understand correctly)
Comment: yes, I am implicitly assuming that $m \geq n$. I should mention that in my post. You are right about the second point too. I wrote it in a way so as to remain as close as possible to the format of the original linear algebra problem, which inspired this problem. I edited the post now. Thank you.
Comment: I think the same proof (actually, even a bit simpler since you don't need to remove rows in this case) works also here. Try it, let me know if you want me to write the full answer.
Answer: Proof by induction on $n$; assume it's true for $k=n-1$ (note that $m\geq n$ so $m\geq k$).
Step 1: remove a column (say column $n$). Then row-rank$(A^{\{1,\dots,n-1\}})\geq n-1$ by the hypothesis so by the induction hypothesis has maximal column-rank $\{e_1,\dots, e_{n-1}\}$, with $e_i$ in column $i$. Since row-rank$(A)\geq n$, by matroid properties (e.g., rank) there is an element $v_{i,j}\in A$ such that $v_{i,j}=e_n\notin cl(e_1,\dots,e_{n-1})$. Clearly, if $j=n$ then we are done, so assume $j\neq n$; wlog we may assume $j=n-1$. Now $e_1,\dots, e_n$ are independent with $e_i$ in column $i$ for $i\leq n-1$ and $e_n$ is in column $n-1$ (this column has exactly $2$ $e_i$'s).
Step 2: remove the column $n-1$ from $A$. Then by Step 1 this sub-matrix $B=A^{\{1,\dots,n-2,n\}}$ contains $e_1,\dots, e_{n-2}$ in columns $1,\dots, n-2$ respectively. Additionally, by the hypothesis row-rank$(B)\geq n-1$ so by the induction hypothesis it has maximal column-rank $\{e'_1,\dots, e'_{n-2}, e'_{n-1}\}$, with $e'_i$ in column $i$ (column $n-1$ in $B$ is column $n$ in $A$; note that these $e'_i$'s might be completely different from the $e_i$'s). If $e_{n-1}\notin cl(e'_1,\dots, e'_{n-1})$ or $e_{n}\notin cl(e'_1,\dots, e'_{n-1})$ then we are again done (we can add this element for the missing column), so assume that $e_{n-1},e_n\in cl(e'_1,\dots, e'_{n-1})$.
Step 3: Claim: there is a column $c\leq n-2$ such that $e_c\neq e'_c$ and $\{e'_1,\dots, e'_{n-2}, e'_{n-1}\}\setminus \{e'_c\}\cup \{e_c\}$ is a maximal column-rank for $B$ (i.e., it is possible to replace $e'_c$ with $e_c$ in column $c$).
Proof of claim: $rank(e_1, \dots, e_n)=n>n-1=rank(e'_1,\dots, e'_{n-1})$ so there is $e_c\notin cl(e'_1,\dots, e'_{n-2}, e'_{n-1})$, and by the assumption in Step 2 $c\neq n-1,n$. So $rank(\{e'_1,\dots, e'_{n-2}, e'_{n-1}\}\setminus \{e'_c\}\cup \{e_c\})=n-1$ by standard matroid properties.
Step 4: to conclude the proof we replace $\{e'_1,\dots, e'_{n-2}, e'_{n-1}\}$ in Step 2 with $\{e'_1,\dots, e'_{n-2}, e'_{n-1}\}\setminus \{e'_c\}\cup \{e_c\}$ in Step 3. If it still holds that $e_{n-1},e_n\in cl(e'_1,\dots, e'_{n-1})$ then we can reiterate Step 3 again and again (note that it will have to be a different $c$ each time since the $e_i$'s remain constant while the $e'_i$'s become the $e_i$'s), but at some point this process cannot continue further, since by rank considerations $cl(e_1,\dots, e_{n-2},e'_{n-1})$ cannot contain both $e_{n-1}$ and $e_n$ (i.e., in the extreme case this process stops after we replace all the $e'_i$'s with the $e_i$'s for $i\leq n-1$). At that point (when we cannot continue further) either $e_{n-1}\notin cl(e'_1,\dots, e'_{n-1})$ or $e_{n}\notin cl(e'_1,\dots, e'_{n-1})$, which means that we can add this element from column $n-1$ to form a maximal column-rank for $A$.
Comment: Thank you. And now the linear algebra problem is also solved, thanks to your proof of the problem here. Kindly see  and please tell me if you agree with my proof (I think it is fine, but just to double check).


Find the global maximum and global minimum

Question: $ f(x) = x^3 - 6x^2 - 15x + 8 $ for the interval $ [-2,6] $
My answer was :
$$ f'(x) = 3(x^2-4x-5) $$
$$ 3(x-5)(x+1) $$
so the critical points are $ x =5\; and \;x=-1 $
plugging them back with the end points into the original function
$$f(5) = 5^2 - 6(5)^2 - 15(5) +8 = -92 $$
$$ f(-1) = 16 $$
$$ f(-2) =6 $$
$$ f(6) = -82 $$
so i got the min is $-92$ and max is $16$ but the answer in the book says the min is $5$ and max is $-1$
Comment: You have a minimum of $-92$ when $x=5$ and maximum of $16$ when $x=-1$.  So going by the last comment, you and the book are both saying the same thing.  So what is the problem?
Comment: What is wrong here?!
Comment: I don't know, it's weird. The book says the right answer is min at $ x=5 $ and max at $ x=-1 $
Comment: Nothing is wrong???
Comment: yeah sorry i just got confused a little bit. sorry
Comment: f(5) = (5)^3 - ... instead of (5)^2
Answer: Hint: You are almost right!
Look at http://en.wikipedia.org/wiki/Maxima_and_minima
The global maxima is different than the maximum value of the function $f(x)$. It is the value of $x$ which maximizes $f(x)$, not the maximum value itself.
Comment: What am i wrong at ?
Comment: The global maxima is DIFFERENT from the maximum value of the function $f(x)$; it is the value of $x$ which maximizes $f(x)$ @Tennisman
Comment: Ahhh yeah :) iam stupid. Thank you


Topologies on a 3 point space

Question: Let $Y_1$ denote a 2-point discrete space, $Y_2$ a 2-point indiscrete space and $Y_3$ a 2-point space that is neither discrete nor indiscrete. Let $X$ denote a set with 3 points and describe topologies on $X$ such that $X$ has subspaces homeomorphic to two of the $Y_i$'s. Can there be a topology on $X$ such that $X$ has subspaces $Z_1$, $Z_2$, $Z_3$ such that $Z_i$ is homeomorphic to $Y_i$ for each $i$?
So I'm a little confused at how to conceptualize the $Y_2$ and $Y_3$ spaces. I'm also not sure how subspaces of X could be homeomorphic to two $Y_i$'s. Thanks for the help.
Comment: Since you are new, I want to give some advice about the site: **To get the best possible answers, you should explain what your thoughts on the problem are so far**. That way, people won't tell you things you already know, and they can write answers at an appropriate level; also, people tend to be more willing to help you if you show that you've tried the problem yourself.
Comment: You can find some good starting points on how to format mathematics on the site [here](http://meta.math.stackexchange.com/questions/5020). [This AMS reference](ftp://ftp.ams.org/ams/doc/amsmath/short-math-guide.pdf) is very useful. If you need to format more advanced things, there are many excellent references on LaTeX on the internet, including StackExchange's own [TeX.SE](http://tex.stackexchange.com/) site.
Comment: Thanks for the suggestions and help
Answer: Note that if $Y = \{ 1 , 2 \}$, then topologies on $Y$ corresponding to $Y_1$, $Y_2$, and $Y_3$, respectively, are

$\{ \emptyset , \{ 1 \} , \{ 2 \} , Y \}$;
$\{ \emptyset , Y \}$;
$\{ \emptyset , \{ 1 \} , Y \}$.

Let us now consider a three element set $X = \{ a , b , c \}$.

First suppose that we are given the following topology of $X$: $\{ \emptyset , \{ a \} , \{ b , c \} , X \}$.  Note that the subspace $\{ a , b \}$ of $X$ has as open sets the following:

$\emptyset \cap \{ a , b \} = \emptyset$;
$\{ a \} \cap \{ a , b \} = \{ a \}$;
$\{ b , c \} \cap \{ a , b \} = \{ b \}$;
$X \cap \{ a , b \} = \{ a , b \}$

And it follows that the $\{ a , b \}$ is a discrete subspace of $X$; i.e., it is homeomorphic to $Y_1$.
Now consider the following topology of $X$: $\{ \emptyset , \{ b , c \} , X \}$.  In a similar manner to the above we find that the topology on the subspace $\{ a , b \}$ is $\{ \emptyset , \{ b \} , \{ a , b \} \}$, and so this subspace is homeomorphic to $Y_3$.

While you could go through all 29 topologies on $X$ (okay, 9 up to homeomorphism) to show that none has each of $Y_1 , Y_2, Y_3$ as subspaces, we can prove this by analysing those topologies on $X$ which have homeomorphic copies of both $Y_1$ and $Y_2$ as subspaces.
If $Z_1$, $Z_2$ denote subspaces of $X$ homeomorphic to $Y_1$, $Y_2$, respectively, note that $| Z_1 \cap Z_2 | = 1$.  So without loss of generality $Z_1 = \{ a , b \}$ and $Z_2 = \{ a , c \}$. Let $U,V,W$ denote the smallest open neighbourhoods of $a,b,c$, respectively, in $X$.

As $U \cap Y_1 = \{ a \}$ and $U \cap Y_2 = \{ a , c \}$, we have $U = \{ a , c \}$.
As $c \in U$ we must have $W \subseteq U = \{ a,c \}$, and as $W \cap Y_2 = \{ a , c \}$, it follows that $W = \{ a , c \}$.
As $V \cap Y_1 = \{ b \}$, then  $V \subseteq \{ b , c \}$. If $c \in V$, then $V \cap W = \{ c \}$ is also an open neighbourhood of $c$, which is impossible since $W = \{ a , c \}$ is the smallest open neighbourhood of $c$.

This means that the topology on $X$ is $\{ \varnothing , \{ a , c \} , \{ b \} , X \}$, and it is easy to show that $X$ has no subspace homeomorphic to $Y_3$.
Answer: If $Y_1=\{a,b\}$ then the topology on $Y_1$ (the set of open sets) is $\bigl\{\emptyset,\{a\},\{b\},Y_1\bigr\}$.
If $Y_2=\{c,d\}$ then the topology on $Y_2$ is $\bigl\{\emptyset,Y_2\bigr\}$.
If $Y_3=\{e,f\}$ then the topology on $Y_3$ must be neither $\bigl\{\emptyset,\{e\},\{f\},Y_1\bigr\}$ nor $\bigl\{\emptyset,Y_3\bigr\}$; hence it is either $\bigl\{\emptyset,\{e\},Y_1\bigr\}$ or $\bigl\{\emptyset,\{f\},Y_1\bigr\}$ (and in fact there is no need to distinguish these two cases as swapping $e$ and $f$ is a homeomorphism between these two topologies); note that exactlya one of the points in $Y_3$ is closed.
Let $X=\{u,v,w\}$ be a three point space such that among the three two-point subspaces $Z_1=\{v,w\}, Z_2=\{u,w\},Z_3\{u,v\}$ there is one homeomorphic to each  $Y_i$. Wlog. (i.e. because we may rename the elements of $X$)
$Y_i\cong Z_i$.
By definition of subspace topology,a set $U\subseteq Z_i$ is (relatively) open iff there is an open set $V\subseteq X$ with $U=V\cap Z_i$.
From $Z_1\cong Y_1$, we see that one of the sets $\{v\}$ and $\{u,v\}$ is open.
From $Z_2\cong Y_2$, we see that neither $\{u\}$ nor $\{u,v\}$ is open, hence $\{v\}$ is open. Also, one of $\{w\}$, $\{u,w\}$ is open (because of $Z_1$) but neither of $\{w\}$, $\{v,w\}$ is open, hence $\{u,w\}$ is open.
But since $\{v\}$ and $\{u,w\}$ are open in $X$, their intersections $\{v\}$ and $\{u\}$ are relatively open in $Z_3$, thus making $Z_3$ discrete unlike $Y_3$.
Can we obtain a topology on $X$ if we drop the wish about $Z_3$? Using only info about $Z_1$ and $Z_2$, we have obtained the following info:
$$\begin{align}\emptyset & \text{is always open}\\
\{u\}&\text{not open}\\
\{v\}&\text{open}\\
\{u,v\}&\text{not open}\\
\{w\}&\text{not open}\\
\{u,w\}&\text{open}\\
\{v,w\}&\text{not open}\\
\{u,v,w\}&X\text{ is always open}\\
\end{align} $$
That is, we already know that the topology on $X$ is precisely $\bigl\{\emptyset,\{v\},\{u,w\},X\bigr\}$.

Topologies on a 3 point space


MYSQL - Erro código 1644

Question: Tenho duas database, quando uma trigger é disparada ela gera um insert em outra database é um artifício para gerar log :
O esquema é esse: database de nome local tem uma tabela chamada tab_manifesto e é feito um insert nesta e a trigger dispara um insert no database local_log.log_tab_manifesto.
Segue abaixo a construção e um exemplo do erro na hora de fazer o insert.
USE local_log;

delimiter $$
DROP TABLE IF EXISTS `local_log`.`log_tab_manifesto`$$
CREATE TABLE `log_tab_manifesto` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user_nome` varchar(30) NOT NULL,
  `data_hora` datetime NOT NULL,
  `host` varchar(45) NOT NULL,
  `operacao` varchar(2) NOT NULL COMMENT 'I-Insert, D-Delete, U-Update',
  `manifesto_id` int(11) DEFAULT NULL,
  `man_id` int(11) DEFAULT NULL,
  `uni_id` int(11) DEFAULT NULL,
  `filial_id` int(11) DEFAULT NULL COMMENT 'numero da carta frete de cada filial, exemplo foz_id',
  `mot_mot_id` int(11) DEFAULT NULL,
  `mot_est_id` int(11) DEFAULT NULL,
  `veic_id` int(11) DEFAULT NULL,
  `man_data` date DEFAULT NULL,
  `man_origem` varchar(45) DEFAULT NULL,
  `man_destino` varchar(45) DEFAULT NULL,
  `man_status` varchar(1) DEFAULT '0' COMMENT 'null  ou 0 = Viajando / 1 = chada / 2 = descarregando / 3 = finalizado',
  `man_ordem_chegada` datetime DEFAULT NULL COMMENT 'Ordena a Chegada dos Manifestos',
  `man_cancelado` varchar(1) DEFAULT NULL,
  `man_descarga` datetime DEFAULT NULL,
  PRIMARY KEY (`id`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8$$

    -- CRIANDO trigger PARA A TABELA - triggers SÃO CRIADAS NA DATABASE DE ***PRODUÇÃO***
DELIMITER $$

USE `local`$$

DROP TRIGGER IF EXISTS `local`.`tg_tab_manifesto_after_i`$$
CREATE
DEFINER=`root`@`127.0.0.1`
TRIGGER `local`.`tg_tab_manifesto_after_i`
AFTER INSERT ON `local`.`tab_manifesto`
FOR EACH ROW
BEGIN
    DECLARE EXIT HANDLER FOR SQLEXCEPTION /*DECLARAR EXECEÇÃO*/
    RESIGNAL SQLSTATE '21S01' SET MESSAGE_TEXT = 'TRIGGER tg_tab_manifesto_after_i';/*RETORNA O NOME DA TRIGGER EM CASO DE ERRO*/
    /*LOG - INSERIR NOVO REGISTRO DE LOG */
    set @id = (select ifnull(max(id)+1,1) from local_log.log_tab_manifesto);
    insert into local_log.log_tab_manifesto
        values(
            @id,
            substring_index(session_user(),'@',1),
            now(),
            substring_index(session_user(),'@',-1),
            'I',
            NEW.`log_tab_manifesto`.`manifesto_id`,
            NEW.`log_tab_manifesto`.`man_id`,
            NEW.`log_tab_manifesto`.`uni_id`,
            NEW.`log_tab_manifesto`.`filial_id`,
            NEW.`log_tab_manifesto`.`mot_mot_id`,
            NEW.`log_tab_manifesto`.`mot_est_id`,
            NEW.`log_tab_manifesto`.`veic_id`,
            NEW.`log_tab_manifesto`.`man_data`,
            NEW.`log_tab_manifesto`.`man_origem`,
            NEW.`log_tab_manifesto`.`man_destino`,
            NEW.`log_tab_manifesto`.`man_status`,
            NEW.`log_tab_manifesto`.`man_ordem_chegada`,
            NEW.`log_tab_manifesto`.`man_cancelado`,
            NEW.`log_tab_manifesto`.`man_descarga`
        );
end$$

O erro acontece aqui nesse insert abaixo:
INSERT INTO
tab_manifesto(
    uni_id,
    filial_id,
    mot_mot_id,
    mot_est_id,
    veic_id,
    man_origem,
    man_destino
) values (
    1,
    NULL,
    30,
    NULL,
    327,
    'FOZ',
    ' SAO PAULO'
);

Error Code: 1644. TRIGGER tg_tab_manifesto_after_i

Alguém poderia me ajudar a corrigir esse erro ?
Comment: O erro não é nessa linha ? `TRIGGER `local`.`tg_tab_manifesto_after_i``
Comment: Qual a versão do MySQL?
Answer: Achei esse site que diz que esse erro é definido pelo usuário... então dei uma olhada novamente no código para ver onde eu escrevi isso e achei as linhas são essas
DECLARE EXIT HANDLER FOR SQLEXCEPTION /*DECLARAR EXECEÇÃO*/
RESIGNAL SQLSTATE '21S01' SET MESSAGE_TEXT = 'TRIGGER tg_tab_manifesto_after_i';/*RETORNA O NOME DA TRIGGER EM CASO DE ERRO*/

Comentei essas linhas e rodei o script novamente, ai sim consegui uma mensagem de erro mais detalhada:

08:34:09  INSERT INTO   tab_manifesto(   uni_id,   filial_id,   mot_mot_id,   mot_est_id,   veic_id,   man_origem,   man_destino  ) values (   1,   NULL,   30,   NULL,   327,   'FOZ',   ' SAO PAULO'  ) Error Code: 1054. Unknown column 'NEW.log_tab_manifesto.manifesto_id' in 'field list'   0.031 sec

Não existe NEW.log_tab_manifesto.manifesto_id o correto é NEW.tab_manifesto.manifesto_id
Obrigado a todos pela atenção, lição aprendida!

MYSQL - Erro código 1644


Link a repository folder to another non-repo folder

Question: I have local windows machine which I use as a local dev environment.
Which has a project directory as follows.
<code>C:\xampp\htdocs
 |-project1
 |-project2
</code>
I also use what Github/AWS code deployment. Which basically is repo I have that when I publish changes, it deploys the changes to the server.
However the structure of the repo files is a bit different. This is how its structured locally on my computer.
<code>..\Github
     |-repository
        |-folder1
        |-folder2
        |-project2
        |-some other files
</code>
So the project that is associated in this repository is project2 which contatins the websites files of my server (hence the reason its at the htdocs folder). Currently the way I make changes is:

do them at htdocs
then copy all changes to the repo folder

which is tedious if you have alot of changes.
I then came across symbolic links to link the htdocs/project2 and repository/project2, which unfortunately are unsupported in git.
So is there way to link them, or maybe a way to tell git to use the htdocs\ project2 folder as its project2 folder.
Answer: You can't really link a folder using git - that is more of a OS thing - probably if you where using linux the sym-links would work better.
However, if project2 is some sort of common repo (i.e. its going to be used in more than one place) you could make it a separate repository and then add it to your github/repository as a sub-module.
Then git clone your project2 repo into htdocs (not as a submodule, but as a normal repo).
Now when you make changes to htdocs/project2 you can push them to the remote (in github). When you are happy with your changes you update your github/repository (which has the submodule preject2 in it) to point to the latest project2 commit. Then your AWS will automatically deploy as before with the updated project2.
This would probably be the correct "workflow" for this sort of work...
Answer: I think the approach with symlinks could work. You can make a link from htdocs/project2 -> to repository/project2. On Windows this can be done with mklink.
I would instead align the 2 structures. Because your local XAMPP configuration is under your full control, you could just configure Apache so that your DocumentRoot points to your ...\Github\repository folder instead of C:\xampp\htdocs . Then you can work and commit to the same place without copying.
Comment: Why it is not trivial on Windows? Just `mklink /J link target`
Comment: That's cool, I didn't know.

So something like:

 mklink /J C:\xampp\htdocs\project2 ...\Github\repository\project2

should work then.
Might also need to set FollowSymLinks in Apache config?


how monitor root search path in linux RedHat 8.3?

Question: Due to security policies I have to regulary monitor root search PATH for any changes.
My question is what is best solution ?
Is enough to monitor just variable $PATH  or do I need to also monitor config files like:  /etc/profile, /bashrc ...?
Comment: What about LD_LIBRARY_PATH?   Do you plan to monitor that also?
Comment: Hi, Looks that LD_LIBRARY_PATH is not part of my security audit requirement, so not now.
Answer: Usually the procedure for security audit is to check the current status (when run the audit). So the simplest way is to run echo $PATH when login as (or become) root. This check will actually include "check" of /etc/profile and other related files
About how exactly to do the monitoring you can use ansible to collect info or monitoring program like nagios.


Lavel 5.x with Redis Queues generating huge logs

Question: I have a project that's setup with Laravel and Redis Queues. The application is configured to send push notifications when it receives a message. As soon as message is received, it's stored in the DB and a push is generated:
dispatch(new CreateMessageNotification($message));
Project is using Redis queue and Service Provider. The problem is that queue dispatch doesn't work if we don't execute the following command:
php artisan queue:work redis --daemon
However, when we do run this command, the application start to generate error logs below. It appears that some routine is stuck somewhere, and we're unable to figure out where, why and how? If we don't run this script, push notifications don't work. If we do run this script, push notifications work with delay, and ERROR logs are produced AND the size of log reaches to GB in a matter of an hour. What are we doing wrong here?
We're using Redis/Predis:
'redis' => [
    'client' => 'predis',
    'cluster' => env('REDIS_CLUSTER', false),
    'default' => [
        'host' => env('REDIS_HOST', 'localhost'),
        'password' => env('REDIS_PASSWORD', null),
        'port' => env('REDIS_PORT', 6379),
        'database' => env('REDIS_DB', 0),
        'timeout' => 15.0,
    ],
],

For broadcasting, we're using Pusher:
'default' => env('BROADCAST_DRIVER', 'pusher'),

For queue, we're using Redis:
'default' => env('QUEUE_DRIVER', 'sync'),

QUEUE_DRIVER=redis

For cache, we're using Redis:
'default' => env('CACHE_DRIVER', 'file'),

CACHE_DRIVER=redis

CreateMessageNotification
<?php
namespace App\Jobs\EventHandlers;

use App\Events\Notifications\NewMessageCreatedEvent;
use App\Repositories\UserDevicesRepository;
use Event;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class CreateMessageNotification implements ShouldQueue
{
    use InteractsWithQueue, Queueable, SerializesModels;

    private $message;

    public function __construct($message)
    {
        $this->message = $message;
    }

    public function handle()
    {
        Event::fire(new NewMessageCreatedEvent($this->message));
    }
}

NewMessageCreatedEvent
<?php
namespace App\Events\Notifications;

use App\Models\Chat\Message;
use Event;
use Illuminate\Queue\SerializesModels;

class NewMessageCreatedEvent extends Event
{
    use SerializesModels;

    public function __construct(Message $message)
    {
        $message->load(['other', 'chat', 'chat.chatUsers']);

        foreach ($message->chat->chatUsers as $chatUser) {
            if ($chatUser->user_id !== $message->other->id) {
                Event::fire(new NewMessageNotificationEvent($message, $chatUser->user_id));
            }
        }
    }
}

ERROR LOG
[2018-09-06 06:28:55] local.ERROR: exception 'Illuminate\Broadcasting\BroadcastException' with message 'API call failed since (daily) message quota exceeded
' in /var/www/html/project/vendor/laravel/framework/src/Illuminate/Broadcasting/Broadcasters/PusherBroadcaster.php:106
Stack trace:
#0 /var/www/html/project/vendor/laravel/framework/src/Illuminate/Broadcasting/BroadcastEvent.php(49): Illuminate\Broadcasting\Broadcasters\PusherBroadcaster->broadcast(Array, 'new_$
#1 [internal function]: Illuminate\Broadcasting\BroadcastEvent->handle(Object(Illuminate\Broadcasting\Broadcasters\PusherBroadcaster))
#2 /var/www/html/project/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(30): call_user_func_array(Array, Array)
#3 /var/www/html/project/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(87): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#4 /var/www/html/project/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(31): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Appli$
#5 /var/www/html/project/vendor/laravel/framework/src/Illuminate/Container/Container.php(539): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Arr$
#6 /var/www/html/project/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(94): Illuminate\Container\Container->call(Array)
#7 /var/www/html/project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(114): Illuminate\Bus\Dispatcher->Illuminate\Bus\{closure}(Object(Illuminate\Broadcasting\Broa$
#8 /var/www/html/project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(102): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Broadcast$
#9 /var/www/html/project/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(98): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#10 /var/www/html/project/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(43): Illuminate\Bus\Dispatcher->dispatchNow(Object(Illuminate\Broadcasting\BroadcastEv$
#11 /var/www/html/project/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php(69): Illuminate\Queue\CallQueuedHandler->call(Object(Illuminate\Queue\Jobs\RedisJob), Array)
#12 /var/www/html/project/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(317): Illuminate\Queue\Jobs\Job->fire()
#13 /var/www/html/project/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(267): Illuminate\Queue\Worker->process('redis', Object(Illuminate\Queue\Jobs\RedisJob), Object(Il$
#14 /var/www/html/project/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(113): Illuminate\Queue\Worker->runJob(Object(Illuminate\Queue\Jobs\RedisJob), 'redis', Object(Ill$
#15 /var/www/html/project/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(102): Illuminate\Queue\Worker->daemon('redis', 'default', Object(Illuminate\Queue\Wo$
#16 /var/www/html/project/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(86): Illuminate\Queue\Console\WorkCommand->runWorker('redis', 'default')
#17 [internal function]: Illuminate\Queue\Console\WorkCommand->fire()
#18 /var/www/html/project/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(30): call_user_func_array(Array, Array)
#19 /var/www/html/project/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(87): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#20 /var/www/html/project/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(31): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Appl$
#21 /var/www/html/project/vendor/laravel/framework/src/Illuminate/Container/Container.php(539): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Ar$
#22 /var/www/html/project/vendor/laravel/framework/src/Illuminate/Console/Command.php(182): Illuminate\Container\Container->call(Array)
#23 /var/www/html/project/vendor/symfony/console/Command/Command.php(252): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\$
#24 /var/www/html/project/vendor/laravel/framework/src/Illuminate/Console/Command.php(168): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\Ar$
#25 /var/www/html/project/vendor/symfony/console/Application.php(946): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\C$
#26 /var/www/html/project/vendor/symfony/console/Application.php(248): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Queue\Console\WorkCommand), Object(Symf$
#27 /var/www/html/project/vendor/symfony/console/Application.php(148): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfon$
#28 /var/www/html/project/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(122): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\In$
#29 /var/www/html/project/artisan(36): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\Conso$
#30 {main}

[2018-09-06 06:28:55] local.ERROR: exception 'ErrorException' with message 'Trying to get property of non-object' in /var/www/html/project/app/Events/Notifications/NewMessageCreate$
Stack trace:
#0 /var/www/html/project/app/Events/Notifications/NewMessageCreatedEvent.php(27): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8, 'Trying to get p...', '/var/www/h$
#1 /var/www/html/project/app/Jobs/EventHandlers/CreateMessageNotification.php(38): App\Events\Notifications\NewMessageCreatedEvent->__construct(Object(App\Models\Chat\Message))
#2 [internal function]: App\Jobs\EventHandlers\CreateMessageNotification->handle()
#3 /var/www/html/project/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(30): call_user_func_array(Array, Array)
#4 /var/www/html/project/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(87): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#5 /var/www/html/project/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(31): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Appli$
#6 /var/www/html/project/vendor/laravel/framework/src/Illuminate/Container/Container.php(539): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Arr$
#7 /var/www/html/project/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(94): Illuminate\Container\Container->call(Array)
#8 /var/www/html/project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(114): Illuminate\Bus\Dispatcher->Illuminate\Bus\{closure}(Object(App\Jobs\EventHandlers\Creat$
#9 /var/www/html/project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(102): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(App\Jobs\EventHandle$
#10 /var/www/html/project/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(98): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#11 /var/www/html/project/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(43): Illuminate\Bus\Dispatcher->dispatchNow(Object(App\Jobs\EventHandlers\CreateMessag$
#12 /var/www/html/project/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php(69): Illuminate\Queue\CallQueuedHandler->call(Object(Illuminate\Queue\Jobs\RedisJob), Array)
#13 /var/www/html/project/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(317): Illuminate\Queue\Jobs\Job->fire()
#14 /var/www/html/project/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(267): Illuminate\Queue\Worker->process('redis', Object(Illuminate\Queue\Jobs\RedisJob), Object(Il$
#15 /var/www/html/project/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(113): Illuminate\Queue\Worker->runJob(Object(Illuminate\Queue\Jobs\RedisJob), 'redis', Object(Ill$
#16 /var/www/html/project/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(102): Illuminate\Queue\Worker->daemon('redis', 'default', Object(Illuminate\Queue\Wo$
#17 /var/www/html/project/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(86): Illuminate\Queue\Console\WorkCommand->runWorker('redis', 'default')
#18 [internal function]: Illuminate\Queue\Console\WorkCommand->fire()
#19 /var/www/html/project/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(30): call_user_func_array(Array, Array)
#20 /var/www/html/project/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(87): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#21 /var/www/html/project/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(31): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Appl$
#22 /var/www/html/project/vendor/laravel/framework/src/Illuminate/Container/Container.php(539): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Ar$
#23 /var/www/html/project/vendor/laravel/framework/src/Illuminate/Console/Command.php(182): Illuminate\Container\Container->call(Array)
#24 /var/www/html/project/vendor/symfony/console/Command/Command.php(252): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\$
#25 /var/www/html/project/vendor/laravel/framework/src/Illuminate/Console/Command.php(168): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\Ar$
#26 /var/www/html/project/vendor/symfony/console/Application.php(946): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\C$
#27 /var/www/html/project/vendor/symfony/console/Application.php(248): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Queue\Console\WorkCommand), Object(Symf$
#28 /var/www/html/project/vendor/symfony/console/Application.php(148): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfon$
#29 /var/www/html/project/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(122): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\In$
#30 /var/www/html/project/artisan(36): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\Conso$

Answer: What worked for me was to remove all failed jobs from the queue (after attempting to retry just one more time):
php artisan queue:restart
php artisan queue:work redis --daemon --tries=1

Re-run the queue:
php artisan queue:work redis --daemon

Also, I had to get rid to calls to Pusher which were failing to get this to work.


How to display translated term names in exposed form in block

Question: So I've got a views page displaying a list of nodes from specific content type. This view has filter form exposed in a block.
Some of the filters in the form are vocabularies. I'm using the BEF module to display the terms from each vocabulary as checkboxes instead of the default select lists.
The terms are translated - I'm using i18ntaxonomy for that, the vocabularies have this option selected: Localize terms. Terms are common for all languages, but their name and description may be localized.
The problem is that when the site is displayed in other languages different than the default one, the terms in the form are not translated.
I guess the problem is not with BEF as when I disable the module the terms remain untranslated.
I'm looking for any advice on how to debug/solve this issue.
This is definitely not the correct way to do it, but as the project deadline is tomorrow I've got no other choice but to hack the views module source code:
<code>--- a/htdocs/sites/all/modules/views/modules/taxonomy/views_handler_filter_term_node_tid.inc
+++ b/htdocs/sites/all/modules/views/modules/taxonomy/views_handler_filter_term_node_tid.inc
@@ -122,7 +122,7 @@ class views_handler_filter_term_node_tid extends views_handler_filter_many_to_on
           $result = db_query("SELECT td.* FROM {term_data} td INNER JOIN {vocabulary} v ON td.vid = v.vid ORDER BY v.weight, v.name, td.weight, td.name");
         }
         while ($term = db_fetch_object($result)) {
-          $options[$term->tid] = $term->name;
+          $options[$term->tid] = i18ntaxonomy_translate_term_name($term);
         }
       }
</code>
I don't think a patch for the views module will be accepted. Any suggestions how should I proceed with this?
Answer: Your best path would be to open an issue with Views after confirming that the terms don't translate correctly with BEF module disabled.
I found this issue related to translation in BEF's queue, but that looks to be slightly different or only part of your issue.
Unfortunately it can be difficult for contrib module maintainers to test their modules in multiple languages unless they happen to run their own multilingual site, so it is up to the community to make them aware of issues and help test patches.
You also might want to take a look at http://drupal.org/project/i18nviews
Comment: Hey, thanks for looking at this. As I've already wrote above, I have confirmed that the issue is not with BEF. Unfortunately the i18nviews module doesn't solve the problem neither. So yes, I'll be opening an issue, just have to decide in which queue, maybe the i18nviews is the appropriate place for that, but I think the views code has to be changed. I'll have to look more at how things are handled in views-3 first.
Answer: According to Martin, it's not an issue with BEF. I was struggling with this and after installing http://drupal.org/project/i18nviews I saw an option in my view that said:
Profile: Country (field_academy_country) (translated) --> In your case would be Content Type: Field title (field_name) (translated).
This provides me an exposed filter with translated terms. Hope this helps.


My navigation menu disappears when the window resizes

Question: This is my wordpress site.
When the window gets smaller, the navigation menu disappears and the logo gets bigger.
What can I do to keep the logo and a fixed size in relation to the window size and also make sure the navigation menu doesnt disappear ?
I am pretty new to wordpress and css etc. So it would be useful if someone gave me some tips.
I think I am supposed to use an <code>@media query</code>, thats about all I know. WP is a little bit confusing to use.
Comment: Your question is pretty unclear. Please read this article and try to improve your question: http://meta.stackoverflow.com/questions/156810/stack-overflow-question-checklist
Answer: because your wp theme seem to use the Bootstrap, when your window gets smaller than 992px
these code  work:
<code>@media (max-width: 992px)
#nav-main ul.sf-menu {
 display: none;
}
</code>
so you can find the bootstrap.css and delete these code up there.
Then you will got this:
Comment: Also you may find the `bootstrap.css` here `http://smart-charge-no.mrbazaari.com/wp-content/themes/virtue/assets/css/bootstrap.css?ver=204`
Comment: THanks. I cant seem to find any file named "bootstrap.css".
Comment: @user3702037 Ok, then you can add it to your own `.css` file. like `@media (max-width: 992px){
#nav-main ul.sf-menu {
 display: block !important;
}}`


About a bijective function with the disjoint sets

Question: In this video by 0:55, it says

Lemma: Let $A,B,C,D$ be sets with $A\cap B=\emptyset$ and $C\cap D=\emptyset$. Suppose that $F_1:A\to C$ and $F_2:B\to D$ are both bijections. Define $F:A\cup B\to C\cup D$ by
  $$
F(x)=\begin{cases}
F_1(x) & \text{ if } x\in A \\
F_2(x) & \text{ if } x\in B
\end{cases}
$$
  Then $F$ is a bijection.

To me, it is easy to prove it by looking at the $F|_A$ and $F|_B$ seperately, and then, by construction, $F$ is bijective by collecting the elements of $A$ and $B$. The question is, why do the intersections $A\cap B$ and $C\cap D$ have to be empty, in particular the last one?
Answer: If the intersection $A \cap B$ is nonempty, the function may not be well-defined — if $x\in A \cap B$ and $F_1(x) \neq F_2(x)$, which one do you choose when evaluating $F(x)$?
If the intersection $C \cap D$ is nonempty, the function may not be an injection. For $y \in C \cap D$, there must be $x_1 \in A$ and $x_2 \in B$ such that $F_1(x_1) = y$ and $F_2(x_2) = y$. But then $F(x_1) = F(x_2)$; if $x_1 \neq x_2$ (which may very well be true), then $F$ is not an injection.
Comment: @BertrandWittgenstein'sGhost Nope, I meant what I said. If there is $x \in A \cap B$ such that $F_1(x) \neq F_2(x)$, then the function $F$ will not be well-defined, as we would have both $F(x) = F_1(x)$ and $F(x) = F_2(x)$. It certainly does not imply that the function is always undefined if the intersection is nonempty, but in order to guarantee that the function is well-defined, you want this to hold.
Comment: By definition, a function maps each element do the domain to exactly one element of the codomain. Ergo, in the chance that $F_1(x) \neq F_2(x)$, the function $F$ is not well-defined.
Comment: Nothing I wrote implies that the function will necessarily not be surjective, as it is quite possible that the function is actually bijective (let $A = C = \{1,2\}$ and $B = D = \{2,3\}$ and take all three functions to be the identity). My point is that, if we do not add the constraint that $A \cap B$, you cannot even guarantee that $F$ is well-defined. Is there some aspect of this argument in particular which you do not understand?
Comment: I think you mean the function will not be a bijection. Non-empty intersection does not imply undefined function even by the answer you have posed. Please fix it.
Comment: I still do not see the logic, your answer and the comment imply the function is not surjective. Which is fine, but not necessarily undefined.
Comment: You said, $F_1(x)\neq F_2(x)$, which one do you choose evaluting. What I am saying is that indeterminacy does not imply that it is undefined. There is a big leap between the premise and conclusion. What I am saying is given the conditions we can deduce the function is not a bijection, but you are saying the function is not defined altogether. Your argument is not supported by what you are writing.
Comment: You are absolutely correct. My god, that totally skipped my mind lol. Sorry about that!
Comment: +1 :) for this answer.
Answer: If $y \in A\cap B$ then which do you choose to define $F(y)$ as?  $F_1(y)$ or $F_2(y)$?  If you define it as $F_1(y)$ then it's possible that nothing will be mapped to $F_2(y)$ and vice versa so it may not be surjective.  (And if $C\cap D = \emptyset$ then definitely on of $F_1(y)$ or $F_2(y)$ will not be mapped to.)
Likewise if $z \in C\cap D$ then it's possible there is an $a \in A$ and a $b \in B$ so that $F_1(a) = F_2(b) = z$.  So $F$ may not be one to one.


What are some application of finding largest eigenvalue numerically?

Question: I am interested in knowing some applications of approximating the largest eigenvalue of a large matrix using methods such as power method and Lanczos method and Arnoldi iteration... in domains such as machine learning and sciences. What are some examples? I thought of one application that is to approximate the condition number of a large matrix. However, for engineering and sciences I have no idea when they're used and as an applied mathematics student I am curious to know about these applications.
Comment: I had a small summer job a decade ago where I compiled and wrapped an Arnoldi package (it was called Arpack, written in Fortran, and they needed it to work with C#). I was, unfortunately, never curious enough to dig deeply into why they wanted me to do it. But I did hear "dimensionality reduction" mentioned. So some kind of optimisation problem, apparently. But don't ask me how large eigenvalues are actually useful for that.
Comment: Google's PageRank algorithm; see [this question](https://math.stackexchange.com/questions/936757/why-is-pagerank-an-eigenvector-problem), for example.
Answer: The dominant eigenvalue determines the maximum growth rate on the norm of a vector when you apply the operator to it.   So if your largest eigenvalue is $M$ for a matrix $A$,  then you know for all vectors $v$,
$$\|Av\|\leq M\|v\|$$
with equality if $v$ is in the eigenspace for one of the eigenvalues of maximal norm.   This obviously helps us bound the possible growth, as well as knowing in what direction things grow in.
One interesting application I know of was in Conway's look and say sequence, where one takes a $92\times 92$ matrix,  finds a 21 dimensional invariant subspace where the eigenvalues are all norm 1 (so in that area it doesn't grow), then on the remaining $71\times 71$ matrix you get the dominant eigenvalue is Conway's Cosmological Constant.


Metric Density always zero or one?

Question: I am given a fixed Borel measurable set $E\subset\mathbb [0,1]^n$, $|E|>0$, and I want to show that there exists some $\epsilon_0>0$ such that for all $\delta>0$ there exists a cube $C_\delta\subset [0,1]^n$ with $|C_\delta|\le\delta$ such that
$$
\epsilon_0\le\frac{|C_\delta\cap E|}{|C_\delta|}\le 1-\epsilon_0.
$$
This would hold true if there existed a point at which the metric density of $E$ was neither zero nor one. My question therefore is: Does there always exist such a point? And if not, how else can I prove the claim above?
A simple example is $E = [0,\tfrac 1 2]$ in $[0,1]$ (i.e., $n=1$). Then we can choose $C_\delta = (\tfrac 1 2-\tfrac\delta 2,\tfrac 1 2+\tfrac\delta 2)$.
Comment: What if $E=[0,1]^n$? Am I missing something?
Comment: If $E$ has measure zero, then every point has density zero; if the complement has measure zero, then every point has density one.  Those are trivial cases.  Are there any other Borel sets $E \subset [0,1]^n$ such that every point has density either zero or one?
Answer: For any Borel-measurable set, it is known that the almost-all points are Lebsgue Points, see also Lebesgue differentiation theorem.
It is easy to find simple counterexamples for the fact that not all points are Lebesgue Points: Take just $E=[1/3,2/3]$, then for any $\delta >0$ we have with $C_\delta := [1/3-\delta,1/3+\delta]$
$$\frac{\lambda(C_\delta \cap E)}{\lambda(C_\delta)} = \frac{1}{2}.$$

Metric Density always zero or one?


Find the conserved quantity

Question: I have the system of ode $\frac{da}{dt}=2ab$,
$\frac{db}{dt}=b^2-a^2+1-\frac{a}{\pi}$
When I am plotting it in xppaut(see the picture attached). I can see that a quantity is conserved but I am unable to figure out the expression. Can anyone please help? If you can give me the steps on how you get the conserved quantity that would be very helpful as well.
My try: I was using trial and error with $\alpha a^2+\beta b^2$ but didn't get much help.
Now I am trying to find out the integrating factor of $\frac{da}{db}=\frac{2ab}{b^2-a^2+1-\frac{a}{\pi}} \Rightarrow (b^2-a^2+1-\frac{a}{\pi})da-(2ab)db=0$.
Now this is not exact[$2b\neq -2b$].
Then I got the integrating factor $=\frac{1}{a^2}$ and got the solution
$$\frac{b^2}{a}+\frac{1}{a}+a+\frac{\ln a}{\pi}=C$$ for some integrating constant $C$.
Now I am trying to use it somehow. If you get a conserved quantity please let me know.
Comment: The expression $\frac{b^2}{a} + \frac{1}{a} + a + \frac{\ln a}{\pi}$ is the conserved quantity. What else are you asking?
Comment: Could you give references to xppaut ?
Comment: Yes I got that later on.
Comment: @JeanMarie what are "references to xppaut"? I haven't done that before. So I was not aware.
Comment: I mean : you have mentionned and used a software called "xppaut". My question was "could you give some information about this software" ?
Answer: $$\left(b^2-a^2+1-\frac{a}{\pi}\right)da-(2ab)db=0$$
$$\implies b^2da-(2ab)db=\left(a^2+\frac{a}{\pi}-1\right)da$$
$$\implies \frac{1}{\left(\frac{a}{b^2}\right)^2}d\left(\frac{a}{b^2}\right)=\frac{1}{a^2}\left(a^2+\frac{a}{\pi}-1\right)da$$
$$\implies \frac{b^2}{a}+\frac{1}{a}+a+\frac{\ln a}{\pi}=C$$
Since $C$ is independent of the variable $t$, it is a conserved quantity.
Comment: Hasn't this result already been obtained by Ri-Li ?

Find the conserved quantity


Error installing pyo module

Question: Using Python 3.5.3 on Windows 10.
I am trying to install the pyo 0.8.6 module but I simply can't.
Firstly, I tried by using the installer provide by AJAX SOUND STUDIO pyo_0.8.6_py3.5_setup.exe, but gave me the next error every time I import the module:
Traceback (most recent call last):
  File "D:/OneDrive/Documents/Python/prubas/pyo test.py", line 1, in <module>
    from pyo import *
  File "C:\Users\Yooma\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pyo.py", line 21, in <module>
    import pyolib.analysis as analysis
  File "C:\Users\Yooma\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pyolib\analysis.py", line 32, in <module>
    from ._core import *
  File "C:\Users\Yooma\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pyolib\_core.py", line 57, in <module>
    from _pyo import *
ImportError: DLL load failed: The specified module could not be found

Then I tried to install the Python 2.7 pyo version with no luck.
Then I tried to install it from source code using the next command as admin
D:\OneDrive\Documents\Python\Librerías\pyo-master> C:\Users\Yooma\AppData\Local\Programs\Python\Python35-32\python.exe setup.py install

and gave me the next output
running install
    running build
    running build_py
    running build_ext
    building '_pyo' extension
    C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -DUSE_PORTAUDIO -DUSE_PORTMIDI -DUSE_OSC -IC:\porta
    udio\include -IC:\portmidi\pm_common -Iinclude "-IC:\Program Files (x86)\Mega-Nerd\libsndfile\include" -IC:\liblo-0.28 -IC:\pthreads\include -IC:\portmid
    i\porttime -IC:\Users\Yooma\AppData\Local\Programs\Python\Python36-32\include -IC:\Users\Yooma\AppData\Local\Programs\Python\Python36-32\include "-IC:\Pr
    ogram Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.15063.0\ucrt" "-IC:\Program Files (x86)
    \Windows Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.15063.0\shared" "-IC:\Program Files (x86)\Windows Kits\10
    \include\10.0.15063.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.15063.0\winrt" /Tcsrc/engine\pyomodule.c /Fobuild\temp.win32-3.6\Release
    \src/engine\pyomodule.obj -Wno-strict-prototypes -Wno-strict-aliasing -O3 -g0
    cl : Command line error D8021 : invalid numeric argument '/Wno-strict-prototypes'
    error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\cl.exe' failed with exit status 2

Then I tried to change the bin folder to uppercase C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\cl.exe to C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\cl.exe and nothing. do not ask why
Then I downgraded Visual C++ 2017 (14.10) to Visual C++ 2015 (14.0) (MSC v.1900) do not ask why
And finally I tried to use the build_installers_win.bat inside the pyo-master\installers\win directory using
PS D:\> D:\OneDrive\Documents\Python\Librerías\pyo-master\installers\win\build_installers_win.bat

and gave me the next output
*** Build installer for python2.7 ***
"Compil32" is not recognized as an internal or external command, operable program or batch file.
*** Build installer for python3.5 ***
"Compil32" is not recognized as an internal or external command, operable program or batch file.

I am completely lost.
ʰᵉˡᵖ
Answer: Finally, Belangeo said there was a bug on Windows that will fix in the next version for Python 3.6...
I managed to make it work by installing an older version. (0.8.4).

Error installing pyo module


angular-ui-router Gone Wrong

Question: I have tried this multiple times to no avail. Here is my set-up:
Angular: 1.5.7
angular-ui-router: 0.3.1
Here are my files:
/demo
  /node_modules
    (module files)
  -index.html
  -route1.html
  -route1.list.html
  -route2.html
  -route2.list.html

Here are the file contents:
index.html
<!doctype html>

    <title>AngularJS ui-router Demo</title>
    <link href="<path to bootstrap css file>" rel="stylesheet" />

        Quick Start

Route 1

Route 2

The route1.html, route1.list.html, route2.html and route2.list.html are all simple H1 tag titles with a P tag of dummy text, nothing special.
This code structure was modified from the original AngularJS ui-router examples.
There doesn't seem to be anything wrong with the code. If anyone notices any bug or gremlin, please advise.
Thanks!
Comment: So what doesn't work exactly? What errors pops in the console (if any)?
Comment: @AlonEitan there was absolutely nothing showing as an error. When I went to inspect elements and view the console, I received no errors either, because I injected "ui-router" instead of "ui.router". (see below answer)
Comment: Yes, I know, I wrote that answer after noticed that problem with the module name :)
Comment: @AlonEitan oh, that IS you ^_^ You're fast! I thought that was someone else.
Answer: The problem is here:
var myapp = angular.module('myapp', ['ui-router']);

The module name is ui.router, so change it to:
var myapp = angular.module('myapp', ['ui.router']);

Comment: That was it. Thanks a million!

angular-ui-router Gone Wrong


Silverlight app in iframe access to parent window

Question: I have Silverlight application test page named A.html hosted in an iframe which is an element of B.html, so is there a way for Silverlight app to access elements in B.html by referring something like HtmlPage.Document..?
Thanks!
Answer: You can always walk up the DOM tree by doing something like this:
var htmlElement = HtmlPage.Document.DocumentElement.Parent;

Answer: In the container html page, add following function:
function GetParent
{
   return parent;
}

In the SL control, do this:
HtmlWindow parent = (HtmlWindow)HtmlPage.Window.Invoke("GetParentWindow");

Now to invoke any function from the parent Html page, just call
parent.Invoke("myFunction");

Hope this solves your issue.
Ahmad.
Answer: Using Silverlight/Moonlight is very risky. Most of your website's guests will not have this plugin installed. This will strongly limit your website accessibility.
Use Flash instead, or even better use only [x]html+css+javascript.
Comment: Not a very helpful answer. It's akin to telling someone to use Linux or Mac OS X when they say they've got a problem with a Windows virus.


Prove that for every $x>0$, it follows that $\frac{\ln x}{x} \leq\frac{1}{e}$

Question: I need to prove that for every $x>0$ $$\frac{\ln x}{x} \leq\frac{1}{e}$$
I tried to show that when the limit goes to $+\infty$ the function $\frac{\ln x}{x} -\frac{1}{e}$ goes to $-1/e$ but that of course doesn't guarantee it won't suddenly "jump" far and beyond somewhere along the way and then come back.
When I take the derivative I get that for some of the range the function is going up rather than down, so that it being smaller than $0$ cannot be guaranteed.   As a result don't I know how to prove this.
Comment: Mathjax/Latex tip: Instead of "<=". Type "\leq" (less or equal) with dollar signs around it. It will look like this: $\leq$
Comment: you just need to show that $x^e\le e^x$
Comment: you can have a look: https://math.stackexchange.com/questions/1619911/why-ex-is-always-greater-than-xe/1619966#1619966
Answer: defining $$f(x)=\frac{x}{e}-\ln(x)$$ then we get:
$f(x)$ has a Minimum in $x=e$ and $$\lim_{x\to 0^+}f(x)=+\infty$$ and $$\lim_{x\to \infty}f(x)=+\infty$$ thus we have $$\frac{\ln(x)}{x}\le \frac{1}{e}$$ for $x>0$
Answer: Let $f(x)=\ln x -\frac{x}e$.
What you wish to prove is equivalent to $f(x)\leq 0$ for all $x<0$.
Notice that $f$ is continuous and $\lim_{x\to0^+}f(x)= \lim_{x\to+\infty}f(x)=-\infty$, so $f$ must attain a maximum on $(0,+\infty)$. (Why? Can you show this?)
Since $f$ is differentiable, the maximum must be a solution to $f'(x)=0$, that is, a solution to $\frac1x-$$\frac1e=0$.
It's easy to see that the only solution is $x=e$.
It follows that $f(e)=0$ is the maximum, which concludes the proof. $\square$
Answer: For $x=e$ we have obtain equality. If we take $x\neq e$, for $x>e$(similarly for $x<e$, it can be shown) by MVT there exists $x_0 \in (x,e)$ such that
\begin{align*}
\frac{\ln e-\ln x}{e-x}&=\frac{1}{x_0}\\
\end{align*}
Hence we have
\begin{align*}
\frac{1-\ln x}{e-x}&=\frac{1}{x_0}\\
& > \frac{1}{e}\\
\end{align*}
and
$$1-\frac{e-x}{e}>\ln x$$
namely $$\frac{1}{e}>\frac{\ln x}{x}.$$
Answer: Consider $f(x)=\frac{\ln x}{x}$ with
$$
f'(x)=\frac{1-\ln x}{x^2}
$$
so that $f$ has a maximum at $x=e$; since $f(e)=1/e$, we get the claim.
Answer: Let $f(x) = \frac {ln (x)} { x}.$
$f'(x) = \frac{1}{x^2}-\frac {ln (x)}{x^2}$
$=\frac {1}{x^2}  (1-ln (x)) $
For $0 <x <e $,
$f'(x) >0$. This means that
$f (e)> f (x)$
For $x>e $,
$f'(x)<0$. This means that
$f (x) < f(e)$
For $x=e $, both sidess of the given equation are equal, hence the equality sign.
Since $f (e) = \frac {1}{e}$,
For all $x>0$,
$ \frac {ln(x) }{x } \leq  \frac {1}{e} $
Answer: $$
\frac{ln(x)}{x} \leq \frac{1}{e} \iff x^e \le e^x. e^x \in C(\mathbb R), x^e \in C(\mathbb R).
$$
$e^x \gt x^e, x \in [0,e)$ and $(e,+\infty)$ because both of them are continious and have only one point of intersaction (e), after that point $e^x \gt x^e$ as before, so $\frac{ln(x)}{x} \leq \frac{1}{e}$ is proofed.
Comment: What a joke ?? so if two continuous functions have one common point then such inequality holds?
Comment: not really, we have two functions, both of them are continuous. They have one point of intersection and after this point and before this point one is greater then another, so that such inequality holds.


Selecionar um select pelo valor digitado no input

Question: Bom, vamos lá, acredito que minha duvida seja simples mas não consigo desenrolar.

Código de Cliente:

<input type="text" id="codigocliente" />

lista
<select name="lista" id="lista" disabled="disabled">
  <option>Digite seu CPF</option>
  <option value="b3cdb2_353be7884bbf44488145b33338c03e52~mv2">12345678</option>
  <option value="b3cdb2_0bb5060e934b4896a8d78974355254d8~mv2">00000000</option>

</select>

<button type="button" class="button" onclick="window.open('https://static.wixstatic.com/media/' + document.getElementById('lista').value + '.jpg')" >Acessar</button>

Tenho esse scrypt, gostaria que o select selecionasse automaticamente o valor pelo valor digitado no input. Tipo, se no input o cliente digitar o valor 00000000, o selected mude automaticamente para esse valor, caso não exista, exibir um alerta dizendo que o valor não existe.
Deixei o selected desabilitado porque não quero exibir a lista de valores, só quero que o cliente digite no input e que o selected selecione o valor se ele existir ou mande uma mensagem dizendo que o valor não existe.
Assim que o valor do selected é selecionado, tem um botão ao qual redireciona ele para uma imagem ou arquivo especifico.
Comment: Pesquise sobre a função each() do JQuery, isso pode te ajudar.
Comment: [oninput](https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/oninput)
Answer: A solução é simples, insira o código abaixo em seu JavaScript, mas não se esqueça de colocar as referências do JQuery no header do seu código.
$(function(){
    var existeCpf = false;

    $('#id_do_input').keyup(function(){
        verificaCpf($(this).val());
    });

    function verificaCpf(_valor){
        $('#lista').each(function(){
            if($(this).val() == _valor){
                $(this).val(_valor);
                existeCpf = true;
            }
        });
    }
});

Basicamente o que eu fiz foi rodar o seu combobox e verifiquei se há algum valor igual o que foi digitado, se possui, ele irá selecionar e alterar a variável existeCpf para true, desta maneira você pode dar um alerta ao usuário.
Observações: Antes de colar este código, altere os values de seu combobox para os valores reais dos CPFs.
Answer: Bem vindo ! podemos fazer usando js observe:

$('#input').keyup(function(){

  var input = document.getElementById("input").value; //pega o valor digitado.

  if (input == '000' || input == '111' || input == '222') { //verifica se é o valor de sua preferencia. se for seleciona.

     //seleciona o elemento de acordo com o text do select
    $("#lista option:contains('"+input+"')").attr('selected', 'selected');
  }
  //coloco o length para pegar uma quatidade minimade caracteres para não mandar o alert direto
  if(input.length == 3 && input != '000' && input != '111' && input != '222'){
    alert("valor não existente. tente novamente!");
  }

});

<input type="text" id="input"></input>

<select name="lista" id="lista" class="form-control">
<option value="" selected>Selecione</option>
    <option value="888888">000</option>
    <option value="999999">111</option>
    <option value="777777">222</option>
  </select>
Comment: Boa tarde amigo, ficou perfeito esse código, só tem um pequeno problema, ele pesquisa o resultado no valor do select, sendo que precisaria buscar o nome dele, tipo. 000 . nesse exemplo, ele deveria buscar pelo 000 e não pelo 888888. como faço essa alteração?
Comment: Corrigido ! alterei a linha que seleciona o elemento pelo `value`. agora ele seleciona pelo `text` do `select`
Comment: Ficou perfeito agora. Muito obrigado !!!
Comment: Que bom ! De uma olha aqui [Como aceitar uma resposta](https://pt.meta.stackoverflow.com/questions/1078/como-e-por-que-aceitar-uma-resposta)


Let $K=\Bbb Q (e^{\frac{2 \pi i}{7}})$ and $\alpha \in K - \Bbb Q$. Then show that, $\Bbb Q(\alpha)=K$

Question:
Let $K=\Bbb Q (e^{\frac{2 \pi i}{7}})$ and $\alpha \in K - \Bbb Q$. Then show that, $\Bbb Q(\alpha)=K$ .

My attempt:
I have computed the minimal polynomial of$e^{\frac{2 \pi i}{7}}$ over $\Bbb Q$ to be $x^6+x^5+x^4+x^3+x^2+x+1 $ and thus, $[K:\Bbb Q]=6$
Since, $\alpha \in K - \Bbb Q$ , it follows that, $\Bbb Q(\alpha)$ is a subfield of $K$ containing $\Bbb Q$, moreover, $[\Bbb Q(\alpha):\Bbb Q] | [K:\Bbb Q] \implies [\Bbb Q(\alpha):\Bbb Q] =$1 or 2 or 3 or 6 .Since, $\alpha \notin \Bbb Q$, $[\Bbb Q(\alpha):\Bbb Q] \ne 1$ .
Since, for $\beta = e^{\frac{2 \pi i}{7}}$, $\{1,\beta,\beta^2,\beta^3 ,\beta^4,\beta^5\}$ is a basis of $K$ over $\Bbb Q$. then, $\exists a_j \in \Bbb Q , 0\le j \le 5$ with at least one of $a_j \ne 0 $ for $j \ge 1$ so that, $\alpha=a_0 +a_1 \beta+\dots+a_5 \beta^5$ .
How to proceed with then proof. Thanks in advance for help!
Note that this question is also present in here, here etc. but they use galois theory, but I only know Field theory and am also trying to solve the question using only that.
Comment: Let $\alpha=\beta+\beta^{-1}$. Then ${\bf Q}(\alpha)$ has degree 3. There are also examples with degree 2.
Comment: @GerryMyerson so is my question wrong? Anyway would you considering giving an answer.
Comment: OK, I've given an answer – does it work for you?
Comment: Are you still here, Coherent?
Comment: @GerryMyerson In the linked questions, it's proved that there is no intermediate field between $Q$ and $Q(e^{\frac{2 \pi i}{7}})$ other than those two itself, so I am also waiting for a few other answers. If I find you answer helpful, I'll definitely accept it, you don't need to worry about it.I'm not a new member to the site.
Comment: I don't know what more you want answered. You've asked to show that ${\bf Q}(\alpha)$ is $K$, and I've shown that ${\bf Q}(\alpha)$ doesn't have to be $K$. What else are you hoping to see in an answer?
Answer: Let $\beta=e^{2\pi i/7}$, let $K={\bf Q}(\beta)$, let $\alpha=\beta+\beta^{-1}$. Then $$\alpha^3=\beta^3+3\beta+3\beta^{-1}+\beta^{-3}=\beta^3+3\beta+3\beta^6+\beta^4$$ and $$\alpha^2=\beta^2+2+\beta^{-2}=\beta^2+2+\beta^5$$ [thanks to Robert Lewis for drawing my attention to a typo here, which I have corrected] so $$\alpha^3+\alpha^2-2\alpha-1=1+\beta+\beta^2+\beta^3+\beta^4+\beta^5+\beta^6=0$$ It's easily seen that $x^3+x^2-2x-1$ is irreducible over the rationals, so it is the minimal polynomial for $\alpha$, so ${\bf Q}(\alpha)$ is a proper subfield of $K$, of degree 3.
Similarly, one can show that $\gamma=\beta+\beta^2+\beta^4$ is of degree two over the rationals.
Comment: If $\alpha = \beta + \beta^{-1}$, does not $\alpha^2 = \beta^2 + \beta^{-1} + 2$? Where does $\alpha^2 = \beta^2 + 2\beta^{-1} + 2$ come from?


Can someone explain the logic of recursion in this pattern printing method?

Question: I'm trying to piece together the logic in this example. This is the normal code. FYI, I had a university tutor help me with this example but he's still trying to figure out how to explain it to me. The code is also done, this is just for my own knowledge of recursion.
public class Practice {

    public static void printTriangle(int n) {

        if (n < 1) {
            return;

        }
        else {

        printTriangle(n - 1);
        printStars(n);
        System.out.println();
        }
    }
    public static void printStars(int n) {
        if (n > 0) {
        System.out.print("*");
        printStars(n-1);
        }
    }
    public static void main(String[] args) {
        printTriangle(5);
    }
}
 Output
*
**
***
****
*****

This is the test code with markers that I used to find out what is happening when. It's kind of an eyesore so if you think you can explain it without looking at this mess, by all means.
public class Practice {

    public static void printTriangle(int n) {

        if (n < 1) {
            System.out.println(n);

            return;

        }
        else {
        System.out.println("1");
        printTriangle(n - 1);
        System.out.println(n);
        printStars(n);
        System.out.println("A");
        }
    }
    public static void printStars(int n) {
        if (n > 0) {
        System.out.print(n);
        System.out.print("*");
        printStars(n-1);
        }
    }
    public static void main(String[] args) {
        printTriangle(5);
    }
}
1
1
1
1
1
0
1
1*A
2
2*1*A
3
3*2*1*A
4
4*3*2*1*A
5
5*4*3*2*1*A

I've figured it out up until the first star is printed. I printed the value of n after the printTriangle method decremented it to 0, then I printed the value of n right before the first star is printed and somehow, it's equal to 1. I'm just curious as to how the value of n is increasing. The value goes into the printStars method at 1 and also keeps increasing as it prints stars
Comment: First the call stack goes down to triangle(0) to the base case. Then it runs stars(1). The stack continues to unwrap, first stars(2) then stars(3).
Comment: So, let me get this straight. After triangle is decremented down to the base case (0 is the base case because of the if statement in the method?). the call stack basically invokes the printStars method from base case to the original parameter of 5? it starts with 0 but that does nothing so it increases from the base case until it hits the original parameter set in the main method?

I'm sorry if this explanation sounds like nonsense.
Comment: That's exactly what happens.
Answer: Well,
printTriangle(5) calls printTriangle(4)
printTriangle(4) calls printTriangle(3)
printTriangle(3) calls printTriangle(2)
printTriangle(2) calls printTriangle(1)
printTriangle(1) calls printTriangle(0)
printTriangle(0) does nothing, but returns to printTriangle(1)
printTriangle(1) procedes with calling printStars(1)
printStars(1) prints a star and calls printStars(0)
printStars(0) does nothing and returns to printStars(1)
printStars(1) has nothing more to do and returns to printTriangle(1)
printTriangle(1) prints a linebreak and returns to printTriangle(2)
printTriangle(2) procedes with calling printStars(2)
printStars(2) prints a star and calls printStars(1)
printStars(1) prints a star and calls printStars(0)
printStars(0) does nothing and returns to printStars(1)
printStars(1) has nothing more to do and returns to printStars(2)
printStars(2) has nothing more to do and returns to printTriangle(2)
printTriangle(2) prints a linebreak and returns to printTriangle(3)
...
Answer: I will hopefully answer your question by providing both a written and visual explanation:
Written:
First we start with printTriangle(5). Since n < 1 is false, we continue by doing printTriangle(4). This process continues until we reach printTriangle(0). Since printTriangle(0) will not output anything (since 0 < 1 is true), we start with printTriangle(1):
From printTriangle(1) we go to printStars(1). We can only print one star from here. After we do this, we print a newline. Next, we have printTriangle(2) which leads us into printStars(2). This gives 1 star, but leads into printStars(1) which gives us a second star and a newline. This process continues until we reach our 5 stars.
Visual Representation:

I hope this helped answer your question! Please let me know if you need further clarification or details :)
Comment: This helped enormously, and thank you for the drawing.