login  home  contents  what's new  discussion  bug reports     help  links  subscribe  changes  refresh  edit

Edit detail for SandBoxChoose revision 2 of 6

1 2 3 4 5 6
Editor: Bill Page
Time: 2014/09/19 06:12:45 GMT+0
Note:

changed:
-  while j(n)<=#a repeat
-    --output j
-    j(n):=j(n)+1
-    k:=n
-    while j(n)>#a and k>1 repeat
-      k:=k-1
-      j(k):=j(k)+1
-      for i in k..n-1 repeat j(i+1):=j(i)+1
-    if j(n)<=#a then r:=concat(r,[a(j(i)) for i in 1..n])
  k:=n
  while k>0 and j(k)+n-k<#a repeat
    j(k):=j(k)+1
    for i in k..n-1 repeat j(i+1):=j(i)+1
    r:=concat(r,[a(j(i)) for i in 1..n])
    k:=n; while j(k)+n-k>=#a and k>1 repeat k:=k-1

added:
choose([1],1)
choose([1,2],1)
choose([1,2],2)

fricas
choose(a,n) ==
  j:=[i for i in 1..n]
  r:=[[a(j(i)) for i in 1..n]]
  k:=n
  while k>0 and j(k)+n-k<#a repeat
    j(k):=j(k)+1
    for i in k..n-1 repeat j(i+1):=j(i)+1
    r:=concat(r,[a(j(i)) for i in 1..n])
    k:=n; while j(k)+n-k>=#a and k>1 repeat k:=k-1
  if binomial(#a,n)~=#r then error "error in choose"
  return r
Type: Void

fricas
choose([1],1)
fricas
Compiling function choose with type (List(PositiveInteger),
      PositiveInteger) -> List(List(PositiveInteger))

\label{eq1}\left[{\left[ 1 \right]}\right](1)
Type: List(List(PositiveInteger?))
fricas
choose([1,2],1)

\label{eq2}\left[{\left[ 1 \right]}, \:{\left[ 2 \right]}\right](2)
Type: List(List(PositiveInteger?))
fricas
choose([1,2],2)

\label{eq3}\left[{\left[ 1, \: 2 \right]}\right](3)
Type: List(List(PositiveInteger?))
fricas
choose([1,2,3],1)

\label{eq4}\left[{\left[ 1 \right]}, \:{\left[ 2 \right]}, \:{\left[ 3 \right]}\right](4)
Type: List(List(PositiveInteger?))
fricas
choose([1,2,3],2)

\label{eq5}\left[{\left[ 1, \: 2 \right]}, \:{\left[ 1, \: 3 \right]}, \:{\left[ 2, \: 3 \right]}\right](5)
Type: List(List(PositiveInteger?))
fricas
choose([1,2,3],3)

\label{eq6}\left[{\left[ 1, \: 2, \: 3 \right]}\right](6)
Type: List(List(PositiveInteger?))
fricas
choose([x,y,z,w],1)
fricas
Compiling function choose with type (List(OrderedVariableList([x,y,z
      ,w])),PositiveInteger) -> List(List(OrderedVariableList([x,y,z,w]
      )))

\label{eq7}\left[{\left[ x \right]}, \:{\left[ y \right]}, \:{\left[ z \right]}, \:{\left[ w \right]}\right](7)
Type: List(List(OrderedVariableList?([x,y,z,w])))
fricas
choose([x,y,z,w],2)

\label{eq8}\left[{\left[ x , \: y \right]}, \:{\left[ x , \: z \right]}, \:{\left[ x , \: w \right]}, \:{\left[ y , \: z \right]}, \:{\left[ y , \: w \right]}, \:{\left[ z , \: w \right]}\right](8)
Type: List(List(OrderedVariableList?([x,y,z,w])))
fricas
choose([x,y,z,w],3)

\label{eq9}\left[{\left[ x , \: y , \: z \right]}, \:{\left[ x , \: y , \: w \right]}, \:{\left[ x , \: z , \: w \right]}, \:{\left[ y , \: z , \: w \right]}\right](9)
Type: List(List(OrderedVariableList?([x,y,z,w])))
fricas
choose([x,y,z,w],4)

\label{eq10}\left[{\left[ x , \: y , \: z , \: w \right]}\right](10)
Type: List(List(OrderedVariableList?([x,y,z,w])))