MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Notation Package Precedence?

  • To: mathgroup at
  • Subject: [mg62070] Re: [mg62026] Notation Package Precedence?
  • From: Jason Harris <jasonh at>
  • Date: Thu, 10 Nov 2005 02:51:34 -0500 (EST)
  • References: <>
  • Sender: owner-wri-mathgroup at

Hi Steven,

The following is true independent of the Notation package. Its the 
general way you can "manipulate" the precedence of something in the 
FrontEnd in Mathematica.

If you want to change the precedence form of an operator then you 
have to wrap the *boxes* of thing you want to be of a different 
precedence with a TagBox with the option SynatxForm-><someString> 
where the parsed result of <someString> is the precedence that you 
want. That is you have to edit the box structure with cmd-shift-E or 
another method.

Thus for your operator you probably want something like the following 
underlying box structure


The string "\[Implies]" means that this composite structure has the 
precedence of an \[Implies] operator. (\[Implies] has a lower 
precedence than either \[And] or \[Or] so groups the way that you 
want (See A.2.7 in the Mathematica help.)

(Refinements: In fact you probably want to add Editable->False, and 
Selectable->False to that as well so that the users can't separately 
select the "\[DoubleLeftRightArrow]" inside the TagBox. Ie they have 
to select the whole composite structure. (You might also might want 
to package the TagBox options up into a style so you can just use 
something like TagBox["\[DoubleLeftRightArrow]","Biconditional"].) 
(Actually I just discovered there is an annoying assertion failure in 
Mathematica 5.x when using Selectable->False in this TagBox 
structure. However, this has already been corrected for the next 
major version of Mathematica. This assertion error while annoying is 
harmless and you can ignore it.))

Thus after loading the notation package you would use the following 
statement. Paste and evaluate this into Mathematica:

     RowBox[{"Notation", "[",
               SyntaxForm->"\[Implies]"], "b_"}],
           TagStyle->"NotationTemplateStyle"], " ", 
"\[DoubleLongLeftRightArrow]", " ",
           RowBox[{"Biconditional", "[",
             RowBox[{"a_", ",", "b_"}], "]"}],
           TagStyle->"NotationTemplateStyle"]}], "]"}]], "Input"]

Then just evaluate the following or use convert to StandardForm

Biconditional[(a && b) || c, (a || c) && (b || c)]

However, you won't be able to just type a plain 
\[DoubleLeftRightArrow] character to get this non-standard precedence 
character. Ie there is no global way to change the precedence of the 
\[DoubleLeftRightArrow] character. However you can easily create an 
input alias so you can type this composite character easily.

Ie paste and evaluate the following into Mathematica after loading 
the Notation package:

     RowBox[{"AddInputAlias", "[",
       RowBox[{"\"\<bic\>\"", "\[Rule]",
           TagStyle->"NotationTemplateStyle"]}], "]"}]], "Input"]

Then you can just type say: a esc-bci-esc b to get an expression a 
<biconditional> b

where the <biconditional> looks like a \[DoubleLeftRightArrow] but 
groups like an \[Implies] operator and using the Notation statement 
above is parsed and formatted to/from a Biconditional.


At 3:45 AM -0500 11/9/05, Steven T. Hatton wrote:
>I've discovered that I can produce a "logical equals" like this:
>Biconditional[p_, q_] := (LogicalExpand //@ p) == (LogicalExpand //@ q)
>But if I infix it like so:
>p_ \[DoubleLeftRightArrow] q_ := Biconditional[p, q]
>it doesn't group correctly unless I force it with parentheses.  For example:
>(a \[And] b) \[Or] c \[DoubleLeftRightArrow] (a \[Or] c) \[And] (b \[Or] c)
>(a && b) || (c == (a || c) && (b || c))
>This seems to work correctly.  At least it produces the expected results.
>((a \[And] b) \[Or]
>       c) \[DoubleLeftRightArrow] ((a \[Or] c) \[And] (b \[Or] c))
>I tried using the Utilitie`Notation` package, but when I passed the option
>SyntaxForm to Notation, it seemed to ignore it.  Does anybody know how to
>get the Notation package to change the precedence of an operator?
>I'm not convinced that will solve the genearl case.  I still have a problem
>((a \[And] b) \[Or] c) \[DoubleLeftRightArrow] (a \[Or] c) \[And] (b \[Or]
>which groups correctly
>(c || (a && b)) == (a || c) && (b || c)
>But does not evaluate to True, as it should.
>The Mathematica Wiki:
>Math for Comp Sci
>Math for the WWW:

  • Prev by Date: Re: Re: 5.2 on suse 10.0 error
  • Next by Date: Re: 'Good' or 'Proper' Mathematica coding habits question
  • Previous by thread: Notation Package Precedence?
  • Next by thread: Re: Notation Package Precedence?