Skip to content

Yurie/Math/Label

Kernel

  • label[var_,lab_,head_] - join the variable(s) and label(s) into a (sequence of) labeled object(s).

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

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

    • 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]
  • labelAt[var_,rule_,head_] - take the specific value(s) of the labeled object(s).

    • rule_ accepts __Rule|List[__Rule].
  • labelConvert[var_,head1_->head2_,opts_][expr_] - convert the labeled object(s) 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[var_,head_,opts_][expr_] - special cases 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|2,Function]
Out[] = Sequence[x[1],x[2],y[1],y[2]]
label[x|y,1|2,Symbol]
Out[] = Sequence[x1,x2,y1,y2]
label[x|y,1|2,head]
Out[] = Sequence[head[x,1],head[x,2],head[y,1],head[y,2]]

label Patterned variables

label[x_|y_,Range[4],Symbol]
Out[] = Sequence[x1_,x2_,x3_,x4_,y1_,y2_,y3_,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"]}]