Ask Your Question

Matteo's profile - activity

2023-08-28 05:10:22 +0200 received badge  Popular Question (source)
2019-06-05 20:55:28 +0200 received badge  Popular Question (source)
2018-10-17 12:53:17 +0200 commented answer How to use a software package available for SageMath

Nice! Thank you @slelievre, so SageMath has several interfaces for a lot of existing libraries!

And if I wanted to modify the source code of Rubik, by downloading the original version it in my cloud service and by modifying some pieces of code inside it, how could I reload it in SageMath (specifically SageMathCell) in order to use my modified code instead of the original one the user finds here?

In other words how could I modify the following sage commands (shown here) to use the modified version of "optimal.c" in my cloud?

from sage.interfaces.rubik import *
C = RubiksCube("R U")
CubexSolver().solve(C.facets())

Thank you

2018-10-17 11:21:30 +0200 asked a question How to use a software package available for SageMath

Hi. I know SageMath is meant for math (so here user should post questions related mainly to math problems with Sage), but I'm testing SageMath capabilities about use/loading of external libraries created by user (c, fortran, etc...), that is like a complete environment able to process other prog languages like C and Fortran (mainly for scientific purposes).

I've found here that SageMath can load and use some external libraries (not only python libraries) to allow user to perform some tasks with them.

For example I'd like to know how to use the Rubik program (a C program) for fun and for testing by using SageMath (specifically SageMathCell). It is listed in position 82 of the list here.

Can you kindly show me a procedure to load/compile/use this library available for SageMath? I'd like to run the compiled code to solve (only for fun) some virtual/random Rubik cubes. The procedure for Rubik library could help me to understand how to run other libraries listed in the link above.

Thanks

2018-10-08 17:08:34 +0200 received badge  Supporter (source)
2018-10-08 17:08:16 +0200 commented answer How to run Cython examples in SageMathCell

Hi @Iguananaut, thank you for testing it! Ok, I will try to contact the SageMathCell service to understand how to solve the problem.

For now I will try to perform some tests with C functions that are independent from the standard C input/output library.

Thanks, I appreciated your help.

2018-10-08 12:42:03 +0200 received badge  Editor (source)
2018-10-08 12:34:25 +0200 commented question How to run Cython examples in SageMathCell

Please can you run without problems the script in first post by using SageMathCell or not? I'm testing Cython features of the online service SageMathCell by following the simple example "How to call a C code (or a compiled library) from Sage?".

"hello_sage.pyx":

cdef extern from "Call_C_code/hello_test.c":
    void hello_world()

def my_bridge_function():
    hello_world() # This is the C function from hello_test.c

"hello_test.c":

#include <stdio.h>

void hello_world(){
    printf("Hello World\n");
}

Thanks

2018-10-08 12:29:11 +0200 commented question How to run Cython examples in SageMathCell

Hi @Iguananaut thank you for support, I try to describe better what I mean. I use sage only on the Internet using the free service SageMathCell. It is an online sagemath service.

Inside the zip folder "Call_C_code.zip" there are 3 files, one of them (text.txt) is a dummy text file I added for some tests, the other two files are the files of the example here. The two files for Cython test are: "hello_sage.pyx" and "hello_test.c".

Inside "hello_sage.pyx" there is the Cython code, while inside "hello_test.c" there is the C code. The content is, adapted on filenames, the same you find here.

2018-10-03 16:03:40 +0200 commented question How to run Cython examples in SageMathCell

Hi @Iguananaut thanks, I use sys.path.append() to be sure the remote python environment can find my files and libraries to be compiled in the temporary folder. Why it is not necessary?

"hello_sage.pyx" is a file containing: """ cdef extern from "hello.c": void hello_world()

def my_bridge_function(): hello_world() # This is the C function from hello.c """ as this link suggests. The path for "hello_sage.pyx", I suppose, is directory_name/Call_C_code, as indicated in "%runfile Call_C_code/hello_sage.pyx" and with the command "os.chdir(directory_name)" I'm sure my working folder is the temporary folder named "directory_name".

What is wrong? Thank you

2018-09-27 17:20:24 +0200 asked a question How to run Cython examples in SageMathCell

Hi, this is not a math question, this is a programming question.

I'm trying to run the first example at doc.sagemath.org/html/en/thematic_tutorials/cython_interface by using SageMathCell service (link).

For this, I've created a zip folder that I've stored in the cloud (Google Drive).

When I run the following python script in SageMathCell (I wrote it to test Cython capabilities in SageMath remote server), it seems good, but I can't see the output, that would be "Hello World".

This python script, after execution, ends with "Compiling ./Call_C_code/hello_sage.pyx..." without anyone else output.

Can you help me? Thanks,

import os
import tempfile
import sys
from distutils.dir_util import copy_tree

directory_name = tempfile.mkdtemp()
print(directory_name)
sys.path.append(directory_name)

#https://drive.google.com/open?id=129vvaCzB0M5iuPxdSdNWRG5A2gG0DwEu

import urllib
url = "https://drive.google.com/uc?export=download&id=129vvaCzB0M5iuPxdSdNWRG5A2gG0DwEu"
filename = "/Call_C_code.zip"
urllib.urlretrieve(url, directory_name + filename)

# opening the zip file in READ mode
from zipfile import ZipFile
os.chdir(directory_name)
file_name = "Call_C_code.zip"

with ZipFile(file_name, 'r') as zip:
    # extracting all the files
    print('Extracting all the files now...')
    zip.extractall()
    print('Done!')

print(sys.path)
print(os.getcwd())

for root, dirs, files in os.walk("."):  
    for filename in files:
        print(filename)

#############
%runfile Call_C_code/hello_sage.pyx
my_bridge_function()
2018-09-25 08:38:03 +0200 answered a question How to run Cython example with SageMathCell

Hi, I'm trying to run this example at doc.sagemath.org/html/en/thematic_tutorials/cython_interface by using SageMathCell service.

For this, I've created a zip folder that I've stored in the cloud (Google Drive).

When I run the following python script in SageMathCell, it seems good, but I can't see the output, that would be "Hello World".

import os
import tempfile
import sys
from distutils.dir_util import copy_tree

directory_name = tempfile.mkdtemp()
print(directory_name)
sys.path.append(directory_name)

#https://drive.google.com/open?id=129vvaCzB0M5iuPxdSdNWRG5A2gG0DwEu

import urllib
url = "https://drive.google.com/uc?export=download&id=129vvaCzB0M5iuPxdSdNWRG5A2gG0DwEu"
filename = "/Call_C_code.zip"
urllib.urlretrieve(url, directory_name + filename)

# opening the zip file in READ mode
from zipfile import ZipFile
os.chdir(directory_name)
file_name = "Call_C_code.zip"

with ZipFile(file_name, 'r') as zip:
    # extracting all the files
    print('Extracting all the files now...')
    zip.extractall()
    print('Done!')

print(sys.path)
print (os.getcwd())

for root, dirs, files in os.walk("."):  
    for filename in files:
        print(filename)

#############
%runfile Call_C_code/hello_sage.pyx
my_bridge_function()

This python script, after execution, ends with "Compiling ./Call_C_code/hello_sage.pyx..." without anyone else output.

Can you help me? Thanks,

2018-09-25 08:36:56 +0200 commented question How to run Cython example with SageMathCell

Hi @slelievre, yes you are right, it is a good idea I had not thought about. I write in the answer below my extensive question.

2018-09-25 04:09:03 +0200 received badge  Nice Question (source)
2018-09-24 21:16:36 +0200 received badge  Student (source)
2018-09-24 21:16:25 +0200 asked a question How to run Cython example with SageMathCell

Hi, how can I run the first Cython example by using SageMathCell? Sorry the poor question , but Ask Sagemath requires I have more than 1 karma to post link (OMG)... Thank you