Ticket #11871: trac_11871-cellular.patch

File trac_11871-cellular.patch, 1.9 KB (added by jhpalmieri, 8 years ago)
  • sage/interacts/library.py

    # HG changeset patch
    # User J. H. Palmieri <palmieri@math.washington.edu>
    # Date 1339540285 25200
    # Node ID 2a763c96be6c9d243ea830eb78034a3163cce78f
    # Parent  1443689d20f38c96610b8cd6b3d52c3ae128c86d
    Fix cellular automaton interact: add a doctest, fix a few small errors.
    
    diff --git a/sage/interacts/library.py b/sage/interacts/library.py
    a b def cellular_automaton( 
    14511451
    14521452    from sage.interacts.library_cython import cellular
    14531453    M = cellular(rule, N)
    1454     plot_M = matrix_plot(M)
     1454    plot_M = matrix_plot(M, cmap='binary')
    14551455    plot_M.show(figsize=[size,size])
    14561456
    14571457
  • sage/interacts/library_cython.pyx

    diff --git a/sage/interacts/library_cython.pyx b/sage/interacts/library_cython.pyx
    a b cpdef mandel(ff_m, z, int iterations): 
    7575
    7676
    7777cpdef cellular(rule, int N):
    78     '''
    79     Cythonized helper function for the callular_automata fractal.
     78    """
     79    Cythonized helper function for the cellular_automata fractal.
    8080    Yields a matrix showing the evolution of a Wolfram's cellular automaton.
    8181    Based on work by Pablo Angulo.
    8282    http://wiki.sagemath.org/interact/misc#CellularAutomata
    cpdef cellular(rule, int N): 
    9191        sage: from sage.interacts.library_cython import cellular
    9292        sage: rule = [1, 0, 1, 0, 0, 1, 1, 0]
    9393        sage: N = 3
    94         sage: print cellular(rule, 3)
    95 
    96     '''
     94        sage: print cellular(rule, N)
     95        [[0 0 0 1 0 0 0 0]
     96         [1 1 0 1 0 1 0 0]
     97         [0 1 1 1 1 1 0 0]]
     98    """
    9799    from numpy import zeros
    98100    cdef int j, k, l
    99     M=zeros((N, 2*N+1), dtype=int)
     101    M=zeros((N, 2*N+2), dtype=int)
    100102    M[0,N]=1 
    101103   
    102104    for j in range(1, N):
    103         for k in range(N-j, N+j+1):
     105        for k in range(0, 2*N):
    104106            l = 4 * M[j-1, k-1] + 2 * M[j-1, k] + M[j-1, k+1]
    105107            M[j,k] = rule[l]
    106108    return M