Haggle with them. Get the absolute best deal you can. If they offer you code of laws for 100 gold, they will probably take 75 or even lower.
The Great Library can be immensely powerful, or it can suck, depending on the situation. I nearly always gun for it. Like Mark, I'm all about shooting for Republic, as I think Monarchy is a waste of time and effort. Setting your science rate low in order to buy tech is good for another reason. Once you switch to Republic, you're gonna be short on cash, believe me. You will need some money lying around until you can get some marketplaces up and running. Speaking of which, get currency asap.
The amount you can afford to spend on research is limited by the total commerce of your empire. Once you have a large, well developed empire, science is no longer a problem. So, fighting an ancient war and extorting a bunch of techs is generally a good idea, along with judicious use of your treasury to buy some others. Then settle down, switch to republic, build marketplaces, banks, universities, go democratic... get Copernicus and Newton (same city if possible). Your science rate will improve dramatically.
The higher the difficulty level, the bigger the AI's initial lead will be. You should be able to keep pace early (and kick butt late) up to and including Regent level, as there are no AI bonuses on that level, and AI disadvantages on Chief and Warlord. After that, it gets tougher, but usually involves either beating the AI with a large stick or just biding your time and catching up later.
-Arrian