Post Reply 
Recursive programs in XCAS.
03-01-2017, 04:46 AM (This post was last modified: 03-01-2017 05:28 AM by Han.)
Post: #7
RE: Recursive programs in XCAS.
Here's a CAS version that works on the Prime. Notice the upper-case MAKELIST command (which is different from the lower-case makelist command). MAKELIST is a non-CAS command. This was a quick conversion from non-CAS to CAS (which does not support CASE as far as I can tell; it does have CASES, though, which seems to be the same as piecewise). You can make the code much cleaner using several return() calls.

PHP Code:
#cas
comboset(s,n):=
BEGIN
local l
;
local sl;
local tl;
local k;
local j;
local m;
local t;

m:=size(s);
l:={};
sl:={};
tl:={};

if 
n==m then l:={s}; else
  if 
n==1 then l:=MAKELIST({s(X)},X,1,m); else 
    if 
n>m then l:={}; else
      for 
k from 2 to m-n+do
        
sl:=sub(s,k,m); 
        
tl:=comboset(sl,n-1);
        for 
j from 1 to size(tl) do
          
tl[j]:=concat({s[k-1]},tl[j]);
        
end;
        
l:=concat(l,tl); 
      
end;
    
end;
  
end;
end;

return(
l);

END;
#end 

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Recursive programs in XCAS. - John P - 02-12-2017, 12:22 AM
RE: Recursive programs in XCAS. - Han - 02-12-2017, 01:41 AM
RE: Recursive programs in XCAS. - John P - 02-12-2017, 02:08 AM
RE: Recursive programs in XCAS. - John P - 02-12-2017, 02:32 AM
RE: Recursive programs in XCAS. - Han - 02-12-2017, 02:52 AM
RE: Recursive programs in XCAS. - Han - 02-12-2017, 04:06 AM
RE: Recursive programs in XCAS. - Han - 03-01-2017 04:46 AM
RE: Recursive programs in XCAS. - Han - 03-01-2017, 04:49 AM



User(s) browsing this thread: 3 Guest(s)