Mixed or Fixed Effect Model for this data?

Question: I recently asked for some assistance with selecting an optimal model for genetic data, but feel the inclusion of too many details may have resulted in a lack of responses (see: Mixed vs Fixed effects model).  I hope that this simplified example may help to solicit more responses.
Suppose that we wish to evaluate whether treating the leaves of plants with chemical X causes the leaves to grow or shrink.  We have six plants and test 12 doses, so split each into the left side and the right side.

Five leaves on each side of the plant are then painted with a single dose of the chemical: -

plant
region
dose

A
L
0

A
R
1

B
L
2

B
R
3

C
L
4

C
R
5

D
L
6

D
R
7

E
L
8

E
R
9

F
L
10

F
R
11

After one month, the change in leaf size is quantified and a model is fit.
Two questions: -
One)
Which of the following models would you fit on the growth data?

~dose + (1|plant_id) + region
~dose + region

Two)
Do you anticipate that in the mixed model, the inclusion of a random term for plant id (i.e. A,B,C,D,E,F) as a confounder may be problematic given that the two regions of the plant receive different doses?
Thanks for any pointers!
Answer: In this experiment you make repeated measures on each plant - each plant is measured twice, the left side and the right side. Due to this, measurements taken on one plant are likely to be more similar to the other measurement on the same plant, than measures on a different plant. This clustering means that observations are not independent and unless you account for this somehow, you are likely to obtain biased results.
One way to account for this non-independence is by fitting random intercepts for plant, as per your model 1. Another approach is to fit plant ID as a fixed effect
response ~ dose + plant_id + region

However if you have a lot of plants this will result in a lot of extraneous output and also suffers from lower statistical power due to each plant consuming a degree of freedom.
Comment: Thanks, Robert, this makes sense.  Just a couple of follow up questions: does the use of a fixed effect for the plant_id change the interpretation of the results?  Also, is there a general rule about how many n plants are reasonable with a fixed effect for plant_id before using a random effect is considered more appropriate?  How does that change with additional confounders (e.g. plant species, or say `sex` in human subjects)?  Thanks!
Comment: You're welcom. If it's a LMM (not a GLMM) then the interpretation of `dose` and `region` is the same. There are various rules of thumb about how many levels are needed before it's OK  to use random effects. There is some consensus around 6. Fewer than 6 and you should fit fixed effects, 6 or more and you could use random intercepts. If you are unsure, then fit two models. The addition of other fixed effects does not affect this.


Determine the convergence of $ \int_1^\infty (\ln(x+\sin x)-\ln(x))\sqrt{x} \, dx $

Question: I need to determine if the integral $$ \int_1^\infty (\ln(x+\sin x) - \ln(x))\sqrt{x} \, dx $$ is convergent/divergent, and if it's convergent then to check if it's absolutely convergent.
I tried to do integration by parts and to check what will be the limit, but it was too complicated.
Also, we cant use any comparison test, because $ \ln\left(x+\sin x\right)-\ln\left(x\right) $ changes the sign, we cant use Dirichlet's test, because $ \sqrt{x} $ doesn't tend to $ 0 $.
Any idea would be helpful, thanks in advance.
Comment: Very broad hint: consider breaking the domain into chunks of length $\pi$ (maybe starting from $x=\pi$ rather than $x=1$ for simplicity's sake, since that clearly doesn't affect the convergence) and getting estimates on the integral on each interval.
Comment: (followup hint: the fact that $\alpha-\alpha^2/2 \leq \ln(1+\alpha) \leq \alpha$ may come in handy. Note that you can simplify the term in parentheses a bit...)
Comment: It only seems to be conditionally convergent (not absolutely). I don't have a proof of this though.
Answer: Combining the $\ln$ terms, $$ I=\int_1^\infty (\ln(x+\sin x) - \ln(x))\sqrt{x} \, dx $$
$$= \int_1^\infty \ln\left(1+\frac{\sin(x)}{x}\right)\sqrt{x} \, dx $$Note that $\sin(x)/x<1$, since equality is only reached at $x=0$. By Taylor's Theorem, for $|z|<1$ $\ln(1+z) = z + O(z^2)$; then
$$
I = \int _1^{\infty} \frac{\sin(x)}{x}\sqrt{x}\,dx + \int _1^{\infty} O\left(\frac{\sin^2(x)}{x^2}\right)\sqrt{x}\,dx
$$The first integral converges by comparison with the usual Fresnel sine integral and the second integral converges by comparison with $x^{-3/2}$. So $I$ exists, i.e. the integral converges.
That being said, the convergence is only conditional, not absolute. To see this, note we can bound $|\ln(1+\sin(x)/x)|>\sin(x)/(8x)$. Then
$$
\int_{ 1}^{\infty } \ln\left(1+\frac{\sin(x)}{x}\right)\sqrt{x} \, dx
$$
$$
> \int_{ \pi}^{\infty } \left|\frac{\sin(x)}{8x}\right|\sqrt{x} \, dx
$$
$$
=\frac{1}{8}\int_{ \pi}^{\infty } \frac{|\sin(x)|}{\sqrt{x}} \, dx
$$Now break the integration into intervals of length $\pi$ and the result follows.
$$
=\sum_{k=1}^{\infty}\frac{1}{8}\int_{ k\pi}^{(k+1)\pi} \frac{|\sin(x)|}{\sqrt{x}} \, dx
$$
$$
> \sum_{k=1}^{\infty}\frac{1}{8\sqrt{\pi}\sqrt{k}}\int_{ k\pi}^{(k+1)\pi} {|\sin(x)|} \, dx
$$
$$
=\sum_{k=1}^{\infty}\frac{1}{4\sqrt{\pi}\sqrt{k}}=\infty
$$


Is there a mathematical notion of "why"?

Question: Is there a mathematical notion of "why"? That is, are there reasons behind the truth of certain mathematical statements? Personally, my belief is that true mathematical statements just are true. There are no reasons behind them. In fact, the notion of "reasons why a certain mathematical statement is true" does not even make sense to me. But perhaps some mathematician or philosopher has rigorously defined a notion of "why". If so, I would like to see such a text.
Comment: Sounds like an epistemological question.
Comment: I mean, mathematical things are true if we can successfully deduce them from the given axioms.  What else could there be?
Comment: If you are asking for a mathematical proof that there is a reason for the existence of...well, anything...then I think you are out of luck.
Comment: "Tiger got to hunt, bird got to fly; Man got to sit and wonder, 'Why, why, why?' Tiger got to sleep, bird got to land; Man got to tell himself he understand." - Kurt Vonnegut
Comment: there is a thing called a proof. What do you mean by "why"? Do you mean as in a proximate cause (grand underlying reason for the truth of a statement) or the immediate preceding one (if P, then Q, then Y, then Z, then W...)such as in a proof?
Comment: Are you talking about logic?
Comment: What does "why" mean *outside* mathematics?
Answer: One idea comes from Plato's world of forms (see Plato's Republic), that the reason we can reason about things logically is because our cognition dips into this world of forms. For example, we don't really deal with circles in this world, only approximations, but that in the cognitive world of forms our minds can grasp a real circle, the form of the circle and that reasoning about circles is just our minds exploring this world of forms.
The why of mathematical truth is thus: because there exists a cognitive world of forms we can dip into. But then, why does such a world exist?
There are lots of ideas, but none of them are satisfying in that we feel like we have reached a bottom ground fundemental truth that all other truths are built on. Perhaps that bottom ground fundemental truth is just that things are because they are, as proposed.


Cannot expand the folder

Question: Boss wants access to all staff mailboxes (31 users).
I've added full access permissions for each mailbox via powershell:
Add-MailboxPermission -Identity "STAFF" -User" "BOSS" -AccessRights FullAccess

All mailboxes are appearing in bosses outlook. A couple of mailboxes will not expand and give the following error:

Your server administrator has limited the number of items you can open simultaneously. Try closing messages you have opened or removing attachments and images from unsent messages you are composing.

This error still appears even when no other mailboxes are expanded and it's always the same couple of mailboxes that give the error (user mailboxes).
(Outlook 2013 w/ Exchange 2013, Remote Desktop Environment, mailboxes all on same DB).
Comment: See: [Exchange Store Limits](https://technet.microsoft.com/en-us/library/ff477612%28v=exchg.141%29.aspx?f=255&MSPPError=-2147217396), specifically Message under Open Item Limits.
Comment: Does that link also apply to outlook/exchange '13?
Answer: Does he need to have all of the mailboxes open at the same time?
This has huge implications for performance both for the Exchange server and the client, particularly as you are using RDP, and it isn't something I would recommend.
Furthermore, depending on your jurisdiction, your boss could be breaking the law. Being the boss, owner or whatever doesn't make it ok to look at people's mailboxes without cause in a lot of locations.
When I have had to do this in the past, against my recommendation I might add, I have not tried to have all mailboxes open at the same time. The manager is granted the permissions, and auto-mapping is disabled when doing so, therefore stopping all mailboxes from opening within Outlook. The manager can then look when required, but doesn't have the performance impact of having them all open.
Although when word gets round that he has access to everything, it will not go down well and could cause some resentment in the staff. Therefore having the mailboxes open on demand ensures that they aren't all listed if someone catches a glimpse by accident.
Simon.
Comment: It's against my recommendation also!! The staff are aware that he has access to their emails :-/ How would he access the mailboxes if auto mapping is disabled?
Comment: Have removed automapping from the affected mailboxes, re-added permissions (with automapping disabled) and manually added the mailboxes to open via "Open these additional mailboxes" option in account settings. Issue appears to be fixed!
Comment: Issue is back :-/
Comment: Doesn't surprise me - you have probably hit the throttled limits by having too many mailboxes open.
Comment: So take a look at the throttling policy then? I was thinking I'd need to, darn.
Comment: You will need to create a new throttling policy just for that one user, then apply it to the mailbox. It will not take effect immediately.
Comment: How long does it take? Is it linked to a service that can be restarted or is it closer to some form of replication?
Comment: It will be subject to the usual caching of Exchange, so a couple of hours. The only way to speed it up is to restart the information store service, which will kick everyone out of Exchange.

Cannot expand the folder


Why DSCP tag does not work on TCP in Windows 10?

Question: I tried to tag all packets from a certain program with Group Policy - QOS. But only UDP packets were tagged and all TCP still has tag value of 0.

Is this caused by Windows 10 or DSCP just does not work on TCP ?
Answer: TCP should use the same TOS for datagrams containing only TCP
control information as it does for datagrams which contain user
data. Windows does exacly that, so triple check that you are dissecting payload when checking.
Although it might seem intuitively correct to always
request that the network minimize delay for segments containing
acknowledgements but no data, doing so could corrupt TCP's round
trip time estimates.
Also, check the source of your packets. Windows is usually very strict about DSCP tags. There is an API, which can set DSCP tags from within an application. However, this is only possible if you tell Windows that this access is permitted.
The following REG file enables the API:
<code>Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Tcpip\Parameters]
"DisableUserTOSSetting"=dword:00000000

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Tcpip\QoS]
"Do not use NLA"="1"
</code>
Without this, every packet created "manually" (using WinSock) is reset to DCSP 0. If you want to have a non-zero value set, check your application, too.
Comment: Thanks for answering. The program does not support setting DSCP value from within, so using QoS is the only option. I checked with Microsoft Network Monitor 3.4, all UDP was tagged and all TCP has zero value. Are you sure those registry works on Win10 ?
Comment: Check the type of the packet(s) and if you are using a supported flag (like 46).


How to address an image which is in system resource in android

Question: I am writing a media player in which I am using Image buttons and Images are from system resource. Now in java file, how should it be addressed?
here is the code:
case R.id.ib2:
    if (isPlaying) {
         pause();
         //the red line is under R.drawable.ic_media_pause
         playPause.setImageResource(R.drawable.ic_media_pause);

Comment: I need to provide an address for setImageResource()
Comment: Or finding system resource images and put them in drawable folder(how?)
Answer: You need to use android's resource file, like so:
playPause.setImageResource(android.R.drawable.ic_media_pause);

Or You can add it to the imports if you aren't using any of your own resources:
import android.R;

Comment: ic_media_stop came about in 4.0 this site may be of use to you: http://androiddrawables.com/
Comment: Yes, not *your* `R`, but Android's. @Civiato
Comment: Is there any idea about how to find the original file?
Comment: for example, there isn't a ic_media_stop image. and have no idea how to arrange dimensions if i want to create it.
Comment: if i have the size of others, then i can easily make it.


Does instanceof return true if instance of a parent?

Question: I have a class Child that extends Parent.
Parent child = new Child();

if (child instanceof Parent){
    // Do something
}

Does this return true or false, and why?
Comment: By just compiling and executing your code you would have got the answer, at least to the first question.
Comment: Of course. I think it was a rhetorical question as I was trying to make sense of type hierarchy in Java long time ago. I also wanted to invoke a good answer that could help the community.While it's obvious that Child is a subtype of Parent, it was questionable for me why it would also be an instance of it. To me it was only logical this to return true when it was the exact type. I would also expect a more explicit operator such as subtypeOf in that time
Answer: Yes, it would. And why should it not?
Because child is in fact an instance of Parent. If, you want to perform an operation only for a child you should check
if (child instanceof Child){
}

However you should remember the following statement from Effective C++, by Scott Meyers :

"Anytime you find yourself writing
code of the form "if the object is of
type T1, then do something, but if
it's of type T2, then do something
else," slap yourself.

which I think applies in this case too. If you want to doSomething based on what type of class the referenced object belongs to, the following code structure should help you with it.
NOTE: I have not compiled it.
class Parent {
    public void doSomething() {
        System.out.println("I am the Parent, and I do as I like");
    }
}

class ChildA extends Parent {
    public void doSomething() {
        System.out.println("I am a child named A, but I have my own ways, different from Parent");
    }
}

class ChildB extends Parent {
    public void doSomething() {
        System.out.println("I am a child named B, but I have my own ways, different from my Parent and my siblings");
    }
}

public class Polymorphism101 {

    public static void main(String[] args) {

        Parent p = new Parent();
        p.doSomething();

        p = new ChildA();
        p.doSomething();

        p = new ChildB();
        p.doSomething();

    }

}

EDIT: A better example
You could be developing a drawing application. An application that draws shapes of any kind. In that case, you should have an abstract type Shape.
For purpose(s) like; drawing all shapes; list all shapes; find a shape or delete a shape, you need to have a list of Shapes. Since the list is of a parent type, it can store any shapes.
The Shape interface/abstract class/virtual class should have an abstract/pure virtual function Draw(). So, in your DrawToDeviceLoop, you just call Draw() for each shape, you never need to check what shape it is.
The Shape interface can have an abstract implementation AbstractShape, which can have shape name or id as data members and GetName, Cleanup and other functions with functionality common to all shapes.
Remember an abstract type cannot be instantiated, so Shape itself cannot be instantiated, as it cannot be drawn either.
EDIT 2: Polymorphism and Exception Handling - user1955934 asked "What about checking for exception class" For exception handling the best practices with respect to polymorphism are:

Prefer (to throw) specific exception - For example throw a NumberFormatException instead of IllegalArgumentException
Catch the most specific exception first - For example, if you catch an IllegalArgumentException first, you will never reach the catch block that should handle the more specific NumberFormatException because it's a subclass of the IllegalArgumentException.

So, its principally the same, if an exception needs to be handled differently, a child/specific class should be defined, and the specific exception should be caught (not checked instanceof)
To know more best practices on exception handling. See 9 Best practices to handle exception in Java and Best practices for exceptions (C#)
EDIT 3: I admit to an exception in this rule
So, I am working with a legacy code (written in C++), which has mostly been written about 15 years ago, where they always check for the child class to perform certain actions. I was asked to add some code with the same logic, and I told my manager (he is a Dev too) I cannot do this, pointing to this answer, and then we discussed and accepted to this exception to the rule. In our case, this parent class has had just 2 children since the year 2000, and we do not see any child being added in the near future, with the core code limited for growth, we decided that with no addition to child classes and current number being just 2, it is more efficient to check for type, especially when that is how the code has been written, since ever.
There aren't many instances of this check too though, the parent implements the complicated functionalities mostly and it exists more for sharing code then specializing/differentiating them.
Comment: I would like an improved answer as well, this would be useful for working with Frame.getComponents() instead of handling each one individually.
Comment: but I determine the object type in runtime and I need to define a parent reference to hold all types of childs. how can I do that in the other way?
Comment: @user479129: You can hold a reference to any of a parent's child(s) in a reference of type parent. That is if there is a `class Parent {}` and `class ChildA extends Parent` and `class ChildB extends Parent` then you can use `Parent p` to refer an object of type `ChildA` or `ChildB`, but I don't get what you mean by other way round.
Comment: I need to control that object p is a type of its child, not the parent. in some cases it can be the parent type so I need to check that it is exactly the type I want. that is what I want. I hope it s clear
Comment: @JasonK. Do you mean a better example?
Comment: what about checking for exception class?
Answer: instanceof will return true if it's a subclass...
instanceof Documentation
Comment: And now, this question is always true. Thank
Answer: ofcourse it returns true because child is an instance of the parent
Comment: Yes, java any return true if child is instance of the parent (or implement).
Answer: Yes. instanceof will be true whenever the reference(left side of the instanceof expression) can be cast to the ReferenceType(the type on the right side of the instanceof expression). This will be true for subclasses in relation to their parent:
Child child = new Child();
Parent parent = (Parent) child; //works!
assert child instanceof Parent; //true

From The Java Language Specification, Java SE 9 Edition:

15.20. Relational Operators
...
RelationalExpression instanceof ReferenceType
15.20.2. Type Comparison Operator instanceof
...
At run time, the result of the instanceof operator is true if the value of the RelationalExpression is not null and the reference could be cast to the ReferenceType without raising a ClassCastException. Otherwise the result is false.


Is this professional pianist respecting the score of Dance of the Fairy Dragée

Question: As one could see from the score of Dance of the Fairy Dragée, tranposed for piano, this is only starting at measure 5th than the staccato begins.

But if we listen to this professional pianist (who plays very nicely), he does not respect this since he starts the staccato at the very beginning, not at the measure 5th.
So, is what he do correct/respecting the score ?
Comment: I would prefer 'faithful to original' over 'respecful'- nothing disrespectful about some variation in an arrangement.
Answer: Well, this is hardly "the score"; it's an arrangement. THE score in this case is the orchestral score of the ballet. The opening notes are played by pizzicato strings, which can never sustain at all; it's about as staccato as you can get. One might say the arrangement hasn't respected the score. But it has marked it leggero, or "lightly"; to distinguish between notes that are short because you're playing "lightly" and those that are short because they're marked staccato might devolve into a quibble. The arrangement clearly wants to highlight the right-hand material in the 5th bar as being in some way "different," as that's where the celeste enters.
Meanwhile, the pianist has perhaps "respected" both the original and the arranged score by knowing the origin of the piece and reflecting the orchestral timbre in his articulation.
As a broader point, regardless of this example: It is not disrespecting a score to add to it. Very few pieces expect you to play only what you see on the page and to take no expressive initiative—all notes equal in volume unless otherwise marked, all notes sustained for their full duration and without decay, unless otherwise marked. Such pieces would be rare experimental works. Instead, throughout performative history, it's been not merely allowed but expected that the performer would "add to" what's on the page. In this case, starting with a "light" touch is quite a reasonable decision, especially since he does in fact differentiate the celeste entrance.
Comment: The interesting point is why the accompaniment also acquires staccato dots when the celeste melody starts!
Comment: @Laurence Yeah, seems like a difficult decision to defend, since those LH eighth are supposed to just compress the same thing it's already been doing for four bars. An uncharitable speculation might be that the arranger didn't think we could do different articulations in the two hands at once...?
Comment: My uncharitable speculation is that the arranger simply didn't give it much thought (and also didn't do adequate use testing).  Also note Lazy's answer: not only is the arrangement given in the question only _an_ arrangement, it's not even the arrangement being played in the video.
Answer: When we consult the original orchestral version, we see that the accompaniment throughout this section is on pizzicato strings.  For some reason the creator of this piano version interprets this as detached 8th notes marked 'leggero' for the first 4 bars, then he changes to staccato dots.  So if anyone's not respecting the composer, it's this arranger!
(Incidentally, the piece isn't 'transposed' for piano, the key remains the same.  It's 'transcribed'.)
Comment: It's also worthwhile to note that the performer is not playing the arrangement given in the question.
Answer: The pianist here is playing the transcription by Mikhail Pletnev, which does feature these staccato dots in the beginning:

The edition you are using seems to be the edition by Stépan Esipoff (this was a pseudonym of Arthur Bransby Burnand) as published by Schott music. You can find these transcriptions on IMSLP under "For Piano (Esipoff)", published by Augener or Schirmer.
Comment: @phoog The YouTube video (uploaded by the pianist himself) literally states "Tchaïkovsky/Pletnev" in the title, so I'm quite confident that this *is* the Pletnev transcription.
Comment: Nice find.  Are you sure that it's this arrangement, though?  It's clear that the arrangement given in the question isn't the one being played in the video, but it doesn't exclude the possibility that there's yet another arrangement.  I didn't see the arrangement being identified in the YouTube metadata.


How to insert field value programmatically after node is created?

Question: Let's say user creates a node of article type.There is a field called my_field which can be added multiple times to that node.If user creates or edits the node leaving my_field blank, a default value something like NA should be created in database and should be visible inside the my_field when user edits node next time.
Tried so far:
Inside page.tpl.php
$query = new EntityFieldQuery();

$query->entityCondition('entity_type', 'node')
      ->entityCondition('bundle', 'article')
      ->propertyCondition('status', 1);

$result = $query->execute();

if (!empty($result['node'])) {
  $nids = array_keys($result['node']);

  foreach ($nids as $nid) {

    $node = node_load($nid);

   if(empty($node->field_my_field))
   {
     $field_language = field_language('node', $node, 'field_my_field');
     $node->field_my_field['LANGUAGE_NONE'][0]['value'] = 'NA';

      field_attach_insert('node', $node);
   }
  }
 }

Note: I don't want to create default value inside field settings as my_field can be added multiple times which can go upto more than 20.
I am using drupal 7.41.
Comment: You really should not be doing this in `page.tpl.php`. This code scans all your nodes on every page load, which is a huge performance loss. You should do this in a custom module implementing [`hook_node_insert()`](https://api.drupal.org/api/drupal/modules%21node%21node.api.php/function/hook_node_insert/7) and [`hook_node_update()`](https://api.drupal.org/api/drupal/modules%21node%21node.api.php/function/hook_node_update/7). Act only after saving or editing a node.
Comment: I tried the same with above hooks,field value didn't go to databse.
Answer: I suppose it is due to your field_attach_insert(). Usually one should save the entire node using node_save().
However it is a lot easier if you install the entity API module and utilize its Entity Metadata Wrappers.
And I'd really recommend creating a custom module. You will need something similar to this:
function mymodule_node_insert($node) {
  if ($node->type == 'article') {
    mymodule_update_empty_value($node);
  }
}

function mymodule_node_update($node) {
  if ($node->type == 'article') {
    mymodule_update_empty_value($node);
  }
}

function mymodule_update_empty_value($node) {
  $wrapper = entity_metadata_wrapper('node', $node);
  // No value?
  if  (empty($wrapper->field_myfield->value())) {
    $wrapper->field_myfield->set('NA');
    $wrapper->save();
  }
}

Comment: how abt if it is for specific bundle say `article`?
Comment: Added the condition in the example, the same applies to `status`.
Comment: showing error                                                                                EntityMetadataWrapperException: Invalid data value given. Be sure it matches the required data type and format. in EntityMetadataWrapper->set() (line 122 of /var/www/drupal3.com/sites/all/modules/entity/includes/entity.wrapper.inc).
Comment: is the field a textfield?
Comment: textarea with rows
Comment: Obtain a value of a known node with `entity_metadata_wrapper('node', $nid)->field_myfield->value();` and see how it is structured (there might be another layer). Also take a look at the bottom of the linked entity metadata wrapper page. There are some dubuggin functions there as well.
The body field (which is similar to what you might need can be set with `$wrapper->body->set(array('value' => "Der zweite Text."));`
Comment: `textfield` and `long text` are not supporting `set` method.How to set values for those types,any clue?
Comment: I find it hard to believe that, but you can either use the field array `$node->field_my_field['LANGUAGE_NONE'][0]['value'] = 'NA';` and `node_save()`. Or take a look here http://drupal.stackexchange.com/questions/64833/fast-saving-single-field-value
Comment: above link is ok if you want to update existing field value,but problem is for newly created node


MPMoviePlayerController Done button unresponsive in Landscape mode

Question: All,
   The Done button in MPMoviePlayerController dismisses the control in portrait mode.
   However, both the Done and Toggle full screen button become unresponsive when i rotate to landscape.
    My app is a very very simple app and just has didRotatefromInterfaceOrientation method where i change the movie frame width and height to landscape and change the origin to match landscapemode.
`- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
    // Update the frame of the view.
    CGRect newFrame = [[UIScreen mainScreen] applicationFrame];
<code>newFrame.origin.x = - (newFrame.size.width / 2);
newFrame.origin.y = - (newFrame.size.height / 2);

[[self view] setBounds:newFrame];
[[self view] setCenter:CGPointMake( [[self view] bounds].size.width / 2, [[self view] bounds].size.height / 2)];
[self view].userInteractionEnabled = YES;

// Update the frame of the movie player.
newFrame = [[UIScreen mainScreen] applicationFrame];
if( fromInterfaceOrientation == UIInterfaceOrientationPortrait || fromInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
    newFrame.size.width = newFrame.size.height;
    newFrame.size.height = [[UIScreen mainScreen] applicationFrame].size.width;
}
newFrame.origin.x = - (newFrame.size.width / 2);
newFrame.origin.y = - (newFrame.size.height / 2);
[[[self moviePlayer] view] setFrame:newFrame];
[[[self moviePlayer] view ] setUserInteractionEnabled:YES ];
</code>
}`
Comment: Why are you changing values on rotate programmatically?
Comment: Cause if i don't then the view shifts off screen.
Answer: Well the problem here was that i was rotating the view and resizing it in `- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation.
You are not required to do that as the movie player automatically does that for you.
Resizing and rotating the frame actually got the button confused and hence did not receive touch events when tapped.


Can functions within a matrix adjust its size?

Question: I've been working my way through a proof, and without going into the full extent of the details it's come down to whether a function G() exists such that the 1 by 3 matrix:
\begin{bmatrix}G\begin{pmatrix}1\\0\\0\end{pmatrix}&G\begin{pmatrix}0\\1\\0\end{pmatrix}&G\begin{pmatrix}0\\0\\1\end{pmatrix}\end{bmatrix}
could become a n by 3 matrix, for any whole number n (for example in the case above I would want to resolve it to a 5 by 3 matrix.
Is this possible? Or is it back to the drawing board?
Comment: what about $G=I_{{5}{3}}* ()$
Answer: That is mostly a question of notation and convention. You can certainly choose to define that in your work, the notation
$$ A = \begin{bmatrix}X & Y & Z\end{bmatrix} $$
where $X$, $Y$ and $Z$ are column matrices of the same height, will mean that $A$ is the $3\times n$ matrix that has those three columns. As a matter of terminology that would mean that you're defining $A$ as a block matrix.
However, it seems unlikely that this is actually what your problem depends on. There's essentially no mathematical content in asking (effectively) "is it possible to form block matrices" -- the answer to that will only tell you how your notation works, but not anything about the underlying mathematical structure that your notation speaks about.
So when you say that your problem "comes down to" whether you can employ that notation or not, it sounds very likely that you have some conceptual confusion or mistake in your work before you reach that point. And you should probably ask another question where you give details of that work and ask whether your approach is legitimate.


Conectar banco externo ao UI Designer no Bonitasoft Community

Question: Estou utilizando a ferramenta Bonitasoft para desenvolver um projeto BPM, possuo um banco de Dados PostgreSQL que através de uma conexão JDBC consegui inserir e alterar registros pelo Bonitasoft, porém não consigo selecionar os dados do banco e exibi-los no meu UI Designer, por ser uma ferramenta ainda não muito utilizada não encontrei muita informação sobre a mesma, se tiverem daqui a pouco algum material, ou alguma ideia de como posso exibir os dados em uma planilha no meu UI Designer, seria muito útil.
Testei o retorno que meu Select me traz e as informações bateram corretamente com o que eu preciso, então adicionei as informações em um arrayList, meu problema agora é exibir as informações desse Array no UI Designer
Comment: Bom, nunca tinha ouvido falar no bonitasoft, mas quem sabe se você postar um pouco do seu código e onde está tentando exibir os registros...
Comment: É que na verdade por ser uma ferramenta BPM a própria ferramenta Bonitasoft se encarrega de gerar os códigos automaticamente por trás.
Comment: Entendo. É complicado então alguém sugerir alguma resposta, só pra quem já utilizou mesmo esta ferramenta. Pois não tem como ter noção onde se aplicaria o código.
Comment: Essa era a ideia @CarlosAndrade caso alguém soubesse mesmo, ou tivesse alguma ideia para seguir
Answer: Após muita pesquisa e auxilio de um usuário com mais experiência e conhecimento da ferramenta, consegui exibir as informações que estão em meu banco de dados externo no meu UI Designer.
Inicialmente tive que configuraram uma variável API REST que apontasse para meu BDM:
../API/bdm/businessData/com.hss.model.TransportadoraPostgreSQL?q=find&p=0&c=100
Onde:

TransportadoraPostgreSQL é o nome do meu BDM.
q=find é a minha query que encontra tudo que esta no BDM.
c=100 é a quantidade máxima de registros do BDM que serão exibidos

Configuração da Variável API REST:

Configuração da Tabela onde será exibido os registros:


Value cannot be null. C#

Question: Im trying to get an int[] array but it's returning an error which is Value cannot be null. I'm still a newbie to c#. Can someone help or give a clue how to solve this? I tried many techniques of passing the value but still no luck.
here's where the array came from
    private void btnTag_Click(object sender, EventArgs e)
    {
        List<int> employee_id_list = new List<int>();
        foreach (Control c in panelEmployee.Controls)
        {
            if (c is CheckBox)
            {
                if (((CheckBox)c).Checked)
                {
                    employee_id_list.Add(Convert.ToInt32(c.Tag));
                }
            }
        }

        var type = Type.GetType("Payroll." + dynamic_form);
        dynamic form = Activator.CreateInstance(type) as Form;
        form.GetEmployeeID(employee_id_list.ToArray());
        this.Close();

    }

here's where i displayed it
    public int[] emp_id;

    public void GetEmployeeID(int[] employee_id)
    {
        emp_id = employee_id;
        //in this code there are no errors and it is showing the array
        MessageBox.Show(string.Join(Environment.NewLine, emp_id));
    }

    private void btnSave_Click(object sender, EventArgs e)
    {
       // but when i trigger this it returns and error Value cannot be null
        MessageBox.Show(string.Join(Environment.NewLine, emp_id));
    }

Comment: Make sure to call GetEmployeeID before calling btnSave_Click
Answer: I think your problem is that you lose the value of the variable emp_id between the GetEmployee call (it assigns value to emp_id from the parameter so it will work always you pass a not null value) and the later call to btnSave_Clickthat is trying to use the previously( and hopefully) assigned value of emp_id
Maybe you are using WebForms , in that case you should assign the emp_id to a Session state or something that won't get deleted on next request.
public int[] emp_id;

public void GetEmployeeID(int[] employee_id)
{
    emp_id = employee_id;
    //in this code there are no errors and it is showing the array
    MessageBox.Show(string.Join(Environment.NewLine, emp_id));
}

private void btnSave_Click(object sender, EventArgs e)
{
   // but when i trigger this it returns and error Value cannot be null
    MessageBox.Show(string.Join(Environment.NewLine, emp_id));
}

Comment: Thanks for the idea and comment. I changed the `public int[]` to `public static int[]`. Thanks bro.

Value cannot be null. C#


interpretation of ranef dotplot - random slopes variable centered at zero? R

Question: I have an generalized mixed effects model such as the following:
library(lme4)
mod1<-glmer(resp~var1+(var1||group1)+(1|group2), family=binomial, data=testdata,
             control=glmerControl(optimizer="bobyqa", optCtrl=list(maxfun=2e6)),nAGQ=0)

     AIC      BIC   logLik deviance df.resid
  1112.4   1140.6   -550.2   1100.4      814

Scaled residuals:
    Min      1Q  Median      3Q     Max
-1.8083 -0.9033 -0.5787  0.9235  1.7280

Random effects:
 Groups   Name        Variance Std.Dev.
 group2   var1        0.0000   0.0000
 group2.1 (Intercept) 0.2059   0.4538
 group1   var1        0.0000   0.0000
 group1.1 (Intercept) 0.1071   0.3272
Number of obs: 820, groups:  group2, 74; group1, 7

Fixed effects:
            Estimate Std. Error z value Pr(>|z|)
(Intercept)  1.08061    0.35577   3.037 0.002387 **
var1        -0.08115    0.02308  -3.516 0.000438 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Correlation of Fixed Effects:
     (Intr)
var1 -0.900

When I look at ranef plot, the var 1 which I modeled as a random slope is centered around 0. I haven't been able to find any similar looking ranef plots, I haven't been able to dwell too deep into mixed effect models as my background is not really mathematical heavy. I am not sure what to think of this plot, what does it mean in terms of var 1?
lattice::dotplot(ranef(mod1,which="group1", condVar=TRUE))

my data is
testdata<-structure(list(group2 = c(27, 27, 27, 27, 27, 27, 27, 27, 27,
27, 27, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 10, 10, 10, 10,
10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 16, 16, 16, 16, 16, 16,
16, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 19, 19,
19, 19, 19, 19, 19, 19, 19, 56, 56, 56, 56, 56, 56, 56, 56, 56,
56, 56, 56, 56, 56, 56, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
65, 65, 65, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 66, 66,
66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 67, 67, 67,
67, 67, 67, 67, 67, 67, 67, 67, 67, 68, 68, 68, 68, 68, 68, 68,
68, 68, 68, 68, 68, 68, 68, 68, 69, 69, 69, 69, 69, 69, 69, 69,
69, 69, 69, 69, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 72, 72, 72, 72, 72,
72, 72, 72, 72, 72, 72, 72, 72, 72, 73, 73, 74, 74, 74, 74, 74,
74, 74, 74, 74, 74, 74, 74, 74, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 64, 64, 64, 64, 64, 64, 64, 64, 64, 63, 63, 63, 63,
63, 63, 63, 63, 63, 63, 63, 63, 63, 62, 62, 62, 62, 62, 62, 62,
62, 62, 62, 62, 62, 62, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61,
61, 61, 61, 61, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 59,
59, 58, 58, 58, 58, 58, 58, 58, 58, 57, 57, 57, 57, 57, 57, 21,
21, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23,
23, 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24,
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26,
26, 26, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9,
9, 9, 9, 9, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 14, 14, 14,
14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15,
52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 53, 53, 53, 53,
53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 54, 54, 54, 54, 54, 54,
54, 54, 54, 54, 54, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55,
55, 55, 55, 55, 51, 51, 51, 51, 51, 51, 51, 51, 51, 50, 50, 50,
50, 50, 50, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 30, 30,
30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 31, 31,
31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 33, 33, 33, 35, 35,
35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 37, 37, 37,
37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 39, 39, 39, 39, 39, 39,
39, 39, 39, 39, 39, 39, 39, 39, 41, 41, 41, 41, 41, 41, 41, 41,
41, 41, 41, 41, 41, 43, 43, 43, 43, 43, 42, 42, 42, 42, 42, 45,
45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 28, 28, 28, 28,
28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29,
29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 47, 47, 47, 47, 47,
47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 32, 32, 32, 32, 32,
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 34, 34, 34, 34,
34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 36,
36, 36, 36, 36, 36, 36, 36, 36, 38, 38, 38, 38, 38, 38, 38, 38,
38, 38, 38, 38, 38, 38, 38, 38, 38, 40, 40, 40, 40, 40, 40, 40,
40, 40, 40, 40, 40, 40, 40, 40, 44, 44, 44, 44, 44, 44, 44, 44,
44, 44, 44, 44, 44, 44, 44, 44, 46, 46, 46, 46, 46, 46, 46, 46,
46, 46, 46, 46, 46, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
49, 49, 49, 49, 49), group1 = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7), resp = c(0, 1, 1, 1, 1,
0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0,
1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1,
0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1,
1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0,
0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1,
0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1,
0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0,
0, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1,
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0,
0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0,
1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0,
0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1,
1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1,
1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0,
0, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0,
0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1,
1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1,
1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1,
0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0,
0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0,
1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1,
0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1,
1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1,
0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1,
1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0,
0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1,
1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0,
0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1,
0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0,
1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1,
0, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1,
0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0,
0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1), var1 = c(18.8679622641132,
18.8679622641132, 21.2132034355964, 20.976176963403, 20.7364413533277,
19.2353840616713, 19.2353840616713, 19.2353840616713, 19.2353840616713,
19.2353840616713, 19.2353840616713, 18.8679622641132, 18.8679622641132,
18.8679622641132, 15.8113883008419, 15.8113883008419, 15.8113883008419,
20.976176963403, 20.976176963403, 20.976176963403, 22.9128784747792,
22.9128784747792, 22.9128784747792, 22.9128784747792, 22.9128784747792,
22.9128784747792, 22.9128784747792, 22.9128784747792, 22.9128784747792,
22.9128784747792, 22.9128784747792, 22.9128784747792, 17.606816861659,
18.1659021245849, 18.1659021245849, 18.1659021245849, 18.1659021245849,
18.1659021245849, 17.0293863659264, 17.0293863659264, 17.0293863659264,
21.095023109729, 21.095023109729, 21.095023109729, 20.2484567313166,
20.2484567313166, 22.9128784747792, 22.9128784747792, 18.4390889145858,
22.9128784747792, 22.9128784747792, 22.9128784747792, 20.976176963403,
20.7364413533277, 20.7364413533277, 20.7364413533277, 20.7364413533277,
20.7364413533277, 18.3030052177231, 17.8885438199983, 17.8885438199983,
14.142135623731, 20.4939015319192, 20.4939015319192, 20.4939015319192,
20.7364413533277, 20.7364413533277, 18.8414436814168, 20.7364413533277,
20.7364413533277, 20.7364413533277, 20.2484567313166, 20.1246117974981,
20.1246117974981, 20, 20, 20, 20, 20.976176963403, 17.606816861659,
19.2353840616713, 19.7484176581315, 20.4939015319192, 20.4939015319192,
20.2484567313166, 20.2484567313166, 20.2484567313166, 13.1909059582729,
16.9705627484771, 10.4880884817015, 11.4891252930761, 11.8743420870379,
11.8743420870379, 11.8743420870379, 11.8743420870379, 9.48683298050514,
11.4017542509914, 11.4017542509914, 11.4017542509914, 12.6491106406735,
11.4017542509914, 11.4017542509914, 16.9115345252878, 9.53939201416946,
12.6491106406735, 11.4891252930761, 11.1803398874989, 14.0356688476182,
14.0356688476182, 14.0356688476182, 14.0356688476182, 14.0356688476182,
14.0356688476182, 14.0356688476182, 14.0356688476182, 14.5258390463339,
10.0995049383621, 12.1243556529821, 15.4272486205415, 11.1803398874989,
10.4403065089106, 9.64365076099295, 9.64365076099295, 11.7473401244707,
11.7473401244707, 11.7473401244707, 13.7840487520902, 10.4880884817015,
10.4880884817015, 11.8743420870379, 11.8743420870379, 11.8743420870379,
11.8743420870379, 11.8743420870379, 11.8743420870379, 11.8743420870379,
11.8743420870379, 11.8743420870379, 11.8743420870379, 11.8743420870379,
11.8743420870379, 11.8743420870379, 11.8743420870379, 11.8743420870379,
14.4913767461894, 14.4913767461894, 14.4913767461894, 14.4913767461894,
14.4913767461894, 14.4913767461894, 14.4913767461894, 14.4913767461894,
14.4913767461894, 14.4913767461894, 16.1245154965971, 12.8840987267251,
8.24621125123532, 8.83176086632785, 14.0712472794703, 17.8044938147649,
17.8044938147649, 17.8044938147649, 17.8044938147649, 17.8044938147649,
17.8044938147649, 17.8044938147649, 17.8044938147649, 17.8044938147649,
11.8321595661992, 9.59166304662544, 14.8660687473185, 13.0384048104053,
11.8743420870379, 13.3790881602597, 13.3790881602597, 13.3790881602597,
13.3790881602597, 15.4272486205415, 12.0415945787923, 12.0415945787923,
13.0384048104053, 13.0384048104053, 13.114877048604, 7.14142842854285,
7.14142842854285, 7.14142842854285, 7.14142842854285, 7.14142842854285,
7.14142842854285, 9.64365076099295, 9.64365076099295, 9.64365076099295,
6.70820393249937, 6.32455532033676, 6.32455532033676, 16.5227116418583,
5.56776436283002, 6.70820393249937, 7.81024967590665, 9.21954445729289,
9.21954445729289, 9.53939201416946, 9.32737905308882, 9.4339811320566,
9.4339811320566, 7.28010988928052, 8.12403840463596, 8.12403840463596,
9.89949493661167, 9.4339811320566, 9.4339811320566, 9.4339811320566,
9.4339811320566, 9.4339811320566, 9.4339811320566, 9.4339811320566,
9.4339811320566, 10.2469507659596, 10, 9.53939201416946, 15.556349186104,
13.7113092008021, 12.4096736459909, 12.9614813968157, 16.1554944214035,
16.1554944214035, 16.1554944214035, 16.1554944214035, 16.1554944214035,
16.1554944214035, 16.1554944214035, 16.1554944214035, 16.1554944214035,
12.6491106406735, 12.6491106406735, 11.6189500386223, 11.6189500386223,
11.6189500386223, 11.6189500386223, 11.6189500386223, 11.6189500386223,
11.6189500386223, 11.6189500386223, 11.6189500386223, 11.6189500386223,
9.69535971483266, 12.6491106406735, 14.4913767461894, 12.1655250605964,
8.94427190999916, 8.94427190999916, 8.94427190999916, 8.94427190999916,
8.94427190999916, 8.36660026534076, 18.7082869338697, 18.7082869338697,
18.7082869338697, 19.8746069143518, 19.8746069143518, 19.8746069143518,
15.1657508881031, 17.1755640373177, 17.1755640373177, 17.1755640373177,
17.1755640373177, 17.1755640373177, 18.1659021245849, 15.1657508881031,
15.1657508881031, 15.1657508881031, 19.8746069143518, 22.4722050542442,
19.8746069143518, 19.8746069143518, 19.8746069143518, 19.8746069143518,
19.8746069143518, 19.8746069143518, 21.9089023002066, 23.8746727726266,
21.9089023002066, 21.9089023002066, 21.9089023002066, 14.4913767461894,
11.6189500386223, 17.464249196573, 17.464249196573, 17.464249196573,
17.464249196573, 23.0217288664427, 23.6643191323985, 5.47722557505166,
18.8414436814168, 23.6643191323985, 18.3030052177231, 18.3030052177231,
18.3030052177231, 16.431676725155, 16.431676725155, 16.431676725155,
16.431676725155, 16.431676725155, 16.431676725155, 16.7332005306815,
16.7332005306815, 16.7332005306815, 18.4390889145858, 18.4390889145858,
13.4164078649987, 25.0998007960223, 13.9642400437689, 21.095023109729,
21.095023109729, 21.095023109729, 21.095023109729, 21.095023109729,
16.1245154965971, 16.1245154965971, 23.6643191323985, 23.6643191323985,
23.6643191323985, 22.8035085019828, 22.8035085019828, 22.8035085019828,
10.2469507659596, 9.32737905308882, 9.32737905308882, 9.38083151964686,
9.89949493661167, 11.9582607431014, 9.79795897113271, 7.14142842854285,
11.9582607431014, 12.4096736459909, 12.4096736459909, 12.4096736459909,
9.79795897113271, 9.32737905308882, 9.32737905308882, 9.32737905308882,
12.2882057274445, 8.94427190999916, 10.4880884817015, 10.4880884817015,
10.4880884817015, 10.4880884817015, 10.4880884817015, 9.9498743710662,
9.9498743710662, 12, 8.94427190999916, 8.66025403784439, 9.74679434480896,
6.92820323027551, 6, 6, 6, 6.70820393249937, 6.70820393249937,
7.87400787401181, 7.87400787401181, 7.93725393319377, 8.42614977317636,
8.24621125123532, 7.48331477354788, 7.74596669241483, 7.74596669241483,
7.74596669241483, 9.4339811320566, 5, 9.8488578017961, 9.8488578017961,
9.8488578017961, 9.8488578017961, 9.8488578017961, 6.85565460040104,
9.53939201416946, 9.53939201416946, 9.53939201416946, 9.59166304662544,
9.38083151964686, 9.38083151964686, 9.38083151964686, 12.2474487139159,
9.79795897113271, 9.79795897113271, 9.79795897113271, 9.79795897113271,
10.4880884817015, 10.0498756211209, 9.38083151964686, 9.53939201416946,
8.30662386291807, 8.30662386291807, 10.7238052947636, 10.7238052947636,
10.7238052947636, 5.8309518948453, 10.9544511501033, 9.32737905308882,
9, 7.74596669241483, 10.2469507659596, 10.2469507659596, 10.2469507659596,
10.2469507659596, 10.2469507659596, 4.47213595499958, 4.47213595499958,
4.47213595499958, 4.47213595499958, 4.47213595499958, 4.47213595499958,
7.61577310586391, 7.61577310586391, 7.61577310586391, 7.61577310586391,
7.61577310586391, 11.9582607431014, 11.9582607431014, 11.9582607431014,
8.48528137423857, 6.70820393249937, 8.48528137423857, 8.48528137423857,
8.48528137423857, 7.14142842854285, 7.14142842854285, 13, 13,
8.42614977317636, 8.94427190999916, 10.295630140987, 9.64365076099295,
10.3923048454133, 11.3137084989848, 8.18535277187245, 11.2694276695846,
9.32737905308882, 9.32737905308882, 9.2736184954957, 8.36660026534076,
8.36660026534076, 9.8488578017961, 8.77496438739212, 5.91607978309962,
9.05538513813742, 9.05538513813742, 8.24621125123532, 9.53939201416946,
8.12403840463596, 8.06225774829855, 7, 9.4339811320566, 9.38083151964686,
9.38083151964686, 9.38083151964686, 7.87400787401181, 8.30662386291807,
7.68114574786861, 9.64365076099295, 9.64365076099295, 9.64365076099295,
9, 8.54400374531753, 8.54400374531753, 9.64365076099295, 8.71779788708135,
8.71779788708135, 8.71779788708135, 8.71779788708135, 8.71779788708135,
8.71779788708135, 8.71779788708135, 10.9544511501033, 9, 9, 9,
6.48074069840786, 6.48074069840786, 6.48074069840786, 8.83176086632785,
10.4403065089106, 8.83176086632785, 6.6332495807108, 7.93725393319377,
10.6301458127346, 7.93725393319377, 7.93725393319377, 9.69535971483266,
9.69535971483266, 9.69535971483266, 9.69535971483266, 7.74596669241483,
8.36660026534076, 8.83176086632785, 8.30662386291807, 8.36660026534076,
7.87400787401181, 8.77496438739212, 8.77496438739212, 8.77496438739212,
7.68114574786861, 8.94427190999916, 13.7840487520902, 12.328828005938,
10.9544511501033, 14.8323969741913, 14.8323969741913, 14.8323969741913,
14.8323969741913, 14.8323969741913, 14.8323969741913, 14.142135623731,
14.142135623731, 14.7648230602334, 12.1655250605964, 12.1655250605964,
14.7648230602334, 14.7648230602334, 15.4919333848297, 14.142135623731,
16.2788205960997, 16.2788205960997, 11.4017542509914, 8.06225774829855,
8.06225774829855, 8.94427190999916, 11.4017542509914, 11.4017542509914,
8.66025403784439, 8.66025403784439, 8.94427190999916, 11.8321595661992,
13.4164078649987, 11.8321595661992, 17.8885438199983, 17.8885438199983,
17.8885438199983, 10.4880884817015, 10.4880884817015, 15, 19.8746069143518,
8.94427190999916, 8.94427190999916, 15.6524758424985, 10.4880884817015,
10.9544511501033, 8.94427190999916, 9.21954445729289, 10, 17.3205080756888,
17.8885438199983, 17.8885438199983, 17.3205080756888, 17.8885438199983,
17.8885438199983, 17.8885438199983, 17.8885438199983, 16.1245154965971,
16.1245154965971, 17.8885438199983, 17.8885438199983, 17.8885438199983,
15.9687194226713, 15.1657508881031, 16.1245154965971, 13.6014705087354,
15.4919333848297, 14.6628782986152, 14.6628782986152, 15.4919333848297,
8.94427190999916, 9.48683298050514, 15.4919333848297, 9.48683298050514,
9.48683298050514, 9.48683298050514, 14.142135623731, 12.8452325786651,
12.1243556529821, 19.8746069143518, 19.8746069143518, 19.8746069143518,
19.8746069143518, 19.8746069143518, 19.8746069143518, 19.8746069143518,
18.0277563773199, 18.0277563773199, 14.8323969741913, 17.8885438199983,
18.0277563773199, 18.0277563773199, 14.0712472794703, 13.7840487520902,
11.4017542509914, 11.1803398874989, 16.2788205960997, 15.6524758424985,
10, 10.9544511501033, 17.8885438199983, 16.1245154965971, 16.1245154965971,
10, 8.36660026534076, 8.36660026534076, 8.94427190999916, 13.9642400437689,
12.5698050899765, 12.5698050899765, 17.1755640373177, 14.142135623731,
13.4164078649987, 14.8323969741913, 14.4913767461894, 18.1659021245849,
17.8885438199983, 17.8885438199983, 14.7648230602334, 15.2643375224737,
16.583123951777, 16.583123951777, 16.583123951777, 16.583123951777,
16.583123951777, 16.583123951777, 16.583123951777, 15.1657508881031,
16.1245154965971, 16.431676725155, 16.431676725155, 16.431676725155,
18.1383571472171, 18.1383571472171, 15.4919333848297, 15.9373774505092,
15.9373774505092, 15.9373774505092, 15.9373774505092, 15.9373774505092,
15.9373774505092, 15.9373774505092, 15.1657508881031, 16.1245154965971,
16.1245154965971, 16.1245154965971, 16.1245154965971, 8.48528137423857,
15.3297097167559, 20.1246117974981, 16.5227116418583, 17.058722109232,
20.7364413533277, 16.431676725155, 16.1245154965971, 7.93725393319377,
13.5277492584687, 8.06225774829855, 8.06225774829855, 19.2353840616713,
7.41619848709566, 9.48683298050514, 9.48683298050514, 9.79795897113271,
18.8148877222268, 18.8148877222268, 10.1488915650922, 8.54400374531753,
13.1529464379659, 13.1529464379659, 13.1529464379659, 13.1529464379659,
13.1529464379659, 13.1529464379659, 13.1529464379659, 13.1529464379659,
13.1529464379659, 15.4919333848297, 15.4919333848297, 20.1246117974981,
6.2449979983984, 18.9736659610103, 18.9736659610103, 18.9736659610103,
16.7630546142402, 16.7630546142402, 16.7630546142402, 16.7630546142402,
16.7630546142402, 16.7630546142402, 19.4935886896179, 16.7630546142402,
20.2484567313166, 20.2484567313166, 20.2484567313166, 11.916375287813,
11.916375287813, 11.6189500386223, 11.0905365064094, 11.0905365064094,
11.0905365064094, 11.0905365064094, 10, 10, 15.8113883008419,
15.8113883008419, 15.8113883008419, 15.8113883008419, 8.94427190999916,
8.66025403784439, 8.36660026534076, 21.5638586528478, 17.6635217326557,
15.2315462117278, 15.2315462117278, 15.2315462117278, 14.0712472794703,
14.0712472794703, 14.422205101856, 14.0356688476182, 17.2626765016321,
17.2626765016321, 17.2626765016321, 8.94427190999916, 15.8113883008419,
15.8113883008419, 14.4913767461894, 13.7840487520902, 14.8323969741913,
14.8323969741913, 10.5356537528527, 17.6635217326557, 16.0312195418814,
16.9705627484771, 14.0712472794703, 14.0712472794703, 14.0712472794703,
14.0712472794703, 14.0712472794703, 14.0712472794703, 10.1980390271856,
19.3649167310371, 19.3649167310371, 19.3649167310371, 16.2788205960997,
14.422205101856, 16.2788205960997, 12.8840987267251, 19, 15.1327459504216,
14.7648230602334, 14.7648230602334, 14.4913767461894, 14.4913767461894,
13.4164078649987, 17.8885438199983, 15.1657508881031, 18.1659021245849,
18.1383571472171, 18.1383571472171, 18.9208879284245, 13.5646599662505,
14.6969384566991, 13.4536240470737, 12.8840987267251, 19.94993734326,
19.94993734326, 13.5277492584687, 13.5277492584687, 13.5277492584687,
13.5277492584687, 13.5277492584687, 18.6547581061776, 16.2788205960997,
14.422205101856, 17.058722109232, 14.6969384566991, 15.3297097167559,
15, 19.313207915828, 19.313207915828, 15.1657508881031, 16.1245154965971,
15.1657508881031, 15.1657508881031, 15.1657508881031, 7.54983443527075,
7.87400787401181, 17.8885438199983, 14.7648230602334, 15.3948043183407,
15, 15, 15, 15, 15, 15, 15, 19.2093727122985, 19.2093727122985,
19.2093727122985, 10, 10, 13.9283882771841, 14.4913767461894,
15.6204993518133, 15.8429795177549, 15.6204993518133, 14.6969384566991,
15.8113883008419, 16.431676725155, 15.1657508881031, 16.1245154965971,
14.8323969741913, 16.1245154965971, 17.2336879396141, 17.2336879396141
)), class = "data.frame", row.names = c(NA, -820L))

Comment: what does the summary of model `mod1` show? Is the variance term zero / almost zero?
Comment: Thanks for adding the model output. Re you comment below; rather than hiding the singular message, It would be good if you read `?isSingular` as prompted -- it gives info on why this may be happening and what to do about it.
Answer: It is plotting everything at 0 because the variance term is exactly zero.
summary(mod1)
Generalized linear mixed model fit by maximum likelihood (Adaptive
  Gauss-Hermite Quadrature, nAGQ = 0) [glmerMod]
 Family: binomial  ( logit )
Formula: resp ~ var1 + (var1 || group1) + (1 | group2)
   Data: testdata
Control:
glmerControl(optimizer = "bobyqa", optCtrl = list(maxfun = 2e+06))

     AIC      BIC   logLik deviance df.resid
  1110.4   1133.9   -550.2   1100.4      815

Scaled residuals:
    Min      1Q  Median      3Q     Max
-1.8083 -0.9033 -0.5787  0.9235  1.7280

Random effects:
 Groups   Name        Variance Std.Dev.
 group2   (Intercept) 0.2059   0.4538
 group1   var1        0.0000   0.0000
 group1.1 (Intercept) 0.1071   0.3272
Number of obs: 820, groups:  group2, 74; group1, 7

Fixed effects:
            Estimate Std. Error z value Pr(>|z|)
(Intercept)  1.08061    0.35577   3.037 0.002386 **
var1        -0.08115    0.02308  -3.516 0.000438 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Correlation of Fixed Effects:
     (Intr)
var1 -0.900

I'm not sure why the singular fit warning is not showing up automatically, but when I fit the model and run the following we see that it is one, and the model has not been able to estimate the random slope:
isSingular(mod1)
[1] TRUE

I would recommend looking at the different approaches to dealing with the singularity here: https://bbolker.github.io/mixedmodels-misc/glmmFAQ.html#singular-models-random-effect-variances-estimated-as-zero-or-correlations-estimated-as---1
Comment: I've now edited my answer to direct you to a really useful page. The link should take you directly to the relevant section.
Comment: It does show singular fit warning if you remove "control=glmerControl(optimizer="bobyqa", optCtrl=list(maxfun=2e6)),nAGQ=0)" part, I found this in another post as a way to deal with a singular fit warning.
Comment: It gets rid of the warning, but the fit is still singular. What you are seeing is the result of the model not being able to estimate the random slope.
Comment: Yeah, I see that now. Any other way to deal with the singular fit? Other than reducing model complexity?


Projecting an affine hypersurface away from a point in its projective closure is never a finite map?

Question: Let $X\subset \mathbb{A}_k^r$ be an irreducible hypersurface defined by a polynomial $g$, where $k$ is an algebraically closed field. Embed $\mathbb{A}^r\hookrightarrow\mathbb{P}^r$ in the usual way. Consider the stereographic projection of $X$ from a point $p$ in $\overline{X}\setminus X$ to some hyperplane not containing $p$, where $\overline{X}$ is $X$'s projective closure. I want to show that this projection is never a finite map from $X$ to this hyperplane.  (This comes from an exercise in Shafarevich, specif. section 1.5 exercise 8 in Basic Algebraic Geometry 1.)
(Aside: Actually the desired result is false! See Addendum below for revised question.)
I have reduced the problem to the following algebraic one, but haven't seen how to complete the proof in these terms. My ideal answer would show me how to fill in the needed steps in this algebraic situation, but I would also be interested to hear more geometric arguments as well.
Algebraic reformulation: Let $g$ be an irreducible polynomial in $k[x_1,\dots,x_r]$. Let $L_1,\dots,L_{r-1}$ be $r-1$ linear functions on $\mathbb{A}^r$, and let each $L_j = \ell_j +\alpha_j$ where each $\ell_j$ is a linear form and each $\alpha_j\in k$. Suppose the $\ell_j$'s are linearly independent. Let $g_m$ be $g$'s maximum-degree homogeneous component, and suppose we are given that $g_m$ vanishes on the common zero set of $\ell_1,\dots,\ell_{r-1}$. Prove that in this case, $k[x_1,\dots,x_r]/(g)$ is not finite over the subring generated by the $L_j$'s.
Explanation of algebraic reformulation: The $L_j$'s are the restrictions to $\mathbb{A}^r$ of linear forms $L_j'$ on $\mathbb{P}^r$ that, together with $x_0=0$, cut out the point $p$ that is the center of the stereographic projection. Then the projection is, for suitable parametrization of the hyperplane being projected into, given by $(x_0:x_1:\dots:x_r)\mapsto (x_0:L_1':\dots:L_{r-1}')$; so its restriction to $\mathbb{A}^r$ is given by $(x_1,\dots,x_r)\mapsto (L_1,\dots,L_{r-1})$. The fact that $p$ is in $X$'s projective closure is expressed by the condition that when $x_0=0$ and all the $L_j'$'s are zero too, then $g$'s homogenization is zero. This translates into the condition that $g_m$ vanishes when all the $\ell_j$'s vanish. The question of whether the map is finite is then the question of whether $X$'s coordinate ring $k[x_1,\dots,x_r]/(g)$ is finite over the pullback image of $k[y_1,\dots,y_{r-1}]$ (the coordinate ring of the hyperplane), which is the subalgebra generated by the $L_j$'s.
Work so far: By the Nullstellensatz, the condition that $g_m$ vanishes when the $\ell_j$'s vanish amounts to saying that $g_m$ is in the radical of the ideal generated by the $\ell_j$'s; call it $L$. It seems to me that this ideal is already radical, since the $\ell_j$'s are homogeneous of degree $1$, though I'm not sure of this. Then $g_m$ is actually in $L$. Also, not every $x_i$ can be in $L$ because since it is a homogeneous ideal, an $x_i$ could only be in $L$ if it is a linear combination of the $\ell_j$'s, but there are only $r-1$ of them and $r$ $x_i$'s, so they cannot span the $k$-vector space containing the $x_i$'s. So, consider an $x_i$ that is not in $L$. If $k[X]$ were finite over the subalgebra generated by the $L$'s, there would be an integral equation for $x_i$ over this subalgebra, occurring in $k[X] = k[x_1,\dots,x_r]/(g)$:
$$x_i^s + \sum_{j=0}^{s-1} F_j(L_1,\dots,L_{r-1}) x_i^j = 0$$
Lifting this to an equation in $k[x_1,\dots,x_r]$, and noting that polynomials in the $L_j$'s are equally well polynomials in the $\ell_j$'s (and changing the $F_j$'s accordingly), yields:
$$x_i^s + \sum_{j=0}^{s-1} F_j(\ell_1,\dots,\ell_{r-1}) x_i^j = Hg$$
for some $H\in k[x_1,\dots,x_r]$.
If I could rig the left side to guarantee that the highest-degree homogeneous component is degree $s$, then this would yield a contradiction: reducing mod $L$ would reduce the degree of the right side but not the left, since $x_i^s\notin L$ (if I am right that $L$ is radical). But this is where I am stuck.
Thanks in advance for your thoughts.
Addendum, 3/27: It seems that the result is false! user119882 gives more or less the easiest possible counterexample: $r=2$, $L_1=x$, $g=y+x^2$. Clearly $k[x,y]/(y+x^2)$ is finite over the subring $k[L_1] = k[x]$.
This is also a counterexample to the original geometric statement: we have a plane conic tangent to the line at infinity; the stereographic projection away from this point of tangency is a finite map (actually an isomorphism) to $\mathbb{A}^1$.
Unless I am very very confused, I lifted this statement directly from Shafarevich. The following is on p. 66 of the paperback second edition:

Let $X\subset\mathbb{A}^r$ be a hypersurface of $\mathbb{A}^r$ and $L$ a line of $\mathbb{A}^r$ through the origin. Let $\varphi_L$ be the map projecting $X$ parallel to $L$ to an $(r-1)$-dimensional subspace not containing $L$. Write $S$ for the set of all lines $L$ such that $\varphi_L$ is not finite. Prove that $S$ is an algebraic variety. [Hint: Prove that $S = \overline{X}\cap \mathbb{P}^{r-1}_\infty$.]

So the parenthetical hint must be wrong! $S$ is a subset of $\overline{X}\cap\mathbb{P}^{r-1}_\infty$ but not necessarily the whole thing!
Revised question: What is the condition (either geometric or algebraic) on the point $p$ of $\overline{X}\setminus X$ such that stereographic projection from this point is not a finite map on $X$?
Comment: @user119882 - yup, that's a counterexample! I've edited the question to reflect this.
Answer: Why might $\varphi_L$ not be finite?  Because points might be "missing" from certain fibres.
If $X$ has degree $d$, then typically, a line through $P$ will meet $\overline{X}$ in $d$ points, one of which will be $P$, and the remainder of which will be
$d-1$ other points of $X$.  (If a line passes through two distinct points
of $\overline{X} \setminus X$, say $P$ and another point at infinity $Q$,
then it lies in the plane at infinity, and so can't contain any point of $X$.
In other words, a line through $P$ and a point of $X$ can't contain any point
at infinity besides $P$.)
But if the line has a multiple intersection at $P$, i.e. lies in the
tangent plane to $\overline{X}$ at $P$ (here I am assuming that $\overline{X}$
is smooth, so that it makes sense to talk about the tangent plane), then it meets
$X$ in $< d-1$ points, and so finiteness will be violated (the number of points
in the fibre, counted with multiplicity, it not being preserved).
But ... what if this line lies entirely at infinity (as in the counterexample)?
Then it won't contain any point of $X$, and so the problem with having
a fibre that is too small goes away.
Now every tangent line to $P$ is at infinity if and only if the tangent hyperplane to $P$ of $\overline{X}$ is just the hyperplane at infinity.  So if $P$ is
such that the hyperplane at infinity is tangent to $\overline{X}$ at $P$,
we shouldn't get a violation of finiteness.  (And this is what is happening in the counterexample.)
[The above is only approximate. I am not describing finiteness in a precise way,
but just using the intuition of "having a constant number of points in the fibre",
which is more like finite flat than simply finite.  Although, if $X$ is smooth,
then by miracle flatness, if the projection to the hyperplane is finite, then it is automatically flat.  So I am not being too egregious.]


For a positive definite matrix $A$, how to prove that $\| Ax \| \geq \lambda_1 \| x \|$?

Question: For a positive definite matrix $A$, how to prove that  $\| Ax \| \geq \lambda_1 \| x \|$ where $\lambda_1$ is the minimum eigenvalue of $A$.
Comment: Use \| instead of \parallel for norms.
Answer: Since $A$ is PSD then so is $A - \lambda_1 I$. Using the PSD definition on $A-\lambda_1 I$, we have
$$x^T (A - \lambda_1 I) x > 0$$
for all $x$. Expand and re-arrange, we get
$$x^T A x > \lambda_1 x^T x$$
But $x^T A x < \Vert Ax \Vert \Vert x \Vert$ by the Cauchy-Schwarz and $x^Tx = \Vert x \Vert ^2$ so
$$\Vert Ax \Vert \Vert x \Vert > \lambda_1 \Vert x \Vert ^2$$
or
$$\Vert Ax \Vert > \lambda_1 \Vert x \Vert $$
Comment: It seems to me that your first sentence assumes the very thing that we want to prove.
Comment: I see no problem with this answer. It starts basically by the observation that for general A, b, the eigenvalues of A-bI are the eigenvalues of A, shifted by b, and deduces $A-\lambda_1 I$ has non-negative eigenvalues.
Comment: @TonyK dang it. I was just typing something very similar. Fully agreed. That statement isn't true for an arbitrary $\lambda_1$, after all..
Comment: @TonyK how ? I thought we're proving $\Vert Ax \Vert > \lambda_1 \Vert x \Vert$
Answer: We have $ 0 \le \lambda_1 = \min \{ \frac{\langle Ax,x \rangle }{\|x\|^2} \  : \ x \in \mathbb{R} \}$. Hence
$$ \lambda_1 \| x\|^2 \le x^T Ax\le \|Ax\| \cdot \|x\|.$$
The last $ \le$ " is Cauchy-Schwarz.
Answer: If $A$ is positive definite, then $A-\lambda_1 I$ is semi positive definite since the eigenvalues of $A-\lambda_1 I$ are $\lambda_i - \lambda_1$ which are nonnegative. Then use the definition of semi positive definiteness in https://en.wikipedia.org/wiki/Definiteness_of_a_matrix
then use cauchy schwartz inequality finally you will get the result.


Adding 90 days to created date

Question: I'm grabbing the first day of the next quarter as StartDate. How can I add 90 days to it. The below is gives me invalid column error for StartDate within EndDate.
SELECT
    DATEADD(qq, DATEDIFF(qq, 0, MAX(Time_Stamp)) + 1, 0) as StartDate,
    DATEADD(day, 90, MAX(StartDate)) as EndDate
FROM Survey
WHERE MainHospital = 'Hospital1'

column
Time_Stamp
-----------
2014-06-04 16:01:14.000
2014-06-04 15:55:33.000
2014-06-04 15:45:05.000
2014-06-04 15:36:15.000
2014-06-04 15:00:34.000
2014-06-04 14:35:24.000
2014-06-04 14:04:50.000
2014-06-04 13:46:55.000
2014-06-04 13:23:57.000
2014-06-04 11:27:51.000

Just for refernce I found this which was very useful:
http://zarez.net/?p=2484
So ended up with something like this:
SELECT
     --Returns first day of next quarter
     DATEADD(qq, DATEDIFF(qq, 0, MAX(Time_Stamp)) + 1, 0) as StartDate,
     --Returns last day of next quarter
     DATEADD (dd, -1, DATEADD(qq, DATEDIFF(qq, 0, MAX(Time_Stamp)) +2, 0)) as EndDate
    FROM Survey
    WHERE MainHospital = 'Hospital1'

Comment: Please type `DAY`/`QUARTER` instead of this lazy `dd`/`qq` shorthand. https://sqlblog.org/blogs/aaron_bertrand/archive/2011/09/20/bad-habits-to-kick-using-shorthand-with-date-time-operations.aspx
Answer: It's invalid because StartDate is alias for your date calculation. You can use alias only when you have results. In other words alias is available when you have dataset returned from server.
You can for example use subquery:
SELECT
  StartDate,
  DATEADD(day, 90, MAX(StartDate)) as EndDate
FROM (
  SELECT
     DATEADD(qq, DATEDIFF(qq, 0, MAX(Time_Stamp)) + 1, 0) as StartDate
  FROM Survey
  WHERE MainHospital = 'Hospital1'
) DS

Answer: The sql query doesn't know of column alias in the select.  It is a self referencing error.  The select statement creates the alias so it can't itself use the alias.  The only statement to run after select is order by, where you can use an alias.
I would reuse your logic to prevent needing a subquery.  Since ninety days is just another quater, change 1 to 2 and add another quarter to your Time Stamp.
SELECT
    DATEADD(qq, DATEDIFF(qq, 0, MAX(Time_Stamp)) + 1, 0) as StartDate,
    DATEADD(qq, DATEDIFF(qq, 0, MAX(Time_Stamp)) + 2, 0) as EndDate
FROM Survey
WHERE MainHospital = 'Hospital1'

Answer: You can't reference a derived column by name within the same query. You will have to add the same logic here.
SELECT
DATEADD(qq, DATEDIFF(qq, 0, MAX(Time_Stamp)) + 1, 0) as StartDate,
DATEADD(day, 90, DATEADD(qq, DATEDIFF(qq, 0, MAX(Time_Stamp)) + 1, 0)) as EndDate
FROM Survey
WHERE MainHospital = 'Hospital1'

Not quite sure what you are trying to do with MAX in there so I just removed it.

Adding 90 days to created date


How to combine the GOOGLEFINANCE formula with the INDEX

Question: I used the following GOOGLEFINANCE function to import market data straight into Google Sheets and it works:
=GOOGLEFINANCE("INDEXDJX:.DJI"; "high"; $A$1)
But I only want to get the high price, without the cells that indicate the date and the headers. Tried this formula but didn't work:
=index(GOOGLEFINANCE("INDEXDJX:.DJI"; "high";$A$1),2,2)
Any ideas?
Answer: Try index + flatten and get the 4th element:
=index(flatten(GOOGLEFINANCE("INDEXDJX:.DJI", "high", $A$1)),4)


Compare Json in Hierachy to Set Vars

Question: I need to set three category meta vars on a product page from json IDs. Each product page can have any number of products on the page, and each product can have values for each of those categories.
If Product 1 has values, we use those. However, if Product 1 has a zero ('None' category) or it is undefined, it needs to fall through to the next product and so on until a category value is found, or it gets set to 'None' if it reaches the end of the product comparison.
JSON
_jsonmeta = [
    { "Product": 1, "c1": 0, "c2": 1111, "c3": undefined },
    { "Product": 2, "c1": 2222, "c2": 2222, "c3": undefined }];
    //should set category1=2222, category2 = 1111, category3 = 0 ('None')

Then I set each category by passing in the item and the index
function compareJson(json) {
        $.each(json, function (i, item) {
            //update if applicable
            category1 = checkForNullOrZero(item.c1, i);

            category2 = checkForNullOrZero(item.c2, i);

            category3 = checkForNullOrZero(item.c3, i);
        });

Then I need a way to sort, filter, or compare the current value against all other products' respective category.
function checkForNullOrZero(categoryidarg, indexarg) {
        if (categoryidarg == null || typeof categoryidarg === 'undefined') {
            //ignore it if undefined
            console.log('Ignore: ' + categoryidarg);
        }
        else if (categoryidarg == 0) {
            //check the others because this category is 'None'
            console.log('Fall through to next: ' + _jsonmeta[indexarg]);
        }
        else {
            //check the hierarchy to see if this Area trumps the others
            console.log('Compare: ' + categoryidarg + ' vs ' + _jsonmeta[indexarg]);
        }

       //need to return category here
    }
    }

Here is a full fiddle: http://jsfiddle.net/TheFiddler/6mwpff7p/
Answer: In order to do it that way, from the checkForNullOrZero function you either have to return (1) the value of current category or (2) the value of the current product of the category.
I think it might be easier to define categories as an array:
var categories = [undefined,undefined,undefined];

and then change the compareJson function as so:
function compareJson(json) {
    $.each(json, function (i, item) {
        //update if applicable
        categories[0] = checkForNullOrZero(item.c1, 0);

        categories[1] = checkForNullOrZero(item.c2, 1);

        categories[2] = checkForNullOrZero(item.c3, 2);
    });
}

and then from the checkForNullOrZero function, you have access to categories[indexarg], which is the original value you should return if the new value doesn't overwrite it.
A working fiddle is here:
http://jsfiddle.net/6mwpff7p/5/
A problem with this solution is that is checks every product, even if all categories are already set. A better solution might be to use a for loop. Fiddle with this method is: http://jsfiddle.net/6mwpff7p/6/
Comment: Great, the second method is better. I'll go with that, thanks.

Compare Json in Hierachy to Set Vars


Use Facebook account in Selenium tests

Question: I'm using selenium for integration tests, so it clicks through our web app, logs into Facebook and do some actions. Facebook started to block account used in those tests and send an email "Did you log in to Facebook from somewhere new?"
All logins are done from same IP, same OS (Linux, Jenkins) and safari browser. I've marked several times that it's me who logged in (well, its jenkins;p). We run those tests every 30 minutes -- sometimes it ok for couple days, sometimes account is blocked right away.
Is there any way to mark an account as 'safe' for such actions?
Update:
Seems test accounts are a way to go -- didn't see them before:
https://developers.facebook.com/docs/facebook-login/testing-your-login-flow/.
Comment: use test users instead: https://developers.facebook.com/docs/apps/test-users
Comment: thx @luschn, found it maybe a minute before you wrote :) and seems to work so far
Comment: Scrapping **`Facebook`** is against their **`ToS`**. Use **`Facebook APIs`** instead.
Comment: but I want to test same flow as user will use. Using different way in those tests doesnt make sense as it will test something different ; )
Comment: I am afraid :( you may land up in **`Facebook Jail`**
Answer: For testing purposes, you can use Test Users: https://developers.facebook.com/docs/apps/test-users
You can create/manage them in the App settings or even with the API.

Use Facebook account in Selenium tests


Mnemonics for memorizing the Staff: useful or harmful?

Question: I want to teach a friend of mine how to read music, but I don't know if to use mnemonics or not. The benefit of using them is that you can remember them more easily. The downside is that you might start "counting" the lines and reciting the mnemonics in order to recognize each note. to use mnemonics or there is another way?
For those who don't know what I'm talking about, example mnemonics are:

Treble clef lines: Every Good Band Draws Fans
Treble clef spaces: FACE
Bass clef lines: Good Boys Deserve Fudge Always
Bass clef spaces: All Cows Eat Grass

During research for this question I found this site which looks really nice to help memorize the different notes using flash cards.
Answer: Personally, I think this is too simple for mnemonics to be particularly useful.  The important thing is practice.  It doesn't matter how they're recalling the notes, as long as they're practising them.  If they do it enough it will become automatic.
Answer: It is harmful to spend time learning mnemonics for something you plan to use without looking it up all the time. It will slow you all the time and all the way (like writing letters on the notes) and act like a crutch, because you will have in fact several things to remember to go to the result.
The best way is to use a book with, say, treble clef reading exercices, introducing one then two, then three, etc. different notes.  You are not supposed to learn music notation at once, in a day.
This way, at each step, you are training only for novelty. Many instrument methods for young beginners (when you have to learn at the same time music notation and instrument technique) use this trick. And some of them are beautifully illustrated. I have used them successfully with adults.
If your friend is already playing guitar, if you can do it yourself (for instance with a freeware music notation software), make random reading exercices for him with more and more open guitar strings notes on the treble clef (start with the highest ones (G B e) and reserve low E for later). Then add a few notes in between, like A, c, d, f, f#, Bb.  And make them longer.
Comment: When i started learning my first instrument, i used a book which introduces you to one note at a time, showing you where it is on the stave and how to play it. You then play short tunes using this note and any other notes previously mentioned. There are no letter written on the page or mnemonics, so you are forced to remember which note is where on the stave and how to play it. This was a great exercise to learn the staff. For those interested, this was in a book called 'The Guitarist's way' which is perfect for beginner guitarists, especially if you want to learn classical guitar.
Answer: I've never found mnemonics helpful for music notation (obviously very subjective)
Dangerously close to being out of scope for this site, but I am aware that people learning Morse code are told not to use mnemonics because it slows down recognition. One of the two most popular methods for learning Morse code (and arguably the one most effective for full speed recognition) is the Koch method, which involves introducing new letters gradually.
I believe the same would be true of music notation: No mnemonics, just gradually introduce new notes.
Answer: I've found over my years on studying music that some mnemonics learned in the past have become an annoyance. I agree that in the early stages of musical development they do help focus a persons attention to the essentials of note reading, interval recognition, and sequence of accidentals.
This concept used in ear training, where a commonly known song is used to identify intervals, has been the most difficult for me to shake these 20 years after learning it. For example 'Here Comes the Bride' for an ascending perfect 4th or 'My Bonnie Lies Over the Ocean' for an ascending major 6th are both called upon when I'm trying to sing a melody that I have never heard before. It can be frustrating to be singing those songs in your head at this stage of musical development. I'd be interested to see if singers who sight sing regularly suffer the same problem. Perhaps reliance on mnemonics is limited to activities that are done on a less regular basis.
If you want to be really cruel but effective you could have your friend go through Hindemith's 'Elementary Training for Musicians'. They would certainly become an adept musician if they make it through that book.
Answer: The really hard part is remembering which mnemonic goes with which thing.  Is "Fat Boys Eat After Dumping Garbage Cans" the order of the sharps on a key signature or the order of the flat keys?  Or is it the Resistor Color Code?  No, wait, that's "How I want a drink, alcoholic of course."
I was so young when I learned to read music that I never would have understood the mnemonics.


Simple optimization problem.

Question: In my Calculus I assigment, I'm stuck on the following :
Find $M_1=(x_1,y_1)$ on $y=5x+6$ and $M_2=(x_2,y_2)$ on $y=-(x-3)^2+4$ such that the square of the distance between $M_1$ and $M_2$ is minimal.
I'm fine with that, but they add the following : formulate the problem using a fourth degree polynomial implying only variables $x_1$ and $x_2$.
I did :
Be $D=(x_1-x_2)^2+((5x_1+6)-(-(x_2-3)^2+4))$ the distance we want to minimize, then $D=x_1^2+2x_2^2-2x_1x_2+5x_1-6x_2+11$ when expanded.
I don't understand where that "fourth degree polynomial" will appear?
Thanks !
Comment: Double check the expression for $D$, you need $(y_1 - y_2)^2$.
Comment: @user111288: maybe you can translate both the line and the parabola, so that the line goes thru the origin. Then you can find the ortho projection of a general point in $y=x^2$ into the line.
Answer: Answered in comment:   the correct formula for squared distance, $$D=(x_1-x_2)^2+((5x_1+6)-(-(x_2-3)^2+4))^2$$ is indeed a fourth degree polynomial in $x_1,x_2$.
The straightforward approach is to equate $\partial D/\partial x_1$ to zero (this is a linear equation for $x_1$), and eliminate $x_1$ from $D$. The deal with $\partial D/\partial x_2=0$. Not pleasant, but maybe this is the purpose of the exercise.
A smarter approach is to realize that the tangent line to the parabola at $M_2$ must be parallel to the line $5x+6$. This gives $x_2$ right away.

Simple optimization problem.


How to Pass Jsonstringfy object with other parameters

Question: I want pass more parameter with json stringify()  but when passing other variable getting null value. please let me know right way of passing more variable .
I have tried this
data: {model:JSON.stringify(arr), buildingid ,shopid,post},

$("#btnArchive").click(function () {
    var Buildingid = $("#BuildingId").val();
    var shopid = $("#ShopId").val();
    var Post = $("#SelectedValue").val();

    var arr = [];
    debugger;
    //Loop through the Table rows and build a JSON array.
    var customers = new Array();
    $(".tblSavingCollChk:checked").each(function () {
        var row = $(this).attr("chkid");
        alert(row);
        debugger;
        //customers.push(row);
        arr.push({ Id: row });
    });

    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: "/Archive/UpdateStatus",
        data: JSON.stringify(arr),
        dataType: "json",
        success: function (r) {
            if (r == true) {
                alert("Record Updated successfully");
                document.location = '@Url.Action("ArchiveList","Archive")';
            }
        },
        error: function (err) {},
    });
});

Controller action
public ActionResult UpdateStatus([FromBody] ArchiveViewModel[] model,string buildingid, string shopid, string Post)//List values)
{}
Comment: What's your parameter of UpdateStatus  in your controller ?
Comment: public ActionResult UpdateStatus([FromBody] ArchiveViewModel[] model,string buildingid, string shopid, string Post)//List values){}
Answer: If you want to pass more variable,I have a work demo like below, you can refer to it:
remove [Frombody] and dataType,contentType
In the controller:
public class jsonPostController : Controller
    {
        public IActionResult Index()
        {
            return View();
        }
        [HttpPost]
        public IActionResult GetData(AuthorVM jsonInput ,string cc, string buildingid, string shopid)
        {
            return View();
        }
    }

Index view:
<input type="button" id="btnGet" value="submit" />

<input id="BuildingId" value="aa" type="hidden" />
<input id="ShopId" value="aaa" type="hidden" />

Author:
public class Author
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }

Update
If you want to pass array, we can add a new model , ajax change as above:
AuthorVm:
public class AuthorVm
    {
        public List<Author> Authors { get; set; }
    }

Result:
Comment: Thanks a lot  its working for other variable but  Still i am getting null because have to use array object to pass bulk of data that's why  added checked values in array. please let me know how to pass array also
Comment: please suggest me how to pass array and other variable.
Comment: @Jayaacharya To pass array , I make some change at ajax and add a new model, please see my update.


Colocar campos text inline bootstrap

Question:

*

      <input type="number" id="" name="protocolos[]"  class="form-control col-md-3 col-xs-3" style="width:65px;display:inline"/>

      <input type="hidden" id="" name="siglas[]" value="'.$sigla.'" style="width:65px;display:inline"/>

Comment: Pode explicar um pouco melhor a necessidade? Não consegui entender...
Comment: Não tem sentido transformar o elemento em inline e setar width, porque o width não funciona em elementos inline. Talvez o que vc queira é inline-block.
Comment: Isadora o seu problema MUITO provavelmente é com a importação do Bootstrap na página! Eu testei aqui e ficou o * e o input na mesma linha sem problemas. Se quiser eu posto a resposta com o código
Comment: Oi, gente! Obrigada pelas respostas! @dvd vou testar o  inline-block. O width é apenas p diminuir o tamanho do campo.
Comment: @DiegoSantos apenas quero colocar campos do tipo text na mesma linha, queria saber se o bootstrap tem alguma classe especial p isso.
Comment: @hugocsl se você não se importa em compartilhar, ficaria agradecida.
Answer: Isadora de acordo com a Documentação do Bootstrap a forma de fazer o formulário "inline" é essa https://getbootstrap.com/docs/3.3/css/#forms-inline
O seu código tinha alguns errinho básicos como a tag  sem estar fechada e outro problemas de estrutura da organização do html.
Fiz esse modelo misturando o seu código e o da documentação do Bootstrap, acho que ele pode te atender da forma que vc deseja.
OBS: No primeiro exemplo o  *  está dentro da mesma Col- do <input> já no segundo exemplo o  *  está separado em uma Col- e o <input> em outra Col- (mas tudo fica tipo inline)

<link rel="stylesheet" type="text/css" media="screen" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
<form class="form-inline">

                *
            <input type="number" id="" name="protocolos[]" class="form-control" style="width:65px;display:inline"/>

        *

            <input type="text" id="" name="siglas[]" class="form-control" value="'.$sigla.'" style="width:65px;display:inline"/>

</form>

Qualquer dúvida é só falar

Colocar campos text inline bootstrap


Two sequences are equivalent. Prove that one is Cauchy iff the other is Cauchy.

Question: This question has already been asked and answered here

Let $ϵ>0$ be given. With loss of generality, we may assume $ϵ$ is rational. Suppose $a_n$ is a Cauchy sequence and $b_n, a_n$ are equivalent.
Choose N such that $|b_k−a_k|<\frac13\epsilon$ and $|a_n−a_m|<\frac13\epsilon$ whenever $k,m,n≥N.$ We can do this because an is Cauchy, and $a_n,b_n$ are equivalent.
Then if $n,m≥N$, we have
$|b_n−b_m|≤|b_n−a_n|+|a_n−a_m|+|a_m−b_m|≤\frac13\epsilon+\frac13\epsilon+\frac13\epsilon=ϵ.$ Hence $b_n$ is Cauchy.
Reversing the roles of $a_n,b_n$ finishes the proof.

What I cannot follow in the answer is why we can assume:
$|b_m-b_n|\le|b_n-a_n|+|a_n-a_m|+|a_m-b_m|$
Am I missing something huge here or I am out of the loop on some standard inequality?
Comment: This is an easy inequality to prove. It's usually given as an exercise. What have you tried?
Comment: What does "two sequences are equivalent" mean? That their difference converges to zero?
Comment: Yes. That their distance from each other eventually gets less than any rational number.
Comment: Thanks @atecce I was just about to post my proof of this problem, but thanks to you i dont have to type it in.
Answer: This is a standard trick in analysis-y proofs: Add $0$ creatively, and use the triangle inequality. In particular, we have
$$|a - b| = |a - (c - c) - b| = |(a - c) + (c - b)| \le |a - c| + |c - b|$$
for any $a, b, c$. This can be generalized to $3$ (as in your case) or more terms.
Answer: It is the triangle inequality:
$$|b_m-b_n|=|(b_n-a_n)+(a_n-a_m)+(a_m-b_m)|\le|b_n-a_n|+|a_n-a_m|+|a_m-b_m|$$
Comment: Thank you both! Sorry it was so easy for you guys.


Trying to create a stored procedure that will build multiple entries

Question: We use a product that essentially sets permissions for objects via a SQL table. I am trying to create a stored procedure that will essentially set the permissions for one user to the same as another. Here's what I have so far:
CREATE PROCEDURE SETPRODUCTS
    @sourceCC BIGINT,
    @targetCC BIGINT
BEGIN
    DECLARE @SQL varchar(5000)

    DECLARE @Sequence_Id varchar(50)
    SET @sequence_id = 0

    BEGIN TRANSACTION

    DELETE FROM TCC WHERE CC_Id = @targetCC

    DECLARE cursorCurrent CURSOR FOR
        SELECT MAX(TCC_Id) + 1
        FROM TCC WITH (tablockx holdlock)

    OPEN cursorCurrent
    FETCH NEXT FROM cursorCurrent INTO @sequence_id

    IF (@sequence_id IS NULL)
       SET @sequence_id = 1

    INSERT INTO TCC (TCC_Id, T_Id, CCC_Id)
    VALUES (@sequence_id,
        (SELECT T_Id FROM TCC WHERE CC_Id = @sourceCC), @targetCC)

    CLOSE cursorCurrent
    DEALLOCATE cursorCurrent

    COMMIT TRANSACTION
END

The error I get is that my subquery has more than one value, which is true. I want to take every entry from that subquery and use it to insert new rows into my database.
Any help would be greatly appreciated!
Comment: Why are you creating a cursor and then only using the first row??? And be very careful here with your TCC_Id. Using MAX + 1 is prone to a LOT of error. Even using tablockx holdlock you can still get some errors. I would prefer to use an identity here as it already handles all of the concurrency issues that are so challenging to do yourself.
Comment: How would I go about using an identity?
Comment: You would have a column in TCC that is an identity column. Then this entire process becomes a single insert statement with no extra code. https://msdn.microsoft.com/en-us/library/ms186775.aspx
Comment: My only concern is regarding adding additional columns to this database. I don't see any triggers on this particular table, but could anything (say, upgrades to the application) create issues going forward if I add an identity column? I assume I would need to retroactively populate for the previously existing rows in the table?
Comment: I couldn't possibly tell you that adding a new column will not cause an issue. I am guessing this is a third party application? If you add an identity column to an existing database it will populate the existing rows.
Comment: Fair enough - and you are right, it's a 3rd party app. Their solution to this is to manually add each product to the user individually. 300 users x 100 products is a LOT of clicking. Just looking for ways to simplify things for my team. Thanks for the info though! Maybe it will help with the full solution
Answer: Try this version of Insert:
INSERT INTO TCC (TCC_Id, T_Id, CCC_Id)
   SELECT @sequence_id, @targetCC, T_Id FROM TCC WHERE CC_Id = @sourceCC

Answer: Alter your procedure as below
Alter PROCEDURE SETPRODUCTS
@sourceCC BIGINT,
@targetCC BIGINT
 BEGIN
 DECLARE @SQL varchar(5000)

DECLARE @Sequence_Id varchar(50)
SET @sequence_id = 0

BEGIN TRANSACTION

DELETE FROM TCC WHERE CC_Id = @targetCC

DECLARE cursorCurrent CURSOR FOR
    SELECT MAX(TCC_Id) + 1
    FROM TCC WITH (tablockx holdlock)

OPEN cursorCurrent
FETCH NEXT FROM cursorCurrent INTO @sequence_id
Declare @total int
IF (@sequence_id IS NULL)
   SET @sequence_id = 1

     SELECT T_Id,ROW_NUMBER() over (order by TCC_id) as rowno into #temp
     FROM TCC WHERE CC_Id = @sourceCC
   select @total=COUNT(*) from #temp
   while(@rowno <> @total)
   begin
       Declare @t_id int
       set @t_id=(select top 1 T_id from #temp where rowno=@rowno)

       INSERT INTO TCC (TCC_Id, T_Id, CCC_Id)
        VALUES (@sequence_id,@t_id,@targetCC)

       set @rowno=@rowno+1
   End
DROP TABLE #temp
CLOSE cursorCurrent
   DEALLOCATE cursorCurrent
   COMMIT TRANSACTION
  END


Entendendo como funciona a conversão de um Objeto para Json

Question: Tenho uma rota PUT que recebe um Json na variável "edicoes" e pelo que entendi, no C# acaba ficando como objeto.
Estava pesquisando uma forma de receber o arquivo corretamente e través de algumas pesquisas por ai, encontrei este código que não entendi muito bem mas funcionou e deu certo.
Queria realmente entender o que está acontecendo e porque foi preciso criar uma variável do tipo Usuario (minha classe)

Usuario _edicoes = Newtonsoft.Json.JsonConvert.DeserializeObject(edicoes);

Answer: O que ocorre nesse caso é que o C# é uma linguagem tipada e o seu objeto JSON é apenas uma string até que ocorra o processo de serialização, ou seja, converter esse texto JSON para um objeto tipado do C#.
O que o código:
Usuario _edicoes = Newtonsoft.Json.JsonConvert.DeserializeObject(edicoes);

Vai fazer é o equivalente a criar um novo objeto usando o new:
Usuario _edicoes = new Usuario();

Com a diferença que o método DeserializeObject do pacote Newtondoft.Json vai fazer o mapeamento das propriedades do objeto JSON para a sua classe definida no C# (Usuario), caso elas possuam o mesmo nome, exemplo:
JSON usuário:
{
  "nome": "Fulano",
  "sobrenome": "da Silva",
  "email": "firstname.lastname@example.com"
}

Classe usuário:
public class Usuario
{
   public string Nome { get; set; }
   public string Sobrenome { get; set; }
   public string Email { get; set; }
}

Nesse caso, a deserialização ocorreria normalmente, já que os nomes das propriedades dos dois objetos coincidem. Um detalhe é que o pacote Newtonsoft.Json já aplica as convenções de nome e transforma as propriedades de Camel Case do JSON para Pascal Case no C#.