This file is indexed.

/usr/share/octave/packages/symbolic-2.6.0/assumptions.m is in octave-symbolic 2.6.0-3build1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
%% Copyright (C) 2014-2016 Colin B. Macdonald
%%
%% 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
%% @deftypefun  {@var{A} =} assumptions ()
%% @deftypefunx {@var{A} =} assumptions (@var{x})
%% @deftypefunx {[@var{v}, @var{d}] =} assumptions (@var{x}, 'dict')
%% @deftypefunx {@var{L} =} assumptions ('possible')
%% List assumptions on symbolic variables.
%%
%% The assumptions are returned as a cell-array of strings:
%% @example
%% @group
%% syms x y positive
%% syms n integer
%% assumptions
%%   @result{} ans =
%%     @{
%%       [1,1] = n: integer
%%       [1,2] = x: positive
%%       [1,3] = y: positive
%%     @}
%% assumptions(n)
%%   @result{} ans =
%%     @{
%%       [1,1] = n: integer
%%     @}
%% @end group
%% @end example
%%
%% You can get the list of assumptions relevant to an expression:
%% @example
%% @group
%% f = sin(n*x);
%% assumptions(f)
%%   @result{} ans =
%%     @{
%%       [1,1] = n: integer
%%       [1,2] = x: positive
%%     @}
%% @end group
%% @end example
%%
%% With the optional second argument set to the string @code{'dict'},
%% return the assumption dictionaries in @var{d} corresponding
%% to the variables in @var{v}.
%%
%% You can also get a list of possible assumptions:
%% @example
%% @group
%% A = assumptions('possible');
%% strjoin(sort(A), ', ')
%%   @result{} ans = ..., finite, ..., positive, ..., zero
%% @end group
%% @end example
%%
%% @seealso{sym, syms, @@sym/assume, @@sym/assumeAlso}
%% @end deftypefun

%% Author: Colin B. Macdonald
%% Keywords: symbolic

function [A, B] = assumptions(F, outp)

  if ((nargin == 1) && ischar(F) && strcmp(F, 'possible'))
    A = valid_sym_assumptions();
    return
  end

  if ((nargin == 0) || isempty(F))
    find_all_free_symbols = true;
  else
    find_all_free_symbols = false;
  end
  if (nargin <= 1)
    outp = 'no';
  end

  if (find_all_free_symbols)
    %% no input arguments
    % find all syms, check each for free symbols
    workspace = {};
    context = 'caller';
    S = evalin(context, 'whos');
    evalin(context, '[];');  % clear 'ans'
    for i = 1:numel(S)
      workspace{i} = evalin(context, S(i).name);
    end
    F = findsymbols(workspace);
  end

  cmd = {
      'x = _ins[0]'
      'outputdict = _ins[1]'
      'd = x._assumptions.generator'
      'if d == {}:'
      '    astr = ""'
      'else:'
      '    astr = ", ".join(sorted([("" if v else "~") + str(k) for (k,v) in list(d.items())]))'
      'if outputdict:'
      '    return (astr, d)'
      'else:'
      '    return astr,' };

  c = 0; A = {};
  if strcmp(outp, 'dict')
    B = {};
  end
  if (isempty(F))
    return
  end
  s = findsymbols(F);
  for i=1:length(s)
    x = s{i};
    if strcmp(outp, 'dict')
      [astr, adict] = python_cmd(cmd, x, true);
      if ~isempty(astr)
        c = c + 1;
        A{c} = x;
        B{c} = adict;
      end
    else
      astr = python_cmd(cmd, x, false);
      if ~isempty(astr)
        c = c + 1;
        str = [x.flat ': ' astr];
        A{c} = str;
        %if c == 1
        %  A = str;
        %elseif c == 2
        %  A = {A str};
        %else
        %  A{c} = str;
        %end
      end
    end
  end

end


%!test
%! syms x
%! assert(isempty(assumptions(x)))

%!test
%! x = sym('x', 'positive');
%! a = assumptions(x);
%! assert(~isempty(strfind(a{1}, 'positive')))

%!test
%! syms x
%! assert(isempty(assumptions(x)))

%!test
%! clear variables  % for matlab test script
%! syms x positive
%! assert(~isempty(assumptions()))
%! clear x
%! assert(isempty(assumptions()))

%!test
%! % make sure we have at least these possible assumptions
%! A = {'real' 'positive' 'negative' 'integer' 'even' 'odd' 'rational'};
%! B = assumptions('possible');
%! assert (isempty (setdiff(A, B)))

%!test
%! A = assumptions('possible');
%! for i = 1:length(A)
%!   x = sym('x', A{i});
%!   a = assumptions(x);
%!   assert(strcmp(a{1}, ['x: ' A{i}] ))
%!   s1 = sympy (x);
%!   s2 = ['Symbol(''x'', ' A{i} '=True)'];
%!   assert (strcmp (s1, s2))
%! end

%!test
%! syms x positive
%! syms y real
%! syms z
%! f = x*y*z;
%! a = assumptions(f);
%! assert(length(a) == 2)
%! assert(~isempty(strfind(a{1}, 'positive')))
%! assert(~isempty(strfind(a{2}, 'real')))

%!test
%! % dict output
%! syms x positive
%! syms y real
%! syms z
%! f = x*y*z;
%! [v, d] = assumptions(f, 'dict');
%! assert(length(v) == 2)
%! assert(iscell(v))
%! assert(isa(v{1}, 'sym'))
%! assert(isa(v{2}, 'sym'))
%! assert(length(d) == 2)
%! assert(iscell(d))
%! assert(isstruct(d{1}))
%! assert(isstruct(d{2}))

%!test
%! %% assumptions on just the vars in an expression
%! clear variables  % for matlab test script
%! syms x y positive
%! f = 2*x;
%! assert(length(assumptions(f))==1)
%! assert(length(assumptions())==2)

%!test
%! %% assumptions in cell/struct
%! clear variables  % for matlab test script
%! syms x y z w positive
%! f = {2*x [1 2 y] {1, {z}}};
%! assert(length(assumptions())==4)
%! assert(length(assumptions(f))==3)
%! clear x y z w
%! assert(length(assumptions())==3)
%! assert(length(assumptions(f))==3)

%!test
%! % multiple assumptions
%! n = sym('n', 'negative', 'even');
%! assert (logical (n < 0))
%! assert (~(logical (n > 0)))
%! assert (~(logical (n == -1)))

%!test
%! % multiple assumptions: eqn neither true nor false
%! n = sym('n', 'negative', 'even');
%! assert (~isequal (n, sym(true)) && ~isequal (n, sym(false)))

%!test
%! %% TODO: rewrite later with https://github.com/cbm755/octsympy/issues/622
%! a = python_cmd ('return Symbol("a", real=False)');
%! assert (strcmp (assumptions (a), {'a: ~real'}))