Questions in category: Magma (Magma)
软件 >> Magma
<[1] [2] [3] >

11. Magma 支持的群

Posted by haifeng on 2011-08-08 08:49:42 last update 2011-08-08 08:49:42 | Answers (0) | 收藏


Magma 支持五种类型的群:

  • 交换群(abelian group)
  • 有限表现群(finitely-presented, fp)
  • 矩阵群(matrix group)
  • 置换群(permutation group)
  • 可解群(soluble groups in power-conjugate/polycyclic(pc) representation)

12. 编写一个过程(procedure), 输出 n 个字符 c

Posted by haifeng on 2011-08-08 08:04:02 last update 2011-08-08 08:04:02 | Answers (1) | 收藏


SeparatingLine := procedure(c,n)
    print c^n;
  end procedure;
> SeparatingLine(\"#\",35);

注: 过程不同于函数, 过程是没有返回值的.

13. 保存日志文件

Posted by haifeng on 2011-08-08 08:00:31 last update 2011-08-08 08:00:31 | Answers (0) | 收藏


> SetLogFile(\"F:\\cs\\magma\\log.txt\");

14. 使用 magma 计算组合数 $C_n^r$

Posted by haifeng on 2011-08-07 17:14:15 last update 2011-08-07 17:14:56 | Answers (1) | 收藏


用复合方式定义函数 counting(n,r)=$\frac{n!}{r!(n-r)!}$.

> counting:= function(n,r)
>   x:= Factorial(n);
>   y:= Factorial(r);
>   z:= Factorial(n-r);
>   p:= x div z; // 这里正好可以整除
>   c:= p div y; // 同上
>   return p, c; // 可以返回两个值\r
> end function; // 别忘了函数体需要结束\r
> per, com := counting(5,2);

15. 使用 magma 定义函数 $f(n,q)=\Pi_{i=1}^{n}q^n-q^{i-1}$.

Posted by haifeng on 2011-08-07 17:00:23 last update 2011-08-07 17:01:19 | Answers (0) | 收藏


>f:=func < n,q|&*[q^n-q^(i-1):i in [1..n]] >;
>f(5,3);

16. magma 中的循环语句

Posted by haifeng on 2011-08-07 16:38:23 last update 2011-08-07 16:38:23 | Answers (0) | 收藏


magma 中有三种循环语句: while, repeat, for. 与其他编程语言类似.

  • while Boolean expression do
        statements;
    end while;
    
  • repeat
        statements;
    until Boolean expression;
    
  • for variable in domain do
        statements;
    end for;
    

17. magma 中的笛卡尔积

Posted by haifeng on 2011-08-07 16:33:12 last update 2011-09-03 20:27:27 | Answers (0) | 收藏


例如:

> {<a,b,c> : a,b,c in [1..10]|a^2+b^2 eq c^2};
{ <6, 8, 10>, <4, 3, 5>, <3, 4, 5>, <8, 6, 10> }

18. 使用 magma 计算 $\sum_{i=1}^{10}(i!)^2$

Posted by haifeng on 2011-08-07 16:24:26 last update 2011-08-07 16:24:26 | Answers (1) | 收藏


>&+[Factorial(i)^2:i in [1..10]];

这里 Factorial(i) 表示 $i!$. 符号 & 后面加上一个二元运算符再紧跟一个集合或者数组 $S$, 表示将该集合或数组中的元素使用此二元运算符结合起来.

19. magma 中的集合与数组

Posted by haifeng on 2011-08-07 15:55:53 last update 2011-08-07 16:16:02 | Answers (0) | 收藏


集合中的元素是惟一的, 即不可以重复. magma 中用 {} 表示集合; 数组中的元素是按一定顺序排列的, 用 [] 表示数组.

一些构造集合或数组的方法

{i..j by k}i,i+k,i+2k,...,j
[i..j by k]i,i+k,i+2k,...,j
{expression in $x$: $x$ in $D$ | condition}描述集合
[expression in $x$: $x$ in $D$ | condition]描述数组

例子:

> t:={n^2:n in [-11..11 by 2] | IsPrime(n)};

20. magma 的控制语句

Posted by haifeng on 2011-08-07 15:47:44 last update 2011-08-07 15:48:21 | Answers (0) | 收藏


if ... then
...;
elif ... then
...;
else
...;
end if;
<[1] [2] [3] >