How to use the ring.SR.var function in ring

To help you get started, we’ve selected a few ring examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sagemath / sagelib / sage / symbolic / units.py View on Github external
- ``name`` -- string

    OUTPUT:

        - UnitExpression


    EXAMPLES::

        sage: sage.symbolic.units.str_to_unit('acre')
        acre
        sage: type(sage.symbolic.units.str_to_unit('acre'))
        
    """
    return UnitExpression(SR, SR.var(name))
github sagemath / sagelib / sage / symbolic / units.py View on Github external
Returns variable if 'unit' is not a unit::

        sage: sage.symbolic.units.base_units(var('x'))
        x
    """
    from sage.misc.all import sage_eval
    if not unit_to_type.has_key(str(unit)):
        return unit
    elif unit_to_type[str(unit)] == 'si_prefixes' or unit_to_type[str(unit)] == 'unit_multipliers':
        return sage_eval(unitdict[unit_to_type[str(unit)]][str(unit)])
    else:
        v = SR.var(unit_to_type[str(unit)])
        if unit_derivations.has_key(str(v)):
            base = unit_derivations_expr(v)
            for i in base.variables():
                base = base.subs({i:SR.var(value_to_unit[str(i)]['1'])})
            return base*sage_eval(unitdict[str(v)][str(unit)])
        else:
            base = SR.var(value_to_unit[str(v)]['1'])*sage_eval(unitdict[str(v)][str(unit)])
            return base
github sagemath / sagelib / sage / symbolic / units.py View on Github external
kilogram*meter/second^2
        sage: sage.symbolic.units.base_units(units.volume.liter)
        1/1000*meter^3

    Returns variable if 'unit' is not a unit::

        sage: sage.symbolic.units.base_units(var('x'))
        x
    """
    from sage.misc.all import sage_eval
    if not unit_to_type.has_key(str(unit)):
        return unit
    elif unit_to_type[str(unit)] == 'si_prefixes' or unit_to_type[str(unit)] == 'unit_multipliers':
        return sage_eval(unitdict[unit_to_type[str(unit)]][str(unit)])
    else:
        v = SR.var(unit_to_type[str(unit)])
        if unit_derivations.has_key(str(v)):
            base = unit_derivations_expr(v)
            for i in base.variables():
                base = base.subs({i:SR.var(value_to_unit[str(i)]['1'])})
            return base*sage_eval(unitdict[str(v)][str(unit)])
        else:
            base = SR.var(value_to_unit[str(v)]['1'])*sage_eval(unitdict[str(v)][str(unit)])
            return base