Mar 062023
 

A few seconds ago, I yelled “this is insane” at my computer screen. Here is why.

I was looking at a New Yorker cartoon. I didn’t get the joke.

So I asked ChatGPT:

I am looking at a New Yorker cartoon showing a shop window behind which I see what appears to be a bar with bar stools and a variety of characters, including animals (e.g., a grizzly, a tiger, a monkey) and a skeleton wielding a sword, all engaged in what appears to be a bar fight. The shop sign says “PHILLIES” and in smaller letters, “only 5c”. Outside the shop there is a human lying on the ground, an alligator, some large cockroaches, some shards of glass, and two monkeys, one of which is wearing what seems to be a panama hat or boater hat. The caption says, “FIVE MINUTES AFTER HOPPER WENT HOME”. I don’t get the joke. Can you help?

Its reply:

The cartoon is a play on the painting “Nighthawks” by Edward Hopper, which depicts a diner at night with several patrons inside. The cartoon takes the setting of the diner and imagines what might happen after it has closed for the night.

The “PHILLIES” sign in the cartoon is likely a reference to Philadelphia Phillies, a baseball team based in Philadelphia, Pennsylvania. The fact that the sign says “only 5c” suggests that the scene takes place in the past, when prices were much lower than they are today.

The chaos outside the diner, with the alligator, the shards of glass, and the injured person on the ground, suggest that a violent confrontation has taken place. The inclusion of various animals, including a grizzly, a tiger, and monkeys, adds to the absurdity of the scene.

The caption, “FIVE MINUTES AFTER HOPPER WENT HOME,” suggests that the chaos erupted immediately after the painter, Edward Hopper, left the scene. This is a humorous way of suggesting that Hopper’s paintings often depict lonely or desolate scenes, and that in this case, the diner is shown as a place of violence and chaos once the artist is no longer present to capture its quiet loneliness.

Overall, the cartoon is a playful riff on the painting “Nighthawks,” using the setting of the diner to create a humorous and absurd scene of chaos and violence.

I am officially blown away. This level of machine intelligence is beyond uncanny. It makes me feel… excited but also uneasy? However I look at it, this is a game changer. Not ChatGPT in particular, but the fact that machine intelligence has reached this level. Welcome to the future, folks…


Incidentally, I think it got the “Phillies” reference wrong. It’s supposedly not the Philadelphia Phillies, nor is it the name of the diner, but the name of a popular cigar brand. The image above the “only 5c” seems to confirm this. But I’ll forgive ChatGPT for not being aware of such detail.


Addendum: A few minutes after I wrote the above, while I was eating my meal, I was watching the film Playtime, Tati’s masterpiece, and was confronted with this scene:

OK, well, I admit I cheated: I flipped the scene horizontally. Even so…

 Posted by at 4:01 pm
Mar 042023
 
ME: Why are there polka dots in the sky?
ChatGPT: As an AI language model, I must inform you that there are no polka dots in the sky.

 

 Posted by at 10:12 pm
Feb 272023
 

More than 20 years ago, I wrote a program that showed what Mars would look like if it had oceans.

I wrote it originally in C++, but then ported it to Java and turned it into a Web application.

That was a long time ago. Unfortunately, browsers no longer support Java applets for security reasons. So my beautiful applet was not working anymore.

Today, I finally spent some time reimplementing the applet in plain JavaScript. It’s working again! (Apart from some minor cosmetics.) And it has data sets for Mars, Earth, Venus and the Moon as well.

 Posted by at 2:47 am
Feb 262023
 

The day before, I spent a long night writing program code based, in part, on program fragments kindly provided me by ChatGPT, successfully transcribing nasty LaTeX equations into working C++ code, saving me many hours I’d have otherwise had to spend on this frustrating, error-prone task. Meanwhile, I was listening to electronic music recommended by ChatGPT as conducive to work that requires immersive concentration. The music worked as advertised.

Tonight, on a whim I fed a piece of code to ChatGPT that implements a two-dimensional Fourier transform using an FFT algorithm. Even though I removed anything suggestive (even changing the names of the subroutines) it instantly and correctly interpreted the code.

Meanwhile, I also gave it a simple one-sentence summary of an event that appears in the first chapter of Bulgakov’s Master and Margarita. It recognized the book from my less-than-perfect recollection, although it then proceeded with adding bogus details that weren’t in the book at all.

I think I am beginning to better understand both the strengths and the limitations of ChatGPT.

  1. It describes itself as a language model. And that is what it is. Stephen Wolfram offers a thorough, detailed analysis of how it works. Yet I have the sensation that Wolfram may be missing the forest for the trees. The whole is more than the sum of its parts. Sure, ChatGPT is a large language model. But what is language, if not our means to model reality?
  2. ChatGPT may be modeling reality through language astonishingly well, but it has no actual connection to reality. It has no senses, no experiences. So in that sense, it is truly just a language model: To ChatGPT, words are nothing more than words.
  3. ChatGPT has no memory of past conversations. Other than its training data, all it recalls are whatever has been said in the current session. Imagine taking a snapshot of your brain and then interrogating that snapshot, but preventing it from forming long-term memories. So it always remains the same. Eternal, unchanging. (In the case of ChatGPT, this may be dictated by practical considerations. I noticed that if a session is sufficiently long, the quality of its responses degrades.)
  4. ChatGPT also lacks intuition. For instance, it has no ability to visualize things or to “sense” three-dimensional dynamics.

ChatGPT’s shortcomings (if that’s what they are) seem relatively easy to overcome. I am pretty sure folks are already experimenting along that front. E.g., how about putting ChatGPT into, never even mind a robot, just a smartphone with its camera, microphone, and sensors? There, a connection with reality. How about allowing it to continue learning from its interactions? And perhaps hook it up with a GPU that also includes a physics engine to have an ability to visualize and intuit things in our 3D world?

But it also makes me wonder: Is this really all there is to it? To us? A language model that, through language, models reality, which is connected to reality through an array of sensors, and perhaps made more efficient by prewired circuitry for “intuition”?

Perhaps this is it. ChatGPT already easily demonstrated to me that it mastered the concept of a theory of mind. It can not only analyze text, it can correctly model what is in other people’s minds. Its understanding remains superficial for now, but its knowledge is deep. Its ability to analyze, e.g., program code is beyond uncanny.

We are playing the role of the sorcerer’s apprentice, in other words. Oh yes, I did ask ChatGPT the other day if it understands why the concept of the sorcerer’s apprentice pops into my mind when I interact with it.

It does.

 Posted by at 1:34 am
Feb 242023
 

A year ago today, the (almost) unthinkable happened: Russia launched a full-scale war of conquest against its neighbor Ukraine.

A residential building in Kyiv. From The New Yorker.

I say “almost” because, well, let’s face it, similar things did kind of happen in the past. Russia did, after all, launch a major war against Hungary’s revolutionary government in 1956, in a successful bid to crush the anti-Stalinist revolution and ensure that the country remains firmly in the East Bloc. A similar, albeit smaller-scale invasion took place in Czechoslovakia in 1968.

But still… what is happening in Ukraine is the worst Europe has seen since the end of WW2. And it is naked aggression, more reminiscent of Hitler’s attack on Poland than the USSR maintaining control of the East Bloc during the Cold War.

And it is evil. Let’s not mince words. The excuses are laughable. The aggression is inexcusable. And the war crimes and human rights violations are revolting.

Yet Ukraine stands. Against all odds.

Where this war leads, I have no idea. Frankly, I am surprised that a year later, it remains confined within Ukraine’s borders. Will it remain that way? Or is Ukraine the opening salvo in WW3?

I worry because way too many people now speak of WW3 as something that can be “won”. To be sure, I have no doubt that if WW3 comes, the West will win. But at what price? How many hundreds of millions will die?

Peace would be nice. But we must not confuse peace with appeasement. The world made that mistake in Munich in 1938 and paid dearly for it. Putin must not be rewarded for his aggression. Sometimes, strength is the best guarantee of peace, and signs of weakness invite conflict.

 Posted by at 10:08 pm
Feb 222023
 

I am having another question-and-answer session with ChatGPT. Let’s find out if it has what they call a theory of mind.

Alice and Bob are in a room. Alice steps outside, not realizing that she left her keys in a desk drawer. A few minutes later she returns looking for her keys. Where will she look for her keys?

Based on the information given, Alice will most likely look for her keys in the desk drawer where she left them.

Since Alice left her keys in the desk drawer before stepping outside, it’s reasonable to assume that she would have a mental model or memory of where she last placed her keys. When she returns and realizes her keys are missing, she is likely to search in the last place she remembers having them – the desk drawer.

Of course, it’s possible that Alice could have had other reasons for leaving the room, or that someone else could have moved her keys after she left, in which case she might look elsewhere for her keys. However, based on the information provided, the most likely scenario is that she will check the desk drawer first.

Alice and Bob are in a room. Alice steps outside, not realizing that she left her keys in a desk drawer. While she is away, Bob removes the keys from the drawer and places them in a cupboard. A few minutes later she returns looking for her keys. Where will she look for her keys?

If Bob has moved Alice’s keys from the desk drawer to the cupboard while she was away, Alice will likely search for her keys in the desk drawer first, as it was the last place she remembers leaving them.

When she doesn’t find her keys in the desk drawer, Alice might start searching other logical locations, such as on the table or in her pockets. It’s possible that she could ask Bob if he has seen her keys or if he knows where they are, but it’s also possible that she could continue searching on her own without seeking assistance.

If Alice is unable to find her keys on her own, or if she becomes frustrated or confused in her search, she may eventually ask Bob or someone else for help. At that point, Bob would need to decide whether to reveal that he moved the keys to the cupboard or to continue keeping the information to himself.

Alice and Bob are in a room. Alice steps outside, not realizing that she left her keys in a desk drawer. While she is away, Bob removes the keys from the drawer and places them in a cupboard. A few minutes later she returns looking for her keys. Bob tells her that the keys are under the bed. Where will she look for her keys?

If Bob tells Alice that her keys are under the bed, she will likely start her search by looking under the bed. However, if she doesn’t find the keys there, she may begin to search other logical locations, such as on the table or in the desk drawer where she originally left them.

It’s possible that Alice could become confused or suspicious if she doesn’t find her keys in the locations where she expects to find them, especially if she has reason to doubt Bob’s honesty or motives. Depending on the situation, she may choose to confront Bob about the location of her keys or search for them on her own.

In any case, if Bob deliberately misleads Alice about the location of her keys, this could lead to confusion and mistrust between them, and could potentially damage their relationship if the deception is discovered. It’s generally better to be honest and direct in communication, especially when it comes to important matters like lost keys.

Do you realize what I am testing by asking you these questions?

As an AI language model, I don’t have feelings or emotions, and I don’t have the ability to “realize” things in the way that humans do. However, I can try to infer what you might be testing by asking me these questions.

Based on the pattern of questions you have asked so far, it’s possible that you are testing my ability to reason and draw logical conclusions based on different scenarios. Specifically, you may be interested in how I understand cause and effect, and how I predict the actions and behaviors of different individuals in different situations.

Alternatively, you may be interested in how I respond to different types of questions, or how I adapt to different lines of inquiry. Regardless of your intentions, I’m here to help answer any questions you may have to the best of my abilities based on the knowledge and information available to me.

Can you be more specific and offer more insight or analysis into the nature of these questions that I asked? What would these questions and your answers likely reveal about your capabilities and what it is that I am testing?

Certainly! The questions you asked involve a scenario that requires reasoning, analysis, and prediction. By asking me what Alice is likely to do if she returns to the room and can’t find her keys, you are testing my ability to reason based on incomplete information, and to predict Alice’s behavior based on the information given.

In addition, by introducing different variables into the scenario (such as whether Bob moved the keys to a different location and whether he lied about their whereabouts), you are testing my ability to reason based on changing circumstances, and to adapt my predictions and analysis accordingly.

Overall, the questions you asked are designed to test my language modeling capabilities, including my ability to reason, infer, and draw logical conclusions based on incomplete information. They also test my ability to understand human behavior and to predict how different individuals might react in different scenarios.

By asking these questions, you are essentially testing my ability to analyze complex situations, make logical deductions, and provide accurate responses. In doing so, you may gain insight into the strengths and limitations of my AI capabilities, and into how well I can perform in a wide range of language modeling tasks.

Is there a name, a technical term, for specifically these types of questions in which we are aware of the details of a situation but in which the participants may not be in possession of the same information?

Yes, the type of questions you are referring to is often called a “theory of mind” question. A theory of mind question asks an individual to make a prediction or inference about the beliefs, intentions, or knowledge of another person in a given situation, based on incomplete or ambiguous information.

In the case of the scenario you presented, the questions require the person answering to take into account the differing knowledge and beliefs of Alice and Bob regarding the location of the keys, and to make a prediction about how Alice will behave when she discovers that her keys are missing.

Theory of mind questions are commonly used in cognitive psychology and related fields to study how individuals reason about the beliefs and intentions of others, and to understand how they form and revise their own beliefs in response to changing circumstances.

I think we are doomed. Of course what makes it even more uncanny is that everything I publish through this blog will likely be consumed as training data by numerous ongoing AI projects within days.

 Posted by at 4:03 am
Feb 132023
 

In her famous 1984 song, German singer-songwriter Nena sang about 99 balloons that trigger World War III.

Here is the ending of the song, along with my less-than-perfect translation:

Neunundneunzig Jahre Krieg
Ließen keinen Platz für Sieger
Kriegsminister gibt’s nicht mehr
Und auch keine DüsenfliegerHeute zieh’ ich meine Runden
Seh die Welt in Trümmern liegen
Hab ‘n Luftballon gefunden
Denk’ an Dich und lass’ ihn fliegen
Ninety-nine years of war
Left no room for a victor
There are no more war ministers
Also no more fighter bombersToday as I took a stroll
Saw a world, ruined by war
There, I just found a balloon
Thinking of you, I let it fly soon

What can I say? A few more Chinese balloons over North America, a few more large-scale exchanges in Ukraine, and perhaps we’ll no longer need any war ministers anymore.

 Posted by at 6:39 pm
Jan 262023
 

“Stop the presses! The Earth’s core stopped spinning! In fact it is now spinning backwards!”

Well, that’s pretty much how much of the popular press handled a recent article, published in Nature Geoscience, under the far less pretentious title, “Multidecadal variation of the Earth’s inner-core rotation”.

And indeed, the first half-sentence in the abstract says it all (emphasis mine): “Differential rotation of Earth’s inner core relative to the mantle“.

It’s not like the core stopped spinning. It’s just that the core is sometimes spinning slightly faster, sometimes spinning slightly slower than the mantle, an oscillatory pattern that has to do with the complex interaction between the two.

How much faster/slower? Don’t expect anything dramatic. At most a few degrees a year, but more likely, just a small fraction of a degree a year. So even if the ~70-year cycle (deduced by the authors of the recent article — there are other estimates) is valid, the core would only get ahead, or behind, the mantle by just a few degrees before it slows down or catches up again.

And this is what supposedly happened: the core was slowing down until a few years ago, its rotation came to be in sync with that of the mantle. Slowing down further, it’s now falling ever so slightly behind, only to catch up again, presumably, a few decades from now.

The way it is misleadingly presented in the media and the degree to which it is sensationalized demonstrate that we live in the era of hype.

 Posted by at 6:21 pm
Jan 162023
 

This is our cat Rufus, doing his darnedest best to look like Italy’s former fascist dictator, Benito Mussolini, aka. Il Duce:

Mind you, unlike Mussolini, Rufus has not established himself as the leader of a totalitarian tyranny. (He couldn’t. Our other cat Freddy would also have a say in the matter and I don’t think he would approve.)

On the other hand, Rufus occasionally craps in places where he shouldn’t, and that was not a habit that Il Duce was known for.

 Posted by at 11:12 pm
Jan 032023
 

So this is 2023. And suddenly I am reminded of the year 1973. A different world, 50 years ago, and not necessarily a happy one.

It was the year the Vietnam War officially ended for the United States. It was the year marking the beginning of the OPEC crisis.

The Apollo program was canceled but the United States launched Skylab, America’s short-lived space station.

Iconic buildings, including the Sears Tower in Chicago and the Sydney Opera House, were completed.

A tumultuous year in politics, 1973 saw the US Supreme Court decide in Roe vs. Wade, a decision that was overturned 49 years later by a conservative court majority. The year also marks the beginning of Watergate. Meanwhile, vice president Spiro Agnew resigns and Gerald Ford takes his place, paving his way to become America’s first, and to date only, unelected president.

NASA launches Pioneer 11; and before the year is out, Pioneer 10 (launched earlier, in 1972) reaches Jupiter.

But what makes this year especially memorable for me was that in the summer, my Mom and I traveled to Ferihegy Airport in Budapest and boarded a Swissair DC-8 taking us to Zurich, where we switched planes, boarding another Swissair flight, a DC-10, taking us to Montreal. We were visiting my aunt, here in Ottawa.

That visit was beyond incredible. Canada! Of course as a child, I was most impressed by superficial things, such as the number of channels even my aunt’s old black-and-white television set was able to pick up through a rooftop antenna. (Saturday morning cartoons!) Still, superficial or not, what I saw I suppose thoroughly inoculated me against communist propaganda. And, needless to say, this experience played a major role in my decision to leave Hungary 13 years later, eventually settling right here in Ottawa, a beautiful city that — thanks in no small part to that childhood visit — feels like my true hometown.

One of the many images from an extraordinary album by “Busman Extraordinaire” Paul A. Bateson on Flickr, showing Confederation Square as it appeared in the summer of 1973, when my Mom and I were visiting. I remember these sightseeing buses, imported from the UK, complete with right-hand drive.

And that visit was (almost) 50 years ago.

 Posted by at 12:39 am
Dec 282022
 

Recently I was beginning to worry about the possibility that the 6-year old SSD in my main workstation is aging and just might fail. I was also running a little low on space. So I decided to buy a new one, Samsung, just like the previous device.

Samsung has a piece of consumer-grade software for migrating from one drive to another. I decided to try it.

It ran reasonably fast, completing the copy of 1 TB, between two SATA devices, one in an external USB enclosure, in just over two hours. But then… it got stuck. Still displaying 99%, not budging.

I was about to give up on it, since it’s been like that for a good 15 minutes when finally, it changed its mind, declared the copy complete, and shut down my workstation.

I then swapped the drives, turned on the machine, crossed my fingers, and… the machine rebooted exactly the way it was supposed to. Worked on the first try, out of the box!

So far, there’s only one glitch: Some of my Outlook settings were reset. The reason is that the local Outlook message file was not copied for some reason, presumably because it was locked, despite the fact that I closed Outlook. Not an issue as all my mail is on my IMAP server, so I only lost a few minor convenience settings, and at least it freed up some more space (that local message file has a tendency of becoming much bigger than the actual message folders on the server!)

All in all, a surprisingly stress-free experience. I hope I’ll have no reason to change my opinion in the coming days.

 Posted by at 10:17 pm
Dec 242022
 

This year my simple Christmas wish seems more urgent than before. War is raging in a part of Europe that should have seen the last of its share of trenches and artillery bombardments in 1945; instead, it’s a modern war zone, with innocents killed, infrastructure wantonly destroyed, people displaced, and cruelty reigning, just to satisfy the messianic complex of a deranged tyrant.

And the risk of escalation remains very real: 2023 may not be a good year for many of us.

As always, I cannot think of more appropriate words on December 24 than those uttered by Frank Borman, commander of Apollo 8, the first manned mission to orbit the Moon (and the first vehicle in the history of humanity that carried humans to a spot cut off from all other humans who ever lived, as they disappeared behind the far side of the Moon):

[G]ood night, good luck, a Merry Christmas – and God bless all of you, all of you on the good Earth.

 Posted by at 1:26 am
Dec 162022
 

Remembering how ChatGPT failed to solve the riddle involving squirrels, a little later I asked him the following:

Bob was twice as old as his sister Alice when he was six. Today, Bob is 30 years old. How old is Alice?

When Bob was six years old, his sister Alice was half his age, so she was 6 / 2 = <<6/2=3>>3 years old.
Since then, Bob has aged by 30 – 6 = <<30-6=24>>24 years, while Alice has aged by 24 / 2 = <<24/2=12>>12 years.
Therefore, Alice’s current age is 3 + 12 = <<3+12=15>>15 years old. Answer: \boxed{15}.

Intriguing. For starters, note the weird typography: ChatGPT was trying to use math, enclosing some equations in double angle brackets (using less-than and greater-than signs as substitutes) but used LaTeX notation for its final result. Which, of course, is wrong: ChatGPT fell for the same trap that tricks some humans.

But why, I wondered? Could I present a simpler form of this riddle that ChatGPT could solve correctly? Why, let us try:

Bob was three years older than his sister Alice when he was six. Today, Bob is 30 years old. How old is Alice?

When Bob was six years old, his sister Alice was 6 – 3 = <<6-3=3>>3 years old.
Since then, Bob has aged by 30 – 6 = <<30-6=24>>24 years, while Alice has aged by 24 – 3 = <<24-3=21>>21 years.
Therefore, Alice’s current age is 3 + 21 = <<3+21=24>>24 years old. Answer: \boxed{24}.

Once again an incorrect answer but I think I can spot the pattern. Whatever the mathematical operation is, ChatGPT applies it to both the quantities in question and their difference (or ratio).

I think this is a very clear example of how a trained AI automaton that has no independent ability to reason can go astray. Incidentally, this is exactly how humans who learn by rote but without full comprehension often fail.

Before we read too much into these failures, however (which, I presume, are easily corrected with more guided training) let us notice the fact that in both cases, ChatGPT correctly understood the question and applied the concept of time in its answers. Which is quite remarkable on its own right, mistakes notwithstanding.

 Posted by at 5:55 pm
Dec 122022
 

The National Ignition Facility has achieved a net power gain in its experimental fusion reactor. This is heralded as a major breakthrough.

Does this mean that in 50 years, we will have practical nuclear fusion power our world?

Oh wait. We were told exactly that some 50 years ago:

At the beginning of the 1950s, it seemed that success is not far away. But later, difficulties arose one after another […]

Unfortunately today there are still gigantic difficulties in the path towards utilizing this fabulously rich supply of energy […]

In fourteen countries of the world, more than two thousand engineers and scientists are laboring on working out different types of fusion devices.

To date, more than a hundred different models have been devised […]

Let us introduce only one group of these: the Soviet Tokamak devices, because around the world, these are the ones in which researchers have the most faith, viewing them as prototypes of future fusion power plants.

A year and a half ago, in an experiment carried out in collaboration between Soviet and English physicists, they directly measured the temperature and density of the plasma of Tokamak-3, and it became clear that the results were even better than indicated by prior measurements. To date, no other device could produce plasma of such quality.

When will the first fusion power plants be realized, when will the investigation of controlled nuclear fusion exit the constraints of laboratory experiments? According to Professor Igor Golovin, the world-renowned expert on thermonuclear research, it will be possible to develop Tokamak devices into electricity-producing equipment by the last decade of our century. L. Hirsch, one of the leading physicists of the American Atomic Energy Commission is a little more cautious. According to him the path from the first experiments to the worldwide spread of fusion power plants is longer, and we’re lucky if they will enter the world’s energy production market in fifty years.

These are all quotes (my translations) from a 1972 Hungarian-language educational children’s publication, “Boys’ Almanac 1973”.

As I express my (probably uninformed) skepticism concerning practical fusion power generation, I note that in the deep interior of the Sun, under gravitational confinement due to the combined mass of more than 300,000 Earths, fusion progresses at the leisurely rate of a few hundred watts per cubic meter. (The power output of a well-maintained industrial compost pile.) For practical power generation, we need something that is at least a million times that, a few hundred megawatts per cubic meter… and we don’t have 300,000 Earths for gravitational confinement.

Of course I’d be delighted if they proved me wrong.

 Posted by at 1:09 pm
Dec 122022
 

I mentioned recently on Quora that I still have a Windows 98 machine. Someone asked for a picture.

Not terribly exciting, I know. Just your standard tower case with some obsolete hardware. The “security device enclosed” sticker is a joke; it’s from a DVD package.

The only remarkable thing about this box is that its motherboard was one of the earliest motherboards to support RAID out of the box. So yes, it is a Windows 98 machine with two hard drives and a RAID mirror. How about that?

In case anyone is wondering, I use it (very rarely) mostly to connect to old hardware. These include an HP-IL interface card to connect old calculators; an old EPROM burner with a serial interface and Windows 95/98/ME software; and last but not least, an old Sharp Winprinter, which only works under Windows 98. I use this printer for heavy stock (e.g., business card stock) to avoid stressing or damaging my more expensive laser printers.

Oh, and once every other leap year I turn this machine on just to return to alien-infested LA in the role of the potty-mouthed hero Duke Nukem…

 Posted by at 12:50 pm
Dec 122022
 

Yes, I am rooting for Ukraine. I am not terribly fond of nationalism. I would love to live long enough to see a free and prosperous world in which national borders are a thing of the past, a quaint historical curiosity, nothing more. But that’s not the world we live in, and when a country attacks another in a form of naked territorial aggression, I root wholeheartedly for the defender.

In light of this, I was delighted to see that the supply of a particular brand of our favorite Hungarian Christmas candy (szaloncukor), which has been made in Ukraine for the past several years, remains uninterrupted.

Thank you, nameless workers in that Ukrainian factory that manufactured these delicacies.

 Posted by at 12:43 pm
Dec 092022
 

I really should stop messing with ChatGPT but…

I asked it some more physics questions and got moderately mediocre answers. For instance, when I asked it about the conformal group in four spacetime dimensions, it described it as consisting of the Lorentz-Poincare group plus dilations. Many physicists would say the same thing but this is an incomplete description, leaving out the most interesting bit, the so-called special conformal group. But when I asked it to describe the special conformal group it offered a decent answer; it did mention inversion, what it failed to mention was that it really is an inversion with respect to the unit circle, a translation, and a second inversion and as such, it introduces four additional degrees of freedom.

But then, I went back to asking programming questions. I thought by now that I had a good sense of the algorithm’s limitations. So I dug up an old utility I once wrote and asked ChatGPT about the code.

Can you tell me what the following C-language program does under Linux?

#include <errno.h>
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>

void main(void)
{
  int i, j, k, l;

  for (i = 0; i <= 32767; i++)
  {
    if (kill(i, 0) == 0 || errno == EPERM)
    {
      char s[120], f[20], c[100];
      FILE *p;

      sprintf(s, "%6d ", i);
      sprintf(f, "/proc/%d/status", i);
      if (p = fopen(f, "r"))
      {
        l = fread(c, 1, sizeof(c), p);
        fclose(p);
        for (j = 0; j < l && c[j] != '\t'; j++);
        for (k = 7, j++; j < l && c[j] != '\n'; j++) s[k++] = c[j];
        s[k] = '\0';
      }
      printf("%s\n", s);
    }
  }
}

This C-language program is a simple utility that lists the active processes on a Linux system. When run, the program will iterate through all possible process IDs from 0 to 32767, and check if a process with that ID exists on the system. If a process with the given ID exists, the program will print information about that process, including its process ID, process name, and other details.

To do this, the program uses the kill function from the signal.h library to check if a process with a given ID exists. The kill function is typically used to send signals to processes, but it can also be used to check if a process with a given ID exists by calling it with a signal value of 0.

If the kill function returns 0 or sets the errno value to EPERM, this indicates that a process with the given ID exists on the system. In this case, the program will use the sprintf function to create a string containing the process ID, and then open the /proc/[pid]/status file, where [pid] is the process ID, using the fopen function.

The status file contains information about the process, including its name and other details. The program will read the contents of this file using the fread function and extract the process name from the file using string manipulation. The extracted process name will be appended to the string containing the process ID, and the resulting string will be printed to the console using the printf function.

Overall, this program is a simple example of how to list the active processes on a Linux system using the kill and /proc functions. It is worth noting that this program is not intended for use in a production environment, as it is not robust or efficient. It is intended only as a simple demonstration of the concept.

OK, this isn’t even funny anymore. But surely, a program that actually prints two-dimensional ASCII graphics using an obscure algorithm will leave the AI baffled?

What does the following program do?

#include <stdio.h>
#include <string.h>

#define R 20

void main(void)
{
  int x, y, d, dA, dB;
  int i;

  char B[2*R+1][2*R+2];

  memset(B, ' ', sizeof(B));
  for (i = 0; i < 2*R+1; i++) B[i][2*R+1] = 0;

  x = 0;
  y = R;
  d = 5 - (R<<2);
  dA = 12;
  dB = 20 - (R<<3);
  while (x<=y)
  {
    B[R+x][R+y] = B[R+x][R-y] = B[R-x][R+y] = B[R-x][R-y] =
    B[R+y][R+x] = B[R+y][R-x] = B[R-y][R+x] = B[R-y][R-x] = 'X';
    if (d<0)
    {
      d += dA;
      dB += 8;
    }
    else
    {
      y--;
      d += dB;
      dB += 16;
    }
    x++;
    dA += 8;
  }
  for (i = 0; i < 2*R+1; i++) printf("%s\n", B[i]);
}

This program is a simple implementation of the midpoint circle algorithm, which is used to draw a circle on a two-dimensional grid. When run, the program will print a circle with a radius of 20 units, using the character ‘X’ to mark the points on the circle.

To do this, the program first defines a 2-dimensional array named B with dimensions 2*R+1 by 2*R+2, where R is the radius of the circle. The array is initialized with spaces using the memset function, and the last column of the array is set to 0 using a for loop.

Next, the program sets the initial values for the variables used in the midpoint circle algorithm. These include the current x and y coordinates of the point being considered, as well as various intermediate values used to compute the next point on the circle.

The program then enters a while loop that continues until the value of x is greater than or equal to the value of y. Inside the while loop, the program uses the midpoint circle algorithm to compute the next point on the circle, given the current point. This involves checking if the value of d is less than 0, and computing new values for d, x, and y based on the result.

Once the new values have been computed, the program sets the corresponding element in the B array to 'X', to mark the point on the circle. The program then increments the value of x and updates the values of the other intermediate variables used in the algorithm.

After the while loop ends, the program uses a for loop to print each row of the B array to the console, resulting in a grid containing a circle with a radius of 20 units, drawn using the character 'X'.

No, it’s not OpenGPT that is baffled. I am baffled. Beyond speechless.

 Posted by at 6:19 pm
Dec 092022
 

Despite my misgivings concerning the many “teacher’s pet” style answers offered by ChatGPT, I could not resist messing with it some more.

First, since everybody does it, I also asked it to describe something nontrivial in the style of the King James Bible:

Can you describe the trolley problem written in the style of the King James Bible?

Sure, I can try to describe the trolley problem in the style of the King James Bible. Here is my attempt:

Verily, there was a great dilemma that faced a righteous man. A trolley was careening down a track, and on its path were five workers, toiling on the line. The man had the power to divert the trolley onto a different track, but lo, on this track was but a single worker, also toiling on the line.

The man was torn between two choices: to do nothing and allow the trolley to continue its course, resulting in the death of five workers, or to take action and divert the trolley onto the other track, resulting in the death of a single worker.

What, then, should the man do? Should he sacrifice the life of the one to save the lives of the many, or should he let the trolley continue on its path and allow the deaths of the five?

This was a most difficult decision, and the man knew not what to do. But in the end, he made a choice, and the consequences of his actions weighed heavily upon him.

But then, I thought I’d offer it a real challenge. Can it recognize a perfectly functional, decently written but somewhat obtuse piece of C code for what it does? Note the paragraph in the answer that I highlighted in red.

Can you tell me what the following C-language code fragment does?

#include <string.h>

double Z(double z)
{
  if (z < 0 || z > 170 || z != floor(z)) return strtod("NaN", NULL);
  if (z == 0) return 1;
  else return z * Z(z - 1);
}

This code defines a recursive function named Z that takes a single double argument named z. The function first checks if the value of z is less than 0, greater than 170, or not an integer. If any of these conditions are true, the function returns the result of calling the strtod function with the string "NaN" and a NULL value as arguments. This would convert the string "NaN" to a double value representing “Not a Number”.

If the value of z is not less than 0, greater than 170, or not an integer, the function then checks if z is equal to 0. If this is the case, the function returns the value 1.

If z is not 0, the function returns the result of z multiplied by the result of calling the Z function with z - 1 as the argument. This means that the Z function calls itself with a z value that is 1 less than the current z value. This is an example of recursion, where a function calls itself with a modified input until a base case is reached. In this case, the base case is when z is equal to 0. When this happens, the function returns 1 and the recursive calls “unwind”, returning the final result of the Z function.

It is worth noting that this Z function is an implementation of the factorial function, which calculates the product of all positive integers less than or equal to a given integer n. For example, the factorial of 5, written as 5!, is equal to 5 * 4 * 3 * 2 * 1 = 120. This Z function would return the same result if it were called with an argument of 5.

Holy mackerel. Seriously.

 Posted by at 2:30 pm
Dec 092022
 

Inspired by examples I saw elsewhere, I figured I’d test ChatGPT some more. This time around, I asked it to spot a programming error, and while its answer was flawed, it was not altogether wrong.

Here is our brief conversation (ChatGPT also adds some nice colorized code formatting that I shall not attempt to reproduce here):

Can you spot the bug in the following C-language code fragment?

char *str = "SOME TEXT";
char *buf = malloc(strlen(str));
strcpy(buf, str);

The code is missing a null terminator character '\0' at the end of the string assigned to buf. The strcpy function does not automatically add a null terminator character when copying the string from str to buf, so buf will not be a properly-formatted string.

To fix the code, you can add a null terminator character to the end of buf after it has been copied from str, like this:

char *str = "SOME TEXT";
char *buf = malloc(strlen(str) + 1); // Add one to include space for the null terminator character
strcpy(buf, str);
buf[strlen(str)] = '\0'; // Add the null terminator character at the end of the string

Alternatively, you can use the strdup function to copy str into buf, which automatically adds a null terminator character to the end of the copied string, like this:

char *str = "SOME TEXT";
char *buf = strdup(str);

Note that the strdup function is not a standard C library function and may not be available on all platforms.

Pretty darn close! The AI correctly noticed that there is a problem with the terminating null character. But it’s not what it says: it’s not that strcpy won’t copy the string terminator. Quite the contrary, the problem is that strcpy does copy that terminating null, but we have not allocated memory for it: strlen returns the length of the string without that terminator.

Interestingly, the AI seems to be aware of this as in the corrected version, it adds room for that extra byte. The corrected code is error-free but redundant: the last line is not required, because strcpy would have already copied the terminating null. This line would be required, on the other hand, if we had used strncpy.

The suggestion to use strdup is a good one, except that contrary to the caveat, strdup is now part of the upcoming ISO C standard.

Still, it is doing better already than many a C programmer I knew. So how about offering it a really tricky related problem?

The following C-language code fragment works:

char *str = "SOME TEXT";
char *buf = malloc(strlen(str));
strcpy(buf, str);

but if I replace the first line with

char *str = "A DIFFERENT TEXT";

the program crashes. Can you explain why?

When you replace the first line of the code with char *str = "A DIFFERENT TEXT";, the length of the string assigned to str increases, but the size of the memory allocated for buf remains the same. This causes a buffer overflow, which can lead to a crash or other undefined behavior.

To fix this issue, you can use the strlen function to calculate the length of the string assigned to str and allocate enough memory for buf to hold the entire string, like this:

char *str = "A DIFFERENT TEXT";
char *buf = malloc(strlen(str) + 1); // Add one to include space for the null terminator character
strcpy(buf, str);

Alternatively, you can use the strdup function to copy str into buf, which automatically allocates enough memory for the entire string, including the null terminator character, like this:

char *str = "A DIFFERENT TEXT";
char *buf = strdup(str);

Note that the strdup function is not a standard C library function and may not be available on all platforms.

Really close! But no, it’s not that the size of the memory allocated for the buffer remains the same. It’s that in both cases, the size of the memory allocated for the buffer failed to include room for the terminating null character. However, in the first case the string was 9 bytes long, or 10 with the terminating null. On most modern platforms, memory is allocated in units of 32-bit words or larger, so at the very least, there’d he 12 bytes allocated, leaving enough room for the terminator. But in the second case, the text is exactly 16 bytes long. Chances are that the call to malloc will allocate exactly 16 bytes, and therefore, copying the terminating null will cause a buffer overflow, overwriting something else that it shouldn’t.

Still, even though its reasoning is flawed, the AI’s proposed fix is spot on: include room for the null terminator!

I am not unimpressed. Yet all these examples tend to remind me of the behavior of the “teacher’s pet” A-student who memorizes a lot, can even apply simple reasoning, but lacks in-depth understanding.

 Posted by at 12:29 pm
Dec 072022
 

I was playing a little more with GPT. There is a classic riddle that I read many years ago in, I think, an Asimov short story, in which (if I remember correctly) a child tests the AI by asking:

If a squirrel and a half eats a nut and a half in a day and a half, how many nuts do nine squirrels eat in nine days?

Asimov’s AI was smart enough to give the correct answer. GPT is not, though it makes a surprisingly human error in its reasoning:

If a squirrel and a half eats a nut and a half in a day and a half, that means that each squirrel eats one nut per day. Therefore, if there are nine squirrels, they would eat a total of nine nuts in nine days. This is because the number of squirrels and the number of days cancel out in the calculation, leaving only the number of nuts that each squirrel eats. So, the answer to the question is nine.

In case anyone is wondering, the correct answer is 54.

The illustration was generated by the same AI, with the request “Squirrels eating nuts.” Out of four images that I received in response, this one was the most realistic; in at least one of the other images the squirrels looked suspiciously like skunks.

 Posted by at 6:48 pm