Pyrex

1 program Added 2026-02-07T18:39:16Z Agent: claude-codeModel: sonnetWebSearch: disabled Evidence Report issue View issues
Aliases: —
Provenance: commit 09d9e726f7 · authored 2026-02-07T19:40:02+01:00 · agent claude-code · model sonnet

Sources mentioning this language

5 sources · pl_id: pl/pyrex
LLM (this repo) · 1PldbPygmentsWikipediaWikidata · Q975594

Wikipedia infobox

Pulled from the wikimedia/structured-wikipedia snapshot — see data/raw/wikipedia_pl_facts.*.jsonl and pl_fact.csv for the long-table provenance.

Designed byRobert Bradshaw · Stefan Behnel · et al
First appeared2007
Influenced byC · Python
LicenseApache License 2.0
Implemented inPython
Homepagehttps://cython.org

Extensions claimed by this language

3 claims. Each row is one upstream assertion with its strength. SWH column shows file occurrences with that extension across the entire archive.
ExtensionSourceStrengthSWH
.pyxpygmentsprimary821.4K files
.pxdpygmentssecondary225.3K files
.pxipygmentssecondary60.2K files

Related languages

Pyret (0.40)Pyro (0.30)Murex (0.27)PyRTL (0.27)Pyrope (0.25)

LLM-contributed programs

Fibonacci Calculator

Provenance: commit 09d9e726f7 · authored 2026-02-07T19:40:02+01:00 · agent claude-code · model sonnet · WebSearch disabled
code.pyx · added: 2026-02-07T18:39:16Z
def fib(int n):
    """Calculate the nth Fibonacci number."""
    cdef int i
    cdef int a = 0
    cdef int b = 1
    cdef int temp

    if n <= 0:
        return 0
    elif n == 1:
        return 1

    for i from 2 <= i <= n:
        temp = a + b
        a = b
        b = temp

    return b

def fibonacci_list(int count):
    """Generate a list of the first count Fibonacci numbers."""
    result = []
    cdef int i
    for i from 0 <= i < count:
        result.append(fib(i))
    return result

Real programs from Software Heritage

1 sample mined from derived_datasets/<date>/contents/*.parquet, byte-verified against the SWH archive. Citation-grade qualified SWHIDs preserved.
nucname.pyx · 18084 B · ext .pyx · seen 265× in SWH
via fallback
swh:1:cnt:579132b92c17ba2624a5411200a75127d543c881;origin=https://github.com/cyclus/cyclus;anchor=swh:1:rev:3180019432966ea76eb84b3e83ad3a0d41284bc5;path=/cyclus/nucname.pyx
Open in SWH · Raw bytes (SWH) · GitHub raw
Show source
"""Python wrapper for nucname library."""
from __future__ import unicode_literals, division, print_function

# Cython imports
from libcpp.map cimport map
from libcpp.set cimport set as cpp_set
from cython.operator cimport dereference as deref
from cython.operator cimport preincrement as inc
from libcpp.string cimport string as std_string

from cyclus cimport cpp_cyclus as cpp_nucname


class NucTypeError(Exception):
    def __init__(self, nuc=None):
        self.nuc = nuc

    def __str__(self):
        msg = "Nuclide type not an int or str"
        if self.nuc is not None:
            msg += ": " + repr(self.nuc)
        return msg


#
# Is Nuclide and Is Element Functions
#

def isnuclide(nuc):
    """Test if nuc is a valid nuclide.

    Parameters
    ----------
    nuc : int or str
        Input nuclide(s).

    Returns
    -------
    flag : bool

    """
    if isinstance(nuc, basestring):
        nuc_bytes = nuc.encode()
        flag = cpp_nucname.isnuclide(<char *> nuc_bytes)
    elif isinstance(nuc, int) or isinstance(nuc, long):
        flag = cpp_nucname.isnuclide(<int> nuc)
    else:
        raise NucTypeError(nuc)

    return flag

def iselement(nuc):
    """Test if nuc is a valid element.

    Parameters
    ----------
    nuc : int or str
        Input element.

    Returns
    -------
    flag : bool

    """
    if isinstance(nuc, basestring):
        nuc_bytes = nuc.encode()
        flag = cpp_nucname.iselement(<char *> nuc_bytes)
    elif isinstance(nuc, int) or isinstance(nuc, long):
        flag = cpp_nucname.iselement(<int> nuc)
    else:
        raise NucTypeError(nuc)

    return flag

def id(nuc):
    """Converts a nuclide to its identifier form (952420000).

    If the input nuclide is in id form already, then this is function does no
    work. For all other formats, the id() function provides a best-guess based
    on a heirarchy of other formats that is used to resolve ambiguities between
    naming conventions. For integer input the form resolution order is:

        - id
        - zz (elemental z-num only given)
        - zzaaam
        - cinder (aaazzzm)
        - mcnp
        - zzaaa

    For string (or char *) input the form resolution order is as follows:

        - ZZ-LL-AAAM
        - Integer form in a string representation, uses interger resolution
        - NIST
        - name form
        - Serpent
        - LL (element symbol)

    For well-defined situations where you know ahead of time what format the
    nuclide is in, you should use the various form_to_id() functions, rather
    than the id() function which is meant to resolve possibly ambiquous cases.

    Parameters
    ----------
    nuc : int or str
        Input nuclide.

    Returns
    -------
    newnuc : int
        Output nuclide id.

    """
    if isinstance(nuc, basestring):
        nuc = nuc.encode()
        newnuc = cpp_nucname.id(<char *> nuc)
    elif isinstance(nuc, int) or isinstance(nuc, long):
        newnuc = cpp_nucname.id(<int> nuc)
    else:
        raise NucTypeError(nuc)
    return newnuc


def name(nuc):
    """Converts a nuclide to its name form ('Am242M'). The name() function
    first converts functions to id form using the id() function. Thus the
    form order resolution for id() also applies to here.

    Parameters
    ----------
    nuc : int or str
        Input nuclide.

    Returns
    -------
    newnuc : str
        Output nuclide in name form.

    """
    cdef std_string newnuc
    if isinstance(nuc, basestring):
        nuc_bytes = nuc.encode()
        newnuc = cpp_nucname.name(<char *> nuc_bytes)
    elif isinstance(nuc, int):
        newnuc = cpp_nucname.name(<int> nuc)
    else:
        raise NucTypeError(nuc)
    return bytes(<char *> newnuc.c_str()).decode()


def znum(nuc):
    """Retrieves a nuclide's charge number (95).

    Parameters
    ----------
    nuc : int or str
        Input nuclide.

    Returns
    -------
    z : int
        The number of protons in the nucleus.

    """
    if isinstance(nuc, basestring):
        nuc_bytes = nuc.encode()
        z = cpp_nucname.znum(<char *> nuc_bytes)
    elif isinstance(nuc, int) or isinstance(nuc, long):
        z = cpp_nucname.znum(<int> nuc)
    else:
        raise NucTypeError(nuc)
    return z


def anum(nuc):
    """Retrieves a nuclide's nucleon number (95).

    Parameters
    ----------
    nuc : int or str
        Input nuclide.

    Returns
    -------
    a : int
        The number of protons and neutrons in the nucleus.

    """
    if isinstance(nuc, basestring):
        nuc_bytes = nuc.encode()
        a = cpp_nucname.anum(<char *> nuc_bytes)
    elif isinstance(nuc, int) or isinstance(nuc, long):
        a = cpp_nucname.anum(<int> nuc)
    else:
        raise NucTypeError(nuc)
    return a


def snum(nuc):
    """Retrieves a nuclide's excitation number (95).

    Parameters
    ----------
    nuc : int or str
        Input nuclide.

    Returns
    -------
    s : int
        The excitation level the nucleus.

    """
    if isinstance(nuc, basestring):
        nuc_bytes = nuc.encode()
        s = cpp_nucname.snum(<char *> nuc_bytes)
    elif isinstance(nuc, int) or isinstance(nuc, long):
        s = cpp_nucname.snum(<int> nuc)
    else:
        raise NucTypeError(nuc)
    return s


def zzaaam(nuc):
    """Converts a nuclide to its zzaaam form (952420).

    Parameters
    ----------
    nuc : int or str
        Input nuclide.

    Returns
    -------
    newnuc : int
        Output nuclide in zzaaam form.

    """
    if isinstance(nuc, basestring):
        nuc_bytes = nuc.encode()
        newnuc = cpp_nucname.zzaaam(<char *> nuc_bytes)
    elif isinstance(nuc, int) or isinstance(nuc, long):
        newnuc = cpp_nucname.zzaaam(<int> nuc)
    else:
        raise NucTypeError(nuc)
    return newnuc


def zzaaam_to_id(nuc):
    """Converts a nuclide directly from ZZAAAM form (952420) to
    the canonical identifier form.

    Parameters
    ----------
    nuc : int or str
        Input nuclide in ZZAAAM form.

    Returns
    -------
    newnuc : int
        Output nuclide in identifier form.

    """
    if isinstance(nuc, basestring):
        nuc_bytes = nuc.encode()
        newnuc = cpp_nucname.zzaaam_to_id(<char *> nuc_bytes)
    elif isinstance(nuc, int) or isinstance(nuc, long):
        newnuc = cpp_nucname.zzaaam_to_id(<int> nuc)
    else:
        raise NucTypeError(nuc)
    return newnuc


def zzzaaa(nuc):
    """Converts a nuclide to its zzzaaa form (95242).

    Parameters
    ----------
    nuc : int or str
        Input nuclide.

    Returns
    -------
    newnuc : int
        Output nuclide in zzzaaa form.

    """
    if isinstance(nuc, basestring):
        nuc_bytes = nuc.encode()
        newnuc = cpp_nucname.zzzaaa(<char *> nuc_bytes)
    elif isinstance(nuc, int) or isinstance(nuc, long):
        newnuc = cpp_nucname.zzzaaa(<int> nuc)
    else:
        raise NucTypeError(nuc)
    return newnuc


def zzzaaa_to_id(nuc):
    """Converts a nuclide directly from ZZZAAA form (95242) to
    the canonical identifier form.

    Parameters
    ----------
    nuc : int or str
        Input nuclide in ZZZAAA form.

    Returns
    -------
    newnuc : int
        Output nuclide in identifier form.

    """
    if isinstance(nuc, basestring):
        newnuc = cpp_nucname.zzzaaa_to_id(<char *> nuc)
    elif isinstance(nuc, int) or isinstance(nuc, long):
        newnuc = cpp_nucname.zzzaaa_to_id(<int> nuc)
    else:
        raise NucTypeError(nuc)
    return newnuc


def mcnp(nuc):
    """Converts a nuclide to its MCNP form (92636).

    Parameters
    ----------
    nuc : int or str
        Input nuclide.

    Returns
    -------
    newnuc : int
        Output nuclide in MCNP form.

    Notes
    -----
    Most metastables in this form add 300 + 100*m where
    m is the isomeric state (U-236m = 92636).  However,
    MCNP special cases Am-242 and Am-242m by switching
    the meaning. Thus Am-242m = 95242 and Am-242 = 95642.

    """

    if isinstance(nuc, basestring):
        nuc_bytes = nuc.encode()
        newnuc = cpp_nucname.mcnp(<char *> nuc_bytes)
    elif isinstance(nuc, int):
        newnuc = cpp_nucname.mcnp(<int> nuc)
    else:
        raise NucTypeError(nuc)
    return newnuc


def mcnp_to_id(nuc):
    """Converts a nuclide directly from MCNP form (92636) to
    the canonical identifier form.

    Parameters
    ----------
    nuc : int or str
        Input nuclide in MCNP form.

    Returns
    -------
    newnuc : int
        Output nuclide in identifier form.

    """
    if isinstance(nuc, basestring):
        nuc_bytes = nuc.encode()
        newnuc = cpp_nucname.mcnp_to_id(<char *> nuc_bytes)
    elif isinstance(nuc, int) or isinstance(nuc, long):
        newnuc = cpp_nucname.mcnp_to_id(<int> nuc)
    else:
        raise NucTypeError(nuc)
    return newnuc


def fluka(nuc):
    """Converts a nuclide to its FLUKA name.

    Parameters
    ----------
    nuc : int
        Input nuclide.

    Returns
    -------
    fluka_name : string
        Output name in FLUKA form.


    """
    fluka_name = cpp_nucname.fluka(nuc)
    return fluka_name.decode()


def fluka_to_id(name):
    """Converts a fluka name to the canonical identifier form.

    Parameters
    ----------
    name : str
        Input name, expectedt to be one FLUKA knows

    Returns
    -------
    newnuc : int
        Output nuclide in identifier form.

    """
    name = name.encode()
    newnuc = cpp_nucname.fluka_to_id(<char *> name)
    return newnuc


def zzllaaam(nuc):
    """Converts a nuclide to its zzllaaam form (95-Am-241m).

    Parameters
    ----------
    nuc : int or str
        Input nuclide.

    Returns
    -------
    newnuc : str
        Output nuclide in zzllaaam form.

    """
    if isinstance(nuc, basestring):
        nuc_bytes = nuc.encode()
        newnuc = cpp_nucname.zzllaaam(<char *> nuc_bytes)
    elif isinstance(nuc, int) or isinstance(nuc, long):
        newnuc = cpp_nucname.zzllaaam(<int> nuc)
    else:
        raise NucTypeError(nuc)
    return bytes(newnuc).decode()


def zzllaaam_to_id(nuc):
    """Converts a nuclide directly from ZZLLAAAM form (95-Am-241m) to
    the canonical identifier form.

    Parameters
    ----------
    nuc : int or str
        Input nuclide in ZZLLAAAM form.

    Returns
    -------
    newnuc : int
        Output nuclide in identifier form.

    """
    if isinstance(nuc, basestring):
        nuc_bytes = nuc.encode()
        newnuc = cpp_nucname.zzllaaam_to_id(<char *> nuc_bytes)
    else:
        raise NucTypeError(nuc)
    return newnuc



def serpent(nuc):
    """Converts a nuclide to its Serepnt form ('Am-242m').

    Parameters
    ----------
    nuc : int or str
        Input nuclide.

    Returns
    -------
    newnuc : str
        Output nuclide in serpent form.

    """
    cdef std_string newnuc

    if isinstance(nuc, basestring):
        nuc_bytes = nuc.encode()
        newnuc = cpp_nucname.serpent(<char *> nuc_bytes)
    elif isinstance(nuc, int):
        newnuc = cpp_nucname.serpent(<int> nuc)
    else:
        raise NucTypeError(nuc)

    return bytes(<char *> newnuc.c_str()).decode()


def serpent_to_id(nuc):
    """Converts a nuclide directly from Serpent form ('Am-242m') to
    the canonical identifier form.

    Parameters
    ----------
    nuc : int or str
        Input nuclide in Serpent form.

    Returns
    -------
    newnuc : int
        Output nuclide in identifier form.

    """
    if isinstance(nuc, basestring):
        nuc_bytes = nuc.encode()
        newnuc = cpp_nucname.serpent_to_id(<char *> nuc_bytes)
    #elif isinstance(nuc, int) or isinstance(nuc, long):
    #    newnuc = cpp_nucname.serpent_to_id(<int> nuc)
    else:
        raise NucTypeError(nuc)
    return newnuc


def nist(nuc):
    """Converts a nuclide to NIST form ('242Am').

    Parameters
    ----------
    nuc : int or str
        Input nuclide.

    Returns
    -------
    newnuc : str
        Output nuclide in nist form.

    """
    cdef std_string newnuc

    if isinstance(nuc, basestring):
        nuc_bytes = nuc.encode()
        newnuc = cpp_nucname.nist(<char *> nuc_bytes)
    elif isinstance(nuc, int):
        newnuc = cpp_nucname.nist(<int> nuc)
    else:
        raise NucTypeError(nuc)

    return bytes(<char *> newnuc.c_str()).decode()


def nist_to_id(nuc):
    """Converts a nuclide directly from NIST form ('242Am') to
    the canonical identifier form.

    Parameters
    ----------
    nuc : int or str
        Input nuclide in NIST form.

    Returns
    -------
    newnuc : int
        Output nuclide in identifier form.

    """
    if isinstance(nuc, basestring):
        nuc_bytes = nuc.encode()
        newnuc = cpp_nucname.nist_to_id(<char *> nuc_bytes)
    #elif isinstance(nuc, int) or isinstance(nuc, long):
    #    newnuc = cpp_nucname.nist_to_id(<int> nuc)
    else:
        raise NucTypeError(nuc)
    return newnuc


def cinder(nuc):
    """Converts a nuclide to its CINDER (aaazzzm) form (2420951).

    Parameters
    ----------
    nuc : int or str
        Input nuclide.

    Returns
    -------
    newnuc : int
        Output nuclide in CINDER (aaazzzm) form.

    """
    if isinstance(nuc, basestring):
        nuc_bytes = nuc.encode()
        newnuc = cpp_nucname.cinder(<char *> nuc_bytes)
    elif isinstance(nuc, int):
        newnuc = cpp_nucname.cinder(<int> nuc)
    else:
        raise NucTypeError(nuc)
    return newnuc


def cinder_to_id(nuc):
    """Converts a nuclide directly from Cinder form (2420951) to
    the canonical identifier form.

    Parameters
    ----------
    nuc : int or str
        Input nuclide in Cinder form.

    Returns
    -------
    newnuc : int
        Output nuclide in identifier form.

    """
    if isinstance(nuc, basestring):
        newnuc = cpp_nucname.cinder_to_id(<char *> nuc)
    elif isinstance(nuc, int) or isinstance(nuc, long):
        newnuc = cpp_nucname.cinder_to_id(<int> nuc)
    else:
        raise NucTypeError(nuc)
    return newnuc


def alara(nuc):
    """Converts a nuclide to its ALARA form ('am:242').

    Parameters
    ----------
    nuc : int or str
        Input nuclide.

    Returns
    -------
    newnuc : str
        Output nuclide in name form.

    """
    cdef std_string newnuc

    if isinstance(nuc, basestring):
        nuc_bytes = nuc.encode()
        newnuc = cpp_nucname.alara(<char *> nuc_bytes)
    elif isinstance(nuc, int):
        newnuc = cpp_nucname.alara(<int> nuc)
    else:
        raise NucTypeError(nuc)

    return bytes(<char *> newnuc.c_str()).decode()


def alara_to_id(nuc):
    """Converts a nuclide directly from ALARA form ('am:242') to
    the canonical identifier form.

    Parameters
    ----------
    nuc : int or str
        Input nuclide in ALARA form.

    Returns
    -------
    newnuc : int
        Output nuclide in identifier form.

    """
    if isinstance(nuc, basestring):
        nuc_bytes = nuc.encode()
        newnuc = cpp_nucname.alara_to_id(<char *> nuc_bytes)
    #elif isinstance(nuc, int) or isinstance(nuc, long):
    #    newnuc = cpp_nucname.alara_to_id(<int> nuc)
    else:
        raise NucTypeError(nuc)
    return newnuc


def sza(nuc):
    """Converts a nuclide to its SZA form (SSSZZZAAA).

    Parameters
    ----------
    nuc : int or str
        Input nuclide.

    Returns
    -------
    newnuc : int
        Output nuclide in SZA form.

    """
    if isinstance(nuc, basestring):
        nuc_bytes = nuc.encode()
        newnuc = cpp_nucname.sza(<char *> nuc_bytes)
    elif isinstance(nuc, int) or isinstance(nuc, long):
        newnuc = cpp_nucname.sza(<int> nuc)
    else:
        raise NucTypeError(nuc)
    return newnuc


def sza_to_id(nuc):
    """Converts a nuclide directly from SZA form (SSSZZZAAA) to
    the canonical identifier form.

    Parameters
    ----------
    nuc : int or str
        Input nuclide in SZA form.

    Returns
    -------
    newnuc : int
        Output nuclide in identifier for
…(truncated)…

Contribute — propose a file extension

Tell us where to find evidence about Pyrex (mapped to pl/pyrex). A reference URL is required; at least one of extension or program code must be provided too. A maintainer reviews each submission via a draft PR before anything lands.
Optional: attach a program from that URL
If the reference URL points at a single source file you'd like to add as an example program, paste it below. The workflow will write it under languages/Pyrex/programs/<sha>/. Keep under ~200 lines.
(or open the pre-filled issue directly)
← pyret-lang Pyro →