157 views

Skip to first unread message

Apr 30, 2024, 3:29:35 AMApr 30

to sage-...@googlegroups.com

Hi all,

My team is about to develop a webapp where we want to factor polynomials with coefficients in ZZ.

We want to offer a dropdown menu where the user can select the base ring and then the factorisation changes interactively. We use React and JavaScript and also Web Assembly, e.g. for our Web-OpenSSL here: https://www.cryptool.org/en/cto/openssl/

Sage offers the command change_ring, we did not find a JavaScript Library that has this functionality. So I thought, perhaps we could look for solutions where Sage is used together with web assembly.

After some research I have the impression that there are some proofs of concept, but there is nothing actively developed?

Since I am not a programmer and nobody in my team is a mathematician (so my developers don't know Sage), I kindly ask on this list for any hints how we could proceed?

Thanks in advance

Doris

My team is about to develop a webapp where we want to factor polynomials with coefficients in ZZ.

We want to offer a dropdown menu where the user can select the base ring and then the factorisation changes interactively. We use React and JavaScript and also Web Assembly, e.g. for our Web-OpenSSL here: https://www.cryptool.org/en/cto/openssl/

Sage offers the command change_ring, we did not find a JavaScript Library that has this functionality. So I thought, perhaps we could look for solutions where Sage is used together with web assembly.

After some research I have the impression that there are some proofs of concept, but there is nothing actively developed?

Since I am not a programmer and nobody in my team is a mathematician (so my developers don't know Sage), I kindly ask on this list for any hints how we could proceed?

Thanks in advance

Doris

Apr 30, 2024, 8:46:18 AMApr 30

to sage-...@googlegroups.com

Hi Doris,

I believe some parts of Sage can be used in WASM (via pyodide) but

others cannot so I am not sure if it is possible to get the

functionality that you want from Sage in WASM.

It is however possible to use SymPy in WASM (via pyodide) as

demonstrated here using JupyterLite:

https://live.sympy.org/

You should be able to test the following commands in SymPy Live which

I assume is the functionality that you are looking for:

factor(x**2 + 1, domain=QQ)

factor(x**2 + 1, domain=ZZ_I)

factor(x**2 + 1, domain=GF(2))

--

Oscar

> --

> You received this message because you are subscribed to the Google Groups "sage-devel" group.

> To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+...@googlegroups.com.

> To view this discussion on the web visit https://groups.google.com/d/msgid/sage-devel/08830539-4D13-4E63-80E0-4F1F788B1657%40me.com.

I believe some parts of Sage can be used in WASM (via pyodide) but

others cannot so I am not sure if it is possible to get the

functionality that you want from Sage in WASM.

It is however possible to use SymPy in WASM (via pyodide) as

demonstrated here using JupyterLite:

https://live.sympy.org/

You should be able to test the following commands in SymPy Live which

I assume is the functionality that you are looking for:

factor(x**2 + 1, domain=QQ)

factor(x**2 + 1, domain=ZZ_I)

factor(x**2 + 1, domain=GF(2))

--

Oscar

> You received this message because you are subscribed to the Google Groups "sage-devel" group.

> To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+...@googlegroups.com.

> To view this discussion on the web visit https://groups.google.com/d/msgid/sage-devel/08830539-4D13-4E63-80E0-4F1F788B1657%40me.com.

Apr 30, 2024, 9:37:36 AMApr 30

to sage-...@googlegroups.com

On Tue, Apr 30, 2024 at 3:29 AM 'Doris Behrendt' via sage-devel <sage-...@googlegroups.com> wrote:

Hi all,

My team is about to develop a webapp where we want to factor polynomials with coefficients in ZZ.

We want to offer a dropdown menu where the user can select the base ring and then the factorisation changes interactively. We use React and JavaScript and also Web Assembly, e.g. for our Web-OpenSSL here: https://www.cryptool.org/en/cto/openssl/

Sage offers the command change_ring, we did not find a JavaScript Library that has this functionality. So I thought, perhaps we could look for solutions where Sage is used together with web assembly.

What base rings do you intend to support? The hard part is the factoring itself, not the change_ring (which basically only requires that you have a reasonable internal representation for that base ring). Reasonable base rings that I can think of:

* Finite fields GF(p) with p prime

* Finite fields GF(q) with q a prime power

* Complex numbers

* Real numbers

* p-adic numbers for prime p

* Number fields

* the integers themselves

* Z/N for N not prime (there are tricky issues here, since factorization is no longer unique)

Sage mainly uses other open source C libraries to carry out these factorizations, so you would need to be able to port these to wasm as well. The underlying C libraries used vary by base field, and include pari, FLINT, NTL and maybe others. You can figure out what is used by each base ring using the get_systems function (note the warning displayed; I haven't recompiled my sage):

sage: from sage.misc.citation import get_systems

sage: R.<x> = ZZ[]

sage: f = (x^4 + 2)*(x^3 - 3)

sage: get_systems("factor(f)")

<ipython-input-101-7ff638a220bf>:1: UserWarning: get_systems() requires Cython profiling to be enabled, otherwise the results will be very unreliable. Rebuild Sage with the environment variable 'SAGE_PROFILE=yes' to enable profiling.

get_systems("factor(f)")

['FLINT']

sage: R.<x> = ZZ[]

sage: f = (x^4 + 2)*(x^3 - 3)

sage: get_systems("factor(f)")

<ipython-input-101-7ff638a220bf>:1: UserWarning: get_systems() requires Cython profiling to be enabled, otherwise the results will be very unreliable. Rebuild Sage with the environment variable 'SAGE_PROFILE=yes' to enable profiling.

get_systems("factor(f)")

['FLINT']

Finally, you should think about what scope you want to support in terms of degree (and, to a lesser extent, size of coefficients), as well as whether you want to allow non-monic polynomials.

Good luck!

David

After some research I have the impression that there are some proofs of concept, but there is nothing actively developed?

Since I am not a programmer and nobody in my team is a mathematician (so my developers don't know Sage), I kindly ask on this list for any hints how we could proceed?

Thanks in advance

Doris

Apr 30, 2024, 10:52:15 AMApr 30

to sage-...@googlegroups.com

> > Since I am not a programmer and nobody in my team is a mathematician (so my developers don't know Sage), I kindly ask on this list for any hints how we could proceed?

> Sage mainly uses other open source C libraries to carry out these factorizations, so you would need to be able to port these to wasm as well.

To be clear, porting parts of Sage or the underlying C libraries to
WASM/pyodide is a formidable task even for a mathematical programmer.

That is why I suggested SymPy instead since it already works in

WASM/pyodide.

SymPy does not provide factorisation over as many different rings as

Sage does but is easy to install and use in WASM via pyodide:

https://pyodide.org/en/stable/

You can just micropip.install('sympy') and add a short snippet of

Python code to use SymPy from JS:

https://pyodide.org/en/stable/usage/loading-packages.html

The next release of SymPy (1.13) can make use of python-flint for

factorisation of some polynomials using the underlying Flint C

library. Also python-flint has been ported to pyodide so it should be

possible to use SymPy backed by Flint in WASM:

https://pyodide.org/en/latest/usage/packages-in-pyodide.html

In future if Sage becomes more usable from WASM/pyodide then I assume

that you would be able to use it in the same way via pyodide. As I

understand it though it is not possible right now to install enough

pieces of Sage in pyodide to be able to factorise a polynomial. I

imagine that making that work using Sage would require some

significant porting work that is likely out of scope for a team of

non-mathematicians who do not know Sage or its dependencies.

--

Oscar

Apr 30, 2024, 1:06:08 PMApr 30

to sage-devel

Hi Doris,

porting Sage to pyodide is in progress, see https://github.com/sagemath/sage/issues/34539, but it's not ready to be used for what you have in mind.

I second Oscar's suggestion to look into using **sympy** and/or **python-flint**.

The current status of the Sage pyodide port:

- Some key dependencies of Sage will be shipped with the next pyodide release (0.26): **ipython**, **cysignals**, *ppl*/**pplpy**, *flint*, **memory_allocator**

- https://github.com/pyodide/pyodide/pull/4438 provides the fundamental modularized distribution packages **sagemath-objects**, **sagemath-categories**, **sagemath-environment**, **sagemath-repl**

The current bottlenecks / next steps:

- Adding the modularized distribution packages that provide more parts of Sage, in particular **sagemath-pari** and **sagemath-flint**: https://github.com/sagemath/sage/pull/37900, https://github.com/sagemath/sage/pull/37901 (needs review)

Matthias

Apr 30, 2024, 5:57:02 PMApr 30

to Dima Pasechnik, sage-...@googlegroups.com, wst...@cocalc.com

Hi,

Thanks Dima for mentioning CoWasm. Unfortunately, I ran out of resources to work on cowasm, so there likely

won't be any further work on it until things change.

-- William

On Tue, Apr 30, 2024 at 2:53 PM Dima Pasechnik <dim...@gmail.com> wrote:

It's interesting to compare this with the development by cocalc people, cowasm

<https://cowasm.org/>

Perhaps William can explain the differences.

Apr 30, 2024, 6:08:25 PMApr 30

to sage-...@googlegroups.com, wst...@cocalc.com

It's interesting to compare this with the development by cocalc people, cowasm

<https://cowasm.org/>

Perhaps William can explain the differences.

<https://cowasm.org/>

Perhaps William can explain the differences.

On 30 April 2024 18:00:26 BST, Matthias Koeppe <matthia...@gmail.com> wrote:

May 2, 2024, 10:42:51 AMMay 2

to sage-devel

giac has a wasm version, that support factoring over Q, Q[extension], approx real, approx complex, Z/pZ and GF(p,n). Example:

An example of simple webapp using the giac wasm kernel is available here https://www-fourier.univ-grenoble-alpes.fr/~parisse/giacjs/

Reply all

Reply to author

Forward

0 new messages

Search

Clear search

Close search

Google apps

Main menu