# Polypiling
In NetHack, polypiling is the action of polymorphing a pile of items in hopes of getting some useful items as a result. Objects polypiled are often referred to as polyfodder and usually consist of junk. Polymorph can be caused by a spell, wand, or potion of polymorph.
Polypiling has its drawbacks: Polyfodder may be destroyed, and hostile golems may be generated. The exact mechanics of item destruction are rather complex, but understanding them is important if you want to get the most out of your resources - see the next section for more details.

Contents

1 Introduction
2 Probability of item loss and golem generation

2.1 Shuddering
2.2 Golem absorption and types
2.3 Artifacts
2.4 Summary of polyfodderdestruction

3 Probability of item transformation
4 Forbidden items
5 Strategy

5.1 General tips
5.2 Preparing
5.3 When to polypile
5.4 When not to polypile

6 Stacking strategies

6.1 Seven small piles

6.1.1 Step by step
6.1.2 Explanation

6.2 One large pile

6.2.1 Step by step
6.2.2 Explanation
6.2.3 One large pile with meatballs

7 Variants

7.1 SLASH'EM
7.2 SlashTHEM

8 Code
9 References
10 External links

Introduction
When considering polypiling, it is important to distinguish stacks of items, which are all of one type (e.g., "4 blessed scrolls of blank paper"), from piles of items, which are all of the items on the floor in one square. The terms stack and pile will be used rigorously on this page.
The spell and wand supply a beam with a random range between 6 and 13 (long enough to hit 3 to 7 piles if they are all in line and contiguous and you are adjacent to the first) so you can work on several piles at once. A potion of polymorph works on one item stack at a time, the item stack you dip into it.
Polymorphed items do not change item class: Potions will always yield potions, scrolls will yield scrolls, armor will always yield armor, etc. - the exception to this is polymorphing a crocodile corpse, which will yield a pair of non-cursed fireproof +0 low boots instead of another comestible. Stackable weapons and tools can "merge" into non-stackable ones (e.g. a stack of 4 daggers morphing into a single long sword); other stackable objects are not subject to this.[1][2][3] Unicorn horns are especially popular polyfodder because they may polymorph into other magical tools, such as magic markers. Another useful thing to do if you gain polymorph in the early game is to polypile spellbooks. Polymorphing retains the charges and enchantment of polymorphed items.
When polymorphing wands and spellbooks, their quality degrades. A spellbook will act as if it had been read once more. If the book's combined read/polymorph-count is four or more, it will turn into a blank spellbook counted as read 0–3 times;[4] it will thus subsequently be able to be polymorphed into a non-blank spellbook with 75% chance.
Likewise, a wand may count as if it had been recharged, increasing the chance of an explosion if you attempt to recharge it; thus, it is not generally worthwhile to polypile empty wands, even if they become something worth charging, the chances of the new wand exploding instead of charging are already higher than normal. The chance of a wand's charge counter being incremented by polymorphing it is 6 − x7 where x is the number of times the wand has been recharged.[5]
The recharge count of tools is not affected by polymorphing them, unless the tool becomes a magic marker, in which case its charge counter will be set to 1.
Polypiling items that belong to a shopkeeper can anger the shopkeeper.

Probability of item loss and golem generation
The polymorph beam generated by the wand and spell acts on each pile separately.[6]
First, each item stack in the pile has a chance of resisting, which is 5% for normal items and 95% for artifacts; unique items cannot shudder, polymorph, or be absorbed by forming golems.

A user has suggested improving this page or section as follows:
"List which materials can produce specific golems."

Shuddering
Then, each item stack that did not resist has a chance of "shuddering" (i.e., undergoing a system shock).[7][8]
The probability of an item stack undergoing system shock depends on its BUC status, unless it is a wand, and its size, as follows:[9]

For stacks of less than 5 items:
Blessed non-wand: 1⁄12
Uncursed non-wand: 1⁄8
Wand of any BUC or stack of any cursed items: 1⁄3
For stacks of 5 items or more:
Blessed: 1⁄6
Uncursed: 1⁄4
Cursed: 1
When a stack shudders, it loses 1d(items in stack − 1) items, except in the case of single items, which are always destroyed.
For each item stack in the pile that undergoes a system shock, there is a chance of a golem being created. For each item in a shuddering stack (counting those items destroyed by the shock itself) there is a 1luck + 45 probability of creating a golem.[10] A 1luck + 45 chance for each item means the chance that a stack generates a golem is approximately sluck + 45 for small s. No more than one golem can be created per pile.[11] However, even after NetHack has decided to create a golem, additional stacks in the pile can shudder. 
If an item stack shuddered, even if some of the items that were in the stack remain, it will not be polymorphed. The rest of the stacks in the pile still have a chance of being polymorphed.[12][13][14][15]
For any stack that did not shudder, the polymorph process continues. There is a (number of items in stack/1000) probability that the entire stack merges into a single item.[16]
Additionally, when attempting to polypile rocks or gray stones into gems or worthless glass, an 1d4 is rolled against stack size; if the stack is larger, transmutation "backfires", destroying half of the stack and turning the rest into rocks unconditionally.[17]
The actual polymorph is now performed. See the next section for exactly what your item stack will be turning into.
This process is repeated for each item stack in the pile.

Golem absorption and types
If a golem is created from any stack in a pile, it can "absorb" additional item stacks in the pile, destroying them. The material destroyed by the golem is separate from that destroyed by the original system shock(s). If, after every stack has been polymorphed, zero or one item remains in the pile (due perhaps to bad system shocks), golem creation is aborted, if it had been planned at all. According to a comment in the source: "no golems if you zap only one object – not enough stuff".[18] (This comment is slightly inaccurate; it's possible to zap several items, reach this point in the code, and have the material check fail because all or all but one of the items were destroyed by system shocks.)
The golem will attempt to absorb a number of individual items (not item stacks, "4 scrolls" counts for 4, not 1), equal to its weight.[19][20][21] Only items that are made of the same material as the item stack whose shuddering cause the golem to form are eligible for absorption. For instance, if a mithril-coat shudders and results in an iron golem, that iron golem will absorb other mithril items on the pile, but leave iron items untouched. Each eligible item stack has a 1 in (golem weight + 1) chance of escaping absorption. Given the high weights of golems, 400 for straw and paper up to 2000 for iron, it is highly unlikely that any eligible item will survive this process. Also, this absorption occurs after the items have been polymorphed. If a mithril item shudders and creates an iron golem, and several other mithril objects on the pile are polymorphed into other materials, e.g. leather coats or iron helmets, they will not be absorbed, though any leather coats or iron helmets polymorphed into mithril items will be absorbed.[22]
Each stack in a pile is polymorphed separately, in order of the most recently dropped, and the type of golem is determined by the material of the first item stack to shudder and result in golem creation.[23][24][25] This is exploitable; see §&nbsp;One large pile for details.

Artifacts
Artifacts have a 95% chance of resisting. (Compare to 5% for normal items.) If this 95% chance fails, they are polymorphed just like every other item, first undergoing a shuddering check and then, if they aren't destroyed, undergoing a polymorph to a random non-artifact weapon. Artifacts have no resistance to being absorbed by a forming golem. Excalibur may be mostly safe from shuddering or polymorphing atop that pile of iron junk, but if an iron golem forms it is virtually guaranteed that Excalibur will be destroyed.[26]

Summary of polyfodderdestruction
This process, from the resistance check to here, is repeated for each pile hit by the beam.
In other words, there are 3 ways polyfodder can be destroyed:

Shuddering, the probability of which is decreased by blessing, polymorphing items other than wands, and keep the size of individual stacks under 4.
Merging, the probability of which is reduced by lowering the size of individual stacks.
Stackable weapons and tools merging into non-stackables (separate from the n/1000 chance outlined above), which is mitigated by lowering stack size of weapons and tools.
Absorption into forming golems, the probability of which is reduced by:
Increasing your luck, reducing the chance of golem formation.
Reducing the size of the individual item stacks, reducing the chance of golem formation.
Reducing the number of item stacks on the pile, reducing the number of opportunities for golems to form.
Limiting the number of items on the pile that are made of the same material, reducing the number of items a forming golem can absorb.
In particular, the items on the top of the pile, the ones you drop last, should be a different material than the most valuable items in the pile. Potential golems will likely be made out of the material of the top items, not the material of the valuable items. Thus the valuable items will survive while the cheaper ones are destroyed. See §&nbsp;One large pile for details.
Probability of item transformation
When polymorphing a magical object, the game will try to change it into another random magical object, retrying up to two times if the replacement would be non-magical.[27] The third item generated will be used, regardless if it is magical. The reverse is true when polymorphing a non-magical object. The upshot is that a magical object has a significantly higher probability than a non-magical object of turning into another magical object. So don't expect many magic markers from polypiling pick-axes and mirrors; you will have much better odds polypiling unicorn horns. The exceptions are potions of water, blank scrolls, blank spellbooks, and wands of nothing, all of which have a high chance of becoming more-useful items of the same type. As mentioned above, blessed items have only a 1/12 chance of undergoing system shock, so blessing your polypile items is definitely worth the expenditure if you have a surplus of holy water.

A user has suggested improving this page or section as follows:
"Numbers for rings (and scrolls?) would be nice."

Class
Magical → Non-magical
Non-magical → Magical

Armor
54%
0.60%

Gem
92%
negligible

Potion
1.70%
41%

Spellbook
negligible
95%

Tool
60%
0.30%

Wand
negligible
93%

Forbidden items
The following items cannot be produced by polymorph:

magic lamp[28]
wand of wishing
wand of polymorph[29]
potion of polymorph[30]
spellbook of polymorph[31]
artifacts[32]
any item not normally randomly generated, such as athames and fedoras
The following items cannot be polymorphed:

Rider corpses
wand of polymorph
potion of polymorph
spellbook of polymorph
Strategy
Polypiling is often used to get ascension kit armor (and completed by wishing). Therefore, you might want to collect all those elven cloaks and boots in the game.
Polypiling is most often used by conduct players who need certain items: It can substitute for wishing, prayer and sacrifice benefits, or literacy, and it can be done relatively safely. Generated monsters offer an almost unlimited supply of polyfodder. However, polypiling is time-consuming and tedious. Generally, it is not worth it unless you are trying for conducts, or unless you are looking for many items at once.
Over-preparing is the other common reason for polypiling. This goes for many first ascenders, pacifist characters who want the most protection, or even an attempt to get a very high score by polypiling rocks into gems.

General tips
Never handle both polyfodder and items you want to keep in your main inventory at the same time, and never ever drop anything useful on your polypile line. People have wondered where their bag of holding with all the artifacts went.
Even if you do not care about polyfodder loss, #name rocks to get stacks of at most four. There is a limit to how many gems can be created.
Max out your luck to minimize golem creation. That reduces the total material lost. This is particular useful for larger stacks and piles, where any golem will do comparatively more damage. Do not max your luck if using the one large pile strategy below.
Configure autopickup exceptions to pick up good morphs and your want-to-keeps from the pile.
Polypile your items near a general store to help identify good morphs. Be very careful of polypiling in a store; if any of the shopkeeper's items are polymorphed, they will become angry and attack you without giving you a chance to pay.
Familiarize yourself with the ways polyfodder is lost to determine how much risk to take on, given your available polyfodder and the amount of polypile sources you have available to you. Your patience is also a factor, perfect optimization is time consuming and tedious.
Preparing
To minimize loss, it is a good idea to mass-bless magical polyfodder, which is much less abundant than ordinary junk. Potions and scrolls can be canceled so they will stack, and then dipped in holy water. Name and separate them into stacks of at most four items before polymorphing. Only armor and weapons (and wands) retain their enchantment; these should be canceled if negative before blessing. A large stack of darts can be enchanted to +7 in one go and then polypiled individually for potentially powerful weapons. Magical armor and tools tend to become non-magical rather than shuddering, so there is no point blessing them.
Non-stackables, such as rings, require more work to bless. Often, it is not worth the costs. The most efficient way is with a blessed, confused scroll of remove curse. In a safe location, pick up as much polyfodder as possible but carry no other uncursed items. Then confuse yourself, read a blessed scroll of remove curse, end confusion, and mass-uncurse cursed items with the remove curse spell at a skilled level. The light blue aura boon when carefully praying on an altar or even another scroll can also uncurse your entire main inventory. This procedure yields 12.5 blessings per scroll on average.
Unless you will need only one read, name spellbooks individually how often you have read them, and sort them accordingly. Under each pile you intend to polymorph, engrave that number. Any nameless books after the polymorph will count as read one more time. Keep in mind how often you will have to re-read the spells you get.
Sort polyfodder by BUC status so you won't have to re-test after polypiling.
When to polypile
If a game has been unforgiving, a good time to consider polypiling is when there are many things needed at once; the odds of getting at least one of them is improved. For example, if you're looking for a magic marker in particular, getting a tinning kit would be seen as a waste. However, if you were looking for both a magic marker and a tinning kit, the effective odds of getting something you want go up. If you're looking for a horn of plenty, a magic marker, a pair of lenses, and a tinning kit all at once, polypiling unicorn horns begins to look increasingly attractive.
Potions are attractive to polymorph, due to the ease of creating fruit juice and water, and mass blessing them. Furthermore, with the help of alchemy, a good third of the available potions are useful in some way. While you may not get the potion of enlightenment, or gain level, that you wanted, you are likely to end with various healing potions, levitation, etc, that can be quickly used to work towards what you really want.
Scrolls are commonly polymorphed for similar reasons. Here, part of the motivation is in doing away with magic markers. It adds a great deal of randomness to the mix, but scrolls are still cheaper than marker charges.
Magical tools, especially unicorn horns, are a common fodder due to the large number of useful magical tools and the abundance of unicorn horns. (Revived unicorns have a 50% chance of leaving another horn.) Certainly, the magic marker is generally what most would go for, but in the attempt you might find other goodies. A horn of plenty, for instance, spawns potions you can polypile; a fire or frost horn may also be of help, as may a magic harp or magic flute. This is especially helpful to Tourists or other neutral players with the PYEC.
Magical armor can help finish off an ascension kit, most often using the various abundant elven equipment as fodder. This is mostly only useful to (wishless) conduct players, as the castle's guaranteed five wishes are good enough to get all the missing types of armor; furthermore, its armor stores might contain missing pieces.
A common trick is to polymorph elven armor, which can safely be enchanted to +7, into a +7 T-shirt. The number of +7 armors isn't terribly prohibitive: the blessed scroll of enchant armor (to get to +7) will also bless the armor and reduce the odds of shuddering.

Confidence
Base chance
25%
50%
75%
95%

Polymorphs
1 in 100

28.62

68.97

137.94

298.07

Shuddering
1 in 12

3.31

7.97

15.93

34.43

Armors needed (approx.)
—

3.59

8.66

17.32

37.41

Rings can help finish off an ascension kit, particularly with rings of levitation, slow digestion, or free action, if you're unlucky and haven't found them before Medusa's Island. Most other rings are only useful in specific situations, polypiling or not.
One cheesy trick is to polypile for rings of protection or increase damage, with the intention of eating them. It's possible to get a ridiculously low AC  or ridiculously high damage. The former is pointless, other than to sound impressive, because you can reasonably get to −40AC without such mind-numbing busywork, and that is enough to make even a minotaur barely scrape the polish on your armor. The latter may be for Death farming to a ludicrously high score.
Spellbooks, if you are happy with any random book and accept you cannot re-read it. Early in the game, when you don't know many spells yet, you can get dozens of new ones out of a few spellbooks.  In 3.6.0 the bug allowing to always learn new spells from overpolymorphed spellbooks has been fixed; a non-blank polymorphed spellbook will be counted as read 1–3 times, and you can only learn a new spell from it if this number is lower than 3. Otherwise, it will turn blank on reading. Thus, it is advised to formally identify unknown polymorphed spellbooks before reading, so you could overwrite them with a magic marker in the latter case.  Newbies might carry books and rings along (unencumbered) into a Minetown shop in the early game and polymorph there.
Junk armor: Shirts are annoyingly rare in the main dungeon, but other armors are not. Zapping a wand of polymorph at that 15 pages pile of items in Fort Ludios is probably the easiest way to get a shirt outside of bones, wishing, or playing a Tourist.
When can also be considered "in the temporal sense". By the time you reach Vlad's Tower, you can take a little break, lock the door and begin the process in peace and quiet, after having accumulated a backbreaking load of loot. One nice benefit is that you can also use that location to summon wraiths that will leave a corpse to eat, unlike the rest of Gehennom, should your efforts yield magic markers for writing genocide on any cursed blank scrolls (for generating the last, note the guaranteed water walking boots there).
When not to polypile
Wands are generally not worth it. This is mostly because by the usual time the player has a serious stash of wands, and abundant means to polymorph objects (read: the spell), there is only one wand seriously worth going after: death. But this late into the game, there are only four monsters that it matters on—Pestilence, Famine, the Wizard of Yendor, and the high priest of Moloch. Likely (but not necessarily), you already have enough wands of death to deal with those enemies. Also, polymorphed wands will more likely explode if charged again.
In the midgame, however, it may be worth it. If the player doesn't quite have enough items to make a full polypile line, a square of scrap wands may not make anything that you need, but it might make a wand you've yet to identify (if it has charges left). It may also be that you need a wand's special properties—for example, a wand of fire's ability to engrave a permanent Elbereth square.
Specific spellbooks: If you only need one specific spellbook (or a spellbook of polymorph to start with), there are better methods than polypiling. Wizards with sufficient luck can write one using a magic marker. Anyone willing to do the altar work can get books from their god, especially the last few ones you do not yet know.
There are better ways to get various other items. For example, a trident, while normally quite rare, can be found in the death drop of a salamander or a horned devil. A silver saber, very desirable for twoweapon combat, can be found in the inventory of the Minetown watch, or the various captains that show up in the Castle.
Items not generated randomly aren't available from polypiling, e.g. athames.
Stacking strategies
Seven small piles
Step by step
Maximize your luck. (+13 is best.)
Collect your items. See the section above to decide what to polypile.
Individually name stackables to separate them into stacks of two (preferable), three, or four. Try to avoid single items, except for weapons and tools, which should be completely unstacked.
Distribute the item stacks over seven small piles in a straight line, each pile containing a good mix of different types of material. Put the items you want polymorphed most at the front of the line. (First three piles are guaranteed, each of the four piles after that is progressively less likely.)
Zap polymorph.
Review results. Autopickup with exceptions can automate this for you.
Repeat.
Explanation
Separating your stackables minimizes the chances of merging and shuddering. Weapons and tools will eventually turn into something unstackable, and you lose all but one. For other items, stacks of one are less desirable, since shuddering destroys them completely, while larger stacks only lose half of the stack on average.
Maximizing your luck minimizes the chances of golems forming.
Distributing your item stacks over 7 squares minimizes the damage a forming golem can do, because a golem can only absorb items from the square it forms on. 
Ensuring a good mix of different materials also minimizes the damage a forming golem can do, because the golem can only absorb items that are made of the same material as the shuddered item that led to its formation.

One large pile
Step by step
Minimize your luck. (0 is good; −13 is better!)
Collect your items. See the section above to decide what to polypile, but avoid items made of mineral (e.g. some rings, wands). The number of wands and rings destroyed by this method will be slightly greater than the number destroyed by the seven small piles method. If you want to polypile mineral-based items, do not use this method.
Individually name stackables to separate them, especially weapons and tools. Separating them all the way into stacks of just one single item is best, but just getting them into stacks of four or fewer is almost as good.
Put every item stack in one large pile.
Obtain a very large number of rocks.
Curse the rocks.
Individually name the rocks to break them into small stacks. Five rocks per stack is best, get as close to that as your patience allows. Do not make stacks smaller than five.
Drop all the rocks on top of the item pile. Make sure you drop the rocks after the items so they are on top!
Zap polymorph.
Kill the stone golem.
Review results.
Repeat.
You want a stone golem to form from those rocks, because it will prevent other types of golems from forming and damaging your valuable polyfodder. Assuming cursed rocks in stacks of 5, and Luck of 10: 50 rocks is approximately a 58% chance of a stone golem, 200 rocks is approximately a 97% chance of a stone golem, and 300 rocks is approximately a 99.5% chance of a stone golem.
A rubber chicken and a pick-axe are quite helpful here, in order to create a large number of rocks near the fodder pile.

Explanation
This method exploits the specifics of the polypiling algorithm.
Separating your stackables minimizes the chances of merging and shuddering. The only threat to deal with now is golem absorption.
Ordinarily putting every item stack on one pile would be a terrible idea, because any forming golem would have access to every item you were polypiling. However, in this strategy we ensure that the golem won't be able to absorb anything useful, by manipulating the material it is made of. A golem can only absorb items made of the same material it is. An iron golem generated from shuddering mithril can only absorb other mithril items. A wood golem generated from shuddering wood can only absorb other wood items. And—most importantly in this case—a stone golem generated from a shuddering mineral item can only absorb other mineral items.
Only one golem can be generated from a pile, and the first item stack to shudder and lead to golem formation gets to decide the material. By putting the rocks on top we ensure that they get processed first.
Cursing the rocks increases the chances that they will shudder.
Keeping the rocks in stacks of more than 4 (5 in this case) also increases this chance.
Minimizing our luck increases the chances that our rocks will give rise to a golem once they shudder.
The probability of an individual stack not giving rise to a golem, if it shudders, is (luck + 44luck + 45)s, where s is the stack size. The probability of the stack shuddering (and not resisting initial polymorph) is 95% for stacks of 5 or more cursed items; this is the highest chance we can get. Thus the probability of a stack not forming a golem is 0.05 + 0.95 × (luck + 44luck + 45)s. If every stack of rocks in a pile is identical (all contain 5 cursed rocks), then the chance of none of them giving rise to a golem is (0.05 + 0.95 × (luck + 44luck + 45)s)n, where n is the number of stacks. Thus we want our stacks to be as small as possible, so that we can have as many as possible, without having fewer than 5 rocks per stack.
For the most part, there are no items made from mineral you might be interested in polypiling for. The exceptions are marble wands and granite, opal, clay, coral, moonstone and black onyx rings. The material an item is made of can change when it is polymorphed, and it is the final material that matters for golem absorption. Since any polymorphed wand or ring could end up being one of the mineral ones, the effect is that this technique will consume slighty more wands and rings than the other technique, and that the specific item types that are made of mineral cannot be polypiled for (with this method).
There is a 5% chance of a normal item resisting polymorph and reaching this point unchanged, so the initial material matters somewhat as well. For instance if you try to polypile a figurine and it resists, it is almost guaranteed to be absorbed (because figurines are mineral).
Beware! In the unlikely event that a stone golem does not form from the rocks: then, given the large pile underneath, there is a good chance a golem will form from another material, possibly doing a lot of damage. With enough cursed rocks, less material is lost on average with the one-pile than with the multi-pile technique.

One large pile with meatballs
If you know stone to flesh spell, you should cast it at your rocks to turn them into meatballs, then use them instead of rocks in the advice above. In this case, you can polypile for mineral items, but can't polypile for eggs and tripe rations. The golem rising from the pile will be a flesh golem instead of a stone golem.

Variants
SLASH'EM
In SLASH'EM, polymorphed items revert back to their original form after 500–999 turns.[33] Items that will eventually revert are described as "hazy" in wizard mode. Hazy items can be "fixed" by dipping them in a potion of restore ability.
There are some exceptions to this:

Items that were initially eggs laid by the player[34] or corpses[35] do not revert.
If a magic lamp is randomly chosen at first, the oil lamp with which it is replaced does not revert.[36]
Items that become land mines or beartraps do not revert.[37]
Items that become the same object type as they were before do not revert, even if they otherwise changed (such as a diluted potion of sickness becoming an undiluted potion of sickness).[38]
The reversion is done not by restoring the original item but by changing the item to the original item's type,[39] which has some consequences that may not be expected, including the following:

Some properties, such as beatitude and erosion, are carried over from the transformed item rather than the original.
Some other properties, such as being an artifact, are lost.
A stack of multiple items that became a single item reverts to a single item of the original type.
An item that became an amulet of unchanging does not revert.[40]
The transmutation limits the usefulness of polypiling somewhat, as obtaining permanent items requires a commensurate supply of potions. However, polypiling is still just as useful to obtain items that can be useful right away or relatively soon; for example, a polypiled magic marker can be immediately used to write a few scrolls, and then allowed to transmute back after it is empty.
In some cases, the reversion can be useful:

When polypiling magical items, if they turn into non-magical items, one can simply wait for them to revert, and try again.
Boulders can be polymorphed into statues and transported more easily, and will turn back into boulders.
Any armor can be safely enchanted to +7 by polymorphing it into elven armor.
If you have a wand of polymorph and two or three potions of gain level, you can easily get a +7 helm of brilliance by polypiling ubiquitous orcish and dwarven helmets until you get an elven item (or something that can be upgraded into one), enchanting, and upgrading the enchanted helmet after it reverts.
Some further consequences are probably bugs:
After polymorphing a boulder into a statue, breaking it will result in a number of rocks; if they are separated, each separate stack reverts to a boulder.
Weapons can be polymorphed into dwarvish mattocks, upgraded to pick-axes, and polymorphed further into other tools, particularly charged ones; when they revert, the weapon's enchantment will be the tool's number of charges, which can be much higher than normally feasible.
SlashTHEM
In SlashTHEM, polymorphed items that will revert after a certain amount of turns are displayed as "hazy" in normal play; the same mechanics apply for "fixing" that item in its current form.

Code
bhito in zap.c is the root of item polymorphs from the spell and wand. It is called for each stack of items a polymorph zap hits by bhitpile. First it refuses to polymorph polymorph-sources, and allows items to resist.[41] It calls obj_shudders to check for system shocks[42] and calls do_osshock to perform them.[43] Finally bhito calls polyobj to actually transform the stack.[44]
do_osshock determines whether or not to generate a golem, and after all the stacks in the pile have been polymorphed by repeated calls to bhito, bhitpile calls create_polymon to actually generate thegolem.
If create_polymon is called, it possibly creates the golem and then, if the golem was created, in turn calls polyuse to consume additional polyfodder.[45]

References

↑ zap.c in NetHack 3.4.3, line 1234

↑ zap.c in NetHack 3.4.3, line 1312

↑ objclass.h in NetHack 3.4.3, line 15

↑ zap.c in NetHack 3.6.1, line 1552

↑ zap.c in NetHack 3.4.3, line 1333: recharge count &lt; rn2(7)  to see if polymorph increments charge counter on wands

↑ zap.c in NetHack 3.4.3, line 2744: bhit calls bhitpile for each square/pile

↑ zap.c in NetHack 3.4.3, line 1733: bhitpile goes through each stack separately, calling bhito--to which a function pointer has been passed in as fhito--to perform the actual polymorph

↑ zap.c in NetHack 3.4.3, line 1515: bhito calls obj_shudders on just one object, and obj_shudders does not inspect other items on the square, i.e. in the pile

↑ obj_shudders in zap.c (obj_shudders determines whether a given stack will shudder.)

↑ zap.c in NetHack 3.4.3, line 1162: do_osshock decides whether or not it should make a golem

↑ zap.c in NetHack 3.4.3, line 1160: poly_zapped is a file level static variable, visible to every function in zap.c, −1 means no golem created yet, else it contains the material of the item whose shuddering resulted in golem creation. do_osshock checks that its −1 before trying to make a golem.

↑ zap.c in NetHack 3.4.3, line 1519: if the obj shuddered, bhito exits WITHOUT polymorphing the object.

↑ splitobj in mkobj.c (If any items remained after the shuddering occurred, they will have been reinserted in the item tracking linked list, but they will have been inserted before the deleted ones, and bhitpile will not return to them.)

↑ zap.c in NetHack 3.4.3, line 1735: bhitpile decides the next object before bhito has a chance to call do_osshock and destroy/split item stacks.

↑ zap.c in NetHack 3.4.3, line 1521: poly_obj is called AFTER do_osshock has finished with the stack.

↑ zap.c in NetHack 3.4.3, line 1312: poly_obj decides whether or not to merge the items in the stack

↑ zap.c in NetHack 3.6.1, line 1561

↑ zap.c in NetHack 3.4.3, line 1076: golem creation aborted for not enough items

↑ zap.c in NetHack 3.4.3, line 1140: mons[pm_index] is a permonst structure, defined in permonst.h, the cwt field is the weight of the monsters corpse, which is defined for golems even though they leave no corpses.

↑ zap.c in NetHack 3.4.3, line 1035: polyuse doesn't stop absorbing items until minwt is 0, minwt is initialized to golem corpse weight

↑ zap.c in NetHack 3.4.3, line 1054: not that polyuse is subtracting the QUANTITY of objects from minwt, not the WEIGHT of those objects. iron golems will absorb up to 2000 iron items

↑ zap.c in NetHack 3.4.3, line 1043: which items are eligible for absorption; note that "mat" is the material of the shuddered item stack NOT of the golem created

↑ zap.c in NetHack 3.4.3, line 1160: once NetHack decides to create a golem it records the shuddering stack's material and stops trying to create golems for additional stacks.

↑ zap.c in NetHack 3.4.3, line 1733: bhitpile goes through objects forwards through the list

↑ mkobj.c in NetHack 3.4.3, line 1115: place_object adds dropped objects to the front of the list, where bhitpile will encounter them first.

↑ zap.c in NetHack 3.4.3, line 1038: resistance check only serves to protect the invocation items and the amulet

↑ zap.c in NetHack 3.4.3, line 1215

↑ zap.c in NetHack 3.4.3, line 1319: no magic lamps

↑ zap.c in NetHack 3.4.3, line 1329: no wands of wishing or polymorph

↑ zap.c in NetHack 3.4.3, line 1338: no potions of polymorph

↑ zap.c in NetHack 3.4.3, line 1343: no spellbooks of polymorph

↑ zap.c in NetHack 3.4.3, line 1225: mksobj is called with "artif" set to false -- no artis

↑ timeout.c in SLASH'EM 0.0.7E7F2, line 455

↑ zap.c in SLASH'EM 0.0.7E7F2, line 1443

↑ zap.c in SLASH'EM 0.0.7E7F2, line 1489

↑ zap.c in SLASH'EM 0.0.7E7F2, line 1518

↑ zap.c in SLASH'EM 0.0.7E7F2, line 1526

↑ timeout.c in SLASH'EM 0.0.7E7F2, line 453

↑ timeout.c in SLASH'EM 0.0.7E7F2, line 480

↑ zap.c in SLASH'EM 0.0.7E7F2, line 1374

↑ zap.c in NetHack 3.4.3, line 1503: bhito does a resistance check for each item

↑ zap.c in NetHack 3.4.3, line 1515: bhito checks for system shocks

↑ zap.c in NetHack 3.4.3, line 1518: bhito performs a system shock

↑ zap.c in NetHack 3.4.3, line 1521: bhito calls polyobj

↑ zap.c in NetHack 3.4.3, line 1140: create_polymon calls polyuse

External links
Breaking wands, cancelling, and polymorphing in NetHack 3.4

This page may need to be updated for the current version of NetHack.
It may contain text specific to NetHack 3.4.3. Information on this page may be out of date.
Editors: After reviewing this page and making necessary edits, please change the {{nethack-343}} tag to the current version's tag or {{noversion}} as appropriate.