2
$\begingroup$

I am trying to define a function which recursively computes a polynomial associated to every binary string:

ComputePoly[s_]:=(** Recurse on the string s**)

For example, suppose my initial conditions were the following:

ComputePoly[""]:=1;
ComputePoly["0"]:=x_1;
ComputePoly["1"]:=x_2;

And suppose my recurrence relation was:

ComputePoly[u concatenated with v]:=ComputePoly[u]*ComputePoly[v]

Then this would describe a homomorphism from the monoid of binary strings to the multiplicative monoid of a polynomial ring in $x_1,x_2$.

How would I implement something like this? Should I even use strings, or is there a better data structure for working with binary sequences?

$\endgroup$
4
  • $\begingroup$ What are x_1 and x_2? $\endgroup$ Jun 25, 2015 at 0:06
  • $\begingroup$ Indeterminates, which generate the polynomial ring. $\endgroup$
    – pre-kidney
    Jun 25, 2015 at 0:22
  • $\begingroup$ Maybe I am missing something, but do you just want $x_1^\text{# of 0s} x_2^\text{# of 1s}$? $\endgroup$
    – wxffles
    Jun 25, 2015 at 1:10
  • $\begingroup$ In the example I've given, that is what it reduces to. There is a much more complicated recurrence that I am currently working with. $\endgroup$
    – pre-kidney
    Jun 25, 2015 at 4:06

1 Answer 1

1
$\begingroup$

As a recurrence:

ComputePoly[{}] := 1;
ComputePoly[{0}] := x1
ComputePoly[{1}] := x2
ComputePoly[l_List] := ComputePoly[l[[1 ;; 1]]]*ComputePoly[Rest@l]

ComputePoly[{0, 1, 0, 1, 1, 1, 1}]

(* x1^2 x2^5 *)

Of course different recurrence relationships need different implementations. As you don't mention your actual one it's very difficult to provide more insight

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.