programming – ComplexExpand in Module doesn’t work as it should, when there is function at the left

I’m new with mathematica and I’m having a problem. I hope you can help me.
I made a module to built a system that I can use to find some condition for given polynomial is a Shur polynomial. (Actually using only a sufficient condition)

Here is the code

    ClearAll("Global`*")
    SuffShur(poly_, r_) :=
 Module({polyshur = poly, coeff, induxshur, conjpolyshur, sys2 = {}, 
   app, w, z, t, y,},
  z = I*y;
  Print(polyshur(w, z));
  coeff(z_) = 
   CoefficientList(polyshur(w, z), 
    w);
  Print("the coefficients");
  Print(coeff(z));
  app(z_) = ComplexExpand(Conjugate (coeff(z)));
  Print("the list of coefficient conjugated");
  Print(app(z));
  Print("the calculation");
  Print(Sum(
    ComplexExpand(Conjugate(Indexed(coeff(z), k)))*w^(r - k + 1), {k, 
     1, r + 1}));
  conjpolyshur(w_, z_) = 
   Sum(ComplexExpand(Conjugate(Indexed(coeff(z), k)))*
     w^(r - k + 1), {k, 1, r + 1});
  Print("the not so done calculation")
   Print(conjpolyshur(w, z));
  sys2 = {DeleteCases(
      CoefficientList(
       Simplify(
        ComplexExpand(Abs(conjpolyshur(0, z)))^2 - 
         ComplexExpand(Abs(polyshur(0, z)))^2), y), 0) > 0};
  Print(conjpolyshur(0, z)*polyshur(w, z) - 
    polyshur(0, z)*conjpolyshur(w, z));
  Print(ComplexExpand(
    conjpolyshur(0, z)*polyshur(w, z) - 
     polyshur(0, z)*conjpolyshur(w, z)));
  induxshur(w_, z_) = 
   1/w*Simplify(
     ComplexExpand(
      conjpolyshur(0, z)*polyshur(w, z) - 
       polyshur(0, z)*conjpolyshur(w, z)));
  Print(induxshur(w, z));
  t = r - 1;
  While(
   t > 0,
   polyshur(w_, z_) = Simplify(induxshur(w, z));
   Print(polyshur(w, z));
   coeff(z_) = 
    CoefficientList(polyshur(w, z), 
     w);(*dalla potenza piu bassa alla più alta*)
   conjpolyshur(w_, z_) = 
    Sum(ComplexExpand(Conjugate(Indexed(coeff(z), k)))*
      w^(t - k + 1), {k, 1, t + 1});
   Print(conjpolyshur(w, z))
    AppendTo(sys2, 
     DeleteCases(
       CoefficientList(
        Simplify(
         ComplexExpand(Abs(conjpolyshur(0, z)))^2 - 
          ComplexExpand(Abs(polyshur(0, z)))^2), y), 0) > 0);
   induxshur(w_, z_) = 
    1/w*FullSimplify(
      ComplexExpand((conjpolyshur(0, z)*polyshur(w, z) - 
         polyshur(0, z)*conjpolyshur(w, z)), w));
   t = t - 1);
  {sys2}
  )

Now if you use this with this input

    poly(w_, z_) := -1 + w^2 - 3/2 *z - 1/2 w *z
    re = SuffShur(poly, 2)

These are (partially) the results

-1+w$2384^2-(3 I y$2384)/2-(I w$2384 y$2384)/2

the coefficients

{-1-(3 I y$2384)/2,-((I y$2384)/2),1}

the list of coefficient conjugated

{-1-(3 I y$2384)/2,-((I y$2384)/2),1}

the calculation

1+w$2384^2 (-1+(3 I y$2384)/2)+(I w$2384 y$2384)/2

the not so done calculation

1+w$2384^2 (-1-(3 I y$2384)/2)-(I w$2384 y$2384)/2

As you can see when I use ComplexExpand the things don’t go well, and I don’t know why, in fact if do something like

app(z_)=Conjugate(coeff(z))
Print(ComplexExpand(app(z))

the results are right.

Thanks in advance ^^.

N.B. If you don’t write this as a module, it actually works, but I need it to be a module.
If you need me with the first part of the code I could make the second part work by myself.

Why doesn’t the PIN become part of the encryption key in bitlocker with TPM?

TPM is a fantastic addition to motherboards. But I have read some bitlocker papers and they tell me that if you choose TPM + PIN protection, then the PIN does not become part of the key, it is simply used by the chip as an additional security measure. When I understood this thing, I got stunned, because it doesn’t make sense to me, it would have been much safer and much easier to implement, to use the PIN as part of the key or to encrypt the key saved in the TPM with the hash of the PIN. In fact, since the TPM is only a physical solution, attacks have been made against it and the fact that it is protected by a PIN or not, if the chip is broken, for example, with a good electron microscope, is irrelevant. While with the implementation I said before, which is apparently the most logical (correct me if I’m wrong), there is a protection based on mathematics plus TPM helps for keyloggers and rootkits. I understand that normally the TPM + PIN is used for enemies like thieves etc … where it is more than enough. But as I said before, nothing would change for the end user, it would be easier to implement, and safer, therefore also suitable for other purposes. So why was this choice made?

Are there alternatives to bitlocker that use the method described by me? I have seen that LUKS and veracrypt still have very limited support for the chip, therefore still far from using the PIN at the same time.

like – Mysql, Getting all rows in which field ends in a specific character, and another field exists that is the same but doesn’t end in that character

I need to get all rows which end in a specific character, P for example, but in which a similar key sans the P exists. I have no idea how to approach this one in MySQL.

This is very small example, my actual data is huge with other columns also.

+------------+
|    key     |
+------------+
| value_100  |
| value_100P |
| value_101  |
| value_101  |
| value_102  |
| value_102P |
| value_103P |
| value_104P |
+------------+

The query would output,

+------------+
|    key     |
+------------+
| value_100P |
| value_102P |
+------------+

macos – Can’t figure out why Service doesn’t execute from other Applications

I wrote a short Python script that inserts text into an Excel file. I’m calling this .py file via Run Shell Script from a Service in Automator.

  • When I run the python file through either PyCharm or Terminal, it works.
  • When I add a Get Specified Text before the Run Shell Script in the
    Service and pass some string as an argument, it works.

However, when I try to invoke the service from any other application I get a PermissionError: (Errno 1) Operation not permitted from some built-in python library (zipfile.py)

I don’t understand what is happening!

Error log:

The action “Run Shell Script” encountered an error: “Traceback (most recent call last):
  File "./writer.py", line 26, in <module>
    insert_to_excel(sys.argv(1))
  File "./writer.py", line 19, in insert_to_excel
    book = load_workbook(file_path)
  File "/Users/ben/PycharmProjects/Excel_writer/venv/lib/python3.8/site-packages/openpyxl/reader/excel.py", line 312, in load_workbook
    reader = ExcelReader(filename, read_only, keep_vba,
  File "/Users/ben/PycharmProjects/Excel_writer/venv/lib/python3.8/site-packages/openpyxl/reader/excel.py", line 124, in __init__
    self.archive = _validate_archive(fn)
  File "/Users/ben/PycharmProjects/Excel_writer/venv/lib/python3.8/site-packages/openpyxl/reader/excel.py", line 96, in _validate_archive
    archive = ZipFile(filename, 'r')
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/zipfile.py", line 1251, in __init__
    self.fp = io.open(file, filemode)
PermissionError: (Errno 1) Operation not permitted: '/Users/ben/Desktop/Ben_Test.xlsx'”

shell script:

source /Users/ben/PycharmProjects/Excel_writer/venv/bin/activate && cd /Users/ben/PycharmProjects/Excel_writer
./writer.py "${1}"

Note: Automator and Finder have been added Privacy > Accessibility

8 – Metatag module doesn’t seem to play nice with page_attachments_alter

I have created custom theme in drupal 8. I have installed metatags module in backend and added meta descriptions for articles, page, content but it is not showing any meta tag on front end.

I read that using page_attachments_alter hook may cause the problem. I have used it in my theme as I want to add custom meta tags.

What should I do so I can use metatag module as well as page_attachments_alter? Or is there any other problem?

Note: After removing hook and clearing cache its same problem. I just one suspect of hook, I don’t know the exact reason.

[ Politics ] Open Question : Why doesn’t anyone feel sorry for the cop?

He is only doing what he was taught in police academy…

c++ – Cube doesn’t render as expected when rotated (representing 3D in 2D)

Cube.
enter image description here
When I rotate the object around OZ moves to the left.
enter image description here
Rotation around OX – the cube rises up.
enter image description here
Rotation around the OY-the cube is compressed.
enter image description here
The function I use for rotation:

void rotation(double angleX, double angleY, double angleZ, int x, int y, int z)
{
    angleX = angleX * M_PI / 180;
    angleY = angleY * M_PI / 180;
    angleZ = angleZ * M_PI / 180;

    double cX = cos(angleX);
    double sX = sin(angleX);
    double cY = cos(angleY);
    double sY = sin(angleY);
    double cZ = cos(angleZ);
    double sZ = sin(angleZ);

    double x0 = x;
    double y0 = y * cX + z * sX;
    double z0 = z * cX - y * sX;

    double x1 = x0 * cY - z0 * sY;
    double y1 = y0;
    double z1 = z0 * cY + x0 * sY;

    double x2 = x1 * cZ + y1 * sZ;
    double y2 = y1 * cZ - x1 * sZ;


    SDL_RenderDrawPoint(ren, x2, y2);
}

Full code:

#include <SDL.h>
#include <iostream>
#include    <vector>
struct point
{
    int x, y;
};
using namespace std;

int SCREEN_WIDTH = 640;
int SCREEN_HEIGHT = 480;

SDL_Window* win = NULL;
SDL_Renderer* ren = NULL;

void init() {
    win = SDL_CreateWindow("Cube", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
    ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED);
}

void quit() {
    SDL_DestroyWindow(win);
    win = NULL;
    SDL_DestroyRenderer(ren);
    ren = NULL;
    SDL_Quit;
}

std::vector<point> lines(int centerX, int centerY)
{
    std::vector<point> v;
    //line 1
    int x1 = centerX;
    int y1 = centerY;
    for (int i = 0; i < 100; i++)
    {
        x1 += 1;
        v.push_back(point{ x1, y1 });
        //SDL_RenderDrawPoint(ren, x1, y1);
    }
    //line 2
    int x2 = x1;
    int y2 = y1;
    for (int i = 0; i < 100; i++)
    {
        y2 -= 1;
        v.push_back(point{ x2, y2 });
        //SDL_RenderDrawPoint(ren, x2, y2);
    }
    //line 3
    int x3 = x2;
    int y3 = y2;
    for (int i = 0; i < 100; i++)
    {
        x3 -= 1;
        v.push_back(point{ x3, y3 });
        //SDL_RenderDrawPoint(ren, x3, y3);
    }
    //line 4
    int x4 = x3;
    int y4 = y3;
    for (int i = 0; i < 100; i++)
    {
        y4 += 1;
        v.push_back(point{ x4, y4 });
        //SDL_RenderDrawPoint(ren, x4, y4);
    }
    //line 5
    int x5 = x1;
    int y5 = y1;
    for (int i = 0; i < 50; i++)
    {
        y5 -= 1;
        x5 += 1;
        v.push_back(point{ x5, y5 });
        //SDL_RenderDrawPoint(ren, x5, y5);
    }
    //line 6
    int x6 = x5;
    int y6 = y5;
    for (int i = 0; i < 100; i++)
    {
        y6 -= 1;
        v.push_back(point{ x6, y6 });
        //SDL_RenderDrawPoint(ren, x6, y6);
    }
    //line 7
    int x7 = x2;
    int y7 = y2;
    for (int i = 0; i < 50; i++)
    {
        y7 -= 1;
        x7 += 1;
        v.push_back(point{ x7, y7 });
        //SDL_RenderDrawPoint(ren, x7, y7);
    }
    //line 8
    int x8 = x7;
    int y8 = y7;
    for (int i = 0; i < 100; i++)
    {
        x8 -= 1;
        v.push_back(point{ x8, y8 });
       //SDL_RenderDrawPoint(ren, x8, y8);
    }
    //line 9
    int x9 = x3;
    int y9 = y3;
    for (int i = 0; i < 50; i++)
    {
        y9 -= 1;
        x9 += 1;
        v.push_back(point{ x9, y9 });
        //SDL_RenderDrawPoint(ren, x9, y9);
    }
    //line 10 
    int x10 = centerX;
    int y10 = centerY;
    for (int i = 0; i < 50; i++)
    {
        y10 -= 1;
        x10 += 1;
        v.push_back(point{ x10, y10 });
       // SDL_RenderDrawPoint(ren, x10, y10);
    }
    //line 11 
    int x11 = x10;
    int y11 = y10;
    for (int i = 0; i < 100; i++)
    {
        x11 += 1;
        v.push_back(point{ x11, y11 });
        //SDL_RenderDrawPoint(ren, x11, y11);
    }
    //line 12
    int x12 = x10;
    int y12 = y10;
    for (int i = 0; i < 100; i++)
    {
        y12 -= 1;
        v.push_back(point{ x12, y12 });
        //SDL_RenderDrawPoint(ren, x12, y12);
    }
    return v;
}

void rotation(double angleX, double angleY, double angleZ, int x, int y, int z)
{
    angleX = angleX * M_PI / 180;
    angleY = angleY * M_PI / 180;
    angleZ = angleZ * M_PI / 180;

    double cX = cos(angleX);
    double sX = sin(angleX);
    double cY = cos(angleY);
    double sY = sin(angleY);
    double cZ = cos(angleZ);
    double sZ = sin(angleZ);

    double x0 = x;
    double y0 = y * cX + z * sX;
    double z0 = z * cX - y * sX;

    double x1 = x0 * cY - z0 * sY;
    double y1 = y0;
    double z1 = z0 * cY + x0 * sY;

    double x2 = x1 * cZ + y1 * sZ;
    double y2 = y1 * cZ - x1 * sZ;

    SDL_RenderDrawPoint(ren, x2, y2);
}

int main(int arhc, char** argv) {
    init();
    SDL_SetRenderDrawColor(ren, 0xFF, 0xFF, 0xFF, 0xFF);
    int centerX = SCREEN_WIDTH / 3;
    int centerY = SCREEN_HEIGHT / 2 + 100;
    int angleX = 0;
    int angleY = 0;
    int angleZ = 50;
    auto v = lines(centerX, centerY);
    for (int i = 0; i < 1000; i++)
        rotation(angleX, angleY, angleZ, v(i).x, v(i).y, 100);
    SDL_RenderPresent(ren);
    SDL_Delay(500000);
    quit();
    return 0;
}

Used matrices. However, the result was the same.

finite automata – NFA that ends with 0 and doesn’t have 11 after the first 0

So as the title says i m trying to find this NFA. So far i thought to make an NFA that “guesses” what comes after the first 0 and i got this: enter image description here

After some time trying to get rid of all the extra (7 !) states i put in i got to this beauty: enter image description here

But now i cant figure out how to get rid of the one extra state. Also if you have any tips on how to go to simpler NFA’s instead of what i did (like a thought process for this problem) i would appreciate it a lot. Thank you

ipados – iPad search screen doesn’t respond properly. Its like the screen is frozen

I have a 12.5 inch iPad Pro 2nd Generation running iPadOS 13.5. It developed a problem this week. When I swipe down on the home screen it brings up the search screen shown below.

enter image description here

Normally I would use this screen to search for a certain app and then open it. Now that doesn’t work anymore. I can search ok and it’ll find the app but then its like the screen freezes. It doesn’t recognize me tapping on the screen. So if I want the Kindle reader, for example, I used to be able to just tap the icon. Now it doesn’t sense a tap. To use a different app now I have to page through my apps till I find the app I want and tap it then. Does anyone know what’s wrong?