MathGroup Archive 2007

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

Search the Archive

Re: Problem with Which

  • To: mathgroup at smc.vnet.net
  • Subject: [mg74102] Re: Problem with Which
  • From: "Dana DeLouis" <dana.del at gmail.com>
  • Date: Sat, 10 Mar 2007 06:50:40 -0500 (EST)

Hi.  Just an idea.  If you had 1 or 2 more variables, your function would be
very long.  If your variables represented binary digits, you may be able to
shorten the code.
I was thinking of some sort of Rank function from Combinatorica, but I don't
think there is one for this type of conversion.  Here are some ideas...

Reverse[Select[Range[63],
    Count[IntegerDigits[#1, 2], 1] == 2 & ]]

{48, 40, 36, 34, 33, 24, 20, 18, 17, 12, 10, 9, 6, 5, 3}

Unfortunately, there is no easy formula...
http://www.research.att.com/~njas/sequences/A018900


Fx[Ts_, Th_, Tr_, f_, w_, i_] := Module[{t},
    t = Boole[Map[NumericQ, {Ts, Th, Tr, f, w, i}]];
    If[Count[t, 1]
        ≠ 2, "Error", Mod[1414254666747063480272674439478, 6*FromDigits[t,
            2] + 29]]
    ]

Fx2[Ts_, Th_, Tr_, f_, w_, i_] := Module[{t, p = Permutations[{1, 1, 0,
   0, 0, 0}]},
    t = Boole[Map[NumericQ, {Ts, Th, Tr, f, w, i}]];
    If[Count[t, 1] ≠ 2, "Error", Position[p, t][[1, 1]]]
    ]

Or, not even use Boole....

Fx3[Ts_, Th_, Tr_, f_, w_, i_] :=
  Module[{t, p = Permutations[{True, True, False, False,
       False, False}]},
   t = NumericQ /@ {Ts, Th, Tr, f, w, i};
    If[Count[t, True] != 2, "Error", Position[p, t][[1,
      1]]]]


Fx[a, b, c, d, 1, 2]
15

Fx2[1, 2, a, b, c, d]
1
= = = = =
HTH
Dana DeLouis
XP and Mathematica 5.2


> AH[Ts_,Th_,Tr_,f_,w_,i_]:=(
>    Which[NumericQ[Ts]&&NumericQ[Th],tipo=1,
>      NumericQ[Ts]&&NumericQ[Tr],tipo=2,
>      NumericQ[Ts]&&NumericQ[f],tipo=3,
>      NumericQ[Ts]&&NumericQ[w],tipo=4,
>      NumericQ[Ts]&&NumericQ[i],tipo=5,
>      NumericQ[Th]&&NumericQ[Tr],tipo=6,
>      NumericQ[Th]&&NumericQ[f],tipo=7,
>      NumericQ[Th]&&NumericQ[w],tipo=8,
>      NumericQ[Th]&&NumericQ[i],tipo=9,
>      NumericQ[Tr]&&NumericQ[f],tipo=10,
>      NumericQ[Tr]&&NumericQ[w],tipo=11,
>      NumericQ[Tr]&&NumericQ[i],tipo=12,
>      NumericQ[f]&&NumericQ[w],tipo=13,
>      NumericQ[f]&&NumericQ[i],tipo=14,
>      NumericQ[w]&&NumericQ[i],tipo=15];
> tipo)



  • Prev by Date: infinity problem in mathematica
  • Next by Date: RE: Re: Multi-core Support in Mathematica 5.2
  • Previous by thread: Re: Problem with Which
  • Next by thread: Re: Problem with Which