1
$\begingroup$

How can I convince mathematica to simplify the ratio of these two symbolic products. You can see that the terms in the denominator are present in the numerator.

enter image description here

FullSimplify[
   Sum[((1 - pf[K[2]])/Product[ν*pf[K[1]], {K[1], 0, K[2]}])*
       Product[ν*pf[K[1]], {K[1], 0, -1 + n}], 
     {K[2], 0, -1 + n}]]

A simpler example would be the following,

Product[\[Nu]*pf[i], {i, 0, -1 + N}]/Product[\[Nu]*pf[i], {i, 0, -5 + N}]

Again every term in the denominator is present in the numerator. If you set N to be 9 or a specific number mathematica will expand and cancel the terms, but symbolically it cannot

$\endgroup$
5
  • $\begingroup$ Please post the Mathematica code. $\endgroup$
    – cvgmt
    Sep 4, 2022 at 3:28
  • 1
    $\begingroup$ When posting code, convert to InputForm prior to copy and paste. $\endgroup$
    – Bob Hanlon
    Sep 4, 2022 at 13:53
  • $\begingroup$ I see you did that for me, thank you, and thanks for the advice $\endgroup$
    – abnowack
    Sep 4, 2022 at 18:53
  • $\begingroup$ Your products are not the same. In the simpler example, i goes from -1+N in the numerator while it goes from 0 to -5+N in the numerator. $\endgroup$
    – bill s
    Sep 4, 2022 at 19:09
  • $\begingroup$ They are not meant to be the same, it's that it can be simplified to one product with a different starting index. I might be off by one, but it should be equivalent to one product from -5+N+1 to -1+N $\endgroup$
    – abnowack
    Sep 4, 2022 at 19:20

2 Answers 2

1
$\begingroup$

With some manually added simplification rules, Mathematica is able to simplify the expression as expected:

fullSimplify[args___] := FullSimplify[args,
  TransformationFunctions -> {
    Automatic, 
    ReplaceAll[
     HoldPattern[
       Product[f1_, {v1_, l1_, u1_}]^
         e1_. Product[f2_, {v2_, l2_, u2_}]^e2_.] :>
      fullSimplify /@ Unevaluated[
        Product[f1, {v1, l1, Max[l1, l2] - 1}]^e1 
         Product[f1, {v1, Min[u1, u2] + 1, u1}]^e1 
         
         Product[f1^e1 (f2 /. v2 -> v1)^e2, {v1, Max[l1, l2], 
           Min[u1, u2]}] 
         Product[f2, {v2, l2, Max[l1, l2] - 1}]^e2 
         Product[f2, {v2, Min[u1, u2] + 1, u2}]^e2
        ]
     ],
    ReplaceAll[
     Sum[s_, {v_, l_, u_}] :>
      Sum[Assuming[l <= v <= u, fullSimplify[s]], {v, l, u}]
     ]
    }
  ]

fullSimplify[
 Sum[((1 - pf[K[2]])/Product[ν*pf[K[1]], {K[1], 0, K[2]}])*
   Product[ν*pf[K[1]], {K[1], 0, -1 + n}], {K[2], 0, -1 + n}]]

enter image description here

The first additional rule effectively simplifies products of Products:

$$\left(\prod_{i_1=l_1}^{u_1}f_1(i_1)\right)^{e_1}\left(\prod_{i_2=l_2}^{u_2}f_2(i_2)\right)^{e_2}$$

This can be split into a product of 5 parts: The intersecting part of the index ranges, and the four remaining parts (most of which are hopefully empty):

$$\begin{align} &\left(\prod_{i_1=l_1}^{u_1}f_1(i_1)\right)^{e_1}\left(\prod_{i_2=l_2}^{u_2}f_2(i_2)\right)^{e_2}\\ =&\left(\prod_{i_1=l_1}^{\min(l_1,l_2)-1}f_1(i_1)\right)^{e_1}\left(\prod_{i_2=l_2}^{\min(l_1,l_2)-1}f_2(i_2)\right)^{e_2}\\ &\times\prod_{i=\max(l_1,l_2)}^{\min(u_1,u_2)}f_1(i)^{e_1}f_2(i)^{e_2}\\ &\times\left(\prod_{i_1=\max(u_1,u_2)+1}^{u_1}f_1(i_1)\right)^{e_1}\left(\prod_{i_2=\max(u_1,u_2)+1}^{u_2}f_2(i_2)\right)^{e_2} \end{align}$$

Two subtleties: a/b is effectively Times[a, Power[b, -1]], which is why the rule matches. And with a_^e_., we also match a (since the e can be defaulted to 1).

The second rule helps with the simplification of the Min and Max expressions: We tell Mathematica that the value of the index variable inside the Sum will always be between the two bounds, and to simplify based on that.

Another important part is that we apply our custom simplification rules again to the individual parts of the transformed expressions, otherwise FullSimplify gives up to soon. So effectively we use the second rule, set $Assumptions, then apply the first rule to the content of the sum, simplifying the individual parts again (where now the $Assumptions) set in the first step help to get rid of some of the products). It is important that we map fullSimplify over the individual parts of the transformed product, otherwise we end up in a near-endless loop (since we can always recursively replace 2 products by 5)

$\endgroup$
5
  • 1
    $\begingroup$ The code as posted does not produce the answer shown on Mma 13.1 on Mac OS. Is some definition not included? $\endgroup$ Sep 4, 2022 at 21:20
  • 1
    $\begingroup$ @ChrisDegnen Thanks for pointing that out! That's what I get for quickly "improving" the code without testing it again... should be fixed now $\endgroup$
    – Lukas Lang
    Sep 4, 2022 at 22:15
  • $\begingroup$ This works great! Thanks for understanding the issue and implementing a solution. I'm a bit new with mathematica, how did you learn to write this kind of function? $\endgroup$
    – abnowack
    Sep 4, 2022 at 22:39
  • $\begingroup$ One issue is that I see an incorrect minus sign in front, is that a bug? $\endgroup$
    – abnowack
    Sep 4, 2022 at 22:42
  • 1
    $\begingroup$ @abnowack the minus sign is correct, note how the first factor is reversed. I don't know why Mathematica decided that this is simpler though.. $\endgroup$
    – Lukas Lang
    Sep 5, 2022 at 7:59
0
$\begingroup$

In your simplified example:

Product[ν*pf[i], {i, 0, -1 + N}]/Product[ν*pf[i], {i, 0, -5 + N}]

The difficulty seems to be the unknown pf[] function.

If it is omitted the expression is simplified.

Product[ν*i, {i, 1, -1 + N}]/Product[ν*i, {i, 1, -5 + N}]

(ν^4 Gamma[N])/Gamma[-4 + N]

$\endgroup$
1
  • $\begingroup$ ? Every term in the denominator product is present in the numerator. The end result should be one product with different starting and ending conditions $\endgroup$
    – abnowack
    Sep 4, 2022 at 18:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.