background preloader

Math

Facebook Twitter

Programming practices - Why would a program use a closure? - Software Engineering Stack Exchange. Closures are equivalent to objects implementing a run() method, and inversely, objects can be emulated with closures. The advantage of closures is that they can be used easily anywhere you expect a function: a.k.a. higher-order functions, simple callbacks (or Strategy Pattern).

You don't need to define an interface/class to build ad-hoc closures.The advantage of objects is the possibility to have more complex interactions: multiple methods and/or different interfaces. So, using closure or objects is mostly a matter of style. Here is an example of things that closures make easy but is inconvenient to implement with objects: (let ((seen)) (defun register-name (name) (pushnew name seen :test #'string=)) (defun all-names () (copy-seq seen)) (defun reset-name-registry () (setf seen nil))) Basically, you encapsulate a hidden state that is accessed only through global closures: you don't need to refer to any object, only use the protocol defined by the three functions. Zen in the art of IT: The simple Big-O Notation Post. Huffman Codes « Harder, Better, Faster, Stronger. Some time ago, I presented a piece on compressing voxel worlds and I just realized that I discussed different types of variable length codes quite a few times, but that I never took the time to present you the basic method of Huffman coding!

The problem of finding an optimal variable length code is to find an uniquely decodable binary code (that is, a code using only 0 and 1 for which there exists only one way of decoding a message) that encodes each symbol in a number of bits that is proportional to its probability of occurrence. A first strategy was devised by Robert Fano, Huffman’s teacher at one point. The so-called Shannon-Fano code is a top-down approach to solving the problem but it was shown to be suboptimal. The code proposed by David Huffman solves the problem optimally by taking exactly the opposite approach, that is, building the code bottom-up. In a previous post, I summarized what makes a tree-structured code uniquely decodable: So we create our list of nodes: Like this:

Understanding the Fourier transform » #AltDevBlogADay. Yes, I realize that after reading the title of this post, 99% of potential readers just kept scrolling. So to the few of you who clicked on it, welcome! Don’t worry, this won’t take long. A very long time ago, I was curious how to detect the strength of the bass and treble in music, in order to synchronize some graphical effects. I had no idea how to do such a thing, so I tried to figure it out, but I didn’t get very far.

What I found was the Discrete Fourier Transform (DFT), which looks like this: This formula, as anyone can see, makes no sense at all. Eventually, I was able to visualize how it works, which was a bit of a lightbulb for me. Disclaimer: my math skills are pitch-patch at best, and this is just intended to be an informal article, so please don’t expect a rigorous treatment.

A quick bit of background – what does the Fourier transform do? The picture on the left shows 3 cycles of a sine wave, and the picture on the right shows the Fourier transform of those samples. A Calculus Primer Part V- Techniques For Integration - Software Development Tutorials. MathJax | Beautiful math in all browsers. Kojo Home. Kojo is an open source App that runs on Linux, Windows, and the Mac. It is a Learning Environment – with many different features that enable play, creation, and learning in the areas of: Computer Programming Math and Science Systematic and Computational Thinking Art, Music, and Creative Thinking Problem Solving Strategies Computer and Internet Literacy Electronics and Robotics To play with Kojo, you can Download and Install it. Or you can run it Online. The Kojo Overview Story tells you more about Kojo (you need to have Java 6 or later installed to view the Story).

The Kalpana Center Page describes the thinking behind the use of Kojo in Education. Kojo has been developed to provide children an environment where they can do self-directed learning in an interactive fashion – through exploration and discovery. Kojo is based on ideas derived from Logo, Processing, and The Geometer's Sketchpad. Kojo builds upon these ideas and provides the following: