Tag Info

New answers tagged

0

This might be along the lines of what you want. I expand the terms before trying the replacement, and do that in two steps so I don't have to deal separately with all manner of products. Df = f'[x]; Dhf = (f[x + h] - f[x])/h; ss = Expand[Normal[Series[-Df/Dhf, {h, 0, 3}]]] (* Out[79]= -1 + (h*Derivative[2][f][x])/(2*Derivative[1][f][x]) - ...


1

MMA, V9: StringCases[test1, __ ~~ "uniprotkb:" ~~ x__ ~~ "(gene name)|" :> x] (*{{"Dvl1"}, {"Nxn"}, {"Lrp8"}, {"Reln"}}*)


1

If you are strictly looking for the shortest string between "|uniprotkb:" and "(gene name)" in each record, this is a way : StringCases[test1, "|uniprotkb:" ~~ x__ ~~ "(gene name)" :> x, Overlaps -> True] // (First@SortBy[#, StringLength] &) /@ # & {Dvl1,Nxn,Lrp8,Reln}


9

The behaviour we see here is due to the semantics of the regular expression pattern-matching process. Notionally, the string is scanned from left to right. At each character position, an attempt is made to match the string by looking ahead from that position. If there is no match, scanning moves onto the next character. If there is a match, then (by ...


1

The code provided in the Question seems to be selecting the first instance rather than the Shortest, as can be seen by moving |uniprotkb:Lrp8(gene name) earlier in test1[[3]]. However, the following seems to work well. StringCases[test1, "|uniprotkb:" ~~ aa__ ~~ "(gene name)" /; (StringLength[aa] <= 8) :> aa] (* {{"Dvl1"}, {"Nxn"}, {"Lrp8"}, ...


3

StringCases[test1,"|uniprotkb:" ~~ aa : (WordCharacter ..) ~~ "(gene name)" -> aa] (* {{"Dvl1"}, {"Nxn"}, {"Lrp8"}, {"Reln"}} *)


1

FirstCase[{f, f[0], h[f[e[d[c[a]]]]], p[q[r[f]]], f[2][3][4], x[y[z[0, f[5][6], 1, 2]]]}, _?(! FreeQ[#, f[___]] &)] (* f[0] *)


3

Try the following. Let this: expr = (ks - foo1*bar1) Exp[ks^foo1 - bar1] + (ks - foo2*bar2) Exp[ ks*foo2 - bar2]; This pos = Position[expr, Exp[__]]; returns the position of exponents in it. Then this: expr2 = MapAt[ReplaceAll[#, ks -> kg] &, expr, pos] /. ks -> Y /. kg -> ks (* E^(-bar1 + ks^foo1) (-bar1 foo1 + Y) + E^(-bar2 + ...


7

Use two rules in the replacement with a dummy rule to replace exponents with themselves. Along the lines of. (ks-foo*bar) Exp[ks^foo-bar] /. {x:Exp[___]->x, ks->Y} So anything that is an exponent is 'caught' by the first rule and the kx replacement rule doesn't get a look in.


3

Quite often the documentation is not complete in describing the behavior of Mathematica functions. In my opinion a user has to accept in vivo behavior as at least co-authoritative with the documentation. I know this causes consternation for those who want a rigorous language definition as far as I know from the beginning we have never been provided with ...


2

Position is a pattern matching function, and pattern matching is performed on (something close to) the FullForm of an expression. Therefore when designing patterns, and especially when debugging them, the first thing to do is to look at the FullForm of the expression(s) you are working with. In this case: Infinity // FullForm DirectedInfinity[1] ...


2

I get the same on OS X. The cause of the "problem" can be seen by first evaluating Position[m, 1, {3}] (* {{1, 1, 1}, {1, 2, 1}, {1, 3, 1}, {2, 1, 1}, {3, 1, 1}} *) say what??!!! But then FullForm[m] (* List[List[DirectedInfinity[1],DirectedInfinity[1],DirectedInfinity[1]],List[DirectedInfinity[1],1,2],List[DirectedInfinity[1],2,3]] *) ...explains it ...


11

I think the documentation needs to be more clear on this; the order of definitions is important: Remove[plus] Attributes[plus] = {Orderless}; plus[x__Integer, y__Real] := x + y plus[2.5, 3] 5.5 So the Orderless attribute must be active at the time the definition is created. Noteworthy is that definitions made before setting the attribute can ...


0

Most Likely is because x^n^1 == x^n x^n == (x^n)^1 (*True*) a_ can be anything including x^n If you try for example Cases[Table[x^n, {n, 1, 10}], Power[x,1]] (*{x}*)


1

a_^1 is converted to a_ before Cases is executed, matching each element of the Table. Trace[Cases[Table[x^n, {n, 1, 10}], a_^1]] (The output is a bit long to be presented here.)


0

In case you don't have V10, you can use a combination of GatherBy and Cases as follows: First, define a helper function, vF, for aggregation of vote pairs: vF[{"ABSTAIN", Except["ABSTAIN"]} | {Except["ABSTAIN"], "ABSTAIN"}] = .5; vF[{x_, x_}] := 1; vF[{x_, y_}] := 0; and another helper function, rearrangeF, that rearranges the data for each resolution ...


0

Maybe I understood you right now. Give it a try with (the famous) Dataset ;-) keys = {venue, session number, resolution code, descriptor, full date, year, month, day, topic, country, vote code, vote}; First we make strings from the keys: keys = ToString /@ keys Now we have the data: (just your data) data = {{"UNGA", 63, 15294, "...", "30-Jun-09", ...


1

Maybe these other approaches will be useful for you pointer to function problem : 1.expr[x_] := 2*func[x] + 5 You can now for example always use expr but switch func to your needs. For example : func = Sin ; expr[hello] func = #^2 &; {expr[hello], expr[5]} return 5 + 2 Sin[hello] {5 + 2 hello^2, 55} But if you really need to create ...


2

I seem to recall a similar question but I cannot find it now. Anyway a key detail is that the body of the function presumably should not be evaluated, meaning e.g. func = Print[#^2] & should still work. Here is one approach: expr = Hold[2*{"FUNCTION1"} + 5]; func = Print[#^2] &; newfunc = Function @@ expr /. {"FUNCTION1"} -> Hold @@ func // ...


2

The answer is pretty simple and you were very close to seeing this yourself: Default[Times] (* Out[9]= 1 *) As you see, the DefaultValues for Times and Plus are already built in.


7

Your code StringMatchQ["ы", LetterCharacter] returns False, because only the following characters are treated as letters: StringJoin[Select[Characters[FromCharacterCode[Range[2^16 - 1]]], LetterQ]] and LetterCharacter only matches the characters for which LetterQ gives True. You can include Cyrillic symbols using: StringMatchQ["ы", ...



Top 50 recent answers are included