I'm at my string rewrite systems again. I always implemented these as rules on function arguments. For example, assume a rule is you can drop all arguments 0
:
F[x___,0,y___]:=F[x,y];
F[1,0]
No problem. But now assume my task is to insert a pair of formal brackets (call them A
and Z
) everywhere in F
:
(*In*) F[1,2]
(*Out*) {F[A,1,Z,2],F[1,A,2,Z],F[A,1,2,Z]}
Doable - I replace F
by List
, run over all position pairs, replace List
back to F
, whoopsie, forgot that I can have nested F
expressions...a nuisance. Then I had the idea: Why not define on List
directly?
List[x___,a,y___]:=List[x,y];
(*Special Epic Fail*)
My question: Am I right that you can't make rules on internal functions of Mathematica at all, to protect the innocent?
Log[x_]:=Sin[x];
(*Generic Epic Fail*)
Or is there a limited possibility? Of course, since all Mathematica is based on List
, it has to be protected at all costs, but, say, replacing all Exp[x]=Cos[x]+I*Sin[x]
on the fly doesn't look that desastrous...
SetAttributes[Log, Flat]
Log[Log[a]]
(Silly, but this shows that Protected
doesn't protect against all shenanigans.)
List
in as sweeping a way as you did. It is a Very Bad Idea and it will Break Things all over the place. But you have found out the answer to that question already, by direct experimentation. So perhaps rewrite your question to focus on accomplishing the task you originally wanted instead. $\endgroup$