Skip to main content
Commonmark migration
Source Link

#Mathematica 92 49

Mathematica 92 49

Calle deserves full credit for streamlining the code.

f@l_:=2 N@Norm[Tr[l/.{"r"→1,"l"→-1,"u"→I,"d"→-I}]]

Example

f[{"u", "u", "u", "u", "d", "r", "r", "r", "l"}]

7.2111

#Mathematica 92 49

Calle deserves full credit for streamlining the code.

f@l_:=2 N@Norm[Tr[l/.{"r"→1,"l"→-1,"u"→I,"d"→-I}]]

Example

f[{"u", "u", "u", "u", "d", "r", "r", "r", "l"}]

7.2111

Mathematica 92 49

Calle deserves full credit for streamlining the code.

f@l_:=2 N@Norm[Tr[l/.{"r"→1,"l"→-1,"u"→I,"d"→-I}]]

Example

f[{"u", "u", "u", "u", "d", "r", "r", "r", "l"}]

7.2111

shortened code due Calle's suggestion
Source Link
DavidC
  • 25.4k
  • 2
  • 52
  • 105

#Mathematica 9292 49

Calle deserves full credit for streamlining the code.

f@l_ := 2 √Tr[{Re@#, Im@#}²] &@Tr[Select[ToLowerCase@l 
 =2 N@Norm[Tr[l/. {"r" -> 1"r"→1, "l" -> "l"→-1, "u" -> I"u"→I, "d" -> "d"→-I}, NumericQ]] // N]]

Example

f[{"u", "U""u", "u", "u", "d","X", "r", "r", "r", "l"}]

7.2111

#Mathematica 92

f@l_ := 2 √Tr[{Re@#, Im@#}²] &@Tr[Select[ToLowerCase@l 
  /. {"r" -> 1, "l" -> -1, "u" -> I, "d" -> -I}, NumericQ]] // N

Example

f[{"u", "U", "u", "u", "d","X", "r", "r", "r", "l"}]

7.2111

#Mathematica 92 49

Calle deserves full credit for streamlining the code.

f@l_:=2 N@Norm[Tr[l/.{"r"→1,"l"→-1,"u"→I,"d"→-I}]]

Example

f[{"u", "u", "u", "u", "d", "r", "r", "r", "l"}]

7.2111

Source Link
DavidC
  • 25.4k
  • 2
  • 52
  • 105

#Mathematica 92

f@l_ := 2 √Tr[{Re@#, Im@#}²] &@Tr[Select[ToLowerCase@l 
  /. {"r" -> 1, "l" -> -1, "u" -> I, "d" -> -I}, NumericQ]] // N

Example

f[{"u", "U", "u", "u", "d","X", "r", "r", "r", "l"}]

7.2111