[sage-support] Re: var() definition in finite fields

2014-10-01 Thread Kim Schoener
Hi Peter, hi Martin,

somehow both approaches I think don't work for me. For example, the square 
(m1^2) is carried in both approaches, even though it can be simplified to 
m1 in GF(2). I would like sage to account for the GF(2) in order to 
simplify terms. For example I would expect that x * (x + 1) is simplified 
to 0 if x is a variable in GF(2).

Is there a way to do this or does sage lack that funcitonality?

Thank you,
Kim

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


[sage-support] Re: var() definition in finite fields

2014-10-01 Thread Nils Bruin
On Wednesday, October 1, 2014 3:30:16 PM UTC-7, Kim Schoener wrote:

 Hi Peter, hi Martin,

 somehow both approaches I think don't work for me. For example, the square 
 (m1^2) is carried in both approaches, even though it can be simplified to 
 m1 in GF(2). I would like sage to account for the GF(2) in order to 
 simplify terms. For example I would expect that x * (x + 1) is simplified 
 to 0 if x is a variable in GF(2).


It means that you want to work modulo the ideal 
(m1^2-m1,m2^2-m2,m3^2-m3,m4^2-m4). You can use

sage: P.m1,m2,m3,m4=BooleanPolynomialRing()
sage: m1^2+m1
0
sage: q=matrix(2,2,[m1,m2,m3,m4])
sage: q^2
[   m1 + m2*m3 m1*m2 + m2*m4]
[m1*m3 + m3*m4m2*m3 + m4]

 

 Is there a way to do this or does sage lack that funcitonality?

 Thank you,
 Kim


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


[sage-support] Re: var() definition in finite fields

2014-09-30 Thread Volker Braun
Anything symbolic is in the symbolic ring SR, finite field elements are in 
GF(2). You can wrap finite field elements in the symbolic ring if you want 
to do symbolic computations with finite field coefficients:

sage: SR(GF(5)(3)) * x
3*x
sage: _ * 2
x

though the symbolic elemnts still don't know anything about finite fields, 
they just carry the coefficients along.



On Tuesday, September 30, 2014 3:14:03 PM UTC+1, Kim Schoener wrote:

 Heya!

 I want to do something relatively easy in Sage but can't figure out how. 
 Hopefully you can help me. I want to do some symbolic operations 
 (matrix/vector) in the GF(2). Let's start out with real numbers first:

 (m1, m2, m3, m4) = (var(m1), var(m2), var(m3), var(m4))
 q = Matrix([
 [m1, m2],
 [m3, m4],
 ])
 print(q)
 print(q * q)

 Works pefectly:

 [m1 m2]
 [m3 m4]
 [ m1^2 + m2*m3 m1*m2 + m2*m4]
 [m1*m3 + m3*m4  m2*m3 + m4^2]

 But when I try the same thing in GF(2) by definiing

 q = Matrix(GF(2), [
 [m1, m2],
 [m3, m4],
 ])

 I get:

 [...]
   File parent.pyx, line 1069, in sage.structure.parent.Parent.__call__ 
 (sage/structure/parent.c:8546)
   File coerce_maps.pyx, line 156, in 
 sage.structure.coerce_maps.NamedConvertMap._call_ 
 (sage/structure/coerce_maps.c:4930)
   File expression.pyx, line 857, in 
 sage.symbolic.expression.Expression._integer_ 
 (sage/symbolic/expression.cpp:5877)
 TypeError: unable to convert x (=m1) to an integer

 However, the matrix definition seems to be okay, when I do

 q = Matrix(GF(2), [
 [1, 1 ],
 [1, 0],
 ])
 print(q * q)

 I get

 [0 1]
 [1 1]

 which is what I'd expect. Why does it not work with variables when working 
 in GF(2) and how can I get this to work the way I want it to?

 Thank you so much,
 Regards,
 Kim



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


[sage-support] Re: var() definition in finite fields

2014-09-30 Thread Kim Schoener
I'm not sure I understand fully what you're saying. I did

m1 = SR(GF(2)(1)) * var(m1)
m2 = SR(GF(2)(1)) * var(m2)
m3 = SR(GF(2)(1)) * var(m3)
m4 = SR(GF(2)(1)) * var(m4)

but the Matrix definition

q = Matrix(GF(2), [
[m1, m2],
[m3, m4],
])

still results in the same error: unable to convert x (=x1) to an integer.

How do I define a variable in the SR that I can work with? I can't seem to 
figure it out from the example you gave me.

Thank you,
Kim


Am Dienstag, 30. September 2014 17:04:10 UTC+2 schrieb Volker Braun:

 Anything symbolic is in the symbolic ring SR, finite field elements are in 
 GF(2). You can wrap finite field elements in the symbolic ring if you want 
 to do symbolic computations with finite field coefficients:

 sage: SR(GF(5)(3)) * x
 3*x
 sage: _ * 2
 x

 though the symbolic elemnts still don't know anything about finite fields, 
 they just carry the coefficients along.



 On Tuesday, September 30, 2014 3:14:03 PM UTC+1, Kim Schoener wrote:

 Heya!

 I want to do something relatively easy in Sage but can't figure out how. 
 Hopefully you can help me. I want to do some symbolic operations 
 (matrix/vector) in the GF(2). Let's start out with real numbers first:

 (m1, m2, m3, m4) = (var(m1), var(m2), var(m3), var(m4))
 q = Matrix([
 [m1, m2],
 [m3, m4],
 ])
 print(q)
 print(q * q)

 Works pefectly:

 [m1 m2]
 [m3 m4]
 [ m1^2 + m2*m3 m1*m2 + m2*m4]
 [m1*m3 + m3*m4  m2*m3 + m4^2]

 But when I try the same thing in GF(2) by definiing

 q = Matrix(GF(2), [
 [m1, m2],
 [m3, m4],
 ])

 I get:

 [...]
   File parent.pyx, line 1069, in sage.structure.parent.Parent.__call__ 
 (sage/structure/parent.c:8546)
   File coerce_maps.pyx, line 156, in 
 sage.structure.coerce_maps.NamedConvertMap._call_ 
 (sage/structure/coerce_maps.c:4930)
   File expression.pyx, line 857, in 
 sage.symbolic.expression.Expression._integer_ 
 (sage/symbolic/expression.cpp:5877)
 TypeError: unable to convert x (=m1) to an integer

 However, the matrix definition seems to be okay, when I do

 q = Matrix(GF(2), [
 [1, 1 ],
 [1, 0],
 ])
 print(q * q)

 I get

 [0 1]
 [1 1]

 which is what I'd expect. Why does it not work with variables when 
 working in GF(2) and how can I get this to work the way I want it to?

 Thank you so much,
 Regards,
 Kim



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


Re: [sage-support] Re: var() definition in finite fields

2014-09-30 Thread Martin Albrecht
Your matrix is over GF(2) not over the symbolic ring SR:

sage: m1 = SR(GF(2)(1)) * var(m1)
sage: m2 = SR(GF(2)(1)) * var(m2)
sage: m3 = SR(GF(2)(1)) * var(m3)
sage: m4 = SR(GF(2)(1)) * var(m4)

sage: q = Matrix(SR, [
[m1, m2],
[m3, m4],
])

sage: q^2
[ m1^2 + m2*m3 m1*m2 + m2*m4]
[m1*m3 + m3*m4  m2*m3 + m4^2]


On Tuesday 30 Sep 2014 08:46:42 Kim Schoener wrote:
 I'm not sure I understand fully what you're saying. I did
 
 m1 = SR(GF(2)(1)) * var(m1)
 m2 = SR(GF(2)(1)) * var(m2)
 m3 = SR(GF(2)(1)) * var(m3)
 m4 = SR(GF(2)(1)) * var(m4)
 
 but the Matrix definition
 
 q = Matrix(GF(2), [
 [m1, m2],
 [m3, m4],
 ])
 
 still results in the same error: unable to convert x (=x1) to an integer.
 
 How do I define a variable in the SR that I can work with? I can't seem to
 figure it out from the example you gave me.
 
 Thank you,
 Kim
 
 Am Dienstag, 30. September 2014 17:04:10 UTC+2 schrieb Volker Braun:
  Anything symbolic is in the symbolic ring SR, finite field elements are in
  GF(2). You can wrap finite field elements in the symbolic ring if you want
  to do symbolic computations with finite field coefficients:
  
  sage: SR(GF(5)(3)) * x
  3*x
  sage: _ * 2
  x
  
  though the symbolic elemnts still don't know anything about finite fields,
  they just carry the coefficients along.
  
  On Tuesday, September 30, 2014 3:14:03 PM UTC+1, Kim Schoener wrote:
  Heya!
  
  I want to do something relatively easy in Sage but can't figure out how.
  Hopefully you can help me. I want to do some symbolic operations
  (matrix/vector) in the GF(2). Let's start out with real numbers first:
  
  (m1, m2, m3, m4) = (var(m1), var(m2), var(m3), var(m4))
  q = Matrix([
  
  [m1, m2],
  [m3, m4],
  
  ])
  print(q)
  print(q * q)
  
  Works pefectly:
  
  [m1 m2]
  [m3 m4]
  [ m1^2 + m2*m3 m1*m2 + m2*m4]
  [m1*m3 + m3*m4  m2*m3 + m4^2]
  
  But when I try the same thing in GF(2) by definiing
  
  q = Matrix(GF(2), [
  
  [m1, m2],
  [m3, m4],
  
  ])
  
  I get:
  
  [...]
  
File parent.pyx, line 1069, in sage.structure.parent.Parent.__call__
  
  (sage/structure/parent.c:8546)
  
File coerce_maps.pyx, line 156, in
  
  sage.structure.coerce_maps.NamedConvertMap._call_
  (sage/structure/coerce_maps.c:4930)
  
File expression.pyx, line 857, in
  
  sage.symbolic.expression.Expression._integer_
  (sage/symbolic/expression.cpp:5877)
  TypeError: unable to convert x (=m1) to an integer
  
  However, the matrix definition seems to be okay, when I do
  
  q = Matrix(GF(2), [
  
  [1, 1 ],
  [1, 0],
  
  ])
  print(q * q)
  
  I get
  
  [0 1]
  [1 1]
  
  which is what I'd expect. Why does it not work with variables when
  working in GF(2) and how can I get this to work the way I want it to?
  
  Thank you so much,
  Regards,
  Kim

signature.asc
Description: This is a digitally signed message part.


[sage-support] Re: var() definition in finite fields

2014-09-30 Thread Peter Bruin
Hello,

I want to do some symbolic operations (matrix/vector) in the GF(2).


Here is an alternative approach (assuming all your expressions are 
polynomials in m1, m2, m3 and m4):

sage: R.m1,m2,m3,m4 = PolynomialRing(GF(2))
sage: q = Matrix(R, [[m1, m2], [m3, m4]])
sage: q
[m1 m2]
[m3 m4]
sage: q*q
[ m1^2 + m2*m3 m1*m2 + m2*m4]
[m1*m3 + m3*m4  m2*m3 + m4^2]

Note that the coefficients are elements of R = GF(2)[m1, m2, m3, m4], not 
of GF(2); cf. the other answers where they are in SR.

Peter

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