On Tuesday, August 19, 2014 7:39:18 PM UTC+2, Peter Bruin wrote:
>
> Hi Jean-Pierre,
>
> I'm currently wrapping FLINT fq modules into new Sage classes for finite 
>> fiels and got strange coercion errors when running non trivial code.
>> Indeed, the polynomial ring constructors use a dictionary and so relies 
>> on the hash of finite fields (the parents).
>> By some chance, the hashes of two previous implementations of finite 
>> fields using PARI where different because some variable name was replaced 
>> by something else in some object and this prevented this problem to occur.
>>
>> I read 
>> http://www.sagemath.org/doc/developer/coding_in_python.html#the-hash-special-method
>>  
>> but would welcome any advice.
>>
>> Though (non-prime) finite fields with the same order and defining 
>> polynomial are considered equal, I'd say the hashes should be different.
>> So, let's add the string of the implementation of the finite field into 
>> it's hash (which is cached by the way).
>> Does that seem sensible?
>>
>> Or should I modify the finite field code so that these hashes are equal 
>> whatever the implementation is?
>> Then we'd need coercion between all of the implementations (which is not 
>> currently the case but should be done anyway), but that would surely yield 
>> a non-negligible speed penalty, and you'll never know what the 
>> implementation of the base ring of the polynomial ring will be as it will 
>> depend on the order finite fields and their polynomial rings are created.
>>
>> Or should we modify the caching system of the polynomial rings not to use 
>> hashes but ids?
>>
>
> I'm not sure I understand correctly; do you mean that the problem is 
> caused by fields comparing equal even if the implementations are 
> different?  I think we should in any
>
Not sure.
I seem to be able to produce things with different hashes but equal...
sage: GF(13**5, 'a', impl='pari_ffelt') == GF(13**5, 'a', impl='flint_fq')
True
Though I have:
sage: GF(13**5, 'a', impl='pari_ffelt') == GF(13**5, 'a', impl='pari_mod')
False
Maybe that's because of the __cmp__ functions I copied/pasted/slightly 
modified.
Or maybe I forgot to implement some methods as the new classes are cdefed.
I'll check that.

Even if it boils down to a different matter, I don't feel that the current 
other __hash__ method are good enough as well to tell between different 
finite field.
It mostly work by chance.
And indeed whe copy/paste/modify'ing it, it gave me similar hashes for 
different implems.
Not sure for what __hash__ is used directly.
In most cases the EqualityById stuff might do the trick.

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to