New answers tagged

7

The problem arises from naming the inner sub-patterns in your two pattern definitions with the same identifier. When you combine the patterns with Alternatives, you then have a pattern with two sub-patterns tagged with the same name, which is bad. Consider this simpler case. pattern1 = StartOfString ~~ "(" ~~ t : WordCharacter .. ~~ ")1" ~...


0

Yet another approach is to take the Union of 2-subsets that satisfy the condition: highlighted = Union @@ Select[Length[Intersection @@ #] >= 2 &] @ Subsets[list, {2}] {{a, b, c}, {b, c, d}, {c, a, m}, {c, d, n}} list /. x : Alternatives @@ highlighted :> Style[x, Gray]


1

list /. x : {__Symbol} /; Max[Length[Intersection[x, #]] & /@ DeleteCases[list, x]] >= 2 :> Style[x, Gray] A method using GatherBy: gb = Join @@ Select[Length@# > 1 &]@ GatherBy[list, Function[x, Max[Length[Intersection[x, #]] & /@ DeleteCases[x][list]]]] {{a, b, c}, {b, c, d}, {c, a, m}, {c, d, n}} list /. x : ...


1

I think the easy way is still use Gather and reorder the index. Here we handle the general situation. SeedRandom[400]; list = Table[RandomSample[Alphabet[], 3], 40]; newlist = Thread[Range[Length@list] -> list]; result = Gather[newlist, Length[Intersection[Last@#1, Last@#2]] >= 2 &]; keys = Keys /@ result; keyc = Thread[keys -> RandomColor[...


1

A variant of OP's solution that avoids nesting of Highlighted: list //. {a___, x : ({_, _, _} | Highlighted[{_, _, _}, ___]), b___, y : ({_, _, _}), c___} /; Length[Intersection[x /. Highlighted -> (# &), y]] >= 2 :> {a, Highlighted[x /. Highlighted -> (# &)], b, Highlighted@y, c} Same approach using Style: list //. {a___, x : (...


3

rg = RelationGraph[UnsameQ @ ## && Length@Intersection[##] >= 2 &, list] hl = VertexList @ EdgeList @ rg {{a, b, c}, {b, c, d}, {c, a, m}, {c, d, n}} list /. x : Alternatives @@ hl :> Style[x, Gray] list /. x : Alternatives @@ hl :> Highlighted[x, BaseStyle -> Red] HighlightGraph[rg, hl] You can also use ConnectedComponents and ...


2

ClearAll[formatList] formatList[list_] := Module[{rules}, rules = AssociationThread[ list -> (If[Max[#] >= 2, Gray, Black] & /@ Function[{element}, Length@Intersection[element, #] & /@ Complement[list, {element}]] /@ list) ]; Style[#, rules[#]] & /@ list ] formatList[list]


3

You can use SequenceCases: SequenceCases[ data, {textHeader, s:PatternSequence[moveTo, text]..} -> {textHeader, s} ] {{textHeader, moveTo, text, moveTo, text}, {textHeader, moveTo, text}}


2

Let us introduce a function factor that will be able to factorize the expression taking out a desired multiplicand: factor[expr_, fact_, fun1_ : Expand, fun2_ : Identity] := Module[{a = fact, b = expr/fact},fun2[Evaluate[a]]*fun1[Evaluate[b]]] This is the expression: expr = -t^-b + (t - t^(1/2 + 1/(8 k)))^-b; By applying the function factor as follows ...


1

Based on Mathematica documentation, and alternative solution could be implement a simple replacement rule as follows in the next function: NoUnits[f_] := f /. q_Quantity :> QuantityMagnitude[q] Then, implement the Plot as a pure function to increase drastically the execution time: AbsoluteTiming[Plot[ #, {l, .1, 15}, Frame -> True, ...


0

If already in the input of the actual notebook: KnownUnitQ["Microflicks"] gives True. So there is need for someaction to get this referentially connceted to other known unit entities. Mathematica V 12.0.0 has FormularLookup and FormulaData for lot of the questions purposes. FormulaLookup["planck's law"] The unit system in Physics is in ...


2

Instead of using UnitConvert, you can just divide the output by the relevant output unit. Here's one implementation of the idea, based on the OP's version: ClearAll @ NoUnits; SetAttributes[NoUnits, HoldAll]; NoUnits[fun_, quants : {__Quantity}, output : Quantity[1, out_]] := Expand[fun/output /. Thread[quants[[All, 1]] -> quants]] /. x_ y_Piecewise ...


4

data = {{"S", "T", "C", "R1", "R2"}, {a, 1, x, 2.9}, {a, 1, y, 2.6}, {a, 1, z, 8.7}, {a, 2, x, 9.4, 0.372}, {a, 2, y, 8.1, 0.208}, {a, 2, z, 7.6, 0.154}, {b, 1, x, 7.5}, {b, 1, y, 7.3}, {b, 1, z, 1.7}, {b, 2, x, 3.9, 0.213}, {b, 2, y, 7.9, 0.435}, {b, 2, z, 2.5, 0.294}, {c, 1, x, 6.2}, {c, ...


4

I am not sure wether I understood correctly which results should be recombined but this code does the following: First the data is gathered by condition, then by test, then subsets of length 2 are generated and in the final step the numerical computation on the results is applied: test1[{{a_,1,c_,R1a_},{b_,1,c_,R1b_}}]:={a,b,1,c,R1a/R1b} test2[{{a_,2,c_,R1a_,...


Top 50 recent answers are included