1%% Copyright (C) 2014-2016, 2018 Colin B. Macdonald 2%% 3%% This file is part of OctSymPy. 4%% 5%% OctSymPy is free software; you can redistribute it and/or modify 6%% it under the terms of the GNU General Public License as published 7%% by the Free Software Foundation; either version 3 of the License, 8%% or (at your option) any later version. 9%% 10%% This software is distributed in the hope that it will be useful, 11%% but WITHOUT ANY WARRANTY; without even the implied warranty 12%% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13%% the GNU General Public License for more details. 14%% 15%% You should have received a copy of the GNU General Public 16%% License along with this software; see the file COPYING. 17%% If not, see <http://www.gnu.org/licenses/>. 18 19%% -*- texinfo -*- 20%% @documentencoding UTF-8 21%% @defop Method @@sym and {(@var{x}, @var{y})} 22%% @defopx Operator @@sym {@var{x} & @var{y}} {} 23%% Logical "and" of symbolic arrays. 24%% 25%% Examples: 26%% @example 27%% @group 28%% sym(false) & sym(true) 29%% @result{} (sym) False 30%% 31%% syms x y z 32%% x & (y | z) 33%% @result{} (sym) x ∧ (y ∨ z) 34%% @end group 35%% @end example 36%% 37%% @seealso{@@sym/or, @@sym/not, @@sym/xor, @@sym/eq, @@sym/ne, 38%% @@sym/logical, @@sym/isAlways, @@sym/isequal} 39%% @end defop 40 41function r = and(x, y) 42 43 if (nargin ~= 2) 44 print_usage (); 45 end 46 47 r = elementwise_op ('And', sym(x), sym(y)); 48 49end 50 51 52%!shared t, f 53%! t = sym(true); 54%! f = sym(false); 55 56%!test 57%! % simple 58%! assert (isequal (t & f, f)) 59%! assert (isequal (t & t, t)) 60 61%!test 62%! % mix wih nonsym 63%! assert (isequal (t & false, f)) 64%! assert (isequal (t & true, t)) 65%! assert (isequal (t & 0, f)) 66%! assert (isequal (t & 1, t)) 67%! assert (isa (t & false, 'sym')) 68%! assert (isa (t & 1, 'sym')) 69 70%!test 71%! % array 72%! w = [t t f f]; 73%! z = [t f t f]; 74%! assert (isequal (w & z, [t f f f])) 75 76%!test 77%! % number 78%! assert (isequal( sym(1) & t, t)) 79%! assert (isequal( sym(0) & t, f)) 80 81%!test 82%! % output is sym even for scalar t/f 83%! assert (isa (t & f, 'sym')) 84 85%!test 86%! % eqns, exclusive 87%! syms x 88%! e = (x == 3) & (x^2 == 9); 89%! assert (isequal (subs(e, x, [-3 0 3]), [f f t])) 90 91%!error and (sym('x'), 2, 3) 92