Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP lib: add SetAsDomain #3460

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/domain.gd
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ InstallTrueMethod( IsDuplicateFree, IsDomain );
## <#GAPDoc Label="GeneratorsOfDomain">
## <ManSection>
## <Attr Name="GeneratorsOfDomain" Arg='D'/>
## <Attr Name="GeneratorsOfSetAsDomain" Arg='D'/>
##
## <Description>
## For a domain <A>D</A>, <Ref Attr="GeneratorsOfDomain"/> returns a list
Expand All @@ -158,6 +159,9 @@ InstallTrueMethod( IsDuplicateFree, IsDomain );
## <A>D</A>, <C><A>D</A>.i</C> returns the <M>i</M>-th generator if
## <M>i</M> is a positive integer, and if <C>name</C> is the name of a
## generator of <A>D</A> then <C><A>D</A>.name</C> returns this generator.
## <P/>
## <Ref Attr="GeneratorsOfSetAsDomain"/> is a synonym for
## <Ref Attr="GeneratorsOfDomain"/>.
## </Description>
## </ManSection>
## <#/GAPDoc>
Expand Down
6 changes: 6 additions & 0 deletions lib/set.gd
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,9 @@ DeclareOperation( "IntersectSet", [ IsList and IsMutable, IsList ] );
## <#/GAPDoc>
##
DeclareOperation( "SubtractSet", [ IsList and IsMutable, IsList ] );

#############################################################################
##
# MOVE THIS TO domain.gd
DeclareSynonym("IsSetAsDomain", IsDomain);
DeclareSynonym("SetAsDomain", Domain);
47 changes: 47 additions & 0 deletions lib/set.gi
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,50 @@ InstallMethod( SubtractSet,
RemoveSet( set, obj );
od;
end );


#############################################################################
##
InstallMethod(SetAsDomain,
"for a set & collection",
[IsSet and IsCollection],
function(set)
local copy, type, domain;
copy := Immutable(set);
type := NewType(FamilyObj(copy),
IsSetAsDomain and IsAttributeStoringRep);
return ObjectifyWithAttributes(rec(), type,
GeneratorsOfDomain, copy,
AsList, copy,
AsSet, copy);
end);

# Provide family of objects `fam`. Then the resulting domain lives in the same
# family as a domain created from a non-empty set of objects of `fam`.
InstallOtherMethod(SetAsDomain,
"for a family and an empty list",
[IsFamily, IsEmpty and IsList],
function(family, set)
local copy, type;
copy := Immutable([]);
type := NewType(CollectionsFamily(family),
IsSetAsDomain and IsAttributeStoringRep);
return ObjectifyWithAttributes(rec(), type,
GeneratorsOfDomain, copy,
AsList, copy,
AsSet, copy);
end);

InstallMethod(\in,
"for an IsSetAsDomain",
[IsObject, IsSetAsDomain],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But IsSetAsDomain is merely a synonym for IsDomain; so now you really have installed a generic \in method for arbitrary domains, which tries to use AsList. That makes me a bit nervous, though I can't put my finger on it right now.

function(elm, set)
return elm in AsList(set);
end);

InstallMethod(PrintObj,
"for an IsSetAsDomain",
[IsSetAsDomain],
function( setAsDomain )
Print("SetAsDomain(", AsList(setAsDomain), ")");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you need a different function for empty domains?

end);