cascada.algebraic.value module
Represent type of value properties.
Represent value properties. |
|
Represent word value properties. |
|
Represent bit value properties. |
- class cascada.algebraic.value.Value(value)[source]
Bases:
cascada.abstractproperty.property.PropertyRepresent value properties.
Given a function \(f\), a
Valueproperty pair \((\alpha, \beta)\) is a bit-vectorProperty\((\alpha, \beta)\) where the propagation probability is simply 1 if \(\beta = f(\alpha)\) otherwise 0, that is, the propagation probability is 0 or 1 depending on whether the output value is the image of the input value through \(f\).This class is not meant to be instantiated but to provide a base class for the different representations of the value of a bit-vector (see
BitValueorWordValue).Internally,
Valueis a subclass ofProperty(asDifference). TheValuemethods inherited fromPropertyrequiring arguments of typePropertyshould be called instead with arguments of typeValue.
- class cascada.algebraic.value.WordValue(value)[source]
Bases:
cascada.algebraic.value.ValueRepresent word value properties.
The word value is a
Valueproperty where the underlying bit-vector value of the property is given as is (i.e., as a bit-vectorTerm).>>> from cascada.bitvector.core import Constant, Variable >>> from cascada.algebraic.value import WordValue >>> alpha = WordValue(Constant(0b001, 3)) >>> alpha, alpha.val (WordValue(0b001), 0b001) >>> alpha.get_value() 0b001 >>> alpha = WordValue(Variable("alpha", 3)) >>> alpha, alpha.val (WordValue(alpha), alpha)
- classmethod propagate(op, input_val)[source]
Propagate the given input
WordValuethrough the given operation.For any operation
opand any input valueinput_val, the output valueoutput_valis uniquely determined and its bit-vector value isf(input_val).See
Property.propagatefor more information.User-defined or new
Operationopcan store its associatedWordValuealgebraic.opmodel.OpModelinop.word_model, as this method first checks whetherophas its associatedalgebraic.opmodel.OpModelstored in the class attributeword_model.>>> from cascada.bitvector.core import Variable, Constant >>> from cascada.bitvector.operation import BvXor, BvIdentity >>> from cascada.algebraic.value import WordValue >>> d1, d2 = WordValue(Variable("d1", 8)), WordValue(Constant(1, 8)) >>> WordValue.propagate(BvXor, [d1, d2]) WordValue(d1 ^ 0x01) >>> WordValue.propagate(BvIdentity, d1) WordModelId(WordValue(d1))
- class cascada.algebraic.value.BitValue(value)[source]
Bases:
cascada.algebraic.value.ValueRepresent bit value properties.
The bit value is a
Valueproperty where the underlying bit-vector value of the property is given as the list of its bits (starting from the least significant bit (LSB) and ending in the MSB).>>> from cascada.bitvector.core import Constant, Variable >>> from cascada.algebraic.value import BitValue >>> alpha = BitValue(Constant(0b001, 3)) >>> alpha, alpha.val (BitValue(0b001), 0b001) >>> alpha.get_value() (0b1, 0b0, 0b0) >>> alpha = BitValue(Variable("alpha", 3)) >>> alpha, alpha.val (BitValue(alpha), alpha) >>> alpha.get_value() (alpha[0], alpha[1], alpha[2])
- classmethod propagate(op, input_val)[source]
Propagate the given input
BitValuethrough the given operation.For any operation
opand any input valueinput_val, the output value is uniquely determined and its bit-vector value isf(input_val).For some operations, the output value is given implicitly through a system of binary equations or constraints (see
BitModelBvAdd). For these operations, this method return analgebraic.opmodel.OpModel.See
Property.propagatefor more information.User-defined or new
Operationopcan store its associatedBitValuealgebraic.opmodel.OpModelinop.bit_model, as this method first checks whetherophas its associatedalgebraic.opmodel.OpModelstored in the class attributebit_model.>>> from cascada.bitvector.core import Variable, Constant >>> from cascada.bitvector.operation import BvXor, Concat, BvIdentity >>> from cascada.algebraic.value import BitValue >>> d1, d2 = BitValue(Variable("d1", 2)), BitValue(Constant(1, 2)) >>> BitValue.propagate(BvXor, [d1, d2]) BitValue((d1[1]) :: ~(d1[0])) >>> d1, d2 = BitValue(Variable("d1", 2)), BitValue(Variable("d2", 2)) >>> BitValue.propagate(Concat, [d1, d2]) BitValue(d1 :: (d2[1]) :: (d2[0])) >>> BitValue.propagate(BvIdentity, d1) BitValue(Id(d1[1]) :: Id(d1[0]))