diff --git a/inst/@sym/ainterval.m b/inst/@sym/ainterval.m new file mode 100644 index 000000000..085b91b49 --- /dev/null +++ b/inst/@sym/ainterval.m @@ -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 . + +%% -*- 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. +%% +%% 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)) diff --git a/inst/@sym/binterval.m b/inst/@sym/binterval.m new file mode 100644 index 000000000..d08f48e36 --- /dev/null +++ b/inst/@sym/binterval.m @@ -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 . + +%% -*- 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)) diff --git a/inst/@sym/boundary.m b/inst/@sym/boundary.m new file mode 100644 index 000000000..7f920e6fa --- /dev/null +++ b/inst/@sym/boundary.m @@ -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 . + +%% -*- 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))) diff --git a/inst/@sym/complement.m b/inst/@sym/complement.m new file mode 100644 index 000000000..036deacbe --- /dev/null +++ b/inst/@sym/complement.m @@ -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 . + +%% -*- 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)) diff --git a/inst/@sym/complexregion.m b/inst/@sym/complexregion.m new file mode 100644 index 000000000..b568f3052 --- /dev/null +++ b/inst/@sym/complexregion.m @@ -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 . + +%% -*- texinfo -*- +%% @documentencoding UTF-8 +%% @defmethod @@sym complexregion (@var{x}, @var{y}) +%% Represents the Set of all Complex Numbers. +%% It can represent a region of Complex Plane in +%% 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 diff --git a/inst/@sym/contains.m b/inst/@sym/contains.m new file mode 100644 index 000000000..50837d07e --- /dev/null +++ b/inst/@sym/contains.m @@ -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 . + +%% -*- 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)); +end + + +%!test +%! a = interval (sym (0), 10); +%! assert (logical (~contains (-1, a))) + +%!test +%! a = interval (sym (0), 10); +%! assert (logical (contains (5, a))) diff --git a/inst/@sym/imageset.m b/inst/@sym/imageset.m new file mode 100644 index 000000000..2351623c6 --- /dev/null +++ b/inst/@sym/imageset.m @@ -0,0 +1,82 @@ +%% 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 . + +%% -*- texinfo -*- +%% @documentencoding UTF-8 +%% @defmethod @@sym imageset (@var{f}, @var{d}) +%% @defmethodx @@sym imageset (@var{f}, @var{x}, @var{d}) +%% Image of a set under a mathematical function. +%% The imageset is created in the function @var{f} in the variable +%% @var{x} on the domain @var{d}, if @var{x} don't is passed will +%% be used the first var detected for symvar. +%% +%% Example: +%% @example +%% @group +%% syms x +%% f = x^2; +%% imageset (f, x, domain ('Complexes')) +%% @result{} ans = (sym) +%% ⎧ 2 ⎫ +%% ⎨x | x ∊ ℂ⎬ +%% ⎩ ⎭ +%% @end group +%% @end example +%% +%% @example +%% @group +%% syms y +%% f = x^exp(y); +%% imageset (f, [x y], domain ('Naturals0')) +%% @result{} ans = (sym 1×2 matrix) +%% ⎡⎧ ⎛ y⎞ ⎫ ⎧ ⎛ y⎞ ⎫⎤ +%% ⎢⎨ ⎝ℯ ⎠ ⎬ ⎨ ⎝ℯ ⎠ ⎬⎥ +%% ⎣⎩x | x ∊ ℕ₀⎭ ⎩x | y ∊ ℕ₀⎭⎦ +%% @end group +%% @end example +%% +%% @end defmethod + + +function y = imageset(f, a, b) + + if nargin == 1 || nargin > 3 + print_usage (); + elseif nargin == 2 + b = a; + b = symvar (f, 1); + if isempty (b) + error ('The function must be expression with a symbol.'); + end + end + y = elementwise_op ('lambda f, a, b: imageset(Lambda(a, f), b)', sym (f), sym (a), sym (b)); + +end + + +%!test +%! syms x +%! b = interval (sym (0), 4); +%! a = imageset (x^2, x, interval (sym (0), 2)); +%! assert (isequal (a, b)) + +%!test +%! syms x +%! b = interval (sym (0), 20); +%! a = imageset(x*2, x, interval (sym (0), 10)); +%! assert (isequal (a, b)) diff --git a/inst/@sym/infimum.m b/inst/@sym/infimum.m new file mode 100644 index 000000000..6961296dc --- /dev/null +++ b/inst/@sym/infimum.m @@ -0,0 +1,51 @@ +%% 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 . + +%% -*- texinfo -*- +%% @documentencoding UTF-8 +%% @defmethod @@sym infimum (@var{x}) +%% The infimum of @var{x}. +%% +%% Example: +%% @example +%% @group +%% a = interval (sym (1), 2); +%% infimum (a) +%% @result{} ans = (sym) 1 +%% @end group +%% @end example +%% +%% @end defmethod + + +function y = infimum(x) + if (nargin ~= 1) + print_usage (); + end + y = elementwise_op ('lambda x: x.inf', sym(x)); +end + + +%!test +%! a = interval (sym (0), 1); +%! assert( isequal( infimum (a), sym (0))) + +%!test +%! a = interval (sym (-1), 1); +%! b = interval (sym (2), 3); +%! assert (isequal (infimum (a+b), sym (-1))) diff --git a/inst/@sym/iscomplement.m b/inst/@sym/iscomplement.m new file mode 100644 index 000000000..cd65e0c7b --- /dev/null +++ b/inst/@sym/iscomplement.m @@ -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 . + +%% -*- texinfo -*- +%% @documentencoding UTF-8 +%% @defmethod @@sym iscomplement (@var{x}) +%% Retrurn True if @var{x} is complement. +%% +%% Example: +%% @example +%% @group +%% a = domain ('Reals'); +%% b = domain ('Complexes'); +%% iscomplement (b - a) +%% @result{} ans = (sym) True +%% @end group +%% @end example +%% +%% @end defmethod + + +function y = iscomplement(x) + if (nargin ~= 1) + print_usage (); + end + y = elementwise_op ('lambda x: x.is_Complement', sym (x)); +end + + +%!test +%! a = domain ('Reals'); +%! b = domain ('Integers'); +%! assert (logical (iscomplement (a - b))) diff --git a/inst/@sym/isdisjoint.m b/inst/@sym/isdisjoint.m new file mode 100644 index 000000000..a5a711dae --- /dev/null +++ b/inst/@sym/isdisjoint.m @@ -0,0 +1,53 @@ +%% 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 . + +%% -*- texinfo -*- +%% @documentencoding UTF-8 +%% @defmethod @@sym isdisjoint (@var{x}, @var{y}) +%% Returns True if @var{x} and @var{y} are disjoint. +%% +%% Example: +%% @example +%% @group +%% a = interval (sym (0), 10); +%% b = interval (sym (11), 15); +%% isdisjoint (a, b) +%% @result{} ans = (sym) True +%% @end group +%% @end example +%% +%% @end defmethod + + +function y = isdisjoint(x, y) + if (nargin ~= 2) + print_usage (); + end + y = elementwise_op ('lambda x, y: x.is_disjoint(y)', sym (x), sym (y)); +end + + +%!test +%! a = interval (sym (0), 2); +%! b = interval (sym (1), 2); +%! assert (logical (~isdisjoint (a, b))) + +%!test +%! a = interval (sym (0), 2); +%! b = interval (sym (3), 4); +%! assert (logical (isdisjoint (a, b))) diff --git a/inst/@sym/isemptyset.m b/inst/@sym/isemptyset.m new file mode 100644 index 000000000..55509d463 --- /dev/null +++ b/inst/@sym/isemptyset.m @@ -0,0 +1,64 @@ +%% 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 . + +%% -*- texinfo -*- +%% @documentencoding UTF-8 +%% @defmethod @@sym isemptyset (@var{x}) +%% Return True if @var{x} is EmptySet. +%% +%% Example: +%% @example +%% @group +%% isemptyset (domain ('EmptySet')) +%% @result{} ans = (sym) True +%% @end group +%% @end example +%% +%% @example +%% @group +%% isemptyset (domain ('Complexes')) +%% @result{} ans = (sym) None +%% @end group +%% @end example +%% +%% @end defmethod + + +function y = isemptyset(x) + if (nargin ~= 1) + print_usage (); + end + y = elementwise_op ('lambda x: x.is_EmptySet', sym (x)); +end + + +%!test +%! a = isemptyset (interval (sym (0), 1)); +%! if isa (a, 'sym') +%! assert (isNone (a)) +%! else +%! assert (~logical (a)); +%! end + +%!test +%! a = isemptyset (domain ('EmptySet')); +%! if isa (a, 'sym') +%! assert (~isNone (a)) +%! else +%! assert (logical (a)); +%! end diff --git a/inst/@sym/isintersection.m b/inst/@sym/isintersection.m new file mode 100644 index 000000000..f08b012d4 --- /dev/null +++ b/inst/@sym/isintersection.m @@ -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 . + +%% -*- texinfo -*- +%% @documentencoding UTF-8 +%% @defmethod @@sym isintersection (@var{x}) +%% Return True if @var{x} is intersection. +%% +%% Example: +%% @example +%% @group +%% syms x +%% a = interval (x, 1); +%% b = interval (sym (-1), 3); +%% isintersection (intersect (a, b)) +%% @result{} ans = (sym) True +%% @end group +%% @end example +%% +%% @end defmethod + + +function y = isintersection(x) + if (nargin ~= 1) + print_usage (); + end + y = elementwise_op ('lambda x: x.is_Intersection', sym (x)); +end + + +%!test +%! syms x +%! a = interval(sym(0), x^2); +%! b = interval(x, 1); +%! c = isintersection (intersect (a, b)); +%! if isa(c, 'sym') +%! assert (~isNone (c)) +%! else +%! assert (logical (c)); +%! end + +%!test +%! a = interval (sym (0), 4); +%! b = interval (2, sym (8)); +%! c = isintersection (intersect (a, b)); +%! if isa (c, 'sym') +%! assert (isNone (c)) +%! else +%! assert (~logical (c)); +%! end diff --git a/inst/@sym/isleftopen.m b/inst/@sym/isleftopen.m new file mode 100644 index 000000000..7d35e47c1 --- /dev/null +++ b/inst/@sym/isleftopen.m @@ -0,0 +1,56 @@ +%% 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 . + +%% -*- texinfo -*- +%% @documentencoding UTF-8 +%% @defmethod @@sym isleftopen (@var{x}) +%% True if @var{x} is left-open. +%% +%% Example: +%% @example +%% @group +%% isleftopen (interval (sym (0), 1, true)) +%% @result{} ans = (sym) True +%% @end group +%% @end example +%% +%% @example +%% @group +%% isleftopen (interval (sym(0), 1, false)) +%% @result{} ans = (sym) False +%% @end group +%% @end example +%% +%% @end defmethod + + +function y = isleftopen(x) + if (nargin ~= 1) + print_usage (); + end + y = elementwise_op ('lambda x: x.left_open', sym (x)); +end + + +%!test +%! a = interval (sym (0), 1, true); +%! assert (logical (isleftopen (a))) + +%!test +%! b = interval (sym (0), 1, false); +%! assert (logical (~isleftopen (b))) diff --git a/inst/@sym/isleftunbounded.m b/inst/@sym/isleftunbounded.m new file mode 100644 index 000000000..444ba6274 --- /dev/null +++ b/inst/@sym/isleftunbounded.m @@ -0,0 +1,58 @@ +%% 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 . + +%% -*- texinfo -*- +%% @documentencoding UTF-8 +%% @defmethod @@sym isleftunbounded (@var{x}) +%% Return True if the left endpoint is negative infinity. +%% +%% Example: +%% @example +%% @group +%% a = interval (sym (-inf), 0); +%% isleftunbounded (a) +%% @result{} ans = (sym) True +%% @end group +%% @end example +%% +%% @example +%% @group +%% a = interval (sym (0), inf); +%% isleftunbounded (a) +%% @result{} ans = (sym) False +%% @end group +%% @end example +%% +%% @end defmethod + + +function y = isleftunbounded(x) + if (nargin ~= 1) + print_usage (); + end + y = elementwise_op ('lambda x: x.is_left_unbounded', sym (x)); +end + + +%!test +%! a = interval (sym (-inf), 1); +%! assert (logical (isleftunbounded (a))) + +%!test +%! a = interval (sym (0), inf); +%! assert (logical (~isleftunbounded (a))) diff --git a/inst/@sym/ispolar.m b/inst/@sym/ispolar.m new file mode 100644 index 000000000..02de11574 --- /dev/null +++ b/inst/@sym/ispolar.m @@ -0,0 +1,60 @@ +%% 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 . + +%% -*- texinfo -*- +%% @documentencoding UTF-8 +%% @defmethod @@sym ispolar (@var{x}) +%% Returns True if @var{x} is in polar form. +%% +%% Example: +%% @example +%% @group +%% a = interval (sym (2), 3); +%% b = interval (sym (4), sym (pi)); +%% ispolar (complexregion (a * b)) +%% @result{} ans = (sym) False +%% @end group +%% @end example +%% +%% @example +%% @group +%% ispolar (complexregion (a * b, true)) +%% @result{} ans = (sym) True +%% @end group +%% @end example +%% +%% @end defmethod + + +function y = ispolar(x) + if (nargin ~= 1) + print_usage (); + end + y = elementwise_op ('lambda x: x.polar', sym (x)); +end + + +%!test +%! a = interval (sym (1), 2); +%! b = interval (sym (4), 5); +%! assert (logical (~ispolar (complexregion (a * b)))) + +%!test +%! a = interval (sym (1), 2); +%! b = interval (sym (4), sym (pi)); +%! assert (logical (ispolar (complexregion (a * b, true)))) diff --git a/inst/@sym/ispropersubset.m b/inst/@sym/ispropersubset.m new file mode 100644 index 000000000..a1a3c1938 --- /dev/null +++ b/inst/@sym/ispropersubset.m @@ -0,0 +1,52 @@ +%% 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 . + +%% -*- texinfo -*- +%% @documentencoding UTF-8 +%% @defmethod @@sym ispropersubset (@var{x}, @var{y}) +%% Returns True if @var{x} is a proper subset of @var{y}. +%% +%% Example: +%% @example +%% @group +%% a = interval (sym (0), sym (1)/2); +%% b = interval(sym (0), 1); +%% ispropersubset (a, b) +%% @result{} ans = (sym) True +%% @end group +%% @end example +%% +%% @end defmethod + + +function y = ispropersubset(x, y) + if (nargin ~= 2) + print_usage (); + end + y = elementwise_op ('lambda x, y: x.is_proper_subset(y)', sym (x), sym (y)); +end + + +%!test +%! a = interval (sym (0), sym (1)/2); +%! b = interval (sym (0), 1); +%! assert (logical (ispropersubset(a, b))) + +%!test +%! a = interval(sym(0), 1); +%! assert (logical (~ispropersubset (a, a))) diff --git a/inst/@sym/ispropersuperset.m b/inst/@sym/ispropersuperset.m new file mode 100644 index 000000000..c01b84035 --- /dev/null +++ b/inst/@sym/ispropersuperset.m @@ -0,0 +1,52 @@ +%% 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 . + +%% -*- texinfo -*- +%% @documentencoding UTF-8 +%% @defmethod @@sym ispropersubset (@var{x}, @var{y}) +%% Returns True if @var{x} is a proper superset of @var{y}. +%% +%% Example: +%% @example +%% @group +%% a = interval (sym (0), 1); +%% b = interval (sym (0), sym (1)/2); +%% ispropersuperset (a, b) +%% @result{} ans = (sym) True +%% @end group +%% @end example +%% +%% @end defmethod + + +function y = ispropersuperset(x, y) + if (nargin ~= 2) + print_usage (); + end + y = elementwise_op ('lambda x, y: x.is_proper_superset(y)', sym (x), sym (y)); +end + + +%!test +%! a = interval (sym (0), sym (1)/2); +%! b = interval (sym (0), 1); +%! assert (logical (~ispropersuperset (a, b))) + +%!test +%! a = interval (sym (0), 1); +%! assert (logical (~ispropersuperset (a, a))) diff --git a/inst/@sym/isrightopen.m b/inst/@sym/isrightopen.m new file mode 100644 index 000000000..606919618 --- /dev/null +++ b/inst/@sym/isrightopen.m @@ -0,0 +1,56 @@ +%% 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 . + +%% -*- texinfo -*- +%% @documentencoding UTF-8 +%% @defmethod @@sym isrightopen (@var{x}) +%% True if @var{x} is right-open. +%% +%% Example: +%% @example +%% @group +%% isrightopen (interval (sym (0), 1, true, true)) +%% @result{} ans = (sym) True +%% @end group +%% @end example +%% +%% @example +%% @group +%% isrightopen (interval (sym (0), 1, false, false)) +%% @result{} ans = (sym) False +%% @end group +%% @end example +%% +%% @end defmethod + + +function y = isrightopen(x) + if (nargin ~= 1) + print_usage (); + end + y = elementwise_op ('lambda x: x.right_open', sym (x)); +end + + +%!test +%! a = interval (sym (0), 1, true, true); +%! assert (logical (isrightopen (a))) + +%!test +%! b = interval (sym (0), 1, false, false); +%! assert (logical (~isrightopen (b))) diff --git a/inst/@sym/isrightunbounded.m b/inst/@sym/isrightunbounded.m new file mode 100644 index 000000000..dd56c6593 --- /dev/null +++ b/inst/@sym/isrightunbounded.m @@ -0,0 +1,57 @@ +%% 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 . + +%% -*- texinfo -*- +%% @documentencoding UTF-8 +%% @defmethod @@sym isrightunbounded (@var{x}) +%% Return True if the right endpoint is positive infinity. +%% +%% Example: +%% @example +%% @group +%% a = interval (0, sym (inf)); +%% isrightunbounded (a) +%% @result{} ans = (sym) True +%% @end group +%% @end example +%% +%% @group +%% a = interval (-inf, sym (0)); +%% isrightunbounded (a) +%% @result{} ans = (sym) True +%% @end group +%% @end example +%% +%% @end defmethod + + +function y = isrightunbounded(x) + if (nargin ~= 1) + print_usage (); + end + y = elementwise_op ('lambda x: x.is_right_unbounded', sym (x)); +end + + +%!test +%! a = interval (sym (-inf), 1); +%! assert (logical (~isrightunbounded (a))) + +%!test +%! a = interval (sym (0), inf); +%! assert (logical (isrightunbounded (a))) diff --git a/inst/@sym/issubset.m b/inst/@sym/issubset.m new file mode 100644 index 000000000..5b9230d7b --- /dev/null +++ b/inst/@sym/issubset.m @@ -0,0 +1,53 @@ +%% 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 . + +%% -*- texinfo -*- +%% @documentencoding UTF-8 +%% @defmethod @@sym issubset (@var{x}, @var{y}) +%% Returns True if @var{x} is a subset of @var{y}. +%% +%% Example: +%% @example +%% @group +%% a = interval (sym (0), sym (1)/2); +%% b = interval (sym (0), 1); +%% issubset (a, b) +%% @result{} ans = (sym) True +%% @end group +%% @end example +%% +%% @end defmethod + + +function y = issubset(x, y) + if (nargin ~= 2) + print_usage (); + end + y = elementwise_op ('lambda x, y: x.is_subset(y)', sym (x), sym (y)); +end + + +%!test +%! a = interval (sym (0), sym (1)/2); +%! b = interval (sym (0), 1); +%! assert (logical (issubset (a, b))) + +%!test +%! a = interval (sym (0), 1); +%! b = interval (sym (0), 1, true); +%! assert (logical (~issubset (a, b))) diff --git a/inst/@sym/issuperset.m b/inst/@sym/issuperset.m new file mode 100644 index 000000000..4530d92da --- /dev/null +++ b/inst/@sym/issuperset.m @@ -0,0 +1,53 @@ +%% 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 . + +%% -*- texinfo -*- +%% @documentencoding UTF-8 +%% @defmethod @@sym issuperset (@var{x}, @var{y}) +%% Returns True if @var{x} is a superset of @var{y}. +%% +%% Example: +%% @example +%% @group +%% a = interval (sym (0), 1); +%% b = interval (sym (0), 1, true); +%% issuperset (a, b) +%% @result{} ans = (sym) True +%% @end group +%% @end example +%% +%% @end defmethod + + +function y = issuperset(x, y) + if (nargin ~= 2) + print_usage (); + end + y = elementwise_op ('lambda x, y: x.is_superset(y)', sym (x), sym (y)); +end + + +%!test +%! a = interval (sym (0), sym (1)/2); +%! b = interval (sym (0), 1); +%! assert (logical (~issuperset (a, b))) + +%!test +%! a = interval (sym (0), 1); +%! b = interval (sym (0), 1, true); +%! assert (logical (issuperset (a, b))) diff --git a/inst/@sym/isuniversalset.m b/inst/@sym/isuniversalset.m new file mode 100644 index 000000000..908b7dd64 --- /dev/null +++ b/inst/@sym/isuniversalset.m @@ -0,0 +1,64 @@ +%% 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 . + +%% -*- texinfo -*- +%% @documentencoding UTF-8 +%% @defmethod @@sym isuniversalset (@var{x}) +%% Return True if @var{x} is UniversalSet. +%% +%% Example: +%% @example +%% @group +%% isuniversalset (domain ('UniversalSet')) +%% @result{} ans = (sym) True +%% @end group +%% @end example +%% +%% @example +%% @group +%% isuniversalset (domain ('Reals')) +%% @result{} ans = (sym) None +%% @end group +%% @end example +%% +%% @end defmethod + + +function y = isuniversalset(x) + if (nargin ~= 1) + print_usage (); + end + y = elementwise_op ('lambda x: x.is_UniversalSet', sym (x)); +end + + +%!test +%! a = isuniversalset (interval (sym (0), 1)); +%! if isa (a, 'sym') +%! assert (isNone (a)) +%! else +%! assert (~logical (a)); +%! end + +%!test +%! a = isuniversalset (domain ('UniversalSet')); +%! if isa (a, 'sym') +%! assert (~isNone (a)) +%! else +%! assert (logical (a)); +%! end diff --git a/inst/@sym/measure.m b/inst/@sym/measure.m new file mode 100644 index 000000000..c69229bcb --- /dev/null +++ b/inst/@sym/measure.m @@ -0,0 +1,52 @@ +%% 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 . + +%% -*- texinfo -*- +%% @documentencoding UTF-8 +%% @defmethod @@sym measure (@var{x}) +%% The (Lebesgue) measure of @var{x}. +%% +%% Example: +%% @example +%% @group +%% a = interval (sym (0), 1); +%% b = interval (sym (2), 3); +%% measure (a + b) +%% @result{} ans = (sym) 2 +%% @end group +%% @end example +%% +%% @end defmethod + + +function y = measure(x) + if (nargin ~= 1) + print_usage (); + end + y = elementwise_op ('lambda x: x.measure', sym (x)); +end + + +%!test +%! a = interval (sym (0), 1); +%! assert( isequal( measure (a), sym (1))) + +%!test +%! a = interval (sym (0), 1); +%! b = interval (sym (2), 3); +%! assert (isequal (measure (a + b), sym (2))) diff --git a/inst/@sym/normalizethetaset.m b/inst/@sym/normalizethetaset.m new file mode 100644 index 000000000..afb338400 --- /dev/null +++ b/inst/@sym/normalizethetaset.m @@ -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 . + +%% -*- texinfo -*- +%% @documentencoding UTF-8 +%% @defmethod @@sym normalizethetaset (@var{x}) +%% Normalize a Real Set thetatheta in the Interval [0, 2*pi). +%% It returns a normalized value of theta in the Set. +%% +%% Example: +%% @example +%% @group +%% normalizethetaset (interval (sym (pi) * 9 / 2, 5 * sym (pi))) +%% @result{} ans = (sym) +%% ⎡π ⎤ +%% ⎢─, π⎥ +%% ⎣2 ⎦ +%% @end group +%% @end example +%% +%% @end defmethod + + +function y = normalizethetaset(x) + if (nargin ~= 1) + print_usage (); + end + y = elementwise_op ('lambda x: normalize_theta_set(x)', sym (x)); +end + + +%!test +%! a = normalizethetaset (interval (sym (pi) * -3, sym (pi) / 2)); +%! b = interval (sym (0), 2 * sym (pi), false, true); +%! assert (isequal (a, b)) + +%!test +%! a = normalizethetaset (interval (-sym (pi) / 2, sym (pi) / 2)); +%! b = interval (sym (0), sym (pi) / 2) + interval (sym (pi) * 3 / 2, sym (pi) * 2, false, true); +%! assert (isequal (a, b)) diff --git a/inst/@sym/point.m b/inst/@sym/point.m new file mode 100644 index 000000000..09e4fefa3 --- /dev/null +++ b/inst/@sym/point.m @@ -0,0 +1,76 @@ +%% 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 . + +%% -*- texinfo -*- +%% @documentencoding UTF-8 +%% @defmethod @@sym point (@var{x}) +%% @defmethodx @@sym point (@var{x}, @var{y}) +%% @defmethodx @@sym point (@var{x}, @var{y}, @var{dor}) +%% Represent a point or a set of points. +%% The plus of two points is the concatenation of it. +%% +%% Example: +%% @example +%% @group +%% point (sym (1), 2) +%% @result{} ans = (sym) (1, 2) +%% @end group +%% @end example +%% +%% @example +%% @group +%% syms x +%% point (x, x^2) +%% @result{} ans = (sym) +%% ⎛ 2⎞ +%% ⎝x, x ⎠ +%% @end group +%% @end example +%% +%% Check if exist the point in a space: +%% @example +%% @group +%% space = interval (sym (0), 7) * interval (sym (4), 9); +%% p = point (sym (6), 7); +%% contains (p, space) +%% @result{} ans = (sym) True +%% @end group +%% @end example +%% +%% @end defmethod + + +function y = point(varargin) + varargin = cellfun(@sym, varargin, 'UniformOutput', false); + y = elementwise_op ('lambda x: S(tuple(x)) if len(x) > 1 else S(*x)', varargin); +end + + +%!test +%! a = point (sym (1)); +%! b = point (sym (-1)); +%! c = interval (sym (0), 3); +%! assert (logical (contains (a, c))) +%! assert (~logical (contains (b, c))) + +%!test +%! a = point (sym (2), 2); +%! b = point (sym (-1), 2); +%! c = interval (sym (0), 5) * finiteset (1, 2, 3); +%! assert (logical (contains (a, c))) +%! assert (~logical (contains (b, c))) diff --git a/inst/@sym/powerset.m b/inst/@sym/powerset.m new file mode 100644 index 000000000..af3b73a34 --- /dev/null +++ b/inst/@sym/powerset.m @@ -0,0 +1,53 @@ +%% 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 . + +%% -*- texinfo -*- +%% @documentencoding UTF-8 +%% @defmethod @@sym powerset (@var{x}) +%% Find the Power set of @var{x}. +%% +%% Example: +%% @example +%% @group +%% powerset (domain ('EmptySet')) +%% @result{} ans = (sym) @{∅@} +%% @end group +%% @end example +%% +%% @example +%% @group +%% powerset (finiteset (1, 2, 3)) +%% @result{} ans = (sym) @{∅, @{1@}, @{2@}, @{3@}, @{1, 2@}, @{1, 3@}, @{2, 3@}, @{1, 2, 3@}@} +%% @end group +%% @end example +%% +%% @end defmethod + + +function y = powerset(x) + if (nargin ~= 1) + print_usage (); + end + y = elementwise_op ('lambda x: x.powerset()', sym (x)); +end + + +%!test +%! a = finiteset (1, 2, 3, 4); +%! b = finiteset (4, 3, 2, 1); +%! assert (isAlways (powerset (a) == powerset (b))) diff --git a/inst/@sym/productset.m b/inst/@sym/productset.m new file mode 100644 index 000000000..81b178ad9 --- /dev/null +++ b/inst/@sym/productset.m @@ -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 . + +%% -*- texinfo -*- +%% @documentencoding UTF-8 +%% @defmethod @@sym productset (@var{x}, @var{y}) +%% Return the Cartesian Product of @var{x} with @var{y}. +%% +%% Example: +%% @example +%% @group +%% a = interval (sym (-1), 6); +%% b = interval (sym (-3), 2); +%% a * b +%% @result{} ans = (sym) [-1, 6] × [-3, 2] +%% @end group +%% @end example +%% @example +%% @group +%% productset (a, b) +%% @result{} ans = (sym) [-1, 6] × [-3, 2] +%% @end group +%% @end example +%% +%% @end defmethod + + +function y = productset(x, y) + if (nargin ~= 2) + print_usage (); + end + y = elementwise_op ('lambda x, y: ProductSet(x, y)', sym (x), sym (y)); +end diff --git a/inst/@sym/psets.m b/inst/@sym/psets.m new file mode 100644 index 000000000..0399e0453 --- /dev/null +++ b/inst/@sym/psets.m @@ -0,0 +1,78 @@ +%% 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 . + +%% -*- texinfo -*- +%% @documentencoding UTF-8 +%% @defmethod @@sym psets (@var{x}) +%% Return a cell of sets (ProductSets) input of the @var{x}. +%% +%% Example: +%% @example +%% @group +%% a = interval (sym (2), 3); +%% b = interval (sym (4), 5); +%% c = interval (sym (1), 7); +%% +%% psets (complexregion (a * b)) +%% @result{} ans = (sym) [2, 3] × [4, 5] +%% @end group +%% @end example +%% +%% @example +%% @group +%% psets (complexregion (a * b + b * c)) +%% @result{} ans = (sym 2×1 matrix) +%% ⎡[2, 3] × [4, 5]⎤ +%% ⎢ ⎥ +%% ⎣[4, 5] × [1, 7]⎦ +%% @end group +%% @end example +%% +%% @end defmethod + + +function varargout = psets(x) + if (nargin ~= 1) + print_usage (); + end + + out = python_cmd ('return Matrix(_ins[0].psets)', sym (x)); + + if nargout == 0 || nargout == 1 + varargout = {out}; + else + assert (~isequal (length (out), nargout), ['This only have ' num2str(length (out)) ' returns, please set the correct number of outputs']); + varargout = out; + end +end + + +%!test +%% a = interval (sym (1), 9); +%% b = interval (sym (4), 6); +%% sol = {a * b}; +%% r = psets (complexregion (a * b)); +%% assert (isequal (r, sol)) + +%!test +%% a = interval (sym (1), 9); +%% b = interval (sym (4), 6); +%% c = interval (sym (2), 3); +%% sol = {a * b; c * b}; +%% r = psets (complexregion (a * b + c * b)); +%% assert (isequal (r, sol)) diff --git a/inst/@sym/rangeset.m b/inst/@sym/rangeset.m new file mode 100644 index 000000000..011e00982 --- /dev/null +++ b/inst/@sym/rangeset.m @@ -0,0 +1,74 @@ +%% 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 . + +%% -*- texinfo -*- +%% @documentencoding UTF-8 +%% @defmethod @@sym rangeset (@var{stop}) +%% @defmethodx @@sym rangeset (@var{start}, @var{stop}) +%% @defmethodx @@sym rangeset (@var{start}, @var{stop}, @var{step}) +%% @defmethodx @@sym rangeset (@var{start}, @var{stop}, @var{step}, @var{list}) +%% Represents a range of integer from @var{start} to @var{stop} in @var{step} steps. +%% If you ignore some of this values it will takes this be default: +%% @var{start}: 0 +%% @var{stop} : 1 +%% @var{step} : 1 +%% +%% If you set @var{list} to 'list', this will return the list of values +%% instead the set representation. +%% +%% Example: +%% @example +%% @group +%% rangeset (sym (10), 0, -2) +%% @result{} ans = (sym) @{2, 4, …, 10@} +%% @end group +%% @end example +%% +%% @example +%% @group +%% rangeset (sym (0), 20, 3, 'list') +%% @result{} ans = (sym) [0 3 6 9 12 15 18] (1×7 matrix) +%% @end group +%% @end example +%% +%% @end defmethod + + +function y = rangeset(varargin) + if (nargin > 4 || nargin < 1) + print_usage (); + end + + %% Note, in Sympy 1.0 the negative steps produce a sorted + %% output, over 1.0 don't is sorted. + + if strcmp (varargin{nargin}, 'list') + varargin = cellfun(@sym, varargin, 'UniformOutput', false); + y = python_cmd ('return list(Range(*_ins)),', varargin{1:3}); + y = cell2sym (y); + else + varargin = cellfun(@sym, varargin, 'UniformOutput', false); + y = python_cmd ('return Range(*_ins),', varargin{:}); + end + +end + + +%!test +%! a = rangeset (sym (1), 5); +%! assert (logical (isemptyset (intersect (a, interval (sym (6), inf))))) diff --git a/inst/@sym/reversed.m b/inst/@sym/reversed.m new file mode 100644 index 000000000..0cbf42654 --- /dev/null +++ b/inst/@sym/reversed.m @@ -0,0 +1,49 @@ +%% 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 . + +%% -*- texinfo -*- +%% @documentencoding UTF-8 +%% @defmethod @@sym reversed (@var{x}) +%% Return an @var{x} Range in the opposite order. +%% +%% Example: +%% @example +%% @group +%% a = rangeset (sym (0), 10, 3); +%% reversed (a) % doctest: +SKIP +%% @result{} ans = (sym) @{9, 6, 3, 0@} +%% @end group +%% @end example +%% +%% @end defmethod + + +function y = reversed(x) + if (nargin ~= 1) + print_usage (); + end + y = elementwise_op ('lambda x: x.reversed', sym (x)); +end + + +%!test +%! if (python_cmd ('return Version(spver) > Version("1.0")')) +%! a = rangeset (sym (10), 1, -3); +%! b = reversed (reversed (a)); +%! assert (isequal (a, b)) +%! end diff --git a/inst/@sym/sets.m b/inst/@sym/sets.m new file mode 100644 index 000000000..5162e0543 --- /dev/null +++ b/inst/@sym/sets.m @@ -0,0 +1,68 @@ +%% 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 . + +%% -*- texinfo -*- +%% @documentencoding UTF-8 +%% @defmethod @@sym sets (@var{x}) +%% Return raw input sets of @var{x}. +%% +%% Example: +%% @example +%% @group +%% a = interval (sym (2), 3); +%% b = interval (sym (4), 5); +%% c = interval (sym (1), 7); +%% +%% sets (complexregion (a * b)) +%% @result{} ans = (sym) [2, 3] × [4, 5] +%% @end group +%% @end example +%% +%% @example +%% @group +%% sets (complexregion (a * b + b * c)) +%% @result{} ans = (sym) ([2, 3] × [4, 5]) ∪ ([4, 5] × [1, 7]) +%% @end group +%% @end example +%% +%% @end defmethod + + +function y = sets(x) + if (nargin ~= 1) + print_usage (); + end + + y = elementwise_op ('lambda x: x.sets', sym (x)); +end + + +%!test +%% a = interval (sym (1), 9); +%% b = interval (sym (4), 6); +%% sol = a * b; +%% r = sets (complexregion (a * b)); +%% assert (isequal (r, sol)) + +%!test +%% a = interval (sym (1), 9); +%% b = interval (sym (4), 6); +%% c = interval (sym (2), 3); +%% sol = a * b + c * b; +%% r = sets (complexregion (a * b + c * b)); +%% assert (isequal (r, sol)) diff --git a/inst/@sym/supremum.m b/inst/@sym/supremum.m new file mode 100644 index 000000000..db6786b02 --- /dev/null +++ b/inst/@sym/supremum.m @@ -0,0 +1,51 @@ +%% 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 . + +%% -*- texinfo -*- +%% @documentencoding UTF-8 +%% @defmethod @@sym supremum (@var{x}) +%% The supremum of @var{x}. +%% +%% Example: +%% @example +%% @group +%% a = interval (sym (1), 2); +%% supremum (a) +%% @result{} ans = (sym) 2 +%% @end group +%% @end example +%% +%% @end defmethod + + +function y = supremum(x) + if (nargin ~= 1) + print_usage (); + end + y = elementwise_op ('lambda x: x.sup', sym (x)); +end + + +%!test +%! a = interval (sym (0), 1); +%! assert( isequal( supremum (a), sym (1))) + +%!test +%! a = interval (sym (0), 1); +%! b = interval (sym (2), 3); +%! assert (isequal (supremum (a + b), sym (3))) diff --git a/inst/domain.m b/inst/domain.m new file mode 100644 index 000000000..c1b41def9 --- /dev/null +++ b/inst/domain.m @@ -0,0 +1,56 @@ +%% 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 . + +%% -*- texinfo -*- +%% @documentencoding UTF-8 +%% @defmethod domain (@var{x}) +%% Return the domain @var{x}. +%% +%% List of supported domains (from SymPy 1.0.1): +%% EmptySet +%% Integers +%% Naturals +%% Naturals0 (Naturals with 0) +%% Reals +%% Complexes +%% UniversalSet +%% +%% Example: +%% @example +%% @group +%% domain ('Reals') +%% @result{} ans = (sym) ℝ +%% @end group +%% @end example +%% +%% @example +%% @group +%% domain ('Complexes') +%% @result{} ans = (sym) ℂ +%% @end group +%% @end example +%% +%% @end defmethod + + +function y = domain(x) + if (nargin ~= 1) + print_usage (); + end + y = python_cmd (strrep ('return S.{domain}', '{domain}', x)); +end