# Older blog entries for tampe (starting at number 90)

16 Nov 2008 (updated 16 Nov 2008 at 21:24 UTC) »

You can do everything in assembler

I first want to say that layout manager and such really is something that is old technology and already included in all modern gui's, but it is always good to just focus on a thing and think a little to see if things can be improved.

When drawing diagrams in powerpoint I always get very frustrated. the reason is that I believe that something like a well implementation of the tools found in the TeX community to draw diagrams, would be so much easier (for me). It would be so cool to be able to use the TeX tools to layout stuff in diagramming and gui construction. If you are like me I suggest to read and play with those TeX tools like xy-pic, great fun.

Let me also point out that QP is probably not used because simpler solutions then what I described is probably already implemented. The point using QP is that you can specify that not only X is close to Y, but allow the distance is allowed to vary if there is conflicting constraint(s). It is also a quite general framework if you stick to linear constructs. What I miss is a framework and tools, to handle and develop layout managers. There should simply be a tool for me and others who now the math (perhaps do it using scipy) to develop some great markup framework to do layout of different things. I could imagine it being based of QP and also of cause, as a special case Linear programming. One could think of including other mathematical tools as well like convex programming.

As an example let's discuss about implementing a tool to make sure that the layout has straight left and right margins. We stack a sequence of objects X1,X2,X3..., with a smallest distance d1,d2,d3,.. between X1,X2;X2,X3;..., And we also say that we punish a deviation from di by a coupling constants C1,C2,... basically you could automatically select Ci,di according to the sizes of objects (xy-pic in the TeX world has such ideas in it's layout strategy of diagrams.) Now to specify a conflicting constraint to let the total distance of the sequence to be constant in order to achieve a right margin. You never get an exact right margin, but by adjusting the spaces between words or objects you may make it happen. The good thing using this is that you will always get an answer and depending on measures how well every constraints is satisfied you can decide to remove objects to the next line or include new objects. Also you could fire up guis and let users who want to tweak the coupling constants, do it to adjust the layout.

Finally here is a trick I use to deduce the components in a quadratic criteria x'S'x + v'x + d from other representations without thinking. When I first tried to do this I went for the white board and started to deduce things by hand. well that is not needed. just define a function f(x) that is your definition of the criteria, that is most easy to define. Then use your computer to evaluate f(0), f(ei),i=1,..,n, f(ei+ej) i,j=1,..,n. Using this information you will be able to deduce S and v. I find this a very neat tool. It is written once and will save you ton's of time.

What I fear is that we mostly develop to make things simple for the less advanced users because most users are on that level which means that this is ok. Beeing an advanced user means that you don't get the benefit of most development and that means that you are not 10 times as effective but perhaps only 2 times and you loose.

Cheers

In the beginning there was a Layout

I think that a great layout engine should be the base of a great Gui. So here is some thoughts about layout.

I don't now about all quirks of TeX, but basically, it seems, its that art about stacking rectangles where the rectangles themselves can be based of stacked rectangles and so on. It is a simplified description but you can see one fundamental point in this argument, you can use an object oriented description of the rectangles. Actually you should be able to use the TeX engine to do a automatic layout of a Gui. Anyone now anything about how to do this in a nice way?

Automatic Layout of graphs are cool, and I ones made a huge call-graph of a python program on a A2 paper with the help of the ghraphviz package, really nice. In graphviz you can have nodes that are rectangles. You should then be able to use the graphviz engine to find the coordinates of your gui elements as well to get a certain kind of layout. Is there such a link out in the wild?

Constraint Programming for layout is cool and of cause not a new idea. You basically give constraints for how the coordinates in each rectangle can vary in relation to other coordinates in different rectangles. Something like x>y,x-y>d (x is after y and at minimum d units apart). Then you might add a penalty av magnitude, say C((x-y) - d)^2 and include all these in a quadratic criteria telling how much you like a deviation from d distance and play with that. This is a more fuzzy and general way of implementing stacking. Say that we implement stacking according to this. We might want to align stuffs in different ways e.g. want your coordinate to be close to other coordinate in some way, close can again be related to quadratic criteria. You can express that a linear transformation of a set of coordinates can be close to another set of coordinates and so on. It is a powerful concept. You will end up with quadratic programming QP.

There are some special cases. For example if you always stack in an exact way when you build your rectangles, you may skip the inequalities and just solve the fuzzy constraints that's left in the quadratic criteria. Then you basically need to solve linear equation systems. Kan we do this fast? Well in order to have as an exact and general solution and keep it simple you may start using linear algebra routines of full matrices. The order of this algorithm is n^3 if I'm not misstaken so a layout of 1000 coordinate values will take 10GFlops to calculate, Maximum space is about 100MB for doubles. (The transfer to the computing unit may actually be much less due to sparseness of the matrix)) Now considering that GPGPU solutions can deliver 400GFlops (see one of the examples at the CUDA site (with a TESLA card)). You may now understand that you in a few years when the GPU technology have been standardized and matured, you will be able to do some cool things with layouts. To the reader, for cases with sparse matrices you will find other mathematical tools and GPGPU may not be suited.

Solving quadratic programming problems with constraints is if I remember correctly heavily dependant on solving equation systems as well so GPGPU technology is probably welcomed for this case as well

Can we dream up more layout tricks? Well some kind of morphing. Say that I have a set of symbols and wants them to be more square like. How can we implement this? Maybe one way is to make the best fit of a square to some set of coordinates from a symbol. Then you can calculate the closest points on the square for each point on the symbol. A new symbol with the same coordinate identities will then be searched for so that you weight the variance to the square and the variance to the old symbol and then hence morph between them. I don't now how this works, but there are plenty of tricks like this that have the potential to implement more fuzzy notions about a layout.

And then the content begun

Robot Robs Retrospection

I got some good laughs today, cool

Anyway It got a bit too late yesterday and I ended my last post without checking it very well. Anyone wanting to implementing delayed variables should try to skip the case when you cannot know for sure if things yield or not. I just don't see any uses of it and it can quite easy create infinite loops. In the description I presented there seems to exist some good seeds of ideas though, that can grow to a checker that can warn about dangerous constructs, if you still need to implement this case as well.

How do I create those delayed variables. Well I'm lazy. Each delayed value is composed of a value and a list of lambdas. when I know the value I fill it in and then execute the lambdas which will propagate the value through the whole delayed graphs. It is expensive of cause but to do it this way is, well my way of having fun. Anyway normal stateless functions can be blessed to use delayed variables. It works by checking if an argument is delayed if it is, the correct lambdas is added to the incoming delayed argument(s) lambda list. This lambda just checks to see if all arguments now have materialized and if that is the case calculate the function and put the value in the returned delayed value and then evaluate all the lambdas in the returned delayed value lambda list.

Everything is not what you think it is, reality is an retinal image, Nothing... makes you think.

My God

What so cool with Internet and forums like advogato is that ideas, words and units of thought is flowing from mind to mind mutating, mixing, replicating, bouncing, In a very subtle way. The communication is many to many and this is indeed important, we must be able to communicate in order to make sure that the world won't fuck up.

Introspection is a nice powerful feature that seems like a hot topic these days. I try to practice this a lot, not only in my code, but on myself. It is kind of cool to dig out the association and logic behind an idea.

One idea I got was to check out scheme. There is some nice food for thought in that community. I've planning to read about lazy evaluations, but here is my current view on delayed evaluations.

If D1,D2 is delayed, basically f(D1,D2) :D3 is delayed as well represented if any of its arguments is delayed. Now this means that D1->D3 and D2->D3 and you see that what you have is a directed acyclic graph (DAG) that represent your overall delayed state with a pointer to a function at each node. So it is not at all a difficult concept. But what about and (if D A B), D is delayed. Here it seems you need to store the value of both A and B in order to be able to use it later, this is actually a difficulty. I will need only one of A and B but I have to get both values in order to later retrieve the correct value. If you have recursion in A or B you may find your way into an infinite loop. So if A = (g C E) you need to store (g C E) and continue so recursively. With no gotos and internal state in your code you will then be safe. If you have state you then need to store the state related to both A and of B. A key issue here is to avoid relation pollution e.g. you do not want to store state that is not needed to retrieve the value later.

In my (switch-if P A B) construct if P A is incremented else B is incremented. I try to avoid using delayed values in the P but storing the state of A and B may seem to solve the problem. will it will be safe? No, there is another problem. A and B will contain signals backwards in the system about yielding values, about finishing iteration and skipping stuff. So depending on the possible signals send back you will have both complicated knots to untie as well as more trivial ones. Some of these questions can be mitigated by simply returning values of special type like a skip value. A quit value which also can be implemented.

Consider that we are under a delay. And now the delay is activated with a skip value. This is the interesting construct. Consider an update of internal state:

```
(update Var Vals Oldval)
```
The most simple choice of logic is that if any Val is a skip value, Var is a skip value and equal to Oldval. A function just returns a skip value if any of it's arguments is a skip value. This logic is then transported in the delay graph.

The finish signal is a little more subtle but basically each object as a finish value Vf, and if object Y at an update gets a finish value then it should fire it's finish function to update Vf, the variable representing the finishing value. Else the transportation and action of the finish type is like skip but of higher precedence.

Now the actual iteration is something like

```
(do
(make-generator X)
(loop X))
```

```
(define loop X
for:
(X.next)
Ret = (relate Ret (X.val))
(if (finish? Ret)
goto exit
goto for:

exit:
X.Vf
```

The relate is just a relation that represents the transport of the finish all the way to the current Ret if this has been delayed and you have to iterate a few iterations more than needed.

Trying to handle the yield signal is delayed. No just kidding. You need to do the following

```
(do A B C)
```
The logic is, take next A, if A is a yield stop! and use value of A. the next time start with A again. Else continue with B and so on. Now if B is delayed and might be a yield you need to store the state of the do e.g. the state of

A,B,C and the internal state of do e.g. a program pointer. Then at the next update of this object if the delayed value have materialized you will then just continue with the evaluation of the do construct and everything would be fine else you will have to just chain the actual updating and return the delayed value.

Can we have infinite loops? Well, At each step you will have a tree of objects that you update in the natural order, when you update subtrees will collapse an new subtrees will be created. A delayed object is returned at a certain object and then transported to objects below it in the order. Hence if you keep a logic where you always will fill in the missing information at the same object that you issued the delay you will be safe.

I didn't realize all this before I started writing. This is why I write, enjoy

My best practice

Many times you hear that it is good to read for your children and it is.

Many times you hear that it is good for your children to be home with them when they are small, and it is.

But I'm so tired on the focus on children, the thing is that it is good for _you_ to take care of your children. At least that is my experience.

I have found out that caring for my child have increased my understanding of humans. I have found out that reading and telling stories has improved my verbal abilities a lot, my memory is better and my creativity is well ahead of the times before her birth. I found out that my wife can bring in serious amount of money to the family and among all she is not hitting the wall as many other mothers in my country. I found out that I do more in less time. I found out that I can work all of the time all day, all night, enjoying it, not feeling stressed a bit. I guess I just found out about life.

The trick to achieve all this is UBNA or ...

This is a constant fight. I realized the key part to success was to try use my brain when doing stuff and not put on my autopilot or what I call my arse. Things might be boring but If you use your brain _everything_ can become interesting. Caring can be boring, Caring can be very interesting. Reading can be boring, but if you put your heart into it, you will find out that your mind and voice when playing together is like any other cool rock-band you like and after a while you will dig it.

yielding stuff has it's complications, consider this generator,

```
(+ (do (yield 1) (yield 2))
(do (yield 3) (yield 4)))
```

(do (yield 1) (yield 2)) first yield 1 and then yields 2 if there is no yield in the other argument that argument will not be updated, but now we have another yield statement. How would you solve that?

I just consider the evaluation of the yield as a parallel statement meaning that the above construct will give

```
(+ 1 3)
(+ 2 4)
```
The hole construct is a little isoteric but you may want to have the possibility to first yield all the elements of the first arguments and then all the elements of the second argument or any combination you can dream up This is a sequencing patterns that I have not considered but it's interesting to make a note of it in the head. Implementing a tool to allow all possibilities is not that hard but if it is worth it, I don't now.

A strange day, is also a day, Cheers

TeX

Look at it, it's lovely, it's a mathematical formula

I check out the texmacs project regularily. I think that it has such a potential and there are some very interesting ideas floating around in that project.

What are the optimizations I've been thinking about? Well my method although slow should yield a taste of how it works, if it works and shed light on interesting patterns, not new, but interesting. So I'm just looking to find the elements, and how to combine them. This means that I do a tremendous amount of function referencing and consing! Just inlining all the small functions and maybe some tools around that will be enough (the consing is due to me not using multiple-value-bind) maybe not. Other loop macro framework that is interesting and fun to check out, usually seems to flatten the stuff and this could be a good pattern to mimic for success. I have tools that manages the closured internal variable state so flattening the variable space can maybe succeed. Now flattening everything and use gotos might be a bit clumsy and too clumsy, much of that can be done by the lisp compiler perhaps, it might be more wise to concentrate on some kind of loop unrolling helping framework, to find fastpaths and cut out unlikely paths to functions, I don't now. All I know is that while I'm coding with functions and closures I keep in a parallel universe in my head a version of the code that is flattened. One note, some patterns can function on the stack, but not all can do that, If stack variables are faster you may want to think about how to make as much use of the stack as possible and minimize the need to use the heap.

This might end up as a quantum dot of importance, but I don't care, at worst it will result in a document with cool patterns of computing, that's good enough for me

Well, now I need to finish the slow slurry singularities of black magic wormholes between I and I + 1.

Cheers

1 Nov 2008 (updated 1 Nov 2008 at 13:44 UTC) »

Oh my, its high up here!

I should remind myself to quote Newton. But I don't. Why? Well that's implicit. The thing is every good thought I have can probably be found in an scientific archive somewhere or in some project X out there and My whole experience is based of others efforts. That's how an open system works and that's probably a key fact to explain the technological success we have had the last centuries. So I'm blowing in the wind and we all are blowing the wind.

What I'm heading at is my clambda stuff. This stuff will be basically c morphed into a more lispy syntax. That is, there should be a mapping between C-syntax and c-lambda and when you managed to grasp that mapping the translation will be simple meaning that you can actually use the c experience. Now why this exercise? The main reason is that I want to build my own object system!! ... Just kidding, When I coded in C i just recognized that stuff I wanted that is not that hard to do in lisp is difficult in C due to the inferior pre-processor. Thats It, I wan't to add a lispy pre-processor to C,C++,Java,C#,...

I choosen the Qi flavor of lisp because, well, I think it is the best base to start from and I wanted to learn it

Now to mentally sell this stuff and have fun I would need to implement extensions to C that makes a difference e.g. with some batteries included. Ok here are some ideas,

1. Meta Object System, He he, I'm not kidding here, look at Lisp, they have actually abstracted out the action of dealing with objects in a tool that constructs object systems - this is a neat idea and why not bring that over to the C family so that everybody easily can make their own home brew object system. (Python seem to have similar system as well and you may find more examples)

2. Loop macro facilities This is what I have been discussed and worked on during some time now.

3. Static type checking Tools exists today but I would like to have better meta facilities to explore new inroads and versions of it and better integration.

4. Custom types, deduction of types. Qi Has an advanced type system, cool if we can use some of that.

5. structs vs file-systems Structs in C are a much like file system without the tools of the file system. Well Using C++ we do have the potential of a file system but it would just be a cool idea to just tighten these two metaphors together to see what it brings still keeping it light weight. The idea is that we work with the struct incrementally like in a shell we consider files, we consider directories, we don't consider content, we just manages the content structures and the metadata of the structures and at a point the struct is set in stone e.g. this is a metastuff to define data structures. Not to manage the content.

6. Different views of code If you want to study very difficult code because the problem is, difficult. The notation system is very important for your success. Long variable names and whitespace is not well suited for this. Hard stuff just demands that the patterns inside in it can be recognized and matched by your experience. For these use cases I need some tools to design the notation systems. My idea here is to use a simple notational macro facility and a tool to layout sheet cheets information well alligned in a column to the right of the code. E.g. I do not want to use tool tip technology, I want to layout the translation information well visible in a column to the right. Basically a macro is associated with it's usage, it's usage for the first time, it's usage after beeing not used for x lines of code and so on. The idea is that the definition of these macros should always be visible according to some logic

7. Transfer of Meta Information True Openness will allow users to tag their information and let these tags transfer through the system to basically do more with your data. Think of associating each byte with a meta information, have tools to define how all basic operations handle the flow of information. This framework can be used if you want to track your content, for security and so on. It is wothless for doing DRM cause the user is in power of it and this is why it is interesting </b>

He he in 10 years I will be finished with this and it will rule the world.... No, of cause that will not happen, but It is so fun blowing in the wind and what is important is progress and that my friend, is all us blowing the wind.

I'm falling, Touching ground, Over and Out

CTRL-w

I'm using emacs, but it has it's drawbacks. When editing this blog I tend to accidentally hit ctr-w. If there is only one open tab in firefox, bam!, firefox quits and I cannot find the text in the history. I Looked around for a fix, looked at firemacs, but decided to wait for a new upcoming plugin that will let you use emacs directly instead, e.g. EmbeddedEditor . Meanwhile I will make sure to have one extra tab open or just paste in the text

Oh well here are some Loopy cranky stuff: Consider,

```
(for X in (li L)
(for Y in .X
(sum Y)))
```
Can you see two possible interpretations of sum?

Here is one:

```
(for X in (li L)    (A)
(for Y in .X    (B)
(A sum Y)))
```
E.g. yield the sum of all Y in the list of list. And of cause this will yield the sum of the elements of the last list in the list of list L,
```
(for X in (li L)    (A)
(for Y in .X    (B)
(B sum Y)))
```
(we could have skiped B here) Permutations could be expressed as
```
(for X in (li L)    (A)
(for Y in .X    (B)
(coll ((A X) B coll Y)))
```
This is a complex construct but to dechiffer it we could have used the notation,
```
(X B coll Y)  ==  (update in B (coll.X Y))
```
E.g, coll.X is multiple collectors parametrized by X and define in X defining scope, A. Each of coll.X is updated in scope B by the value Y.

Lets put in a mental overdrive, lets talk like spook, and walk the talk.

Consider walking in a tree, Personally I'm very found of doing that by recursion, these two models fits so nicely together. When walking and you are at function G, the stack trace could be represented by for example "FHFFHHGGGHG".Do you see where I'm heading with this observation?

```
(define atom-12
X  ->  [atom-12
(FromStart          Here             sum 1)
(FromLatestFunction Here :default -1 sum 1)])

FromStart            = ^*
FromLatestFunction   = F[^F]*
```
permutations can also be used by using (Matcher Var) eg, parametrize by Var defined in the scope defined by the Matcher. See, using abstractions makes us trekkers in a larger universe then we set out to explore in the beginning. You can combine any of the current knowledge about how to do matching on sequences and use that as a Matcher, you can use perl regexps or whatever. The simple un optimized implementation is to just use scopes in the stack as objects that you can duck-type in these constructs, define a mechanism to label scopes and then just use pattern matchers and some simplifying notation for the most obvious and common cases.

A matched objects has a start, that start is what you would like to use to define the needed scope and associated variables. Another possibility of matcher definitions is to start at the current scope and move backwards. One should also consider cases with multiple matches of the same pattern and some way to handle this like doing stuff in multiple channels meaning that secondary collectors and accumulators get a distributed just like in matrix algebra

```
A*(a + b + c)  -> A*a + A*b + A*c
```

Calling Earth / Good Bye / Over and Out

Cool Cranks

I'm mayby too kind to people, cranky people have a tendency tend to want my company (temporally), and you now what, that's cool.

The thing is I listen to people I meet and I always try to deliver food for thought, play along in dialogs with my character of the moment simply because it makes a difference.

You see, I,ve got this idea, that If I (at a reasonable rate) answer someone a little cranky, which usually is quite intelligent but by some kind of accident or sickness went out on a limb, they will become a litle less cranky, a little less sad, a little less dangerous.

And you know what, some of these dialogs become soo cool that I keep them as funny/deer/cool memories.

This happens maybe ones a year to me so it is not a big effort.

Take Care

81 older entries...