Smart way of simplifying logical circuits by hand? - logical-operators

Let's say I have the following logical circuit:
How can I create a simplified version (assuming that one exists) without laboriously creating a truth table for it? I was thinking of perhaps writing the boolean expression as a sum of minterms to then create a Karnaugh map, but the expression that I get is unwieldy. Is there a better way?

Related

How do I declare an array in R?

I'm trying to declare an array in R, something logically equivalent to the following Java code:
Object[][] array = new Object[6][32]
After I declare this array, I plan to loop over the indices and assign values to them.
I am not familiar with what you are planning on doing in R, but loops are generally not recommended. I would say this is especially true when you don't know the length of the output.
You might want to find a "vectorized" solution first and if not, then using something in the apply family might also be helpful
Disclaimer: I am certain there is more nuance to this discussion based on what I have read, so I don't want to claim to be an expert on this subject.

Perform operation on subset of vector in rust?

I'm very new to Rust, and I come from C++ land. I'm trying to use the experimental Vec::partition_at_index function. I'm trying to call this function on a certain range of indices of my vector, but have it still modify the original vector (I'm implementing a version of quicksort). Is there a way this can be done?
I also noticed Iterator::partition_in_place. Is this more what I should going for? Can the iterator version be used to operate on a subset of values?
If there are C++ folks hanging out here, I'm looking for the behavior of std::partition, which can operate on an iterator range.

What is the R equivalent of numpy "stride" indexing?

In numpy if you have an array x you can access it's elements with a 'stride' (i.e. skipping some inbetween) like so: x[::2]. How can you do this in R with a vector? I've searched all over the internet and couldn't find an answer to something so simple, kind of surprising.
EDIT:
I just realized that you could use seq(), but is there no built-in method for doing this?
Ya so it turns out you just need to use
v[seq(to=length(v),by=stride)], just another quirk of R.
Though as #Igor F. mentioned they don't bother making it easier since array order is less important to statisticians. I imagine people are more likely to do something like sample(v,as.integer(length(v)/stride)) without being so verbose of course.
There is none, to my knowledge, but a hard-core R user (which I am not) would probably tell you that you are having a wrong approach. R is made for statistics, by statisticians. In their worldview, the order of the entries in an array or frame is irrelevant (or random), so there is no point in accessing them in a particular order.

In R, how can I read in complex(as in complex number) data using read.table

I am fairly new to R. I have a datafile which has a matrix of complex numbers, each of the form 123+123i, when I try to read in the data in R, using read.table(), it returns strings, which is not what I want. Is there some way to read in a file of complex numbers?
One possible thing that I could do, since the program that generates the matrix is available to me, I can modify it to generate two real numbers instead of a single complex number, and after reading into R, I can make them into a single complex number, now would this be the canonical way to doing what I want?
See ?read.table, in particular you want to use the colClasses="complex" argument.

Find HEX patterns and number of occurrences

I'd like to find patterns and sort them by number of occurrences on an HEX file I have.
I am not looking for some specific pattern, just to make some statistics of the occurrences happening there and sort them.
DB0DDAEEDAF7DAF5DB1FDB1DDB20DB1BDAFCDAFBDB1FDB18DB23DB06DB21DB15DB25DB1DDB2EDB36DB43DB59DB32DB28DB2ADB46DB6FDB32DB44DB40DB50DB87DBB0DBA1DBABDBA0DB9ADBA6DBACDBA0DB96DB95DBB7DBCFDBCBDBD6DB9CDBB5DB9DDB9FDBA3DB88DB89DB93DBA5DB9CDBC1DBC1DBC6DBC3DBC9DBB3DBB8DBB6DBC8DBA8DBB6DBA2DB98DBA9DBB9DBDBDBD5DBD9DBC3DB9BDBA2DB84DB83DB7DDB6BDB58DB4EDB42DB16DB0DDB01DB02DAFCDAE9DAE5DAD9DAE2DAB7DA9BDAA6DA9EDAAADAC9DACADAC4DA92DA90DA84DA89DA93DAA9DA8CDA7FDA62DA53DA6EDA
That's an excerpt of the HEX file, and as an example I'd like to get:
XX occurrences of BDBDBD
XX occurrences of B93D
Is there a way to mine the file to generate that output?
Sure. Use a sliding window to create the counts (The link is for Perl, but it seems general enough to understand the algorithm). Your patterns are named N-grams. You will have to limit the maximal pattern, though.
This is a pretty classic CS problem. The code in general is non-trivial to implement as it will require at least one full parse of the sequence, and depending on your efficiency and memory/processor constraints might require several. See here.
You will need to partition your input string in some way to ensure that you get a good subsequence across it.
If there is a specific problem we might be able to help more, but the general strategy is in the Wikipedia article above.
You can use Regular Expressions to make a pattern to search for.
The regex needed would be very simple. Just use the exact phrase you're searching for. Then there should be a regular expression function in the language you're using (you didn't specify) that can count the number of matches.
Use that to create a simple counter.

Resources