I am learning the basic part right now. And I found that the mult function contains plus as below:
Fixpoint mult (n m : nat) : nat :=
match n with
| O ⇒ O
| S n' ⇒ plus m (mult n' m)
end.
Example test_mult1: (mult 3 3) = 9.
Proof. simpl. reflexivity. Qed.
i unfold the mult and it showed
1 subgoal
______________________________________(1/1)
3 + (3 + (3 + 0)) = 9
I know that BC plus m and m is 3 so there are 3 times of plus. But I am curious where the 0 comes from. if this 3 means m, then where is n?
Thank you!
First, you should remember that 3 is a notation for S (S (S O))
When you ask for the computation of mult 3 3, only one step of mult, you get this:
mult 3 3 = mult (S 2) 3 = 3 + mult 2 3
Now if you compute mult 2 3 you get :
mult 2 3 = mult (S 1) 3 = 3 + mult 1 3
and then:
mult 1 3 = mult (S O) 3 = 3 + mult 0 3
and tnen:
mult 0 3 = 0
So the 0 that appears when computing mult comes from mult 0 3
Related
I'm using nssm.exe in my scripts to manage the windows services. But in PowerShell, the command output is coming with spaces after every alphabet.
PS> $nssm = (Get-Command D:\nssm.exe)
PS> & $nssm
nssm.exe : N S S M : T h e n o n - s u c k i n g s e r v i c e m a n a g e r
At line:1 char:1
+ & $nssm
+ ~~~~~~~
+ CategoryInfo : NotSpecified: (N S S M : T h... m a n a g e r :String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
V e r s i o n 2 . 2 4 3 2 - b i t , 2 0 1 4 - 0 8 - 3 1
U s a g e : n s s m < o p t i o n > [ < a r g s > . . . ]
T o s h o w s e r v i c e i n s t a l l a t i o n G U I :
n s s m i n s t a l l [ < s e r v i c e n a m e > ]
T o i n s t a l l a s e r v i c e w i t h o u t c o n f i r m a t i o n :
n s s m i n s t a l l < s e r v i c e n a m e > < a p p > [ < a r g s > . . . ]
T o s h o w s e r v i c e e d i t i n g G U I :
n s s m e d i t < s e r v i c e n a m e >
How to get the output without such wide-format spaces among alphabets?
Given this objective function:
Minimize:
f = (Ax + By)' * G * (Ax + By)
subject to some equalities and inequalities.
where x and y are real-valued vectors (decision variables) with p and q elements, respectively. A of size m * p, B of size m * q, G is a symmetric matrix of size m * m.
My question is how to write f in the form v' * G * v, such that it can be easily be used in quadprog. In other words, how to mix A, B and G?
This looks incompletely specified!
It seems, for whatever reason, you want to model in terms of two variable components. Now you did not specify how they interact with each other.
As most optimizers work on a single variable-vector, you need to concatenate yours.
As you did not show G, i'm assuming you got one G for x and one for y, let's call it H.
(Remark: not a matlab user; don't take example-syntax for granted!)
z = [x y]
P = blkdiag(G,H)
assuming x and y independent in regards to quadratic-term
e.g. no x0*y1 like terms
Solve: for z` P z
Example:
x = [x0 x1 x2]
y = [y0 y1]
G = [6 2 1; 2 5 2; 1 2 4]
H = [8 2; 2 10]
# G
6 2 1
2 5 2
1 2 4
# H
8 2
2 8
z = [x0 x1 x2 y0 y1]
P = [6 2 1 0 0; 2 5 2 0 0; 1 2 4 0 0; 0 0 0 8 2; 0 0 0 2 8]
# P
6 2 1 0 0
2 5 2 0 0
1 2 4 0 0
0 0 0 8 2
0 0 0 2 8
I simplified the original problem up to this point
((P∧¬R)∨(¬Q∨R))∧((Q∧¬R)∨(¬P∨R))
, and I got stuck here. What would be the next step? Thanks for the help!!
I am solving it with you.
Hint-1: ((P∧Q)∨R) = (PVR) ∧ (QVR)
Hint-2: P ∧ True = P
Hint-3: P V True = True
Answer
It would be true in the end. Check it once.
Next step would be
= [(P V (~Q V R)) ^ ( ~R V (~Q V R))]
^[(Q V (~P V R)) ^ ( ~R V (~P V R))]
= (P V ~Q V R) ^ ( ~p V Q V R)
= R V ( (P V ~Q) ^ ( Q V ~P))
= R v (( Q -> P ) ^ ( P -> Q))
= R V (P <-> Q)
whenever R is True it is True.
Else
P Q P<->Q
------------------
F F T
F T F
T F F
T T T
So it conforms to the truth table. Shown above by trincot.
The following expressions are equivalent:
(p ⇒ r) ⇔ (q ⇒ r)
(¬p v r) ⇔ (¬q v r)
(¬p ⇔ ¬q) v r
(p ⇔ q) v r
(p ∧ q) v (¬p ∧ ¬q) v r
Truth table:
p q r result
---------------
0 0 0 1
0 0 1 1
0 1 0 0
0 1 1 1
1 0 0 0
1 0 1 1
1 1 0 1
1 1 1 1
I have a lemma that is proved for Z. All the variables are bounded to be greater that or equal to zero.
Q: How can one as easily and generally as possible "port" that lemma to nat, i.e. use that lemma to prove a similar lemma for nat by using the lemma for Z?
Example:
Require Import ZArith.
Open Scope Z.
Lemma Z_lemma:
forall n n0 n1 n2 n3 n4 n5 n6 : Z,
n >= 0 -> n0 >= 0 -> n1 >= 0 ->
n2 >= 0 -> n3 >= 0 -> n4 >= 0 ->
n5 >= 0 -> n6 >= 0 ->
n5 + n4 = n6 + n3 ->
n1 + n0 = n2 + n ->
n5 * n1 + n6 * n2 + n3 * n0 + n * n4 =
n5 * n2 + n1 * n6 + n3 * n + n0 * n4.
Admitted.
Close Scope Z.
Lemma nat_lemma:
forall n n0 n1 n2 n3 n4 n5 n6 : nat,
n5 + n4 = n6 + n3 ->
n1 + n0 = n2 + n ->
n5 * n1 + n6 * n2 + n3 * n0 + n * n4 =
n5 * n2 + n1 * n6 + n3 * n + n0 * n4.
(* prove this using `Z_lemma` *)
You can do it rather generically for all the lemmas which have this shape by defining a tactic exploiting the fact that Z.of_nat is injective and distributes over (+) and (*):
Ltac solve_using_Z_and lemma :=
(* Apply Z.of_nat to both sides of the equation *)
apply Nat2Z.inj;
(* Push Z.of_nat through multiplications and additions *)
repeat (rewrite Nat2Z.inj_mul || rewrite Nat2Z.inj_add);
(* Apply the lemma passed as an argument*)
apply lemma;
(* Discharge all the goals with the shape Z.of_nat m >= 0 *)
try (apply Zle_ge, Nat2Z.is_nonneg);
(* Push the multiplications and additions back through Z.of_nat *)
repeat (rewrite <- Nat2Z.inj_mul || rewrite <- Nat2Z.inj_add);
(* Peal off Z.of_nat on each side of the equation *)
f_equal;
(* Look up the assumption in the environment*)
assumption.
The proof of nat_lemma now simply becomes:
Lemma nat_lemma:
forall n n0 n1 n2 n3 n4 n5 n6 : nat,
n5 + n4 = n6 + n3 ->
n1 + n0 = n2 + n ->
n5 * n1 + n6 * n2 + n3 * n0 + n * n4 =
n5 * n2 + n1 * n6 + n3 * n + n0 * n4.
Proof.
intros; solve_using_Z_and Z_lemma.
Qed.
My requirement is to find the location of a particular string in a line from notepad file but while reading it in powershell additional space get added that's why not able to find the location of a particular string. How I can find the location is this case??
I am using this code for achieving this
$ParamsPathForData = ($dir + "\TimeStats\TimeStats_1slot\29_12_2015_07TimeStats1.txt")
$data = Get-Content $ParamsPathForData
write-host $data.count total lines read from file
foreach ($line in $data)
{
$l =$line.IndexOf("12/29/2015")
write-host $l
}
I am reading this line from notepad ->
TimeStats 29 12/29/2015 7:13:42 AM +00:00 Debug PREPROCESS: SlotNo:
325-00313, Ip Address: 10.2.200.15, Duplicate Message: False,
Player-Card-No: , MessageId: 883250003130047966, MessageName:
GameIdInfo, Thread Init Delay: 14, Time To Parse: 155, Time To Exec
Main Workflow: 424, Time To Construct & send Response: 22, Total
Response Time: 615
But while exceuting it in powershell i am getting this with additinal spaces ->
T i m e S t a t s 2 9 1 2 / 2 9 / 2 0 1 5 7 : 1 3 : 4 2 A M
+ 0 0 : 0 0 D e b u g P R E P R O C E S S : S l o t N o : 3 2 5 - 0 0 3 1 3 , I p A d d r e s s : 1 0 . 2 . 2 0 0 . 1 5 , D
u p l i c a t e M e s s a g e : F a l s e , P l a y e r
- C a r d - N o : , M e s s a g e I d : 8 8 3 2 5 0 0 0 3 1 3 0 0 4 7 9 6 6 , M e s s a g e N a m e : G a m e I d I n f o , T h
r e a d I n i t D e l a y : 1 4 , T i m e T o P a r s e :
1 5 5 , T i m e T o E x e c M a i n W o r k f l o w : 4 2
4 , T i m e T o C o n s t r u c t & s e n d R e s p o n s
e : 2 2 , T o t a l R e s p o n s e T i m e : 6 1 5
Anybody please help me???
Change the the encoding to Unicode...
$data = Get-Content $ParamsPathForData -Encoding Unicode