ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 18 Jan 2021 11:34:33 +0100How to use for loops and assign values to arrayhttps://ask.sagemath.org/question/55324/how-to-use-for-loops-and-assign-values-to-array/> x = 3 z = IncreasingArrays() z =
> x.binary()
>
> for i in range(x):
> if z[i] == 1:
> print(' ', 2^i) # Not printing here
I'm unable to print the 3rd line it always says space indent etc.
How to solve this?
Also please help me how to assign values in an array in for loop
Also binary values I should store in array how to??
I'm new please help
I'm using this only on sagemath cell server online
ThanksRamaMon, 18 Jan 2021 11:34:33 +0100https://ask.sagemath.org/question/55324/I should store binary values in an arrayhttps://ask.sagemath.org/question/55323/i-should-store-binary-values-in-an-array/Given a Sage integer, I wish to obtain the list of its binary digits.
How can I get that?
So far, I found the `binary` method of Sage integers.
Given an integer, that method returns its binary expansion as a string.
For example:
sage: a = 8
sage: a.binary()
'1000'
-----
Thanks for the response.
Here is a follow-up question.
x = 3
z = IncreasingArrays()
z = x.binary()
for i in range(x):
if z[i] == 1:
print(' ', 2^i) # Not printing here
I want to print if binary value is 1.
And raise it to power 2.
The `for` loop isn't printing print statement also.
Please help me with these for loops and also how to store values in an array.
In C I go:
int a[6];
for(i = 2 ; i <= 5 ; i++) { a[i] = 1 ; }
Here like this in C, array values are set.
How to do the same in Sage please help.RamaMon, 18 Jan 2021 11:29:54 +0100https://ask.sagemath.org/question/55323/Count number of ones in a set of matrixhttps://ask.sagemath.org/question/45540/count-number-of-ones-in-a-set-of-matrix/I am having the following code:
v = MatrixSpace(GF(2),2,2)
c = [0]*2
for vv in v.list():
t=sum(vv)
c = [x+y for x,y in zip(c,t)]
print c
My goal is to count how many '1s' that I have for each column within the set of matrices. For example with the first 4 matrices in the set:
[0 0] [1 0] [0 1] [0 0]
[0 0], [0 0], [0 0], [1 0]
I expect to receive [2,1] as a result, i.e. there are 2 of '1s' appear in the 1st column and 1 of '1s' appears in the 2nd column. However, I got [0, 1], because it's binary base.
Thank you for reading my problem and support :)imnvshMon, 25 Feb 2019 03:15:10 +0100https://ask.sagemath.org/question/45540/sage binary "base-toolchain" failedhttps://ask.sagemath.org/question/43998/sage-binary-base-toolchain-failed/I'm trying to use SageMath 8.3 binary for Ubuntu 16.04 LTS.
The binary does not work out of the box, it complains "RecursionError", which seems to be caused by Anaconda overriding the default python2.7 interpreter. So I temporarily comment out the Anaconda path, and the python interpreter is now the default 2.7.
Then there is this "bas-toolchain" error:
<pre>
patching /home/abc/usr/SageMath/local/bin/g++
Traceback (most recent call last):
File "./relocate-once.py", line 208, in <module>
ch(3478673, 3478845).save()
File "./relocate-once.py", line 113, in patch
self.search_and_replace, self.filename
File "./relocate-once.py", line 52, in __init__
super(FileBinaryPatch, self).__init__(search_and_replace, filename)
File "./relocate-once.py", line 40, in __init__
self.st = os.stat(filename)
OSError: [Errno 2] No such file or directory: '/home/abc/usr/SageMath/local/bin/g++'
Makefile:31: recipe for target 'base-toolchain' failed
make: *** [base-toolchain] Error 1
</pre>
I created a symlink of g++
<pre>
ln -sf /usr/bin/g++ ./local/bin/g++
</pre>
but it doesn't work.
I have no idea what to do, please help. Thanks in advance!
### Edit (10/20/2018):
The binary also reports error. Output of `sudo ./sage`:
<pre>
Traceback (most recent call last):
File "/home/abc/usr/SageMath/relocate-once.py", line 208, in <module>
ch(3478673, 3478845).save()
File "/home/abc/usr/SageMath/relocate-once.py", line 113, in patch
self.search_and_replace, self.filename
File "/home/abc/usr/SageMath/relocate-once.py", line 52, in __init__
super(FileBinaryPatch, self).__init__(search_and_replace, filename)
File "/home/abc/usr/SageMath/relocate-once.py", line 40, in __init__
self.st = os.stat(filename)
OSError: [Errno 2] No such file or directory: '/home/abc/usr/SageMath/local/bin/g++'
ERROR: The Sage installation tree has moved
from /home/buildbot/slave/binary_pkg/build/source/SageMath/jc4b6yulaujayb9sr94ia88eourzeqip0oidmas391yaj2
to /home/abc/usr/SageMath
This is not supported, and Sage will not work. To install Sage from a
binary package:
1. Open the .tar.bz2 archive (or .dmg on OSX)
2. Move the SageMath folder/app to where you want it to be. You can
also rename the directory now.
3. Start sage for the first time. This will then automatically patch
paths in binaries.
After starting Sage for the first time you cannot change the
installation any more. To install Sage elsewhere, start over from the
binary package. Or recompile Sage from scratch in the new location
("make distclean && make")
</pre>
I also tried `sudo sage --nodotsage`, same output.
It looks like the binary in the first run must call the make.msgboxaFri, 19 Oct 2018 19:33:22 +0200https://ask.sagemath.org/question/43998/How to convert an integer to fixed length binary string in Sage?https://ask.sagemath.org/question/43916/how-to-convert-an-integer-to-fixed-length-binary-string-in-sage/ I want to get
(192,14,100)=>8bit binary of 192 || 8bit binary of 14 ||8bit binary of 100 => 110000000000111001100100 => 12586596 (equivalent decimal of the 24bits binary sting).
I have written python code to do this, but this code does not work in sage. Here is the code :
L=(192,14,100)
a=0
for i in range(3):
a=(a << 8) ^ (L[i])
print a
print bin(a)
What is the best way to do so in Sage?BSFUThu, 11 Oct 2018 15:20:46 +0200https://ask.sagemath.org/question/43916/linux binary seems to be sourcehttps://ask.sagemath.org/question/42736/linux-binary-seems-to-be-source/ I followed the link "Linux binaries" from the Download page, which leads to a page titles "Binaries for Linux" for which I do not have enough karma to post the exact url, but it is sagemath dot org slash download minus linux dot html. As recommended I downloaded the torrent version of sage-8.2-Ubuntu_16.04-x86_64.tar.bz2
But ./sage gives this result:
~/Documents/SageMath $ ./sage
RecursionError: maximum recursion depth exceeded during compilation
************************************************************************
It seems that you are attempting to run Sage from an unpacked source
tarball, but you have not compiled it yet (or maybe the build has not
finished). You should run `make` in the Sage root directory first.
If you did not intend to build Sage from source, you should download
a binary tarball instead. Read README.txt for more information.
************************************************************************
never_too_lateTue, 26 Jun 2018 15:23:11 +0200https://ask.sagemath.org/question/42736/Can I define a symbolic equation where the variables are concatenating?https://ask.sagemath.org/question/38009/can-i-define-a-symbolic-equation-where-the-variables-are-concatenating/Hi,
Can I define a symbolic equation with variable concatenating?
For example:
let $x \in \mathbb{F}_2$
How can I define the following equation:
$11111x1111 = 2*x + 2$
where the x is a digit in the left number.
(The obvious way is by taking the binary exression of that number i.e $\Sigma_{i=0}^{i=n}2^ib_i$)
SAvaGEMon, 19 Jun 2017 09:27:43 +0200https://ask.sagemath.org/question/38009/Non linear Binary equations using sat solverhttps://ask.sagemath.org/question/36165/non-linear-binary-equations-using-sat-solver/ How can I solve a set of nonlinear binary equations in SAGE using the sat solver?RADEON360Wed, 04 Jan 2017 07:25:06 +0100https://ask.sagemath.org/question/36165/Generate all binary strings of length nhttps://ask.sagemath.org/question/30644/generate-all-binary-strings-of-length-n/ I need to generate all binary strings of length 15 and then access individual bits. Is there some function for that?
Thank YouProWed, 11 Nov 2015 22:48:42 +0100https://ask.sagemath.org/question/30644/Binary variable in mixed integer linear programhttps://ask.sagemath.org/question/29626/binary-variable-in-mixed-integer-linear-program/Hi asksage!
I'm using the `MixedIntegerLinearProgram` class to model a mixed integer linear program. I am using binary variables created e.g. by `x = mip.new_variable(binary=True, name="x")`. Now, I am using this variable e.g. by `x[0]` or `x[3,2]`. When I create a constraint using sums over binary variables, this sum is in the integers, as it should be. However, I am wondering if there is another way to easily add such variables together over `GF(2)` such that e.g. `x[0] + x[0]` disappears from the equation?
I ask because my model is too complicated to write by hand, so I am using some auxiliary methods to construct constraints and variables, etc.
I hope you can help me out!mmlauridsenMon, 28 Sep 2015 08:58:51 +0200https://ask.sagemath.org/question/29626/Why are the binary tarballs for Debian/Ubuntu the only ones provided officially for SageMath?https://ask.sagemath.org/question/28795/why-are-the-binary-tarballs-for-debianubuntu-the-only-ones-provided-officially-for-sagemath/I have been wondering why the only binaries for SageMath that are provided officially via the Sage mirrors are for Debian/Ubuntu only. Like, I do understand that Debian and Ubuntu are amongst the most popular Linux distributions, but Arch Linux, CentOS, Fedora, Mageia, openSUSE, PCLinuxOS and Gentoo/Sabayon Linux also rank high in popularity amongst Linux distributions (according to [DistroWatch](http://distrowatch.com/dwres.php?resource=popularity), for example).
For Arch Linux there's a fairly up-to-date SageMath package in the official repository ([here it is](https://www.archlinux.org/packages/community/x86_64/sagemath/)), but with SageMath 6.8 I noticed it lagged about 3 days behind the release of SageMath Linux binaries provided by the official mirrors.
I also wanted to know why Debian and Ubuntu binaries are provided as tarballs and not as the more easily-installed `.deb` package format. Fusion809Mon, 10 Aug 2015 04:57:25 +0200https://ask.sagemath.org/question/28795/PIP Install Fail 6.5https://ask.sagemath.org/question/26084/pip-install-fail-65/I download sage-6.5-x86_64-Darwin-OSX_10.7_x86_64-app.dmg. Everything seemed fine, but I tried to using ./sage pip install pandas and got the following error:
error: command 'gcc' failed with exit status 1
----------------------------------------
Cleaning up...
Command /Applications/sage-6.5.app/contents/resources/sage/local/bin/python -c "import setuptools, tokenize;__file__='/private/var/folders/q5/mcrwfjqj7_l3gjlqtx02d2g40000gn/T/pip_build_eh/pandas/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/q5/mcrwfjqj7_l3gjlqtx02d2g40000gn/T/pip-678ua0-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /private/var/folders/q5/mcrwfjqj7_l3gjlqtx02d2g40000gn/T/pip_build_eh/pandas
I also tried ./sage --sh followed by pip install pandas and received the same error.
A somewhat similar question is listed here: http://ask.sagemath.org/question/10978/how-to-upgrade-a-python-package-with-pip/
I used what was listed there, but have been unable to figure out how to solve this issue.
jahmul14Mon, 09 Mar 2015 01:00:10 +0100https://ask.sagemath.org/question/26084/Exact syntax for bdisthttps://ask.sagemath.org/question/7979/exact-syntax-for-bdist/I get tripped up on this all the time. What is the *exact* syntax for creating a 'canonical' binary distribution? (I assume there are scripts on [home/release](http://sage.math.washington.edu/home/release) for this, but I want this here where I can find it again.)
What I mean is what extra commands do I put in
./sage -bdist
in order to create something like `sage-4.6-OSX-32bit-10.4-i386-Darwin.dmg` or `sage-4.6.1-linux-32bit-ubuntu_10.04_lts-i686-Linux.tar`? I think that that version number comes for free, and I'm not worried about the file extension, but I don't know about the rest and want to do it right.
I THINK it is
./sage -bdist OSX-32bit-10.4-i386-Darwin
but I'm just not sure, and don't want to waste time making a mistake.
Edit: I see the following in sage-bdist
if [ $# -ne 2 ]; then
echo "Usage: $0 <SAGE_VERSION> <SAGE_ROOT>"
exit 1
fi
but the following in sage-sage
if [ "$1" = '-bdist' -o "$1" = "--bdist" ]; then
if [ $# -ne 2 ]; then
echo >&2 "** MISSING VERSION NUMBER! **"
exit 1
fi
sage-bdist $2 "$SAGE_ROOT"
exit $?
fi
is a little annoying - it's not clear whether you can even get to the 'usage' place in sage-bdist.
(Hint is that I think the answer to my question is in the rest of sage-bdist, but I'm too lazy to figure it out exactly now.)kcrismanWed, 02 Mar 2011 08:06:45 +0100https://ask.sagemath.org/question/7979/Binary Field Multiplicationhttps://ask.sagemath.org/question/23707/binary-field-multiplication/Hi,
I was trying to verify the binary field multiplication required to perform the GHASH part of the [Galois/Counter Mode (GCM)](http://csrc.nist.gov/publications/nistpubs/800-38D/SP-800-38D.pdf) for block ciphers using Sage. In order to do so, I need to compute a multiplication in `GF(2^128)` using the provided irreducible polynomial `p(x) = x^128 + x^7 + x^2 + x + 1`.
I took *Test Case 2* of *Appendix B* from [this](http://csrc.nist.gov/groups/ST/toolkit/BCM/documents/proposedmodes/gcm/gcm-revised-spec.pdf) source. According to the specification of the standard, multiplying the ciphertext, denoted by `C`, with the hash subkey `H` (both values are represented by bit vectors containing the coefficients of their respective polynomial representation using hexadecimal basis) should give the result `X1`. I tried to compute the product (again represented in a hexadecimal value as provided in the standard) as follows:
<pre><code>sage: print version();
Sage Version 6.2, Release Date: 2014-05-06
sage: # Get test vectors from the document linked above (Test Case 2).
sage: C = Integer(0x0388dace60b6a392f328c2b971b2fe78);
sage: H = Integer(0x66e94bd4ef8a2c3b884cfa59ca342b2e);
sage: X1_exp = Integer(0x5e2ec746917062882c85b0685353deb7); # Expected product
sage: # Create the binary finite field using the given irreducible polynomial.
sage: P2.<x> = GF(2)[];
sage: p = x^128 + x^7 + x^2 + x + 1;
sage: GFghash = GF(2^128, 'x', modulus=p); GFghash
Finite Field in x of size 2^128
sage: # Create the field elements from the hexadecimal representation and multiply them.
sage: C_bf = GFghash._cache.fetch_int(C);
sage: H_bf = GFghash._cache.fetch_int(H);
sage: X1_bf = C_bf * H_bf;
sage: # Convert the field element back into a HEX representation containing the coefficients only.
sage: X1_bitvec = ''.join(map(str,X1_bf.polynomial().coeffs()));
sage: X1 = Integer(str(X1_bitvec)[::-1], base=2);
sage: # Check whether the result is correct.
sage: X1 == X1_exp
False
</code></pre>
Unfortunately, as you can see from the output, I do not get the expected result of the multiplication (as printed in the document referenced above). Interestingly, when I perform this calculation within a smaller field (for which I can verify the result by paper and pencil), for instance in `GF(2^4)`, the approach actually works (or at least I get the result I expected):
<pre><code>sage: print version();
Sage Version 6.2, Release Date: 2014-05-06
sage: # Use two elements of GF(2^4) represented by a hexadecimal coefficient bit vector.
sage: C = Integer(0xa); # a = x^3 + x = 1010(bin) = 10(dec) = a(hex)
sage: H = Integer(0xa);
sage: X1_exp = Integer(0x8); # Expected product = x^3 = 1000(bin) = 8(dec) = 8(hex)
sage: # Create the binary finite field using the given irreducible polynomial p(x) = x^4 + x + 1;
sage: P2.<x> = GF(2)[];
sage: p = x^4 + x + 1;
sage: GF16 = GF(2^4, 'x', modulus=p); GF16
Finite Field in x of size 2^4
sage: # Create the field elements from the hexadecimal representation and multiply them.
sage: C_bf = GF16._cache.fetch_int(C);
sage: H_bf = GF16._cache.fetch_int(H);
sage: X1_bf = C_bf * H_bf;
sage: # Convert the field element back into a HEX representation containing the coefficients only.
sage: X1_bitvec = ''.join(map(str,X1_bf.polynomial().coeffs()));
sage: X1 = Integer(str(X1_bitvec)[::-1], base=2);
sage: # Check whether the result is correct.
sage: X1 == X1_exp
True
</code></pre>
The actual questions I have right now, are:
1. Are there any limitations with regard to the maximum degree of the binary extension field with the approach I am using here?
2. If possible, can anybody point me to the mistake I am doing when operating in `GF(2^128)`?
Thanks,
MikemikemichiThu, 07 Aug 2014 10:48:35 +0200https://ask.sagemath.org/question/23707/Binary fieldshttps://ask.sagemath.org/question/11059/binary-fields/Hello, I would like to perform the following on a binary field, i.e. `GF(2^m)`.
1. Define a polynomial and solve the polynomial over a binary field.
2. Convert an element of the binary field into a bit string.
For the first, I've tried the following:
K = GF(2^7,'a');
PK.<x>=K[]; #I've also tried "x = PolynomialRing(GF(2^7,'a'),'x').gen"
f = (a^6 + a^3 + a)*x^2 + (a^6 + a^4 + a^3)*x + (a^5 + a^4 + a^3 + a^2 + 1);
print f.roots();
But the error is `TypeError: unable to coerce from a finite field other than the prime subfield`.
For the second, I would like to know how finite field elements are stored in SAGE, are they stored as vectors?
If you have any resources that could point me in the right direction, I'll be very thankful for your help!BlackadderThu, 05 Jun 2014 23:05:40 +0200https://ask.sagemath.org/question/11059/OS X 10.8.5 installation failurehttps://ask.sagemath.org/question/10619/os-x-1085-installation-failure/I downloaded the OS X binary: sage-5.12-OSX-64bit-10.8-x86_64-Darwin-app.dmg
It installed the software (2.66GB). When I launch the program, it fails to launch the Notebook (although a kind of welcome screen comes up in the browser). The message on the command line is:
dyld: Library not loaded: /usr/local/lib/libreadline.5.2.dylib
Referenced from: /usr/local/bin/bash
Reason: no suitable image found. Did find:
/usr/local/lib/libreadline.5.2.dylib: stat() failed with errno=13
/usr/local/lib/libreadline.5.2.dylib: stat() failed with errno=13
Trace/BPT trap: 5
I read several previous messages about dyld failures on OS X. Some suggested I needed to install ImageMagick (I have no idea why). I did that, but still get the error message above.
Then I noticed that /usr/local/lib had restrictive permissions so I reset it to Everyone read/write.
But I still get almost the same error message on the command line:
dyld: Library not loaded: /usr/local/lib/libreadline.5.2.dylib
Referenced from: /usr/local/bin/bash
Reason: image not found
Trace/BPT trap: 5
The only things on /usr/local/lib are three directories - two versions of ImageMagick and one of audacity. The only things in the ImageMagick directories are more subdirectories and the file configure.xml The only thing in the audacity directory is libmp3lame.dylib
What is libreadline.5.2.dylib and where can I get it? I believe it is some gnu dynamic library for commandline editing.
j
almagestThu, 17 Oct 2013 14:48:31 +0200https://ask.sagemath.org/question/10619/Is there a server (ftp server?) that keeps old sage binaries?https://ask.sagemath.org/question/9309/is-there-a-server-ftp-server-that-keeps-old-sage-binaries/I can find any old sage binaries on the web. The sage server and mirrors erase any links to the old ones. I am sure there are kept somewhere.
I would like to try the sage cell server (I need Sage 5.0 on Ubuntu 10.04) but I do not intend to compile the source.shoibalcTue, 11 Sep 2012 00:43:37 +0200https://ask.sagemath.org/question/9309/looking for a sage 4.3.3 binaryhttps://ask.sagemath.org/question/9170/looking-for-a-sage-433-binary/hi, could somebody upload sage 4.3.3 binary plz? i have win7 :\ and i can't compile it under vm..
i have some old scripts i'd like to examine that don't run under the new sage..idLFri, 10 Aug 2012 09:18:36 +0200https://ask.sagemath.org/question/9170/Fedora 14 binaryhttps://ask.sagemath.org/question/8132/fedora-14-binary/Dear all,
I just installed sage-4.7-linux-64bit-fedora_release_14_laughlin_-x86_64-Linux.tar.lzma on my computer running Fedora 14:
boole[~]$ uname -a
Linux boole.math.utk.edu 2.6.35.12-90.fc14.x86_64 #1 SMP Fri Apr 22 16:01:29 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux
But I'm getting the following error:
ImportError: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.15' not found (required by /work/local/sage-4.7/local/lib/python2.6/site-packages/sage/rings/finite_rings/element_givaro.so)
Error importing ipy_profile_sage - perhaps you should run %upgrade?
WARNING: Loading of ipy_profile_sage failed.
I do get a prompt but
sage: 2+2
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
/work/local/sage-4.7/local/bin/<ipython console> in <module>()
NameError: name 'Integer' is not defined
Can this be fixed or should I just compile it from source.
Thanks,
LuisfinottiFri, 27 May 2011 11:48:59 +0200https://ask.sagemath.org/question/8132/