0
$\begingroup$

I was wondering if there is a way to assign a value to a specific problem.

For example if I wanted $a\cdot a$ to equal $-1$. How would I go about doing that?

$\endgroup$

closed as unclear what you're asking by Mr.Wizard Jan 29 '15 at 6:51

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    $\begingroup$ Can you explain your particular use case through an example? I could suggest several "solutions" which would seem to fit what you are asking but I suspect that most of them won't be useful to you. $\endgroup$ – Szabolcs Jan 28 '15 at 23:59
  • $\begingroup$ Please include some code for your example, or at least a greater explanation. Possibly UpSet or TagSet will be applicable but I cannot yet tell. What is $a$? $\endgroup$ – Mr.Wizard Jan 29 '15 at 0:00
  • $\begingroup$ I am dealing with multiplication of the elements in the Hamiltonians. so things of the form a+bi+cj+dk. $\endgroup$ – new to Mathematica Jan 29 '15 at 0:03
  • $\begingroup$ so i*i=-1, or i*j=k and so on $\endgroup$ – new to Mathematica Jan 29 '15 at 0:04
  • 3
    $\begingroup$ Quaternions are already built-in to Mathematica; see Quaternions/tutorial/Quaternions in the Documentation Center to learn how to use them. $\endgroup$ – DumpsterDoofus Jan 29 '15 at 0:14
3
$\begingroup$

If all you are looking for is a basic implementation of quaternions, then there is no need to implement them yourself, since they are already built-in:

<< Quaternions`
Quaternion[0, 1, 0, 0] ** Quaternion[0, 1, 0, 0]

producing

Quaternion[-1, 0, 0, 0]

as you asked for.

$\endgroup$
1
$\begingroup$

Here's one way to interpret your question. You seem to be asking about defining an operation. Let's call it "dot". If you want dot of any pair to be -1, then you specify:

dot[a_, a_] := -1

Now you have the property that whenever you type something like dot[w,w] or dot[5,5] you get -1 but dot takes on no value for things like dot[a] or dot[a,b]. Of course you could define these other cases as well to build up a complete operation.

$\endgroup$
1
$\begingroup$

I think you looking for TagSet, see also What are the most common pitfalls awaiting new users?.

a /: a*a = -1

-1

list = Range[1, 10]

{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

a a + list

{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}

a a*list

{-1, -2, -3, -4, -5, -6, -7, -8, -9, -10}

ca = ConstantArray[a a, {2, 2}]

{{-1, -1}, {-1, -1}}

ca*a a

{{1, 1}, {1, 1}}

mat = {{1, 2}, {3, 4}} + a a

{{0, 1}, {2, 3}}

$\endgroup$

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