wrh

5 Reputation

One Badge

7 years, 205 days

MaplePrimes Activity


These are replies submitted by wrh

Thanks for the helpful answers!

I knew about whattype(e) but wanted to understand op(0,e) better for a course that I am teaching.

I think the complete answer for non-indexed e is now as follows: op(0,e) is a constructor for e if it exists, and it equals whattype(e) if no constructor exists. Examples without a constructor include set, list, exprseq, string.

One subtlety that I noticed is that, although op(0,e)(op(e)) always seems to give e when e has a constructor, it is not in general true that v(op(e)) gives e if v is the value of op(0,e). The problem is that is sometimes a reserved word (union, intersect, minus, subset, in, and, etc.). To make the constructor, in general we need to backquote v, e.g. if e := a union b, then

  • op(0,e) is union, and op(e) is a,b,
  • the would-be expression union(a,b) gives an error message
  • `union`(a,b) correctly evaluates as a union b,

Note that backquotes are included in op(0,e) in the case of operators like `+` but not in the case of reserved words.

Page 1 of 1