6.61 assigning to a function a(1) (1.10.01)

6.61.1 Arieh Tal
6.61.2 Adri van der Meer (2.10.01)
6.61.3 Dr Francis J. Wright(2.10.01)
6.61.4 Preben Alsholm (3.10.01)
6.61.5 Robert Israel (9.10.01)

6.61.1 Arieh Tal

The following behavior puzzles me: apparently Maple doesn’t consider a(1) as a different name than a but is also giving an error when I try to reassign a(1) and not when I reassign a?!

> a(1):=1; 
 
                              a(1) := 1 
 
> a:=12; 
 
                               a := 12 
 
> a(1); 
 
                                  12 
 
> a(1):=1; 
Error, invalid left hand side in assignment 
 
> a:=13; 
 
                               a := 13 
 
> a(5); 
 
                                  13 
 
> a(12):=1; 
Error, invalid left hand side in assignment 
 
> a(12); 
                          13
 

6.61.2 Adri van der Meer (2.10.01)

> a(1):=1; 
                              a(1) := 1
 

Here you make an undefined procedure a and place the value a(1) in its remember table:

> whattype(eval(a)); 
                              procedure 
 
> op(4,eval(a)); 
                            table([1 = 1]) 
 
 
> a:=12; 
                               a := 12
 

Now you assign to a the value 12:

> whattype(a); 
                               integer
 
... which may act as the constant function x -> 12:
 
> a(1); 
                                  12 
 
> a(1):=1; 
Error, invalid left hand side in assignment
 

But, of course, a constant function doesn’t have a remember table, so you can not place a value in it.

6.61.3 Dr Francis J. Wright(2.10.01)

My best advice is not to use functional forms (i.e. anything of the general form y(x)) as variables. Maple allows this, but it causes considerable confusion. a(1) IS different from a. I will try to explain below what is happening in your example.

> a(1):=1; 
 
                              a(1) := 1
 

a is unbound and so a(1) is a valid functional form that can be used as a variable.

> a:=12; 
 
                               a := 12 
 
> a(1); 
 
                                  12
 

Now a has the value 12, and Maple accepts 12 as a constant function, so that 12 applied to any argument(s) returns the value 12.

> a(1):=1; 
Error, invalid left hand side in assignment
 

But 12(1) is not a valid functional form for assignment. The above also explains the rest of your example.

If you want to define functions then use either the arrow syntax or the full procedure syntax.

[In fact, an assignment of the form y(x) := z implicitly assigns a procedure to y (if necessary) and then inserts an entry in its remember table, which can be very useful for defining "point" mappings, base cases for recursion, etc. The error above arises because the integer 12 cannot be used as an identifier and so cannot be assigned a procedure.]

6.61.4 Preben Alsholm (3.10.01)

a(1) is not a valid name in Maple. But if a is unassigned or the name of a procedure, then a(1) means a applied to 1 and you can assign to that, like a(1):=37; which has the effect of putting that information in the remember table for a.

The command a:=12; makes a the integer 12. Even the command a:= x->12; is by Maple simplified to the integer 12, thus also in this case making it impossible to assign to a remember table. That in fact the command a(1); gives 12 is due to the fact that 12(1); by Maple is simplified to 12. You could do like this:

a:=proc()  12  end proc;
 

This way a is not simplified to the integer 12 and so we can assign to its remember table:

a(1):=37;
 

To see the remember table, do this:

op(4,eval(a));
 

6.61.5 Robert Israel (9.10.01)

a(1) isn’t a name, it’s the value of the function "a" on the argument 1. At the start of your session, "a" was unassigned. When you entered

> a(1):= 1;
 

Maple actually assigned a value to "a", namely a function that returns unevaluated, but has a remember table containing the value you assigned:

> interface(verboseproc=3): 
  eval(a); 
 
              proc() option remember; 'procname(args)' end proc # (1) = 1
 

When you then said

> a:= 12;
                                                                                    
                                                                                    
 

you erased this definition, and gave "a" the number 12 as a value. A number can be used as a function with a constant value:

> 12(3); 
 
         12
 

But a number doesn’t have a remember table, so

> a(1):= 1;
 

is not allowed.