12/23/2009

Major breakthrough in image processing

In fact, this breakthrough is based on Haskell.

Find all the resources here:


Or just go right away to this YouTube video to get a quick idea:


This lecture was prepared upon invitation by the local research team on active vision. They asked me to hold a lecture on "Bildverarbeitung in Haskell" (engl.: "Image processing in Haskell"). Here I should mention in passing that their invitation was about an Xmas party kind of workshop. Accordingly, my lecture is short and somewhat contrived, but see for yourself. More importantly, all the shown Haskell code is short, well-typed, and available for download, but totally useless.

Technically, the shown, 4th encoding of "image processing" encodes "Bildverarbeitung" and potentially other words, letter by letter, in the type system. The overloaded functions for the letters of the alphabet can only be composed (by means of ".") to form words that are known to the type system. Hence, type checking is spell checking. Quite obviously, this particular approach is horrendously verbose, inefficient and limited. The encoding is good however in so far that it allowed me to illustrate the notion of Haskell's Triangle (as opposed to Pascal's).

Merry Xmas and a Happy New Year!

Yours,
PF

11/29/2009

OOPM-Vorlesung auf der Treppe

Im folgenden fasse ich die Abläufe zusammen, welche ultimativ zu der "Treppenvorlesung" in der OOPM-Veranstaltung am 26.11.2009 geführt haben. Alle die dabei waren, hatten trotz des schlechten Sounds und der Besetzung doch auch ein bisschen Spass neben all der harten Materie?

_______________________________________________________

25.11.2009, 13:03, Post von ASta-Vorsitz in Newsgroup infko.general

"Die VV [Vollversammlung, Anmerkung PF] aller Studierenden hat soeben beschlossen, dass der Audimax (D 028) besetzt wird."

_______________________________________________________

25.11.2009, 13:39, Reply von PF in eben dieser Newsgroup

"Was ist die Semantik dieser Aktion insbesondere in Hinblick auf die Frage, ob damit grosse Vorlesungen im D 028 bis auf weiteres abzusetzen sind?"

_______________________________________________________

25.11.2009, 17:45, PF veröffentlicht eine Blogpost zum Thema


Ein bisschen Wertung extra:

Mein Verständnis war, dass die OOPM-Vorlesung nicht ausfallen sollte, da es sich bei der Besetzung des AUDIMAX nicht um einen allgemeinen Streik handelt. Vielmehr schien es im Sinne der Organisatoren und aller Studenten zu sein, dass Lehrveranstaltungen weiter stattfinden. Allerdings kann eine Grossveranstaltung wie OOPM natürlich nur schwer einen anderen Raum finden. Somit ist die Besetzung des AUDIMAX nahezu effektiv ein Ausschlusskriterium für die Durchführung der Veranstaltung.

... abgesehen von Alternativen, die in der Blogpost erwähnt wurden.

_______________________________________________________

25.11.2009, 22:39, Reply von ASta-Vorsitz in eben dieser Newsgroup

Meine Zusammenfassung: Der AUDIMAX wird insbesondere während der OOPM-Veranstaltung für einen anderen Programmpunkt benötigt.

_______________________________________________________

26.11.2009, ab 9:00, diverse Anrufe durch PF

- Raumplanung Campus; Nachfrage nach Ersatzraum; Bescheid negativ.
- Leitung der Mensa; Nachfrage nach Erlaubnis zur Austragung: Bescheid negativ.
- Hausmeister; Nachfrage nach Lautsprechersystem; Keine rechtzeitige Verfügbarkeit.
- ...

_______________________________________________________

26.11.2009, 9:43, Post von PF in Newsgroup infko.oopm

Bekanntgabe der Treppe neben AUDIMAX als Austragungsort

_______________________________________________________

26.11.2009, 10:21, Beginn der Vorlesung mit 6 Minuten Verspätung.

Die Verzögerung war wie folgt zu erklären:
- Besorgung und nicht-trivialle Aufstellung des Projektors
- Besorgung und Tuning eines eher ungeeigneten Lautsprechersystems
- Interaktion mit den Teilnehmern

_______________________________________________________

Weitere Links

- Kurzfilm (YouTube)
- Langfilm (Webseite der Lehrveranstaltung)

Gruss,
PF

11/25/2009

Vorlesung kämpft um ihre Austragung

Durch eine Vollversammlung der Studenten wurde heute auf dem Campus beschlossen, dass unser, über alles geliebte AUDIMAX (grosser Hörsaal D 028) besetzt wird. Dies zu tun, ist das demokratische Recht der Studenten und deren Argumentation ist anderswo verfügbar. Ich werde mich hier dazu nicht weiter äussern.


Allerdings überlege ich gerade, ob und wie diese Aktion meine donnerstägliche OOPM-Vorlesung in eben diesem Raum (follow @oopm, siehe Link hier http://userpages.uni-koblenz.de/~laemmel/oopm0910/ ) beeinträchtigt.


Da weder AStA noch die Uni-Leitung, noch irgend jemand anders mit Autorität, so weit ich weiss, bisher klare Empfehlungen gibt, was anstehende Veranstaltungen im D 028 angeht, versuche ich mal etwas OOPM-spezifisches -- in der Hoffnung dass ich nicht unwissentlich meine Beamten- und demokratischen Pflichten verletze:


  • Gelingen und Kooperation durch die Besatzungsmacht vorausgesetzt, findet die morgige OOPM-Veranstaltung im D 028 in unkonventionellerer Form statt.

  • Ich höre gerade, dass es Bemühungen für einen Ersatzraum gibt, aber das bleibt abzuwarten. Ich ziehe natürlich auch gern mit Ihnen auf eine andere Ecke von Koblenz um und kann wieder 3-4 Leute in meinem Auto mitnehmen.

  • Wenn die Besetzer des D 028 mir freundlicherweise etwas Platz auf der Bühne lassen und ebenfalls die Benutzung der Technik nicht behindern, dann soll es am Ende der Veranstaltung einen attraktiven Preis für den qualifiziertesten (aus OOPM-Sicht) Besetzer oder Herumsitzer geben. Ich werde den Gewinner demokratisch selbst auswählen.

  • Ich sehe das wirklich als eine Chance für die Besetzer, etwas Fundiertes über die Programmierung von imperativen Datenstrukturen zu erfahren. Lassen Sie sich das nicht entgehen! Wenn Sie interessante, thematische Bezüge zu dem Besetzungsthema herstellen können, werden wir uns alle freuen.

  • Gelingen und Kooperation durch die Besatzungsmacht vorausgesetzt, werde ich die Vorlesung wie immer aufzeichnen und verlinken. Dies kommt doch vielleicht auch dem PR-Ziel der Besatzungsmacht zugute? Ich könnte die Kamera so ausrichten, dass die Situation im Raum erfassbar ist. Durch Auflösungsmanipulation würde ich Ihre Persönlichkeitsrechte wahren -- ausgenommen Sie treten nah an meine Kamera.

  • Falls es nicht zumutbar für die Besetzer ist oder sie den Ablauf unserer OOPM-Veranstaltung zu sehr stören, schlage ich vor, dass wir in das Treppenhaus neben D 028 umziehen. Dort könnte man eine Projektion von vielen Seiten einsehen.

  • Falls die Besatzungsmacht auch anreichende Gebiete einnimmt, dann lassen Sie uns in mein Büro verlegen. Dort gibt es eine grosse rote Couch und 4 weitere Sitzgelegenheiten (die altmodischen Riesenlautsprecher nicht eingeschlossen). Wir können dann nebenbei an einem Wetten Dass - Beitrag arbeiten. Ich hoffe, dass es keine baustatischen Gründe gibt, die gegen diese Ausweichvariante sprechen.


Gruss,

PF/RL


11/22/2009

Countdown with Prolog

I was just going through G. Hutton's Haskell code for the (simplified) countdown problem which I plan to mention in a class on functional programming. The aforementioned code is discussed in the wonderful book "Programming in Haskell". The development of the brute-force model looks verbose and detouring however. (This is probably because the problem serves some pedagogical purposes.) Here is a simple Prolog-based solution. It is much faster than the brute-force Haskell-based solution, also because some optimizations are naturally achieved by a straightforward solution. I am sure others have tried this because it is so strikingly obvious.

Suppose you want to compute a given number X, by applying the arithmetic operations addition, subtraction, multiplication, and division to numbers picked from a given sequence of positive natural numbers, while using any candidate at most once, and all intermediate results must be positive natural numbers again.

For instance: 765 = (25-10)*(50+1)

?- solve([1,10,25,50],765,Ts).
Ts = [ (25-10)* (1+50), (25-10)* (50+1), (1+50)* (25-10), (50+1)* (25-10)].

% Solutions Ts for countdown problem with numbers Ns, result X

solve(Ns,X,Ts) :-
 findall(T,(
   sublist(L,Ns),
   permutation(L,P),
   compute(P,T),
   X is T
 ),Ts).


% Generate all sublists of a given list

sublist([],[]).
sublist(Z,[H|T]) :-
 sublist(Y,T),
 ( Z = Y
 ; Z = [H|Y]
 ).


% Generate all permutations of a given list

permutation([],[]).
permutation([H|T1],L) :-
 permutation(T1,T2),
 append(T2a,T2b,T2),
 append(T2a,[H|T2b],L).


% Complete sequences of numbers into arithmetic expressions

compute([R],R).
compute(As,T) :-
 As = [_,_|_],
 append(As1,As2,As),
 As1 = [_|_],
 As2 = [_|_],
 compute(As1,T1),
 compute(As2,T2),
 ( T = T1 + T2
 ; T = T1 - T2
 ; T = T1 * T2
 ; T = T1 / T2
 ),
 R is T,
 R > 0,
 integer(R).




Regards,
PF

9/11/2009

PPDP 2009 over and Prological SYB code goes live

Just tried to send an email to what I thought would be the cafe mailing list of the Association of Logic Programming (ALP). My message bounced. Sigh! Anyway, here is the message and below you also see the content of the README file for the tiny code distribution for scrap[p]ing boilerplate prologically.

From: Ralf Laemmel rlaemmel@gmail.com

To: Alp-cafe-request@babel.ls.fi.upm.es

Date: Thu, 10 Sep 2009 22:57:11 +0100

Subject: post-PPDP 2009 greeting

Not sure whether this mailing list is actually working (because I haven't seen any traffic since June when it all started) but I thought it couldn't hurt to send a short post-PPDP 2009 greeting. António Porto, Francisco J. López-Fraguas, Pedro Quaresma, Ana Paula Tomás, and their collaborators have put together a great conference event. The program was really packed; perhaps even a bit stressful :-) I would have loved to interact a bit more during additional breaks and panels.

For what it's worth, I have uploaded the SYB sources for my invited talk to a google code repository.

http://code.google.com/p/strafunski/source/browse/#svn/trunk/ppdp09

Regards,
Ralf




README follows


These are sources that I release with my PPDP 2009 invited talk.
Please understand that this is *illustrative* code.
I have merely sketched certain aspects.
It is really just illustration for a talk!
It may be useful though.

Here is quick inventory of this file system:

shared: basic lib functionality used by several "experiments"
* holp: higher-order logic programming convenience
* syb: very little to be shared of SYB among experiments
* lists: (mainly higher-order) list processing
* meta: metaprogramming convenience
* vars: operations on lists/sets of logical/nonground variables
* msft: test data

experiments: experiments or illustrations used in the talk
* basic: the most basic SYB experiment
* backtracking: illustration of backtracking traversal
* nonground: illustration of traversal of nonground terms
* bidirectional: crazy inquiry into multi-mode traversal
* optimized: a generative and optimized model of SYB

All the experiments consist of two parts:
* lib: all library (generic) functionality
* app: specific illustrations (using msft typically)

9/10/2009

Decreasing salaries with addition

There are some parts of my PPDP 2009 invited talk that didn't make it into the short paper for that talk. In particular, I played a bit with the feature interaction of traversal (SYB) and using predicates in different modes. The use of multi-mode predicates is one of the exciting aspects of logic programming. (It is somewhat disputed how crucial or useful it is, but it is impressive/expressive anyhow.) For instance, beginners are always surprised to see that one can use append/3 to both .... well ... append but also take apart lists.

So I considered the question how to use such multi-modeness, if at all, perhaps even usefully, in the context of traversal programming. Here, we would expect traversal predicates to serve the normal forward direction (traverse first argument, compute second argument) and the unusual backward direction.

Let's consider the following, recession-inspired scenario for the sake of the argument:
  • We certainly know how to increase salaries (say by 1 $) everywhere.
  • However, there is pressure that we need to decrease salaries lately.
  • We wish to run an increasing traversal backwards to decrease salaries.
Let's start with the increase-only traversal.

incSalary(X,Y) :- everywhere(mkT(incSalary_),X,Y).
incSalary_(salary(S1),salary(S2)) :- add(S1,1,S2).
add(X,Y,Z) :- Z is X + Y.

everywhere/3, mkT/3 are defined in a straightforward manner:
(See the PPDP 2009 paper for details.)

% Transform everywhere (bottom-up)

everywhere(T,X,Z) :-
gmapT(everywhere(T),X,Y),
apply(T,[Y,Z]).

% One-layer traversal

gmapT(T,X,Y) :-
X =.. [C|Kids1],
map(T,Kids1,Kids2),
Y =.. [C|Kids2].

% "Make transformation"

mkT(T,X,Y) :- choice(T,id,X,Y).

% Left-biased choice

choice(F,G,X,Y) :-
apply(F,[X,Y]) ->
true
; apply(G,[X,Y]).

% Identity

id(X,X).

The above development will not be able to decrease salaries (by traversing "backwards"). Quite obviously, we need an add/3 predicate that can go backwards. That's easy enough. The following revision of add/3 can cope with any combination of 2 argument positions being instantiated with numbers.

add(X,Y,Z) :-
( \+ var(X), \+ var(Y), Z is X + Y
; \+ var(X), \+ var(Z), Y is Z - X
; \+ var(Y), \+ var(Z), X is Z - Y
).

We need to do a few more things before backward traversal works. In particular, one-layer traversal is not prepared to deal with an uninstantiated first argument. There are actually two reasons for an uninstantiated, first argument to make sense. Reason 1 is that we might be traversing terms with logical variables. Reason 2 is related to our current endeavor: backward traversal with the 2nd argument being instantiated and the first one being variable. So here is our blow that resolves both issues:

gmapT(T,X,Y) :-
var(X), var(Y),
Y = X
;
\+ var(X),
X =.. [C|Kids1],
map(T,Kids1,Kids2),
Y =.. [C|Kids2]
;
var(X), \+ var(Y),
Y =.. [C|Kids2],
map(T,Kids1,Kids2),
X =.. [C|Kids1].

However, this is still not enough. We also need to make fit the traversal scheme everywhere/3. We need to adjust the sequential order of the body of everywhere/3 depending on instantiation. Please note that the resulting traversal is still to be considered a bottom-up traversal (which is good news!).

everywhere(T,X,Z) :-
Apply = apply(T,[Y,Z]),
Recurse = gmapT(everywhere(T),X,Y),
( var(X), \+ var(Z) ->
Apply, Recurse
; Recurse, Apply ).

That's it, we can do backward traversal and hence decrease salaries with incSalary/2.

PF

8/27/2009

Locked into a juicy apple

A bit more than 2 years ago I got bored by my usual XP+cygwin box (and I had given up on Linux anyway), and thought I would try a mac. Meanwhile I have tried macs a lot, spent a fortune on software. Sigh, I am having quite some hardware issues, but fortunately everything so far was covered by warranty or apple care. Anyway, my house is the perfect Mac Family place: several MacBook[pro]s, a time capsule, an iPhone, several editions of all the basic software (iWork, iLive, Mac OS -- Snow Leopard pre-ordered), and a good deal of pay and freeware (e.g., several kinds of screen/video capture/recording).

Here is the problem: I have gotten addicted to apples.

So let me self-diagnose whether I can get rid of that addiction:
  1. I write texts with web apps or with LaTeX. Other Oss can do this too.
  2. I use .key for slides. Some bits would get lost in translation to .ppt[x].
  3. iTunes seems to be platform-independent, no?
  4. iPhoto. Who needs that? I am using Picasa above it anyway.
  5. iWeb. Why did I ever start using it? It is sooo constraining anyway!
  6. I have some minor utilities that I would need to find counterparts for ...
  7. Sure my kids will miss PhotoBooth.
  8. I will miss iMovie; it helped me to understand that I need 4 GB.
Based on such preliminary reflection, I claim that there is an Ok transition path to W7. It's good to have a choice.

PF

8/26/2009

SWI-Prolog's Java Interface JPL

I would like to mix Java and Prolog code on a number of occasions. Together with a student of mine (Joachim Pehl), we just convinced ourselves that the JPL library of SWI-Prolog is really cool. Basically JPL allows you to call Prolog from Java and Java from Prolog.

But the question is, of course, how easy is it and can you easily go back and forth. For instance, can we call Prolog from Java and call back Java from Prolog and share Java state throughout? Sure it works!


PROLOG PORTION FOLLOWS


% This library is all we need to call Java from Prolog
:- ensure_loaded(library(jpl)).

main
:-
% Create an object
jpl_new(class([],['Test']), [], X),

% Printing objects is like printing object ids
write(X),nl,

% Access a field of the object; happens to be static
jpl_get(X, state, Y),

% Prints whatever the state's value is
write(Y),nl.


JAVA PORTION FOLLOWS


// This jar is all we need to call Prolog from Java
import jpl.*;

public class Test {

public static int state = 0;

public static void main(String[] args) {

// Consult a Prolog file
Query q1 = new Query("consult", new Term[] { new Atom("Test.pro") });

// Prints boolean success/failure value
System.out.println(q1.query());

// Affect static field.
// This way we can see whether Prolog sees the same JVM instance.
Test.state = 42;

// Invoke a predicate
Query q2 = new Query("main");

// Prints boolean success/failure value
System.out.println(q2.query());
}
}


BUILDING and RUNNING BOTH

javac -cp $CLASSPATH:/opt/local/lib/swipl-5.6.62/lib/jpl.jar:. Test.java
java -cp $CLASSPATH:/opt/local/lib/swipl-5.6.62/lib/jpl.jar:. -Djava.library.path="/opt/local/lib/swipl-5.6.62/lib/i386-darwin9.5.0" Test
true
@(J#00000000000016809476)
42
true


SO WHAT?

Hence, we can start a Java app, have it start a Prolog engine and consult the Prolog portion of our app, then delegate from Java to Prolog, where we in turn call back on Java in the same JVM and can access some state that we left off in Java before we were calling Prolog.

PF

8/25/2009

The same guy as "Grammarware, Haskellware, XMLware"

What's wrong with the old blog?

I have been using http://blogs.msdn.com/ralflammel/ for some blogging until now. I created that blog when I was still a MS employee and it may be inappropriate to keep using this blog forever. Not that I have any plans to say anything controversial about MS in the future, but some of my personal opinions may be inappropriate on a blogger's domain that is mostly used by MS employees with often more MS-related content. Actually I really like some MS technologies, and I think I can speak about them much more easily when not being hosted on msdn.

Why "Professor Fish"?

I was looking for a content-free title and so I recalled that one of the more offensive students in one of my courses called me a "fish" in a newsgroup. I actually like that name because I like the sea and I like to swim and I like sea food. Anyway, the name is still better than "grammarware, haskellware, xmlware" (the name of my msdn blog) because I also want to (potentially) blog about non-CS stuff.

See me on Twitter.
http://twitter.com/notquiteabba

Regards,
PF