2

I have seen f = sympy.symbols('f', cls=Function) but not any documentation. Python does not like x = sympy.symbols('x', cls=FF(8)), it complains about

raise CoercionFailed("expected an integer, got %s" % a) CoercionFailed: expected an integer, got x

Whan is the purpose of the cls parameters and what must I do so that cls=FF(8) is meaning full?

With x = sympy.symbols('x', cls=FF(8)) I want x to be a symbol in the field FF(8), i.e x^(2^8-1) must give me 1.

Johan
  • 575
  • 5
  • 21

1 Answers1

2

There are a few issues here:

  • The FF object does not allow Symbols. It only works for exact numerical entries, like FF(3)(2).

  • Therefore, the cls parameter of symbols will not work. That just changes what object is used to create the symbol, so it must take a string as an input (the default is Symbol).

  • SymPy does not currently support Symbols over finite fields. The best bet you can get is to use the Poly object with the modulus flag.

  • FF currently only supports finite fields of prime cardinality. FF(8) has actually created the ring Z_8, not the finite field with 8 elements.

  • You probably know this, but ^ does not do exponentiation in SymPy/Python. Use **.

asmeurer
  • 86,894
  • 26
  • 169
  • 240
  • I also work in sage and there '^' is the exponent, at least I thought so until now. I created a python class which I executed in sage when '^' was not the exponent by had to use '**'. Why does sage not see '^' as the exponent in when used in a class? That is the purpose of the string passed to symbols with the cls parameter? – Johan Jul 31 '13 at 20:01
  • Yeah, Sage doesn't override `__xor__` to use `^` because that won't work (`^` has a different precedence than `**`). Rather, it parses the user input to wrap integer literals and replace `^` with `**`. But I guess whatever you were using was not preparsed by sage. – asmeurer Jul 31 '13 at 23:56
  • The parsing will explain. How easy will it be to expand the usage of the cls parameter to be able to give it a name of sage finite field class, so that the variable given by sympy.Symsbols will be in the finite field. – Johan Aug 06 '13 at 07:31