Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Types in Mathematica, a practical example

  • To: mathgroup at smc.vnet.net
  • Subject: [mg62818] Re: [mg62800] Types in Mathematica, a practical example
  • From: Kristen W Carlson <carlsonkw at Gmail.com>
  • Date: Tue, 6 Dec 2005 00:03:14 -0500 (EST)
  • References: <200512051841.NAA21133@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Ingolf,

How about, on an initialized one per your spec:

In[11]:= Table[ Table[0, {2}], {2}]

Out[11]= {{0,0},{0,0}}

In[12]:= MatrixQ[Out[11]]

Out[12]= True

on yours, or an arbitrary one, for which you have to adjust the Depth argument:

In[19]:= idlist = {{{{0, 1}, {2, 3}}, {{-1, 0}, {1, 2}}}, {{{-2, -1},
{0, 1}}, {{-3, -2}, {-1, 0}}}};
ArrayQ[idlist, 4]

Out[20]= True

Note you can also initialize via indexed arrays (See Array in Help),
and then replace by index (eg f[1,1] = 2) or by MapAt.

You can also query some of the qualities of each array element; qv
Help 2.3.5, middle section.

Kris


On 12/5/05, Ingolf Dahl <ingolf.dahl at telia.com> wrote:
> To MathGroup,
>
> I am not an advocate for strong typing in Mathematica, but consider the
> following simple example: I want to see if two matrices are equal. One of
> them was the result from some equation, and is given inside a rule. Then I
> write some code similar to this:
>
>
>
> a = {{1, 2}, {3, 4}};
>
> x - a /. {x -> a}
>
>
>
> I of course hope to get a matrix filled by zeroes, but if x is undefined,
> the following is returned:
>
>
>
> {{{{0, 1}, {2, 3}}, {{-1, 0}, {1, 2}}}, {{{-2, -1}, {0, 1}}, {{-3, -2}, {-1,
> 0}}}}
>
>
>
> First x was assumed to be a number, and (x - a) was evaluated. Then x was
> substituted by the matrix a. No bug in Mathematica, but it was not what I
> wanted as user. It is easy to make such a mistake in the programming. Of
> course there are many ways to get around this problem, but is there any
> reasonably simple way to "type" x to be a list of lists without specifying
> the elements, in such a way that the above example works?
>
>
>
> I could do
>
>
>
> ReleaseHold[Hold[x - a] /. {x -> a}]
>
>
>
> but then we are not in the "typing business" any longer.
>
>
>
> I think this question illuminates one aspect of the typing issue in
> Mathematica. I remember that I as a newbie looked for ways to declare
> matrices, in such a way that I later could specify matrix elements
> one-by-one, without initializing them first. I soon learned that there are
> other ways to achieve similar results, but still I do not see any good
> reason why I cannot force Mathematica to give the following response from
> x-a, if x in some way is declared to be a 2x2 list of lists:
>
>
>
> {{x[[1,1]] - 1, x[[1,2]] - 2},{x[[2,1]] - 3, x[[2,2]] - 4}}
>
>
>
> I am not allowed to Unset or Clear any part of a list either. Why not?
>
>
>
> Ingolf Dahl
>
> Sweden
>
>
>


  • Prev by Date: Re: Types in Mathematica
  • Next by Date: Re: Types in Mathematica thread
  • Previous by thread: Types in Mathematica, a practical example
  • Next by thread: Re: Types in Mathematica, a practical example