{"id":19229221,"url":"https://github.com/ndrean/mandelbrot","last_synced_at":"2026-05-16T09:32:31.837Z","repository":{"id":260960571,"uuid":"882602797","full_name":"ndrean/mandelbrot","owner":"ndrean","description":"Mandelbrot set and orbits with Zig, Zigler and Elixir Nx in a Livebook","archived":false,"fork":false,"pushed_at":"2024-12-10T08:08:16.000Z","size":48243,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-23T10:43:25.896Z","etag":null,"topics":["elixir","livebook","mandelbrot-set","mandelbrot-viewer","nx","zig","zigler"],"latest_commit_sha":null,"homepage":"https://ndrean.github.io/zig-assembly-test/","language":"Zig","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ndrean.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-03T09:49:02.000Z","updated_at":"2024-12-10T08:08:20.000Z","dependencies_parsed_at":"2024-11-03T22:25:02.352Z","dependency_job_id":"501f68cb-76b8-42c2-9b8c-2c1459f82937","html_url":"https://github.com/ndrean/mandelbrot","commit_stats":null,"previous_names":["ndrean/mandelbrot"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ndrean/mandelbrot","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ndrean%2Fmandelbrot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ndrean%2Fmandelbrot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ndrean%2Fmandelbrot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ndrean%2Fmandelbrot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ndrean","download_url":"https://codeload.github.com/ndrean/mandelbrot/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ndrean%2Fmandelbrot/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33096870,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-16T04:41:52.686Z","status":"ssl_error","status_checked_at":"2026-05-16T04:41:52.009Z","response_time":115,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["elixir","livebook","mandelbrot-set","mandelbrot-viewer","nx","zig","zigler"],"created_at":"2024-11-09T15:33:12.307Z","updated_at":"2026-05-16T09:32:31.822Z","avatar_url":"https://github.com/ndrean.png","language":"Zig","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Orbits and Mandelbrot set explorer with Numerical Elixir and Zig\n\n## Introduction\n\nSource:\n\n- [Mandelbrot set](https://en.wikipedia.org/wiki/Mandelbrot_set)\n- [Plotting algorithm](https://en.wikipedia.org/wiki/Plotting_algorithms_for_the_Mandelbrot_set)\n\n\nThis repo is about visualising the orbits of points in the 2D-plane under the map `z -\u003e z*z + c` known as Julia or Mandelbrot sets.\n\nWe are looking whether the iterates stay bounded are not. When we associate a colour that reflects this stability, this gives rise to Mandelbrot images.\n\nThese images are therefor a colourful representation of where the sequence is stable and how fast does these sequences diverge.\n\n\u003cimg with=\"500\" alt=\"zoom detail\" src=\"https://github.com/user-attachments/assets/f0e9dcaa-34b2-4789-97fd-895355a6a7a9\"\u003e\n\n\nThis repo contains:\n- a pur `Zig` computation\n- two `Livebook` to explore the orbits of points and to zoom into the Mandelbrot set.\n\nThe two Livebooks are:\n- one proposing a pur `Elixir` orbit explorer. You click and it displays the orbit of any point.\n- the other proposing a Mandelbrot set explorer with a clickable image to zoom in (and out):\n  - we have a pur `Elixir` implementation  using Numerical Elixir with `EXLA` backend of the Mandelbrot set.\n  - we have an enhanced version where the heavy computations are made with running embedded  `Zig` code thanks to the library `Zigler`.\n\nThe `Zig` code is compiled to `WebAssembly` to demonstrate quickly how this renders:\n\n\u003chttps://ndrean.github.io/zig-assembly-test/\u003e\n\n## Orbit explorer\n\nGiven a complex number `c` and the polynomial `p_c(x)=x^2+c`, we compute the sequence of iterates:\n\n```\np(0)=c\np(p(0))=p(c)=c^2+2\np(p(c)) = c^4+2c^3+c^2+c\n...\n```\n\nThe set of this sequence is the _orbit_ of the number `c` under the map `p`.\n\nFor example, for `c=1`, we have the orbit `O_1 = { 0, 1, 2, 5, 26,...}` but for `c=-1`, we have a cyclic orbit, `O_{-1} = {−1, 0, −1, 0,...}`.\n\nThe code below computes \"orbits\". You select a point and a little animation displays the orbit.\n\n[![Run in Livebook](https://livebook.dev/badge/v1/blue.svg)](https://livebook.dev/run?url=https%3A%2F%2Fgithub.com%2Fndrean%2Fmandelbrot%2Fblob%2Fmain%2Flivebook%2Forbits.livemd)\n\n\n\u003cimg width=\"600\" alt=\"orbit\" src=\"https://github.com/user-attachments/assets/abe4a943-ac31-44db-85c4-906f14f958bd\"\u003e\n\n\n## Mandelbrot set explorer\n\n### The algorithm\n\nGiven an image of size W x H in pixels,\n- loop over 1..H rows,  `i`, and over 1..W columns, `j`\n  - compute the coordinate `c` in the 2D-plane projection corresponding to the pixel `(i,j)`\n  - compute the \"escape\" iterations `n`,\n  - compute the RGB colours for this `n`,\n  - append to your final array.\n\n### A Livebook\n\n[![Run in Livebook](https://livebook.dev/badge/v1/blue.svg)](https://livebook.dev/run?url=https%3A%2F%2Fgithub.com%2Fndrean%2Fmandelbrot%2Fblob%2Fmain%2Flivebook%2Fmandelbrot.livemd)\n\n\nYou can explore the fractal by clicking into the 2D-plane. \n\nThis happens thanks to `KinoJS.Live`.\n\nWe have a pur `Elixir` version that uses `Nx` with the `EXLA` backend, and another one that uses embedded `Zig` code for the heavy computations. The later is 3-4 magnitude faster mostly because we are running compiled Zig code versus interpreted Elixir code in a Livebook running uncompiled on a BEAM.\n\n\n\u003cimg width=\"600\" alt=\"detail\" src=\"https://github.com/user-attachments/assets/e747dbc9-02b1-4fd3-9670-73218d632a5a\" \u003e\n\n## Details of the mandelbrot set\n\n[Needs latex]\n\nIn fact, this set is contained in a disk \n$ D_2$ of radius 2. This does not mean that \n$ 0_c$ is bounded whenever \n$|c|\\leq 2$ as seen above. Merely \n$0_c$ is certainly unbounded - the sequence of \n$z_n$ is divergent whenever \n$|c| \u003e 2$.\n\nWe have a more precise criteria: whenever the absolute value $` |z_n| `$ is greater that 2, then the absolute values of the following iterates grow to infinity.\n\nThe **Mandelbrot set** $M$ is the set of numbers $c$ such that its sequence $O_c$ remains bounded (in absolute value). This means that $` | z_n (c) | \u003c 2 `$ for any $` n `$.\n\nWhen the sequence $` O_c `$ is _unbounded_, we associate to $c$ the first integer $N_c$ such that $` |z_N (c)| \u003e 2 `$.\n\nSince we have to stop the computations at one point, we set a limit $m$ to the number of iteration. Whenever we have $` |z_{n}|\\leq 2 `$ when $n=m$, then point $` c `$ is declared _\"mandelbrot stable\"_.\n\nWhen the sequence $O_c$ remains bounded, we associate to $` c `$ a value $` max `$.\n\nSo to each $` c `$ in the plane, we can associate an integer $n$, whether `null` or a value between 1 and $m$.\nFurthermore, we decide to associate each integer $` n `$ a certain RGB colour.\n\nWith this map:\n\n```math\nc \\mapsto n(c) \\Leftrightarrow \\mathrm{colour} = f\\big(R(n),G(n),B(n)\\big)\n```\n\nwe are able to plot something.\n\nBy convention it is **black** when the orbit $O_c$ remains bounded.\n\nWhen you represente the full Mandelbrot set, you can take advantage of the symmetry; indeed, if $c$ is bounded, so is its conjugate.\n\n\u003chr/\u003e\n\n#### Math details:\n\nFirstly consider some $` |c| \\leq 2 `$ and suppose that for some $` N `$, we have $` |z_N|= 2+a `$ with $` a \u003e 0 `$. Then:\n\n```math\n|z_{N+1}| = |z_N^2+c|\\geq |z_N|^2 -|c| \u003e 2+2a = |z_N|+a\n```\n\nso $` |z_{N+k}| \\geq |z_N| +ka \\to \\infty `$ as $` k\\to \\infty `$.\n\nLastly, consider $|c| \u003e 2$. Then for every $n$, we have $|z_n| \u003e |c|$. So:\n\n```math\n|z_{n+1}| \\geq |z_n|^2 -|c| \\geq |z_n|^2-|z_n| = |z_n|(|z_n|-1) \\geq |z_n|(|c|-1) \u003e |z_n|\n```\n\nso the term grows to infinity and \"escapes\".\n\n\u003chr/\u003e\n\nThe _mandelbrot set_ $M$ is **compact**, as _closed_ and bounded (contained in the disk of radius 2).\nIt is also surprisingly _connected_.\n\n\u003e Fix an integer $n\\geq 1$ and consider the set $M_n$ of complex numbers $c$ such that there absolute value at the rank $n$ is less than 2. In other words, $ M_n=\\{c\\in\\mathbb{C}, \\, |z_n(c)|\\leq 2\\} $. Then the complex numbers Mandelbrot-stable are precisely the numbers in all these $ M_n$, thus $M = \\bigcap_n M_n$.\n\u003e We conclude by remarking that each $M_n$ is closed as a preimage of the closed set $ [0,2]$ by a continous function, and since $M$ is an intersection of closed sets (not necesserally countable), it is closed.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fndrean%2Fmandelbrot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fndrean%2Fmandelbrot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fndrean%2Fmandelbrot/lists"}