[GAP Forum] Overloading functions

Alexander Konovalov alexk at mcs.st-andrews.ac.uk
Mon Nov 19 20:18:45 GMT 2012


Glad that you've found a workaround, Marek.

I also don't know how octonions are constructed in your code, but if they 
permit IsOctonion filter and you already have a function to perform the 
conjugation, it may be installed as a method similarly to this example:

> InstallMethod( ComplexConjugate,
>    "for an octonion",
>    [ IsOctonion ],
>    function( oct )
>    ...
>    ...
>    return result;
>    end );

 
More information may be found in the reference manual, starting from
Chapter 78 "Method Selection" and Tutorial (Chapter 8 "Operations and 
Methods").

Best wishes,
Alexander



On 19 Nov 2012, at 13:29, Marek Mitros wrote:

> Dear Alexander,
> 
> I do not know how to install function ComplexConjugate for octonions.
> I believe I should use "InstallMethod(..." instead of
> "ComplexConjugate:=function(x)...". I below quote example for a list.
> It seems advanced technique for standard GAP user :) But maybe I will
> try it next time.
> 
> Regarding the ReflectionMat I discovered that I can pass parameter
> "conj" which is function which conjugate matrix element. So I managed
> with my original problem.
> 
> Regards,
> Marek
> 
> 
> Here is example I found in lib/cyclotom.gi
> 
> InstallMethod( ComplexConjugate,
>    "for a list",
>    [ IsList ],
>    function( list )
>    local result, i;
> 
>    result:= [];
>    for i in [ 1 .. Length( list ) ] do
>      if IsBound( list[i] ) then
>        result[i]:= ComplexConjugate( list[i] );
>      fi;
>    od;
>    return result;
>    end );
> 
> 
> On 11/19/12, Alexander Konovalov <alexk at mcs.st-andrews.ac.uk> wrote:
>> On 11 May 2012, at 11:49, Marek Mitros wrote:
>> 
>>> Hi,
>>> 
>>> I tried to define ComplexConjugate function for octonions - see below.
>>> In this <conj> is my function for conjugating the octonion.
>>> 
>>> gap> ComplexConjugate:=function(o) return conj(o); end;
>>> Variable: 'ComplexConjugate' is read only
>>> 
>>> I would like to use <ReflectionMat> function which use
>>> <ComplexConjugate>. Is there way in GAP to overload standard
>>> <ComplexConjugate> function, so it works also for my octonions ?
>>> 
>>> The workaround would be to copy function from lib/matrix.gi and modify
>>> but it is less convenient.
>> 
>> Dear Marek, dear Forum,
>> 
>> I've seen that this old message in the Forum was not answered by anyone.
>> 
>> In case this question still makes sense, then is is possible for you just
>> to install a method for ComplexConjugate for octonions?
>> 
>> ComplexConjugate is an attribute, and the GAP library already has several
>> methods for ComplexConjugate installed for different kinds of objects -
>> you may find examples in the files from the 'lib' directory.
>> 
>> Hope this helps,
>> Alexander
>> 
>> 
>> 


--
Dr. Alexander Konovalov               School of Computer Science
& Centre for Interdisciplinary Research in Computational Algebra
University of St Andrews                 Tel +44/0 (1334) 461633
http://www.cs.st-andrews.ac.uk/~alexk    Fax +44/0 (1334) 463278
The University of St Andrews is a charity registered in Scotland:No.SC013532










More information about the Forum mailing list