4
$\begingroup$

I have:

$$\bigwedge_{i=1}^{9} \bigwedge_{n=1}^{9} \bigvee_{j=1}^{9}~p(i,j,n)$$

How can I write it in Wolfram Mathematica code?

I tried this way, but it does not work:

ToExpression["\\bigwedge_{i=1}^{9} \\bigwedge_{n=1}^{9} \\bigvee_{j=1}^{9}~p(i,j,n)",TeXForm]

During evaluation of In[2]:= ToExpression::esntx: Could not parse \bigwedge_{i=1}^{9} \bigwedge_{n=1}^{9} \bigvee_{j=1}^{9}~p(i,j,n) as input.

$Failed

What is the mistake in my above code?

$\endgroup$

2 Answers 2

5
$\begingroup$

Well, Mathematica can only parse its own language, not $\LaTeX$. The Mathematica equivalent would be

P = Array[p, {9, 9, 9}];
Apply[And,
  Apply[And,
   Apply[Or,
    Transpose[P, {1, 3, 2}],
    {2}],
   {1}],
  {0}];
$\endgroup$
10
  • $\begingroup$ But what about this ToExpression["input",TeXForm]? From here: reference.wolfram.com/language/tutorial/… convert TeX input to the Wolfram Language? $\endgroup$
    – vasili111
    Commented Aug 24, 2018 at 16:51
  • $\begingroup$ $\vee$ and $\wedge$ are interpreted quite differently among various mathematical subdisciplines, so Mathematica cannot assign unique meanings to them. Best is not to rely on such a way to code. See, ToExpression["\\sum_{i=1}^10 i", TeXForm] results in 0; complete nonsense. $\endgroup$ Commented Aug 24, 2018 at 16:56
  • $\begingroup$ Do you know any good tutorial/book/etc where is explained notation that is used in proposition in my post? Currently reading discrete math book but there is no explanation of that notation. I even do not know what to search in google to find that information. I tryied to search "index notation", "array notation", "compact for of propositions" but without luck. Maybe you know? $\endgroup$
    – vasili111
    Commented Aug 24, 2018 at 17:06
  • $\begingroup$ I don't exactly know what you mean. In mathematical logic, $\wedge$ means "and" and $\vee$ stands for "or". The notations of the form $\bigvee_{i=1}^9$ and $\bigwedge_{i=1}^9$ are analogous to the sum notation $\sum_{i=1}^9$. The latter should be explained in the first chapters of any beginner's analysis textbook. $\endgroup$ Commented Aug 24, 2018 at 17:15
  • 3
    $\begingroup$ Only single character superscripts are supported by Mathematica's TeXForm parser. Using ToExpression["\\sum_{i=1}^{10} i", TeXForm] works. $\endgroup$
    – Carl Woll
    Commented Aug 24, 2018 at 17:41
2
$\begingroup$

If you want to be able to input your notation into Mathematica directly, you can define special MakeExpression rules:

MakeExpression[RowBox[{UnderoverscriptBox["\[Wedge]",u__],r_}],form_]:=Replace[
    MakeExpression[RowBox[{UnderoverscriptBox["\[Sum]",u],r}],form],
    HoldComplete[Sum[a__]]:>HoldComplete[NaryWedge[a]]
]
NaryWedge[e_, iter_] := With[{list = Table[e, iter]},
    And @@ list /; ListQ @ list
]

MakeExpression[RowBox[{UnderoverscriptBox["\[Vee]",u__],r_}],form_]:=Replace[
    MakeExpression[RowBox[{UnderoverscriptBox["\[Sum]",u],r}],form],
    HoldComplete[Sum[a__]]:>HoldComplete[NaryVee[a]]
]
NaryVee[e_, iter_] := With[{list = Table[e, iter]},
    Or @@ list /; ListQ @ list
]

For example:

enter image description here

$p(7)\lor p(8)\lor p(9)$

Now, you might like to have the vee and wedge symbols slightly larger. To do this we can introduce input auto replacement rules:

CurrentValue[EvaluationNotebook[],{InputAutoReplacements,"vv"}] = StyleBox[
    "\[Vee]",
    FontWeight->Plain,
    FontFamily->"Impact"
];
CurrentValue[EvaluationNotebook[],{InputAutoReplacements,"ww"}] = StyleBox[
    "\[Wedge]",
    FontWeight->Plain,
    FontFamily->"Impact"
];

A short animation:

enter image description here

$\endgroup$
3
  • $\begingroup$ I pasted that code and executed. After I write ww and press Space. There appears $\bigwedge$ but the cursor is to the right side of $\bigwedge$. How can I input upper and lower part of that $\bigwedge$? $\endgroup$
    – vasili111
    Commented Sep 15, 2018 at 19:07
  • $\begingroup$ Use Ctrl-4 for underscript and Ctrl-5 to switch between under and overscript. See this tutorial for more details. $\endgroup$
    – Carl Woll
    Commented Sep 15, 2018 at 19:09
  • $\begingroup$ Very good example. It works great! Thank you. $\endgroup$
    – vasili111
    Commented Sep 15, 2018 at 19:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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