viernes, 30 de julio de 2010

Genius + Brute Force = Ingenious

These two statements have been branded with fire in my mind:
  • Genius find a solution instantly
  • Brute Force searches for a needle in a haystack
Sometimes we need to generate random numbers. History has kept evidence of Dice and Coin toss as methods of generating random choices.

Donald Knuth invented algorithms for pseudo-random number generation.

Edsger Dijkstra stated that there are two approaches to solve computer problems: Mozart Vs. Beethoven. (As a curious fact, Mozart and Beethoven met each other in 1787) The former is a genius, but the latter works by brute force.

In India, Pachisi and Chaturanga were played with Dice. Orthodox Chess can be also played with dice, but Chess isn't normally played that way. The praise of what is random have been lost.

In Watchmen movie, Dr. Manhattan talks about the "Pleasure of Randomness" If there's an origin for that phrase, I'd like to find it out. Also, some levels of randomness are required to produce Fine Arts.

To try to get in touch with that "Pleasure of Randomness", I decided to create a little program that generated three numbers between zero and one-hundred inclusive. Then, I will use only the first two numbers and some operations to generate a result equal to the third number. For example, if those three numbers where {2, 3, 6}, then (2+3)+(3-2)=6. Of course that 2*3=6, but what would you do if numbers were {53, 92, 59}? This is what I did, using Python IDLE:
## OUR THREE RANDOM NUMBERS

a=53 ; b=92 ; c=59 ;

## EXPLORING NUMBERS
92-53 = 39   (b-a)
53-39 = 14 a-(b-a)
39-14 = 25 (b-a)-(a-(b-a))

25-14 = 11 (b-a)-(a-(b-a)) - (a-(b-a)) //???

92-11-11-11 = 59 //MAGIC!

b \
-((b-a)-(a-(b-a))-(a-(b-a))) \
-((b-a)-(a-(b-a))-(a-(b-a))) \
-((b-a)-(a-(b-a))-(a-(b-a))) \
== c

## SIMPLIFICATION

>>> ((b-a)-(a-(b-a))-(a-(b-a)))
11
>>> ((b-a)-(a-b+a)-(a-(b-a)))
11
>>> (b-a-a+b-a-(a-(b-a)))
11
>>> (b-a-a+b-a-(a-b+a))
11
>>> (b-a-a+b-a+(-a+b-a))
11
>>> (b-a-a+b-a-a+b-a)
11
>>> b-a-a+b-a-a+b-a
11
>>> 3*b-5*a
11
>>> (9*b-15*a)
33
>>> b-(9*b-15*a)==c
True
>>> b+(-9*b+15*a)
59
>>> b-9*b+15*a
59
>>> 15*a-8*b
59
Looking at this simplification, some questions pops out from my mind: Would a genius had gotten an equation like this from the start? Would have a genius known that a solution found using this method could be simplified without even trying to solve one problem in the first place? I don't know, but I'm sure I'm not a genius.

This simple game taught me some lessons:
  • Pseudo-Random exploration is helpful to find a solution.
  • Be ware of the word 'repeat'. It could hide a mathematical operation.

---
20100729T0948:
round a problem many times
look for hindrances, obstacles, inconveniences
re-round each found obstacle and find inner obstacles
until one obstacle is solved
then, that solution will solve another
and so, like a domino effect,
the first and original problem
starts to get solved
- [id, status, created, modified, position, modcount]

20100729T1125:
writing undefined sentences to describe the problem
making calculations with parameters to find a result
opening many files to understand and solve the code

20100729T1143:
TDD to automate tests "seems" the way to go.
GUI needs to be scriptable, and HTML allows this.
Maybe JavaScript could be a problem, but if you could
append a [SCRIPT] tag and run it, it will be no problem

Enterprise, Human Resources, People and Wars:
- If you kill people, you must find and train new ones.
- If you forgive people, they will squeeze you.

martes, 20 de julio de 2010

SQL = Sets Quarantined, Lost

I have two tables in a MySQL database. They both have persons, but BOTH tables have persons that are not in both. So, I wanted to bring all those people that are not repeated. I can do this using inner loops, but I tried to do it by MySQL alone.

I elaborated an example with two sets: t1=[a,b,c]; t2=[a,b,d]. What I want to bring is this set: r=[c,d]; because [a,b] can be retrieved by a simple INNER JOIN.


#TEMPORARY TABLES WE WILL USE
#TABLES WITH ELEMENTS WILL BE: t1 AND t2

DROP TEMPORARY TABLE IF EXISTS t1,t2,plus,minus;

#FIRST DATA SET
CREATE TEMPORARY TABLE t1 AS
SELECT 'a' AS f1 UNION SELECT 'b' UNION SELECT 'c';

#SECOND DATA SET
CREATE TEMPORARY TABLE t2 AS
SELECT 'a' AS f2 UNION SELECT 'b' UNION SELECT 'd';

#CREATING THE "UNION"
CREATE TEMPORARY TABLE plus AS
SELECT * FROM t1
UNION
SELECT * FROM t2;

#CREATING THE "INTERSECTION"
CREATE TEMPORARY TABLE minus AS
SELECT t1.* FROM t1
INNER JOIN t2
ON t1.f1=t2.f2;

#CHECK OUR TEMPORARY TABLES
SELECT * FROM t1; #FIRST TABLE
SELECT * FROM t2; #SECOND TABLE
SELECT * FROM plus; #ALL ELEMENTS
SELECT * FROM minus; #COMMON ELEMENTS

#AND THIS IS THE OPERATOR I NEED IN MYSQL
SELECT plus.* FROM plus
LEFT JOIN minus
ON minus.f1=plus.f1
WHERE minus.f1 IS NULL

/*
AN UNION MINUS AN INTERSECTION BRINGS ALL RECORDS
THAT ARE NOT PRESENT IN ANY SET

YOU SEE, VENN DIAGRAMS AND SET THEORY ARE TOO OLD SCHOOL
THAT THEY SEEM NOT NEEDED NOWADAYS. BUT NOW,
OBJECT-ORIENTED ANALYSIS AND DESIGN IS, AGAIN,
BRINGING ALL THOSE OLD-SCHOOLERS BACK!!
*/

domingo, 11 de julio de 2010

Common Sense = Prejudices

"Common sense is the collection of prejudices acquired by age eighteen."
Albert Einstein

There are faults that we allow because they are logical and common sense. This is an example of how a bad action can be seen as good, and that there's no absolute true.
  1. Mixing milk with water
  2. Mixing flour and yeast to make bread
  3. Accepting or giving "payment" to correct a legal "fault"
  4. Drinking "juice powder" instead of natural fruits
  5. Forbidding abortion on EVERY possible situation.
  6. Cutting big trees because they interfere with power lines
  7. Keeping the extra-change mistake because they won't give it back if the mistake was ours.
  8. Not asking questions; but instead, either requesting or begging for answers.
Sadly, I see some of these topics as 'Necessary Prejudices' in some aspects too.

jueves, 1 de julio de 2010

Frameworks = Mathematical Placebos

Thanks to Online LaTeX Equation Editor. Very helpful for "The Placebo Formula"
---

Programming Frameworks are like something I have called as Mathematical Placebos, extra data that we add to equations to help us reach its results.

This extra data bloats the language ahead of the future. We tend to find many gotchas before and while we are working on a code, and they will delay code delivery.

What started easy, now is not.

To give a mathematical example, a very interesting equation, Euler's Identity, goes like this:



LaTeX: e^{i\pi}+1=0
PHP: it doesn't have built-in calculations for imaginary numbers.
Python: print (math.e**(math.pi*1j))+1

The result is this Python expression is not exactly 'zero', but very near to it. This is a common catch in floating point calculations. ;-P

Do you imagine what amount of tests Leonhard Euler did, in order to find out that relation of constants returns -1?

What I call "The Placebo Formula" (numbers I recall when I solve fractional, algebraic, or exponential equations), goes like this:



LaTeX: \frac{\sqrt[1]{\left(\textbf{1}\right)^{1}}}{1}+0=1
PHP: echo pow(1.0,1.0/1.0)*1.0/1.0+0.0;
Python: print 1.0*1.0**(1.0/1.0)/1.0+0.0

Do you get the idea of all those extra artifacts in both placebo formula and frameworks? You have to remind yourself that if you see a simple "1" in a formula, you can add any of those pseudo-numbers to ease your calculations.

In programming, this effect is also achieved when you create a common Object class for every object, including those objects not yet discovered or planned. When you have to add a behavior to all objects, you add it to that base Object class.

---
PS: I annotated what I need to do in this post instead of actually doing it! (e.g. I typed "use an image of euler's identity and wikipedia link") It is always easier said than done, although this action can prompt you to do a better organization of the way in which you express your thoughts. Write for yourself!

Evolution of Coding

It all started so simple:
  • George Boole, and his Boolean Algebra.
  • Claude Elwood Shannon, and his Information Theory.
  • Alan Mathison Turing, and his Turing Machine.
  • Charles Babbage, and his Programmable Computer.
  • John von Neumann, and his Computer Architecture.
I tried to put this in the normal order of understanding for people, but actually I will use the order on which I normally encounter the problem.
  • Every computer problem is composed by 'only' three main parts: input, process, output.
  • The input part needs both a layout and an interface to look nice.
  • The main process must be structured, and it should support alternate logic to handle possible exceptions.
  • The output also needs a layout specifically designed for screens, papers and files.
  • Not all users will be allowed to use this program. So an authentication system is required. Also, it should allow many users, each one with possible different roles and levels.
  • In the input part, users commit many mistakes, so validation is needed for each data that program receives.
  • To ease distribution of the program, and to centralize the data store, a client/server structure is defined.
  • Many users in different remote location have different languages. So, programs now need to support different types of languages, like english, spanish, etc.
  • Good database software and modern platforms have been developed. So, it should be useful to make programs able to migrate to them. (db, os, platform, web, mobile, etc.)
  • It's hard to create a migrable program, so we should separate our development into three layers or tiers: back,middle,front (A.K.A M.V.C.)
  • There are several programming languages on which we can express many of these principles easier (C++, Java, etc.), so we should migrate our programs to them.
  • We are losing performance as our user base grows up. So, we should test concepts like replication.
  • Some foreign programs and systems also want to have access to our program. So, we should create Web Service or open ports for Socket programming.
  • It's probable that, with all these changes, we have left some doors open because of lack of sanitation. We must protect our programs against Session Hijacking, Cross-Site Scripting (XSS), and several types of Injections (SQL, HTML, CMD)
  • Many users access the same resource simultaneously, and that generates either deadlocks or data inconsistency. So, we should program taking into account concurrency and multiple threads of execution.
  • Our application is growing too much. So, we should apply concepts like distributed/cloud computing, to make our programs and database expandable by simply buying extra hardware.
  • OOP, EXCEPTIONS, CHANGE (files,interrupt)
Now, there's a question: What's next? How could we magically and instantly create or adapt a program to any change we still don't know? A possible simple change might touch EVERY AREA of our program! And a touch of that kind needs TIME to be checked in every area we have created. That's the problem known as Essential Complexity.

---
PS: IPO (Input-Proccess-Output) ... Hajime no 'IPO' ;-P

sábado, 5 de junio de 2010

Improving curiosity of "kids"

Money, Satellites, Vices, Limo-Hummer... either to look for or create inventions. Some hunt inventions for money; others for fame and acknowledgment; others, by pleasure; others by needs; others promote inventions to win money; others desperately look for inventions to become rich (they search for them all over the world), but discoveries are born from needs, learning and education. How could you wish that inventors flourish, if the only thing they have in mind is MONEY, not MESSAGE?

The game of adults is so promoted, that we all forget that we were children and, instead of showing to our children why some things are bad, we blindly forbid them, and by that time we also forget that those prohibitions were what motivated us to act opposite to our parents when we were little kids.

This is a Vice Cycle because, in many aspects, searchers and parents are also, although offensive, our bosses.

viernes, 21 de mayo de 2010

amo al sufrir ↔ formar a luis

"Un conocimiento reducido es algo peligroso; pero debemos de tomar ese riesgo, ya que un conocimiento reducido es lo máximo que nuestras cabezas más grandes pueden soportar."
George Bernard Shaw

Él no tiene esperanza, pero "no hay destino que no pueda decorarse con desprecio."
El Mito de Sísifo

"En este negocio, en el momento en el que te das cuenta que estás en problemas, ya es muy tarde para salvarte a tí mismo. A menos que corras asustado todo el tiempo, estás muerto."

Bill Gates

"Tener como meta la Comodidad y la Felicidad nunca me ha atraído; un sistema de éticas construído en estas bases sería suficiente para un rebaño de vacas."

Albert Einstein

"En este mundo hay sólo dos tragedias: una es no obtener lo que se quiere; la otra es obtenerlo. Esta última es la peor, es una verdadera tragedia."

Oscar Wilde

"Sabed sufrir: sabiendo sufrir, se sufre menos."

Anatole France

"El sufrimiento más intolerable es producido por la prolongación del placer más intenso."
George Bernard Shaw

"Si al ser feliz creo serlo,
sufro en mi dichoso estado,
pues me hace desgraciado
sólo el miedo de perderlo.
Y si estoy bien sin saberlo,
pues no lo sé, no lo soy;
así mañana como hoy,
ser feliz nunca podré;
pues si lo soy, no lo sé,
y si lo sé, ya no lo soy."
Joaquín María Bartrina y de Aixemús
(¿O era José María?)


Cúspides:

sábado, 15 de mayo de 2010

The Last "Atreyu" From Earth

After I saw Never Ending Story (first movie), I started to dream about how could somebody write something like that, that can give the same impression for adults as that story created on kids.

A friend of mine, KameKun, recommended me The Last Man From Earth movie. I can assure you that you can bring something useful for yourself after you see this movie. The most important thing I need to study about this movie is how to organize things you say, in a order that all people listening them will be able to understand you, and believe you.

If all is possible, and all these things have happened, then somebody must be desperately hunting for that last man. If not, then the way he organized the story is at the scale of an illusionist or a magician, because it is almost believable.
  • Aristarchus long before that. (story is getting sharp)
  • Yochanan
Now, impressively, I have recalled something I wrote some time ago. I called that story Immortal Rich. Recently, I have commented in my actual job how much I like dialogs in textbooks. Well, this movie is all dialog!

After you see this movie, haven't you felt how your mind tries to fly towards all those moments that John described? I really like that kind of jumps...

"The Last Supper" Man

Reference to my joke in the title:
http://en.wikipedia.org/wiki/The_Last_Supper_%28Leonardo_da_Vinci%29

I have seen Superman Returns movie. I really don't like to underestimate coincidences, like must people do, and in this time, I have found one related to Planet Krypton and Planet Vegeta, and, even knowing that they were not born in Earth, both Goku and Superman love this planet. When I see things like these, I think that Japan is copying some stories from United States...

Some extracts of quotes:
  • God doesn't share His power
  • In jail, my knowledge worth less than a piece of metal and cigarettes
  • Don't alarm. It is normal
  • They don't need superman, but they cry for one
  • Mind over muscle
  • Krrrrryptonite!

If Lex Lutor is the wolf, then is Superman the vampire? Never underestimate the perseverance of a wolf!

When I saw Superman falling towards earth and sea, I recalled the phrase "Fallen Angel" and Jiraiya... and also that I want to jump from a parachute and learn how to swim!! XD

viernes, 14 de mayo de 2010

Parameterizing

There are two ways to pass values to functions. I will state examples using PHP:
  1. showUser('Ignacio','Cortorreal');
  2. showUser(array('name'=>'Ignacio','last'=>'Cortorreal'));
Each one has advantages and drawbacks. At the end, when you are building an API, you must choose what to do. The first version is older, and I have started to valorate the older although, for analysis, it is too painful, but more efficient. Will the Old one version minimize "supposed logic errors" because of its strong typing? No! Neither the New one.

The power of the New one is that parameters can be expressed in any order!! For example, if you want to add the middle name and a second last name to showUser() function, we can add it, and it won't bring problems to other code using that function, but its interface and implementation stars to become a mess, something that is somewhat reduced with the Old method.

DOS
  • format /q/u/v/c/s
  • g++ -Wall hello.cpp -o hello.bin
  • type a.txt b.txt
  • grep -v " OK "
JS (PROGRAMMING)
  • save({a:1,b:2,c:3});
  • sum(1,2,3);
WEB
  • /products/view/5/1
  • /products/list/page:3/sort:desc/
  • script.php?first=john&last=doe
SQL
  • Horizontal Vs. Vertical Structures:

IDFirstLast
3IgnacioCortorreal

--Vs--

IDFieldValue
3FirstIgnacio
3LastCortorreal

In lambda calculus, each function has exactly one parameter. The process to emulate multiple parameters is called currying. It looks crazy, but I think it is the way to go if we want to find a new order for these Parameters' disorder. Python supports this kind of paradigm, and is my next language to study after I achieve a basic-intermediate level of my C++ abilities. I was looking to Haskell or LISP, but Python's documentation on the web is way too much better.

This is the strongest Yin-Yang I have found in programming. Which one to choose?