logo

Demonstrations for the theory of proveit.linear_algebra.addition

In [1]:
import proveit
from proveit import k, t, v, vi, vk, N, Variable
from proveit.logic import InSet
from proveit.linear_algebra import ScalarMult, VecAdd, VecSpaces, VecSum
from proveit.numbers import (zero, one, two, eight, i, e, pi, Exp, Integer,
                             Interval, Less, Mult, Neg, num)
%begin demonstrations
In [2]:
i_var = Variable('i') # to distinguish from imaginary number i
vec_sum_01, vec_sum_02, vec_sum_03, vec_sum_04, vec_sum_05 = (
    VecSum(i_var, vi, domain=Interval(two, two)),
    VecSum(i_var, vi, domain=Interval(one, eight)),
    VecSum(k, vk, domain=Interval(zero, Exp(two, t))),
    VecSum(k, ScalarMult(Exp(e, Mult(two, pi, i, k)), vk), domain=Interval(zero, N)),
    VecSum(k, v, domain=Interval(one, eight)))
vec_sum_01:
vec_sum_02:
vec_sum_03:
vec_sum_04:
vec_sum_05:

VecSum.shallow_simplification()

VecSum.shallow_simplification() will take a single-item vector summation and return the equality of that sum with the vector evaluated at the single index value.

In [3]:
vec_sum_01
In [4]:
vec_sum_01.shallow_simplification()

VecSum.shifting()

In [5]:
vec_sum_02.shifting(one)
In [6]:
vec_sum_02.shifting(two)
In [7]:
vec_sum_02.shifting(Neg(one))
In [8]:
# Here we temporarily set auto_simplify=False to see the underlying shift
vec_sum_03.shifting(Neg(one), assumptions=[InSet(Exp(two, t), Integer)], auto_simplify=False)
In [9]:
# Then we allow auto_simplify to proceed as usual
vec_sum_03.shifting(Neg(one), assumptions=[InSet(Exp(two, t), Integer)])

VecSum.partitioning()

In [10]:
vec_sum_02.partitioning(split_index=num(5), side='after')
In [11]:
vec_sum_02.partitioning(split_index=num(5), side='before')

VecSum.partitioning_last()

In [12]:
vec_sum_02.partitioning_last()
In [13]:
vec_sum_03.partitioning_last(
        assumptions=[InSet(Exp(two, t), Integer), Less(zero, Exp(two, t))])

VecSum.partitioning_first()

In [14]:
vec_sum_02.partitioning_first()
In [15]:
from proveit.logic import Forall, CartExp
from proveit.numbers import Complex, Natural, NaturalPos
from proveit import defaults, n
Cn = CartExp(Complex, n)
defaults.assumptions = [InSet(n, NaturalPos), InSet(N, NaturalPos), Forall(k, InSet(vk, Cn), domain=Natural)]
defaults.assumptions:
In [16]:
defaults.assumptions + vec_sum_04.domain_conditions()
In [17]:
defaults.assumptions[-1].instantiate({k:zero}, assumptions=defaults.assumptions)
In [18]:
vec_sum_04.partitioning_first()
, ,  ⊢  

Testing re: VecAdd.factorization()

In [19]:
from proveit import defaults
from proveit import a, b, c, i, u, v, w, x, y, z, alpha, beta, gamma, delta, fi
from proveit.linear_algebra import TensorProd, VecZero
from proveit.logic import CartExp, Forall, InSet, NotEquals
from proveit.numbers import three, Complex, Natural, Real

Let's set some defaults for convienience in our testing below.

In [20]:
R3 = CartExp(Real, three)
R3:
In [21]:
C3 = CartExp(Complex, three)
C3:
In [22]:
defaults.assumptions = [
    InSet(u, R3), InSet(v, R3), InSet(w, R3), 
    InSet(x, R3), InSet(y, R3), InSet(z, R3),
    NotEquals(x, VecZero(R3)), NotEquals(z, VecZero(R3)),
    InSet(a, Real), InSet(alpha, Complex), InSet(beta, Real),
    InSet(gamma, Real), InSet (delta, Real),
    Forall(i, InSet(fi, R3), domain=Natural)]
defaults.assumptions:
In [23]:
Mult(alpha, beta, gamma, delta).factorization(Mult(beta, gamma))
, , ,  ⊢  
In [24]:
vec_add_01 = VecAdd(ScalarMult(a, x), ScalarMult(Mult(beta, a), y))
vec_add_01:
In [25]:
vec_add_02 = VecAdd(TensorProd(x, y), TensorProd(z, y))
vec_add_02:
In [26]:
vec_add_03 = VecAdd(TensorProd(x, y, z), TensorProd(x, y, w), TensorProd(x, y, v))
vec_add_03:
In [27]:
vec_add_01_factored = vec_add_01.factorization(a, pull='left')
vec_add_01_factored: , , ,  ⊢  

Testing Begin Here! (Needs to be cleaned up and reorganized later.)

In [28]:
supposed_vec_space_membership = TensorProd(x, y).deduce_in_vec_space(field=Real)
supposed_vec_space_membership: ,  ⊢  
In [29]:
supposed_vec_space = supposed_vec_space_membership.domain
supposed_vec_space:
In [30]:
# perhaps this will help the experiment further below?
from proveit.linear_algebra.vector_spaces import containing_vec_space
containing_vec_space(TensorProd(y, z), field=Real)
In [31]:
vec_add_02_factored = vec_add_02.factorization(y, pull='right', field=Real)
vec_add_02_factored: , ,  ⊢  
In [32]:
vec_add_03

Investigating error when Prove-It is trying to perform the following:

return tensor_prod_is_in_tensor_prod_space.instantiate( {a: _a_sub, i: _i_sub, K: _K_sub, V: vec_spaces})

in tensor_prod_membership.py for the case of $x\otimes((y\otimes z) + (y\otimes w) + (y\otimes v))$

In [33]:
# reminder of assumptions:
defaults.assumptions
In [34]:
# this one will work OK (see next cell)
temp_factored_tensor_prod_01 = TensorProd(TensorProd(x, y), VecAdd(z, w, v))
temp_factored_tensor_prod_01:
In [35]:
InSet(temp_factored_tensor_prod_01, TensorProd(R3, R3, R3)).conclude()
, , , ,  ⊢  
In [36]:
temp_factored_tensor_prod_02 = TensorProd(x, VecAdd(TensorProd(y, z), TensorProd(y, w), TensorProd(y, v)))
temp_factored_tensor_prod_02:
In [37]:
deduction_as_vec_space = TensorProd(R3, R3, R3).deduce_as_vec_space()
deduction_as_vec_space:  ⊢  
In [38]:
deduced_field = deduction_as_vec_space.domain.field
deduced_field:
In [39]:
temp_factored_tensor_prod_02.deduce_in_vec_space(field=None)
, , , ,  ⊢  
In [40]:
temp_factored_tensor_prod_02.deduce_in_vec_space(field=deduced_field)
, , , ,  ⊢  
In [41]:
# interestingly, we also can already do this:
VecSpaces.known_vec_space(x, field=Real)
In [42]:
R3.deduce_as_vec_space()
In [43]:
TensorProd(x, TensorProd(y, z)).simplification()
, ,  ⊢  
In [44]:
from proveit.logic import Equals
Equals(TensorProd(R3, TensorProd(R3, R3)), TensorProd(R3, R3, R3)).prove()
In [45]:
vec_add_03_factored_02 = vec_add_03.factorization(x, pull='left', field=Real)
vec_add_03_factored_02: , , , ,  ⊢  
In [46]:
TensorProd(x, TensorProd(y, z)).shallow_simplification()
, ,  ⊢  
In [47]:
# This will not yet work, since the factor is a vector and
# appears in the scaled portion of each ScalarMult but is not a TensorProd factor
try:
    VecAdd(ScalarMult(two, x), ScalarMult(three, x)).factorization(x)
except Exception as the_exception:
    print("Exception: {}".format(the_exception))
Exception: factorization() missing 1 required keyword-only argument: 'pull'

Automatically proving conjunctions are equal via permutation

In [48]:
defaults.assumptions = [InSet(w, R3), InSet(x, R3), InSet(y, R3), InSet(z, R3)]
defaults.assumptions:
In [49]:
Equals(VecAdd(w, x, y, z), VecAdd(z, y, w, x)).prove()
, , ,  ⊢  
In [50]:
Equals(VecAdd(y, z, x, w), VecAdd(x, w, y, z)).prove()
, , ,  ⊢  
In [51]:
%end demonstrations