Usually h @@@ {f[1, 2], f[3, 4]} === {h[1, 2], h[3, 4]} but this is not the case when f is Complex: h @@@ {1 + 2I, 3 + 4I } === {1 + 2 I, 3 + 4 I}
Since Complexis an atomic and as documentation for Apply states: Applying to atomic objects that do not have subparts effectively does nothing
Using Block to replace Complex with complex gives result as expected for non-atomic case:
Block[{Complex = complex},
List @@@ {Complex[1, 2], Complex[3, 4]}
]
(* {{1, 2}, {3, 4}} *)
But then how come replacing Complex with List while not Apply-ing does not give the same result?
Block[{Complex = List},
{Complex[1, 2], Complex[3, 4]}
]
(* {Complex[1, 2], Complex[3, 4]} *)
As it would have for a non-atomic head:
Block[{f = List},
{f[1, 2], f[3, 4]}
]
(* {{1, 2}, {3, 4}} *)
TracePrint[Block[{Complex = List}, {Complex[1, 2], Complex[3, 4]}]], the replacement happens. Quite odd, this evaluation... – J. M.'s missing motivation Jun 19 '13 at 16:19With[{Complex = List}, {Complex[1, 2], Complex[3, 4]}]works, but still does not explain the behavior.Block[{Complex = complex}, {Complex[1, 2], Complex[3, 4]}]does not work either, soApplying seems to be the key – Ajasja Jun 19 '13 at 16:32Block[{Complex}, Complex := List; {Complex[1, 2], Complex[3, 4]}], and after that, the original example works too. Looks like some changes are not propagated properly. – Leonid Shifrin Jun 19 '13 at 16:33Complexexists only by implication, as in a packed array. – Oleksandr R. Jun 19 '13 at 16:45Blockonly affects things that do; right? – Mr.Wizard Jun 19 '13 at 16:46Unprotect[Graph]; Graph[{1 \[UndirectedEdge] 2, 2 \[UndirectedEdge] 3}] // AtomQ (*True*); Graph = hh; Graph[{1 \[UndirectedEdge] 2, 2 \[UndirectedEdge] 3}]; Quit[]then. Even though Mathematica says the expression is an atom, we do get the substitution of heads in this case. – Jacob Akkerboom Jun 19 '13 at 18:39Complex[1, 2]is not equivalent to1 + 2I.Block[{Complex = f}, List @@@ {Complex[1, 2], 3 + 4 I}]gives{{1, 2}, 3 + 4I}I thought that was just a syntactic difference – ssch Jun 19 '13 at 18:44Graphhaving subparts whileComplexdoes not. (i.e. you can't get the real part of aComplexwith(1+2I)[[1]]) – ssch Jun 19 '13 at 18:46Block[{Complex}, Plus[3, Complex[0, 4]]] + 2->5 + Complex[0, 4]. Which is crazy. Also,Tracelies about how3 + 4 IbecomesComplex[3,4]. What a mess. – Jacob Akkerboom Jun 19 '13 at 21:50