Weakened by corruption and low prices, Mexico's giant Pemex petroleum monopoly has been trying to cut costs and raise productivity as it struggles to stay afloat in a world glutted with cheap oil.

But experts say the effort by President Miguel de la Madrid's administration has not made much headway, even though the well-being of Pemex is vital to this debt-ridden country of 84 million people.Two of the main obstacles to raising productivity have been corruption and a very powerful union that has been against trimming an overblown work force, said one expert on the Mexican oil industry, who spoke on condition of anonymity.

Nevertheless, Pemex is enormously important to Mexico both as a major source of foreign exchange, and the country's largest tax payer, said oil expert George W. Grayson in a telephone interview from Richmond, Va.

The taxes and royalties Pemex paid last year made up half the federal government's revenues as it struggled through the nation's sixth year of economic crisis. But the petroleum products it sold abroad accounted for 39.6 percent of the country's 1987 export earnings, down from 79 percent in 1982 when the oil industry was booming here.

Petroleos Mexicanos SA, as it is known by its formal name, monopolizes everything from exploring and drilling to heavy petrochemicals, transportation and wholesaling. Only the gas stations, which carry its logo, are privately owned concessions.

It was created by President Lazaro Cardenas, an army general, through an executive order issued March 18, 1938, a few days after he expropriated 17 foreign companies.

International financial circles did not expect Pemex to live long because it lacked money, skills and technology.

Half a century later, Pemex is celebrating its 50th anniversary as one of the world's biggest integrated petroleum companies and a national institution a majority of Mexicans take pride in.

The big bonanza came when Jose Lopez Portillo, the son of a Pemex engineer, became president in late 1976, shortly after a new generation of Pemex geologists and engineers trained in modern techniques located fields in the southeast that turned out to be about twice the size of Alaska's North Slope in Prudhoe Bay.

With half the world starved for petroleum because of high prices, Arab embargoes, and later erratic deliveries caused by the outbreak of the Iran- Iraq war, the young technocrats at Pemex scrambled to find and develop even more sources of new oil.

Pemex has sole rights over all hydrocarbons in Mexico's 761,604 square miles of national territory (three times the size of Texas) and in the 200- mile offshore belt on both coasts that Mexico claims as an exclusive economic zone.

As a result, the country's proven oil reserves of 48 billion barrels in 1987 - almost twice as big as those of the United States - remain the world's fifth largest after Saudi Arabia, Kuwait, the Soviet Union and Venezuela.

But much of that oil lies inside tightly packed rock formations, making it too expensive to pump out at today's depressed prices. Reserves are down by an estimated 2 percent from three years ago, because exploration has not kept pace with production.

Exploration was restricted after the government cut Pemex's budget by 8 percent last year, along with almost everything except a few priority projects, because of the country's economic crunch.

The bust came during the last months of Mr. Lopez Portillo's six-year term, when North Sea, Alaskan and other non-OPEC oil fields started to flood world markets and traditional producers began slashing prices to hold on to their clients.

At the height of the oil boom from December 1980 to May 1981, Pemex light-grade Isthmus crude sold at $38.50 a barrel. As of this January, Isthmus crude had dropped to an average of $15.03 a barrel. February prices have not yet been released.

Aside from the price slide, the company also continues to battle corruption, much of it centering around the Oil Workers Union, which represents 95 percent of Pemex's 183,000 workers and employees.

Mr. De la Madrid, who inherited these problems - along with a giant foreign debt now estimated at $105 billion and few resources to meet payments on it - launched a moral renovation campaign at the beginning of his administration and appointed Mario Ramon Beteta, a veteran economist, as head of Pemex.

Mr. Beteta riled the union by trying to crack down on corruption, cutting costs and pork-barrel contracts to union companies. By law, 5 percent of the value of all Pemex contracts used to go to the union, which owns a host of service companies, from drilling to pumping and construction. Mr. Beteta cut that to 2 percent, also mandating that the contracts be awarded through open bidding.

Francisco Rojas, who succeeded Mr. Beteta last year, replaced four of Pemex's seven deputy directors and laid off 900 non-union employees, but the fight against corruption continues. Industry sources say the union still wields considerable power and maintains the inside track on most contract work.

To hold down costs, Pemex has concentrated on developing the gusher fields on and offshore in the southeastern part of the Gulf of Mexico, where the oil is cheapest to produce.

Export revenues are down from an annual high of $16.4 billion in 1982-84, to a low of $6.1 billion in 1986 and $8.5 billion last year. Production has dropped from an average of 2.65 million barrels a day then, to 2.40 million in 1986 and 2.60 million last year.

About half of Pemex's production is used domestically, supplying an estimated 90 percent of Mexico's energy needs.

Roughly a quarter more is exported to the United States. The rest goes mostly to Japan, Spain, France, Israel and Central America.

Mexico has consistently tried to project a conservative and independent image as a world exporter. It refuses to join the Organization Petroleum Exporting Countries, even though it has reluctantly cooperated at times.