17 June, 2012

Money

Money is media of possessions.

A media is a channel of transfer/transportation.  

Air is media of sound. Road is media of people. Blood is media of nutrients and oxygen. Vacuum is media of energy. A wire is media of electricity.

A media is means of transportation. A thing through which another thing can change position.

If you want to go from point A on surface of a planet to another point B on the surface of same planet then you have to go through a media. It could be the surface itself, or air, or space or even underground. All of these are media.

TV, internet, radio, sms, phone calls are all media of information.

If you want to exchange possessions with another human being, such as give some hours of labour and get a cell phone in return, then you can conveniently do so by using money.

Note that you can do exchange without money. This is called barter system. In barter system you exchange possessions directly. In money system you first convert your possessions into money, then give the money to the other person, and that person give you the thing.

In every money based transactions, possessions are converted into money twice.

Anything can be made into money, as long as its scarce. Another requirement is durability. A piece of wood cannot be used as money for long period of time because it may get burned, termite-eaten, or just plain damaged.

Money is not valuable, possessions are. Money is supposed to be kept for minimum period of time, and quickly changed into a possession. Keeping money for long period of time jam the economy.

Money is like blood. Blood itself is not valuable. Its the nutrients and oxygen that it transports which is of value. Blood without nutrients and oxygen is useless.


Blood is supposed to be kept running. Nutrients are constantly poured into blood by stomach and lungs and transported to all parts of body. If blood is holded in one part of body for a long period of time then the other parts of body suffer. Same way if money is locked in purses or safes, then nutrients, that is possessions stop being transferred and the whole system suffers. This is why markup is haram.

When a party takes markup, it holds money. Assuming 10% markup rate per period (period can be year, month whatever), it takes 110 units of money per 100 unit it gives, next time it takes 121 units of money and so on. Its like in every cycle, more and more blood is supplied to a certain organ. The other parts of body suffers, as their supply of blood keep on reducing. The part that gets more blood also get damaged after an initial boom.

Markup is more dangerous than looting and levying unfair taxes. Its because none of these have compounding effect that markup has. A very cruel govt can levy a draconian tax rate of 70% but the tax rate remains constant, no compounding. Compounding is when the rate itself increase. Note that even at a fixed markup rate of 10%, the rate of income that goes to banks can increase. For example at an income of Rs. 100, the markup is Rs. 10, next year it becomes Rs. 11, next year to that Rs. 12.1. The percentage of income that goes to banks keep on increasing.

One can say that the percentage of income that goes to banks would not increase if markup is paid the first year. Indeed markup can be paid every year, keeping the percentage of income going to banks constant, if the world is perfect. World is not perfect, problems do come, businesses do fail, natural disasters do come, prices do fluctuate. In most cases, percentage of income going in markup increase, not decrease.

One can say that in an expanding economy, production on average increases, therefore the burden of markup would reduce, not increase, in future. The expansion of economy is an anomaly. The expansion is due to increase in extraction of fossil fuels. In a finite planet in a finite universe, expansion cannot continue indefinitely. Rules are supposed to cover normal cases, a rule is not supposed to cover anomalies.

Expansion for a limited period of time may be universal, but loans are given to individuals. There is no guarantee that in an expanding economy, all of the business would expand, some would contract, some would vanish.

The expansion not comes free. More and more human effort (even if its just mental effort) is needed every year. Its the working labor that is supposed to get the benefit of expansion, not a banker.

Another cost of expansion is pollution. More you produce more you hurt the environment. At sometime you have to pay for the damage of environment, in terms of diseases for example. These costs are usually ignored.

One can say that we can estimate cost of pollution and compensate that by reducing markup rate. One can say that cost of disasters human or natural can be compensated through insurance. One can say that failure of individual business in an expanding economy can be covered by bankruptcy laws (by which lender cannot have money back if business fails). Even with all of these safeguards markup is inherently bad, not just bad but dangerous to economy. Let me explain.

So you have insurance, bankruptcy laws and very low markup rate. Still there are things you don't cover. Such as fall in profits due to increase in production costs or decrease in produced goods prices or both. There is no insurance against these. If you put insurance against these then you kill efficiency at other places by killing competition. Even if a company is still in profit, just that profit percentage decreases, the percentage that goes in markup increases. The reduction in profit may expand till you are not able to pay all of your markup, that is when the compounding effect kicks in. The markup which goes unpaid adds in the base loan and next time you have to pay even more markup, reducing your chance of taking your troubled company out of trouble.

Another problem is that, money becomes a comodity. Money itself is not supposed to become a commodity. Its like buying air before talking. Money is supposed to flow free. Markup is as dangerous to economy as private ownership of roads to transportation. If roads are privately owned, certain critical roads can be blocked by their private owners altogether irrespective of pricing.


Who Owns Your Country?

 Those whose crimes go unpunished.

Examples

    In a military dictatorship, its the military. Generals are effectively forgiven huge crimes, such as surrenders and other crimes such as corruption.

    In fuedalism, its land owners.

    In capitalism, its bankers.

Ideal System

    When nobody gets unpunished for their crimes, then its the people who owns the country. This is easily observed by equality. Equality in opportunities.

Safety Factor

What is Safety Factor?

    Safety Factor is the extend to which system has ability to stay functioning amid problems.

Safety Factor vs Contigency Plan

    When designing a system, one must consider a Safety Factor. Its something other than Contingency Plan. Safety Factor is supposed to work automatically, parts falling place to replace disabled parts, ideally having no change in apparent behavior of system. Contingency Plan requires human intervention.

Explanation of Safety Factor

    A Safety Factor of 1.25 means that 20% of the total resources are extra, i.e. not immediately needed and 80% of the resources cover all of the immediate needs. Then if some of the units in resources break, the extra ones take their place, keeping the whole system working at same level of output.

    Resources can be people, machines, rolling money, buildings etc.

Quantity of Safety Factor

    In quran, God ordered us to prepare for war against non-believers and have twice as much preparation as is needed for visible enemies because there are non-visible enemies too.

    God Himself gave us two eyes when only one is needed, two hands when only one is needed, two legs when only one is needed and so on.

    Therefore, the optimum Safety Factor is 2.

    Half of the resources must be kept idle most of the time to be used only when working units are disabled.

Strategies of Keeping a Safety Factor

    Its better to not keep one half totally idle for all the time when there is no trouble. Either the resources are kept in rolling, with one half resting while other is working, or both halves are kept in working but only at half the capacity. For example in case of people its good to have the rolling strategy, in case of machines its good to have working at half capacity strategy.

What is and what is not Safety Factor

    If a country has two sea-ports, and both of them are needed for proper working of country's economics. For example, one port provide trade to half of the country and the other to the other half of the country, and no sea-port can provide trade for the whole country, then a Safety Factor of 2 means 4 sea-ports.

    In time of war, usually generals never commit all of the soldiers present at field to war. A reserve is always kept. This reserve is something where fighting units are supposed to fall back in case of a retreat. The reserve sits idle, remain fresh and it called at battlefield only when extremely necessary, such as when a front is facing unexpectedly large number of enemy troops or when enemy is using a tactic or weapon not planned for.


    The key is to realistically estimate what is necessary. Often commanders (be it generals, officers or managers) think what is reserve which is not reserve but is needed in normal working of the system. In these situations the reserve falls to 25% of total resources. Keeping this level of reserve is dangerous, its not strong enough to handle most of the problems, therefore in face of situation the whole thing collapse, even though the reserves are kept and paid for all the time. Then commanders think that keeping reserve is wrong strategy and decide to not keep any reserve at all.

    A lots of examples can be given for over-estimating reserves. In a battlefield, certain units have to stay behind to guard the camp, the hospital, equipment and materials. This is not reserve, the guards are needed for normal working of the system. Reserve is something that has no immediate duty and has nothing to do in normal times. Reserve also have to be large enough to provide not just for the fighting units but also for guards. The people working in hospital are similarly not reserve.

    Another example is a guard at a bank. Since most of the time, that is when there are no robbers at or near the bank, the guard sit idle, some managers think this as waste of resources and start giving peon level work to guards. The guard may be asked to post letters, fetch lunch for staff, even clean the manager's car. This is very dangerous. What if robbers come when guard is standing in a line at a post office waiting for his turn to post a letter?

    Another example is engagement of a country's military in running steel mills, electricity production companies or even railways of a country in peace time. Unless these companies are doing any military work, no armed forces person should be assigned to any of it.

    The commanders must clearly understand, without any vagueness, doubt or fuzziness, that certain resources must be kept idle, to be used only in times of crisis. There is a thing called too-efficient.

Where Safety Factor is Needed?

    I advocated a Safety Factor of 2, which I explained as keeping half of the resources idle. Do that means that we must always pay for double the staff than needed? No. Only critical resources must have a Safety Factor of 2, not all the resources.

    Safety Factor is needed for critical resources only, not for all resources. A critical resource is a resource that is mission-saving or life-saving, a thing which we cannot live without.

    Another way of understanding critical resource is that, a critical resource is one whose size must remain unaffected as system shrinks.

    Water supply in your house is a critical resource. You must have an in-house water tank, such as one in toilet or kitchen other than the overhead tank at the roof. Entire military is a critical resource.

    Managers are not critical resource. As company's size shrinks, its number of managers must also shrink accordingly. Same goes for sales staff.

    A commander must be able to distinguish between fats and meat. Fat is dispensible, can and should be shrinked in times of crisis, but meat must never be shrinked.

    Engines in an aircraft is critical, number of passenger seats is not. Pilot is critical, air hostess is not, passengers are not. In a sinking boat its ok to let go some of the passengers, but its not ok to let go the sailor, the man who rows the boat.

    All in all, the critical resource must never be more than 25% of the total number of resources in system. Keeping an extra 25% raises cost 25% if cost of keeping resources is same for all resources. Since critical resources are more expensive to keep, per unit, than non-critical resources, examples being pilots paid more than air hostess and military paid more than teachers, assuming a difference of two times, the cost of resiliency is 50%.

11 June, 2012

Higher Order Logic

Higher order logic is logic applied on logic. So, what is logic? Logic is a set of:

  1. Conditions: Checking whether something has a given relation to something else.
  2. Loops: Continue doing an action as long as a given condition is true.
  3. Actions: Putting some value in some container.


Example:

int i = 10; /* putting link of two bytes in i, putting 10 in those bytes */
int x; /* putting link of two bytes in x */
/* running a loop and in each iteration putting something in x */
for(int a=0; a<100; a++)
x = x + i;

Console.WriteLine(x); /* putting something on screen */

Higher order logic is applying logic on logic. The above code is a block of logic, it can be part of a function or a complete function itself but still its a block of logic. The following code is high level logic:

if(DateTime.Now == "1st Jan 2015")
/* call the above block five times */
else
/* call the above block one time */
When we call a method, on basis of some condition, or when we call a method multiple times in sequence, we have a high level logic.

Event-handling therefore is high level logic. The event-handler function is logic, the decision of when to call what function is high-level logic.

Multi threaded programming is at a higher level logic than single threaded programming. That not to say that single threaded programming is necessarily first order logic. Most programs, even when single threaded are at levels higher than the first level in logic.

If there is a starting method in program, such as main method in c, and all methods are called from this method, then the program is already in second order logic. The code in non-main methods is first order logic, the code in main method is second order logic. This holds even if there are no conditions or loops in the main method. If five methods are simply called one after another then we still have a logic, this is pipeline logic, a sequence.

If the methods called from main call other methods then we have three order logic.

Its better to never have a lower order logic method calling a higher order logic method. The flow must go in one direction, in terms of order of logic too.

The last level of logic should ideally have static code, code that reacts on its arguments only. This can safely be called from any method, at anytime, with thread-safety and no complications, no side effects.

The higher the level of logic, the less the number of callers of the code should be. Therefore, main method must be callable only from one place, the operating system. The methods called directly from within the main must not call each other, they must be callable only from main. These methods have second order logic. Any third level method can be callable from any second order level method but ideally must never be called from main.

Logging logic is higher-order logic, even if its just logging code then calling of the actual code. Exception handling is higher level logic, if multiple blocks are called.

Easy Monad

A monad is a class that has two things:

  • A field that contains an object
  • A higher-order function


The higher-order function is the key. This function takes in argument a normal function. It then apply this normal function to the object the monad contains. The normal function have to have an output type other than void. Whatever the output of normal function is, its then converted into the monad type and returned.

The higher-order function can be made to take a normal action instead of a normal function. The difference between a normal function and a normal action is simple: normal function have an output, action don't. In this case, since there is no output, therefore the higher-order function do not return anything.

The action thing is something that go against the functional programming philosophy. In functional programming, a function have to return something. If nothing else then the object itself. This makes the basis for method-chaining. The action thing is there to make monads compatible with imperative programming where functions often don't return anything.

Here is the simplest, yet useful monad:


public class M
{
    public readonly T _o;

    public Monad(T o)
    {
        _o = o;
    }

    public M Bind(Func f)
    {
        return f(o).ToM();
    }
}

public class ExtensionMethods
{
    publc static M ToM(this T o)
    {
        return new M(o);
    }
}

public class Program
{
    public static void Main(string[] args)
    {
        string s = "some string";
        Console.WriteLine(s.ToM.Bind(s => s.Substring(0, 1)).Bind(s => s.charAt(0)).Value);
    
    }
}


Explanation

M is the monad. It has a field called o which can contain an object of any type. This object has to be passed through the constructor, it cannot be written directly into even though it is public, because its readonly.

Its the Bind method that makes M different than an ordinary class. Bind is a higher-order function. Its argument is a Func, i.e. a function. An entire function can be passed in argument to Bind. This function is applied to the field object _o. The return value of the function is casted into M and returned.

Why do we have to cast the return value, and why into M? Because we want to have method-chaining. In the second line of Main method, we first call the Bind method and then what is return is binded to another function. More explanation below.

In the Main method we have an object s. It can be of any type because any type can be casted into M. This is achieved by the extension method. s is converted into M by calling the ToM method. Now what we have is a monad. This is called lifting, we have converted a normal type (string in this case) in a "higher" type (M in this case). The normal type do not support higher-order functions, the monad do.

Once we have a monad, we call the higher-order function on it. The argument of Bind is body of a function. This need not be an anonymous function. We can very well do this:

Func func = s => s.Substring(0, 1);
string s = "some string";
s.ToM.Bind(func);


Whatever function we pass to Bind is applied on the object contained inside the monad. A monad therefore is a wrapper, it wraps an object of normal type. A monad however is more than a wrapper, it also has a higher-order function and related features as shown above.

In the Main method we are having full use of method chaining. We are calling one method, this results in some changes in the object on which this method is called, the return value is itself a monad and so we can call another method on it and so on. This is the power of monad.

Uses of Monad



A monad can be used for logging. Instead of calling methods on an object directly, we call the Bind method and pass on the method to it, the Bind then calls the method. We can insert our desired logging related code before and/or after calling of the normal function inside the body of Bind. Like this:

public M Bind(Func f)
{
    /* logging code, before calling the normal method */
    f(_o).ToM();
    /* logging code, after calling the normal method */
}
The second use is putting the exception handling logic, that is common to all methods. Like this:

public M Bind(Func f)
{
    try
    {
        f(_o).ToM();
    }
    catch(/* common exception class */ x)
    {
        /* common exception handling code */
    }
}
The thing is, you can send any logic in argument to Bind. For example you have a class with 4 variables and you want to change values of some variables on basis of a complex predicate applied to some other variables. You can even have a for loop's logic put in. Whatever the logic you want to send, the monad class itself need not be changed.

A monad is not designed to have any logic. A monad is designed to have meta-logic. Logic behind logics. The meta-logic can be a place holder of normal logic, or it can be a group of logics working together, or it can be a group of logics applied on each other in a sequence.

The sequence thing is very interesting. In languages in which statements are not guaranteed to run in the same sequence they are written in code, we can pipeline execution of statements using a monad.

It should be noted when the code inside the Bind method would change. In each of the following, we are applying logic differently, means the logic of applying the logic is different, therefore in each of the following the code inside the Bind method have to be different:

  • Logging of method calls


  • Putting common logic of exception handling of method calls together


  • Taking in multiple functions, applying some on basis of result of another. It can be not applying some functions at all on basis of results of calling of other functions or varying number of types some functions are applied


  • Taking in multiple functions, and apply them one after another in a strict order

10 June, 2012

Rules of Computer Backups

  1. Independence: Take backup on a different disk than the original. It can be a different hard disk, CD whatever.

  2. Distance: Keep the backup disk at a different physical location. The ideal is atleast 5 KM distance. Practically it should be at a different building.

  3. Completeness: Take the backup of the entire thing. It may include environment variables, documentation, hand-written notes etc.

  4. Verification: Do frequent restoration of backups at a separate machine to be sure that the backups is complete, in working state and can be restored.

  5. Security: The backup need to be as much secured as the original. This includes computer and network security.

  6. Tailness: As time passes, your periodic backups can pile up and make a huge volume. It do not mean you are allowed to delete the old copies. You must keep all of the copies including the very first, because you never know when and to what extent you have to back track and start anew. Disks are cheap.