11.07.2015 Views

Advanced Programming Guide

Advanced Programming Guide

Advanced Programming Guide

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

[ seq( s[j][c[j]], j=1..2 ) ];2.3 Local Variables and Invoking Procedures • 21[γ, x]Before you call the element procedure you must initialize all the countersto 1, except the first one, which must be 0.> c := array( [0, 1] );c := [0, 1]In following procedure element, nops(s) is the number of sets andnops(s[i]) is the number of elements in the ith set. When you have seenall the elements, the procedure re-initializes the array of counters andreturns FAIL. Therefore, you can repeatedly trace the Cartesian productby calling element.> element := proc(s::list(set), c::array(1, nonnegint))> local i, j;> for i to nops(s) do> c[i] := c[i] + 1;> if c[i] return [ seq(s[j][c[j]], j=1..nops(s)) ] ;> end if;> c[i] := 1;> end do;> c[1] := 0;> FAIL;> end proc:> element(s, c); element(s, c); element(s, c);[α, x][β, x][γ, x]> element(s, c); element(s, c); element(s, c);[α, y][β, y][γ, y]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!