In Stanisław Lem’s writing, perverse invention and rational coherence lock into each other at weird, compelling angles. Photograph from AP

The science-fiction writer and futurist Stanisław Lem was well acquainted with the way that fictional worlds can sometimes encroach upon reality. In his autobiographical essay “Chance and Order,” which appeared in The New Yorker, in 1984, Lem recalls how as an only child growing up in Lvov, Poland, he amused himself by creating passports, certificates, permits, government memos, and identification papers. Equipped with these eccentric toys, he would then privately access fictional places “not to be found on any map.” Some years later, when his family was fleeing the Nazis, Lem notes that they escaped certain death with the help of false papers. It was as if the child’s innocent game had prophesied a horrific turn in history, and Lem wonders if he’d sensed some calamity looming on the horizon—if his game had sprung “perhaps from some unconscious feeling of danger.”

The idea of a private world spilling over unsettlingly into reality is also at the heart of his novel “Solaris,” from 1961, about a sentient ocean with the power of “seeing into the deepest recesses of human minds and then bringing their dreams to life,” as the Lem fan Salman Rushdie once described it. The massive popularity of “Solaris”—made into a film by Andrei Tarkovsky, in 1972, and then again in 2002, by Steven Soderbergh, as a moody near-future love story with George Clooney—helped Lem become one of the most widely read science fiction writers in the world. Yet his writing reached far beyond the borders of the genre. In addition to many novels and stories, he composed a huge philosophical treatise on the relation of human beings and machines, a good deal of pungently argued literary criticism, a volume of reviews of nonexistent books, a stochastic theory of narrative fiction, an experimental detective novel, speculative essays dealing with artificial intelligence, cybernetics, cosmology, genetic engineering, game theory, sociology, and evolution, radio plays and screenplays. Such staggering polymathic curiosity over such a vast range of material, all of it explored with lucidity and charm, gives his writing a unique place on a Venn diagram in which the natural sciences, philosophy, and literature shade into one another with mutually intensifying vividness and fascination.

Lem also became known for a certain kind of techno fairy tale, some of which were collected in 1964 as “Fables for Robots.” The stories are far from the robot pulp made famous by Isaac Asimov and are almost disturbing in their bristling plenitude: wind-up princesses with crystal minds, planet-size computers battling antimatter dragons, energy castles built in the interiors of glass moons, thinking mountains, clockwork clouds. Although the tales have the compact dimensions of fable, they often unfold with cosmological timescales (“the apprentice waited a thousand years, then another thousand, but the engineer did not return”), or their facets ramify with the logic of a Rube Goldberg contraption. I remember reading these stories in an English edition that I happened upon in my high-school library and feeling (to borrow a line from Emily Dickinson) as though the top of my head had been taken off.

The other “fables” seem to be cautionary satires about the psychic rot that breeds within totalitarian regimes. “Uranium Earpieces” imagines a greedy and suspicious king who lives in a platinum palace and requires that his subjects wear earpieces made of an electromagnetic uranium to prevent them from congregating. (The proximity of the earpieces creates a chain reaction leading to an explosion.) Another, “Trurl’s Machine,” tells of an eight-story-tall computer which insists that two plus two equals seven. When the inventor, Trurl, tries to coax it into giving the correct answer, the huge machine rears up and physically threatens him, stubbornly adhering to its answer. (Trurl is on the verge of acceding to a revision of mathematical truth when the machine breaks down.) Another tells of a ruler with a vast cybernetic military who laments the absence of enemies on which to use it, and so builds an equally vast cybernetic enemy against which to fight. (His subjects, at least those who survive, complain that these synthetic wars are an unnecessary extravagance.) Lem’s novel, “Memoirs Found in a Bathtub,” is an acid sendup of bureaucracy at its most insane and dehumanizing, as its bewildered memoirist navigates through a Department of Verification, Department of Misinformation, Department of Instructions, Department of Codes, eventually coming up against more sinister sounding subdivisions, like the Department of N.

Lem’s incorrigibly curious mind was naturally drawn to philosophy and he wrote a massive work of speculative futurology, “Summa Technologiae,” from 1964. The title is already a clue to the book’s ambition. Where Thomas Aquinas, in his thirteenth century “Summa Theologica,” wished to systematize all of Christian doctrine, Lem wrote a secular organon of human civilization’s entanglement with machines. At the center of the book is the (at the time new) discipline of cybernetics. Systems of energy expenditure—like steam engines or people or fish or information itself—Lem called “islets of decreasing entropy,” and, in the course of unfurling his explication of such systems, Lem rehearsed strikingly prescient versions of ideas that were at the time exotic at best. What he calls “phantomatics” we would now instantly recognize as virtual reality; “ariadnology” seems pretty close to a Google search engine (tracking Ariadne’s thread of some sought-after piece of data through tangled labyrinths of information). There is also a penetrating and original discussion of Alan Turing’s imitation game as imagined in his epochal 1950 essay, “Computing Machinery and Intelligence.” Turing, the British logician who accidentally invented computer science in his effort to tackle the problem of completeness in mathematics (and also helped crack the German Enigma cipher, leading to Allied victory in the Second World War), imagined a criterion for determining if a computer can be called intelligent. If an interrogator can’t tell the difference between a human respondent and a machine, the machine must be counted as thinking (now commonly known as the Turing Test). When confronted with all of the branching possibilities of how a conversation might unfold during such a test, Lem, in his “Summa,” imagined a “Cosmic Gramophone,” which would “record not only particular answers to possible questions but also whole sequences of conversations that can potentially take place [and thus] requires memory . . . which probably cannot be contained in the solar system.” And the historical counterfactual—the eternal friend of the science-fiction writer—comes up in the “Summa” in typically playful scenarios, as when Lem wonders how human history might have unfolded had there been typewriters in the Mesozoic era.

The scrupulous review of a nonexistent book—a genre more or less invented by Jorge Luis Borges—was utterly suited to Lem’s ludic sensibility, and he took the form to exhilarating extremes. Among the books under discussion in his collection “A Perfect Vacuum,” from 1971, is a modernist novel of Joycean ambition based not on “The Odyssey” but on “Gilgamesh,” called “Gigamesh,” which expounds upon the significance of the missing letter “L,” complete with a commentary by the (fictional) author more than twice as long as the novel. Another—“Gruppenführer Louis XVI”—is about a Nazi officer who defects to Argentina after the war with a trunk full of cash, heads to the countryside where he enslaves the natives, and commands them to build a meticulous re-creation of the world of Louis the XVI. Anyone who so much as intimates that the surrounding castle and court life are not absolutely real is tortured and shot. (This piece makes one wonder if Lem might have been the source for Roberto Bolaño’s own compendium of reviews of nonexistent books, “Nazi Literature in the Americas.”) Another is a pitch-perfect sendup of the nouveau roman and the breathless structuralist theorizing that went with it; another invents an Italian pastiche of Dostoevsky’s “The Idiot,” then faults it for an insouciant lack of reverence for the original. Taking the premise to its vertiginous reductio, the introduction to “A Perfect Vacuum” is a review of “A Perfect Vacuum” by a certain “S. Lem.” These delightful pieces end up transcending their constraints and become tales of pure information, occupying the rarified upper air where we also find Borges’s “Pierre Menard” and Nabokov’s “Pale Fire.”