How to get rid of Syntax error near "or" in Verilog - syntax-error

I have recently started learning Verilog.
I am trying to build a Full Adder using task
task fullAdder(input a, b, c_in, output reg sum, c_out);
reg x, y, z;
begin
halfAdder H1(x, y, a, b);
halfAdder H2(sum, z, c_in, x);
or M3(c_out, y, z);
end
endtask
task halfAdder(input a, b, output sum, c_out);
xor M1(sum, a, b);
and M2(c_out, a, b);
endtask
I don't know what is wrong in my code, but it is giving errors like:
Syntax error near "or".
Syntax error near "xor".
Syntax error near "and".

You must not place instances inside a task; they should be in a module instead. Also, you should remove the reg type from the output ports, and change the internal reg to wire:
module fullAdder(input a, b, c_in, output sum, c_out);
wire x, y, z;
begin
halfAdder H1(x, y, a, b);
halfAdder H2(sum, z, c_in, x);
or M3(c_out, y, z);
end
endmodule
module halfAdder(input a, b, output sum, c_out);
xor M1(sum, a, b);
and M2(c_out, a, b);
endmodule
You can open up a free account on edaplayground, where you will have access to simulators which give you more specific information about your syntax errors.

Related

How to use np.log or np.exp in GEKKO intermediate

I am using gekko to solve a system of equations. As an intermediate step I am using an intermediate that plugs the MV temperature into the following function:
def riedelVP(T, const):
'''Returns Vapor Pressure
INPUTS
:T - Temperature (K)
:const - A, B, C, D, E constants for eqn
OUTPUTS
:Y - Pressure in Pascals'''
# unpack constants
a, b, c, d, e = const
# plug into equation
Y = np.exp(a+b/T+c*np.log(T) + d*T**e)
return Y
When I do this, I get the following Error:
I have tried using T.value and T.value[0] as arguments into the function instead of T.
TypeError: loop of ufunc does not support argument 0 of type GKVariable which has no callable log method
How can I use a function with exp and log in a gekko intermediate
The problem in this case is that both the np.exp() function and the np.log function require an argument that is a float, while gekko variables are their own type. If you were to use gekko's methods for exponentiation and taking the logarithm in the function, it will work. To do so, use the m.exp or m.log methods. In this example, I already had a gekko model created using m = GEKKO(), then I could create the function:
def riedelVP(T, const):
'''Returns Vapor Pressure
INPUTS
:T - Temperature (K)
:const - A, B, C, D, E constants for eqn
OUTPUTS
:Y - Pressure in Pascals'''
# unpack constants
a, b, c, d, e = const
# plug into equation
Y = m.exp(a+b/T+c*m.log(T) + d*T**e)
return Y
Use gekko's analogous methods when type errors in functions occur.

Finding all nodes connected to a vertex in Prolog

I am curious about pathfinding algorithms, so I took a look at Dijkstra's. I'm using this video as a guide (and it's what I'm basing my graph on). Here is the graph I am working from:
I now want to be able to find all connections of a given vertex. I think that I should use findall for this, which I tried to use in the all_connections goal below. However, with main, my output is [b,b,b,b]. Why is that happening? That makes no sense. If you understand what I am doing wrong please let me know.
connection(s, c, 3).
connection(c, l, 2).
connection(l, i, 4).
connection(l, j, 4).
connection(i, j, 6).
connection(i, k, 4).
connection(j, k, 4).
connection(k, e, 5).
connection(e, g, 2).
connection(g, h, 2).
connection(h, f, 3).
connection(f, d, 5).
connection(d, a, 4).
connection(b, d, 4).
connection(b, a, 3).
connection(b, s, 2).
connection(b, h, 1).
connection(a, s, 7).
are_connected(A, B, Score) :-
connection(A, B, Score);
connection(B, A, Score).
all_connections(A, Z) :-
findall(A, are_connected(A, _, _), Z).
main :-
all_connections(b, X),
write(X).
Congratulations on solving your problem. If you post the solution as an answer, we can upvote it.
This is a comment on something else: Since you are a relative beginner, now is the best possible time to learn good coding conventions. Specifically, this:
are_connected(A, B, Score) :-
connection(A, B, Score);
connection(B, A, Score).
is very bad. Prolog's disjunction is a very powerful, and often confusing, tool. When you use it, the use should really stick out. Otherwise it's easy to mistake your code for this:
are_connected(A, B, Score) :-
connection(A, B, Score),
connection(B, A, Score).
The way you have written this, the semicolon is very easy to miss at the end of a line. Rule of thumb: You should never use ; at the end of a line.
Alternatives:
are_connected(A, B, Score) :-
connection(A, B, Score).
are_connected(A, B, Score) :-
connection(B, A, Score).
(This transformation only works since the entire body of your definition is a disjunction.)
are_connected(A, B, Score) :-
( connection(A, B, Score)
; connection(B, A, Score) ).
Or:
are_connected(A, B, Score) :-
(
connection(A, B, Score)
;
connection(B, A, Score)
).
You get the idea. Each of these variants make it clear that what you are doing is very different from using conjunction.
Here is how I solved my problem:
are_connected(A, B, S) :-
connection(A, B, S)
;
connection(B, A, S).
Many thanks to Isabelle for giving me advice on proper conventions.

vector reflexivity under setoid equality using CoRN MathClasses

I have a simple lemma:
Lemma map2_comm: forall A (f:A->A->B) n (a b:t A n),
(forall x y, (f x y) = (f y x)) -> map2 f a b = map2 f b a.
which I was able to prove using standard equality (≡). Now I am need to prove the similar lemma using setoid equality (using CoRN MathClasses). I am new to this library and type classes in general and having difficulty doing so. My first attempt is:
Lemma map2_setoid_comm `{Equiv B} `{Equiv (t B n)} `{Commutative B A}:
forall (a b: t A n),
map2 f a b = map2 f b a.
Proof.
intros.
induction n.
dep_destruct a.
dep_destruct b.
simpl.
(here '=' is 'equiv'). After 'simpl' the goal is "(nil B)=(nil B)" or "[]=[]" using VectorNotations. Normally I would finish it using 'reflexivity' tactics but it gives me:
Tactic failure: The relation equiv is not a declared reflexive relation. Maybe you need to require the Setoid library.
I guess I need somehow to define reflexivity for vector types, but I am not sure how to do that. Please advise.
First of all the lemma definition needs to be adjusted to:
Lemma map2_setoid_comm : forall `{CO:Commutative B A f} `{SB: !Setoid B} ,
forall n:nat, Commutative (map2 f (n:=n)).
To be able to use reflexivity:
Definition vec_equiv `{Equiv A} {n}: relation (vector A n) := Vforall2 (n:=n) equiv.
Instance vec_Equiv `{Equiv A} {n}: Equiv (vector A n) := vec_equiv.

What makes Crystal (or SQL Server 2012) shorten strings from a database and how to prevent it?

What might cause the following and how can I prevent it?
A command object in the Crystal 2011 “database expert” was something like
Select A, B, C, D, E, F, G, H, I, J from ……
As I was fiddling with format and parameters, Crystal started chopping off A after seventeen characters. The truncation was visible early on, in the “browse data” function of field explorer.
After about a half-hour of trying to figure out why, I gave up and added a needed data item:
Select A, B, C, D, E, F, XXX, G, H, I, J from ……
A went back to normal but B started getting truncated.
So I added a fake item at the end
Select A, B, C, D, E, F, X, G, H, I, J, 'Nil' as Nil from ……
and B went back to normal !

REGEXP_REPLACE - remove commas from string ONLY if enclosed in ()'s

I find an example at oracle forum site :
Input string : a, b, c (x, y, z), a, (xx, yy, zz), x,
WITH t AS (SELECT 'a, b, c (x, y, z), a, (xx, yy, zz), x,' col1
FROM dual)
SELECT t.col1
, REGEXP_REPLACE(t.col1, '(\(.*?\))|,', '\1') new_col
FROM t
Output : a b c (x, y, z) a (xx, yy, zz) x
But i want to make opposite of that. Just remove this character , from inside () and remain outside.
Output : a, b, c (x y z), a, (xx yy zz), x,
This will work for a constant length of arguments with in the brackets.
REGEXP_REPLACE(t.col1, '(\(.*?),(.*?),(.*?\))', '\1\2\3') new_col
update inspired by #Kobi's comment:
this regular expression removes the 1st, optional 2nd and optional 3rd , between ()
it can be extended up to 9 (I've a book stating \1 ... \500 should be possible but only \1 ... \9 worked)
REGEXP_REPLACE(t.col1, '\(([^,]*),([^,]*),?([^,]*),?([^,]*)\)', '(\1\2\3\4)') new_col
A little modified version of the regular expression you used:
REGEXP_REPLACE(column_name, '((\)|^).*?(\(|$))|,', '\1')
Not sure if REGEXP_REPLACE supports negative look aheads and look behinds, but if it does this would work: ,(?<!\)[^\(]*)(?![^\)]*\()
I tested with C#:
string s = "a, b, c (x, y, z), a, (xx, yy, zz), x,";
Console.WriteLine(Regex.Replace(s, #",(?<!\)[^\(]*)(?![^\)]*\()", ""));