Skip to content

Yurie/Math/Label

Kernel

  • label[var_,lab_,head_] - join the variable(s) and label into labeled objects using the specified head.

    • var_ accepts _|(List|Alternatives)[__].

    • lab_ accepts _?AtomQ.

    • head_ accepts _Symbol. The heads Function and Symbol are handled separately, and the default is Function.

      Head Example
      Function var[lab]
      Symbol varlab
      head head[var,lab]
    • label2 - variant of label with Symbol as head.

  • labelRange[var_,range__,head_] - join the variable(s) and labels in the range using the specified head.

    • labelRange2 - variant of labelRange with Symbol as head.
  • labelAt[var_,rules__,head_] - take the specific values of the labeled objects according to rules.

  • labelConvert[var_,head1_->head2_,opts_][expr_] - convert the labeled objects according to the two specified label heads.

    • opts_:"LabelType"->All - control the pattern of labels, and resolve possible conflicts between variable and label.

      The supported values are

      • All
      • Any_ - user-specified function
      • "PositiveInteger"
      • "PositiveIntegerOrSingleLetter"
      • "PositiveIntegerOrGreekLetter"
      • "NaturalNumber"
      • "NaturalNumberOrSingleLetter"
      • "NaturalNumberOrGreekLetter"
    • labelJoin|labelSplit - variants of labelConvert that convert Symbol to/from other heads.

  • labelTo*[var_,rule_,head_] - return a ReplaceAll function according to the rule.

    Name Prototype
    labelToZero $ x_1 \to 0 $
    labelToEqual $ x_1 \to x_2 $
    labelToDiff $ x_1 \to x_{12} + x_2 $
    labelToDiffZero $ x_1 \to x_{12},\, x_2 \to 0 $
    labelToDiffBack $ x_{12} \to x_1 - x_2 $

Example

label Different heads

label[x|y,1,Function]
Out[] = Sequence[x[1],y[1]]
label[x|y,1,Symbol]
Out[] = Sequence[x1,y1]
label[x|y,1,head]
Out[] = Sequence[head[x,1],head[y,1]]

label Patterned variables

labelRange[x_|y_,4,Symbol]
Out[] = Sequence[x1_,y1_,x2_,y2_,x3_,y3_,x4_,y4_]

labelAt Different heads

labelAt[x,1->a,2|3->b,_->c,Function]
Out[] = ReplaceAll[{x[1]->a,x[2]->b,x[3]->b,x[_]->c}]
(* _->c is not supported. *)
labelAt[x,1->a,2|3->b,Symbol]
Out[] = ReplaceAll[{x1->a,x2->b,x3->b}]
labelAt[x,1->a,2|3->b,_->c,head]
Out[] = ReplaceAll[{head[x,1]->a,head[x,2]->b,head[x,3]->b,head[x,_]->c}]

labelConvert Basic usage

x1+y2//labelConvert[x|y,Symbol->Function]
Out[] = x[1]+y[2]

labelConvert Confliction

zb1//labelConvert[z|zb,Symbol->Function,"LabelType"->"PositiveInteger"]
Out[] = zb[1]
zb1//labelConvert[z|zb,Symbol->Function]
Out[] = z[b1]

labelTo* Basic usage

labelToDiff[x,1->2,3->4]
Out[] = ReplaceAll[{x[1]->x[2]+x["12"],x[3]->x[4]+x["34"]}]