0
$\begingroup$

For a special notation I would like to get the help of Mathematica to expand complex expressions through a set of Notation rules. However since this tasks involves applying the notation recursively using the Notation package is out of question. To explain my problem lets look at the following set of rules We first have a function called cut which resembles an inequality defining cutting a 3D space into an interior and an exterior region, whereas the cut plane itself is member of the interior.

$cut[miller\_,c\_]:=miller.\{x,y,z\}+c \ge 0$

another function pcut implements a similiar function but the members of the cutplane are member of the exterior

$cut[miller\_,c\_]:=miller.\{x,y,z\}+c > 0$

with $miller$ being the miller indices of the plane described by a list $\{h,k,l\}$ and $c$ the distance of the plane from the origin.

There are now different rules transforming these junctions like

$-cut[miller,c]\Leftrightarrow cut[-miller,-c]$

$\dagger cut[miller,c]\Leftrightarrow cut[-miller,c]$

$cut[miller,c] \cdot s\Leftrightarrow cut[miller,c\times s]$

$cut[miller,c] / s\Leftrightarrow cut[miller,c/s]$

These rules are now described by the following short hand notations

$x_1\Leftrightarrow cut[\{-1,0,0\},1]$

$x_0\Leftrightarrow -x_1\cdot 0$

$x_2\Leftrightarrow -x_1/2$

$z_1\Leftrightarrow cut[\{0,0,-1\},1]$

and so on.

This syntax enables now more complex notations where even subconditions can be applied like e.g.

$z_0(-y_0)$

which means that the face of the volume $z_0\Leftrightarrow z\ge 0$ given by $z=0$ is restricted to $-y_0\Leftrightarrow y\le 0$ which finally results in the point $\{0,0,0\}$. More details about this syntax and the application of it can be found in "Exact direct-space asymmetric units for the 230 crystallographic space groups".

Now to my problem. If I try to invoke the notation package e.g. by doing the following:

$Notation[-cut[\{h\_,k\_,l\_\},c\_\}]\Leftrightarrow cut[\{-h\_,-k\_,-l\_\},-c\_]$

$Notation[\dagger cut[\{h\_,k\_,l\_\},c\_\}]\Leftrightarrow cut[\{-h\_,-k\_,-l\_\},c\_]$

and then

$Notation[x_1 \Leftrightarrow cut[\{-1,0,0\},1]]$

$Notation[x_0 \Leftrightarrow -cut[\{-1,0,0\},1]\cdot 0]$

this notation does not work recursively as one can quickly see by evaluating

$x_0$

which yields

$cut[\{1,0,0\},-1]\cdot 0$

which shows that Notation does not resolve such symbols recursively.

I noticed from other posts that MakeBoxes may do the trick and I'm not really happy how Notation is implemented. However I'm lost in implementing MakeBoxes correctly to implement above mentioned syntax correctly. Any help?

$\endgroup$
1
  • $\begingroup$ My understanding is that you're trying to do more than just format expressions for display. You're transforming expressions. That's not what Notation of MakeBoxes are really meant for, so I addressed your specific issues in a different way. You mention additional "subconditions," but I don't think they are part of the actual question you're asking, so I didn't address their implementation. $\endgroup$
    – Jens
    May 17, 2015 at 19:03

1 Answer 1

2
$\begingroup$

If I understood you correctly, this set of definitions would do what you wrote:

ClearAll[cut]

cutFunction[miller_, c_] := miller.{x, y, z} + c >= 0

cutSimplify[expr_] := Simplify[expr /. cut -> cutFunction]

cut /: HoldPattern[Times[cut[m_, c_], s_]] /; s > 0 := cut[m, s c];
cut /: HoldPattern[Times[cut[m_, c_], s_]] /; s < 0 := cut[-m, s c];
cut /: HoldPattern[Times[cut[m_, c_], 0]] := cut[m, 0]

Subscript[x, 1] := cut[{-1, 0, 0}, 1];
Subscript[x, 0] := -Subscript[x, 1] 0;
Subscript[x, 2] := -Subscript[x, 1]/2;

Subscript[x, 1]

(* ==> cut[{-1, 0, 0}, 1] *)

Subscript[x, 2]

(* ==> cut[{1, 0, 0}, -(1/2)] *)

Subscript[y, 2]

(* ==> cut[{0, -1, 0}, 1/2] *)

cutSimplify[Subscript[y, 2]]

(* ==> 2 y <= 1 *)

So first of all, I don't use Dot or / because they aren't really appropriate as operators here. The division symbol immediately becomes Times internally, so you cannot base definitions on it. Instead, I just use Times for everything, just distinguish whether you multiply by positive, negative or zero numbers.

The behavior of cut according to your definitions is implemented using TagSetDelayed, which means I can't define cut as a function itself because Heads are evaluated first. Instead, I define the operation as cutFunction and leave it to you at the end to invoke that operation by wrapping the expression in cutSimplify.

The subscript notation is defined simply by copying your definitions verbatim, it causes no problems because there is no need to invoke the Notation package in this approach.

The notation $z_0(-y_0)$ isn't implemented yet, because I just wanted to show the basic idea and can't spend time on reading that paper right now.

$\endgroup$
1
  • $\begingroup$ thats basically what I was looking for. The only "drawback" is that one needs to apply the cutSimplify function to get the inequality. With respect to the subconditions you are right this is not the key element of the question... $\endgroup$
    – Rainer
    May 19, 2015 at 19:55

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.