msgbartop
Just another weblog
msgbarbottom

27 Nov 09 Random Things

It’s been a while since the last update. Here’s a small update on what I’m thinking about various stuff.

Prototype

Gameplay is okay I guess. Nothing I would spent too much time on though. It looks a lot worse than GTA 4 though (same as Crackdown).

Resident Evil

Seems to be lots of fun and some nice graphics, too.

Red Faction: Guerrilla

Some weird texture filtering issues and the presentation doesn’t knock off my chair (terrain popping and other ugliness), but multiplayer is loads of fun with friends. Physics isn’t completely stable though. I played the game for one hour in MP with friends and there were quite a few cases where geometry dropped through the floor with enough pressure from above (after destroying a building).

Brüno

A bad and quite stupid movie (Ali G in Da House is probably the only movie I kinda like that stars Cohen). If you haven’t watched it already, don’t >_<

Shadow Complex

I bought shadow complex a few weeks ago and I have to say that it is an awesome game. I read somewhere that the developer used the Metroid series as inspiration and it shows. It’s really fun to play and quite addictive. The graphics are pretty awesome (it is using the Unreal 3 engine) and the whole presentation is pretty polished. It certainly is worth its 1200 gamerpoints

Summing Formulas

A month ago I was doing some exercises in an analysis book (Königsberger) and found a nice/interesting problem:

Prove that if we denote of the sum of the numbers 1 to n to the p-th power by  S_n^p = 1^p + 2^p + ... + n^p , then the following equation by Pascal holds:  (p+1) S_n^p + \binom{ p + 1 }{ 2 } S_n^{p-1} + \binom{ p + 1 }{ 3 } S_n^{p-2} + ... + S_n^0 = (n+1)^{p+1} - 1

It can be used to get recursively/iteratively get formulas for sums of higher powers of numbers.

This is interesting because the proof doesn’t need any advanced maths (like eg the Euler-MacLaurin formula, which can be used to show this, too).

You can download the proof and a few examples here.

Cheers

19 Oct 09 Extracting Information from StudiVZ

Some time ago somebody stole 1 million data records from StudiVZ, the German Facebook clone. I’m not exactly sure why people call the person a hacker who stole data, because it appears he simply wrote a tool that harvested the publicly available data from StudiVZ (which everyone with an account can view).

People on StudiVZ share all their data by default—contrary to Facebook which values a person’s private data a lot more. Thus by simply opening each profile from a dummy user and processing the HTML data from StudiVZ one can extract a lot and some more information from random people who probably don’t even know about it or don’t care.. so I’m not sure about the stealing part.

Apparently there are some captcha’s when you start browsing searches beyond a few pages. I guess that is where the hacking part comes in, because getting around a captcha probably constitutes hacking—maybe?

Anyway I think part of the media coverage is a bit ridiculous because anyone can write a simple harvester in an hour or two. It took me one and half hours, so I think I’m on the safe side with this estimate and I didn’t really have a clue about this stuff before either.

Since I don’t want to “hack”, I’ve only written a very tame harvester. It connects to your personal StudiVZ account, and retrieves the name and profile ID (and thus profile URL) of all your friends in the “Meine Freunde” pages.

It could do a lot more with that like retrieving everybody’s birthday or random pictures, but I’m too lazy to code that because you use the same pattern for extracting data over and over again and it stops being interesting quite fast.

You can download the project here. It is a one file C# project. I’m releasing it under GPL (whatever).

It’s really easy to explain how it works:

  • It uses System.Net’s HttpWebRequest and HttpWebResponse to get (and post) web pages.
  • StudiVZ (like every other portal) uses cookies, so I create a CookieContainer and use it in every http request.
  • There are a few hidden values that StudiVZ expects during login. I’m retrieving them from the main page using custom built regular expressions. I’ve found a handy AJAX tester for .NET regular expressions. It was really useful for building the expressions and debugging them. (BTW you can find all URLs I used in the comments.)
  • After login I use the same pattern: get page & parse using regex for everything.
  • Visual Studio has an awesome “HTML Visualizer” for strings. It displays the content of a string as HTML page, which is really nifty if you’re doing anything related to HTML processing.

The code is quite ugly. Well, it’s not production code and this is only meant as a proof of concept.

Also note that I have at most violated the AGB of StudiVZ and not committed any criminal acts and I’m not planning to sell my friend’s profile IDs or data either :-)

Maybe someone can extend the code and make it more useful. I guess it would be fun to automatically download all your pictures (including tags) and feed them into flickr or picasa… but someone else can do that.

Cheers,
Andreas

Tags: , ,

17 Oct 09 My Bachelor Thesis

Screenshot of Utah

Screenshot of Utah

For the last two months I have been working on my bachelor thesis at the Chair of Computer Graphics and Visualization. It is about “Multi-Tile Terrain Rendering with OGL/Equalizer”´.
The chair has a very nice Direct3D 10 terrain rendering engine and they want to run it at the newly founded KAUST (King Abdullah University of Science and Technology´) in a massive CAVE environment. A CAVE is a room whose walls are actually screens.
The CAVE at KAUST even supports stereoscopic rendering. Thus in total 12 views can be rendered to.

My job was to port said terrain engine from Direct3D to OpenGL and afterwards to the Equalizer framework, which is an open-source framework for parallelizing OpenGL applications.

You can find/download an online version of my bachelor thesis here. I’ll upload the LaTeX at a later date and update this post.

I’ve spent the last months writing about all this, so I don’t feel like talking about the thesis itself anymore. Instead the remainder of this post will contain a post-mortem of it.
(more…)

Tags: , , , , , ,

18 Aug 09 More Book Reviews and re: Design Patterns

Pattern-Oriented Software Architecture – A System of Patterns (PoSA I)

I’ve finally finished Pattern-Oriented Software Architecture – A System of Patterns and I want to say a few words about it.
First I don’t think, it’s a must-buy. It’s okay to read (but more about that in a minute) and certainly it can come in handy to look up patterns while developing, but if you have small budget, it’s better to get it from a library.

The book can be roughly divided into 4 parts: architectural patterns, design patterns, idioms, “trivia”.

The chapter about architectural patterns is the most interesting,  where as the chapter about design patterns is okay, too, but also borrow or expands upon lots of concepts from the GoF book. The idioms chapter only contains one idiom (think small, language-specific “design pattern”, e.g. reference counting in C++).
The “trivia” part contains information what pattern are, who came up with the idea, influences, the community, yada yada. The most interesting topic being the community and links in there.

The book itself is quite boring to read and the patterns are described in endless detail, which is good, if you want to look things up and avoid common mistakes. On the other hand this makes it a book, you should not read front to back, because it doesn’t really make sense and you won’t get a lot out of it either. (I actually read it front to back, and from that experience I draw my advice :-| ) Just skim over the patterns, until you find something you don’t know and then read the paragraphs that are interesting until you think you understand the pattern and then read some more to verify that you really understand it, but you can probably skip 40% (or more) of the text, if you just want to learn about new patterns and not go into all the details.

Next I’ll try to write a few words about each pattern (so I´ can look up the pattern here instead of in the book)´.

Note: I just found an awesome page, http://vico.org/pages/PatronsDisseny.html, that contains information about all patterns in the book, so it doesn’t make sense for me to write about each and every one of them.

Architectural Patterns

  • Layers
  • Pipes and Filters
  • Blackboard
  • Broker
  • Model-View-Controller
  • Presentation-Abstraction-Control
  • Microkernel
  • Reflection

Design Patterns

  • Whole-Part
  • Master-Slave
  • Proxy
  • Command Processor
  • View Handler
  • Forwarder-Receiver
  • Client-Dispatcher-Server
  • Publisher-Subscriber

Idioms

  • Counted Pointer

Now that I’m done with this, I want to share a few useful resources mentioned in the book:

Personally idioms are very interesting for me, too, because the day-to-day coding work is in a specific language and idioms are exactly about that.
A little googling already turns up lots of useful sources. For example:

There are a few more pattern books that I plan to read, so let’s see how that turns out..

A Manual for Writers of Research Papers, Theses, and Dissertations

This is an awesome book, that explains a lot about how to write research papers and also about all the little details you should pay attention, too. It’s a good read – I spent 1.5 hours a day for a bit more than a week to read through it – and I think it’s going to be quite useful, when I start writing my Bachelor Thesis in a few days.

I’m currently writing some ANTLR grammar and StringTemplate stuff and I might write something about that, too, on the weekend.
I’m not sure I’m really happy with ANTLR, but it’s probably the best thing out there at the moment, but I’m totally in love with StringTemplate, even though you might say it has some rough edges, too.
But more on that on another day.

Over and otu,
Andreas

Tags: , , , ,

18 Jul 09 Fast Forward

I’ve quite a few things I’ve wanted to write about a long time ago and I actually started working on them and taking notes, etc. but never found time for one reason or another to write and publish the actual posts.
So this is meant as fast forward of all these text bits.

Movies and Games

Memento

One awesome movie. I’ve seen it twice already and I still love the movie and its plot. I don’t want to spoil too much of the story, but some will probably inevitable.

A few bullet points:

  • Telling a story in reverse is pretty cool in itself and perfect for the movie
  • I wonder if one could use this kind of plot for a game, too, but it would make the plot quite linear because the player could only do things that won’t change the outcome of the future (i.e. what he has already played).
  • If the game is linear though and goal based it could be possible easily because you would replay it like a movie. If it’s plot-centric, it could be fun and create a kind of suspense similar to Memento.
  • Fahrenheit would be a game that is plot-centric like that..
  • The movie depicts a chaotic system: small imprecision leads to huge consequences (”Don’t believe his lies”).
  • One of the impressions I liked most is the way you have to constantly reevaluate everything you have seen so far because of some new piece of information from the past which totally changes the whole movie a whole time.
  • It’s kind of difficult to remember the movie at first because the human brain is not used to this presentation of causality (seeing the effect before the cause).
  • The movie gets you thinking about what defines yourself – what are you if you can’t remember things anymore and how do you define yourself through your memory.
  • A few weeks ago I read a psychology case book that contained a case similar to Memento. Alcoholics sometimes damage their brain through alcohol abuse and lose all ability to memorize anything new. Their long-term memory only works up until some point of time and after that they won’t remember anything. They constantly live at that moment and will be lost forever.

Fahrenheit

Fahrenheit is a pretty cool. Like many movies it is excellent for 90% of the playtime and then it suddenly starts to suck and/or becomes very weird story-wise.

It’s not a typical game as more a cinematic experience that does a good job at combining gaming aspects with a very advanced plot and some pretty awesome action scenes.

I’ve really enjoyed the game and just like Omikron: The Nomad Soul (an earlier game by developer Quantic Dream) it’s positively refreshing and different.

Some random notes:

  • Vista compatibility sucks. I had to download a hacked binary to make it start at all on Vista. Otherwise it ran fine except for one crash that was due to my notebook overheating slightly.
  • Like in many other games you can’t skip cut scenes or dialogs easily which is annoying if you just want to replay a chapter up to a certain point
  • More annoyingly it seems that if you replay an earlier chapter, you have to replay the ones following it, too. Be careful with that :-|
  • As said – the story is awesome until you have played 90% of the game then it turns a bit into being on the bizarre side of things´.
  • Also “Hiding at Tiffany’s” is awful. If you ever play the game be ready to replay it a few times:
    You have to hide at Tiffany’s place from someone who is searching for, and you have 30 seconds or so to find a hiding place, after which the person starts searching for.
    The problem is that you don’t know where the person will search for you and if you are caught, you obviously won’t see where he would search afterwards, so you have to replay the same part quite a few times if you have bad lack and I think it was one of the more frustrating parts.
  • Zero Punctuation has a good review of the story issue of Fahrenheit hidden in his review of Condemned 2, it is also funny, so it’s certainly worth watching :)
  • The way the controls work in Fahrenheit is also pretty interesting. The wikipedia article about Fahrenheit has a good description of it in its Gameplay section.

Books

The Pragmatic Programmer

Last year I think I wrote that I had started reading “The Pragmatic Programmer“. I actually finished reading it quite a while ago, but here are a few remarks about it:

  • It’s a good and nice read and the book contains lots of helpful suggestions and things to keep in mind when coding or designing software or even just when you want to communicate with co-workers, etc.
  • It’s a “common sense” book – similar to Code Complete – and when you read it, you’ll often think “that’s straight-forward” or “that’s the logical thing to do”, but it still valuable to have all that common sense written down somewhere and to be able to look at it now and then in search for inspiration.
  • It’s not as useful as Code Complete though, which was a real eye opener (and still is) and it’s not going to improve your coding style a lot or the way to think about code design.

OpenGL Superbible

I’ve bought the “OpenGL Superbible” and it’s a pretty good book if you want to learn OpenGL or read a light text about certain advanced OpenGL features before rolling up your sleeves and digging around in the extension specs. It’s written like a big and pretty complete tutorial and the latest edition is a lot better suited for the new features than, say, the latest edition of the OpenGL Programming Guide (which is pretty horrible – I’ve read through the sixth edition and it’s pretty much the second edition plus a paragraph tacked on here and there and long explanations of deprecated features).

The only part of the book that is really, really weak and totally useless is the part about GLSL and shader programming. It contains a short description about GLSL and while the chapter summary mentions functions like glUniform and co, the function is not mentioned anywhere in the chapter nor does it provide even one example on how to set or access vertex attributes or uniforms, which is essential.

If you want to learn about GLSL and shader programming in OpenGL I can only recommend the OpenGL Shading Language and the GLSL language specifications.

Multi-Core Programming

First don’t buy this book. It’s from Intel Press (you can read the book description here) and it’s ridiculously expensive for the content it provides.

I got it for free at university presentation from Intel and have read through most of it in the last weeks and really – if you want to learn about OpenMP and threading techniques and tools, there are better sources available online for free.

Real-Time Rendering

This book on the other hand is awesome – buy it if you are interested in computer graphics and want to understand the underlying principles better.
It’s well-written and presents lots of advanced computer graphics topics in a very understandable way. Especially the chapters about local and global illumination and the physical base of them are very good. It is good starting point to look for resources and papers and the book’s homepage is also pretty useful: http://realtimerendering.com/.

Tags: , , , , ,

07 May 09 Analysis, Cauchy-Schwarz and Reciprocal Sums

Konkrete Analysis

First I want to share some solutions for the exercises of a Maths book. The book is called Konkrete Analysis by Folkmar Bornemann and is written in German as are my solutions for some of the exercises. (I think I cover about 70% of all exercises in the book and pretty much every easy one :-) )

I don’t claim that my solutions are correct and there are probably quite a few (uncorrected) mistakes, but right now I haven’t been able to find any other openly available solutions. Although the book claims to be easily readable without attending the lectures of Professor Bornemann, I doubt that it is possible to do so successfully without being able to do the exercises and while doing so being able to get help or look at possible solutions to find new ideas.

I did all the exercises as way to prepare myself for the exam (it was very successful alas probably not in the most time efficient way), so it also contains solutions for old exams (but those are appended at the end and probably not interesting at all).

You can download the PDF konkrete-analysis-solutions here.

Cauchy-Schwarz and a Problem

The book is quite useful though as was the lecture “Analysis for Computer Scientists” which was based on the book (or vice-versa) and it is probably the single one lecture that has taught most since I started attending Computer Science at university.

One of the many topics (we covered a lot which was one of the nice things) was inequalities and the useful things you can do with them. Especially the Cauchy-Schwarz inequality turns out to be quite useful while pretty basic:

 <a,b> \leq ||a|| \cdot ||b|| with  <a,b> = || a || \cdot || b || when  \exists \lambda: a = \lambda b

Interestingly enough this can already yield results that are quite difficult to obtain otherwise. For example we can easily prove lower or upper bounds that is the existence of a maximum or minimum by applying it.

First we obtain a lower or upper bound (for the right or the left side respectively) and then we can use the equality case to prove the existence of the a minium or maximum.

For example, let’s take a look at this problem:

We have  x \in \mathbb{R}^n, 0 < x, \sum_{i=1}^n {x_i} = 1 and want to minimize  \sum_{i=1}^n { \frac 1 x } .
We simply set  a_i := \sqrt{x_i}, b_i := \sqrt{ \frac 1 x_i } .

Then we get:

 \sum_{i=1}^n { a_i b_i } = \sum_{i=1}^n { \sqrt{ x_i } \frac 1 {\sqrt{ x_i }} } = \sum_{i=1}^n 1 = n
 \leq \sqrt{ \sum_{i=1}^n \sqrt{x_i}^2 } \sqrt{ \sum_{i=1}^n \frac 1 {\sqrt{x_i}^2} } = \sqrt { \sum_{i=1}^n x_i } \sqrt{\sum_{i=1}^n \frac 1 x_i } = 1 \cdot \sqrt{\sum_{i=1}^n \frac 1 x_i }

That is:  \sum_{i=1}^n \frac 1 x_i \geq n^2 .

Now we know an lower bound for the reciprocal sum.
To determine the minimal x vector, we remember to start with:

 a = \lamda b \Leftrightarrow \sqrt x_i = \lambda \frac 1 \x_i \Leftrightarrow x_i = \lambda

We use that with the constraint:  1 = \sum_{i=1}^n x_i = \sum_{i=1}^n \lambda = n \cdot \lambda ,
resulting in:  x_i = \lambda = \frac 1 n .

Generalization

The nice thing is you can go and generalize this finding to more interesting minimization problems as there also exist more advanced versions of the Cauchy-Schwarz inequality´ adding degrees of freedom to play around with´.

Thus it is possible to solve the following class of problems using a slightly more advanced Cauchy-Schwarz inequality:

 x,q \in \mathbb{R}^n; 0 < x, q
0 < \alpha, \gamma < \infty; \beta > 0
\large\sum_{i=1}^n {x_i}^\gamma = \beta
\large min \sum_{i=1}^n \frac {q_i} {x_i^\alpha}

by utilizing

\large \sum_{i=1}^n { a_i b_i } \le \sqrt[p]{ \sum_{i=1}^n a_i^p} \sqrt[p']{ \sum_{i=1}^n b_i^p'} with  \frac 1 p + \frac 1 {p'} = 1

Equality requires the same linear dependence condition as the normal Cauchy-Schwarz inequation.

I’ve only deduced the solution for  \gamma = 1 but it shouldn’t be difficult to adapt it once you get the idea how it works (it’s fairly straight forward).

You can find the whole deduction in the PDF “Minimum of a Generalized Reciprocal Sum”.

For completeness’ sake here are the results for an optimal solution  x^{*} :

\large x_i^{*} = \beta \cdot \frac { \sqrt[1 + \alpha]{q_i} }{\sum_{k=1}^n \sqrt[1 + \alpha]{q_k}}

\large \frac { \left (\sum_{i=1}^n \sqrt[1 + \alpha]{q_i} \right )^{1 + \alpha}} {\beta^\alpha} = \sum_{i=1}^n \frac {q_i} {x_i^{*}^\alpha}

Epilog

Coming up with the solution was actually a lot of fun and quite interesting because I didn’t know it was possible to deduce it this way nor did I know how to do it before. If you read the PDF, I think it’s quite nice how you can play around with the formulas and come up with new things from the Cauchy-Schwarz inequality.
If you are only interested in  x ^ {*} , you can shortcut everything by immediately skipping to the equality case once  p and  p' have been determined and solve for that.
I mainly wrote it all out because I wanted to make sure, that it actually was correct.

If it wasn’t for my Analysis lecture last term, I probably wouldn’t have found this.

Cheers,
Andreas

Tags: , , , ,

12 Mar 09 What I (don’t) like about C#

I’ve been using C# personally quite a bit lately and want to share with you a list of the things I like or don’t about it.

First the things I like about it (compared to C++ and Java sometimes):

  • The out and ref keywords are awesome
    You actually need to use them both when declaring out and reference parameters and in the actual function calls.
    This really avoids confusion and makes the code clearer compared to the way references are transparently handled in C++.
  • a class’s definition and declaration is kept in just one file
    Avid C++ coders will probably disagree with me here, but I really like this way of coding things. It allows me to code faster and also reduces one source of compiler errors. To be honest I would probably go insane when coding in C++ if it wasn’t for Visual Assist’s nifty “Move Implementation to Source File” and “Create Declaration/Implementation” refactorings.
    Likewise one could say that C#’s (or .NET’s) notion of assemblies is better and less messy than C/C++’s compilation units.
  • Properties are simply awesome
    Properties look like normal member variables but you can write your own getter and setter functions and also give both different access levels, so e.g. you can have a property that is public for reading but protected for writing.
    Moreover, you can have C# create the code automatically, so you just end up with a way to specify separate access levels.
  • Read-only variables can be set anywhere in the constructor
    If you know C++’s initialization lists, you will thank god for this feature, because this feature gives you a lot more freedom and again results in more readable code (at least in my opinion).
  • The override and new keywords are really handy
    Again this is a feature to avoid unnecessary bugs because you get warnings as soon as you “override” a method that doesn’t exist.

What I don’t like:

  • No typedefs
    This really bugs me, because the concept of typedefs is a good way to add abstraction to your code and the using keyword in C# only marginally improves the situation, because it only affects the current module.
  • No default/optional parameters
    You have to overload methods instead, which is kind of annoying. I hope this gets fixed sooner or later.
  • No inner classes like in Java
    Passing on references to constructors is annoying and inner classes in Java really help it quite often.
  • No synchronized keyword like in Java
    Again this is a nice-to-have feature because it would  clean up some code.

31 Jan 09 How to make WordPress display Full Text in RSS Feeds

… and why WordPress Moderators are obviously idiots

Today I got an email asking me to enable full text RSS feeds – so far so good, only when I activated the “Full Text” option nothing changed – neither in FireFox, nor in Google Reader, nor anywhere else. Only in Feed Proxy I saw a <content:encoded> tag appear that contained the full text (including html tags), but the description still only contained the excerpt (without html tags).

Before I link you to the thread that made me conclude the statement in the post title, let me quote from the RSS 2.0 specs:

A channel may contain any number of <item>s. An item may represent a “story” — much like a story in a newspaper or magazine; if so its description is a synopsis of the story, and the link points to the full story. An item may also be complete in itself, if so, the description contains the text (entity-encoded HTML is allowed; see examples), and the link and title may be omitted. All elements of an item are optional, however at least one of title or description must be present.

That said take a look at http://wordpress.org/support/topic/190901 – having the problem described above and reading the replies, it just left me with one question:

If Otto42 is a moderator, where does WordPress get its trolls from?

The RSS Specs are pretty unspecific and blurry when it comes to the issue, one can at most point to http://www.feedvalidator.org/docs/warning/DuplicateDescriptionSemantics.html, but the main issue I have is that the rants of this “moderator” don’t help me fix my problem, because Google Reader and FireFox still don’t display the full entries.

A fix for it

If you want to fix it, you can do the following (in WP 2.7):

Open up wp-includes/feed-rss2.php and change

<?php if (get_option('rss_use_excerpt')) : ?>
<description><![CDATA[<?php the_excerpt_rss() ?>]]></description>
<?php else : ?>
<description><![CDATA[<?php the_excerpt_rss() ?>]]></description>
<?php if ( strlen( $post->post_content ) > 0 ) : ?>
<content:encoded><![CDATA[<?php the_content() ?>]]></content:encoded>
<?php else : ?>
<content:encoded><![CDATA[<?php the_excerpt_rss() ?>]]></content:encoded>
<?php endif; ?>
<?php endif; ?>

to

<?php if (get_option('rss_use_excerpt')) : ?>
<description><![CDATA[<?php the_excerpt_rss() ?>]]></description>
<?php else : ?>
<description><![CDATA[<?php the_content() ?>]]></description>
<?php endif; ?>

Similarly, if you want to fix your comments, too, open wp-includes/feed-rss2-comments.php and change

<?php if ( post_password_required($comment_post) ) : ?>
<description><?php echo ent2ncr(__('Protected Comments: Please enter your password to view comments.')); ?></description>
<content:encoded><![CDATA[<?php echo get_the_password_form() ?>]]></content:encoded>
<?php else : // post pass ?>
<description><?php comment_text_rss() ?></description>
<content:encoded><![CDATA[<?php comment_text() ?>]]></content:encoded>
<?php endif; // post pass

to

<?php if ( post_password_required($comment_post) ) : ?>
<description><![CDATA[<?php echo get_the_password_form() ?>]]></description>
<?php else : // post pass ?>
<description><![CDATA[<?php comment_text() ?>]]></description>
<?php endif; // post pass

Cheers,
Andreas

Tags: , , ,

10 Jan 09 Partial Integration and the Substitution Rule

I only want to write this down to have a place to look it up:

If we want to integrate \displaystyle{ \int_{a}^{b}{f'\left(x \right) g\left( x\right)} } , we can use:


  \displaystyle { (f \cdot g)'\left( x \right) & = f'\left(x \right)g\left(x \right) +  f\left(x \right)g'\left(x \right) } \\
 \displaystyle { \Leftrightarrow f\left(x \right)g\left(x \right) \big |_{a=x}^b } & = \displaystyle { \int_{a}^{b}{ f'\left(x \right)g\left(x \right) +  f\left(x \right)g' \left(x \right) } \, dx  } \\
\displaystyle { \Leftrightarrow \int_{a}^{b}{ f'\left(x \right)g\left(x \right) }\, dx } & \displaystyle { = f\left(x \right)g\left(x \right) |_{a=x}^b - \int_{a}^{b}{ f\left(x \right)g' \left(x \right) } \, dx }

And if we want to substitute a function in an integral:

<br />
{  \int_{g\left(a \right)}^{g\left(b \right)}{ f\left( x  \right) } \, dx = F \left ( g \left ( b \right ) \right ) - F \left ( g \left ( a \right ) \right ) = \left (F \circ g \right ) \left ( b \right ) - \left (F \circ g \right ) \left ( a \right ) = } \\<br />
= \int_{a}^{b}{ \left (F \circ g \right ) ' \left ( x \right )  } \, dx = \int_{a}^{b}{ f \left ( g  \left ( x \right ) \right )  } \, g' \left ( x \right ) \, dx<br />

(with  F \left ( x \right ) = \int^{x}{ f \left ( x \right )} \, dx)
or using a trick:

\int_{a}^{b}{f \left ( g \left ( x \right ) \right ) } \, dx = F \left ( b \right ) - F \left ( a \right ) = \left ( F \circ g \circ g^{-1} \right ) \left ( b \right ) - \left ( F \circ g \circ g^{-1} \right ) \left ( a \right ) = \\
= \left ( F \circ g^{-1} \right ) \left( g \left ( b \right ) \right ) - \left ( F \circ g^{-1} \right ) \left( g \left ( a \right ) \right ) =
\int_{g \left ( a \right )}^{g \left ( b \right )}{ \left ( F \circ g^{-1} \right ) ' \left ( x \right ) } \, dx = \\
= \int_{g \left ( a \right )}^{g \left ( b \right )}{ F' \left ( g^{-1} \left ( x \right ) \right ) \, g^{-1} ' \left ( x \right ) } \, dx =
 \int_{g \left ( a \right )}^{g \left ( b \right )}{ f \left ( g \left ( g^{-1} \left ( x \right ) \right ) \right ) \, g^{-1} ' \left ( x \right ) } \, dx = \\
= \int_{g \left ( a \right )}^{g \left ( b \right )}{ f \left ( x \right ) \, \frac{1}{g' \left ( g^{-1} \left ( x \right ) \right} } \, dx

(with  F \left ( x \right ) = \int^{x}{ f \left ( g \left ( x \right ) \right )} \, dx)

Tags: , ,

18 Dec 08 Microsoft PowerPoint Rant

I have to do a presentation at university and it needs to be done in PowerPoint – OpenOffice and LaTeX are explicity not allowed.
Usually I’m all for Microsoft, but PowerPoint really lacks quite a few things that one would expect to be common in modern presentation software:

  • ability to insert document properties
  • working document properties – somehow I get an error message every time I try to open the document property viewer…
  • changing the language of a presentation (for all slides, etc.) – it’s just a huge W-T-F that you have to use macros or add-ins to do that
  • table of contents slides – it’s incredible that there is no way to automate this in PowerPoint.

LaTeX is a 1000x more user-friendly in that regard to be honest. You can download some packages for free that automate everything that is worth automating and you won’t be bothered with updating all possible things manually everytime. It also usually supports more powerful slides with advanced navigation, etc.

Nonetheless if PowerPoint sucks, then Visual Basic for Applications for PowerPoint is one big brainfuck. The level of stupidity and general suckiness of VBA as language and the fact that you somehow don’t find up-to-date documentation about it online (no language specs?) and some braindead decisions in the PowerPoint macro API make it a real PITA to work with..

Anyway, I’ve written a macro to create a Table of Contents slide automatically for a PowerPoint presentation – it also allows for updating it later on and for customizing its title without overwriting it on update:

' create a Table of Contents slide as second slide (but you can move it around afterwards)
' you can use the macro to update an already generated one without it resetting the title or the slide's position
Const TOCTag = "TOC?Level"
Const TOCSlideName = "TOC?Slide"

Sub CreateTOCSlide()
    Dim contentSlide As Slide
    On Error Resume Next
    Set contentSlide = ActivePresentation.Slides(TOCSlideName)

    If contentSlide Is Nothing Then
        Set contentSlide = ActivePresentation.Slides.AddSlide(2, ActivePresentation.Slides(1).CustomLayout)
        contentSlide.Name = TOCSlideName
        contentSlide.Layout = ppLayoutText
        contentSlide.Shapes.title.TextFrame.TextRange.Text = "Table of Contents"
    End If

    UpdateTOCSlide
End Sub

Private Function FindTOCSlideWithTitle(title As String) As Slide
    Dim cSlide As Slide
    For Each cSlide In ActivePresentation.Slides
        If cSlide.Tags(TOCTag) <> "" Then
            If cSlide.Shapes.title.TextFrame.TextRange.Text = title Then
                Set FindTOCSlideWithTitle = cSlide
                Exit Function
            End If
        End If
    Next cSlide
    Set FindTOCSlideWithTitle = Nothing
End Function

Sub UpdateIndentationFromTOC()
    Dim contentSlide As Slide
    On Error Resume Next
    Set contentSlide = ActivePresentation.Slides(TOCSlideName)

    If contentSlide Is Nothing Then
        Exit Sub
    End If

    Dim contentTextRange As TextRange2
    Set contentTextRange = contentSlide.Shapes.Placeholders(2).TextFrame2.TextRange

    Dim p As TextRange2
    For Each p In contentTextRange.Paragraphs()
        Dim cSlide As Slide
        Set cSlide = FindTOCSlideWithTitle(Left(p.Text, Len(p.Text) - 1))
        If Not cSlide Is Nothing Then
            cSlide.Tags.Add TOCTag, p.ParagraphFormat.indentLevel
        End If
    Next p
End Sub

Private Sub UpdateTOCSlide()
    Dim contentSlide As Slide
    On Error Resume Next
    Set contentSlide = ActivePresentation.Slides(TOCSlideName)

    If contentSlide Is Nothing Then
        Exit Sub
    End If

    Dim contentTextRange As TextRange2
    Set contentTextRange = contentSlide.Shapes.Placeholders(2).TextFrame2.TextRange

    contentSlide.Shapes.Placeholders(2).TextFrame2.DeleteText
    contentTextRange.ParagraphFormat.Bullet.Type = ppBulletNumbered

    Dim index As Integer
    index = 1

    For Each pSlide In ActivePresentation.Slides
        Dim tagValue As Integer
        tagValue = Val(pSlide.Tags(TOCTag))
        If tagValue > 0 Then
            contentTextRange.InsertAfter pSlide.Shapes.title.TextFrame.TextRange.Text &amp; vbCrLf
            contentTextRange.Lines(index, 1).ParagraphFormat.indentLevel = tagValue
            contentTextRange.Lines(index, 1).ParagraphFormat.LeftIndent = 40 * tagValue
            'contentTextRange.Lines(index).ParagraphFormat.Bullet.Type = ppBulletNumbered
            index = index + 1
        End If
    Next pSlide

End Sub

Sub ToggleTOCEntrySlide()
    Dim currentSlide As Slide
    Set currentSlide = ActiveWindow.View.Slide

    Dim newValue As String
    If currentSlide.Tags(TOCTag) <> "" Then
        newValue = ""
    Else
        newValue = "1"
    End If
    currentSlide.Tags.Add TOCTag, newValue

    UpdateTOCSlide
End Sub

Private Function ClampIndentLevel(level As Integer) As Integer
    If level < 1 Then
        ClampIndentLevel = 1
    ElseIf level > 5 Then
        ClampIndentLevel = 5
    Else
        ClampIndentLevel = level
    End If
End Function

Sub IndentTOCEntrySlide()
    Dim currentSlide As Slide
    Set currentSlide = ActiveWindow.View.Slide

    currentSlide.Tags.Add TOCTag, ClampIndentLevel(1 + Val(currentSlide.Tags(TOCTag)))

    UpdateTOCSlide
End Sub

Sub UnindentTOCEntrySlide()
    Dim currentSlide As Slide
    Set currentSlide = ActiveWindow.View.Slide

    currentSlide.Tags.Add TOCTag, ClampIndentLevel(Val(currentSlide.Tags(TOCTag)) - 1)
    UpdateTOCSlide
End Sub

The most recent version can be found in this .zip file here (TOC.bas).

Some remarks:

  • “On Error Resume Next” – it’s crazy that VBA uses this to control its error handler (this construct dates back to QuickBasic..)
  • VBA doesn’t support normal exception handling it seems
  • what does the set statement do and why is it necessary to use it when dealing with object references – I’ve experienced strange error messages before I started using it
  • VBA doesn’t seem to support a Continue statement (continue as the counterpart to break)
  • The VBA documentation is inside the Access documentation (in case you look for it)

Hopefully this is useful for other poor souls who have to or try to work with PowerPoint’s macro facilities.

Cheers,
Andreas

Tags: , , ,