Exemple #1
0
 def compute_norm(self, field=None, **defaults_config):
     '''
     Proves ‖a ⊗ b ⊗ ... ⊗ y ⊗ z‖ = ‖a‖·‖b‖·...·‖y‖·‖z‖.
     '''
     from proveit.logic import EvaluationError
     from . import norm_of_tensor_prod, norm_preserving_tensor_prod
     _a = self.operands
     _i = _a.num_elements()
     _K = VecSpaces.get_field(field)
     vec_spaces = VecSpaces.known_vec_spaces(self.operands, field=_K)
     
     # See if all of the operand normalizations evaluate to one.
     all_norm_one = True
     try:
         for operand in self.operands:
             if isinstance(operand, ExprRange):
                 with defaults.temporary() as tmp_defaults:
                     tmp_defaults.assumptions = defaults.assumptions + (
                             operand.parameter_condition(),)
                     body_norm = operand.body.compute_norm()
                     if body_norm.rhs.evaluated() != one:
                         all_norm_one = False
                         break
             else:
                 if operand.compute_norm().rhs.evaluated() != one:
                     all_norm_one = False
                     break
     except (EvaluationError, NotImplementedError):
         all_norm_one = False
         pass
     if all_norm_one:
         thm = norm_preserving_tensor_prod
     else:
         thm = norm_of_tensor_prod
     return thm.instantiate({K: _K, i: _i, V: vec_spaces, a: _a})            
Exemple #2
0
 def insert_vec_on_both_sides_of_equals(tensor_equality, idx, vec,
                                        rhs_idx = None, *,
                                        field = None, 
                                        **defaults_config):
     '''
     From an equality with tensor products of vectors on
     both sides, derive a similar equality but with a vector 
     operand inserted at the particular given zero-based index (idx).
     A different index may be specified for the right side as the 
     left side by setting rhs_idx (i.e., if entries don't line up 
     due to differences of ExprRange entries), but the default will
     be to use the same.
     '''
     from . import insert_vec_on_both_sides_of_equality
     # First check various characteristics of the tensor_equality
     tensor_equality = TensorProd._check_tensor_equality(
             tensor_equality, allow_unary=True)
     if idx < 0:
         # use wrap-around indexing
         idx = tensor_equality.num_entries() + idx
     if rhs_idx is None:
         rhs_idx = idx # use the same index on both sides by default
     _a = tensor_equality.lhs.operands[:idx]
     _b = vec
     _c = tensor_equality.lhs.operands[idx:]
     _d = tensor_equality.rhs.operands[:rhs_idx]
     _e = tensor_equality.rhs.operands[rhs_idx:]
     _i = _a.num_elements()
     _k = _c.num_elements()
     vec_space = VecSpaces.known_vec_space(tensor_equality.lhs, 
                                           field=field)
     _K = VecSpaces.known_field(vec_space)
     _U = VecSpaces.known_vec_spaces(_a, field=_K)
     _V = VecSpaces.known_vec_space(_b, field=_K)
     _W = VecSpaces.known_vec_spaces(_c, field=_K)
     impl = insert_vec_on_both_sides_of_equality.instantiate(
             {K:_K, i:_i, k:_k, U:_U, V:_V, W:_W, 
              a:_a, b:_b, c:_c, d:_d, e:_e})
     return impl.derive_consequent().with_mimicked_style(tensor_equality)
Exemple #3
0
 def deduce_in_vec_space(self, vec_space=None, *, field,
                         **defaults_config):
     '''
     Deduce that the tensor product of vectors is in a vector space
     which is the tensor product of corresponding vectors spaces.
     '''
     from . import tensor_prod_is_in_tensor_prod_space
     _a = self.operands
     _i = _a.num_elements()
     _K = VecSpaces.get_field(field)
     vec_spaces = VecSpaces.known_vec_spaces(self.operands, field=_K)
     membership = tensor_prod_is_in_tensor_prod_space.instantiate(
             {K: _K, i: _i, V: vec_spaces, a: _a})      
     if vec_space is not None and membership.domain != vec_space:
         sub_rel = SubsetEq(membership.domain, vec_space)
         return sub_rel.derive_superset_membership(self)
     return membership