[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Axiom-math] Re: iterators and cartesian product.
From: |
Francois Maltey |
Subject: |
[Axiom-math] Re: iterators and cartesian product. |
Date: |
22 Oct 2007 18:31:13 +0200 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.4 |
> I'm not being facetious, I'm trying to understand your perspectives :
For me it's an exercice I give to my students in maple :
create the list of all matrices which can be magic.
They are a subset of this list :
[matrix [[a,b,15-a-b],[c,d,15-c-d],[15-a-c,15-b-d,15-a-d]]
for << all the (a,b,c,d) in 2..8 x 1..9 x 1..9 x 2..8 >> ]
My first query was about this real exercice : create this list of matrices.
(and then extract the magic ones)
mupad syntax is
[matrix [[a,b,15-a-b],[c,d,15-c-d],[15-a-c,15-b-d,15-a-d]]
$a=2..8 $b=1..9 $c=1..9 $d=2..8]
maple syntax is
['''matrix [[a,b,15-a-b],[c,d,15-c-d],[15-a-c,15-b-d,15-a-d]]
$a=2..8' $b=1..9' $c=1..9' $d=2..8]
So I'm looking for a pretty syntax in order to enumerate a cartesian Product
of lists or of segments.
There are 3 possible methods :
// A //
Today we can use
L := [1,3,5,7,9]
concat [concat [[100*a+10*b+c for a in 1..2] for b in 0..9] for c in L]
I don't find fair many concat.
Of corse
Union_{c in C} (Union_{b in B} {F(a,b,c) for c in C})
= {F(a,b,c) for (a,b,c) in AxBxC}
I write the second terms in mathematics,
and so I prefer to have this second syntax in axiom,
and the concat command looks like an union.
// B //
Waldek writes :
> Concerning more general problem: I think that we also need other approaches.
> More precisely, it would be good to add better iteration constructs, which
> make iterating over products easier. For example, something like:
> [[a, b] for a in 1..10 repeat for b in 1..5]
> Well, concat version creates intermediate lists and concatenates them.
> Psychologically double iteration is an atomic operation,
> so it is easier (at least for some folks) to think about.
// C //
Martin seems to prefer :
L := [1,3,5,7,9]
[100*a+10*b+c for (a,b,c) in Product (1..2,0..9,L)]
I don't disapprove this point of view.
The magic [function|domain] Product generates the list
of all the possibilities.
but I'm really waiting for automatic coerces in order to have
a light command in the interpreter because this construct is (for me)
very common. So I don't want to add a lot of $... and @... everytime.
In this case the "keyword" Product has various arguments :
List or Segment. All terms don't have necessary the same type.
An other example :
LP is a list of Lagrange polynoms, Lx is the list of associated values.
I could test :
test (set [eval (P, x) for (P,x) in Product (LP, Lx)] = set [0,1])
test (set [eval (P, x) for (P,x) in Product (LP, 1..8)] = set [0,1])
even if it is better to test with a matrix.
test (matrix [[eval (P, x) for P in LP] for x in Lx] = identity(n))
F.
- [Axiom-math] Re: [fricas-devel] Re: [open-axiom-devel] [fricas-devel] Re: [fricas-devel] Re: iterators and cartesian product., (continued)
- [Axiom-math] Re: [open-axiom-devel] [fricas-devel] Re: [fricas-devel] Re: [fricas-devel] Re: iterators and cartesian product., Ralf Hemmecke, 2007/10/25
- [Axiom-math] Re: [fricas-devel] Re: [open-axiom-devel] [fricas-devel] Re: [fricas-devel] Re: [fricas-devel] Re: iterators and cartesian product., Bill Page, 2007/10/25
- [Axiom-math] Re: [open-axiom-devel] [fricas-devel] Re: [fricas-devel] Re: [fricas-devel] Re: [fricas-devel] Re: iterators and cartesian product., Ralf Hemmecke, 2007/10/28
- [Axiom-math] Re: [fricas-devel] Re: [open-axiom-devel] [fricas-devel] Re: [fricas-devel] Re: iterators and cartesian product., Waldek Hebisch, 2007/10/23
- [Axiom-math] Re: [fricas-devel] Re: [open-axiom-devel] [fricas-devel] Re: [fricas-devel] Re: iterators and cartesian product., Bill Page, 2007/10/23
- [Axiom-math] Re: [open-axiom-devel] [fricas-devel] Re: iterators and cartesian product., Gabriel Dos Reis, 2007/10/22
- [Axiom-math] Re: [fricas-devel] Re: [open-axiom-devel] [fricas-devel] Re: iterators and cartesian product., Waldek Hebisch, 2007/10/23
- [Axiom-math] Re: [fricas-devel] Re: [open-axiom-devel] [fricas-devel] Re: iterators and cartesian product., Gabriel Dos Reis, 2007/10/24
[Axiom-math] Re: iterators and cartesian product.,
Francois Maltey <=
[Axiom-math] Re: [fricas-devel] Re: iterators and cartesian product., Martin Rubey, 2007/10/22