File: misc.gi

package info (click to toggle)
gap-hapcryst 0.1.15-4
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,088 kB
  • sloc: xml: 1,475; javascript: 155; makefile: 118; sh: 3
file content (134 lines) | stat: -rw-r--r-- 3,591 bytes parent folder | download | duplicates (2)
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
#############################################################################
##
#W misc.gi 			 HAPcryst package		 Marc Roeder
##
##  

##
##
#Y	 Copyright (C) 2006 Marc Roeder 
#Y 
#Y This program is free software; you can redistribute it and/or 
#Y modify it under the terms of the GNU General Public License 
#Y as published by the Free Software Foundation; either version 2 
#Y of the License, or (at your option) any later version. 
#Y 
#Y This program is distributed in the hope that it will be useful, 
#Y but WITHOUT ANY WARRANTY; without even the implied warranty of 
#Y MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
#Y GNU General Public License for more details. 
#Y 
#Y You should have received a copy of the GNU General Public License 
#Y along with this program; if not, write to the Free Software 
#Y Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
##
# there seems to be not method for rationals, even though SignInt 
# did work in all of the cases I tried.
InstallMethod(SignRat, "for rationals",[IsRat],
        function(rat)
    if rat>0
       then
        return 1;
    elif rat<0
      then
        return -1;
    elif rat=0
      then
        return 0;
    else
        Error("cannot calculate sign of rational");
    fi;
    #return SignInt(rat*DenominatorRat(rat));
end);
  

##############################

InstallMethod(IsSquareMat,"for matrices",[IsMatrix],
        function(mat)
        return Size(Set(mat,Size))=1;
end);


##############################


InstallMethod(DimensionSquareMat,"for matrices",[IsMatrix],
        function(mat)
    if not IsSquareMat(mat)
       then
        Error("Matrix is not square");
    else
        return DimensionsMat(mat)[1];
    fi;
end);


##############################
#
# Return the linear part of an affine matrix. This is sometimes called
# "rotational part" for crystallographic groups.
#

InstallMethod(LinearPartOfAffineMatOnRight,"for affine matrices on right",
        [IsMatrix],
        function(mat)
    local dim;
    if not IsAffineMatrixOnRight(mat)
       then
        Error("matrix must be an affine matrix acting from the right");
    fi;
    dim:=DimensionSquareMat(mat);
    return mat{[1..dim-1]}{[1..dim-1]};
end);


##############################
#
# Calculate what a basis change of $n$ dimensional space does to an affine
# transformation represented by an affine $(n+1)\times(n+1)$ matrix.
#

InstallMethod(BasisChangeAffineMatOnRight,"for affine matrices on right",
        [IsMatrix,IsMatrix],
        function(transform,mat)
    local   dim,  linpart,  transpart,  transformed;
    dim:=DimensionSquareMat(mat);
    if not dim>1 and IsAffineMatrixOnRight(mat)
       then
        Error("This matrix is not affine acting on right");
    fi;
    linpart:=LinearPartOfAffineMatOnRight(mat);
    transpart:=mat[dim]{[1..dim-1]};
    transformed:=IdentityMat(dim);
    transformed{[1..dim-1]}{[1..dim-1]}:=linpart^transform;
    transformed[dim]{[1..dim-1]}:=transpart*transform;
    return transformed;
end);


##############################
#
# Return an affine matrix on right which represents the translation 
# by <vector>
#

InstallMethod(TranslationOnRightFromVector,
        [IsVector],
        function(vector)
    local dim, translation;
    dim:=Size(vector)+1;
    translation:=IdentityMat(dim);
    translation[dim]{[1..dim-1]}:=ShallowCopy(vector);
    return translation;
end);


##############################
#
#
InstallMethod(VectorModOne,
        [IsVector],
        function(vector)
    return List(vector,FractionModOne);
end);