maple - 检查索引变量是否在某处分配了值

标签 maple indexed

第 1 部分

如果我们有这个

[> restart; a[5]:=23: a[7]:=41:

然后

[> about(a); whattype(a);
a:
  nothing known about this object
                        symbol

但是

[> print(a);
                 table([5 = 23, 7 = 41])

[> convert(a,list);
                        [23, 41]

所以 Maple 确实有足够的关于变量 a 及其索引的信息。我们如何在不打印的情况下检查该信息?

对于小索引来说这不是问题,但是如果 b[123457891234578912345789]:=789; 那么我们如何检查是否存在某个索引 ib[i] 有一个定义的值,索引 i 是什么(不打印,即不手动)?

第 2 部分

我希望能够在函数内使用此类变量并返回此类变量。 例如,假设我想将所有索引增加 1。如果我知道存在哪些索引,那么我就可以做到这一点

[> a[5]:=23: a[7]:=41:
   f:=proc(x) local y;
      y[6]:=x[5]; y[8]:=x[7]; y;
      end proc:
   b:=f(a); b[6]; b[8];
           b:=y
            23
            41

但我常常不知道变量 a 有什么索引。

最佳答案

您可以进行多种编程查询,

restart;
a[5]:=23: a[7]:=41:

# test whether a is assigned
assigned('a');
                  true

# test whether a is assigned a table
type(a, table);
                  true

# test whether table a has any indexed values
evalb( nops([indices(a, 'nolist')]) > 0 );

                  true

assigned('a'[7]);
                  true

如果您愿意,可以在尝试访问和使用索引引用之前进行此类查询(即检查它是否具有指定值)。例如,

if type(a,table) and assigned('a'[7]) then
  a[7];
end if;
             41

if type(a, table) then
  [indices(a, 'nolist')];
end if;
            [5, 7]

关于maple - 检查索引变量是否在某处分配了值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68749091/

相关文章:

spring - @Indexed 不适用于 spring 数据 cassandra

c++ - 我能以某种方式将 Maple 过程包含到 C++ 代码中吗

c - 扩展 Maple 代码生成中的变量名称

forms - 如何在 TYPO3 中使用 Indexed_search

arrays - 在 Swift 中将索引数组转换为字典

search - 为什么indexed_search仅在TYPO3 8/9中的子页面上不起作用?

javascript - 通过函数名称查找表调用 javascript 函数(或方法)的最快方法?

wolfram-mathematica - mathematica/maple 中的分数阶导数?

matlab - 通过自动引入时间变量或以任何其他方式简化非常长的符号表达式

matlab - 检查符号计算