Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

My notation is not recursing enough. For example,

Notation[W[a_ | b_] ⟹ foo[a_, b_]/foo[b_]]
Notation[W[a__, b_ | c_] ⟹ W[a__ | c_]W[b_ | c_]]

Then

W[a, b, c, d | e]

will give

foo[d, e]W[a, b, c | e]/foo[e]

My question is why does the W[a, b, c | e] in the above not expand further until it gets to the foo level?

share|improve this question

1 Answer 1

up vote 4 down vote accepted

It doesn't recurse because you are using a definition of Notation (from the Notation` package) that is restricted to parsing:

enter image description here

This means that you will have to explicitly ShiftReturn for the notation to take effect. Notice the following:

You can achieve what you want using straightforward definitions instead:

Clear@WW
WW[a__, Verbatim[Alternatives][b_, c_]] := WW[Sequence @@ Most[{a}], Last@{a} | c] WW[b | c]
WW[Verbatim[Alternatives][a_, b_]] := foo[a, b]/foo[b]

which gives as expected:

WW[a, b, c, d | e]
(* (foo[a, e] foo[b, e] foo[c, e] foo[d, e])/foo[e]^4 *)
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.