예제 #1
0
def apply(n, m, b):
    i = Symbol.i(integer=True)

    return Equality(
        Concatenate(
            Concatenate(MatProduct[i:m](Swap(n, i, b[i])), ZeroMatrix(n)).T,
            Concatenate(ZeroMatrix(n), 1)).T,
        MatProduct[i:m](Swap(n + 1, i, b[i])))
예제 #2
0
def apply(n):
    i = Symbol.i(integer=True)
    j = Symbol.j(integer=True)

    return Equality(
        Concatenate(
            Concatenate(Swap(n, i, j), ZeroMatrix(n)).T,
            Concatenate(ZeroMatrix(n), 1)), Swap(n + 1, i, j))
예제 #3
0
def apply(x, w=None):
    n = x.shape[0]
    i = Symbol.i(integer=True)
    j = Symbol.j(integer=True)

    if w is None:
        w = Symbol.w(shape=(n, n, n), definition=LAMBDA[j:n](Swap(n, 0, j)))

    assert w.shape == (n, n, n)
    assert w[j].definition == Swap(n, 0, j)

    return Equality(
        LAMBDA[i:n](x[w[j][i] @ LAMBDA[i:n](i)]), LAMBDA[i:n](Piecewise(
            (x[0], Equality(i, j)), (x[j], Equality(i, 0)), (x[i], True))))
예제 #4
0
def prove(Eq):
    n = Symbol.n(domain=Interval(2, oo, integer=True))
    i = Symbol.i(domain=Interval(0, n - 1, integer=True))
    j = Symbol.j(domain=Interval(0, n - 1, integer=True))
    
    assert Identity(n).is_integer
    w = Symbol.w(integer=True, shape=(n, n, n, n), definition=LAMBDA[j, i](Swap(n, i, j)))
    
    Eq << apply(w)

    Eq << w[j, i].equality_defined()
    
    Eq << Eq[0] @ Eq[-1]
    
    Eq << Eq[-1].this.rhs.expand()
    
    Eq << Eq[-1].this.rhs.simplify(deep=True, wrt=Eq[-1].rhs.variable)
    
    Eq << Eq[-1].this.rhs.function.as_KroneckerDelta()
    
    Eq << Eq[0] @ Eq[0]
    
    Eq << Eq[-1].subs(Eq[-2].reversed)
    
    Eq << w[i, j].inverse() @ Eq[-1]
    
    Eq << Eq[-1].forall((i,), (j,))
예제 #5
0
def apply(given, i=None, j=None, w=None):
    assert given.is_Equality
    x_set_comprehension, interval = given.args
    n = interval.max() + 1
    assert interval.min() == 0
    assert len(x_set_comprehension.limits) == 1
    k, a, b = x_set_comprehension.limits[0]
    assert b - a == n - 1
    x = LAMBDA(x_set_comprehension.function.arg,
               *x_set_comprehension.limits).simplify()

    if j is None:
        j = Symbol.j(domain=[0, n - 1], integer=True, given=True)

    if i is None:
        i = Symbol.i(domain=[0, n - 1], integer=True, given=True)

    assert j >= 0 and j < n
    assert i >= 0 and i < n

    index = index_function(n)
    if w is None:
        _i = Symbol.i(integer=True)
        _j = Symbol.j(integer=True)
        w = Symbol.w(definition=LAMBDA[_j:n, _i:n](Swap(n, _i, _j)))

    return Equality(index[i](w[index[i](x[:n]), index[j](x[:n])] @ x[:n]),
                    index[j](x[:n]),
                    given=given)
예제 #6
0
def apply(given):
    assert given.is_ForAll and len(given.limits) == 2
    j, a, n_munis_1 = given.limits[0]
    assert a == 1
    x, S = given.limits[1]

    contains = given.function
    assert contains.is_Contains
    ref, _S = contains.args
    assert S == _S and ref.is_LAMBDA and S.is_set
    dtype = S.element_type

    assert len(ref.limits) == 1
    i, a, _n_munis_1 = ref.limits[0]
    assert _n_munis_1 == n_munis_1 and a == 0

    piecewise = ref.function
    assert piecewise.is_Piecewise and len(piecewise.args) == 3

    x0, condition0 = piecewise.args[0]
    assert condition0.is_Equality and {*condition0.args} == {i, j}

    xj, conditionj = piecewise.args[1]
    assert conditionj.is_Equality and {*conditionj.args} == {i, 0}

    xi, conditioni = piecewise.args[2]
    assert conditioni

    n = n_munis_1 + 1

    assert x[j] == xj and x[i] == xi and x[0] == x0 and dtype == x.dtype

    w = Symbol.w(definition=LAMBDA[j:n, i:n](Swap(n, i, j)))

    return ForAll(Contains(w[i, j] @ x, S), (x, S), given=given)
예제 #7
0
def apply(x, w=None, left=True, reference=True):
    n = x.shape[0]
    i = Symbol.i(integer=True)
    j = Symbol.j(integer=True)
    k = Symbol.k(integer=True)

    if w is None:
        w = Symbol.w(integer=True,
                     shape=(n, n, n, n),
                     definition=LAMBDA[j:n, i:n](Swap(n, i, j)))
    else:
        assert len(w.shape) == 4 and all(s == n for s in w.shape)

    if left:
        if reference:
            return Equality(LAMBDA[k:n](x[w[i, j, k] @ LAMBDA[k:n](k)]),
                            w[i, j] @ x)
        else:
            return Equality(x[w[i, j, k] @ LAMBDA[k:n](k)], w[i, j, k] @ x)
    else:
        if reference:
            return Equality(LAMBDA[k:n](x[LAMBDA[k:n](k) @ w[i, j, k]]),
                            x @ w[i, j])
        else:
            return Equality(x[LAMBDA[k:n](k) @ w[i, j, k]], x @ w[i, j, k])
예제 #8
0
def prove(Eq):
    n = Symbol.n(domain=Interval(2, oo, integer=True))
    S = Symbol.S(dtype=dtype.integer * n)

    x = Symbol.x(**S.element_symbol().dtype.dict)

    i = Symbol.i(integer=True)
    j = Symbol.j(integer=True)

    w = Symbol.w(integer=True,
                 shape=(n, n, n, n),
                 definition=LAMBDA[j:n, i:n](Swap(n, i, j)))

    k = Symbol.k(integer=True)

    given = ForAll[x:S](Contains(LAMBDA[k:n](x[(w[i, j] @ LAMBDA[k:n](k))[k]]),
                                 S))

    Eq.P_definition, Eq.w_definition, Eq.swap, Eq.axiom = apply(given)

    Eq << algebre.matrix.elementary.swap.identity.apply(x, w)

    Eq << Eq.swap.subs(Eq[-1])

    Eq << swapn.permutation.apply(Eq[-1])
예제 #9
0
def apply(x):
    n = x.shape[0]
    i = Symbol.i(domain=Interval(0, n - 1, integer=True))
    j = Symbol.j(domain=Interval(0, n - 1, integer=True))
    
    w = Symbol.w(integer=True, shape=(n, n, n, n), definition=LAMBDA[j, i](Swap(n, i, j)))
    
    return Equality(x @ w[i, j] @ w[i, j], x)
예제 #10
0
def apply(n, w=None):
    i = Symbol.i(domain=Interval(0, n - 1, integer=True))
    j = Symbol.j(domain=Interval(0, n - 1, integer=True))
    
    assert n >= 2
    if w is None:
        w = Symbol.w(definition=LAMBDA[j, i](Swap(n, i, j)))
    else:
        assert len(w.shape) == 4 and all(s == n for s in w.shape)
    
    return ForAll(Equality(w[0, i] @ w[0, j] @ w[0, i], w[i, j]), (j, Interval(1, n - 1, integer=True) - i.set))
예제 #11
0
def apply(n, w=None):
    domain = Interval(0, n - 1, integer=True)
    t = Symbol.t(domain=domain)
    i = Symbol.i(domain=domain)
    j = Symbol.j(domain=domain)
    assert n >= 2
    if w is None:
        w = Symbol.w(definition=LAMBDA[j, i](Swap(n, i, j)))

    return ForAll(Equality(w[t, i] @ w[t, j] @ w[t, i], w[i, j]),
                  (j, domain - {i, t}))
예제 #12
0
파일: Qu2v.py 프로젝트: cosmosZhou/sagemath
def predefined_symbols(n):
    x = Symbol.x(shape=(oo, ), integer=True, nonnegative=True)
    t = Symbol.t(integer=True)
    Q = Symbol.Q(definition=LAMBDA[t:n + 1](conditionset(
        x[:n + 1],
        Equality(x[:n + 1].set_comprehension(), Interval(0, n, integer=True))
        & Equality(x[n], t))))
    j = Symbol.j(integer=True)
    i = Symbol.i(integer=True)
    w = Symbol.w(definition=LAMBDA[j:n + 1, i:n + 1](Swap(n + 1, i, j)))

    return Q, w, x
예제 #13
0
파일: left.py 프로젝트: cosmosZhou/sagemath
def apply(x, i=None, j=None, w=None):
    n = x.shape[0]
    if i is None:
        i = Symbol.i(domain=Interval(0, n - 1, integer=True))
        
    if j is None:
        j = Symbol.j(domain=Interval(0, n - 1, integer=True))
    
    if w is None:
        w = Symbol.w(definition=LAMBDA[j, i](Swap(n, i, j)))
    
    return Equality(w[i, j] @ w[i, j] @ x, x)
예제 #14
0
def prove(Eq): 
    n = Symbol.n(domain=Interval(2, oo, integer=True))
    S = Symbol.S(dtype=dtype.integer * n)    
    
    x = Symbol.x(**S.element_symbol().dtype.dict)
    
    i = Symbol.i(integer=True)
    j = Symbol.j(integer=True)    
    
    w = Symbol.w(integer=True, shape=(n, n, n, n), definition=LAMBDA[j:n, i:n](Swap(n, i, j)))
    
    given = ForAll[x:S](Contains(w[0, j] @ x, S))
    
    Eq << apply(given)
    
    Eq.given_i = given.subs(j, i)    
    
    Eq << given.subs(x, Eq.given_i.function.lhs)
    
    Eq << (Eq.given_i & Eq[-1]).split()[-1]
    
    Eq << Eq.given_i.subs(x, Eq[-1].function.lhs)
    
    Eq.final_statement = (Eq[-2] & Eq[-1]).split()[0]
    
    Eq << swap2.equality.apply(n, w)
    
    Eq << Eq[-1] @ x
    
    Eq << Eq[-1].forall((Eq[-1].limits[0].args[1].args[1].arg,))
    
    Eq.i_complement = Eq.final_statement.subs(Eq[-1])
    
    Eq.plausible = ForAll(Contains(w[i, j] @ x, S), (x, S), (j, Interval(1, n - 1, integer=True)), plausible=True)    
    
    Eq << Eq.plausible.bisect(i.set, wrt=j)
    
    Eq.i_complement, Eq.i_intersection = Eq[-1].split()
    
    Eq << sets.imply.equality.intersection.apply(i, Interval(1, n - 1, integer=True))
    
    Eq << Eq.i_intersection.this.limits[1].subs(Eq[-1])
    
    Eq << Eq[-1].subs(w[i, i].equality_defined())
    
    Eq << (Eq.i_complement & Eq.i_intersection)
    
    Eq << elementary.swap.transpose.apply(w).subs(j, 0)
    Eq << Eq.given_i.subs(Eq[-1].reversed)
    
    Eq << (Eq[-1] & Eq.plausible)
예제 #15
0
파일: set.py 프로젝트: cosmosZhou/sagemath
def apply(x, w=None):
    n = x.shape[0]
    i = Symbol.i(integer=True)
    j = Symbol.j(integer=True)
    if w is None:
        w = Symbol.w(integer=True,
                     shape=(n, n, n, n),
                     definition=LAMBDA[j:n, i:n](Swap(n, i, j)))
    else:
        assert len(w.shape) == 4 and all(s == n for s in w.shape)
        assert w[i, j].is_Swap or w[i, j].definition.is_Swap

    lhs = (w[i, j] @ x).set_comprehension()
    return Equality(lhs, x.set_comprehension(free_symbol=lhs.variable))
예제 #16
0
def apply(n):
    i = Symbol.i(integer=True)

    p = Symbol.p(shape=(oo, ), integer=True, nonnegative=True)

    P = Symbol.P(dtype=dtype.integer * n,
                 definition=conditionset(
                     p[:n],
                     Equality(p[:n].set_comprehension(),
                              Interval(0, n - 1, integer=True))))

    b = Symbol.b(integer=True, shape=(oo, ), nonnegative=True)

    return ForAll[p[:n]:P](Exists[b[:n]](Equality(
        p[:n], LAMBDA[i:n](i) @ MatProduct[i:n](Swap(n, i, b[i])))))
예제 #17
0
def apply(x, d, w=None):
    n = x.shape[0]
    assert d.shape == (n, )
    i = Symbol.i(integer=True)
    j = Symbol.j(integer=True)
    k = Symbol.k(integer=True)

    if w is None:
        w = Symbol.w(integer=True,
                     shape=(n, n, n, n),
                     definition=LAMBDA[j:n, i:n](Swap(n, i, j)))
    else:
        assert len(w.shape) == 4 and all(s == n for s in w.shape)
        assert w[i, j].is_Swap or w[i, j].definition.is_Swap

    return Equality(x[d @ w[i, j, k]], LAMBDA[k:n](x[d[k]]) @ w[i, j, k])
예제 #18
0
def apply(x, d, w=None):
    n = x.shape[0]
    m = d.shape[0]
    assert m.is_integer and m.is_finite
    i = Symbol.i(integer=True)
    j = Symbol.j(integer=True)
    k = Symbol.k(integer=True)

    if w is None:
        w = Symbol.w(integer=True,
                     shape=(n, n, n, n),
                     definition=LAMBDA[j:n, i:n](Swap(n, i, j)))
    else:
        assert len(w.shape) == 4 and all(s == n for s in w.shape)
        assert w[i, j].is_Swap or w[i, j].definition.is_Swap

    multiplier = MatProduct[i:m](w[i, d[i]])
    return Equality(LAMBDA[k:n](x[(LAMBDA[k:n](k) @ multiplier)[k]]),
                    x @ multiplier)
예제 #19
0
def apply(n, w=None, left=True, P=None):
    i = Symbol.i(integer=True)
    j = Symbol.j(integer=True)    
    
    if w is None:
        w = Symbol.w(definition=LAMBDA[j:n, i:n](Swap(n, i, j)))
    else:
        assert len(w.shape) == 4 and all(s == n for s in w.shape)
        assert w[i, j].is_Swap or w[i, j].definition.is_Swap
        
    x = Symbol.x(shape=(oo,), integer=True, nonnegative=True)
    x = x[:n]
    
    if P is None:
        P = Symbol.P(dtype=dtype.integer * n, definition=conditionset(x, Equality(x.set_comprehension(), Interval(0, n - 1, integer=True))))
    
    if left:
        return ForAll[x:P](Contains(w[i, j] @ x, P))
    else:
        return ForAll[x:P](Contains(x @ w[i, j], P))
예제 #20
0
def apply(m, d, w=None):
    n = d.shape[0]
    i = Symbol.i(integer=True)
    j = Symbol.j(integer=True)

    assert m >= 0
    if w is None:
        w = Symbol.w(definition=LAMBDA[j, i](Swap(n, i, j)))
    else:
        assert len(w.shape) == 4 and all(s == n for s in w.shape)
        assert w[i, j].is_Swap or w[i, j].definition.is_Swap

    x = Symbol.x(shape=(oo, ), integer=True, nonnegative=True)
    x = x[:n]

    P = Symbol.P(dtype=dtype.integer * n,
                 definition=conditionset(
                     x,
                     Equality(x.set_comprehension(),
                              Interval(0, n - 1, integer=True))))

    return ForAll[x:P](Contains(x @ MatProduct[i:m](w[i, d[i]]), P))
예제 #21
0
def prove(Eq):
    n = Symbol.n(domain=Interval(2, oo, integer=True))
    S = Symbol.S(dtype=dtype.integer * n, given=True)

    x = Symbol.x(shape=(oo, ), integer=True)

    i = Symbol.i(integer=True)
    j = Symbol.j(integer=True)

    w = Symbol.w(definition=LAMBDA[j:n, i:n](Swap(n, i, j)))

    given = ForAll[x[:n]:S](Contains(w[i, j] @ x[:n], S))

    Eq.P_definition, Eq.w_definition, Eq.swap, Eq.axiom = apply(given)

    Eq << factorization.apply(n)

    *_, b_i = Eq[-1].rhs.args[1].function.args
    b, _i = b_i.args
    Eq << Eq.w_definition.subs(j, b[_i]).subs(i, _i)

    Eq << Eq[-2].subs(Eq[-1].reversed)

    k = Eq.axiom.lhs.variable
    Eq << Eq[-1][k]

    Eq << Eq[-1].this.function.function.rhs.args[0].limits_subs(_i, k)

    Eq << swapn.utility.apply(x[:n], b[:n], w)

    Eq << Eq[-1].subs(Eq[-2].reversed)

    Eq.plausible = Eq.axiom.subs(Eq[-1])

    Eq << swapn.mat_product.apply(Eq.swap.T, n, b)

    Eq << Eq.plausible.this.function.as_ForAll()
예제 #22
0
def prove(Eq): 
    n = Symbol.n(domain=Interval(2, oo, integer=True))
    S = Symbol.S(dtype=dtype.integer * n, given=True)    
    
    x = Symbol.x(shape=(n,), integer=True)
    
    i = Symbol.i(integer=True)
    j = Symbol.j(integer=True)    
    
    w = Symbol.w(definition=LAMBDA[j:n, i:n](Swap(n, i, j)))
    
    given = ForAll[x[:n]:S](Contains(x[:n] @ w[i, j], S))
    
    Eq.w_definition, Eq.swap, Eq.mat_product = apply(given)
    
    i, _, m_1 = Eq.mat_product.function.lhs.args[1].limits[0]
    m = m_1 + 1
    
    b = Eq.mat_product.function.lhs.args[1].function.indices[1].base
    
    Eq << Eq.mat_product.subs(m, 0)
    Eq << Eq.mat_product.subs(m, m + 1)
    
    Eq << Eq[-1].function.lhs.args[1].this.bisect(Slice[-1:])
    
    Eq << x @ Eq[-1]
    
    Eq << Eq.swap.subs(i, m).subs(j, b[m])
    
    Eq << Eq[-1].subs(x, Eq[2].rhs.func(*Eq[2].rhs.args[:2]))
    
    Eq << Eq[-1].forall((x, S))
    
    Eq << (Eq[-1] & Eq.mat_product).split()
    
    Eq << Eq[-1].subs(Eq[2].reversed)