# Tag Info

1

SeedRandom Mat = Table[vectelem @ RandomInteger[{1, 30}], {i, 10}, {j, 10}]; You can use Pattern + Condition (/;) + VectorQ + NumericQ to define your argument pattern: ClearAll[pattern, Fmat1] pattern = p : Pattern @@@ Array[{Symbol["q" <> ToString@#], _} &, 30] /; VectorQ[p, NumericQ]; Fmat1[pattern] = Mat; If a list of ...

8

A simple trick is to notice that in Mathematica, Exp[x] can be written as Exp@(x) where the @ symbol has very high precedence. A replacement of the string "exp" by the string "Exp@" therefore does the necessary conversion without needing any bracket-matching logic: convert[s_String] := ToExpression[StringReplace[s, "exp" -> &...

7

Update: We can convert the strings to expressions without any string processing: ClearAll[sR0] sR0 = ToExpression[#, TraditionalForm] &; sR0 /@ {str1, str2, str3, str4, str5} // Column If you need to get strings as output wrap the expression with ToString[#, InputForm]& using the third argument of ToExpression: ClearAll[sR01] sR01 = ToExpression[#, ...

8

pattern = StringReplace["f_ath_r", "_" -> Blank[]] "f" ~~ _ ~~ "ath" ~~ _ ~~ "r" DictionaryLookup @ pattern {"feather"} Generalizing to allow __ and ___ in the input string: toSPattern = StringReplace[p : Repeated["_", {1, 3}] :> ToExpression[p]]; DictionaryLookup[toSPattern@&...

0

You could post-process the definitions: ClearAll[FixMinusPattern]; SetAttributes[FixMinusPattern, HoldAll]; FixMinusPattern[fn_] := DownValues[fn] = Quiet@ReplaceAll[DownValues[fn], HoldPattern[ Verbatim[HoldPattern][ fn[PatternSequence[otherArgs1___, Verbatim[Pattern][a_, type_], otherArgs2___, -1*Verbatim[Pattern][a_, ...

0

A slightly pointless way of solving the problem with a single variable... G[X : Repeated[_, {2}] /; {X} . {1, 1} == 0] := 0 G[4, -4] (* 0 *)

Top 50 recent answers are included