8

Recently I tried to check a result of integration which should be a linear combination of the Riemann $\zeta\;$-function at various arguments, the coefficients of the combination being of primary interest.

Unfortunately Mathematica have expanded all occurrences of $\zeta\;$-functions with even integer arguments.

Is there a way to prevent it from doing that?

A sample code:

 Integrate[ Log[1-x]^5/x^5, {x, 0, 1}]
drer
  • 719
  • 3
  • 9

2 Answers2

10

This is even simpler (thanks to @CarlWoll):

ClearSystemCache[]; 
Block[{Zeta = Inactive[Zeta]}, 
 Integrate[Log[1 - x]^5/x^5, {x, 0, 1}]]

Mathematica graphics

Original answer:

Using the Gayley-Villegas trick:

Internal`InheritedBlock[{Zeta},
 Unprotect[Zeta];
 Zeta[a_Integer /; a > 1] /; ! TrueQ[$in] := Block[{$in = True},
   Inactive[Zeta][a]
   ];
 Protect[Zeta];
 Integrate[Log[1 - x]^5/x^5, {x, 0, 1}]
 ]

Note: The integral is actually computed in terms of limits of an expression involving PolyLog[n, 1-x] (for n = 2,3,4,5); we could do something similar for PolyLog as was done for Zeta above. However PolyLog actually evaluates to Zeta first, which is why the above works in this case. I mention it in case PolyLog does not evaluate to Zeta in a future version. And it's possible the integral will not be computed in terms of PolyLog in the future, too, I suppose. In any case, I thought some explanation of why the code happens to work in this case would be helpful. (It will certainly help me a year from now when someone asks why this doesn't work, and I won't remember a thing about it.)

Michael E2
  • 235,386
  • 17
  • 334
  • 747
  • 1
    Simpler is ClearSystemCache[]; Block[{Zeta = Inactive[Zeta]}, Integrate[Log[1 - x]^5/x^5, {x, 0, 1}]]. I tried using this Block earlier and it didn't work. When I saw your answer, I realized that the cache was interfering. – Carl Woll Apr 14 '18 at 15:50
  • @CarlWoll Ditto for me. But I didn't realize the cache was causing the problem, even though I mentioned it to the OP. (Ha-ha). Thanks. – Michael E2 Apr 14 '18 at 15:55
  • After my comment, I read the comments to the OP, and saw that! lol – Carl Woll Apr 14 '18 at 15:59
  • @MichaelE2 This is a nice suggestion, however I would like to recognise when it's superior over a simple pattern matching approach. +1. – Artes Apr 14 '18 at 16:35
  • @Artes This fiddling with the internals slows down Integrate, even worse if we inactivate PolyLog in the same way. Makes me wonder how safe it is. In fact, I got a wrong answer with one thing I tried (not shown). On the other hand, pattern matching can be made much harder if there are coefficients in the integrand that obfuscate or destroy the pattern. But done your way, it is perfectly safe. (+1 to your answer a while ago.) – Michael E2 Apr 14 '18 at 17:49
8

Mathematica is a term rewriting system and there are various ways to suppress automatic evaluation of expressions. The system doesn't evaluate Zeta for odd integer arguments (see e.g. Zeta[Range[2, 20]]). Zeta[n] yields expressions involving n-th powers of Pi, thus one of possible ways to achieve the goal would be e.g.

Integrate[Log[1 - x]^5/x^5, {x, 0, 1}] /. 
 Times[x_, Pi^n_Integer] :> x Pi^n Inactivate[Zeta[n]]/Zeta[n] //
 TraditionalForm

enter image description here

Another way is to use HoldForm[Zeta[n]] instead of Inactivate[Zeta[n]] however the latter is more universal and handy. You can use Activate (also with appropriate patterns) to evaluate the expression, e.g.

Activate[%]
-((5 Pi^2)/6) - (11 Pi^4)/18 - 30 (Zeta[3] + Zeta[5])

Nevertheless using such a replacement should be appropriately restricted to avoid possible ambiguities with expressions involving symbolic results in terms of powers of Pi.

Artes
  • 57,212
  • 12
  • 157
  • 245
  • 1
    For safety, you can restrict the transformation to even powers of $\pi$: Times[x_, π^n_?EvenQ] – J. M.'s missing motivation Apr 13 '18 at 18:11
  • @J.M.needshelp. Right, however the OP might explain if expressions like e.g. Integrate[BesselK[0, x]^2, {x, 0, Infinity}] are subject to transform or not. – Artes Apr 13 '18 at 18:23
  • Thanks for the answer. However we are just lucky that in this special case we can recognize our function by a power of $\pi $. It may be however a more general function with a "simple" value at a special point. Is there a general way to prevent Mathematica from evaluation of some listed functions? – drer Apr 13 '18 at 19:57
  • @drer I've mentioned about pattern option in Inactivate which could be exploited. With an example at hand this could be worked out, nonetheless there is no obvious general way. – Artes Apr 13 '18 at 20:21
  • A simple example would be an output of a calculation equivalent to Range[1,20]Sin[Pi/Range[1,20]]. It is really hard to find a method of "postprocessing". It would be better somehow tell Mathematica never evaluate Sin. But as I understood it is impossible. – drer Apr 13 '18 at 22:23
  • 1
    @drer Re "in this special case we can recognize our function by a power of π": It's not clear that it is because Zeta is evaluating that we have powers of π in the answer. Executing Block[{Zeta = Inactive[Zeta]}, Integrate[Log[1 - x]^5/x^5, {x, 0, 1}]] suggests that the powers of π are computed without using Zeta. If so, one cannot blame the evaluation of special functions for returning a correct answer in a certain form. – Michael E2 Apr 14 '18 at 01:41
  • @MichaelE2 In Wolfram Cloud your code resulted in -5 (Zeta[2]+6Zeta[3]+11Zeta[4]+6Zeta[5]) as it was desired. Thank you!!! – drer Apr 14 '18 at 07:41
  • @MichaelE2 A next try after some pause with the same command has however resulted in expansion of "even" Zeta. I have really no clue what is happening here. – drer Apr 14 '18 at 08:31
  • @MichaelE2 It is certainly a bug in Wolfram Cloud. If I execute once the command Integrate[Log[1 - x]^n/x^n, {x, 0, 1}]] with some n either inside or outside of the Block[{Zeta=Inactive[Zeta]},...], all subsequent calls with the same n result in the same output as in the first one, completely independent from the art of the call (inside or outside of the Block). It however does not influence subsequent calls of the command with a different not yet used n. – drer Apr 14 '18 at 09:30
  • @MichaelE2 Please consider posting an answer with your suggestion, pointing out also the bug (obviously present in your version of Mathematica as well). – drer Apr 14 '18 at 09:40
  • @drer Well, I'm not sure I understand yet. The integral is calculated as the Limit of an expression in terms of PolyLog, Log and powers of x, not in terms of Zeta. It's the polylogs that evaluate to zeta inside the limit call. Another possible issue is that replacement rules can be used to rewrite expressions, not just evaluation. -- As for reproducibility, note that sometimes expressions are cached and reused, rather than recalculated. ClearSystemCache can sometimes be used to reset the cache. – Michael E2 Apr 14 '18 at 13:12
  • @MichaelE2 Were you able to reproduce the "correct" result? – drer Apr 14 '18 at 13:56