I am testing polymorphism in C# with generic types and trying to find the way to make generics countable but C# compiler does not accept operation such as summation on generic types. I found one of the workarounds based on which I created the code below that inherits from an interface that provides a proper function:  using System.IO; using System;  interface ICountable&lt;T&gt; {     T Add(T a, T b);     T Multiply(T a, T b); }  interface IExecute&lt;T&gt; : ICountable&lt;T&gt; {     T Operation(T a, T b); }  class IntSum : IExecute&lt;int&gt; {     public int Add(int a, int b)     {         return a + b;     }     public int Multiply(int a, int b)     {         return a*b;     }     public int Operation(int a, int b)     {         return Add(a,b);     } } class DoubleMultiply : IExecute&lt;double&gt; {     public double Add(double a, double b)     {         return a + b;     }     public double Multiply(double a, double b)     {         return a*b;     }     public double Operation(double a, double b)     {         return Multiply(a,b);     } }  class Program {     static void Main()     {         Console.WriteLine(DoOperation(new IntSum(), 1, 2));         Console.WriteLine(DoOperation(new DoubleMultiply(), 3.5d, 3d));     }      static TResult DoOperation&lt;TOperand, TResult&gt;(TOperand obj, TResult a, TResult b)     where TOperand : IExecute&lt;TResult&gt;     {         return obj.Operation(a,b);     } }   The code above works but in the end I use inheriting to a concrete primitive types and there's a lot of redundant code blocks. My ultimate goal would be to make such types as much generic as possible, something similar to this:  using System.IO; using System;  interface ICountable&lt;T&gt; {     T Add(T a, T b);     T Multiply(T a, T b); }  interface IExecute&lt;T&gt; : ICountable&lt;T&gt; {     T Operation(T a, T b); }  // Generic code class Sum&lt;T&gt; : IExecute&lt;T&gt;, ICountable&lt;T&gt; {     public T Add(T a, T b)     {         return a + b;     }     public T Multiply(T a, T b)     {         return a*b;     }     public T Operation(T a, T b)     {         return Add(a,b);     } }  class Program {     static void Main()     {         //Console.WriteLine(DoOperation(new IntSum(), 1, 2));         //Console.WriteLine(DoOperation(new DoubleMultiply(), 3.5d, 3d));     }      //static TResult DoOperation&lt;TOperand, TResult&gt;(TOperand obj, TResult a, TResult b)     //where TOperand : IExecute&lt;TResult&gt;     //{     //    return obj.Operation(a,b);     //} }   Obviously, the compiler complains as it cannot sum two generic types. Do you think I always have to inherit to specific primitive? Thanks.
What would I do if I want to have a generic method that only accepts types that have overloaded an operator, for instance the subtraction operator. I tried using an interface as a constraint but interfaces can't have operator overloading.   What is the best way to achieve this?
How can I model flips until N successes? You and I decide to play a game where we take turns flipping a coin. The first player to flip 10 heads in total wins the game. Naturally, there is an argument about who should go first.  Simulations of this game show that the player to flips first wins 6% more than the player who flips second (the first player wins approx 53% of the time).  I'm interested in modelling this analytically.  This isn't a binomial random variable, as there are no fixed number of trials (flip until someone gets 10 heads). How can I model this?  Is it the negative binomial distribution?    So as to be able to recreate my results, here is my python code:  import numpy as np from numba import jit   @jit def sim(N):      P1_wins = 0     P2_wins = 0      for i in range(N):          P1_heads = 0         P2_heads = 0         while True:              P1_heads += np.random.randint(0,2)              if P1_heads == 10:                 P1_wins+=1                 break              P2_heads+= np.random.randint(0,2)             if P2_heads==10:                 P2_wins+=1                 break     return P1_wins/N, P2_wins/N   a,b = sim(1000000) Prove that:  $$\displaystyle \sum_{n=m+1}^\infty \dfrac{1}{n!} \le \dfrac{1}{m\cdot m!}$$  I have tried induction on $m$ but it does not work very well. Any suggestion? I need to somehow retrieve the client's IP address using JavaScript; no server side code, not even SSI.  However, I'm not against using a free 3rd party script/service. Order of products of elements in a finite Abelian group We want to show that if $a,b\in G$ where $G$ is a finite Abelian group, we have  $\operatorname{LCM}(|a|,|b|) = |ab|$ given that $ab \neq e$.   How I approached this question was by saying let $\operatorname{LCM}(|a|,|b|) = L$. Then if we show that $L$ divides $|ab|$ and $|ab|$ divides $L$ then $|ab| = L$. Showing that $|ab|$ divides $L$ was fine. But then I am having trouble with the second part that is showing $L$ divides $|ab|$. For this, so far I have:  Consider $(ab)^{|ab|} = e = a^{|ab|}b^{|ab|} $  since we know $a \neq b^{-1}$ by assumption then we can conclude that $|a|$ divides $|ab|$ and $|b|$ divides $|ab|$. We know that $L = \frac{|a||b|}{\operatorname{gcd}(|a|,|b|)}$ from here can we conclude that $L$ divides $|ab|$? If a car hits a wall at a speed of $v$, and an identical car hits a wall at a speed of $2\,v$, with the kinetic energy equation $E_K = \frac{1}{2}mv^2$ (the speed goes from $v$ to $0$) the second car will lose 4 times the energy, and therefore cause 4 times the damage, but with the force equation $F = ma$ (the car hits the wall and decelerates), it will hit with 2 times the force, and cause 2 times the damage.  How can this be explained? My friend and i would like to translate Ubuntu. where should we start? where to find translation tools? How are NFL matchups determined for each season? During the 2012 NFL Season, the Pittsburgh Steelers and Baltimore Ravens play each other in weeks 11 and 13, two weeks (in both NFL schedule and time) apart. To me, that seems too close for comfort.   I do know that teams play other teams in their division twice. How does the NFL schedule procedure work? Is it OK to require users to have a third party login account? For a web app I'm developing I was dreading having to   Require users to create yet another account / password to keep in mind. Handle retrieval of lost passwords etc.   What many sites (like this one for instance) has started offering is to use a third party account to create an account.   What I wonder is whether it would be considered OK to require having third party account, i.e. Do fluorescent lighting and shutter speed create a problem with color cast? I took a bunch of photos at my son's martial arts club using a D90 with a 50mm F1.8.  The club is lit with overhead fluorescent lighting, and I was getting some weird results where some shots are "white", others have an "orange cast", and still others are partly white and partly orange in the same shot.  I suspect it has to do with the combination of the frequency of the light flicker and with the camera shutter speed. Here is a sequence of 3 shots that show the problem.  The shots were taken with 1/500s at F2 and ISO-800 and with Auto-WB.  First shot ("white/normal"):    Second shot ("orange cast" at top):   Third shot ("orange cast" at bottom):   These were taken in burst mode within a second of each other.  Can anybody tell me what is going on?  And, how I can avoid this? Why is "women" pronounced the way it is? As far as I know, it is the only word where wo is pronounced as wee. What is the reason for this? Does it have to do with the origin of the word? SQL Server: Examples of PIVOTing String data Trying to find some simple SQL Server PIVOT examples.  Most of the examples that I have found involve counting or summing up numbers.  I just want to pivot some string data.  For example, I have a query returning the following.  Action1 VIEW   Action1 EDIT   Action2 VIEW   Action3 VIEW   Action3 EDIT     I would like to use PIVOT (if even possible) to make the results like so:  Action1 VIEW EDIT   Action2 VIEW NULL   Action3 VIEW EDIT     Is this even possible with the PIVOT functionality? How to create Motion Trail in Cycles I want to create a motion trail effect for a sword like known in games look at that example if you have an solution that looks not as fancy as in the picture don't mind to post it. I'll accept anything useful. Show that any set in a metric space can be written as the intersection of open sets curl in Mathematica, google link-shortener Is the concept of even/odd numbers applicable to decimal numbers? For e.g. - 4.222 is a even number? Do I need a transit visa for a layover in the United Arab Emirates? Do I need a transit visa for a layover via airports in the UAE, such as Dubai International Airport or Abu Dhabi International Airport? If so, what are the requirements for such a visa? Can I get the transit visa on arrival? Can I buy PSN games and DLC without giving Sony my credit card info? PythonTEX not working on current Overleaf compiler Is there a way to make PythonTEX compile as of today in Overleaf V2 ?  \documentclass[]{article} \usepackage[utf8]{inputenc} \usepackage{pythontex}  \begin{document} \begin{pyverbatim} def calc_ellipticity(theta, delta):     theta = np.deg2rad(theta)     psi = np.arcsin(np.sin(2*theta) * np.sin(delta))/2     return np.tan(psi) \end{pyverbatim} \end{document}   Compiling gives : ? PythonTEX ? Different results between individual and batch clip of rasters in QGIS? Hacking linear regression Let's say I perform linear regression on some data that produces the following $R^2$: $\text{RSS} = 1966815.13$ $\text{TSS} = 2145213.91$ $R^2 =  0.083$ Now let's say I bucket (take the average of successive equal size windows) the data and perform the exact same linear regression. This time the $R^2$ is: $\text{RSS} = 1187.56$ $\text{TSS} = 4758.32$ $R^2 =  0.75$ What have I just done here? I clearly haven't improved the explanatory power of the model over the original data, yet I've hacked the $R^2$ by averaging. What's the bias / variance argument of why this occurs? A graphical representation:  Edit: I've reduced the total variance of the data, but the bias remains unaffected. When (if ever) is this a valid statistical approach?