Kinghajj's Blog

2010-02-25

A Deductive Proof that the Abrahamic Religions are Wrong about the Nature of God

  1. The Abrahamic religions claim that their god exists and has the properties of omniscience, omniscience, and omnibenevolenc.
  2. An omnipotent being could prevent any evil act.
  3. An omniscient being would know of all past, present, and future evil acts.
  4. An omnibenevolent being would want to prevent all evil acts.
  5. ∴ An omnipotent, omniscient, and omnibenevolent being could and would prevent all evil acts.
  6. ∴ If such a being exists, then evil does not.
  7. But, evil exists.
  8. ∴ No such being exists.
  9. ∴ If the Abrahamic god exists, then he lacks at least one of these properties.
  10. If their god lacks one of these properties, then the Abrahamic religions are wrong about his nature.
  11. ∴ If their god exists, then the Abrahamic religions are wrong about his nature.
  12. If their god doesn't exist, then the Abrahamic religions are wrong about his nature.
  13. ∴ The Abrahamic religions are wrong about the nature of their god.

2009-10-24

Clang vs. GCC Benchmark with Heap Sort

Last year I wrote an implementation of heap sort in C. I then wrote some code to benchmark the sorting times between it and the standard C qsort(), and the results were that my hsort() was only about 1.5x slower than qsort(); not too shabby!

You can get the code from Pastebin:
  1. hsort.c
  2. hsort.h
  3. main.c
Last night I decided to install Clang so I could see if it could produce better machine code than GCC with my heapsort code, so I installed clang-svn 84993 from the Arch Linux AUR, and compiled the code with -O3 with both GCC and Clang and saved the output from each program to seperate text files. The results for Clang and GCC are again on pastebin.

What's interesting about these results is that, while the average hsort times went down from 54 ms in GCC to 51 ms in Clang, the average qsort times went up from 34 ms in GCC to 35 ms in Clang. I didn't expect this at all, but I suspect it's some sort of fluke. Maybe someone with more experience with Clang and/or GCC could shed some light on this.

2007-12-17

uthash is the greatest thing ever

I've been working on a reverse polish notation calculator off-and-on for a few months now. This isn't your run-of-the-mill reverse polish notation calculator, though: it supports, among other things, variables. Because most reverse polish notation calculators use stacks to do the actual math, I first implemented variables by making a variable stack.

This is not at all efficient, however. If you try to find a variable that happens to be at the end of the stack, you must step though every item in the stack. When I posted the code I had to 7chan's /pr/, someone immediately complained about my implementation of variables. I agreed that a hash table would be much better.

So, to learn a bit more about hash tables, I looked them up on Wikipedia, which had a link toward the bottom to a project called uthash. uthash lets you make any C structure hashable. Perhaps the best part is that it's small--just a 37.7 KiB C header file. What? Yes, because it is implemented entirely in C macros, there is no library to which to link; all you need to do is include the header.

I downloaded uthash and set out to rewrite the variables module. I had to change the structures and only one function declaration in the header. (The function to create a new variable to an argument to the next variable in the stack; obviously, this wouldn't be needed anymore!)

Using the very helpful documentation, I was able to rewrite the module to use a hash table in under an hour. Best of all--and to my absolute surprise--the first successful compilation worked!

Here's an example of using uthash. This function takes a pointer to a RPNVariables structure, which simply holds a pointer to the hash table in the table member. It then iterates through the hash table and prints the variable names and their values. (My program allows for the types of values to be either double or long double, so there are preprocessor conditions to allow this.)
void RPN_printVariables(RPNVariables *variables)
{
RPNVariable *var;

printf("[ ");
for(var = variables->table; var != NULL; var = var->hh.next)
{
#ifdef RPN_LONG_DOUBLE
printf("%s = %Lg, ", var->name, var->value);
#elif RPN_DOUBLE
printf("%s = %g, ", var->name, var->value);
#endif
}
printf("]\n");
}

2007-11-04

Movie Piracy vs. Movie Theaters: What the Fuck am I Paying For?

Yesterday, I saw American Gangster with my friends. As you may know, high-quality copy of American Gangster was leaked more than a week before its theatrical release, and, yes, I downloaded it and watched it. It was such a good movie that I didn't mind paying for it again, using my money as a voice to say "Yes, Hollywood, make more movies like these, not like Rush Hour 3."

But I was extremely disappointed with my experience at the theater. At the beginning of the movie, the audio cut out in half-second durations multiple times, and at one point it almost completely cut out; a few audience members heckled for refunds. But the sound returned, and all was well... or so I thought.

Next, throughout the entire movie, the focus seemed to shift in and out. Even when the camera was completely still, faces blurred, returned to focus, blurred, returned to focus...; it was so noticeable that I was surprised that no one else heckled.

The last problem, though the smallest, was the number of scratches and white dots on the film. I realize that film degrades, but this movie just came out the day before, so it could only have been run at most 10 times before I saw it. The white dots were especially prevalent on the upper-left corner of the frame.

So, whose problem is this? Could the film projector (the person, not the machine) have been messing with the audio connection and changing the focus arbitrarily just to fuck with the audience? Maybe, but I think that a much more likely reason is that the film print was not made with care, or the film was not taken care of properly en route to the theater (or even at the theater!)

So, what incentive do I have to actually pay to see a movie when I can grab a high-quality, carefully-made copy from Usenet in about an hour or less? If the movie studios want to increase attendance, maybe they should start pressuring theaters to convert to digital, and start offering more digital version of their films. I have seen both a film and digital showing of Spider Man 3, and the digital was so much clearer and had so much less problems that I wondered why every film isn't shown digitally. Perhaps if more films are made available for digital shows, and more digital shows are done per day, Hollywood would find its profits increase?

2007-10-05

Got my Das Keyboard II today

I ordered it last week and it finally arrived this afternoon. So far, I like it a lot. The "clicky" sound is nice, and the keys are weighted after all (though, not as well as my Keytronic keyboard.)

I haven't had any problems with its blankness, probably because I'm already a proficient touch typist. Still, it looks cool, and it feels nice, and the Dvorak layout makes it all the more better ;)

2007-09-09

Contexts as Objects in newLISP

In newLISP, contexts are great at dividing bindings into special areas to avoid
name clashes. But they can also be used to implement classes and objects.

Example 1: The Point "class"
(context 'Point)
(define (Point:Point _x _y)
  (setq x _x)
  (setq y _y))

(define (distance-from p)
  (sqrt
    (add
      (pow (sub p:x y) 2)
      (pow (sub p:y y) 2))))
(context 'MAIN)
This doesn't really look like a class, does it? But it is. Point:Point is the
constructor, and distance-from is a method. Let's see how to use this class.

Example 2: Using the Point class
(new Point 'point1)
(point1 1 1)
(new Point 'point2)
(point2 2 2)
(point1:distance-from point2)
; => 1.414213562
Wow! Isn't that something? But creating and initializing an object is a bit
of a chore as-is. Here's a simple macro to simplify this.

Example 3: Simple
(define-macro (new-object _class _name)
  (apply (new _class _name) (args)))

(new-object Point point1 1 1)
(new-object Point point2 2 2)
(point1:distance-from point2)
; => 1.414213562

Labels:

2007-07-05

This is the worst thing ever.

Ron Paul makes so many good points, yet nobody on the show counters with any logic. They resort to personal attacks like "You couldn't be the President of Disney World!" And the whole show seems to be based on yelling, which forces the panelists to yell in return. I can't believe that this show was ever on TV.

I've only watched the first part so far. I almost don't want to watch the rest.

http://www.youtube.com/watch?v=IHB2I83_N_k