Re: Notation Package Precedence?
- To: mathgroup at smc.vnet.net
- Subject: [mg62070] Re: [mg62026] Notation Package Precedence?
- From: Jason Harris <jasonh at wolfram.com>
- Date: Thu, 10 Nov 2005 02:51:34 -0500 (EST)
- References: <200511090845.DAA17455@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
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 TagBox["\[DoubleLeftRightArrow]","Biconditional",SyntaxForm->"\[Implies]"] 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: Cell[BoxData[ RowBox[{"Notation", "[", RowBox[{ TagBox[ RowBox[{"a_", TagBox["\[DoubleLeftRightArrow]", "Biconditional", SyntaxForm->"\[Implies]"], "b_"}], NotationBoxTag, TagStyle->"NotationTemplateStyle"], " ", "\[DoubleLongLeftRightArrow]", " ", TagBox[ RowBox[{"Biconditional", "[", RowBox[{"a_", ",", "b_"}], "]"}], NotationBoxTag, 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: Cell[BoxData[ RowBox[{"AddInputAlias", "[", RowBox[{"\"\<bic\>\"", "\[Rule]", TagBox[ TagBox["\[DoubleLeftRightArrow]", "Biconditional", SyntaxForm->"\[Implies]"], NotationBoxTag, 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. Cheers, Jason 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) > >produces: > >(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 >with > >((a \[And] b) \[Or] c) \[DoubleLeftRightArrow] (a \[Or] c) \[And] (b \[Or] >c) > >which groups correctly > >(c || (a && b)) == (a || c) && (b || c) > >But does not evaluate to True, as it should. > > >-- >The Mathematica Wiki: http://www.mathematica-users.org/ >Math for Comp Sci http://www.ifi.unizh.ch/math/bmwcs/master.html >Math for the WWW: http://www.w3.org/Math/
- References:
- Notation Package Precedence?
- From: "Steven T. Hatton" <hattons@globalsymmetry.com>
- Notation Package Precedence?