Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
| Download
GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
Project: cocalc-sagemath-dev-slelievre
Views: 418346<?xml version="1.0" encoding="UTF-8"?>12<!-- This is an automatically generated file. -->3<Chapter Label="Chapter_Add_Functions">4<Heading>Add Functions</Heading>56<P/>7This section describes the overall structure of Add-functions and the functions installed by them.8<P/>9<Section Label="Chapter_Add_Functions_Section_Functions_Installed_by_Add">10<Heading>Functions Installed by Add</Heading>1112<P/>13Add functions (up to some exceptions) have the following syntax14<P/>15DeclareOperation( "AddSomeFunc",16[ IsCapCategory, IsList, IsInt ] );17<P/>18The first argument is the category to which some function (e.g. KernelObject)19is added, the second is a list containing pairs of functions and additional20filters for the arguments, (e.g. if one argument is a morphism, an additional filter could be IsMomomorphism).21The third is a weight which will then be the weight for SomeFunc. This is described later.22If only one function is to be installed, the list can be replaced by the function.23Via InstallMethod, CAP installs the given function(s) as methods for the install name of SomeFunc,24as listed in the MethodRecord. If no install name is given, the name SomeFunc is used.25<P/>26All installed methods follow the following steps, described below:27<List>28<Item>29Redirect function30</Item>31<Item>32Prefunction33</Item>34<Item>35Function36</Item>37<Item>38Logic39</Item>40<Item>41Postfunction42</Item>43<Item>44Addfunction45</Item>46</List>47<P/>48Every other part, except from function, does only depend on the name SomeFunc. We now explain the steps in detail.49<P/>50<List>51<Item>52Redirect function: The redirect is used to redirect the computation from the given functions to some other symbol.53If there is for example a with given method for some universal property, and the universal object is already computed,54the redirect function might detect such a thing, calls the with given operation with the universal object as additional55argument and then returns the value. In general, the redirect can be an arbitrary function. It is called with the same56arguments as the operation SomeFunc itself and can return an array containing [ true, something ], which will cause57the installed method to simply return the object something, or [ false ]. If the output is false, the computation will58continue with the step Prefunction. Additionally, for every category and every name like SomeFunc, there is a boolean,59stored in the categorys redirects component under the name of SomeFunc, which, when it is false, will prevent the60redirect function from being executed.61</Item>62</List>63<P/>64<List>65<Item>66Prefunction: The prefunction should be used for error handling and soft checks of the sanity of the input to SomeFunc67(e.g. for KernelLift it should check wether range and source of the morphims coincide). Generally, the prefunction is defined68in the method record and only depend on the name SomeFunc. It is called with the same input as the function itself, and69should return either [ true ], which continues the computation, or [ false, "message" ], which will cause an error with70message "message" and some additional information.71</Item>72</List>73<P/>74<List>75<Item>76Function: This will launch the function(s) given as arguments. The result should be as specified in the type of77SomeFunc. The resulting object is now named the result.78</Item>79</List>80<P/>81<List>82<Item>83Logic: For every function, some logical todos can be implemented in a logic texfile for the category. If there is84some logic written down in a file belonging to the category, or belonging to some type of category. Please see the85description of logic for more details. If there is some logic and some predicate relations for the function SomeFunc,86it is installed in this step for the result.87</Item>88</List>89<P/>90<List>91<Item>92Postfunction: The postfunction called with the arguments of the function and the result. It can be an arbitrary function doing93some cosmetics. If for example SomeFunc is KernelEmbeddingedding, it will set the KernelObject of the input morphism to result.94The postfunction is also taken from the method record and does only depend on the name SomeFunc.95</Item>96</List>97<P/>98<List>99<Item>100Addfunction: If the result is a category cell, it is added to the category for which the function was installed.101</Item>102</List>103<P/>104</Section>105106107<Section Label="Chapter_Add_Functions_Section_Add_Method">108<Heading>Add Method</Heading>109110<P/>111Except from installing a new method for the name SomeFunc, an Add method does slightly more.112Every Add method has the same structure. The steps in the Add method are as follows:113<P/>114<List>115<Item>116Weight check: If the current weight of the operation is lower than the given weight of the new functions,117then the add function returns and installs nothing.118</Item>119</List>120<P/>121<List>122<Item>123Option check: There are two possible options for every add method: SetPrimitive and IsDerivation.124<List>125<Item>126SetPrimitive should be a boolean, the default is true. If SetPrimitive is false, then the127current call of this add will not set the installed function to be primitive. This is used for derivations.128</Item>129<Item>130IsDerivation should be a boolean, default is false. If it is true, the add method assumes that the given131function is a derivation and does not try to install a corresponding pair (See below).132</Item>133</List>134</Item>135</List>136<P/>137<List>138<Item>139Standard weight: If the weight parameter is -1, the Standard weight is assumed, which is 100.140</Item>141</List>142<P/>143<List>144<Item>145Checking for pairs: If the function is not a with given operation, has a corresponding with given or is a with given,146and is newly installed, i.e. the current installation weight which is given to the add function147is less than the current weight, the add method is going to install a corresponding pair function,148i.e. a function for the corresponding with or without given method, which redirects to the currently149installed functions. It also deactivates the redirect for this function.150Note that the pair install is only done for primitive functions, and if the current weight is151higher than the given weight.152</Item>153</List>154<P/>155<List>156<Item>157Can compute: Set the corresponding can compute of the category to true158</Item>159</List>160<P/>161<List>162<Item>163Install methods: Decide on the methods used to install the function. Check wether InstallMethodWithCache, InstallMethodWithToDoForIsWellDefined,164both, or simply InstallMethod is used. This is decided by the ToDo and the caching flags.165</Item>166</List>167<P/>168<List>169<Item>170Installation: Next, the method to install the functions is created. It creates the correct filter list, by merging the standard filters171for the operation with the particular filters for the given functions, then installs the method as described above.172</Item>173</List>174<P/>175<List>176<Item>177SetPrimitive: If the set primitive flag is true, it is set as primitive in the weight list of the category.178</Item>179</List>180<P/>181<List>182<Item>183Pair install: If there is a function pair, as described above, it is installed.184</Item>185</List>186<P/>187After calling an add method, the corresponding Operation is availible in the category. Also, some derivations, which are triggered by the setting188of the primitive value, might be availible.189<P/>190</Section>191192193<Section Label="Chapter_Add_Functions_Section_InstallAdd_Function">194<Heading>InstallAdd Function</Heading>195196<P/>197Almost all Add methods in the CAP kernel are installed by the CapInternalInstallAdd operation.198The definition of this function is as follows:199<P/>200DeclareOperation( "CapInternalInstallAdd",201[ IsRecord ] );202<P/>203The record can have the following components, used as described:204<P/>205<List>206<Item>207function_name: The name of the function. This does not have to coincide with the installation name. It is used for the derivation weight.208</Item>209</List>210<P/>211<List>212<Item>213installation_name (optional): A string which is the name of the operation for which the214functions given to the Add method are installed as methods.215</Item>216</List>217<P/>218<List>219<Item>220pre_function (optional): A function which is used as the prefunction of the installed methods, as described above.221</Item>222</List>223<P/>224<List>225<Item>226redirect_function (optional): A function which is used as the redirect function of the installed methods, as described above.227</Item>228</List>229<P/>230<List>231<Item>232post_function (optional): A function which is used as the postfunction of the installed methods, as described above.233</Item>234</List>235<P/>236<List>237<Item>238filter_list: A list containing the basic filters for the methods installed by the add methods. Possible are filters, or239the strings category, object, morphism, or twocell, which will then be replaced at the time the add method is240called with the corresponding filters of the category.241</Item>242</List>243<P/>244<List>245<Item>246well_defined_todo (optional): A boolean, default value is true, which states wether there should be to do list entries247which propagate well definedness from the input of the installed methods to their output.248Please note that true only makes sense if at least one argument and the output of the249installed method is a cell.250</Item>251</List>252<P/>253<List>254<Item>255cache_name (optional): The name of the cache which is used for the installed methods. If no cache name is given, the caching256for the operation is deactivated completely.257</Item>258</List>259<P/>260<List>261<Item>262argument_list (optional): A list containing integers, which defines which arguments should be used for the additional functions, (e.g redirect, pre, ...).263This is important for the Op method contructions. If no argument list is given, all arguments are used.264Please note that if you have a method selection argument for your function, you need to give the argument_list265to explicitly state which argument is the method selection argument.266</Item>267</List>268<P/>269<List>270<Item>271return_type (optional): The return type can be object, morphism, or twocell. If it is one of those, the correct add function (see above) is272used for the result of the computation. Otherwise, no add function is used after all.273</Item>274</List>275<P/>276<List>277<Item>278is_with_given: Boolean, marks wether the function which is to be installed a with given function or not.279</Item>280</List>281<P/>282<List>283<Item>284with_given_without_given_name_pair (optional): If the currently installed operation has a corresponding with given operation or285is the with given of another operation, the names of both should be in this list.286</Item>287</List>288<P/>289<List>290<Item>291functorial (optional): If an object has a corresponding functorial function, e.g., KernelObject and KernelObjectFunctorial,292the name of the functorial is stored as a string.293</Item>294</List>295<P/>296Using all those entries, the operation CapInternalInstallAdd installs add methods as described above. It first provides a297sanity check for all the entries described, then installs the Add method in 4 ways, with list or functions as second argument, and298with an optional third parameter for the weight.299<P/>300</Section>301302303<Section Label="Chapter_Add_Functions_Section_Install_All_Adds">304<Heading>Install All Adds</Heading>305306<P/>307The function CAP_INTERNAL_INSTALL_ALL_ADDS does not take any arguments, it is an auxiliary function which iterates over the308CAP_INTERNAL_METHOD_NAME_RECORD and calls, after some cosmetics, the CapInternalInstallAdd with the corresponding method record entry.309The steps below are performed for every entry of the method record:310<P/>311<List>312<Item>313No install check: If the no_install component in the record is set to true, the loop continues with the next314entry, since this flag indicates that there should be no add function for this operation.315</Item>316</List>317<P/>318<List>319<Item>320Cache check: If there is no cache_name, set it to the name of the method record entry.321</Item>322</List>323<P/>324<List>325<Item>326Function name: Set the component function_name to the entry name.327</Item>328</List>329<P/>330<List>331<Item>332Redirect: Since the redirect function needs the category to work correctly, the given redirects in the method records are333packed up to discard the last argument, which is the category.334</Item>335</List>336<P/>337<List>338<Item>339arg_list: Next, an argument list for redirect and post function is created, by looking at the filter list in the record.340If the first one is a list, the first and the last (method selection argument) is used, otherwise only the first.341</Item>342</List>343<P/>344<List>345<Item>346WithGiven special case: If the current entry belongs to a WithGiven operation, the with_given_without_given_name_pair is set,347the with given flag is set to true, and the CapInternalInstallAdd is called with the record. The loop348then continues.349</Item>350</List>351<P/>352<List>353<Item>354Non universal object special case: If the Operation does not have a universal type, i.e. does not belong to a universal355construction, CapInternalInstallAdd is called with the record. The loop then continues.356</Item>357</List>358<P/>359Please note that we are now in the case where the operation belongs to a universal construction, (e.g. KernelLift) and is not360a WithGiven type of operation.361<P/>362<List>363<Item>364argument_list: If the method is an Op construction, i.e. has a method selection object, the argument list is set to all but the365last object and then used as above. Otherwise, the argument_list is set to all arguments.366</Item>367</List>368<P/>369<List>370<Item>371If the Operation constructs a universal object, the postfunction is created and then CapInternalInstallAdd is called.372</Item>373</List>374<P/>375<List>376<Item>377If the Operation constructs a universal morphism, the redirect is created and stored in the record.378Also, the postfunction is created. Then CapInternalInstallAdd is called.379</Item>380</List>381<P/>382After one call of this function, all add methods are installed correctly. A second call should not do anything.383<P/>384</Section>385386387</Chapter>388389390391