Math behind Quality

Don't know how to use a machine? Looking for efficient setups? Stuck in a mission?
Tertius
Smart Inserter
Smart Inserter
Posts: 1593
Joined: Fri Mar 19, 2021 5:58 pm
Contact:

Math behind Quality

Post by Tertius »

Who is able to do the math behind these 2 different crafting approaches for legendary fusion power cells?
I tried but failed. I understand the math in general, but I just can't seem to put all the pieces together.

My goal was to get the approach that requires the least amount of normal input items. It also shouldn't be too big, because it's just needed for crafting 1-3 legendary portable fusion reactors. The washing approach here seems the proper one, since upcycling the reactor doesn't seem appropriate. The other legendary ingredients of the reactor can be acquired by upcycling other items much more efficiently.

So what's the math and the exact amount of input items per legendary cell? The approach on the left boosts normal cell production with maximum productivity, then washes the result with quality recyclers. The other one does quality in every machine and is much bigger for the same speed, because you cannot speed boost machines with quality modules.

I just built both approaches and counted the items, and both resulted in roughly the same input:output ratio in general. But is this real or just a result of some lucky roll for one of them?
03-15-2026, 13-28-42.png
03-15-2026, 13-28-42.png (735.47 KiB) Viewed 312 times
03-15-2026, 13-26-06.png
03-15-2026, 13-26-06.png (1.02 MiB) Viewed 312 times
Hurkyl
Fast Inserter
Fast Inserter
Posts: 131
Joined: Mon Dec 02, 2024 10:54 am
Contact:

Re: Math behind Quality

Post by Hurkyl »

If you're just sending things to a recycler that recycle into themselves, then the value (meaning the average number of legendaries you get from it) of an epic item is

Code: Select all

Epic = 0.25 * (0.752 * Epic + 0.248 * Legendary)
Epic = 31/406 * Legendary
Here, 0.248 is the quality percentage on the recycler, and 0.752 is one minus that. 0.25 is the proportion of returns from the recycler.

Similarly, a rare item is worth

Code: Select all

Rare = 0.25 * (0.752 * Rare + 0.248 * (Epic * 9/10 + Legendary * 1/10))
Rare = 4247/329672 * Legendary
and so forth.

Code: Select all

Uncommon = 581839/267693664 * Legendary
Common = 79711943/217367255168 * Legendary
So if you send 1/Common (roughly 2727) common items to the recycler loop, you average one legendary output.

This meshes with your left example, since the productivity modules means you get 3 fuel cells per plate, meaning the ratio is about 909 plates to 1 legendary cell.


So for other mixes of productivity 3 and quality 3 modules, you should be able to just look at the distribution of common:uncommon:rare:epic:legendary items you get from a plate and plug in the values above.

Although, either something's wrong in my program, your setup, or you got super unlucky (but still plausibly unlucky, I think?). With 8 quality modules my program is saying you should expect 1 legendary cell per 390 plates.

The best looked like 3 productivity modules and 5 quality modules, needing only 328 plates to average 1 legendary cell.

---

I feel it important to point out that you should expect a craft-recycle loop to be an order of magnitude or so more efficient with regards to number of input items: self-recycling is really, really bad in this metric. So I do think it's worth putting more thought to the idea of doing craft-recycle loops making reactors, or instead for producing legendary ingredients to the fuel cell recipe.
Nidan
Filter Inserter
Filter Inserter
Posts: 357
Joined: Sat Nov 21, 2015 1:40 am
Contact:

Re: Math behind Quality

Post by Nidan »

Your repetition counts are far too low to have statistical relevance.

The both setups are essentially a self recycling loop, only the input you count is one step before that loop. A standard self recycling loop takes 2726.9095067473136 common per legendary; accounting for the +200% prod in your left setup that's 908.9698355824378 common holmium per legendary fuel cell.
In your right setup the recycler's input isn't only commons, but the [0.504, 0.4464, 0.04464, 0.004464, 0.000496] spread produced by the cryo plant. Reycling that down to legendary gives 389.55850096390185 common holmium per legendary fuel cell.
Hurkyl wrote: Sun Mar 15, 2026 3:44 pm Although, either something's wrong in my program, your setup, or you got super unlucky (but still plausibly unlucky, I think?). With 8 quality modules my program is saying you should expect 1 legendary cell per 390 plates.

The best looked like 3 productivity modules and 5 quality modules, needing only 328 plates to average 1 legendary cell.
Since I get the same numbers, as far as I can tell, those are correct. And the game seems to agree as well:
Tertius_fuel_cell.png
Tertius_fuel_cell.png (409.23 KiB) Viewed 250 times

Instead of the recursive approach Hurkyl uses, I calculate upcycling loops by repeatedly removing the lowest quality until only legendary is left.
Take the number of the lowest available quality items you're currently dealing with (e.g. 0.504 common in Tertius' right setup) run them through upcycling loop and note the resulting spread (here: [0.094752, 0.0281232, 0.00281232, 0.000281232, 3.1248e-5]). Since the leftovers of the lowest quality will run through the loop again and again until none are left, mathematically we get a geometric series. Thus, we can multiply the other qualities outputs by (input / (input - output)) of the lowest quality ([0.034634482758620695, 0.0034634482758620698, 0.000346344827586207, 3.8482758620689666e-5]), add that to the result of the previous crafting step ([0.4810344827586207, 0.048103448275862076, 0.004810344827586208, 0.0005344827586206898]) and forget the lowest quality ever existed. Repeat until only legendary is left.
Tertius
Smart Inserter
Smart Inserter
Posts: 1593
Joined: Fri Mar 19, 2021 5:58 pm
Contact:

Re: Math behind Quality

Post by Tertius »

Nidan wrote: Sun Mar 15, 2026 5:18 pm Your repetition counts are far too low to have statistical relevance.
Definitely. I let my contraptions run for a longer time, but results were so varying I asked for a direct calculation because of that. Didn't want to run it all night long.

Many thanks to both of you for your efforts.
Tertius
Smart Inserter
Smart Inserter
Posts: 1593
Joined: Fri Mar 19, 2021 5:58 pm
Contact:

Re: Math behind Quality

Post by Tertius »

Hurkyl wrote: Sun Mar 15, 2026 3:44 pm I feel it important to point out that you should expect a craft-recycle loop to be an order of magnitude or so more efficient with regards to number of input items: self-recycling is really, really bad in this metric. So I do think it's worth putting more thought to the idea of doing craft-recycle loops making reactors, or instead for producing legendary ingredients to the fuel cell recipe.
All the other ingredients are much more efficiently to get with upcycling other items, since that can involve productivity. Upcycling the reactor is very inefficient still, since it's without productivity in an assembling machine. The fusion power cell is so cheap, it doesn't matter that much how wasteful the recycle loop is.

The portable fusion reactor requires the portable fission reactor as ingredient, which requires uranium fuel cells, which is kind of the same situation as with the fusion reactor. Its ingredients are cheap, actually almost free as legendary, only the uranium fuel cell cannot be upcycled efficiently with productivity in the loop, so I'm going to wash it the same way as with the fusion power cell since the uranium fuel cell is so cheap as well and not needed in bigger amounts and for nothing else.
coffee-factorio
Filter Inserter
Filter Inserter
Posts: 324
Joined: Thu Oct 17, 2024 10:56 pm
Contact:

Re: Math behind Quality

Post by coffee-factorio »

Hmm...

Beyond the numbers, you have to analyze the crafting chain to make sure it makes sense.

1 Holmium ore -> 5x lithium. And that can be fed through intermediate productivity steps.

You could get holmium ore from a less efficient recipe following the logic of "I don't need a lot". Or a more efficient recipe by breaking down 1x legendary EM Plant for it's holmium, and sending that on one rocket.

Split the holmium from that (150/4 legendary holmium is a bit).
The lithium you direct craft at legendary with productivity. So that's 15 lithium when you use legendary p3 modules. Then that gets multiplied by 1.5 in furnaces. And then on the final craft step you put some remainder of holmium in for every 5 lithium to make 3 legendary fusion cells.

The EM Plant route I have a reliable quote for as 1 in 76.98. The youtuber konage made a nice spreadsheet that I use for baselines, and when I've checked it, the numbers have come out to be reasonably accurate. His matlab code appears to follow the wiki's method of matrix iteration. It would be cell H16 (quality only; max ingredients). https://www.youtube.com/@KonageYoutube

For the recycler only route, cell C15 seems like a quote for doing max quality for an item through a recycler. That would be 1 in 454.51 for a foundry driven plate process.

There's not a quote for doing such a process through an EM Plant. But that ends up being a situation where the end step optimization would be another productivity multiplier. Because the holmium is always a precursor for 5 lithium, it does end up being a cost reduction, proportional to the amount of productivity you put into fusion reactors.
Post Reply

Return to “Gameplay Help”