Message Boards Message Boards

0
|
7452 Views
|
10 Replies
|
5 Total Likes
View groups...
Share
Share this post:

User defined plus and product.

Posted 10 years ago

Hello.

I'm a new user of Mathematica. So please be patient with me :)

I try to define E = { e1, e2, e3, e4 }, a set, and two operations on E : the plus and the product. The idea is to compute product of matrices using those user defined operations.

Could someone give me the syntax and the "how to" to make it work ?

Regards

10 Replies

What you are looking for probably already exists: matrix operations and vector + matrices

but you can define your own as well

POSTED BY: Kay Herbert

Thanks helping, but it doesnt help. I alrerady know Mathematica provide matrices product. I dont need to change matrix or vector product, but establishing "computing rules" between some elements of a set, and use it.

example :

E = { a,b,c }

plus : (a,a) -> a, (a,b) -> b, (b,a) -> b, ...

Multiply : (a,a) -> b, (a,b) -> a

And now, if I compute ( {{a, a}, {b, a} } ) ( {{a, b}, {a, a}} )

I expect the result is : {{b, a}, {a, b}}

and not only : {{a^2, a b}, {a b, a^2}}

I tried to search on google, but I dont have the good "key-words" to collect some interesting results.

I know it's something about finite groups, algebra or something like that, but i didnt found at now...

Please help.

Write your own add and multiply functions. Combine them using Inner to make your matrix product function.

POSTED BY: John Doty

Excellent !!! Inner[f,list1,list2,g] is exactly what I was searching for.

The last part now is : defining f and g with elegant writing. Let's consider the informations I have are an enumeration of all tuples X+Y=Z, could I define f and g by using some kind of pattern matching or some similar mechanism ? what is the most "readable" technique for such kind of definitions ?

Regards

Frédéric DIDIER

To use pattern matching to turn an enumeration into a function, define your "plus" function as follows:

plus[a,a]=a
plus[a,b]=b
plus[b,a]=b
...

When the left hand side matches, the right hand side replaces it. Note that a and b are not named function arguments (that would be a_ and b_), but literal symbols that must match the symbols in those slots for the definition to take effect.

POSTED BY: John Doty

Just what I was searching for. It perfectly uses a and b as 'atoms'.

Thanks for your patience.

Posted 10 years ago

This might also be interesting: Operators without Built In Meanings

In[1]:= CirclePlus[a, b] = b

Out[1]= b

In[2]:= a \[CirclePlus] b

Out[2]= b

(Note that [CirclePlus] can be entered as esc c+ esc and looks like a CirclePlus symbol in an actual notebook.)

POSTED BY: David Keith

Nice feature. I really appreciate the opulence of symbols. It make articles more readable and attractive.

Thanks for the tip.

I met a last difficulty I didnt solve. I didnt see it 4 hours ago because of the sample limitation at dimension 2.

If I work on :

Inner[dwproduct, ( {
   {1, On, 0, 0},
   {On, 1, On, On},
   {0, On, 1, 0},
   {0, On, 0, 1}
  } ), ( { {V},{N},{N},{N} } ), wsum]

The given result is

{
 {wsum[V, N, 0, 0]},
 {wsum[V, N, N, N]},
 {wsum[0, N, N, 0]},
 {wsum[0, N, 0, N]}
}

So, how to define wsum a general/generic way to avoid specialize for each tuple ? (i probably will compute samples with matrices at dimension 600 and more)

Could I imagine something recursive (or not) that will transfer "evaluation capability" to binary operation ?

Let's say wsum[x1,x2,x3,...,xn]= ((((x1)+x2)+x3)+...)+xn

I finally found a recursive possibility :

f [ x_ ,y_ , z__ ] = f [ f [x,y] , z ]

hope recursive aspect will be replaced at execution time by iterative computation...

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract