Skip to content

Julia sets

The filled Julia set of z -> z^2 + c (Dilão 2023 §5.5).

  • Class: JuliaSystem
  • Import: from skcomplex.systems.mathematics.fractals import JuliaSystem
  • Field: mathematics/fractals
  • Topics: fractal, complex, map, lattice, escape time
  • References:
    • Dilão 2023

The julia example

Example

Use this system

The block imports the class and simulates the system with its default parameters and its tuned run settings.

from skcomplex.systems.mathematics.fractals import JuliaSystem

trajectory = JuliaSystem().prepare().simulate()

Parameters

The model parameters take these defaults, and set_params changes them.

Parameter Default
c (-0.8+0.156j)
shape (240, 320)
window (-1.6, 1.6, -1.2, 1.2)
radius 2.0
solver 'auto'
backend 'auto'

Tags

The system with its default parameters has these capability tags, which solvers and analyses check.

Tag Values
Time discrete
Space lattice
Laws update
Randomness deterministic
Domains complex, integer
Structure fixed

Class

The source of the class shows how it builds its components from its model parameters.

class JuliaSystem(BaseSystem):
    """The filled Julia set of `z -> z^2 + c` (Dilão 2023 §5.5).

    The set holds the starting points whose orbit stays bounded.

    Every site holds one starting point `z` of the window and iterates the map with the same constant `c`, and `n`
    counts the steps the orbit stays within the escape radius. For `c` in the Mandelbrot set the filled Julia set is
    connected, and outside it the set breaks into dust. The system has the field `plane`, its orbits `plane.z`, and its
    escape times `plane.n`.

    Args:
        c:
            The constant of the map.

        shape:
            The number of sites along the imaginary and the real axis.

        window:
            The smallest and largest real part, then the smallest and largest imaginary part, of the starting points.

        radius:
            The escape radius, at least 2 and at least `|c|`, so escaped orbits never return.

        label:
            The label of the system, which names it when it is nested in another one.

        solver:
            The solver of the problem, or `'auto'` for the one the system chooses.

        backend:
            The backend that evaluates the compiled functions, or `'auto'` for the one the system chooses.

    Examples:
        >>> from skcomplex.systems.mathematics.fractals import JuliaSystem
        >>> JuliaSystem(0.0, (3, 3), window=(-1, 1, -1, 1)).prepare().system_.elements[0].z[:3].tolist()
        [(-1+1j), 1j, (1+1j)]
    """

    field = 'mathematics/fractals'
    topics = ('fractal', 'complex', 'map', 'lattice', 'escape time')
    references = ('Dilão 2023',)
    until = 100
    dt = 1

    def __init__(
        self,
        c: complex = -0.8 + 0.156j,
        shape: Sequence[int] = (240, 320),
        *,
        window: Window = JULIA_WINDOW,
        radius: float = 2.0,
        label: str = 'system',
        solver: BaseSolver | str = 'auto',
        backend: BaseBackend | str = 'auto',
    ) -> None:
        super().__init__(label, solver=solver, backend=backend)
        self.c = c
        self.shape = shape
        self.window = window
        self.radius = radius

    def _prepare(self, context: Sequence[Observable] | None = None) -> None:
        """Set the system of the starting points of the window and their escape."""
        super()._prepare(context)
        points = MandelbrotSystem._get_plane(self.shape, self.window)
        self.system_ = MandelbrotSystem._get_escape_system(self.label, self.shape, points, complex(self.c), self.radius)

Components

The system uses these element and interaction classes, each with its nearest class of the core.

Elements:

  • QuadraticMapElement, from Element

Interactions:

  • QuadraticMapInteraction, from Interaction
class QuadraticMapElement(Element):
    """Points of the complex quadratic map `z' = z^2 + c`, each with a count `n` of its steps.

    A `QuadraticMapInteraction` iterates the points while they stay within the escape radius.

    Args:
        label:
            The label of the element.

        z:
            The initial point.

        n:
            The initial number of steps within the escape radius.

        c:
            The constant of the map.

        space:
            The space with one point per site, or `None` for one point.

    Examples:
        >>> from skcomplex.systems.mathematics.fractals import QuadraticMapElement
        >>> QuadraticMapElement('point', c=0.25).c
        0.25
    """

    visual = VisualSpec('image', {'states': ('n',), 'low': 0.0})

    def __init__(
        self,
        label: str,
        *,
        z: object = 0.0,
        n: int = 0,
        c: object = 0.0,
        space: BaseSpace | None = None,
    ) -> None:
        super().__init__(label, space=space)
        self.z = z
        self.n = n
        self.c = c

class QuadraticMapInteraction(Interaction):
    """Iteration of `z' = z^2 + c` with a count of the steps within the escape radius.

    The point stays once `|z|` exceeds the escape radius, and the count `n` stops at its escape time.

    Args:
        label:
            The label of the interaction.

        target:
            The points whose values `z` and `n` the map sets.

        radius:
            The escape radius.

    Examples:
        >>> from skcomplex.systems.mathematics.fractals import QuadraticMapInteraction
        >>> QuadraticMapInteraction('escape', radius=3.0).radius
        3.0
    """

    law_classes = (UpdateLaw,)

    def __init__(self, label: str, *, target: Role = 'plane', radius: float = 2.0) -> None:
        super().__init__(label)
        self.target = target
        self.radius = radius

    def _prepare(self, context: SimpleNamespace) -> None:
        """Set the next point and the next count as the laws.

        Args:
            context:
                The namespace of the elements a binding of the roles names.
        """
        super()._prepare(context)
        z, n, c = context.target.z, context.target.n, context.target.c
        inside = abs(z) <= context.radius
        self.laws_: list[BaseLaw] = [
            UpdateLaw(z, where(inside, z**2 + c, z)),
            UpdateLaw(n, n + where(inside, 1, 0)),
        ]