1
$\begingroup$

I am introducing a rule:

$Post = # /. x_?NumericQ FiniteField[q_?PrimeQ] [s_] :> FiniteField[q] [x] FiniteField[q] [s] &; 

But for some reason, upon evaluation of this single line, I receive an error:

The modulus q_?PrimeQ should be a prime number.

How can I fix this?

$\endgroup$
5
  • 2
    $\begingroup$ What are you trying to achieve? $\endgroup$ Commented Oct 25 at 22:52
  • $\begingroup$ @azerbajdzan it seems, with Finite Field function no basic replacement rule works: exp/.FiniteField[x_]:>FiniteField[z]; exp/.FiniteField[x_][y_]:>FiniteField[z][y]; exp/.FiniteField[__]:>FiniteField[z]; exp/.FiniteField[x_]->FiniteField[z]; $\endgroup$ Commented Oct 25 at 23:37
  • $\begingroup$ @azerbajdzan I want to replace in output a list with a finite field expression with a number. For instance, FFvector[{n_, FiniteField[q][n_]}]:>n $\endgroup$ Commented Oct 25 at 23:41
  • $\begingroup$ Look at the FullForm of some FiniteField - this is the pattern that should be matched. $\endgroup$ Commented Oct 26 at 8:24
  • $\begingroup$ Have you tried something like vec=Table[FiniteField[3][k],{k,0,2}]; Through[vec["Index"]]? $\endgroup$ Commented Oct 26 at 14:53

1 Answer 1

2
$\begingroup$

There are two main problems with your code.

  1. You want to match something of a form FiniteField[q_?PrimeQ][s_]. But you will never encounter such a form in your result, because it always resolves to a FiniteFieldElement. See it for yourself by observing the InputForm:
FiniteField[3][2] // InputForm (* FiniteFieldElement[FiniteField[3, 1 + #1 & , "Polynomial"], {2}] *) 
  1. Nevertheless, you will still encounter the same error message when you try to fix your pattern:
MatchQ[FiniteField[3][2], FiniteFieldElement[FiniteField[___], _]] (* FiniteField::fmod: The modulus ___ should be a prime number. *) (* FiniteFieldElement::bfld: FiniteField[___] is not a valid FiniteField object. *) (* False *) 

This is because FiniteFieldElement is an atomic expression, which you can confirm by using AtomQ:

AtomQ[FiniteField[3][2]] (* True *) 

You cannot do direct pattern matching on atomic expressions, so you have to construct your pattern differently:

patt = x_?NumericQ ffe_FiniteFieldElement /; PrimeQ[Information[ffe["Field"], "Characteristic"]] :> FiniteField[Information[ffe["Field"], "Characteristic"]][x] * FiniteField[Information[ffe["Field"], "Characteristic"]][ffe["Index"]]; 

This will now correctly match and replace your expression. But, once again, you will actually never encounter a term with the form x * FiniteFieldElement[...], because this always automatically evaluates to another FiniteFieldElement:

5 FiniteField[3][2] (* FiniteFieldElement[FiniteField[3, 1 + #& , "Polynomial"], {1}] *) 

(Unless you are giving it a real number in front of it, but in this case, you will also get an error message.)

This means that you probably need to use $Pre instead of $Post. But at this point, I believe you should specify and clarify what is your actual goal that you want to achieve ...

$\endgroup$
7
  • $\begingroup$ Pre has been deprecated and removed from Wolfram Cloud. $\endgroup$ Commented Oct 26 at 12:45
  • 1
    $\begingroup$ @Anixx, where did you get the idea that $Pre is deprecated? It most certainly doesn't seem so. $\endgroup$ Commented Oct 26 at 15:58
  • $\begingroup$ Thy in Wolfram Cloud, it will report an error. $\endgroup$ Commented Oct 26 at 16:37
  • $\begingroup$ @Anixx, just because it is disabled in Wolfram Cloud does not mean it is deprecated in any way. $\endgroup$ Commented Oct 26 at 16:38
  • 1
    $\begingroup$ @Anixx, in any case, the whole discussion about $Pre misses the point. You should still explain more thoroughly what you are actually trying to achieve. $\endgroup$ Commented Oct 26 at 16:39

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.