The Meaning of Life, the Universe, and Everything.
So, I've decided to apply some enchanted books to my diamond pickaxe, but I'm unsure what the cheapest way is. Would merging the books first be the best, or would merging them one by one onto the pickaxe be better?
Every time you use the anvil on an item the cost goes up which imposes a limit on how many times you can repair the pickaxe once you have it and even, if there are a lot of books whether you can apply them all.
The best way is the way that has the shortest chain of anvil operations, instead of adding books one by one to either the pickaxe or to a single book you want to combine items, both books and the pickaxe two by two.
So if you draw a picture of the combinations you get a pyramid shape instead of a long line and your aim is to make the pyramid even and as low as possible, particularly if you don't end up with Mending on the pickaxe.
So, if you have 7 books
Combine book 1 and 2
Combine book 3 and 4
Combine book 5 and 6
Combine Pick and book 7
Combine book (1+2) and book (3+4)
Combine Pick and book (5+6)
Combine Pick with book (1+2+3+4)
And that only counts as 3 prior anvil operations instead of 7 if you had added them one at a time.
Alright, but would the xp cost be the same if book 7 costed 2 xp rather than being 7 xp?
I don't think it matters whether you use the expensive book first or last since the Prior Work Penalty (the extra cost due to an item having been anviled before) is just added to the cost of combining enchantments.
However since, as I understand it, you don't have to pay for enchantments that can't be used (for example Protection on a pickaxe) you'd be better off picking a book with expensive incompatible enchantments as the first one to combine with the pickaxe but figuring that out could be very complicated.
There's a table of the Costs for Combining Enchantments halfway down the Wiki Anvil Mechanics page
for example Thorns and Infinity are expensive enchantments that won't go on a pickaxe, so if a book with those was combined with the pickaxe as the first step they wouldn't add to the total cost which they would if they were added to another book.
A point of clarification regarding the order, when you combine two items or books it often matters which one you put in the left slot and which in the right slot so it's often worthwhile to switch them and see which way is cheapest.