Why does the main circuit breaker trip but not the smaller branch circuit breakers?
The two branch circuit breakers will trip if the load on their protected circuit is greater than 32 amperes, and 25 amperes respectively. However, since the main breaker trips at 40 amperes. If both branch circuits are pulling a full load the branch circuit breakers will not trip, but the combination of the loads will trip the main breaker (32 + 25 = 57 > 40 as you have said). 

It's a very common situation to have the branch circuit breakers total more than the main breaker, but this is almost never a problem since the circuits usually don't pull a full load. Remember, circuit breakers are there to protect the wires. They shut off the power if you are drawing enough power to damage the wire, so installing a larger main breaker is likely not an option (unless you contact your power company and have the service upgraded, which will include upgrading the feeder cable).   

Contact your local power company, and speak to them about a service upgrade.  Other than plugging less stuff in, or cycling loads, there is not much you can do yourself in this situation.