Live data from Hacker News

The Prospero Challenge

mattkeeter.com

1–10 of 42 posts

Re: The Prospero Challenge

#4
I'm thinking that we can parse the input into an expression tree, and then for each x coordinate, have each node in the tree tell us which intervals of y coordinates it would return a value Composing these intervals is trivial for all operations except addition/subtraction. (For example, `mul` is less than 0 if exactly one of its arguments is less than 0, `neg` is less than 0 if its argument is not less than 0, `min` less than 0 if either of its arguments is less than 0, etc.).

And then we define add(a, b) as sub(a, neg(b)). So then we only need to work out which y values sub(a, b) will return a negative result for.

sub(a,b) is negative when a.

We can have the sub() node asks its 2 child nodes which values they would return a negative result for. Every y coordinate where a gives a negative result and b gives a positive result is a y coordinate where sub(a,b) is negative. Every y coordinate where a is positive and b is negative is positive. For the remaining y values I think we have to actually evaluate the children and find out which ones give a negative result.

Obviously memoise the evaluation so that we don't repeat any work, and turn the expression tree into a DAG by combining any identical nodes. Some subtrees won't contain var-x, so the memoisation of those nodes can persist across different x coordinates.

And then for each x coordinate we ask the expression tree to tell us which y coordinates give negative outputs, and plot those. It's possible that the idea would generalise to 2-dimensional intervals, not sure.

I haven't implemented this yet but I'm planning to try it out, but to be honest I don't expect it to be faster than Matt's GPU version based on recursive subdivision with interval arithmetic. Btw his talk is great https://www.youtube.com/watch?v=UxGxsGnbyJ4&t=80s

And, a second fun challenge would be to reverse engineer the input file to extract the font! I expect the file is basically a union of x/y translations of functions that plot individual letters, so it shouldn't be crazy hard to split out the top-level union, then split-out the x/y translations, and then collect the letters. It's possible that it's more complicated though. In particular, is each character translated in x/y individually, or is each character translated only in x to form each line of text, and then the line as a whole is translated in y? Or something weirder?

Re: The Prospero Challenge

#6
> If you evaluate the expression with (x,y) values in the ±1 square, then color pixels black or white based on their sign

I do not understand what this means at all, particularly the bit before the comma.

Can someone explain it differently?

Re: The Prospero Challenge

#7
post #6

> If you evaluate the expression with (x,y) values in the ±1 square, then color pixels black or white based on their sign I do not understand what this means at all, particularly the bit before the comma. Can someone explain it differently?

Yeah, this took me a while. Basically, the entire file represents a sort of assembly language for a function. You need to evaluate that entire function for each pixel in the output image.

Each line starts with a line number (with a leading underscore). This is followed by an instruction, and zero, one, or two arguments. The arguments can be either floating point constants or integers (with leading underscores) which represent the results of those corresponding lines earlier in the function.

The x and y coordinates of each pixel are loaded in the assembly language using the var-x and var-y instructions.

Re: The Prospero Challenge

#8

Whoa cool invocation of the magician Prospero! I recently adapted “The Tempest” as a screenplay while in jail and typed it up: https://samhenrycliff.medium.com/adapting-shakespeares-the-t...

Thanks so much for writing this up and sharing. It sounds like you've been through a horrific few years, but your perseverance in creativity is inspiring and fascinating. I wish you well in your efforts to make a better life for yourself, and I hope your work finds a wider audience.

Re: The Prospero Challenge

#9
post #6

> If you evaluate the expression with (x,y) values in the ±1 square, then color pixels black or white based on their sign I do not understand what this means at all, particularly the bit before the comma. Can someone explain it differently?

Break down the range of x values from -1 to 1, and y values from -1 to 1, each into 1024 parts (or whatever resolution you want to plot at). Evaluate the function for each (x,y) coordinate. If the resulting number is negative colour the pixel white, otherwise colour it black.

The expression is (probably) a 2d signed-distance function - https://en.wikipedia.org/wiki/Signed_distance_function

Re: The Prospero Challenge

#10

Whoa cool invocation of the magician Prospero! I recently adapted “The Tempest” as a screenplay while in jail and typed it up: https://samhenrycliff.medium.com/adapting-shakespeares-the-t...

What compelled you in jail? I’m asking if there was more to it than just being bored.
Post reply on HN