It is possible to compute the Kauffman bracket using Z3py? - z3

I am trying to compute the Kauffman bracket of the trefoil knot using Z3py. Until now I have the following code:
a, b, c, d, e, f, A, B = Ints('a b c d e f A B')
delta = Function('delta', IntSort(), IntSort(), IntSort())
def X(a,b,c,d):
return A*delta(a,d)*delta(b,c)+B*delta(a,b)*delta(c,d)
Trefoil = X(a,d,b,e)*X(e,b,f,c)*X(c,f,d,a)
print simplify(simplify(Trefoil, som= True),mul_to_power=True)
with this code I am obtaining the following output:
A**3·
delta(a, e)·
delta(b, f)·
delta(c, a)·
delta(d, b)·
delta(e, c)·
delta(f, d) +
A**2·
B·
delta(a, d)·
delta(b, e)·
delta(b, f)·
delta(c, a)·
delta(e, c)·
delta(f, d) +
A**2·
B·
delta(a, e)·
delta(c, a)·
delta(d, b)·
delta(e, b)·
delta(f, c)·
delta(f, d) +
A·
B**2·
delta(a, d)·
delta(b, e)·
delta(c, a)·
delta(e, b)·
delta(f, c)·
delta(f, d) +
A**2·
B·
delta(a, e)·
delta(b, f)·
delta(c, f)·
delta(d, a)·
delta(d, b)·
delta(e, c) +
A·
B**2·
delta(a, d)·
delta(b, e)·
delta(b, f)·
delta(c, f)·
delta(d, a)·
delta(e, c) +
A·
B**2·
delta(a, e)·
delta(c, f)·
delta(d, a)·
delta(d, b)·
delta(e, b)·
delta(f, c) +
B**3·
delta(a, d)·
delta(b, e)·
delta(c, f)·
delta(d, a)·
delta(e, b)·
delta(f, c)
Now I need to apply the rule:
delta(a,b)*delta(b,c) = delta(a,c)
and to simplify the output using such rule. Please, could you tell me how to do it. Many thanks.

You can use the function "substitute" to replace sub-terms by others.
However, on your example, there is no sub-term delta(a,b) or delta(a,c)
so substitution will have no effect. Bear in mind that Z3 does
not perform substitution under associativity or commutativity of operators.
So substitute(x*y*z, (x*z, u)) does not simplify to u*y.

Solution using Reduce:
Please let me know if it is possible to do the same thing using Z3PY.

Related

Why is chain of equational reasoning failing to meet trivially solvable constraints?

The following Agda code:
module test where
open import Data.Float
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_)
open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; step-≡; _∎)
postulate
distrib : {m a b : Float} → m * (a + b) ≡ (m * a) + (m * b)
dbg : (m a b : Float) → m * (a + b) ≡ (m * a) + (m * b)
dbg m a b =
begin
m * (a + b)
≡⟨ distrib ⟩ -- (Line "22")
(m * a) + (m * b)
∎
yields:
_m_18 : Float [ at /Users/dbanas/Documents/Agda/agda_misc/test.agda:22,6-13 ]
_a_19 : Float [ at /Users/dbanas/Documents/Agda/agda_misc/test.agda:22,6-13 ]
_b_20 : Float [ at /Users/dbanas/Documents/Agda/agda_misc/test.agda:22,6-13 ]
———— Errors ————————————————————————————————————————————————
Failed to solve the following constraints:
(_m_18 * _a_19) + (_m_18 * _b_20) = (m * a) + (m * b) : Float
_m_18 * (_a_19 + _b_20) = m * (a + b) : Float
after I type C-c C-l.
(Note: "22,6-13" identifies the second occurrence of the word "distrib".)
I don't understand why the constraints can't be met.
They seem trivially solvable:
_m_18 = m
_a_19 = a
_b_20 = b
While those solutions are correct, they're not inevitable, because multiplication and addition are not injective. In this case, you can fill in just m in line 22, ie distrib {m = m}.

linsolve in maxima no work for these equations

I am very novice in maxima. I want to get the solution for W using these equations:
e1: A*W + B*Y = I$
e2: C*W + D*Y = 0$
linsolve ([e1, e2], [W]);
But linsolve just generates [].
The example in the manual works:
(%i1) e1: x + z = y$
(%i2) e2: 2*a*x - y = 2*a^2$
(%i3) e3: y - 2*z = 2$
(%i4) linsolve ([e1, e2, e3], [x, y, z]);
(%o4) [x = a + 1, y = 2 a, z = a - 1]
That means that the equation cannot be solved for the variables that you requested. You have to solve in respect to both variables:
linsolve([e1,e2],[W,Y]);
D I C I
[W = - ---------, Y = ---------]
B C - A D B C - A D
You can solve for W for each of your equations separately. For example:
linsolve ([e1],[W]);
B Y - I
[W = - -------]
A

Maxima CAS - substitution

I am trying to simplify a differential equation via substitution in maxima. However, the substitution does not seem to be working.
Here's my code:
depends (\rho,[t, r, \theta, z]); depends (V, [t, r, \theta, z]);
f_contin : diff (\rho, t) + diff (\rho*r*V[r], r)*(1/r) = 0;
base : diff (V[b]*r*\rho, r) = 0;
V_sub : V[r] = V[b] + \epsilon*V[r];
subst (V_sub, f_contin);
subst (base, %o6);
The last substitution did not work. What am I doing wrong here?
For clarity I add a Screenshot here:
The problem is that subst(a=b, c) (or equivalently subst(b, a, c)) can only make substitutions when a is an exact subexpression of c.
ratsubst (which see) can handle some cases when a is not an exact subexepression but in this case it doesn't seem to work.
But I think you can get the result you want by just subtracting the one equation from the other. Note that (a=b) - (c=d) yields a - c = b - d. Note also that I've put in another step (in %i7) to apply the diff operator. Also I've multiplied %o7 by r to get something like base.
(%i1) depends (\rho,[t, r, \theta, z]); depends (V, [t, r, \theta, z]);
(%o1) [rho(t, r, theta, z)]
(%o2) [V(t, r, theta, z)]
(%i3) f_contin : diff (\rho, t) + diff (\rho*r*V[r], r)*(1/r) = 0;
drho d
r V ---- + r (-- (V )) rho + V rho
drho r dr dr r r
(%o3) ---- + ------------------------------------ = 0
dt r
(%i4) base : diff (V[b]*r*\rho, r) = 0;
drho d
(%o4) V r ---- + (-- (V )) r rho + V rho = 0
b dr dr b b
(%i5) V_sub : V[r] = V[b] + \epsilon*V[r];
(%o5) V = epsilon V + V
r r b
(%i6) subst (V_sub, f_contin);
drho drho d
(%o6) ---- + (r (epsilon V + V ) ---- + r (-- (epsilon V + V )) rho
dt r b dr dr r b
+ (epsilon V + V ) rho)/r = 0
r b
(%i7) %o6, nouns;
drho drho d d
(%o7) ---- + (r (epsilon V + V ) ---- + r (epsilon (-- (V )) + -- (V )) rho
dt r b dr dr r dr b
+ (epsilon V + V ) rho)/r = 0
r b
(%i8) expand (r*%o7 - base);
drho drho d
(%o8) r ---- + epsilon r V ---- + epsilon r (-- (V )) rho + epsilon V rho = 0
dt r dr dr r r
The function subst (a,b,c) substitutes a for b in c. It uses 3 arguments, your first subst works because its interpreted as subst (V[b] + \epsilon*V[r],V[r], f_contin);
Your second subst is probably interpreted as subst (0,diff (V[b]*r*\rho, r),%) therefor nothing is substituted. What do you want to substitute for what?

Combining proofs of commutativity and associativity of addition

I am trying to proof the below lemma
infixr 5 _~_
_~_ = trans
lemma-+swap : ∀ a b c → a + (b + c) ≡ b + (a + c)
lemma-+swap zero b c = refl
lemma-+swap (suc a) b c = (+-assoc a b c) ~ (comm-+ a (b + c)) ~ (+-assoc b c a)
Note : I imported this file
open import Relation.Binary.PropositionalEquality as PropEq
using (_≡_; refl; sym; trans; cong; cong₂)
While on paper I tried in this way :
(a + b) + c equivalent a + (b + c) -- associativity
a + (b + c) equivalent to (b + c) + a -- commutativity
(b + c) + a equi to b + (c + a) -- associativity
I wrote this in goal but getting error. I have proof of associative and commutative property. Please help.
Transcribing the proof you already have on paper
A very nice way of writing proofs like this is to use the Relation.Binary.PropositionalEquality.≡-Reasoning module, because it enables you to write out your proof exactly how you would do it on paper:
open import Relation.Binary.PropositionalEquality as PropEq using (_≡_)
open import Data.Nat
open import Data.Nat.Properties.Simple using (+-assoc; +-comm)
lemma-+swap : ∀ a b c → a + (b + c) ≡ b + (a + c)
lemma-+swap a b c = begin
a + (b + c) ≡⟨ {!!} ⟩
(a + b) + c ≡⟨ {!!} ⟩
(b + a) + c ≡⟨ {!!} ⟩
b + (a + c) ∎
where
open PropEq.≡-Reasoning
Now all you need to fill in are the three holes corresponding to the three steps of the proof.
Using the semiring solver
The hassle-free way is to just let the semiring solver take care of your equality, since addition and multiplication of natural numbers form a semiring. However, I don't recommend you do this for now, since it seems you need way more experience with the fundamentals to ensure you won't fall into the trap of thinking the semiring solver is black-box magic that shouldn't be understood. So the below is meant more for other readers of this answer and not so much to OP:
open import Relation.Binary.PropositionalEquality as PropEq using (_≡_; refl)
open import Data.Nat
lemma-+swap : ∀ a b c → a + (b + c) ≡ b + (a + c)
lemma-+swap = solve 3 (λ a b c → a :+ (b :+ c) := b :+ (a :+ c)) refl
where
open import Data.Nat.Properties as Nat
open Nat.SemiringSolver
You are basically doing needless case splitting. Let's check the goal in both function clauses. In the first one, we get:
lemma-+swap zero b c = ?
-- goal: b + c ≡ b + c
which is satisfied by simple refl. The second one is however:
lemma-+swap (suc a) b c = ?
-- goal: suc (a + (b + c)) ≡ b + suc (a + c)
And notice that +-assoc a b c (from Data.Nat.Properties.Simple) has a type a + b + c ≡ a + (b + c) - with no suc in sight.
So you have two options: the prefered one is to avoid case splitting and use the properties directly. The other one is to use the properties with suc a instead of a.
Your implementation also most likely won't work even if you fix the above problem.
Here, I assume your properties have the same type as the ones from the module mentioned above (which is a fair assumption, given that for the other variations the subexpression +-assoc a b c ~ comm-+ a (b + c) ~ +-assoc b c a does not typecheck).
+-assoc a b c : a + b + c ≡ a + (b + c)
+-comm a (b + c) : a + (b + c) ≡ b + c + a
+-assoc b c a : b + c + a ≡ b + (c + a)
+-assoc a b c ~ comm-+ a (b + c) ~ +-assoc b c a : a + b + c ≡ b + (c + a) (*)
So, the subexpression has the type (*), but your goal is a + (b + c) ≡ b + (a + c).

symbolically replace expressions in maxima

I'm having trouble finding out how to do this:
x=a+b
y=c+d
z=x*y
I would like the output to be
z=ac+ad+bc+bd
not
z=xy
Like this?
(%i1) x: a+b;
(%o1) b + a
(%i2) y: c+d;
(%o2) d + c
(%i3) z: x*y;
(%o3) (b + a) (d + c)
(%i4) z: expand (z);
(%o4) b d + a d + b c + a c
(%i5)
Assignment in maxima is done by :, not = (which is used for checking for equality)
Actually, to get the output he's requesting without assigning a lot of variables,
you can just do this:
(%i1) z = x*y, x = a+b, y = c+d, expand;
(%o1) z = b d + a d + b c + a c
This is an old question, but the canonical solution in my opinion is the subst() function

Resources