#!/usr/bin/env setl
--
-- Squares in SETL
--
-- This program was inspired by the {log} (setlog) program
-- http://prmat.math.unipr.it/~gianfr/SETLOG/SamplePrograms/Squares.slog
-- """
-- Computes the set S of the squares of all numbers contained
-- in a set I
-- """
--
-- This SETL program was created by Hakan Kjellerstrand (hakank@bonetmail.com)
-- Also see my SETL page: http://www.hakank.org/setl/
--
ss := {2,3,4};
print(squares(ss));
print(squares2(ss));
-- The {log} solution is
-- S = {Y : exists(X, X in I & Y is X * X)}!.
-- However in SETL, we need a range for Y
proc squares(s);
return { y : y in [1..(max/s)**2] | exists x in s | y = x*x};
end proc;
-- this is a more SETL'is version
proc squares2(s);
return {y**2 : y in s};
end proc;