1############################################################################# 2## 3## SageTools.gi RingsForHomalg package Simon Goertzen 4## 5## Copyright 2008 Lehrstuhl B für Mathematik, RWTH Aachen 6## 7## Implementations for the rings provided by Sage. 8## 9############################################################################# 10 11#################################### 12# 13# global variables: 14# 15#################################### 16 17InstallValue( CommonHomalgTableForSageTools, 18 19 rec( 20 Zero := HomalgExternalRingElement( R -> homalgSendBlocking( [ R, ".zero()" ], HOMALG_IO.Pictograms.Zero ), "Sage", IsZero ), 21 22 One := HomalgExternalRingElement( R -> homalgSendBlocking( [ R, ".one()" ], HOMALG_IO.Pictograms.One ), "Sage", IsOne ), 23 24 MinusOne := HomalgExternalRingElement( R -> homalgSendBlocking( [ "-", R, ".one()" ], HOMALG_IO.Pictograms.MinusOne ), "Sage", IsMinusOne ), 25 26 RingElement := R -> r -> homalgSendBlocking( [ R, ".one() * (", r, ")" ], HOMALG_IO.Pictograms.define ), 27 28 IsZero := r -> homalgSendBlocking( [ r, " == ", Zero( r ) ] , "need_output", HOMALG_IO.Pictograms.IsZero ) = "True", 29 30 IsOne := r -> homalgSendBlocking( [ r, " == ", One( r ) ] , "need_output", HOMALG_IO.Pictograms.IsOne ) = "True", 31 32 Minus := 33 function( a, b ) 34 35 return homalgSendBlocking( [ a, " - ( ", b, " )" ], HOMALG_IO.Pictograms.Minus ); 36 37 end, 38 39 Equal := 40 function( A, B ) 41 42 return homalgSendBlocking( [ A, "==", B ], "need_output", HOMALG_IO.Pictograms.AreEqualMatrices ) = "True"; 43 44 end, 45 46 ZeroMatrix := 47 function( C ) 48 49 return homalgSendBlocking( [ "matrix(", HomalgRing( C ), NrRows( C ), NrColumns( C ), ")" ], HOMALG_IO.Pictograms.ZeroMatrix ); 50 51 end, 52 53 IdentityMatrix := 54 function( C ) 55 local R; 56 57 R := HomalgRing( C ); 58 59 return homalgSendBlocking( [ "identity_matrix(", R, NrRows( C ), ")" ], HOMALG_IO.Pictograms.IdentityMatrix ); 60 61 end, 62 63 Involution := 64 function( M ) 65 66 return homalgSendBlocking( [ M, ".transpose()" ], HOMALG_IO.Pictograms.Involution ); 67 68 end, 69 70 TransposedMatrix := 71 function( M ) 72 73 return homalgSendBlocking( [ M, ".transpose()" ], HOMALG_IO.Pictograms.TransposedMatrix ); 74 75 end, 76 77 CertainRows := 78 function( M, plist ) 79 80 plist := plist - 1; 81 return homalgSendBlocking( [ M, ".matrix_from_rows(", plist, ")" ], HOMALG_IO.Pictograms.CertainRows ); 82 83 end, 84 85 CertainColumns := 86 function( M, plist ) 87 88 plist := plist - 1; 89 return homalgSendBlocking( [ M, ".matrix_from_columns(", plist, ")" ], HOMALG_IO.Pictograms.CertainColumns ); 90 91 end, 92 93 UnionOfRows := 94 function( A, B ) 95 96 return homalgSendBlocking( [ "block_matrix([", A, B, "],ncols=2)" ], HOMALG_IO.Pictograms.UnionOfRows ); 97 98 end, 99 100 UnionOfColumns := 101 function( A, B ) 102 103 return homalgSendBlocking( [ "block_matrix([", A, B, "],ncols=1)" ], HOMALG_IO.Pictograms.UnionOfColumns ); 104 105 end, 106 107 DiagMat := 108 function( e ) 109 local f; 110 111 f := ShallowCopy( e ); 112 Add( f, "block_diagonal_matrix(", 1 ); 113 Add( f, ")" ); 114 return homalgSendBlocking( f, HOMALG_IO.Pictograms.DiagMat ); 115 116 end, 117 118 MulMat := 119 function( a, A ) 120 121 return homalgSendBlocking( [ "(", a, ")*", A ], HOMALG_IO.Pictograms.MulMat ); 122 123 end, 124 125 MulMatRight := 126 function( A, a ) 127 128 return homalgSendBlocking( [ A, "*(", a, ")" ], HOMALG_IO.Pictograms.MulMatRight ); 129 130 end, 131 132 AddMat := 133 function( A, B ) 134 135 return homalgSendBlocking( [ A, "+", B ], HOMALG_IO.Pictograms.AddMat ); 136 137 end, 138 139 SubMat := 140 function( A, B ) 141 142 return homalgSendBlocking( [ A, "-", B ], HOMALG_IO.Pictograms.SubMat ); 143 144 end, 145 146 Compose := 147 function( A, B ) 148 149 return homalgSendBlocking( [ A, "*", B ], HOMALG_IO.Pictograms.Compose ); 150 151 end, 152 153 NrRows := 154 function( C ) 155 156 return StringToInt( homalgSendBlocking( [ C, ".nrows()" ], "need_output", HOMALG_IO.Pictograms.NrRows ) ); 157 158 end, 159 160 NrColumns := 161 function( C ) 162 163 return StringToInt( homalgSendBlocking( [ C, ".ncols()" ], "need_output", HOMALG_IO.Pictograms.NrColumns ) ); 164 165 end, 166 167 ZeroRows := 168 function( C ) 169 return StringToIntList( homalgSendBlocking( [ "ZeroRows(", C, ")" ], "need_output", HOMALG_IO.Pictograms.ZeroRows ) ) + 1; 170 end, 171 172 ZeroColumns := 173 function( C ) 174 return StringToIntList( homalgSendBlocking( [ "ZeroColumns(", C, ")" ], "need_output", HOMALG_IO.Pictograms.ZeroColumns ) ) + 1; 175 end, 176 177 ) 178 ); 179