The computer algebra system package

Symbolic expressions are provided by several classes found in module cas/expressions:

  • Constant cst, which represents immediate (signed or unsigned) value of fixed size (bitvector),

  • Symbol sym, a Constant equipped with a reference string (non-external symbol),

  • Register reg, a fixed size CPU register location,

  • External ext, a reference to an external location (external symbol),

  • Floats cfp, constant (fixed size) floating-point values,

  • Composite comp, a bitvector composed of several elements,

  • Pointer ptr, a memory location in a segment, with possible displacement,

  • Memory mem, a Pointer to represent a value of fixed size in memory,

  • Slice slc, a bitvector slice of any element,

  • Test tst, a conditional expression, (see below.)

  • Operator uop, an unary operator expression,

  • Operator op, a binary operator expression. The list of supported operations is not fixed althrough several predefined operators allow to build expressions directly from Python expressions: say, you don’t need to write op('+',x,y), but can write x+y. Supported operators are:

    • +, -, * (multiply low), ** (multiply extended), /

    • &, |, ^, ~

    • ==, !=, <=, >=, <, >

    • >>, <<, // (arithmetic shift right), >>> and <<< (rotations).

    See cas.expressions._operator for more details.

All elements inherit from the exp class which defines all default methods/properties. Common attributes and methods for all elements are:

  • size, a Python integer representing the size in bits,

  • sf, the True/False sign-flag.

  • length (size/8)

  • mask (1<<size)-1

  • extend methods (signextend(newsize), zeroextend(newsize))

  • bytes(sta,sto,endian=1) method to retreive the expression of extracted bytes from sta to sto indices.

All manipulation of an expression object usually result in a new expression object except for simplify() which performs a few in-place elementary simplifications.