Reputation: 2663
Note: I've searched for the answer to this already but I can't find what I need. I may have overlooked something or maybe this is referred to in a different way. I'll delete this if someone points out that it is a duplicate, please let me know.
Question: How can I add multiple conditions to the product
or mul
in Maple?
Example: I am trying to re-create the following, I cannot seem to find a way to add both r != k
and r=1
as parameters.
I've gone over the documentation of the product command and maybe I am missing something.
Upvotes: 2
Views: 215
Reputation: 478
If you want the formula that you showed in your question to be displayed symbolically as you have, I don't have any idea at the moment in Maple. As you may have seen in the help page of product
, it only accepts ranges of the form idx=n..m
or idx=n
and that's it. But if you have values in k
and j
and want to receive the result of your formula, you can use mul
, not product
. As @Robai did a comparison in her answer between mul
and product
, the important thing here is that product
does not support its second argument (the range) to be in the form idx in set
, no "in
" for product
and that means you can not use product
for your case even with the formulation given in @Robai's answer.
Now for mul
, other than the set-minus idea of @Robai's answer. Here is another approach (you can read more about it in another answer I posted for another question in this link https://stackoverflow.com/a/72498377/6195473).
j := 5:
k := 2:
idxs := select( x -> x <> k, [ seq( r, r = 1..j-1 ) ] );
(k/(j-k)) * mul( r/(r-k), r in idxs );
Here is a screenshot from the output.
Upvotes: 0
Reputation: 307
Conditional products can be achieved using sets for index range (in the example below R is a set or can be a list, but set is better in this case since it's easier to remove its members), but that set must not have unknown parameters (so it's a numeric range). For example:
[> j:=6: k:=3:
R:={seq(s, s in {seq(s,s=1..j-1)} minus {k})};
mul(r/(r-k), r in R);
The output will be:
R := {1, 2, 4, 5}
10
You can do it without additional variable R too:
[> mul(r/(r-k), r in {seq(s, s in {seq(s,s=1..j-1)} minus {k})});
A comparison of mul and product:
You can use mul with parameters too, but the range should be numeric (R is defined above):
[> mul((a+r)/(b+r-k), r in R);
The output:
Upvotes: 2