       Re: vector pattern?

• To: mathgroup at smc.vnet.net
• Subject: [mg20277] Re: [mg20258] vector pattern?
• From: "Andrzej Kozlowski" <andrzej at tuins.ac.jp>
• Date: Mon, 11 Oct 1999 02:19:52 -0400
• Sender: owner-wri-mathgroup at wolfram.com

```This can't be done in exactly the way you want. If you give a symbol an
OwnValue (which is what you are doing when setting v={x,y}) that own value
will be evaluated before any other rules which you attach to v. There are
various ways in which you can achieve something that comes close to what you
want. I will just give a couple that come to my mind, I am sure youwill get
more suggestions.

One simple way is to set
In:=
v = {x, y};

and simply write Through[v[t]] rather than v[t]

In:=
Through[v[t]]
Out=
{x[t], y[t]}

Another possible way is to "cheat". You can format v to "look like" {x,y}:
In:=
Clear[v]

In:=
Format[v] := {x, y}

In:=
v[t_] := {x[t], y[t]}

Now indeed everything will look just as you wanted:
In:=
v
Out=
{x, y}
In:=
v[t]
Out=
{x[t], y[t]}

but of course v isn't really a vector now:

In:=
v + {1, 1}
Out=
{1 + {x, y}, 1 + {x, y}}

Andrzej Kozlowski
Toyama International University
JAPAN
http://sigma.tuins.ac.jp
http://eri2.tuins.ac.jp

----------
>From: Susan Hovde <hovde at al.noaa.gov>
To: mathgroup at smc.vnet.net
>To: mathgroup at smc.vnet.net
>Subject: [mg20277] [mg20258] vector pattern?
>Date: Sun, 10 Oct 1999 00:04:08 -0400
>

> I'd like to define a pattern for a 2D vector v such that
>
> v = {x,y}  and
>
> v[t] = {x[t],y[t]}.
>
> I tried
>
> v[t___] := If[Count[{t},s_]==0,{x,y},{x[t],y[t]}]
>
> and this gets me _almost_ what I want.  I get v[t] = {x[t], y[t]} and
> v[] = {x,y}, but when I ask for v, I just get v back.
>
>
> v := {x,y}
>
> but then when I ask for v[t] I get {x,y}[t] instead of {x[t],y[t]}.  (I
> also tried v := v[] with the same result.)  I have tried various Hold
> functions to try to get v not to be evluated too early, to no avail.
> Can someone help me out?
>
> Susan Hovde
> NOAA Aeronomy Lab