Math Genius: n-ary generalizations of De Morgan’s Laws

Original Source Link

$a)$ State the n-ary generalizations of De Morgan’s Laws.

$b)$ Pick one of these generalizations and prove it by induction.

What does this even mean… I know what de morgan’s laws are but I have never heard of the $n$-ary generalizations.

de Morgan’s Laws express the negation duality between bivariate operators $lor$ and $land$. $$lnot(p_1land p_2)=lnot p_1lorlnot p_2\lnot(p_1lor p_2)=lnot p_1landlnot p_2$$

The n-ary extension of these Laws states that this duality also holds for n-tuple series of these operators.
$$lnotbigwedge_{k=1}^n p_k=bigvee_{k=1}^n lnot p_k\lnotbigvee_{k=1}^n p_k=bigwedge_{k=1}^n lnot p_k$$

Where $displaystyle{smallbigwedge_{k=1}^n} p_k = p_1wedge p_2wedge p_3wedgecdotswedge p_n$ and such.

Now it clearly the expressions shall hold for $n=1$.$$bigwedge_{k=1}^1 p_k=p_1qquad,qquadbigvee_{k=1}^1p_k=p_1qquad,qquad lnot(p_1)=lnot p_1$$

Also the expressions hold for $n=2$ because the 2-ary expressions are deMorgan’s laws.

Now you must prove that if they hold for any positive natural number $n$, they shall hold for its successor, $n+1$.
$$forall ninBbb N^+~left(left(lnotbigwedge_{k=1}^n p_k=bigvee_{k=1}^n lnot p_kright)toleft(lnotbigwedge_{k=1}^{n+1} p_k=bigvee_{k=1}^{n+1} lnot p_kright)right)\forall ninBbb N^+~left(left(lnotbigvee_{k=1}^n p_k=bigwedge_{k=1}^n lnot p_kright)toleft(lnotbigvee_{k=1}^{n+1} p_k=bigwedge_{k=1}^{n+1} lnot p_kright)right)$$

Tagged : / / / /

Server Bug Fix: What to do if I don’t understand the related work?

Original Source Link

I am writing a master’s thesis in Computer Science. It’s the first document I write, so not much experience.

My supervisor told me to include some previous/related work on the topic I am writing about. In short, it is about computing influence in social networks. I have found about 10 papers which I think are the most relevant ones.

The problem is that, while the topic and goal are the same as mine, the math/algorithms they apply are often way different than mine, and advanced enough that it would take a lot of work to truly understand them. So in other words, I want to somehow argue why my model makes sense and not others, but at the same time my work is not directly based on others.

The question is, can I write about it even though I don’t understand it? How well am I supposed to know the previous work I am writing about? Is it enough to have some intuition?

Sorry if this is obvious, but my university do not teach us how to write (I guess one point of having a Master’s thesis is to learn these things).

The thing that strikes me most about your question is “the topic and goal are the same as mine”. If this is the case, then those papers are intimately related to yours, and you will want to understand them for your own good. Granted you might not have the time – it is a Masters thesis after all. However, you’ll still want to compare and contrast their results against yours. After all, a big question to answer is “is my method better than theirs?” and you cannot answer that question without knowing how the methods stack up.

You don’t have to fully understand another work to write about it, but you might not be able to go into much detail: for example “Alice and Bob (2019) have also studied this problem using [method], but they ran into [issue] which we do not have” is perfectly fine. Nonetheless, with ten intimately related papers I think you will want to discuss this with your supervisor. That’s a lot of related work, and your professor might already be aware of some/most of them. He might give you direction on which papers to write about, which to read in more detail, and so on.

One of the skills that you have to learn during your masters is reading papers and previous work done in this particular area. So I suggest you put extra effort to understand them. This will benefit you a lot and will definitely boost the quality of your master’s thesis.

Also, learning about these previous papers might give you an idea to improve them and build upon them, and then you have your own paper published! This is how it actually goes in the research world. GoodLuck!

Can you perhaps mention the other research without endorsing it?

Previous work on the subject of frabishes was published by Smith and Jones [2012]. They claim to evaluate all frabishes using methods different than the methods we are using here.

While the most common answer seems to be “well just study all of that thoroughly” I can totally see why this may not be feasible. Related work usually is not the main focus and one cannot spend 2 months just to understand the stuff other people did.

I’d argue that that is not necessary. The key is to understand what those papers did and to get a rough idea of how they did it in principle, but you absolutely do not need to understand their methods in detail. Doing this probably will cost you less than 30 minutes per paper, which seems to be a manageable amount of work.

I think you should raise this question with your supervisor. Think carefully first about what part of this literature you expect you could master well enough in the time you have. Ask about reducing the scope of your project in order to write a narrow good paper rather than a shoddy comprehensive one.

You did not mention your country but in some places (at least Europe, vastly speaking) the Masters thesis is the obligatory door out of your university.

This means that the contents are mostly irrelevant.

There are some philosophical discussions about how it should teach you something – the reality of the real world is that this is something you have to do, full stop. Bonus points if you learn something out of the exercise.

Going from there, you should be as serious as possible and have an idea of what is happening around your master’s thesis topic but this is pretty much that. Skim though the papers (introduction, conclusions and what is in the middle if it sound interesting), discuss that with your advisor and call it a day.

The question is, can I write about it even though I don’t understand it? How well am I supposed to know the previous work I am writing about? Is it enough to have some intuition?

Yes, somehow, yes. Your advisor will redirect you if you start to drift away, so as I mentioned – keep a close contact with him or her.

Sorry if this is obvious, but my university do not teach us how to write (I guess one point of having a Master’s thesis is to learn these things).

If they not teach you how to write (I have not seen any who do – probably the best ones have something), they will not expect you to come out with something spectacular.

One important note: this answer is not there to say that your school is not good, or that you are missing something by having a normal, standard thesis nobody will ever read. It is there to say “do not worry”. This is normal, expected and will have zero impact on your further life (if you are not planning to go into academics, at least)

Talk to you advisor about that. When I was doing my master’s thesis, my advisor (a really good advisor), gave me some papers to read, and she also showed me how to read them. She explained that I didn’t need to understand all the technical details of the methodology involved; the big picture was most important.

I think there’s two critical questions you really need to be able to answer in this setting.

First, is there some mathematical equivalence or relationship between some earlier paper’s methods and your own, even if hidden by a different expression in the algorithms used? This may require some amount of digging in and gaining understanding.

Second, how would you go about comparing results from what you’re doing to the results they got? Are you measuring the same thing? Can you run your design on the same problems as they ran theirs, to compare quality of result and, if relevant, computational performance?

Beyond those, I think it’s perfectly legitimate to say roughly “these other authors took approaches X, Y, and Z to the problem. We describe A, which is truly, fundamentally distinct from X, Y, and Z, and here’s how it stacks up”.

I think on any technical field building understanding is crucial, and what unfortunately is not taught sufficiently in technical universities/colleges is how to actually build it. However, I can give you two hints about learning that I have learnt over the years that will push you forward.

There are two good books that will help you to understand how to speed up understanding:

1) “On Intelligence” by Jef Hawkins, will is a good general presentation how your brain works. The central message is that new things are build on the things you already know. This also means that in order to really understand, you should not leave gaps.

2) “How to solve it” by George PĆ³lya presents guidelines how to learn to seolve problems you can not yet solve. The basic principle is to simplify the problem as much as you can, to the bone, so you eventually can solve it. Look for similar but easier problems as long as you become confident that you understand the problem and you can solve it, and then move forward.

Unfortunately, there is no possibility for shortcuts. Simplify, try, fail, try again.

Tagged : /

Math Genius: show that $h(k)=left lfloor{frac{k}{m}}right rfloor mod m$ is a bad hash function where $m$ is prime

Original Source Link

A “good” hash function should make use of all slots with equal frequency. In this case the ammount of slots is given with $m$.

Also keys which are similar should be distributed as broadly as possible.

Any ideas how to approach this excercise?

Hint. Take for instance $m = 5$ and consider the numbers $0, 1, ldots, 29$. Then you will have $10$ numbers in slot $0$, but only $5$ numbers in slots $1$, $2$, $3$, $4$. Thus taking $k bmod m$ would give a much better result.

Tagged : /

Math Genius: show that $h(k)=left lfloor{frac{k}{m}}right rfloor mod m$ is a bad hash function where $m$ is prime

Original Source Link

A “good” hash function should make use of all slots with equal frequency. In this case the ammount of slots is given with $m$.

Also keys which are similar should be distributed as broadly as possible.

Any ideas how to approach this excercise?

Hint. Take for instance $m = 5$ and consider the numbers $0, 1, ldots, 29$. Then you will have $10$ numbers in slot $0$, but only $5$ numbers in slots $1$, $2$, $3$, $4$. Thus taking $k bmod m$ would give a much better result.

Tagged : /

Math Genius: Difference between Shannon Entropy limit and Kolmogorov Complexity?

Original Source Link

I’ve read in numerous places that Shannon Entropy provides some kind of fundamental limit to the compressibility of messages (according to, for example, Shannon’s source coding theorem). I have also read about Kolmogorov complexity, which establishes a different kind of limit to compression by considering the shortest program that could output a given piece of text.

My question is: How are these related? They can’t both be limit of compression.

There have been previous questions on MSE which superficially resemble what I’m asking but have never been given an appropriate answer. I’m looking for:

  • A clear explanation of the different notions (if they exist) of compression potentially being discussed.

  • A clear explanation of what the different compression-limits are and why they differ. This should also mention something about why K. complexity is uncomputable whereas Shannon entropy is computable (I understand the proof of the uncomputability of K-complexity, I’m just saying it should be clear why there’s a difference).

Shannon Entropy is about compression of (long) words generated by biased die toss. And if dice entropy is $H$, we can’t (on average) compress results of $n$ tosses to less than $ncdot H$ bits.

Kolmogorov Complexity is about compression of arbitrary words. Of course, if word is generated by the same die, it’s average complexity will be $ncdot H + O(1)$.

However, if your data is not generated by biased die, then you may be able to achieve better compression than just recoding individual chars. For example, if you want to send $n$ first digits of $pi$, it’s quite easy to compress them to $log(n) + O(1)$ bits: if we know that we want to send first digits of $pi$, it’s enough to send number of digits we want to send (which will require $log(n)$ bits), and then we will be able to calculate necessary digits by ourselves.

About computability – I think good intuition will be that to compress something, we need to find some “patterns” (ways to distinguish our sequence from arbitrary random in the same alphabet) in object we want to compress. If we use, for example, arithmetic coding – we only use very simple pattern of noticing that different symbols have different probabilities. If we want to compress word for Kolmogorov’s decompessor, we are interested in any computable “patterns”, which is much larger and more complex set. And discovering arbitrary computable “pattern” turns out to be uncomputable.

Tagged : / / / /

Math Genius: Estimating Catalan numbers using Monte Carlo method

Original Source Link

This question regards the classical problem of estimating Catalan numbers by performing a random walk on a grid of $ntimes n$ squares. I will dectribe the problem for those who are not familiar with it, but you may also skip this section to the Monte Carlo code which is the reason I started this thread.

We start at the lower left corner of the grid with initial step to the right (marked by a right arrow). We may only take steps rightwards or upwards. We will only consider paths that end in the upper right corner and that stay below the main diagnoal, see figure below for some examples when the grid is $4times 4$, where the dashed line is the main diagonal.

enter image description here

The problem we would like to solve is to find out what the size of the set that contains all such paths (i.e. initial right steps in lower left corner, travel by only rightwards and upwards steps, do not cross the main diagonal and ends in upper right corner) is. Let us denote this set by $S_{n}$ and let us also denote the set that allows paths to cross the main diagonal by $T_{n}$. Then it clearly holds that $S_{n}subset T_{n}$. As prepatory work in solving this problem, let us compute the size of $T_{n}$, i.e. $vert T_{n}vert$. If we think about it in the right manner it will not be so hard to compute: we know that a random walk in $T_{n}$ must consist of $n$ right-steps and $n$ up-steps, thus $2n$ steps in total, one of which (the initial step) is fixed to a right step. Thus, if we imagine the $2n-1$ remaining steps as blanks to be filled in in different ways by either $n$ up-steps or $n-1$ right-steps we realize that this number of ways is given by the binomial coefficient

vert T_{n}vert = {2n-1choose n} = {2n-1choose n-1}.

Finally, the Monte Carlo estimator to the Catalan number $c_{n}=vert S_{n}vert$ can be formulated: let $X^{i}$ for $i=1,dots,N$ by i.i.d. be $p(x)=text{Unif}(T_{n})$, i.e. random walks in $T_{n}$ with uniform probabilites. Then

&vert S_{n}vert = sum_{xin T_{n}}mathbf{1}_{S_{n}}(x) = sum_{xin T_{n}}frac{1}{p(x)}mathbf{1}_{S_{n}}(x)p(x) = mathbf{E}(mathbf{1}_{S_{n}}(x)/p(x)) implies \[3mm]
&c_{n}^{N} = frac{1}{N}sum_{i=1}^{N}frac{1}{p(x)}mathbf{1}_{S_{n}}(X^{i}) = frac{vert T_{n}vert}{N}sum_{i=1}^{N}mathbf{1}_{S_{n}}(X^{i}).

Now, what I will do is simulate $N$ random walks in $T_{n}$ and then associate every one of those walks that also are in $S_{n}$ with the number $1$ (the other walks will be associated with $0$) and in the end aggregate all the $1$:s to get the sum in the above expression. Here is my code:

N = 10000;
n = 4;
S = 0;      % Number of paths that belong to Sn
for i = 1:N
    X = path(n);
    % If the i:th element of the cumulative sum of the path X is a number
    % that is < 0, then the path belongs to Sn
    P = cumsum(X);
    if ~any(P < 0)
        S = S + 1;

cn = 1/(n+1)*nchoosek(2*n,n);
Tn = nchoosek(2*n-1,n);

tau = 1/N*S*Tn;

disc = abs(cn-tau);

function output = path(n)
steps = 2*n;
dir = zeros(1,steps);

% -1 rep. upwards and 1 rep. rightwards
dir(1) = 1;     % Initial step
tot0 = 1;       % Total (current) number of 1:s in path
tot1 = 0;       % Total (current) number of negative 1:s in path
for i = 2:steps
    r = rand;
    if r < 0.5
        if tot0 < n
            dir(i) = 1;     % Step rightwards
            tot0 = tot0 + 1;
            dir(i) = -1;     % Step upwards
            tot1 = tot1 + 1;
        if tot1 < n        
            dir(i) = -1;     % Step upwards
            tot1 = tot1 + 1;
            dir(i) = 1;     % Step rightwards
            tot0 = tot0 + 1;
output = dir;

I am wondering why this code does not give a arbitrarily good estimate when I increase $N$, it seems like me estimation is always a factor $2$ of the Catalan number it tries to estimate. What I am doing wrong in my code? Or have I derived the Monte Carlo scheme in the worng way?

You have to generate a random anagram of the word UUUURRR (U=Up, R=Right), that is just a permutation of the letters. To do so, you can apply any of the methods described, for example, here.

Tagged : / / / /

Math Genius: Minimizing the distance between points in two sets

Original Source Link

Given two sets $A, Bsubset mathbb{N}^2$, each with finite cardinality, what’s the most efficient algorithm to compute $min_{uin A, vin B}d(u, v)$ where $d(u,v)$ is the (Euclidean) distance between $u$ and $v$ (may be considered as points or vectors). Also what’s the most efficient algorithm to determine $u$ and $v$ (not necessarily unique) such that $d(u,v)$ is minimized?

So minimizing $d(u,v)$ is pretty much the same as minimizing $[d(u,v)]^2$, which can be written using the distance formula. But I couldn’t think of anything better than a brute-force $O(|A||B|)$ solution (where $|A|$ denotes the cardinality of $A$) which tries every possible $uin A,vin B$.

Here’s an $O(n log n)$ algorithm that works for all possible sets $A$ and $B$.

Let $n = |A| + |B|$.

This question has been asked in other platforms (here or here), but none of them give satisfactory answers (…at least to me. I cannot verify that they work in the claimed time for all possible inputs. For example, using KD tree does not guarantee $O(n log n)$ unless the points are sufficiently random. The answer to second link is even more evil).

So, here’s a purely $O(n log n)$ algorithm to solve this! Good thing you asked this in a math forum, because despite being theoretically interesting, I wouldn’t want to implement it…

First, construct the voronoi diagram $V_A$ of all the points in $A$. For each point $b_j in B$, find the voronoi cell $v_i in V_A$ that contains the point — by the property of a voronoi diagram, we know that $a_i$ is the closest neighbor of $b_j$. Thus, by doing this for all points in $B$ and taking the minimum, we get the pair with minimum distance.

Of course, that’s assuming we are able to find the cell $v_i$ for each point $b_i$ quickly. To do it quickly, we use the sweep line algorithm: sweep all the points in the voronoi diagram $V_A$ and the points $B$. We store the current partition of the space using a binary tree so that whenever the sweep line encounters a point $b_i in B$, we are able to find the voronoi diagram containing $b_i$ in $O(log n)$. Whenever we encounter a point $a_i in A$, we update the tree from the structure of the voronoi diagram. This sweep line is rather analogous to the sweep line performed for the “find intersecting lines” algorithm.

Since construction of a voronoi diagram takes $O(n log n)$ time, the entire procedure is $O(n log n)$.

Tagged : / / / /

Math Genius: Proving Kirchhoff’s Theorem using techniques appreciated by a first year undergrad

Original Source Link

I would like to prove Kirchhoff’s theorem. Briefly, it states that cofactor of a certain matrix $M$ is equal to the number of spanning trees of the graph. $M$ is equal to the difference between the graph’s degree matrix (a diagonal matrix with vertex degrees on the diagonals) and its adjacency matrix (a $(0,1)$-matrix with $1$‘s at places corresponding to entries where the vertices are adjacent and $0$‘s otherwise).

It seems to be a very powerful theorem which generalizes Cayley formula. I tried proving it, but did not make much headway. I have never proved any theorem like this before, and I am unable to connect the notion of a determinant with that of “no of spanning trees”.

I looked over the proof of Wikipedia, unfortunately it contained terms like Cauchy Binet formula, which I have never encountered before. I am compelled to ask if there is a proof of Kirchoff’s theorem which can be understood by a first year undergraduate?

I am looking for multiple methods of proving them, ideally using nice insights.

Tagged : / /

Server Bug Fix: Are computer integers a finite group (under addition with overflow)?

Original Source Link

The integers and the integers modulo a prime are both groups under addition.

What about the computer representation of integers (e.g. int64)?

It’s closed under addition, since a sum that is too large wraps around to the negatives. It also inherits the other group properties from the integers (associativity, identity, inverse).

So int64 seems like a finite group, but am I missing anything?

If you just let overflows happen without doing anything about it, and in particular with 2’s complement representation (or unsigned), a computer’s $n$-bit integer representation becomes the integers modulo $2^n$. So yes, you’re entirely right: It is a finite group (and with multiplication becomes a finite ring).

(As a side note, working with and thinking about 2’s complement became a lot easier for me once I realized this. No one really told me during my education, so for ages I was stuck having to remember all the details in the algorithm for taking negatives, i.e. actually taking the 2’s complement. Now that I have the algebraic knowledge of what’s actually going on, I can just deduce the algorithm on the fly whenever I need it.)

It’s not entirely obvious to check explicitly that they satisfy, say, associativity when overflow is in the picture. It’s easier to set up the obvious bijection with the integers modulo $2^n$ and show that addition stays the same, and prove the group properties that way.

You’ve checked all the axioms, so you’re fine. The $n$-bit integers, whether they start at $0$ or $-2^{n-1}$, are isomorphic to the order-$2^n$ cyclic group.

The C Standard allows, but does not require, that implementations targeting two’s-complement platforms extend the language to process signed arithmetic in quiet wraparound function. According to the published Rationale, the authors of the Standard expected that commonplace implementations would only process signed and unsigned arithmetic differently when processing operations not associated with the abstract algebraic group/ring (e.g. division, relational operators, etc.). Since unsigned arithmetic behaves as an algebraic ring, that would suggest that they expected that signed arithmetic do so as well, at least with regard to the ring operators. Modern compilers, however, cannot be relied upon to generate code that behaves meaningfully when an overflow occurs when full optimizations are enabled. Versions of the gcc compiler targeting typical 32-bit platforms, for example, if given a function like:

unsigned mul_mod_65536(unsigned short x, unsigned short y)
{ return (x*y) & 0xFFFFu; }

will sometimes use the fact that they’re not required to behave meaningfully if x is above 2147483647/y to infer that functions will never receive input that would cause x to exceed that value. Compilers used to process signed arithmetic as an algebraic ring, but on “modern” compilers signed integer arithmetic isn’t closed under addition nor multiplication, and is thus not a group much less a ring.

One point to avoid tripping on:

#include <stdio.h>
#include <limits.h>

int main() {
  int x = INT_MIN;
  int y = -x;
  printf("%d, %dn", x, y);
  printf("%dn", x+y);

prints on my machine

-2147483648, -2147483648

In twos complement, there is one more negative number than there are positives. So you might worry that nothing happens when you try to negate INT_MIN. But, it all works out correctly! For the $k$-bit signed integers to be isomorphic to $mathbb{Z} / 2^k$ you must line them up correctly, e.g. for $k=3$:

0  1  2  3  4  5  6  7
0  1  2  3 -4 -3 -2 -1

For example the element “6” of $mathbb{Z} / 2^k$ is represented by -2 and “4” by -4. In particular it’s true that -(-4) = -4, because in this group, 4 is its own additive inverse. So the program above is correct (note: correct according to $mathbb{Z}/2^k$, not $mathbb{Z}$), because $-x = x$ and $x + x = 0$ mod $2^k$.

In general INT_MIN corresponds to $2^{k-1}$ and is its own additive inverse:

0  1 ... 2^(k-1)-1  2^(k-1) ...  2^k - 1
0  1 ... INT_MAX    INT_MIN ...     -1

Tagged : / / /

Code Bug Fix: I want to make categories the rating of the basis of the range

Original Source Link

I want to make categories the rating of the basis of the range of rating given by the user.and also I want to visualise that data.

Categories and generate the visualization of how many hotels have the rating in
the range of 0 to 1, 1 to 2, 2 to 3, 3 to 4 and 4 to 5. All will follow the [ …. )
the format which means the lower limit includes and upper limit value is excluded
while generating the range.

Can any body help me..???

enter image description here

I am assuming ratings in the range [0, 10]. The following code plots a histogram of the ratings distribution.

import math
import pandas as pd
import matplotlib.pyplot as plt

# read the rating.csv file into a pandas data frame
df = pd.read_csv('rating.csv')

# rounding the feedbacks and adding them to the data frame
df['Feedback_rounded'] = df['Feedback'].apply(lambda x : math.floor(x))

# calculate the number of feedbacks for each bin
counts_per_rating = df.groupby('Feedback_rounded')['no_of_feedback'].sum()

# create a list of tuples of the form (bin, count)
ratings_with_counts = list(zip(counts_per_rating.index.tolist(),

# append tuples for bins with 0 feedbacks
for rating in np.arange(0, 10):
    if rating not in [tup[0] for tup in ratings_with_counts]:
        ratings_with_counts.append((rating, 0))

# sort the list based on the bins
ratings_with_counts_sorted = sorted(ratings_with_counts, key=lambda tup: tup[0])        

# a list of the rating bins
ratings = [tup[0] for tup in ratings_with_counts_sorted]

# a list of the corresponding counts
counts = [tup[1] for tup in ratings_with_counts_sorted]

# plot the ratings histogram, counts);
plt.title('Ratings Histogram');
plt.xticks(ratings, np.arange(0, 10));

The above code, using your sample data, yields this graph.

Let me know if this helps.

PS: It would have been helpful had you provided the sample data as text instead of as an image.

print("                Category1               ")
print("Total Hotel found in Category-1 is",count_cate_1)

print("                Category2               ")
print("Total Hotel found in Category-2 is",count_cate_2)

print("                Category3               ")
print("Total Hotel found in Category-3 is",count_cate_3)

print("                Category4               ")
print("Total Hotel found in Category-4 is",count_cate_4)

print("                Category5               ")
print("Total Hotel found in Category-5 is",count_cate_5)
print("***************************************************")'Hotel_id',y='Feedback',rot=70,title="Hotel having rating between 1 and 2")'Hotel_id',y='Feedback',rot=70,title="Hotel having rating between 2 and 3")'Hotel_id',y='Feedback',rot=70,title="Hotel having rating between 3 and 4")'Hotel_id',y='Feedback',rot=70,title="Hotel having rating between 4 and 5")


dafa=pd.DataFrame(category,columns=['Categorys','Count'])'Categorys',y='Count',rot=70,title="Total Hotel Rating")

Tagged : / / / /