# A Better Approach to DFA Minimization

DFA minimization is often described as follows:

1. First eliminate any unreachable states (easy).
2. Then create a table of all possible pairs of states $$(p, q)$$, initially unmarked. (E.g. a two-dimensional array of booleans, initially set to false.) We mark pairs $$(p, q)$$ as and when we discover that $$p$$ and $$q$$ cannot be equivalent.
1. Start by marking all pairs $$(p, q)$$ where $$p \in F$$ and $$q \not\in F$$, or vice versa.
2. Look for unmarked pairs $$(p, q)$$ such that for some $$u \in \Sigma$$, the pair $$(δ(p, u), δ(q, u))$$ is marked. Then mark $$(p, q)$$.
3. Repeat step 2.2 until no such unmarked pairs remain. If $$(p, q)$$ is still unmarked, can collapse $$p$$ and $$q$$ to a single state.

Source: Mary Cryan, Informatics 2A: Processing Formal and Natural Languages, Lecture 5, 2018.

Based on my very limited research, aforementioned algorithm seems to be the most common way of teaching undergrads how to minimise a given DFA, but I believe that it suffers from reasons soon listed below, and I will instead propose a better way of executing the same algorithm that does not (make the student) suffer from the same problems.

# Marketing is a State of Mind, not an Afterthought

Marketing, due to its historical luggage, is gravely misunderstood by many people as something to be done to increase the sales of a product (i.e. promoting), whereas it should instead be understood as a strategical process, which is never done but continuing as long as the producer exists. Whether you are an entrepreneur, a solo free-software developer, or an indie game-dev, as long as you are a producer, you -presumably- must be working for your products to be used/consumed/bought by people (unless -of course- you are an artist, then you might want to abstain from the consideration of your audience). It is clear then, that marketing is crucial simply if you do not want your work to get wasted. You do need marketing.

Philip Kotler

If this post manages to wet your appetite, you should absolutely check Marketing: An Introduction by Gary Armstrong, Philip Kotler et al. It is a 640 pages-long book, and as it indicates, there is no way for anyone to even briefly summarise -yet alone cover– marketing thoroughly. What you are reading is (a) written by a student, and (b) is a tiny fraction of a tiny fraction: think of it as a stimulus.

I’ll mention 3 different (simplified) eras each industry goes (or already went) through, so that you can understand where most of the misconceptions about marketing came from, and then I will explain how the modern approach to marketing makes more sense in today’s context – assuming that the industry you are working in is already matured; this will make more sense once you read the post.

# 3 Eras of Each Industry

What I call here “eras of industries” is in fact called marketing orientation in the jargon, and is the way you approach your business; marketing is “a corporate state of mind” but I think it should not be limited to corporations necessarily.

## Product & Production Oriented Era

The initial era of a new-born industry is the product & production oriented era, and it remains so as long as the industry is under-saturated, that is, the industry is nearly non-competitive in the sense that it is possible for a producer to earn marketshare without stepping on others’ toes.

Tesla Model S

Tesla Inc. would be a great example for product & production oriented company: (a) the electric car industry is currently nowhere nearly as competitive as its gasoline-powered precedent; (b) many potential (in the long term) customers of Tesla do not currently own an electric car; (c) the number of products (electric cars) and side-products (electric stations, electric car repair shops, etc.) are much lower than their potential.

It is no doubt why Musk is expanding Tesla’s product line by introducing Tesla Semi -an electric powered truck-, and by re-introducing Tesla Roadster. Is Musk’s obsession with Tesla Gigafactory 1 then any more surprising? Musk’s orientation is clear: products and production.

Prototype of Tesla Semi

Being product and production oriented is the best mindset you can possibly have under given similar circumstances. Musk -and people around him- know that wider their product line is, better the chances are that they are addressing a currently unmet need of their potential customers. Why else then would a luxurious electric car company introduce an electric truck into the market? Being first in the market is invaluable, so long as your customers can afford and also that you can deliver. Musk is surely aware of that as well, and that is certainly why Gigafactory 1 is being built: (a) to lower the unit production costs of its electric cars, (b) to be able to meet the enormous demand by increasing the production rate.

Now how much advertisement Tesla needs do you think? Each event of Tesla, and frankly any significant development in the electric car industry, is covered by the press and ends up in the news feeds of many people. If a person considers buying an electric car, his/her options are much more limited in contrast with gasoline cars, and Tesla seem to have a monopoly on the high-end of the market, and a few other niches such as trucks and roadsters: even a simple Google search would redirect potential customers to Tesla’s website. Tesla’s marketing strategy does not consist of “marketing” its products, but focusing on the products themselves, and their production.

## Sales Oriented Era

Sales oriented era starts when significant increases in competition become threatening to producers. A characteristic of this era is that a consumer in the given industry has now more alternatives to consider and choose amongst. In the classic purchase funnel metaphor with AIDA (Awareness, Interest, Desire, Action) model, this the era where companies aim to increase the awareness of their own products, evoke interest in them, and finally convince customers to buy (action) their product by catching their desire.

To link with the product & production oriented era, it is clear that to be able evoke interest in a product, it must be able to address a need of its potential owner/beneficiary, hence you expand your product line first to accommodate different needs. There is no point in trying to catch the desire of potential customers either, if they cannot afford paying for the product, or if you cannot deliver your orders, hence you develop your production first to reduce the unit costs and increase the output rate.

I don’t have much to add about this era, and I don’t think there is any need: sales orientation is what many people have in their minds when they think of marketing, although you should realise that sales orientation is just one way of marketing. Advertising your product is not marketing, it is part of it.

## Marketing Oriented Era

The final era where advertising your product after it’s already been produced won’t do. This is the era where the market for the given industry is almost fully saturated (or even over-saturated), where the competition is really high. This is one way to think of it but then we would have a marketing myopia, that is, a denial of the human element in the market. We must be able to look a bit further, and shift our focus from production, products, and the sale of products, to the customer: to put simply, marketing orientation is customer orientation. The ultimate aim of each company is to make money, and each producer is to serve its customers/users of his/her products. Each of them, then, must realise that the products they produce is merely means in increasing the customer satisfaction (which, in turn, will increase your profits if that is your aim).

“iOS users spend $500 more per month than those on Android” Apple is an exemplary company when it comes to marketing, because they know how to create and maintain profitable relationships with its customers. According to the graph from Business Insider (on the right), “iOS users spend$500 more per month than those on Android”. Combined with the unbelievably high brand loyalty Apple has, it is clear that Apple is in a more desirable position in smartphone industry than its competitors, because it has a greater customer equity.

Very surprisingly, you might have realised now how little consideration was given to the future in the previous eras, whilst how far-reaching the current understanding is. In the previous eras your relationship with the customer would be very much transaction-oriented, that is, you produce and the customer buys. This approach can work fine, and indeed can be the only working model given the circumstances, but it is less than optimal in the marketing era. The increase in competition pushes companies to take the full advantage of its customers (i.e. milk them), and to persuade them to stay loyal to the brand, which is a façade that you want your customers to think of you. For instance, it might be more profitable for Dropbox to spend $15 of its marketing budget on an existing user to convince him/her to upgrade to a more expensive plan, than to spend$100 to acquire a new user. And if Dropbox loses a paid user, it will also loose ($8.25 / month) * (5 years) =$495 at least.

To summarize the marketing oriented approach:

• You should regard your products as a means of creating and maintaining profitable relationships with your customers.
• If its unprofitable, you should not be afraid to get rid of the customer.
• This point also indicates that marketing is designing products for a profitable target audience, not an an afterthought on how to advertise & sell them once being produced.
• Increase in customer satisfaction will lead to an increase in customer profitability (presumably), and also in brand loyalty.
• Increase in customer profitability will also increase the customer lifetime value.
• Increase in brand loyalty and customer lifetime value will increase the customer equity.
• Sales indicates how well you did in the past, customer equity indicates how well you will do in the future.
• It is easier to keep your current customers to acquire new ones in a competitive market.
• Therefore you should take full advantage of each of your customers (i.e. increase their CLTVs).
• Marketing orientation is customer orientation.

# Conclusion

As you have just read, contrary to common understanding, marketing is much more than advertisement & sales of products, and it depends on the current state of the industry, as well as a number of other factors to make the right decisions. I like to think of marketing as simply managing the company, that is, it is not a concern of a department or a sub-division, but the most important duty of each manager who is more than an executive. Out of laziness, I used the term “company” more frequently than producer, but surely any producer/creator too can see the merit in being user/consumer oriented, whether the competition in the market is driven by money, or fame or altruism. =)

# Dropping root Privileges Permanently on Linux in C

If you would like to drop root privileges permanently on Linux using C:

#define _GNU_SOURCE  // for secure_getenv()

int drop_root_privileges(void) {  // returns 0 on success and -1 on failure
gid_t gid;
uid_t uid;

// no need to "drop" the privileges that you don't have in the first place!
if (getuid() != 0) {
return 0;
}

// when your program is invoked with sudo, getuid() will return 0 and you
// won't be able to drop your privileges
if ((uid = getuid()) == 0) {
const char *sudo_uid = secure_getenv("SUDO_UID");
if (sudo_uid == NULL) {
printf("environment variable SUDO_UID not found\n");
return -1;
}
errno = 0;
uid = (uid_t) strtoll(sudo_uid, NULL, 10);
if (errno != 0) {
perror("under-/over-flow in converting SUDO_UID to integer");
return -1;
}
}

// again, in case your program is invoked using sudo
if ((gid = getgid()) == 0) {
const char *sudo_gid = secure_getenv("SUDO_GID");
if (sudo_gid == NULL) {
printf("environment variable SUDO_GID not found\n");
return -1;
}
errno = 0;
gid = (gid_t) strtoll(sudo_gid, NULL, 10);
if (errno != 0) {
perror("under-/over-flow in converting SUDO_GID to integer");
return -1;
}
}

if (setgid(gid) != 0) {
perror("setgid");
return -1;
}
if (setuid(uid) != 0) {
perror("setgid");
return -1;
}

// change your directory to somewhere else, just in case if you are in a
// root-owned one (e.g. /root)
if (chdir("/") != 0) {
perror("chdir");
return -1;
}

// check if we successfully dropped the root privileges
if (setuid(0) == 0 || seteuid(0) == 0) {
printf("could not drop root privileges!\n");
return -1;
}

return 0;
}


I hope this would save you some time so that you won’t spend an hour like me, trying to find a proper solution!

The code is provided “as is”, without warranty of any kind, express or implied.

## Sources

c – Dropping root privileges – Stack Overflow

man sudo (Sudo Manual)

# Closed-Form Expression to Calculate n-th Fibonacci Number

A more interesting way to find nth Fibonacci number.

Fibonacci sequence is a prime example in teaching recursion to newcomers, and a great opportunity to brag if your language supports Tail Call Optimization, but it often goes unnoticed that there is a closed-form expression which lets us find the nth Fibonacci number with great ease and in much faster way. This article will present the expression, and explain -step by step- its derivation using high-school mathematics.

# Commandments for University/College Applicants

After messing up my university applications, I have decided to create a list for fellow UWC Dilijan students to get rid of the glooming feeling of regret, but I guess the list might be equally useful for other UWCers, as well as IB students and others who are planning to study abroad.

# Western Media Bias: Analysis of an Article in The Economist

I have happened to buy “The Economist” for my two-days-long layover in İstanbul to kill some spare time, and read an article titled The prince’s time machine, which is about the “shift from the Islamic to the Gregorian calendar” in Saudi Arabia. The article was so full of bias that I couldn’t resist myself but to write a response.

# Some Advice to Those Who Will Serve Time in a UWC

or Things I Wish I Had Known When I Started UWC Dilijan

It has been one and a half year since I have started studying in Dilijan and it has been only one semester that I can confidently say that I have been mentally and emotionally stable. There are many things that you realize in your third term when everything is kind of done and that makes you realize what have you done wrong in the past, or what you could have done better. Take this prose as a honest reflection and a sincere advice to those who will serve time in a UWC.

Let us not waste our time in idle discourse! (Pause. Vehemently.) Let us do something, while we have the chance! It is not every day that we are needed. Not indeed that we personally are needed. Others would meet the case equally well, if not better. To all mankind they were addressed, those cries for help still ringing in our ears! But at this place, at this moment of time, all mankind is us, whether we like it or not. Let us make the most of it, before it is too late! Let us represent worthily for once the foul brood to which a cruel fate consigned us! What do you say? (Estragon says nothing.) It is true that when with folded arms we weigh the pros and cons we are no less a credit to our species. The tiger bounds to the help of his congeners without the least reflection, or else he slinks away into the depths of the thickets. But that is not the question. What are we doing here, that is the question. And we are blessed in this, that we happen to know the answer. Yes, in this immense confusion one thing alone is clear. We are waiting for Godot to come—

# Using LLVM’s IR for semi-compiled packages

As many other things that comes into my mind between 1-3 AM, this is also a bit blurry.

I was thinking about the possibility of utilizing LLVM’s Intermediate Representation to pre-compile packages into an intermediate language which is high level enough, and yet with its dense bitcode representation, can easily shorten compile times by reducing the time that is spent on parsing, analyzing and intermediate code generation.

Distros such as Gentoo can benefit from to a great extent I believe, but as I don’t know how their system works, I can not elaborate about the details. Also any open source project, that doesn’t provide pre-built packages, can at least use this method to shorten build times of their users.

I’ll think about it, to come up with an idea.