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_Managing_Derived_Methods">4<Heading>Managing Derived Methods</Heading>56<P/>7<Section Label="Chapter_Managing_Derived_Methods_Section_Info_Class">8<Heading>Info Class</Heading>910<ManSection>11<InfoClass Name="DerivationInfo" />12<Description>13Info class for derivations.14</Description>15</ManSection>161718<P/>19<ManSection>20<Func Arg="arg" Name="ActivateDerivationInfo" />21<Description>22<P/>23</Description>24</ManSection>252627<P/>28<ManSection>29<Func Arg="arg" Name="DeactivateDerivationInfo" />30<Description>31<P/>32</Description>33</ManSection>343536</Section>373839<Section Label="Chapter_Managing_Derived_Methods_Section_Derivation_Objects">40<Heading>Derivation Objects</Heading>4142<ManSection>43<Filt Arg="arg" Name="IsDerivedMethod" Label="for IsObject"/>44<Returns><C>true</C> or <C>false</C>45</Returns>46<Description>47A derivation object describes a derived method.48It contains information about which operation the derived method49implements, and which other operations it relies on.50</Description>51</ManSection>525354<ManSection>55<Oper Arg="name, target_op, used_ops_with_multiples, weight, implementations_with_extra_filters, category_filter" Name="MakeDerivation" Label="for IsString, IsFunction, IsDenseList,IsPosInt, IsDenseList, IsFunction"/>56<Description>57Creates a new derivation object.58The argument <A>name</A> is an arbitrary name used to59identify this derivation, and is useful only for debugging60purposes.61The argument <A>target_op</A> is the operation which62the derived method implements.63The argument <A>used_ops_with_multiples</A> contains each64operation used by the derived method, together with a positive65integer specifying how many times that operation is used.66This is given as a list of lists, where each sublist has as67first entry an operation and as second entry an integer.68The argument <A>weight</A> is an additional number to add69when calculating the resulting weight of the target operation70using this derivation. Unless there is any particular reason71to regard the derivation as exceedingly expensive, this number72should be <C>1</C>.73The argument <A>implementations_with_extra_filters</A> contains74one or more functions with the actual implementation of the75derived method, together with lists of extra argument filters76for each function. The argument is a list with entries of the77form <C>[fun, filters]</C>, where <C>fun</C> is a function and78<C>filters</C> is a (not necessarily dense) list of argument79filters. If only one function is given, then <C>filters</C>80should be the empty list; in this case the argument's value81would be [[fun,[]]], where <C>fun</C> is the function.82The argument <A>category_filter</A> is a filter describing83which categories the derivation is valid for. If it is valid84for all categories, then this argument should have the value85<C>IsCapCategory</C>.86</Description>87</ManSection>888990<ManSection>91<Attr Arg="d" Name="DerivationName" Label="for IsDerivedMethod"/>92<Description>93The name of the derivation. This is a name identifying this94particular derivation, and normally not the same as the name95of the operation implemented by the derivation.96</Description>97</ManSection>9899100<ManSection>101<Attr Arg="d" Name="DerivationWeight" Label="for IsDerivedMethod"/>102<Description>103Extra weight for the derivation.104</Description>105</ManSection>106107108<ManSection>109<Attr Arg="d" Name="DerivationFunctionsWithExtraFilters" Label="for IsDerivedMethod"/>110<Description>111The implementation(s) of the derivation, together with lists112of extra filters for each implementation.113</Description>114</ManSection>115116117<ManSection>118<Attr Arg="d" Name="CategoryFilter" Label="for IsDerivedMethod"/>119<Description>120Filter describing which categories the derivation is valid for.121</Description>122</ManSection>123124125<ManSection>126<Oper Arg="d, C" Name="IsApplicableToCategory" Label="for IsDerivedMethod, IsCapCategory"/>127<Returns><C>true</C> if the category <A>C</A> is known to satisfy the category filter of the derivation <A>d</A>.128</Returns>129<Description>130Checks if the derivation is known to be valid for a given category.131</Description>132</ManSection>133134135<ManSection>136<Attr Arg="d" Name="TargetOperation" Label="for IsDerivedMethod"/>137<Returns>The name (as a string) of the operation implemented by the derivation <A>d</A>138</Returns>139<Description>140<P/>141</Description>142</ManSection>143144145<ManSection>146<Attr Arg="d" Name="UsedOperations" Label="for IsDerivedMethod"/>147<Returns>The names (as strings) of the operations used by the derivation <A>d</A>148</Returns>149<Description>150<P/>151</Description>152</ManSection>153154155<ManSection>156<Attr Arg="d" Name="UsedOperationMultiples" Label="for IsDerivedMethod"/>157<Returns>Multiplicities of each operation used by the derivation <A>d</A>, in order corresponding to the operation names returned by <C>UsedOperations(d)</C>.158</Returns>159<Description>160<P/>161</Description>162</ManSection>163164165<ManSection>166<Attr Arg="d" Name="UsedOperationsWithMultiples" Label="for IsDerivedMethod"/>167<Returns>The names of the operations used by the derivation <A>d</A>, together with their multiplicities. The result is a list consisting of lists of the form <C>[op_name, mult]</C>, where <C>op_name</C> is a string and <C>mult</C> a positive integer.168</Returns>169<Description>170<P/>171</Description>172</ManSection>173174175<ManSection>176<Oper Arg="d, weight, C" Name="InstallDerivationForCategory" Label="for IsDerivedMethod, IsPosInt, IsCapCategory"/>177<Description>178Install the derived method <A>d</A> for the category <A>C</A>.179The integer <A>weight</A> is the computed weight of the operation180implemented by this derivation.181</Description>182</ManSection>183184185<ManSection>186<Oper Arg="d, op_weights" Name="DerivationResultWeight" Label="for IsDerivedMethod, IsDenseList"/>187<Description>188Computes the resulting weight of the target operation of this189derivation given a list of weights for the operations it uses.190The argument <A>op_weights</A> should be a list of integers191specifying weights for the operations given by192<C>UsedOperations( d )</C>, in the same order.193</Description>194</ManSection>195196197</Section>198199200<Section Label="Chapter_Managing_Derived_Methods_Section_Derivation_Graphs">201<Heading>Derivation Graphs</Heading>202203<ManSection>204<Filt Arg="arg" Name="IsDerivedMethodGraph" Label="for IsObject"/>205<Returns><C>true</C> or <C>false</C>206</Returns>207<Description>208A derivation graph consists of a set of operations and a set of derivations209specifying how some operations can be implemented in terms of other operations.210</Description>211</ManSection>212213214<ManSection>215<Oper Arg="operations" Name="MakeDerivationGraph" Label="for IsDenseList"/>216<Description>217Make a derivation graph containing the given set of operations and no derivations.218The argument <A>operations</A> should be a list of strings, the names of the219operations. The set of operations is fixed once the graph is created.220Derivations can be added to the graph by calling <C>AddDerivation</C>.221</Description>222</ManSection>223224225<ManSection>226<Oper Arg="graph, operations" Name="AddOperationsToDerivationGraph" Label="for IsDerivedMethodGraph, IsDenseList"/>227<Description>228Adds a list of operation names <A>operations</A> to a given derivation graph <A>graph</A>.229This is used in extensions of CAP which want to have their own primitive operations,230but do not want to pollute the CAP kernel any more. Please use it with caution. If231a weight list/category was created before it will not be aware of the operations.232</Description>233</ManSection>234235236<ManSection>237<Oper Arg="G, d" Name="AddDerivation" Label="for IsDerivedMethodGraph, IsDerivedMethod"/>238<Description>239Add a derivation to a derivation graph.240</Description>241</ManSection>242243244<P/>245<ManSection>246<Oper Arg="arg1,arg2,arg3,arg4" Name="AddDerivation" Label="for IsDerivedMethodGraph, IsFunction, IsDenseList, IsObject"/>247<Description>248<P/>249</Description>250</ManSection>251252253<P/>254<ManSection>255<Oper Arg="arg1,arg2,arg3" Name="AddDerivation" Label="for IsDerivedMethodGraph, IsFunction, IsDenseList"/>256<Description>257<P/>258</Description>259</ManSection>260261262<P/>263<ManSection>264<Oper Arg="arg1,arg2,arg3" Name="AddDerivation" Label="for IsDerivedMethodGraph, IsFunction, IsFunction"/>265<Description>266<P/>267</Description>268</ManSection>269270271<P/>272<ManSection>273<Oper Arg="arg1,arg2,arg3,arg4,arg5,arg6" Name="AddDerivationPair" Label="for IsDerivedMethodGraph, IsFunction, IsFunction, IsDenseList, IsDenseList, IsDenseList"/>274<Description>275<P/>276</Description>277</ManSection>278279280<ManSection>281<Oper Arg="arg1,arg2,arg3,arg4,arg5" Name="AddDerivationPair" Label="for IsDerivedMethodGraph, IsFunction, IsFunction, IsDenseList, IsDenseList"/>282<Description>283<P/>284</Description>285</ManSection>286287288<ManSection>289<Oper Arg="arg1,arg2,arg3,arg4,arg5,arg6" Name="AddDerivationPair" Label="for IsDerivedMethodGraph, IsFunction, IsFunction, IsDenseList, IsFunction, IsFunction"/>290<Description>291<P/>292</Description>293</ManSection>294295296<ManSection>297<Oper Arg="arg1,arg2,arg3,arg4,arg5" Name="AddDerivationPair" Label="for IsDerivedMethodGraph, IsFunction, IsFunction, IsFunction, IsFunction"/>298<Description>299<P/>300</Description>301</ManSection>302303304<P/>305<ManSection>306<Func Arg="arg" Name="AddDerivationToCAP" />307<Description>308<P/>309</Description>310</ManSection>311312313<P/>314<ManSection>315<Func Arg="arg" Name="AddDerivationPairToCAP" />316<Description>317<P/>318</Description>319</ManSection>320321322<P/>323<ManSection>324<Func Arg="arg" Name="AddWithGivenDerivationPairToCAP" />325<Description>326<P/>327</Description>328</ManSection>329330331<ManSection>332<Attr Arg="G" Name="Operations" Label="for IsDerivedMethodGraph"/>333<Description>334Gives the operations in the graph <A>G</A>, as a list of strings.335</Description>336</ManSection>337338339<ManSection>340<Oper Arg="G, op_name" Name="DerivationsUsingOperation" Label="for IsDerivedMethodGraph, IsString"/>341<Description>342Finds all the derivations in the graph <A>G</A> that use the operation named343<A>op_name</A>, and returns them as a list.344</Description>345</ManSection>346347348<ManSection>349<Oper Arg="G, op_name" Name="DerivationsOfOperation" Label="for IsDerivedMethodGraph, IsString"/>350<Description>351Finds all the derivations in the graph <A>G</A> targeting the operation named352<A>op_name</A> (that is, the derivations that provide implementations of this353operation), and returns them as a list.354</Description>355</ManSection>356357358</Section>359360361<Section Label="Chapter_Managing_Derived_Methods_Section_Managing_Derivations_in_a_Category">362<Heading>Managing Derivations in a Category</Heading>363364<ManSection>365<Filt Arg="arg" Name="IsOperationWeightList" Label="for IsObject"/>366<Returns><C>true</C> or <C>false</C>367</Returns>368<Description>369An operation weight list manages the use of derivations in a single category <Math>C</Math>.370For every operation, it keeps a weight value which indicates how costly it is371to perform that operation in the category <Math>C</Math>. Whenever a new operation is372implemented in <Math>C</Math>, the operation weight list should be notified about this and373given a weight to assign to this operation. It will then automatically install374all possible derived methods for <Math>C</Math> in such a way that every operation has the375smallest possible weight (the weight of a derived method is computed by using376the weights of the operations it uses; see <C>DerivationResultWeight</C>).377</Description>378</ManSection>379380381<ManSection>382<Oper Arg="C, G" Name="MakeOperationWeightList" Label="for IsCapCategory, IsDerivedMethodGraph"/>383<Description>384Create the operation weight list for a category.385This should only be done once for every category, and the category should386afterwards remember the returned object.387The argument <A>C</A> is the CAP category this operation weight list is associated to,388and the argument <A>G</A> is a derivation graph containing operation names and derivations.389</Description>390</ManSection>391392393<ManSection>394<Attr Arg="owl" Name="DerivationGraph" Label="for IsOperationWeightList"/>395<Description>396Returns the derivation graph used by the operation weight list <A>owl</A>.397</Description>398</ManSection>399400401<ManSection>402<Attr Arg="owl" Name="CategoryOfOperationWeightList" Label="for IsOperationWeightList"/>403<Description>404Returns the CAP category associated to the operation weight list <A>owl</A>.405</Description>406</ManSection>407408409<ManSection>410<Oper Arg="owl, op_name" Name="CurrentOperationWeight" Label="for IsOperationWeightList, IsString"/>411<Description>412Returns the current weight of the operation named <A>op_name</A>.413</Description>414</ManSection>415416417<ManSection>418<Oper Arg="owl, d" Name="OperationWeightUsingDerivation" Label="for IsOperationWeightList, IsDerivedMethod"/>419<Description>420Finds out what the weight of the operation implemented by the derivation <A>d</A>421would be if we had used that derivation.422</Description>423</ManSection>424425426<ManSection>427<Oper Arg="owl, op_name" Name="DerivationOfOperation" Label="for IsOperationWeightList, IsString"/>428<Description>429Returns the derivation which is currently used to implement the operation430named <A>op_name</A>.431If the operation is not implemented by a derivation (that is, either implemented432directly or not implemented at all), then <C>fail</C> is returned.433</Description>434</ManSection>435436437<ManSection>438<Oper Arg="owl, op_name" Name="InstallDerivationsUsingOperation" Label="for IsOperationWeightList, IsString"/>439<Description>440Performs a search from the operation <A>op_name</A>, and installs all derivations441that give improvements over the current state.442This is used internally by <C>AddPrimitiveOperation</C> and <C>Reevaluate</C>.443It should normally not be necessary to call this function directly.444</Description>445</ManSection>446447448<ManSection>449<Oper Arg="owl" Name="Reevaluate" Label="for IsOperationWeightList"/>450<Description>451Reevaluate the installed derivations, installing better derivations if possible.452This should be called if new derivations become available for the category,453either because the category has acquired more knowledge about itself454(e.g. it is told that it is abelian)455or because new derivations have been added to the graph.456</Description>457</ManSection>458459460<ManSection>461<Oper Arg="owl, op_name, weight" Name="AddPrimitiveOperation" Label="for IsOperationWeightList, IsString, IsInt"/>462<Description>463Add the operation named <A>op_name</A> to the operation weight list <A>owl</A>464with weight <A>weight</A>.465This causes all operations that can be derived, directly or indirectly,466from the newly added operation to be installed as well467(unless they are already installed with the same or lower weight).468</Description>469</ManSection>470471472<ManSection>473<Oper Arg="owl, op_name" Name="PrintDerivationTree" Label="for IsOperationWeightList, IsString"/>474<Description>475Print a tree representation of the way the operation named <A>op_name</A>476is implemented in the category of the operation weight list <A>owl</A>.477</Description>478</ManSection>479480481<ManSection>482<Oper Arg="arg1,arg2,arg3" Name="PrintTree" Label="for IsObject, IsFunction, IsFunction"/>483<Description>484Prints a tree structure.485</Description>486</ManSection>487488489<ManSection>490<Oper Arg="arg1,arg2,arg3,arg4" Name="PrintTreeRec" Label="for IsObject, IsFunction, IsFunction, IsInt"/>491<Description>492<P/>493</Description>494</ManSection>495496497</Section>498499500<Section Label="Chapter_Managing_Derived_Methods_Section_Min_Heaps_for_Strings">501<Heading>Min Heaps for Strings</Heading>502503This section describes an implementation of min heaps for storing strings with504associated integer keys, used internally by operation weight lists.505<ManSection>506<Filt Arg="arg" Name="IsStringMinHeap" Label="for IsObject"/>507<Returns><C>true</C> or <C>false</C>508</Returns>509<Description>510A string min heap is a min heap where every node contains a string label and an511integer key.512</Description>513</ManSection>514515516<ManSection>517<Func Arg="arg" Name="StringMinHeap" />518<Description>519Create an empty string min heap.520</Description>521</ManSection>522523524<ManSection>525<Oper Arg="H, string, key" Name="Add" Label="for IsStringMinHeap, IsString, IsInt"/>526<Description>527Add a new node containing the label <A>string</A> and the key <A>key</A>528to the heap <A>H</A>.529</Description>530</ManSection>531532533<ManSection>534<Oper Arg="H" Name="ExtractMin" Label="for IsStringMinHeap"/>535<Description>536Remove a node with minimal key value from the heap <A>H</A>, and return it.537The return value is a list <C>[ label, key ]</C>, where <C>label</C>538is the extracted node's label (a string) and <C>key</C> is the539node's key (an integer).540</Description>541</ManSection>542543544<ManSection>545<Oper Arg="H, string, key" Name="DecreaseKey" Label="for IsStringMinHeap, IsString, IsInt"/>546<Description>547Decrease the key value for the node with label <A>string</A> in the548heap <A>H</A>. The new key value is given by <A>key</A> and must be549smaller than the node's current value.550</Description>551</ManSection>552553554<ManSection>555<Oper Arg="H" Name="IsEmptyHeap" Label="for IsStringMinHeap"/>556<Description>557Returns <C>true</C> if the heap <A>H</A> is empty, <C>false</C> otherwise.558</Description>559</ManSection>560561562<ManSection>563<Oper Arg="H" Name="HeapSize" Label="for IsStringMinHeap"/>564<Description>565Returns the number of nodes in the heap <A>H</A>.566</Description>567</ManSection>568569570<ManSection>571<Oper Arg="H, string" Name="Contains" Label="for IsStringMinHeap, IsString"/>572<Description>573Returns <C>true</C> if the heap <A>H</A> contains a node with574label <A>string</A>, and <C>false</C> otherwise.575</Description>576</ManSection>577578579<ManSection>580<Oper Arg="H, i, j" Name="Swap" Label="for IsStringMinHeap, IsPosInt, IsPosInt"/>581<Description>582Swaps two elements in the list used to implement the heap,583and updates the heap's internal mapping of labels to list indices.584This is an internal function which should only be called from the585functions that implement the heap functionality.586</Description>587</ManSection>588589590<ManSection>591<Oper Arg="H, i" Name="Heapify" Label="for IsStringMinHeap, IsPosInt"/>592<Description>593Heapify the heap <A>H</A>, starting from index <A>i</A>.594This is an internal function.595</Description>596</ManSection>597598599</Section>600601602<P/>603</Chapter>604605606607