pattern matching – Multiplying two expressions with a specific function, effectively

To paraphrase, the problem I am trying to solve is as follows. I am given two sums "evaluated by matrix"

expr1 = Sum(c(i) M(i), {i, range1})
expr2 = Sum(d(j) M(j), {j, range2})

where cs and ds are coefficients and Ms are unspecified (symbolic) matrices. I would like to multiply these two sums, with the multiplication of two of these matrices understood by me, ie specified by a function, let's call it "f". I'm trying to do this effectively. I do not know in advance which matrices will appear, only that they have the head M.

Defining an explicitly linear matrix multiplication works, but seems to be quite ineffective, at least the way I managed to find (my coefficients are other generic expressions).

Using the collection and matching of models instead, I managed to find the following

desiredfunction(a_, b_) := 
  Module({c = Collect(a, M(_)), d = Collect(b, M(_))},
   c((0)) = List; d((0)) = List;
   Outer(#1((1 ;; -2))*#2((1 ;; -2))*f(#1((-1)), #2((-1))) &, c, d)//Flatten//Tr)

that is, I explicitly transform the sums into lists of terms, and generate the external product of the two lists, multiplying the coefficients and combining the matrices using "f", and finally adding everything together.

It does what I want, but I can't shake the feeling that this is some kind of elementary operation (combine two expressions written in the form coefficients * objects with a rule for combining objects and coefficients) that there must be a better way to do this, perhaps via built-in functions. Am I neglecting something obvious here?


To copy and paste in Mathematics:

expr1 = Sum(c(i) M(i), {i, 1, 3});
expr2 = Sum(d(i) M(i), {i, 2, 6});

desiredfunction(a_, b_) := 
 Module({c = Collect(a, M(_)), d = Collect(b, M(_))},
  c((0)) = List;
  d((0)) = List;
  Outer(#1((1 ;; -2))*#2((1 ;; -2))*f(#1((-1)), #2((-1))) &, c, d) // 
    Flatten // Tr)

desiredfunction(expr1, expr2)

Microsoft Excel – matching all dates highlighted in one column to those in another column

My ultimate goal is to highlight all of the dates highlighted in column P of column M. I was wondering if there was a formula so that I could choose all the values ​​highlighted only in column P and highlight the same values ​​in column M.

So I have a bunch of highlighted dates in one column, see column P. I didn't find a way to copy the highlighted dates in column M, so I had to have them copy manually, which led to the formation of column N, as I was hoping that there would be a formula to highlight all of the same values ​​in column N and column M. I could only still not find the appropriate formula to do so.

As there are several documents, it would take an extremely long time to do it by hand. Thanks to the advance picture of my document

pattern matching – DeleteCases with a case as a float?

Could the DeleteCases have matching problems when the list is floats (machine precision numbers)? For example. in this code, it may not match correctly because float == float is not a good operation:

ClearAll(a);
a = RandomReal({0, 1}, 5)
DeleteCases(a, Max(a))

How would you handle these types of situations? What is the robust method?

pattern matching – Take some terms from a polynomial

You can use CoefficientList and select the necessary elements in the matrix:

ser = 
  1 - x/2 - x^2/8 - x^3/16 + 
   y/2 + (3 x y)/4 + (23 x^2 y)/16 + (27 x^3 y)/32 - 
   y^2/8 - (31 x y^2)/16 - (127 x^2 y^2)/64 - (351 x^3 y^2)/128 + 
   y^3/16 + (35 x y^3)/32 + (407 x^2 y^3)/128 + (1915 x^3 y^3)/256;

PolynomialQ(ser, x)
(* True *)

coef = CoefficientList(ser, {x, y})
(* {{1, 1/2, -(1/8), 1/16}, {-(1/2), 3/4, -(31/16), 35/
  32}, {-(1/8), 23/16, -(127/64), 407/128}, {-(1/16), 27/
  32, -(351/128), 1915/256}} *)

List of necessary coefficients:

selectedCoef = Reverse@LowerTriangularize(Reverse@coef, 1)
(* {{1, 1/2, -(1/8), 1/16}, {-(1/2), 3/4, -(31/16), 35/
  32}, {-(1/8), 23/16, -(127/64), 0}, {-(1/16), 27/32, 0, 0}} *)

You can now build a polynomial from these coefficients:

Expand@Fold(FromDigits(Reverse(#1), #2) &, selectedCoef, {x, y})
(* 1 - x/2 - x^2/8 - x^3/16 + y/2 + (3 x y)/4 + (
 23 x^2 y)/16 + (27 x^3 y)/32 - y^2/8 - (31 x y^2)/16 - (
 127 x^2 y^2)/64 + y^3/16 + (35 x y^3)/32 *)

Show the row selected for matching in all columns of a drop-down list in Google Sheets

I would like to create a search from a dropdown list with all unique sheet data which finds a match in any column and returns the selected line items.

Let's say that each row represents a single device with several components described in each column with a unique ID for all. How can I find an ID and get all the column IDs associated with this row selection?

I can do this for a single column or row with VLOOKUP or INDEX, MATCH but maybe there is a way to make it work without a single parent key …

Thanks for the help

Example goal

python – Error passing numpy.core._exceptions.UFuncTypeError parameters: ufunc & # 39; subtract & # 39; did not contain matching loop signature types (dtype (& # 39; <U21 & # 39;)

Basically I have the following code:

import numpy as np

def localize(aux1, aux2, aux3, aux4, aux5, aux6):

    search = np.array(((aux1,aux2,aux3,aux4,aux5,aux6)))

    B1A = np.array(((-46,-78,-72,-70,-81,-59)))     #B1A
    B1B = np.array(((-100,-82,-85,-100,-76,-55)))   #B1B
    B1C = np.array(((-100,-100,-100,-78,-100,-58))) #B1C
    B2A = np.array(((-100,-88,-100,-100,-100,-60)))  #B2A
    B2B = np.array(((-100,-78,-79,-80,-80,-59)))     #B2B

    candidatos = (B1A, B1B, B1C, B2A, B2B)
    margem_erroP = 10.0
    margem_erroN = -10.0

    distancias = candidatos(::) - search

    avaliar_dist = np.where(np.absolute(distancias) < margem_erroP, True, False) 
    avaliar_distN = np.where(np.absolute(distancias) < margem_erroN, True, False)

    vetores_aprovados = avaliar_dist.all(axis=2)
    vetores_aprovados += avaliar_distN.all(axis=2)

    posicao_aprovados = np.array(np.where(vetores_aprovados== True)(0))

    print("---- Resultado ----")
    print()
    print("Busca: {}".format(search))
    print("Resultado: ")
    for x in posicao_aprovados:
        print(candidatos(x))

        here = candidatos(x)(-1)
        print("Aquii")
        print(here)

        if posicao_aprovados(0) == 0:
            print("Local: B1A")
            local = "B1A"
        elif posicao_aprovados(0) == 1:
            print("Local: B1B")
            local = "B1B"
        elif posicao_aprovados(0) == 2:
            print("Local: B1C")
            local = "B1C"
        elif posicao_aprovados(0) == 3:
            print("Local: B2A")
            local = "B2A"
        elif posicao_aprovados(0) == 4:
            print("Local: B2B")
            local = "B2B"
        else:
            local = "não encontrado"

    x = {
        "search" : search.tolist(),
        "locale" : local,
        "result" : here.tolist()
    }
    json.dumps(x)
    return x

So far so good, it works as it should!

The problem is when I try to execute this function from another location. For example:

I have a variable find which contains the following string: '-100,-67,-63,-49,-53,-48'

Since I have to pass 6 values ​​and in this case I only pass 1 (a string), I separate my string into whole numbers using the following command:
valores = find.split(",")

Now my list becomes this: ('-100', '-67', '-63', '-49', '-53', '-48')

To make my function work, I did it as follows: aux = localize.localize(valores(0),valores(1),valores(2),valores(3),valores(4),valores(5))

In other words, what I'm doing is basically: localize.localize(-100 -67 -63 -49 -53 -48)

However, this does not work by returning the error:
distancias = candidatos(::) - search numpy.core._exceptions.UFuncTypeError: ufunc 'subtract' did not contain a loop with signature matching types (dtype(' dtype('

IMPORTANT TO MENTION THAT
If I call my function passing the values ​​directly like this: aux = localize.localize(-100,-70,-68,-55,-53,-55)
It works perfectly but going in that other direction, which I need, won't work at all.

I came to think that it didn't work because there was no comma separating each integer value, so I did it as follows: localize.localize(valores(0)+',',valores(1)+',',valores(2)+',',valores(3)+',',valores(4)+',',valores(5))

What came to pass:

localize.localize(-100,-67,-63,-49,-53,-48) which didn't work either.

I would like help to understand how I can pass values ​​functionally and across variables as I have described it. Thanks in advance for any help

If that helps, I leave the function I am trying to perform underneath. It is a POST of an API that comes with certain parameters (coordinates) and the algorithm will help me tell where the coordinates are closest. It is only after receiving the data and checking the location that the data is saved in the bank. I was printing everything to see how the data got there hehe

@app.route('/api/v1/resources/positions/app', methods=('POST'))
def positions_post_app():
    conn = sqlite3.connect('locale.db')
    conn.row_factory = dict_factory
    cur = conn.cursor()
    users = request.get_json()
    for user in users:
        user_id = user('user_id')
        find = user('search')
        date = user('date')

#        print("valor que chega!")
#        print(find)
#        valores = find.split(",")
#        print("lista de inteiros")
#        print(valores)
#        print("Tabela atualizada:")
#        print(valores(0)+',',valores(1)+',',valores(2)+',',valores(3)+',',valores(4)+',',valores(5))

#        aux = localize.localize(-100,-70,-68,-55,-53,-55) #FUNÇÃO FUNCIONANDO
         aux = localize.localize(valores(0),valores(1),valores(2),valores(3),valores(4),valores(5))

        locale = aux('locale')
        result = aux('result')
        print("insert into positions values(NULL, '{}','{}', {}, {}, '{}')".format(user_id, find, result, locale, date)) #PRINT PARA VER COMO FICARIA O SQL 

#        cur.execute("insert into positions values(NULL, '{}','{}', {}, {}, '{}')".format(user_id, search, result, locale, date))
#        conn.commit()
    return {'Status' : 'Success'}

SQL Server – Quick insertion from the temporary table to the main table – advice needed, matching index order?

I'm rewriting a C # console app from a single insert to perform bulk insertions

based on the tips here, I need to insert loose in a transfer table (with the seed identity id)
Then I load in the temporary tables, do some processing, then insert into the main table

It's for real time 24/7 so it has to be as fast and efficient as possible

1) What is the fastest way to insert data in bulk from the C # console application to the middle table (every 1 min, approximately 50,000 to 150,000 records) – I plan to 39; use SqlBulkCopy

2) Does having an identifier with an identity seed on the middle table slow things down? should i use a bunch?

3) My main question and the highest risk area is inserting into the main occupied table, so this should be as quick as possible to reduce locking: when inserting loose into the table main, do I need to pre-order the data so that it matches the main cluster index (sound on 3 columns: sensorId, DateTime, pkId) or will I just sort twice? this table is extremely busy.
Any other advice in this area is appreciated.

this whole block insertion process is just a stored procedure, and I thought I would call it every 1 min from the sql agent to make sure that It works (I'm not sure if this is the best solution)

sql server 2017 ent.

ms access – Line search without matching the second field for the constants given in the first field

Consider an example of a table with two string fields FIRST_NAME and LAST_NAME.

For a given Lastname == Smith, I find waiting a row with another data Lastname == Johnson and first name identical.

How to find lines for which this is not the case, that is to say Lastname == Smith, Firstname == Julia exists but Lastname == Johnson, Firstname == Julia does not?.

Examples of data:

FIRST_NAME, LAST_NAME
Jane, Smith
John, Smith
Blake, Smith
Jane, Johnson
Blake, Johnson

Request so far:
SELECT FIRST_NAME FROM (SELECT DISTINCT LAST_NAME, COUNT(*) AS c, FIRST_NAME FROM Table1 GROUP BY FIRST_NAME) WHERE c = 1

What I would like to get:

John, Smith

Google sheets – How to find matching cells online based on search?

I have 5 rows with 10 columns. Below this 5×10 grid, I fill a cell with a value listed in column 1 of the grid. "ABC" for example.

If "ABC" is row 3, column 1, I want them to get the values ​​from row 3, columns 4, 5, 6. These three values ​​will go into the cells just above or below the cell "ABC" which is below the grid.

The value where is "ABC" will change because I get information from different lines, but will always correspond to a value in column 1 of the 5×10 grid. do you have any ideas for doing that?

pattern matching – How to make a Flat function return x when it is evaluated as f[x]?

With SetAttributes[f, Flat], f[a_] can be paired with f any number of arguments. How can i do that call it with exactly one argument f[x] Return x?

I'm trying to have an operation like NonCommutativeMultiply but without the "possible problems" that it has. It is important to me that if the result of some simplification is a "product" of a term, it will no longer be treated as such.

I especially want to avoid endless loops like

f[a_] := a
f[a__] /; AnyTrue[{a}, FreeQ[_Symbol]] := "free"
f[a, a]

$ IterationLimit :: itlim: The iteration limit of 4096 has been exceeded. >>