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

Do you like sets? I like sets! Full sets Module! #585

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
bc8cb1a
improve inst/@sym/ainterval.m
latot Jan 26, 2017
8adba2e
improve inst/@sym/binterval.m
latot Jan 26, 2017
1ca789d
improve inst/@sym/boundary.m
latot Jan 26, 2017
0432c94
improve inst/@sym/complement.m
latot Jan 26, 2017
f7aaa18
improve inst/@sym/complexregion.m
latot Jan 26, 2017
ea687f7
improve inst/@sym/contains.m
latot Jan 26, 2017
48f1392
improve inst/@sym/imageset.m
latot Jan 26, 2017
c4f5d14
improve inst/@sym/infimum.m
latot Jan 26, 2017
bd7aa6f
improve inst/@sym/iscomplement.m
latot Jan 26, 2017
21fba6e
improve inst/@sym/isdisjoint.m
latot Jan 26, 2017
6afe6ec
improve inst/@sym/isemptyset.m
latot Jan 26, 2017
f4ea2ba
improve inst/@sym/isintersection.m
latot Jan 26, 2017
f9275ef
improve inst/@sym/isleftopen.m
latot Jan 26, 2017
0bde17b
improve inst/@sym/isleftunbounded.m
latot Jan 26, 2017
8211f68
improve inst/@sym/ispolar.m
latot Jan 26, 2017
8d2e67a
improve inst/@sym/ispropersubset.m
latot Jan 26, 2017
504e490
improve inst/@sym/ispropersuperset.m
latot Jan 26, 2017
e88914c
improve inst/@sym/isrightopen.m
latot Jan 26, 2017
4b79f56
improve inst/@sym/isrightunbounded.m
latot Jan 26, 2017
0b33991
improve inst/@sym/issubset.m
latot Jan 26, 2017
b3dc9ca
improve inst/@sym/issuperset.m
latot Jan 26, 2017
7c8e22e
improve inst/@sym/isuniversalset.m
latot Jan 26, 2017
b628130
improve inst/@sym/measure.m
latot Jan 26, 2017
a5678f5
improve inst/@sym/normalizethetaset.m
latot Jan 26, 2017
187a14c
improve inst/@sym/point.m
latot Jan 26, 2017
31d984c
improve inst/@sym/powerset.m
latot Jan 26, 2017
4b4f6d1
improve inst/@sym/productset.m
latot Jan 26, 2017
02e356a
improve inst/@sym/psets.m
latot Jan 26, 2017
a40c5cd
improve inst/@sym/rangeset.m
latot Jan 26, 2017
3a0e1ef
improve inst/@sym/reversed.m
latot Jan 26, 2017
4a7a4c4
improve inst/@sym/sets.m
latot Jan 26, 2017
ea86f00
improve inst/@sym/supremum.m
latot Jan 26, 2017
38a19ad
improve inst/domain.m
latot Jan 26, 2017
14d4008
fix tests
latot Jan 26, 2017
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
65 changes: 65 additions & 0 deletions inst/@sym/ainterval.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
%% Copyright (C) 2017 Lagu
%%
%% This file is part of OctSymPy.
%%
%% OctSymPy is free software; you can redistribute it and/or modify
%% it under the terms of the GNU General Public License as published
%% by the Free Software Foundation; either version 3 of the License,
%% or (at your option) any later version.
%%
%% This software is distributed in the hope that it will be useful,
%% but WITHOUT ANY WARRANTY; without even the implied warranty
%% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
%% the GNU General Public License for more details.
%%
%% You should have received a copy of the GNU General Public
%% License along with this software; see the file COPYING.
%% If not, see <http://www.gnu.org/licenses/>.

%% -*- texinfo -*-
%% @documentencoding UTF-8
%% @defmethod @@sym ainterval (@var{x})
%% Return the union of intervals of x when, @var{x} is in rectangular form
%% or the union of intervals of r when self is in polar form.
Copy link
Collaborator

Choose a reason for hiding this comment

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

First line need to fit on one line (its used for lookfor).

%%
%% Example:
%% @example
%% @group
%% a = interval (sym (2), 3);
%% b = interval (sym (4), 5);
%% ainterval (complexregion (a * b))
%% @result{} ans = (sym) [2, 3]
%% @end group
%% @end example
%%
%% @example
%% @group
%% c = interval (sym (1), 7);
%% ainterval (complexregion (a * b + b * c))
%% @result{} ans = (sym) [2, 3] ∪ [4, 5]
%% @end group
%% @end example
%%
%% @end defmethod


function y = ainterval(x)
if (nargin ~= 1)
print_usage ();
end
y = elementwise_op ('lambda x: x.a_interval', sym (x));
end


%!test
%! a = interval (sym (1), 2);
%! b = interval (sym (4), 5);
%! k = ainterval (complexregion (a * b));
%! assert (isequal (k, a))

%!test
%! a = interval (sym (1), 2);
%! b = interval (sym (4), 5);
%! c = interval (sym (-3), 2);
%! k = ainterval (complexregion (a * b + b * c));
%! assert (isequal (k, a + b))
65 changes: 65 additions & 0 deletions inst/@sym/binterval.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
%% Copyright (C) 2017 Lagu
%%
%% This file is part of OctSymPy.
%%
%% OctSymPy is free software; you can redistribute it and/or modify
%% it under the terms of the GNU General Public License as published
%% by the Free Software Foundation; either version 3 of the License,
%% or (at your option) any later version.
%%
%% This software is distributed in the hope that it will be useful,
%% but WITHOUT ANY WARRANTY; without even the implied warranty
%% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
%% the GNU General Public License for more details.
%%
%% You should have received a copy of the GNU General Public
%% License along with this software; see the file COPYING.
%% If not, see <http://www.gnu.org/licenses/>.

%% -*- texinfo -*-
%% @documentencoding UTF-8
%% @defmethod @@sym binterval (@var{x})
%% Return the union of intervals of y when, @var{x} is in rectangular form
%% or the union of intervals of theta when self is in polar form.
%%
%% Example:
%% @example
%% @group
%% a = interval (sym (2), 3);
%% b = interval (sym (4), 5);
%% binterval (complexregion (a * b))
%% @result{} ans = (sym) [4, 5]
%% @end group
%% @end example
%%
%% @example
%% @group
%% c = interval (sym (1), 7);
%% binterval (complexregion (a * b + b * c))
%% @result{} ans = (sym) [1, 7]
%% @end group
%% @end example
%%
%% @end defmethod


function y = binterval(x)
if (nargin ~= 1)
print_usage ();
end
y = elementwise_op ('lambda x: x.b_interval', sym (x));
end


%!test
%! a = interval (sym (1), 2);
%! b = interval (sym (4), 5);
%! k = binterval (complexregion (a * b));
%! assert (isequal (k, b))

%!test
%! a = interval (sym (1), 2);
%! b = interval (sym (4), 5);
%! c = interval (sym (-3), 2);
%! k = binterval (complexregion (a * b + b * c));
%! assert (isequal (k, b + c))
48 changes: 48 additions & 0 deletions inst/@sym/boundary.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
%% Copyright (C) 2017 Lagu
%%
%% This file is part of OctSymPy.
%%
%% OctSymPy is free software; you can redistribute it and/or modify
%% it under the terms of the GNU General Public License as published
%% by the Free Software Foundation; either version 3 of the License,
%% or (at your option) any later version.
%%
%% This software is distributed in the hope that it will be useful,
%% but WITHOUT ANY WARRANTY; without even the implied warranty
%% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
%% the GNU General Public License for more details.
%%
%% You should have received a copy of the GNU General Public
%% License along with this software; see the file COPYING.
%% If not, see <http://www.gnu.org/licenses/>.

%% -*- texinfo -*-
%% @documentencoding UTF-8
%% @defmethod @@sym boundary (@var{x})
%% The boundary or frontier of a set.
%%
%% Example:
%% @example
%% @group
%% a = interval (sym (1), 2);
%% b = interval (sym (5), 8);
%% boundary (a + b)
%% @result{} ans = (sym) @{1, 2, 5, 8@}
%% @end group
%% @end example
%%
%% @end defmethod


function y = boundary(x)
if (nargin ~= 1)
print_usage ();
end
y = elementwise_op ('lambda x: x.boundary', sym (x));
end


%!test
%! a = interval (sym (0), 1);
%! b = interval (sym (0), 1, true, false);
%! assert( isequal( boundary (a), boundary (b)))
Copy link
Collaborator

Choose a reason for hiding this comment

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

I know I've been very sloppy in the past, but for new code, let's try to use core Octave style (except for sym()).

55 changes: 55 additions & 0 deletions inst/@sym/complement.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
%% Copyright (C) 2017 Lagu
%%
%% This file is part of OctSymPy.
%%
%% OctSymPy is free software; you can redistribute it and/or modify
%% it under the terms of the GNU General Public License as published
%% by the Free Software Foundation; either version 3 of the License,
%% or (at your option) any later version.
%%
%% This software is distributed in the hope that it will be useful,
%% but WITHOUT ANY WARRANTY; without even the implied warranty
%% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
%% the GNU General Public License for more details.
%%
%% You should have received a copy of the GNU General Public
%% License along with this software; see the file COPYING.
%% If not, see <http://www.gnu.org/licenses/>.

%% -*- texinfo -*-
%% @documentencoding UTF-8
%% @defmethod @@sym complement (@var{x}, @var{y})
%% The complement of @var{x} with @var{y} as Universe.
%%
%% Example:
%% @example
%% @group
%% a = interval (sym (0), 10);
%% b = interval (sym (4), 6);
%% a - b
%% @result{} ans = (sym) [0, 4) ∪ (6, 10]
%% @end group
%% @end example
%% @example
%% @group
%% complement (b, a)
%% @result{} ans = (sym) [0, 4) ∪ (6, 10]
%% @end group
%% @end example
%%
%% @end defmethod


function y = complement(x, y)
if (nargin ~= 2)
print_usage ();
end
y = elementwise_op ('lambda x, y: x.complement(y)', sym (x), sym (y));
end


%!test
%! R = domain ('Reals');
%! a = interval (sym (-1), 1);
%! b = interval (sym (-inf), -1, true, true) + interval (sym (1), inf, true, true);
%! assert (isequal (complement (a, R), b))
63 changes: 63 additions & 0 deletions inst/@sym/complexregion.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
%% Copyright (C) 2017 Lagu
%%
%% This file is part of OctSymPy.
%%
%% OctSymPy is free software; you can redistribute it and/or modify
%% it under the terms of the GNU General Public License as published
%% by the Free Software Foundation; either version 3 of the License,
%% or (at your option) any later version.
%%
%% This software is distributed in the hope that it will be useful,
%% but WITHOUT ANY WARRANTY; without even the implied warranty
%% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
%% the GNU General Public License for more details.
%%
%% You should have received a copy of the GNU General Public
%% License along with this software; see the file COPYING.
%% If not, see <http://www.gnu.org/licenses/>.

%% -*- texinfo -*-
%% @documentencoding UTF-8
%% @defmethod @@sym complexregion (@var{x}, @var{y})
Copy link
Collaborator

Choose a reason for hiding this comment

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

y should be called something else like @var{polar}. And please list both ways of calling it:

@defmethod  @@sym complexregion (@var{x})
@defmethodx @@sym complexregion (@var{x}, @var{polar})

%% Represents the Set of all Complex Numbers.
%% It can represent a region of Complex Plane in
Copy link
Collaborator

Choose a reason for hiding this comment

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

blank line between the "lookfor" and the rest of the body. But this looks wrong? Should it represent all complex numbers if no arguments are passed or what does the lookfor summary line mean?

%% both the standard forms Polar and Rectangular coordinates.
%% Where @var{x} are the interval and if @var{y} is true
%% you will get the polar form, if is not specified or is false
%% it will be constructed in rectangular form.
%%
%% Example for rectangular form:
%% @example
%% @group
%% a = interval (sym (0), 2);
%% b = interval (sym (5), 7);
%% complexregion (a * b)
%% @result{} ans = (sym) @{x + y⋅ⅈ | x, y ∊ [0, 2] × [5, 7]@}
%% @end group
%% @end example
%%
%% Example for polar form:
%% @example
%% @group
%% a = interval (sym (1), 2);
%% b = interval (sym (0), sym (pi) * 2);
%% complexregion (a * b, true)
%% @result{} ans = (sym) @{r⋅(ⅈ⋅sin(θ) + cos(θ)) | r, θ ∊ [1, 2] × [0, 2⋅π)@}
%% @end group
%% @end example
%%
%% @end defmethod


function y = complexregion(x, y)
if (nargin > 2)
print_usage ();
elseif nargin == 1
y = false;
end
y = elementwise_op ('lambda x, y: ComplexRegion(x, polar=y)', sym (x), logical (y));
end


%% This function is tested in @sym/ainterval, @sym/binterval
%% @sym/ispolar, @sym/psets, @sym/sets and @sym/normalizethetaset
Copy link
Collaborator

Choose a reason for hiding this comment

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

add an %! assert true or something here too so automated checks don't flag this as untested.

50 changes: 50 additions & 0 deletions inst/@sym/contains.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
%% Copyright (C) 2017 Lagu
%%
%% This file is part of OctSymPy.
%%
%% OctSymPy is free software; you can redistribute it and/or modify
%% it under the terms of the GNU General Public License as published
%% by the Free Software Foundation; either version 3 of the License,
%% or (at your option) any later version.
%%
%% This software is distributed in the hope that it will be useful,
%% but WITHOUT ANY WARRANTY; without even the implied warranty
%% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
%% the GNU General Public License for more details.
%%
%% You should have received a copy of the GNU General Public
%% License along with this software; see the file COPYING.
%% If not, see <http://www.gnu.org/licenses/>.

%% -*- texinfo -*-
%% @documentencoding UTF-8
%% @defmethod @@sym contains (@var{x}, @var{y})
%% Returns True if @var{x} is contained in @var{y} as an element.
%%
%% Example:
%% @example
%% @group
%% a = interval (sym (0), 10);
%% contains (5, a)
%% @result{} ans = (sym) True
%% @end group
%% @end example
%%
%% @end defmethod


function y = contains(x, y)
if (nargin ~= 2)
print_usage ();
end
y = elementwise_op ('lambda x, y: x in y', sym (x), sym (y));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is x in y the correct way sympy to test for something being in a set? What if y is a list? How is this different from ismember?

end


%!test
%! a = interval (sym (0), 10);
%! assert (logical (~contains (-1, a)))

%!test
%! a = interval (sym (0), 10);
%! assert (logical (contains (5, a)))
Loading