{"id":21053268,"url":"https://github.com/lsevero/clj-maxima","last_synced_at":"2025-05-15T21:36:44.181Z","repository":{"id":43859658,"uuid":"358934367","full_name":"lsevero/clj-maxima","owner":"lsevero","description":"Maxima as a clojure library","archived":false,"fork":false,"pushed_at":"2022-02-15T19:16:08.000Z","size":25283,"stargazers_count":35,"open_issues_count":1,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-03T15:52:32.515Z","etag":null,"topics":["abcl","clojure","common-lisp","maxima"],"latest_commit_sha":null,"homepage":"","language":"Clojure","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lsevero.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-04-17T16:56:43.000Z","updated_at":"2024-08-02T00:22:20.000Z","dependencies_parsed_at":"2022-09-06T10:01:38.655Z","dependency_job_id":null,"html_url":"https://github.com/lsevero/clj-maxima","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lsevero%2Fclj-maxima","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lsevero%2Fclj-maxima/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lsevero%2Fclj-maxima/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lsevero%2Fclj-maxima/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lsevero","download_url":"https://codeload.github.com/lsevero/clj-maxima/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254425815,"owners_count":22069239,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["abcl","clojure","common-lisp","maxima"],"created_at":"2024-11-19T16:05:36.236Z","updated_at":"2025-05-15T21:36:39.174Z","avatar_url":"https://github.com/lsevero.png","language":"Clojure","funding_links":[],"categories":[],"sub_categories":[],"readme":"# clj-maxima\n\n[Maxima](https://maxima.sourceforge.io/) as a Clojure library, using [ABCLJ](https://github.com/lsevero/abclj).\n\n[![Clojars Project](https://img.shields.io/clojars/v/org.clojars.lsevero/clj-maxima.svg)](https://clojars.org/org.clojars.lsevero/clj-maxima)\n\n## But... how?\n\nMaxima is written in Common Lisp, and can be used as a Common Lisp library.\nMaxima by itself has a good Common Lisp interop with options to even switch to the Common Lisp REPL and go back to the Maxima REPL.\n\nWith the powers of [ABCL](https://abcl.org/) and [ABCLJ](https://github.com/lsevero/abclj) we can interop with Common Lisp software from Clojure very easily, **without any servers or subprocessing**.\nMost of the Maxima integrations I've seen depends of having a Maxima installed in your machine (for example [Maxima.jl](https://github.com/nsmith5/Maxima.jl) ), opens the Maxima repl on a subprocess pipe and send commands to it.\nThis library access the Maxima functions directly through ABCL, everything happens on the same JVM process (clojure, common lisp or maxima code).\nYou don't even need Maxima installed in your machine to use this library, this library already have Maxima binaries for ABCL which will be extracted and loaded in the Common Lisp environment automatically.\n\nMaxima is an outstanding project. Is the oldest computer program that I know that is used until nowadays (Macsyma dates from the 60's!!).\nWith this library I hope to improve the clojure current state for scientific computation, and improve Maxima and Common Lisp reach.\n\nCurrently this library is using Maxima version 5.44.0 and ABCL version 1.8.0.\n\n## Usage\n\nMaxima and this library relies 100% on Common Lisp interop, which means that most of the time you will be working with Common Lisp data.\nMaxima does not directly eval code in Maxima syntax, it always convert to its lisp list syntax, for example the maxima expression `x*sin(a*x)` is evaluated to `((MAXIMA::MTIMES MAXIMA::SIMP) MAXIMA::$X ((MAXIMA::%SIN MAXIMA::SIMP) ((MAXIMA::MTIMES MAXIMA::SIMP) MAXIMA::$A MAXIMA::$X)))` in lisp.\nIt is perfectly fine to use this lisp syntax in this library along with Common Lisp interop, but things can become ugly pretty quickly.\nI recommend to use Maxima code with Maxima syntax, and just use the Lisp syntax when needed.\nIf you need to build maxima expressions programmatically try using `mexpr`.\n\n\nTo use maxima syntax use the `meval` function.\n\n```clojure\n(require '[clj-maxima.core :as m])\n(require '[abclj.core :as cl])\n\n(m/meval \"integrate(x*sin(a*x),x)\")\n; ==\u003e returns\n;#abclj/cl-cons ((MAXIMA::MTIMES MAXIMA::SIMP) ((MAXIMA::MEXPT MAXIMA::SIMP) MAXIMA::$A -2) ((MAXIMA::MPLUS MAXIMA::SIMP) ((MAXIMA::MTIMES MAXIMA::SIMP) -1 MAXIMA::$A MAXIMA::$X ((MAXIMA::%COS MAXIMA::SIMP) ((MAXIMA::MTIMES MAXIMA::SIMP) MAXIMA::$A MAXIMA::$X))) ((MAXIMA::%SIN MAXIMA::SIMP) ((MAXIMA::MTIMES MAXIMA::SIMP) MAXIMA::$A MAXIMA::$X))))\n\n;eval and pretty print\n(m/mevalp \"integrate(x*sin(a*x),x)\")\n; ==\u003e prints\n;sin(a x) - a x cos(a x)\n;-----------------------\n;           2\n;          a\n```\n\nIt is possible to create maxima expressions using clojure primitives using `mexpr`:\n```clojure\n(m/mexpr '[= [+ [** $%e [* $%pi $%i]] 1] 0])\n;=\u003e returns\n; #abclj/cl-cons ((MAXIMA::MEQUAL) ((MAXIMA::MPLUS) ((MAXIMA::MEXPT) MAXIMA::$%E ((MAXIMA::MTIMES) MAXIMA::$%PI MAXIMA::$%I)) 1) 0)\n\n(m/displap (m/mexpr '[= [+ [** $%e [* $%pi $%i]] 1] 0]))\n;=\u003eprints\n;  %pi %i\n;%e       + 1 = 0\n```\n\nTo create Maxima lists use `mlist`:\n```clojure\n(m/displap (m/mlist '$x -5 5))\n;=\u003e [x, - 5, 5]\n```\n\nThis library does not provides wrapper functions to all maxima functions (really, it is a lot of them to maintain, see [Maxima Function and Variable Index](https://maxima.sourceforge.io/docs/manual/maxima_363.html#Function-and-Variable-Index)\n), but it provides a unified way to access and call all of maxima functions using the `clj-maxima.core/funcall` function.\nIt is important to notice that common maxima functions can be accessed in lisp with a `$` prefix on the symbol, so the maxima function `diff` is accessed by the symbol `$diff` in lisp for example (see [Lisp and Maxima](https://maxima.sourceforge.io/docs/manual/maxima_165.html#Lisp-and-Maxima) for more details). This is also true for constants, for example `%pi` is accessed in lisp with `$%pi`.\nTo maintain consistency with the Maxima documentation in this library we keep this convention and never auto prefix any symbol with a `$`.\nWhen using `clj-maxima.core/funcall` we automatically put the maxima namespace on all symbols and convert them to their common lisp correspondent classes, if a clojure sequential is passed as a argument `mexpr` will be applied.\n\n`funcall` examples:\n```clojure\n(require '[clj-maxima.core :refer :all])\n\n(funcall '$diff '[** $x 3] '$x)\n;is equivalent to\n(meval \"diff(x**3,x)\")\n\n(displap (funcall '$solve '[= 0 [* [+ [$f $x] -1] [$asin [$cos [* 3 $x]]]]] '$x))\n;=\u003e prints\n;     %pi\n;[x = ---, f(x) = 1]\n;      6\n; is equivalent to\n(mevalp \"solve(asin (cos (3*x))*(f(x) - 1)=0,x)\")\n```\n\n\n## Plotting\n\nPlotting is fully supported, however it **needs gnuplot installed in your system**.\nMaxima alone does not have any GUI facilities, when asked for plots it creates arrays of points and passes to a external program.\nWhen you call the plotting functions Maxima will look for the `gnuplot` binary on your `$PATH`, if it does not find will raise an exception.\n\nTo install gnuplot (on Debian based distributions):\n```bash\nsudo apt install gnuplot-x11\n```\n\nTo plot use:\n```clojure\n(require '[clj-maxima.core :as m])\n(require '[abclj.core :as cl])\n\n(m/meval \"plot2d(x^2,[x,-5,5])\")\n\n;or use funcall\n(m/funcall '$plot2d '[** $x 2] (m/mlist '$x -5 5))\n\n;or call the Maxima lisp functions directly using the lisp syntax through abcl java api\n(cl/funcall (cl/getfunction 'maxima/$plot2d)\n            (cl/cl-cons '[[maxima/mexpt maxima/simp nil] maxima/$x 2 nil])\n            (cl/cl-cons '[[maxima/mlist maxima/simp nil] maxima/$x -5 5 nil]))\n\n;or even with the common lisp interpreter\n(cl/with-cl '(in-package :maxima)\n            '($PLOT2D '((MEXPT SIMP) $X 2) '((MLIST SIMP) $X -5 5)))\n```\n\n## Packaging\n\nclj-maxima is not a conventional clojure package, is half a clojure package and half a common lisp one.\nThe common lisp part (maxima itself) is bundled in this library as a zipped resource.\nWhen clj-maxima is `require`d it will unzip the common lisp portion to `(System/getProperty \"java.io.tmpdir\")` and then import it to the common lisp environment.\nThis is necessary because of maxima package system. If it is necessary to change the location of maxima change this property on clojure boot.\n\n\n## Important Links\n\n* [Call Maxima from Common Lisp](https://niitsuma.hatenadiary.org/entry/20080328/1226706399)\n* [Introduction to Maxima](https://maxima.sourceforge.io/docs/manual/intromax.html)\n* [Lisp and Maxima](https://maxima.sourceforge.io/docs/manual/maxima_165.html#Lisp-and-Maxima)\n* [ABCLJ Readme and tests](https://github.com/lsevero/abclj)\n* [Maxima download page (binaries and source code)](https://maxima.sourceforge.io/download.html)\n* [Maxima Function and Variable Index](https://maxima.sourceforge.io/docs/manual/maxima_363.html#Function-and-Variable-Index)\n\n## TODOS\n\n* mfuncall (call functions defined on maxima on cl/clj side).\n* maxima contrib packages.\n\n## License\n\nGNU General Public License v2.0\n\n(Same as Maxima)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flsevero%2Fclj-maxima","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flsevero%2Fclj-maxima","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flsevero%2Fclj-maxima/lists"}