Thanks to some beneficial math on his behalf — by which his jail sentence was re-computed so that he received credit for time previously served in a drug rehab clinic — actor Robert Downey Jr. was released from a California prison on $5,000 bail yesterday. He had been serving a three-year sentence on drug charges and was due for release in November. “When those additional time credits are added in, it is obvious appellant (Downey) has more than served his sentence,” the California Second District Court of Appeal ruled. The legal woes of the “Chaplin” Oscar nominee, 34, began in June of 1996, when he was stopped for speeding in Malibu and police discovered cocaine, heroin and a gun inside his car. In jail, Downey shared a cell with four other inmates, was assigned to the prison kitchen and attended drug rehab sessions. He is now said to be staying at the L.A. home of an unidentified friend.