User avatar
HermannSW
Posts: 6093
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany

wolframscript 1st experience

Thu Jun 01, 2023 3:14 pm

Yesterday I played with Pari/GP:
viewtopic.php?t=352122

So I wanted to give Mathematica a try as well.
I did execute "wolframscript" on 64bit Raspberry PiOS.
Factorization of integer works:

Code: Select all

In[1]:= FactorInteger[2^256-1]                                                          

Out[1]= {{3, 1}, {5, 1}, {17, 1}, {257, 1}, {641, 1}, {65537, 1}, {274177, 1}, 
 
>    {6700417, 1}, {67280421310721, 1}, {59649589127497217, 1}, 
 
>    {5704689200685129054721, 1}}

In[2]:=

Also factorization of gaussian integers works (complex numbers with real and imaginary part being integers).
Factorization of a prime p=1 (mod 4) results in determination of sum of squares, here 29=5^2 + 2^2:

Code: Select all

In[2]:= FactorInteger[29, GaussianIntegers->True]                                       

Out[2]= {{-I, 1}, {2 + 5 I, 1}, {5 + 2 I, 1}}

In[3]:=                                                                                 


I used https://www.wolframalpha.com/ (Wolfram language in the browser) back in 2014 to provide generating formula for sequence A098586 on oeis.org (online encyclopedia of integer sequences), see "MATHEMATICA" section:
https://oeis.org/A098586

Just works as well:

Code: Select all

In[3]:= LinearRecurrence[{3, -1, -1}, {2, 5, 13}, 28]                                   

Out[3]= {2, 5, 13, 32, 78, 189, 457, 1104, 2666, 6437, 15541, 37520, 90582, 218685, 
 
>    527953, 1274592, 3077138, 7428869, 17934877, 43298624, 104532126, 252362877, 
 
>    609257881, 1470878640, 3551015162, 8572908965, 20696833093, 49966575152}

In[4]:=               

Yesterday I was very positively surprised of Pari's "factorint()" performance, it did factor 59 decimal digits number RSA-59 in 12 seconds on 1.8GHz Pi400!

Code: Select all

pi@pi400-64:~ $ time gp -q <(echo "print(factorint(71641520761751435455133616475667090434063332228247871795429));quit")
[200429218120815554269743635437, 1; 357440504101388365610785389017, 1]

real	0m12.048s
user	0m11.971s
sys	0m0.030s
pi@pi400-64:~ $ 
Python sympy "factorint()" took hours to factor that number ;-(
Now Mathematica does not take hours, but 13.5× the time of Pari:

Code: Select all

pi@pi400-64:~ $ time wolframscript -code "FactorInteger[71641520761751435455133616475667090434063332228247871795429]"
{{200429218120815554269743635437, 1}, {357440504101388365610785389017, 1}}

real	2m42.880s
user	0m1.478s
sys	0m1.959s
pi@pi400-64:~ $ 

Anyway, it is good to have access to Mathematica, although for interest in number theory I have there are killer arguments for Pari/GP as stated in the other posting:
https://oeis.org/wiki/PARI/GP#Comparison_to_other_CAS
In the domain of number theory, PARI/GP is a strong rival to well established all-purpose CAS as Maple and Mathematica, mainly due to its computational speed, where it typically outperforms both of these well known commercial CAS, and its free availability.

P.S:
I did measure factorization in wolframscript shell, took 2:28min, 14 seconds faster than above:

Code: Select all

pi@pi400-64:~ $ wolframscript
Wolfram Language 13.2.1 Engine for Linux ARM (64-bit)
Copyright 1988-2023 Wolfram Research, Inc.

In[1]:= FactorInteger[71641520761751435455133616475667090434063332228247871795429]      

Out[1]= {{200429218120815554269743635437, 1}, {357440504101388365610785389017, 1}}

In[2]:=                                                                                 

https://github.com/Hermann-SW/RSA_numbers_factored
https://stamm-wilbrandt.de/GS_cam_1152x192@304fps
https://hermann-sw.github.io/planar_graph_playground
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/

User avatar
HermannSW
Posts: 6093
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany

Re: wolframscript 1st experience

Sat Sep 30, 2023 7:49 pm

Unplanned I landed using wolframscript again today.

I knew that any postive integer can be expressed by sum of 4 squares.
Searched wikipedia:
https://en.wikipedia.org/wiki/Sum_of_sq ... ber_theory
--> https://en.wikipedia.org/wiki/Lagrange% ... re_theorem
--> https://en.wikipedia.org/wiki/Jacobi%27 ... re_theorem

Searched the web how I can compute all sum of 4 squares representations.
And found Wolfram page:
https://mathworld.wolfram.com/SumofSquaresFunction.html

That mentioned two functions, "SquaresR" for number of representations from last Wiki page above.
But more interestingly "PowersRepresentations" resulting in real representations:
https://reference.wolfram.com/language/ ... tions.html

Good that all PIs have free use of wolframscript, and so I tried:

Code: Select all

In[1]:= PowersRepresentations[17*29,4,2]                                        

Out[1]= {{0, 0, 3, 22}, {0, 0, 13, 18}, {0, 4, 6, 21}, {0, 5, 12, 18}, 
 
>    {1, 2, 2, 22}, {1, 10, 14, 14}, {2, 2, 14, 17}, {2, 5, 8, 20}, 
 
>    {2, 8, 8, 19}, {2, 8, 13, 16}, {2, 10, 10, 17}, {3, 4, 12, 18}, 
 
>    {3, 12, 12, 14}, {4, 4, 10, 19}, {4, 5, 14, 16}, {4, 10, 11, 16}, 
 
>    {6, 6, 14, 15}, {6, 12, 12, 13}, {8, 8, 13, 14}}

In[2]:=   
All these 4-tuples are sum of squares representations of 17*29=493.
Instead of having to program that functionality myself, I can just use wolframscript.


P.S:
With my RSA_numbers_factored repo from signature, I can create one sum of 4 squares representation.
Normally for RSA numbers, but passing "[0,0,p,q]" allows to use for any semiprime p*q:

Code: Select all

$ python -q
>>> from RSA_numbers_factored import *
>>> RSA=RSA()
>>> RSA.square_sums_4([0,0,17,29])
(20, 2, 8, 5)
>>> sq2(17)
(4, 1)
>>> sq2(29)
(5, 2)
>>> 
The last 3 lines in "RSA.square_sums_4()" implementation explain how to compute:
[ sq2(p) computes unique sum of two squares for prime p =1 (mod 4) ]

Code: Select all

        P = sq2(p)
        Q = sq2(q)
        return P[0] * Q[0], P[1] * Q[1], P[0] * Q[1], P[1] * Q[0]
https://github.com/Hermann-SW/RSA_numbers_factored
https://stamm-wilbrandt.de/GS_cam_1152x192@304fps
https://hermann-sw.github.io/planar_graph_playground
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/

User avatar
HermannSW
Posts: 6093
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany

Re: wolframscript 1st experience

Sun Nov 26, 2023 10:32 am

I work with Mathematica from time to time, mostly for functions I do not know how to do in PARI/GP.
Like Solve[] and FindInstance[], I use them with "Integers" variables restriction most times.
Here is a recent example of mixed PARI/GP and wolframscript FindInstance usage of me:
https://pari.math.u-bordeaux.fr/archive ... 00007.html

While my P400 is 5-7 times slower than my fastest PC, it is still fast enough for working with Mathematica for me.
And since Mathematica is free to use on Raspberry Pi computers, that is real value.

Since few days I work on implementing an interesting algorithm from 1878 in PARI/GP.
The German language paper is good to read for me language wise, but the formulas are difficult:
https://pdfhost.io/v/~OwxzpPNA_KUNERTH_1878

I was really surprised that while searching for that paper on the web, I got a hit on amazon.
The English language 47 pages ebook for 1$ only I found helped me much in programming:
(while it is a Kindle ebook, I can read it in browser with Pi400)
https://pari.math.u-bordeaux.fr/archive ... 00057.html

So why do I mention that here?
Title of the ebook is "Adolf Kunerth’s Modular Square Root Algorithm Explained: with examples in Mathematica".
And like me the author did use Mathematica on Raspberry computer (most likely because it is free to use):
Mathematica.ebook.jpg
Mathematica.ebook.jpg
Mathematica.ebook.jpg (75.42 KiB) Viewed 500 times
https://github.com/Hermann-SW/RSA_numbers_factored
https://stamm-wilbrandt.de/GS_cam_1152x192@304fps
https://hermann-sw.github.io/planar_graph_playground
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/

pidd
Posts: 5154
Joined: Fri May 29, 2020 8:29 pm
Location: Wirral, UK

Re: wolframscript 1st experience

Mon Nov 27, 2023 12:04 am

Wolfram on the Pi is only free for non-commercial use iirc

I use its symbolic mode mostly, its a quick way of simplifying or checking the equality of two algebraic equations.

ejolson
Posts: 11715
Joined: Tue Mar 18, 2014 11:47 am

Re: wolframscript 1st experience

Mon Nov 27, 2023 12:28 am

pidd wrote:
Mon Nov 27, 2023 12:04 am
Wolfram on the Pi is only free for non-commercial use iirc

I use its symbolic mode mostly, its a quick way of simplifying or checking the equality of two algebraic equations.
In some ways it's difficult to imagine what one would do with Mathematica on a Pi outside of an academic research and educational context.

My suspicion is the types of industrial projects where engineers would benefit from a computer algebra system are well funded and can afford the $3,652 license of the non-free version.

pidd
Posts: 5154
Joined: Fri May 29, 2020 8:29 pm
Location: Wirral, UK

Re: wolframscript 1st experience

Mon Nov 27, 2023 3:10 am

ejolson wrote:
Mon Nov 27, 2023 12:28 am
pidd wrote:
Mon Nov 27, 2023 12:04 am
Wolfram on the Pi is only free for non-commercial use iirc

I use its symbolic mode mostly, its a quick way of simplifying or checking the equality of two algebraic equations.
In some ways it's difficult to imagine what one would do with Mathematica on a Pi outside of an academic research and educational context.

My suspicion is the types of industrial projects where engineers would benefit from a computer algebra system are well funded and can afford the $3,652 license of the non-free version.
Maybe non-academic research as well, depends how you define academic research, it is slightly fuzzy in most subjects. Everything is getting modelled these days for creating or testing practical solutions, apart from packages like Mathematica (eg Maple) I don't know what else is out there for multi-variable calculus analysis and the like other than DIY with a generic programming language.

Education has to be the main customer, I've had the benefit of at least four licences from educational establishments and now I'm out of that game I have it on the Pi which is pretty good continuity without ever opening my wallet. I used it seriously for one year, I only use it now when desperate, its a handy tool in the toolbox and saves me relearning stuff that I will forget yet again.

ejolson
Posts: 11715
Joined: Tue Mar 18, 2014 11:47 am

Re: wolframscript 1st experience

Mon Nov 27, 2023 3:49 am

pidd wrote:
Mon Nov 27, 2023 3:10 am
ejolson wrote:
Mon Nov 27, 2023 12:28 am
pidd wrote:
Mon Nov 27, 2023 12:04 am
Wolfram on the Pi is only free for non-commercial use iirc

I use its symbolic mode mostly, its a quick way of simplifying or checking the equality of two algebraic equations.
In some ways it's difficult to imagine what one would do with Mathematica on a Pi outside of an academic research and educational context.

My suspicion is the types of industrial projects where engineers would benefit from a computer algebra system are well funded and can afford the $3,652 license of the non-free version.
Maybe non-academic research as well, depends how you define academic research, it is slightly fuzzy in most subjects. Everything is getting modelled these days for creating or testing practical solutions, apart from packages like Mathematica (eg Maple) I don't know what else is out there for multi-variable calculus analysis and the like other than DIY with a generic programming language.
As far as I know the free alternatives to Mathematica and Maple for general purpose computer algebra systems are Macsyma (now Maxima), Reduce, Axiom and FriCAS. Note that FriCAS is a fork of Axiom.

https://maxima.sourceforge.io/

http://www.reduce-algebra.com/

http://www.axiom-developer.org/

http://wiki.fricas.org/FrontPage

There used to be another software called MuPAD which was free but not open source. The technology behind MuPad was purchased by Matlab, watered down and then sold as the Symbolic Math Toolbox.

Of the above FriCAS is interesting because it implements most of the Risch algorithm for symbolic integration. None of the other CAS systems including Mathematica and Maple use such powerful methods.

On the other hand Mathematica and Maple also include graphing and numeric capabilities enhanced with a convenient user interface. This makes these two commercial packages more than general purpose computer algebra systems.

I'm more familiar with Maple because the university where I did my studies had a special deal, presumably related to a historical connection with the team that originally created Maple at the University of Waterloo. It seems 30 years have passed and that deal evaporated.

https://kb.iu.edu/d/ango

I don't know what happened.

There are some libraries for Python, notably SymPy, which are popular. I assume SymPy also works on a Raspberry Pi. I should try SymPy.

User avatar
Gavinmc42
Posts: 7999
Joined: Wed Aug 28, 2013 3:31 am

Re: wolframscript 1st experience

Mon Nov 27, 2023 6:44 am

ejolson, how do these compare to Julia?
I noticed Julia has some plotting features which is what I used Mathematica, for real time Stirling Engine Carnot Cycle.
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

ejolson
Posts: 11715
Joined: Tue Mar 18, 2014 11:47 am

Re: wolframscript 1st experience

Mon Nov 27, 2023 7:35 am

Gavinmc42 wrote:
Mon Nov 27, 2023 6:44 am
ejolson, how do these compare to Julia?
I noticed Julia has some plotting features which is what I used Mathematica, for real time Stirling Engine Carnot Cycle.
Julia is designed for numerical computing with a just-in-time compiler for performance and a read evaluate print loop as an environment for data visualisation, testing and analysis. Julia includes some libraries for symbolic mathematics, but it's not very good at that.

Mathematica is for symbolic computing and computer algebra, but includes libraries for numerical calculation. While there is a lot of overlap, it is not very good at numerics.

Your question seems to be about plotting in a context where there is not much numerical calculation nor computer algebra. I think either Julia or Mathematia can make publication-quality graphs. If only making graphs, I prefer Gnuplot which has a huge number of device drivers for different hardware.

http://www.gnuplot.info/

User avatar
HermannSW
Posts: 6093
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany

Re: wolframscript 1st experience

Mon Nov 27, 2023 7:14 pm

ejolson wrote:
Mon Nov 27, 2023 3:49 am
As far as I know the free alternatives to Mathematica and Maple for general purpose computer algebra systems are Macsyma (now Maxima), Reduce, Axiom and FriCAS. Note that FriCAS is a fork of Axiom.

https://maxima.sourceforge.io/

http://www.reduce-algebra.com/

http://www.axiom-developer.org/

http://wiki.fricas.org/FrontPage

You missed PARI/GP:
https://pari.math.u-bordeaux.fr/pub/par ... pdf#page=5
PARI/GP is a specialized computer algebra system, primarily aimed at number theorists, but has
been put to good use in many other different fields, from topology or numerical analysis to physics.

Although quite an amount of symbolic manipulation is possible, PARI does badly compared
to systems like Axiom, Magma, Maple, Mathematica, Maxima, or Reduce on such tasks, e.g. multivariate polynomials, formal integration, etc. On the other hand, the three main advantages of
the system are its speed, the possibility of using directly data types which are familiar to mathematicians, and its extensive algebraic number theory module (from the above-mentioned systems,
only Magma provides similar features).

oeis.org is very clear:
https://oeis.org/wiki/PARI/GP#Comparison_to_other_CAS
In the domain of number theory, PARI/GP is a strong rival to well established all-purpose CAS as Maple and Mathematica, mainly due to its computational speed, where it typically outperforms both of these well known commercial CAS, and its free availability.
https://github.com/Hermann-SW/RSA_numbers_factored
https://stamm-wilbrandt.de/GS_cam_1152x192@304fps
https://hermann-sw.github.io/planar_graph_playground
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/

User avatar
HermannSW
Posts: 6093
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany

Re: wolframscript 1st experience

Mon Nov 27, 2023 7:24 pm

pidd wrote:
Mon Nov 27, 2023 12:04 am
Wolfram on the Pi is only free for non-commercial use iirc
Interesting:
https://www.wolfram.com/legal/agreement ... pberry-pi/
Permitted Uses and Installations
Subject to the terms of this Agreement and Your acceptance thereof, WRI grants You a non-exclusive license to use the Product solely for personal or educational purposes on a Model A or Model B Raspberry Pi computer.
So use on compute module, Pi0s and my use on Pi400 are illegal ?!?!?
https://github.com/Hermann-SW/RSA_numbers_factored
https://stamm-wilbrandt.de/GS_cam_1152x192@304fps
https://hermann-sw.github.io/planar_graph_playground
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/

ejolson
Posts: 11715
Joined: Tue Mar 18, 2014 11:47 am

Re: wolframscript 1st experience

Mon Nov 27, 2023 9:18 pm

HermannSW wrote:
Mon Nov 27, 2023 7:24 pm
pidd wrote:
Mon Nov 27, 2023 12:04 am
Wolfram on the Pi is only free for non-commercial use iirc
Interesting:
https://www.wolfram.com/legal/agreement ... pberry-pi/
Permitted Uses and Installations
Subject to the terms of this Agreement and Your acceptance thereof, WRI grants You a non-exclusive license to use the Product solely for personal or educational purposes on a Model A or Model B Raspberry Pi computer.
So use on compute module, Pi0s and my use on Pi400 are illegal ?!?!?
I once asked for clarification and understood the license means to refer to any model of Raspberry Pi. It would be nice if the license were worded more clearly. Today I find it interesting that the license does not restrict which the operating system is used on the Pi. Maybe Mathematica under Ubuntu, Void or Arch Linux would also be fine as long as the hardware is a Raspberry Pi.

The flexible license is much of why Linux became standard environment for micro services and on the virtual machines in the cloud.

Return to “Wolfram Language”