Handling branches in computer systems is indeed unbelievably subtle. Here is one slightly complicated example which comes out correctly, at least when looked at in the right way; this is encouraging. The following integral comes up in an ODE test: . The right hand side is as computed by the meijerint code and looks suspicious, not being invariant under complex conjugation. However, note that on both sides are branched functions: and . The left hand side is unbranched at the origin, whereas the right hand side is unbranched at infinity. The left hand side is branched at infinity, whereas the rigth hand side is not. (There is nothing unusual about this, there is no reason to expect indefinite integrals to retain branchpoints.)
Thus in order to understand what is going on, we first have to understand the extension of both functions to true polar numbers , because this is what the meijer g code works with. Since inverse sine is surely nasty, let’s try to understand the square root expression. A clue comes from enabling debug output: the meijerint code decides . From the definitions, for we find , where , which we shall define only for , is , evaluated on the principal branch (indeed it is just a binomial series). Also from the definitions, we find that for , , where denotes the holomorphic function (which is, in particular, continuous, i.e. free of branch cuts). Finally we know that for , these two definitions must patch together continuously.
Note how the branching has been resolved crudely: for every polar number x (outside a set of measure zero which does not disconnect ) the integrand has acquired a definite value, continuous on circles. However, there is a circular branch cut on every other sheet.
Now let’s look back at the integrand. The meijerint code interprets as . [It’s and not since “in the wild” means in the standard branch. Of course one can specify this by hand if it is not the desired choice.] Hence for , the integrand is (Recall that in the first term the the square root means the continuous function on , and so the second term is the same as the first. In the third term the square root denotes the principal branch, which is continuous throughout as well.)
Finally, for , the derivative of is , again with the principal branch of the square root (for the same reason as before: continue analytically on circles from the real-valued function). Thus lo and behold, if we differentiate for , we do get out the right sign. As a side note, if we replace in the integrand by , we get the other sign.