Minecraft wiki entry for Before_1.8, associated text: An approximation for the cost breakdown without renaming or other complications, is: (BaseValue/4) + (PriorWork/2) + (NewEnchantmentCost/2) + levels gained × (cost-per-level × 3/4). If each part in parentheses needs no rounding, then the answer is exact.
When the sacrifice is a book, costs are significantly cheaper than sacrificing a matching item with same enchantment. This allows enchantment combinations that wouldn't be possible otherwise, but it also makes it easier to produce an item that can't even be repaired.
Sometimes it is good to rename an item while combining it with a book with an incompatible (or duplicate, maxed-out) enchantment to lower the cost, especially if you had no use for the book anyway.