Receive an OSC message from Iannix in PD - osc

Sending data from Iannix arrives to Pure Data in a way that causes routing problems.
[listen 57120<
[netreceive -u -b]
[oscparse]
[list trim]
[route cursor]
[route 1]
The data out of that appears to be a symbol with four numbers in it that is unparseable.
The left output of [route 1] should have given me information about the cursor ID 1.
However, sending it to [unpack f f f f] does not output numbers.

this seems to be a problem with your IanniX project itself.
the symbol right after the cursor-ID (or trigger-ID; or "whatever object"-ID) is to be the group-ID, which can be left empty in IanniX.
Pd's [print] object will happily print this empty symbol as an empty string (so it's hard to distinguish from "no atom").
The simple fix is, to assign a group ID to the cursor.
if this is not possible, you can just split the list right after the 1st element to ignore it:
[oscparse]
|
[list trim]
|
[route cursor]
|
[route 1]
|
[list split 1]
| |
ign. [print]
or just build your patch as if there was a group-ID and ignore it
[oscparse]
|
[list trim]
|
[route cursor trigger]
|
[route 1]
|
[unpack s f f ...]
| | |
ign. x y

Something is weird about how Iannix sends data, but this can be worked around with the following:
[listen 57120<
[netreceive -u -b]
[oscparse]
[list trim]
[unpack s f s f f f f f f]
[pack s f f f f f f f] #(don't attach the second s)
[list trim]
[route cursor trigger]
# (the first element out from the first and second outlets of [route] is now the ID)
The list coming from [oscparse] has as it's third element some kind of empty symbol that causes problems if it ever becomes the first element in the list. Unpacking the list into individual elements and then repacking it without that empty symbol allows the data to be used normally.

Related

Scala: oneSet.diff(otherSet) not working

I have a function that finds new columns to add to a cassandra table:
val inputSet:Set[String] = inputColumns.map
{
cht => cht.stringLabel.toLowerCase()
}.distinct.toSet
logger.debug("\n\ninputSet\n"+inputSet.mkString(", "))
val extantSet:Set[String] = extantColumns.map
{
e => e._1.toLowerCase()
}.toSet
logger.debug("\n\nextantSet\n"+inputSet.mkString(" * "))
inputSet.diff(extantSet)
I want the values that are ONLY in the input set. I will then create columns in Cassandra table.
The return set (i.e., inputSet.diff(extantSet)),however, includes columns that are in both sets.
From my log files:
inputSet
incident, funnel, v_re-evaluate, adj_in-person, accident, v_create,....
extantSet
incident * funnel * v_re-evaluate * adj_in-person * accident *
v_create.....
returned set:
funnel | v_re-evaluate | adj_in-person | v_explain | v_devise | dmepos
|....
Which in the end throws
com.datastax.driver.core.exceptions.InvalidQueryException: Invalid column name adj_in-person because it conflicts with an existing column
What have I done wrong?
Any help would be deeply appreciated?
this is what i have tired. which gives me the output as follows.
object ABC extends App {
val x = List("A","B","c","d","e","a","b").map(_.toLowerCase)
val y = List("a","b","C").map(_.toLowerCase)
println(s"${x diff y} List diff")
println(s"${x.toSet diff y.toSet} Set diff")
}
Output:
List(d, e, a, b) List diff
Set(e, d) Set diff
and i think you are looking for the set difference.
As you can see when we are taking the diff of two list then we are getting duplicates in the answer which are a, b but after the operation .toSet we are getting rid of duplicates so this should work for you too.

Pretty Printing Scala Case Classes Like A Tree

I am looking to build a tool that when an expression is input into it, it would produce a step by step evaluation proof and render it as a tree. I will also do the same thing for type checking tree.
Here are several examples of expressions and their equivalent ASTs:
1 + 1 + 1 = Plus(Plus(Num(1), Num(1)), Num(1))
\x:int.x = Lambda(x,IntTy,Var(x))
if 1 + x == 2 then 90 + 1 else 99 = IfThenElse(Eq(Plus(Num(1),Var(x)),Num(2)),Plus(Num(90),Num(1)),Num(99))
I want to output a nicely formatted step-by-step execution tree. Taking an example 1:
Num(1) | {eval res.} Num(1) | {eval res.}
--------------------------------- --------------------
Plus(Num(1), Num(1)) | {eval res.} Num(1) | {eval res.}
--------------------------------------------------------------
Plus(Plus(Num(1), Num(1)), Num(1)) | {eval res.}
At each recursive step, I want to embed evaluation result into {eval res.}
In the future, I will also want to add capability of the user being able to do small-step evaluation. So, when we start at the bottom, when a button is clicked or something like that, the Plus(Num(1), Num(1)) | {eval res.} appears but not Num(1) | {eval res.} because left hand side recursion did not bottom out yet and it continues.
Here are a few examples of such proof trees:
https://i.imgur.com/8hv5Mwb.png
And type checking derivation: https://i.imgur.com/J3RvoYT.png
I want to print out a tree in a vertical manner like that. Having looked through related questions, I have not found anyone attempting this.

if-statement: how to rewrite in matlab

I'm newby in Matlab. I have took the work code with complex if-statement condition and need to rewrite it. This code should prepare some initial data to solve an optimization task. This if-statement condition looks like:
x=[784.8 959.2 468 572 279 341 139.5 170.5 76.5 93.5 45 55];
a=nchoosek(x,6); % all possible combinations from 6 elements of x
n=length(a);
q=[];
for i=1:n
if( ((a(i,1)==x(1)) & (a(i,2)==x(2))) |
((a(i,1)==x(3)) & (a(i,2)==x(4))) |
((a(i,1)==x(5)) & (a(i,2)==x(6))) |
((a(i,1)==x(7)) & (a(i,2)==x(8))) |
((a(i,2)==x(3)) & (a(i,3)==x(4))) |
((a(i,2)==x(5)) & (a(i,3)==x(6))) |
((a(i,2)==x(7)) & (a(i,3)==x(8))) |
((a(i,3)==x(3)) & (a(i,4)==x(4))) |
((a(i,3)==x(5)) & (a(i,4)==x(6))) |
((a(i,3)==x(7)) & (a(i,4)==x(8))) |
((a(i,3)==x(9)) & (a(i,4)==x(10)))|
((a(i,4)==x(5)) & (a(i,5)==x(6))) |
((a(i,4)==x(7)) & (a(i,5)==x(8))) |
((a(i,4)==x(9)) & (a(i,5)==x(10)))|
((a(i,5)==x(5)) & (a(i,6)==x(6))) |
((a(i,5)==x(7)) & (a(i,6)==x(8))) |
((a(i,5)==x(9)) & (a(i,6)==x(10)) |
((a(i,5)==x(11)) & (a(i,6)==x(12)))))
q(i,:)=a(i,:);
end;
end;
q;
R1=a-q;
R1(~any(R1,2),:) = [];
R1(:, ~any(R1)) = [];
Question: Could anyone give an idea how to rewrite if-statement to improve readability of code?
If I understood you correctly, what the convoluted if statement basically says
If "x(1) x(2)" or "x(3) x(4)" or ... "x(11) x(12)" appears anywhere consecutively in row i
Think about it:
((a(i,1)==x(1)) & (a(i,2)==x(2))) | ((a(i,1)==x(3)) & (a(i,2)==x(4))) |
((a(i,1)==x(5)) & (a(i,2)==x(6))) | ((a(i,1)==x(7)) & (a(i,2)==x(8)))
is no different from:
((a(i,1)==x(1)) & (a(i,2)==x(2))) | ((a(i,1)==x(3)) & (a(i,2)==x(4))) |
((a(i,1)==x(5)) & (a(i,2)==x(6))) | ((a(i,1)==x(7)) & (a(i,2)==x(8))) |
((a(i,1)==x(9)) & (a(i,2)==x(10))) | ((a(i,1)==x(11)) & (a(i,2)==x(12)))
since [x(9) x(10)] and [x(11) x(12)] will never appear at a(i, 1:2), so the line I added is always false and does not change the result of the chain of OR's. But if makes the logic much easier to understand. Same logic applies to a(i,2:3), a(i,3:4)..., complete those cases too and then you will get the first statement I made in this answer.
Then, instead of generating a directly from x, you should generate a from the INDEX of x, i.e. [1:12], as such:
a = nchoosek(1:length(x), 6);
Why? You said x consists of real numbers, and using == on real numbers does not guarantee success, and is a very bad practice in general.
Then, your target becomes:
find if sequence `[1 2]` or `[3 4]` or `[5 6]` ... exists in each line of `a`
which is equivalent to:
find if there is any odd number n followed by n+1
This logic can be represented as:
success = any (mod(a(:,1:end-1), 2) & diff(a,1,2)==1, 2)
Now success(i) will be true/false for the every a(i) that your statement evaluates to the same value. This method is better than your statement because it is very concise, automatically adapts to different sizes of x and does not need to run in a loop.
And if you want to get the actual combination of x values, just do
x(a(i)); % Get the ith permutation of x
x(a); % Get all permutation of x
x(a(success,:)); % Get all permutation of x that satisfy the requirement.
EDIT:
q = a; % q is basically a copy of a
q(~success,:) = 0; % except the `non-success` rows are zero
x(q) - x(a) % suppose q and a store index, this will give you the substraction.

Emacs, Evil-Mode: Replace only in visual selection/visual block?

By default, :s/[search-term]/[replace-term] works on whole lines rather than on visual selections. For example, if you select between c and e, as such:
a b |c d e| f g
and do :s/ //g, the result is:
abcdefg
rather than
a b cde f g
Similarly, in a visual block selection:
a b |c d e| f g
0 1 |2 3 4| 5 6
:s/ //g yields
abcdefg
0123456
rather than
a b cde f g
0 1 234 5 6
Does anyone have a way to make evil-mode's :s/ work only on the selection (preferably by default, or alternatively with a keyword like vim's \%V)?
(:s/\%V //g does not seem to work in this case; it leads to 0 matches.)
Thanks beforehand.
You can do the replacement in a visual selection by specifying the range. '<,'> works on the first line to the last line of the selection, and `<,`> works on the first character to the last character. So in your first example of
a b |c d e| f g`,
using :`<,`>s/ //g will give you
a b cde f g
Unfortunately, Evil doesn't seem to currently support replacement in a Visual Block, so there's no easy way to do that replacement.
There is now a package evil-visual-replace to accomplish replacement in blocks:
https://github.com/troyp/evil-visual-replace
It would be nice if the underlying logic were integrated with evil, so that pressing : with a visual block just worked, but it's better than nothing.

Simplify Boolean expression with De Morgan's laws

I need to simplify this Boolean expression with De Morgan's laws.
¬c xor (¬b ∨ c)
Could someone help me?
(accidentally made two accounts, so just responding with this one)
Ive found the best way to visualize a logic formula you do not understand is to make a table for it.
In the case of XOR, it represents One variable or another, but not both. So, lets make a table for A XOR B
A | B | Result
T | T | F *1
T | F | T *2
F | T | T *3
F | F | F *4
To generate the smallest possible result from the above table we can first take the most complex result that takes into account each option. Converting each line into a logical statement is fairly easy.
First, throw out anything that results in a False, Then take those that result in true, and convert them into a logical statement separated by 'OR's. In this case, 1 and 4 are false, and 2 and 3 are true. This means we only need to create logical statements for 2 and 3. I think how to do so would be best explained by example
Lets say X, Y, and Z are our variables, and the table gave us the following rows as true:
T | T | F - X & Y & ¬Z
F | T | F - ¬X & Y & ¬Z
F | F | F - ¬X & ¬Y & ¬Z
then to complete, we simply 'OR' them together
(X & Y & ¬Z) V (¬X & Y & ¬Z) V (¬X & ¬Y & ¬Z)
as you can see, where the variable is true, you put the variable directly in, and where it is false, you put a '¬' before the variable. The statement above basically says...
(True when X=T,Y=T,Z=F: False otherwise) OR (True when X=F,Y=T,Z=F: False otherwise) OR (True when X=F,Y=F,Z=F: False otherwise)
So finally bringing it back to our XOR the table rows are...
*2 A & ¬B
*3 ¬A & B
and are combined to be...
(A & ¬B) V (¬A & B)
So, now that you have an explanation of what to do with xor, you can apply this example to your problem, and come up with a logical statement you can use De Morgan's laws on to simplify.
first you have to split up xor into its basic form.
XOR represents A or B where A != B. If you can do that you should have more luck using demorgans on the whole equation