'Is there a way to add multiple conditions while doing the product in Maple?
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.
Solution 1:[1]
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:
- mul works only for numeric ranges and there should be no infinity involved, it also works for r in R case.
- product can work with symbolic ranges, also range can have infinity, but it doesn't work for r in R case.
- product is more powerful, but mul is much faster, so for numeric ranges mul should be always used instead (similarly add should used instead of sum for numeric ranges).
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:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |