So I am new to maple and need to write a procedure that given one list removes the entries of that list from another.

[> thingy := proc (a1, a2)
[> local i, j, a3; 
[> for i to nops(a1) do 
      for j to nops(a2) do 
         if evalb(a2[j] = a1[i]) then a3 := subsop(i = NULL, a1) end if; 
      end do;
   end do; 
   return a3 end proc

essentially, this code returns the original list, a1, as if I had not run the code. I am really quite stumped as of what to do.



1 Answer 1


There's a little ambiguity in your description. I'm interpreting it as meaning that you want every instance within the first list a1 of any member of the second list a2 to be replaced by NULL.

Is this of any use? I mean, do you just need the functionality? Or is it coursework, for you to code it using loops. etc?

You might want to take care about time and space efficiency. Even if your original had worked, it would be creating an entirely new (partial result) list for each time through the nested loops. That could entail the production a great deal of collectible garbage (and the time to clear such).


thingy2:=proc(a1::list, a2::list)
    local s2;
    s2:={op(a2)}; # saves effort, using a uniquified version
end proc:

thingy2( [1,2,3,4,5,6,5,5,7,2,1], [4,5,4,2,5] );

                    [1, 3, 6, 7, 1]

I'm sure that this is not optimally efficient, but hopefully it scaled not too horribly.

  • $\begingroup$ Thanks, it was for functionality... I am really not familiar with maple and didn't even know about the remove function. Reply is appreciated. $\endgroup$
    – Nick S
    Aug 16, 2013 at 18:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .