Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2002
*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 2002

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

Search the Archive

RE: Simple question on whether function is defined or not

  • To: mathgroup at smc.vnet.net
  • Subject: [mg35136] RE: [mg35093] Simple question on whether function is defined or not
  • From: "DrBob" <majort at cox-internet.com>
  • Date: Tue, 25 Jun 2002 19:55:16 -0400 (EDT)
  • Reply-to: <drbob at bigfoot.com>
  • Sender: owner-wri-mathgroup at wolfram.com

>>BracketDefine[e[3],e[5]] for instance returns nothing

That's the whole point.  If BracketDefine were undefined with those
arguments, it would return

BracketDefine[e[3],e[5]]

Instead, it returns Null, because none of the conditions in the Which
statement are true.  A legally formed Which statement ALWAYS returns a
value, and when you see "nothing", that means there IS something (a
Null).

If you want BracketDefine to be undefined except for those explicit
cases, you could write it this way:

ClearAll[BracketDefine]
BracketDefine[a_.*e[i_], b_.*e[j_]] /; i + j > n := 0
BracketDefine[a_.*e[i_], b_.*e[i_]] := 0
BracketDefine[a_.*e[1], b_.*e[j_]] := a*b*e[j + 1]
BracketDefine[a_.*e[2], b_.*e[3]] := -a*b*e[5]
BracketDefine[a_.*e[3], b_.*e[4]] := 2*a*b*e[7]
ValueQ[BracketDefine[e[3], e[5]]]

False

Or:

ClearAll[BracketDefine]
BracketDefine[a_.*e[i_], b_.*e[j_]] /; i + j > n := 0
BracketDefine[a_.*e[i_], b_.*e[i_]] := 0
BracketDefine[a_.*e[1], b_.*e[j_]] := a*b*e[j + 1]
BracketDefine[a_.*e[2], b_.*e[3]] := -a*b*e[5]
BracketDefine[a_.*e[3], b_.*e[4]] := 2*a*b*e[7]
BracketDefine[a_.*e[i_], b_.*e[j_]] := Undefined
BracketDefine[e[3], e[5]] === Undefined

True

(Undefined isn't anything special here--it's just a symbol we can check
for to see if none of the other cases fit.  I could have called it
anything, or used a string like "undef" or something, so long as it
isn't a value that BracketDefine could evaluate to in the other cases.)

You probably could do better by defining Bracket all at once, but with
these hints, I'll leave you to it.

Bobby Treat

-----Original Message-----
From: Geoff Tims [mailto:Geoff at swt.edu] 
To: mathgroup at smc.vnet.net
Subject: [mg35136] [mg35093] Simple question on whether function is defined or not

I am trying to make a function in mathematica.  I have two questions on
this
and an answer to either would be wonderful.  For me, this looks
complicated,
but for you it probably does not.  However, even if it does, my
question, I
believe, is still simple and I only give what I have to clarify if that
is
needed.

What I have so far should define the function completely as far as I can
tell except for one small problem.


n := 15
BracketDefine[a_.*e[i_], b_.*e[j_]] :=
    Which[
      i + j > n, 0,
      i == j, 0,
      i == 1, a*b*e[j + 1],
      i == 2 && j == 3, -a*b*e[5],
      i == 3 && j == 4, 2*a*b*e[7]
      ];
Bracket[mul_, expr_Plus] := Map[Bracket[mul, #] &, expr];
Bracket[expr_Plus, mul_] := Map[Bracket[#, mul] &, expr];

Bracket[e[i_], e[j_]] :=
  Which[
    ValueQ[BracketDefine[e[i], e[j]]], BracketDefine[e[i], e[j]],
    j - i == 2, -Bracket[e[1], Bracket[e[i], e[i + 1]]],
    True, -Bracket[e[i + 1], e[j - 1]] +
      Bracket[e[1], Bracket[e[i], e[j - 1]]]
    ]



I have BracketDefine[] and then Bracket[] which, in theory, takes values
from BracketDefine.  Well, it does take values from BracketDefine[], but
BracketDefine only has certain values of the entire function Bracket[].
That's why in the first condition and statement of Which, I see if it's
already defined in BracketDefine, and if so, it takes on that value.
That's
my problem.  Mathematica, at least with ValueQ, believes that
BracketDefine
is defined for all values of i and j.  However, it's only defined for a
few
values.  BracketDefine[e[3],e[5]] for instance returns nothing.  This
brings
us to my questions

Is there another test which would return false if the function returns
nothing for certain values, but true if it returns something for other
values?

Or, to avoid the problem altogether, is there a way to just define the
entire Bracket function all at once?  I tried defining Bracket the way
BracketDefine is defined and then again defining Bracket the way Bracket
is
now defined, but it seemed to lose all knowledge of the first
definition.

Thanks
Geoff Tims







  • Prev by Date: Re: Difference /recurrence equations
  • Next by Date: Re: FrameTick Problem
  • Previous by thread: Simple question on whether function is defined or not
  • Next by thread: ConstrainedMin with negative variables