Stopping the clock without gating the clock

Question: How would one go about making a shift register which only shifts when an enable line is high? The obvious answer is to pass the clock and enable through an AND gate, but that breaks the "don't gate clocks" rule. Another possibility might be using a mux to select the input of each flip-flop to either be the previous flip-flop's output, or to feed its own output back to the input. That would work for the shift register, but is there a better way? How are similar effects achieved in complex designs, where portions of the functionality can be temporarily stopped to save power?
Answer: Depends on the flip-flop used in the shift register. Effectively, negate the enable line or assert the disable line :-), but you know that.
I'd ask, "Why not gate clocks, provided that you gate them 'properly'?"
A hazard is that if you asynchronously gate a clock you may (~= 50% chance for a symmetric clock) produce an additional clock transition at disable or re-enable time. ie DO NOT DO THIS

BUT if you gate synchronously so that eg when gate off the clock continues to its next high/low transition, then stays low while still gated off, then when gated on resumes on the next clock low/high edge.
 As described that may allow a very narrow spike at either edge if gating signal just precedes a clock low/ high transition but a bit of common sense in implementation stops that.
Effectively if delay is acceptable between provided and utilised clock signal (and usually one clock cycle is indistinguishable from the next) then  having a toggling FF in the clock line and disabling it will implement the above (possibly with the described spike hazard present.)

In this circuit from - FPGA Design tips
They say

The following figure shows a synchronous alternative to the gated clock using a data path. The flip-flop is clocked at every clock cycle and the data path is controlled by an enable. When the enable is Low, the multiplexer feeds the output of the register back on itself. When the enable is High, new data is fed to the flip-flop and the register changes its state. This circuit guarantees a minimum clock pulse width and it does not add skew to the clock. The XC4000, Spartan-II, and Virtex families' flip-flops have a built-in clock-enable (CE).

Partially answering my "why not" question above - the gated clock will be delayed by the toggle propogation delay of the gating flip-flop. In some cases this does not matter, in others it's clearly ubbacceptable. The 3rd, worst case, is where it seems OK but sometimes just may not be, on an intermittent basis. So, use with care.
On this page  Roadie Roger warns

Actually gating clocks is relatively evil. Having a gated clock that
transitions less often does save power. Every signal edge is a power
waster in the face of capacitance. Gated clocks create other
problems. Your clocks are no longer exactly lined up. Many chips
have a global clock that goes everywhere. Breaking it into pieces
isn't a good thing. You want to enable data rather than gate clocks.
Call the Enable 'E'. This looks something like:

And Robert usefully counters

Depends on your target technology. The above may hold for FPGA's,
but for standard-cell based ASIC technologies, gated clocks are
an elegant (in my opinion) and clean methodology for low-power
design.
In this case, you will most likely be using a clock tree generator
anyway, and all of the clock tree generators I know easily handle
clock gates. They will automatically align the clocks AFTER any
possible gates, i.e. at the leaf nodes (clock inputs of registers).
In this case, generating a low-skew clock tree is far easier for
gated clocks than for derived clocks (i.e. divided clocks).
Modern synthesis tools also can insert clock gates automatically
by replacing register enables (as shown in the post above) by
gated clocks. This can be handy, but it has the drawback of
reducing your control over clock gates (names, hierarchy).
Inserting clock gates in a VHDL design is easy. Just decide what
gating style you want/need (and/or based, with/without latch, with
test bypass, observability, ...).
My choice is to then explicitly instantiate a clock gating
element where needed. This has the disadvantage of requiring one
to "route" different clock signals through the design, but
it gives you full control over clock gating elements for use
in later stages of the design (clock tree generation, physical
optimization, ...).
Information about "clean" clock gating can be found in books
or also in synthesis tool manuals (where automatic clock
gate insertion is described). Probably you'll also find
resources on the web.
Comment: Interesting. I hadn't realized that there were such different design rules between FPGAs and ASICs.
Answer: Depending upon what you can guarantee about the timing of the enable line relative to clock, the easiest approach may be to gate the clock.  If the enable is guaranteed not to change near a clock edge, you could use a flip flop with ClockIn and /Reset tied to the clock input, and Data tied to the enable input.  Provided that the flip flop doesn't mind having clock and /Reset both change at the same time, that approach will give nice full-width clock pulses no matter what the enable does, provided the enable pulse doesn't violate the sample/hold times of the flip flop.
If the flip flop doesn't guarantee that a simultaneous rising edge on clock and /reset will cause the flip flop to clock in data, it may be necessary to use two flip flops and some xor gates to generate a really nice gated clock.
A two-flip-flop approach may be found here.
Provided that the sample/hold times for the flip flops are not violated, every clock pulse will either be passed through at its full width, or not passed through at all.
Answer: Most systems solve this by double-latching.
A positive-edge D flip-flop on each output of the shift register will take a snap-shot of each of the bits of the shift register when the enable line transitions from low to high.  It doesn't matter what shifting happens when the enable line is high, only what is left in there when it transitions from low to high.


Can a business offer a product pre-sale without specifying when the product will be delivered?

Question: For instance, if there were a product that takes a variable amount of time to mature, could a business take pre-sale orders (clearly marked as such) without giving the customer a deadline? If so, what keeps a business from tying up customer funds indefinitely without ever delivering?
Comment: Taking order and tying up funds are different things. Also, I believe taking orders by mail order (regulated by the US-FTC) for items not in stock is regulated differently than a live retail transaction. The answers should take each into account.
Answer: The answer, as with almost every question about U.S. law, depends on the jurisdiction you're dealing with.
In practice, though, most state and federal unfair trade practices (UTP) laws are based on one pretty basic question: is what the shipper is doing fair? These laws normally take the form of a long list of specifically prohibited practices, then a "catch-all" that basically says, if a reasonable person would think it's a scam, don't do it.
In general, if the risks are disclosed to the customer, and the seller is acting in good faith, the mere fact of a long lead time will probably not be in violation, although of course state laws will vary; some may require refunds under some circumstances. If there is inadequate disclosure, or the seller has no intention of selling anything, then it will almost certainly fall under the state UTP law.
In other words: if your unicorns only lay eggs every couple of blue moons, you can sell the rights to the next egg as long as you fully disclose this to the customer and, possibly, offer a refund option if your state requires it.
If you're selling the rights to your unicorn eggs but you don't actually have any unicorns, you will almost certainly be in trouble.
Mail order sales are a special case, governed by federal law. The FTC has a faq for non-lawyers on compliance with the law. But, again, all they require is that you are honest with your customers. There is a section specifically dealing with "dry-testing," basically, selling a product that is not yet available (and that won't be if not enoiugh people order it). Here's what they say:
In an advisory opinion, the FTC told a publishing company that it could "dry-test" its merchandise as long as the following conditions were met:

In promoting the merchandise, the merchant can make no suggestion that the merchandise will be shipped or that customers expressing an
  interest in it will receive it.
      In all promotional materials, the merchant must disclose all material aspects of the promotion, including the fact that the
  merchandise is only planned and may not be shipped.
      If any part of the promotion is later dropped, the merchant must notify subscribers of the fact within a reasonable time after
  soliciting their subscriptions.
      If, within a reasonable time after soliciting their subscriptions, the merchant has made no decision to ship the merchandise, it must
  notify subscribers of this fact and give them the opportunity to
  cancel and, where payment has been made, make a prompt refund.
      The merchant can make no substitutions of any merchandise for that ordered.


Doing an Interpolation through a list of lists into a single function

Question: Suppose I have a list of lists, i.e.
list = Table[{x, x^ k}, {k, 1, 10}, {x, 0, 1, 0.05}];

and I want to interpolate each of the lists by a function using Interpolation (or another appropriate function). Is there a way to create a function of k and x, i.e
Table[interpFunct[k] = Interpolation@list[[k]],{k,1,10}]

so I have interpFunct[1,x], interpFunct[2,x], etc. available?
I know I can interpolate the surface but the mesh is not structured, which leads to new difficulties that have nothing to do with my needs.
Any advice will be very helpfull.
Comment: You just need to tell it what to do with the second argument: `Table[interpFunct[k, x_] = Interpolation[list[[k]]][x], {k, 10}]`
Comment: @wxffles Crap, I knew my q. was kinda lame. Thanks a lot. Two things (lame as well): 1. Is there a way to define the domain of interpolation? 2. Even though it is a dumb question, I'll accept your comment as an answer.
Comment: Can I suggest to @wxffles to post and answer instead of a comment, no matter how "trivial"? It helps everybody 8^)
Answer: I'd normally use Scan[] for the purpose of building a bunch of functions, but the indexing makes the use of MapIndexed[] so tempting:
list = Table[{x, x^k}, {k, 1, 10}, {x, 0, 1, 0.05}];

MapIndexed[With[{k = First[#2]}, interpFunct[k] = Interpolation[#1]] &, list];

Plot[Table[interpFunct[k][x], {k, 10}] // Evaluate, {x, 0, 1}]

Comment: Thanks for taking the time to help. With all this new functions, I've a lot of reading to do!
Answer: As in the comments here's an answer, plus some variations:
Table[interpFunct[k, x_] = Interpolation[list[[k]]][x], {k, Length[list]}]

(interpFunct[#, x_] = Interpolation[list[[#]]][x]) & /@ Range[Length[list]]

Scan[(interpFunct[#, x_] = Interpolation[list[[#]]][x]) &, Range[Length[list]]]

MapIndexed[(interpFunct[#2[[1]], x_] = Interpolation[#1][x]) &, list]


Higher coding standards for dynamic languages?

Question: Due to the inherent risks associated with using dynamic languages (e.g. Python, Ruby) carelessly, what (if any) standards should be imposed on production code written in these languages?
Comment: It depends on the language. For example, in JavaScript you have JSLint and JSHint to validate the code and ensure that the language dynamic features don't break the code...
Answer: Your question contains two contradictory elements:

that someone would use the language carelessly, and
that they would follow standards for the production code.

Any programmer that is part of a team that has standards for production code should not use a language, dynamic or not, carelessly.  There is a lot of experience with writing code in dynamic language, starting with Lisp many, many years before Java was even thought of.
While non-dynamic languages can catch some errors at compile time, they would not catch mistakes like erroneous conversion from SI to English units, etc.   As far as I know (and I would love to be proven wrong...) there does not exist any study that has shown that using dynamic languages to write programs leads to more errors.
Many programmers writing on this, and other forums, express strong opinions one way or another but I suspect (no proof, sorry...) that there is a lot more variation in programmer's skills and proficiency in using good tests than there is coming from the use of language X over language Y.   (with the possible exception of Ada...)
Comment: It is quite a lot of work to make Ada catch erroneous physical unit conversion at compile time.  A type has to be explicitly defined to hold every possible combination of quantities that can arise: meters, kilogram-meters, kilogram-meters/second, etc.  It gets quite tedious.
Comment: Well, F# does have units as a first-class feature of the language.
Answer: Coding standards should be a simple as possible and hopefully restricted to avoiding language features and idioms which are known to be problematic or broken.
Too many rules in program standards can lead programmers to code sub-optimal and unreadable code because the best solution has been declared "bad" in the standards doc.
What dynamic languages really require are higher testing standards. As there are more run time errors possible, and, the forgiving nature of the languages means simple coding errors can cause weird behavior in seemingly unrelated components. You really need a good set of unit tests for every single component, plus a comprehensive set of integration tests which should be run every-time any piece of code has changed.
Comment: @ThomasX: Because, in strongly-typed languages, the compiler catches many errors at compile time that would otherwise be overlooked at run time, so you need additional testing to catch those cases in dynamic languages. Testing is the way you *verify* that your software is correct.
Comment: Why test when you can make software correct by design?
Answer: Not so much a coding standard as a good practice, I would say aggressive testing.
As you said, there are inherent risks with dynamic languages. Issues that would never even exist in a static language can and will crop up in poorly designed or written code in a dynamic language. Applying comprehensive, well-written unit tests as a part of your process will help ensure your code is correct and error free.
Answer: What "inherent risks" are you thinking of?  I can't think of any run-time error that can occur in Python or Ruby that can't occur in C# or Java.  Null pointer exceptions, missing method exceptions, and type conversion errors are all possible in C# and Java.  In Java, we add back all the missing dynamic behavior through Spring and other packages layered on reflection.  This enables all the run-time errors inherent in dynamically typed languages, except that to fix them you have to sift through seventeen layers of XML configuration files.
Connecting strongly typed languages to the untyped HTTP protocol, and the differently-typed SQL database in any reasonable way requires type conversions that cannot be validated at compile time.  I don't believe that dynamically typed languages require special care.  No matter the language, delivering reliable code will require extensive testing.
Comment: There is no way in Java you can confuse `double` with `String`. It is possible in Python.
Comment: @quant_dev. But for the most part python "does the right thing" when it sees a double in a string context. The "intelligent" syntax allows a given task to be done with less lines of code. Less lines of code = less bugs.
Comment: @jamesanderson If I mistakenly assign the string variable Name to the double variable Price, what exactly does Python intelligently do?
Comment: @quant_dev. You can: Double.parseDouble("some string");
Comment: @miraculixx That's not confusion, that's deliberate conversion.


How can I predict which way mortgage rates are moving?

Question: I've been thinking about refinancing my mortgage, but I'm not sure if I should wait a week or two for better rates, or lock in what they are offering today.  How can I make an educated guess?
Answer: Obviously you can't predict the future too much, but it's not too hard to figure out what is going to happen to mortgage rates in the short term.
Mortgage rates are heavily influenced by 10 year treasury yields.  You can find the daily 10 year rates here.  It's easy to see the direction they've been moving recently.  It usually takes a few days for mortgage rates to follow if the 10 year treasury yield is dropping (although if it's going up, mortgage rates will go up faster than they will fall).
Here's a sample of all the 10 year treasury yields for the past 10 years.

Looks like a good time to get a mortgage or refinance!
You can also take a look at movements in mortgage backed securities. Here you can find a chart for Fannie Mae 3.0% mortgages.

As the price goes up, mortgage rates go down.  Think of it this way. Right now people are will to pay $103 for $100 worth of 3.0% mortgages. That doesn't really make sense because I could just loan you $100 at 3.0% and turn around and sell it for $103 immediately, pocketing the $3 profit.  The reason is because right now, no one would willingly borrow money at 3.0%. Rates have fallen so much that if a bank has a customer paying them 3.0% on a mortgage, other people are willing to pay a premium on that mortgage. New mortgages are probably being written for 2.0%. (There is no current mortgage backed security for 2.0% fannie maes because rates have never been this low before).
Answer: Mortgage rates generally consist of two factors:

The price of money - that is, interest rates in the overall economy. (Your mortgage is essentially a purchase of money. You will pay interest on that money over time: that is the price of the money. The fact that you buy a house with the money is kind of incidental.)
A small, typically-competitive premium to cover the work that the bank does
An extra premium to cover the risk associated with making the loan (higher credit score, lower rate).

The risk premium is relatively constant for a particular individual / house combination, so most of the changes in your mortgage rate will be associated with changes in the price of money in the world economy at large.
Interest rates in the overall economy are usually tied to an interest rate called the Federal Funds rate. The Federal Reserve manipulates the federal funds rate by buying and/or selling bonds until the rate is something they like. So you can usually expect your interest rate to rise or fall depending on the policies of the Federal Reserve.
You can predict this in a couple of ways:

Financial institutions who worry about changes in interest rate affecting their businesses may trade options so that they can reduce their risk of interest rate shifts. From this you can determine what financial professionals think the Fed will do. The Fed will actually collect that information and present it to you in an easy-to-digest form:  http://www.clevelandfed.org/research/data/fedfunds/
As of this time, the charts are all very boring, but they have an orange line at y=1.0 labeled 0-0.25% - this implies that pretty much everyone expects rates to remain low through September.
The Federal Reserve will from time to time release information about its general plans for interest rates. This will be reported in various newspapers. You can also access information about their meetings at their monetary policy page: http://federalreserve.gov/monetarypolicy/default.htm

The way they have described their plans recently indicates that will keep interest rates low for an extended period of time - probably through 2014 or so - and they hope to keep inflation around 2%. Unless inflation is significantly more than 2% between now and then, they are extremely unlikely to change that plan.
As such, you should probably not expect mortgage interest rates in general to change more than infinitesimally small amounts until 2014ish. Worry more about your credit score.
Answer: If economic conditions are weakening, i.e. unemployment rising, business and consummer confidence dropping, etc., you can expect interest rates and thus mortgage rates to drop. If economic conditions are strengthening you can expect interest rates and thus mortgage rates to start rising.
As you are in the US, and with official interest rates there at 0.25% there is not much room for these rates to fall further. I am in Australia, with official interest rates at 3.75%, and with the economic weakness in the US and Europe and with China slowing down, we can expect our rates to fall further over the next year.
Regarding your timeframe of one to two weeks, unless there is a decision on rates in the US in the next week I don't think there would be much change, especially with rates there at record lows. You are probably best to shop around for the best rates now and refinance once you have found one you are happy with.
Comment: Well official rates here in Australia were just lowered to 3.50% today.
Comment: Your export market (Australia) is in much better health than the rest of the world (well far superior to the UK, not really hard is it :)). Highly dependant on China, I don't think you do a lot of trade with Europe though. Not in comparison. I think the rate change was down to China not performing as everyone had predicted.


What is nscf calculation in Quantum ESPRESSO?

Question: I have been using 'nscf' for DOS calculation since it is faster and therefore possible to use a higher kpoints. But why is it faster? why not use it in the place of 'scf'?
Answer: NSCF stands for non-self-consistent field calculation and, as explicit by its name, the calculation is not performed in a self-consistent fashion as the SCF (self-consistent field) one. The latter performs the solution trying to minimize the density charge functional until a predetermined limit in the energy difference between two consecutive steps. The convergence against the k-points mesh should also be achieved. Therefore the SCF calculation should be performed first to ensures the minimum Khom-Sham energy state that should resemble the system's ground state.
Calculations such as the Band structure, Density of States, and optical properties, in general, require a denser grid at the reciprocal space.  Thus the NSCF calculation should be performed after the SCF one, sampling the system to a denser mesh in the reciprocal space, allowing for the aforementioned calculations.
Comment: Imagine calculating a sine curve then needing additional accuracy.  You can either interpolate between points or calculate the missing points.  NSCF is basically the same as calculating the missing points.  It can effect the shape of the band structure some but its unlikely to change things dramatically.
Comment: In case of Quantum ESPRESSO, I believe Band structure calculation takes the structure will only take data generated from 'scf' so doing a 'nscf' calculation will no effect band structure does it?
Comment: So is it fine to use a high value for the k-point grid with SCF method to achieve the dense grid condition for the band structure/DOS calculations? The reason for asking this is that nscf calculations sometimes have convergence issues. [https://www.researchgate.net/post/Why-c-bands-2-eigenvalues-not-converged-message-appears-in-nscf-calculation-using-Quantum-Espresso]
Comment: It works, but the denser the mesh the higher the time. The convergence issues with the nscf method can be reduced by increasing the cutoff energies and/or reducing the convergence threshold.
Comment: Although a bit too late, I would like to ask how dense the grid should be for nscf calculation compared to the one for scf calculation? @AnibalBezerra
Comment: It all depends on the system. You can to increase the density and monitoring the convergence of the desirable property. Since nscf is cheaper, it should not be a problem to check for convergence.
Answer: The central goal of KS-DFT is solving Kohn-Sham equation:
$$H\psi_i(\vec{r})=\left( -\dfrac{\nabla^2}{2}+V_{ks}[\vec{r};\psi_i(\vec{r})] \right)\psi_i(\vec{r})=E_i\psi_i(\vec{r})$$
Here the atomic unit has been adopted. Note that the Kohn-Sham equation is a nonlinear differential equation and hence we need to solve it self-consistently. The workflow can be summarized as the following:

Once the self-consistent calculation is done then the converged charge density is obtained.

With this converged charge density at the previous self-consistent run, you can always construct the KS Hamiltonian once again and diagonalize it to obtain eigenvalues along the assigned K path in reciprocal space or calculate the density of states on a denser uniform k mesh. Note that you just read the converged charge density to construct the Hamiltonian without any update for the charge density, that's the meaning of NSCF.
Comment: By solving the KS equation, you can obtain orbital and energy at the same time.
Comment: Dear Jack, in the step when you say that the Kohn Sham equation is being solved, are you obtaining the energies from the orbitals you defined previously? Or are you obtaining the orbitals from values of the energies? I think I am missing something
Comment: Thank you, Jack!


POMDPs in robotics

Question: POMDPs are used when we cannot observe all the states.
However, I cannot figure out when these POMDPs can be useful in robotics. What is a good example of the use of POMDPs? (I have read one paper where they used them, but I didn't find it obvious why pomdps should be used) What would be good projects ideas based on POMDPs?
Comment: POMDP = partially observable Markov decision process?
Answer: A good rule of thumb is that where ever an MDP is useful in theory a POMDP would likely need to be used in reality.
To answer your question directly I would direct you to some of the latest work coming out of the Algorithmic Robotics Lab. My advisor and I recently developed a method wherein we use a POMDP at the core of a new grey-box system identification method. In this method we know an approximate kinematic or dynamic model of the robot in question. We do not however know some of the associated parameters (e.g. mass, center of mass). One way to learn the parameters is to use an extended Kalman filter (EKF) to monitor the system while the motor babbling. However more can be learned if the dynamics are excited correctly. To achieve this part we use a POMDP to plan controls. The details can be found in our paper Online Parameter Estimation via Real-time Replanning of Continuous Gaussian POMDPs.
Comment: The first sentence nailed it completely.  Robots in the real world are never quite able to get all the data they need about their environment, and you need to account for that.
Answer: Partially Observable MDPs actually are very interesting to robotics, and especially for the partially observable part. Sensor signals (laser, sonar, vision, ..) are noisy, some more then others depending on several variables. We cannot trust the sensor signal completely, but we can use them to estimate the real state. The POMDP can thus be used in robotics to do planning with noisy observations. A list of applications is shown by Cassandra [1], a more general overview of planning with uncertainty in robotics is given by Thrun et al. [2], and of course there are lots of examples on the web. The big problem of POMDPs is that finding their optimal solution is intractable (i.e it easily takes too long to compute), but there are several methods which approximate the optimal solution.
[1] Cassandra, A. R. (1997). A Survey of POMDP Applications. In Uncertainty in Artificial Intelligence (pp. 472–480). Retrieved from http://www.cassandra.org/pomdp/papers/applications.pdf.
[2] Thrun, S., Burgard, W., & Fox, D. (2005). Probabilistic Robotics (Intelligent Robotics and Autonomous Agents. The MIT Press.

POMDPs in robotics


What is the difference between the kernel space and the user space?

Question: What is the difference between the kernel space and the user space? Do kernel space, kernel threads, kernel processes and kernel stack mean the same thing? Also, why do we need this differentiation?
Comment: http://www.linfo.org/kernel_mode.html
Comment: https://unix.stackexchange.com/questions/87625/what-is-difference-between-user-space-and-kernel-space
Answer: The really simplified answer is that the kernel runs in kernel space, and normal programs run in user space. User space is basically a form of sand-boxing -- it restricts user programs so they can't mess with memory (and other resources) owned by other programs or by the OS kernel. This limits (but usually doesn't entirely eliminate) their ability to do bad things like crashing the machine.
The kernel is the core of the operating system. It normally has full access to all memory and machine hardware (and everything else on the machine). To keep the machine as stable as possible, you normally want only the most trusted, well-tested code to run in kernel mode/kernel space.
The stack is just another part of memory, so naturally it's segregated right along with the rest of memory.
Comment: @kc3: that's at least partly up to the OS, but I believe most have a kernel-mode stack for each process that's used when the kernel is doing things on behalf of a process (e.g., I/O) and at least one more kernel stack that's exclusively for internal use by the kernel (e.g., for scheduling).
Comment: SO say if I have like 10 processes in my system. Is it that each process has its own stack which is divided into a user stack and a kernel stack OR all the processes share a single kernel stack?
Comment: Is there existences of kernel processes and what's the relationship or differences with userspace processes as asked in question?
Comment: So per se, To run a __user space__ process, it must be mapped to __kernel space__?
Comment: @roottraveller: I'm not sure what gave you that idea, but no, not at all. At the same time, a user-space process *will* normally have some (more or less hidden) kernel-space memory, so (for example) your process will have a user-space stack, and a kernel-space stack that's used when you make OS calls that need to run in kernel mode.
Comment: Yes there are  kernel space processes. These are normally started at boot time or at the module load time. These are  kernel threads and are seen within [ ] when you list with ps -ax. These threads execute in the kernel space. That is they have access to kernel  resources and their scheduling is different. They can get higher priority than any user space process. Otherwise kernel space processes are similar to user space processes.
Answer: The Random Access Memory (RAM) can be logically divided into two distinct regions namely - the kernel space and the user space.(The Physical Addresses of the RAM are not actually divided only the Virtual Addresses, all this implemented by the MMU)
The kernel runs in the part of memory entitled to it. This part of memory cannot be accessed directly by the processes of the normal users, while the kernel can access all parts of the memory. To access some part of the kernel, the user processes have to use the predefined system calls i.e. open, read, write etc. Also, the C library functions like printf call the system call write in turn.
The system calls act as an interface between the user processes and the kernel processes. The access rights are placed on the kernel space in order to stop the users from messing with the kernel unknowingly.
So, when a system call occurs, a software interrupt is sent to the kernel. The CPU may hand over the control temporarily to the associated interrupt handler routine. The kernel process which was halted by the interrupt resumes after the interrupt handler routine finishes its job.
Comment: The first part of this answer is incorrect. RAM is not split into kernel and user space. *Virtual memory* is. I tried editing the answer but the edit que has been full for days. Please fix. Look at Varun's answer below for more information.
Comment: @problemofficer, I think, that a big simplification can provide a wrong basic understanding. Each should figure out that physical memory isn't divided into user space and kernel space, but the kernel provides an abstraction of virtual memory, that is divided into kernel and user space and later is mapped on a physical memory.
Comment: @MeLikeyCode Isn't that a justifiable simplification in the context of trying to provide a widely understandable answer?
Answer: CPU rings are the most clear distinction
In x86 protected mode, the CPU is always in one of 4 rings. The Linux kernel only uses 0 and 3:

0 for kernel
3 for users

This is the most hard and fast definition of kernel vs userland.
Why Linux does not use rings 1 and 2: CPU Privilege Rings: Why rings 1 and 2 aren't used?
How is the current ring determined?
The current ring is selected by a combination of:

global descriptor table: a in-memory table of GDT entries, and each entry has a field Privl which encodes the ring.
The LGDT instruction sets the address to the current descriptor table.
See also: http://wiki.osdev.org/Global_Descriptor_Table
the segment registers CS, DS, etc., which point to the index of an entry in the GDT.
For example, CS = 0 means the first entry of the GDT is currently active for the executing code.

What can each ring do?
The CPU chip is physically built so that:

ring 0 can do anything
ring 3 cannot run several instructions and write to several registers, most notably:

cannot change its own ring! Otherwise, it could set itself to ring 0 and rings would be useless.
In other words, cannot modify the current segment descriptor, which determines the current ring.
cannot modify the page tables: How does x86 paging work?
In other words, cannot modify the CR3 register, and paging itself prevents modification of the page tables.
This prevents one process from seeing the memory of other processes for security / ease of programming reasons.
cannot register interrupt handlers. Those are configured by writing to memory locations, which is also prevented by paging.
Handlers run in ring 0, and would break the security model.
In other words, cannot use the LGDT and LIDT instructions.
cannot do IO instructions like in and out, and thus have arbitrary hardware accesses.
Otherwise, for example, file permissions would be useless if any program could directly read from disk.
More precisely thanks to Michael Petch: it is actually possible for the OS to allow IO instructions on ring 3, this is actually controlled by the Task state segment.
What is not possible is for ring 3 to give itself permission to do so if it didn't have it in the first place.
Linux always disallows it. See also: Why doesn't Linux use the hardware context switch via the TSS?

How do programs and operating systems transition between rings?

when the CPU is turned on, it starts running the initial program in ring 0 (well kind of, but it is a good approximation). You can think this initial program as being the kernel (but it is normally a bootloader that then calls the kernel still in ring 0).
when a userland process wants the kernel to do something for it like write to a file, it uses an instruction that generates an interrupt such as int 0x80 or syscall to signal the kernel. x86-64 Linux syscall hello world example:
.data
hello_world:
    .ascii "hello world\n"
    hello_world_len = . - hello_world
.text
.global _start
_start:
    /* write */
    mov $1, %rax
    mov $1, %rdi
    mov $hello_world, %rsi
    mov $hello_world_len, %rdx
    syscall

    /* exit */
    mov $60, %rax
    mov $0, %rdi
    syscall

compile and run:
as -o hello_world.o hello_world.S
ld -o hello_world.out hello_world.o
./hello_world.out

GitHub upstream.
When this happens, the CPU calls an interrupt callback handler which the kernel registered at boot time. Here is a concrete baremetal example that registers a handler and uses it.
This handler runs in ring 0, which decides if the kernel will allow this action, do the action, and restart the userland program in ring 3. x86_64
when the exec system call is used (or when the kernel will start /init), the kernel prepares the registers and memory of the new userland process, then it jumps to the entry point and switches the CPU to ring 3
If the program tries to do something naughty like write to a forbidden register or memory address (because of paging), the CPU also calls some kernel callback handler in ring 0.
But since the userland was naughty, the kernel might kill the process this time, or give it a warning with a signal.
When the kernel boots, it setups a hardware clock with some fixed frequency, which generates interrupts periodically.
This hardware clock generates interrupts that run ring 0, and allow it to schedule which userland processes to wake up.
This way, scheduling can happen even if the processes are not making any system calls.

What is the point of having multiple rings?
There are two major advantages of separating kernel and userland:

it is easier to make programs as you are more certain one won't interfere with the other. E.g., one userland process does not have to worry about overwriting the memory of another program because of paging, nor about putting hardware in an invalid state for another process.
it is more secure. E.g. file permissions and memory separation could prevent a hacking app from reading your bank data. This supposes, of course, that you trust the kernel.

How to play around with it?
I've created a bare metal setup that should be a good way to manipulate rings directly: https://github.com/cirosantilli/x86-bare-metal-examples
I didn't have the patience to make a userland example unfortunately, but I did go as far as paging setup, so userland should be feasible. I'd love to see a pull request.
Alternatively, Linux kernel modules run in ring 0, so you can use them to try out privileged operations, e.g. read the control registers: How to access the control registers cr0,cr2,cr3 from a program? Getting segmentation fault
Here is a convenient QEMU + Buildroot setup to try it out without killing your host.
The downside of kernel modules is that other kthreads are running and could interfere with your experiments. But in theory you can take over all interrupt handlers with your kernel module and own the system, that would be an interesting project actually.
Negative rings
While negative rings are not actually referenced in the Intel manual, there are actually CPU modes which have further capabilities than ring 0 itself, and so are a good fit for the "negative ring" name.
One example is the hypervisor mode used in virtualization.
For further details see:

https://security.stackexchange.com/questions/129098/what-is-protection-ring-1
https://security.stackexchange.com/questions/216527/ring-3-exploits-and-existence-of-other-rings

ARM
In ARM, the rings are called Exception Levels instead, but the main ideas remain the same.
There exist 4 exception levels in ARMv8, commonly used as:

EL0: userland
EL1: kernel ("supervisor" in ARM terminology).
Entered with the svc instruction (SuperVisor Call), previously known as swi before unified assembly, which is the instruction used to make Linux system calls. Hello world ARMv8 example:
hello.S
.text
.global _start
_start:
    /* write */
    mov x0, 1
    ldr x1, =msg
    ldr x2, =len
    mov x8, 64
    svc 0

    /* exit */
    mov x0, 0
    mov x8, 93
    svc 0
msg:
    .ascii "hello syscall v8\n"
len = . - msg

GitHub upstream.
Test it out with QEMU on Ubuntu 16.04:
sudo apt-get install qemu-user gcc-arm-linux-gnueabihf
arm-linux-gnueabihf-as -o hello.o hello.S
arm-linux-gnueabihf-ld -o hello hello.o
qemu-arm hello

Here is a concrete baremetal example that registers an SVC handler and does an SVC call.
EL2: hypervisors, for example Xen.
Entered with the hvc instruction (HyperVisor Call).
A hypervisor is to an OS, what an OS is to userland.
For example, Xen allows you to run multiple OSes such as Linux or Windows on the same system at the same time, and it isolates the OSes from one another for security and ease of debug, just like Linux does for userland programs.
Hypervisors are a key part of today's cloud infrastructure: they allow multiple servers to run on a single hardware, keeping hardware usage always close to 100% and saving a lot of money.
AWS for example used Xen until 2017 when its move to KVM made the news.
EL3: yet another level. TODO example.
Entered with the smc instruction (Secure Mode Call)

The ARMv8 Architecture Reference Model DDI 0487C.a - Chapter D1 - The AArch64 System Level Programmer's Model - Figure D1-1 illustrates this beautifully:

The ARM situation changed a bit with the advent of ARMv8.1 Virtualization Host Extensions (VHE). This extension allows the kernel to run in EL2 efficiently:

VHE was created because in-Linux-kernel virtualization solutions such as KVM have gained ground over Xen (see e.g. AWS' move to KVM mentioned above), because most clients only need Linux VMs, and as you can imagine, being all in a single project, KVM is simpler and potentially more efficient than Xen. So now the host Linux kernel acts as the hypervisor in those cases.
Note how ARM, maybe due to the benefit of hindsight, has a better naming convention for the privilege levels than x86, without the need for negative levels: 0 being the lower and 3 highest. Higher levels tend to be created more often than lower ones.
The current EL can be queried with the MRS instruction: what is the current execution mode/exception level, etc?
ARM does not require all exception levels to be present to allow for implementations that don't need the feature to save chip area. ARMv8 "Exception levels" says:

An implementation might not include all of the Exception levels. All implementations must include EL0 and EL1.
  EL2 and EL3 are optional.

QEMU for example defaults to EL1, but EL2 and EL3 can be enabled with command line options: qemu-system-aarch64 entering el1 when emulating a53 power up
Code snippets tested on Ubuntu 18.10.
Answer: Kernel space & virtual space are concepts of virtual memory....it doesn't mean Ram(your actual memory) is divided into kernel & User space.
Each process is given virtual memory which is divided into kernel & user space.
So saying
"The random access memory (RAM) can be divided into two distinct regions namely - the kernel space and the user space." is wrong.
& regarding "kernel space vs user space" thing
When a  process is created and its virtual memory is divided into user-space and a kernel-space , where user space region contains data, code, stack, heap of the process & kernel-space contains things such as the page table for the process, kernel data structures  and kernel code etc.
To run kernel space code, control must shift to kernel mode(using 0x80 software interrupt for system calls) & kernel stack is basically shared among all processes currently executing in kernel space.
Comment: A common process has its own kernel space and user space?
Comment: @VictorChoy, a process executes into two modes: user and kernel. The memory, that the process sees is unique to it. But for every processes running in the kernel mode (executing kernel code) there is only one space - kernel space.
Comment: Also, notice, that when a process is created, it's virtual memory is divided into 2 parts (user and kernel), where some part of virtual addresses are reserved for user mode and another for kernel mode.
Answer: Kernel space and user space is the separation of the privileged operating system functions and the restricted user applications. The separation is necessary to prevent user applications from ransacking your computer. It would be a bad thing if any old user program could start writing random data to your hard drive or read memory from another user program's memory space.
User space programs cannot access system resources directly so access is handled on the program's behalf by the operating system kernel. The user space programs typically make such requests of the operating system through system calls.
Kernel threads, processes, stack do not mean the same thing. They are analogous constructs for kernel space as their counterparts in user space.
Answer: Each process has its own 4GB of virtual memory which maps to the physical memory through page tables. The virtual memory is mostly split in two parts: 3 GB for the use of the process and 1 GB for the use of the Kernel. Most of the variables you create lie in the first part of the address space. That part is called user space. The last part is where the kernel resides and is common for all the processes.  This is called Kernel space and most of this space is mapped to the starting locations of physical memory where the kernel image is loaded at boot time.
Comment: your answer is specific to Windows; you should clarify that.
Comment: You saying that for every process out of 4GB virtual memory, 1 GB is Kernel space which is same for every process and just holds mapping.. I cannot understand why!!, why 1GB is required just for mapping to starting location ?
Answer: The maximum size of address space depends on the length of the address register on the CPU.
On systems with 32-bit address registers, the maximum size of address space is 232 bytes, or 4 GiB.
Similarly, on 64-bit systems, 264 bytes can be addressed.
Such address space is called virtual memory or virtual address space. It is not actually related to physical RAM size.
On Linux platforms, virtual address space is divided into kernel space and user space.
An architecture-specific constant called task size limit, or TASK_SIZE, marks the position where the split occurs:

the address range from 0 up to TASK_SIZE-1 is allotted to user space;
the remainder from TASK_SIZE up to 232-1 (or 264-1) is allotted to kernel space.

On a particular 32-bit system for example, 3 GiB could be occupied for user space and 1 GiB for kernel space.
Each application/program in a Unix-like operating system is a process; each of those has a unique identifier called Process Identifier (or simply Process ID, i.e. PID). Linux provides two mechanisms for creating a process: 1. the fork() system call, or 2. the exec() call.
A kernel thread is a lightweight process and also a program under execution.
A single process may consist of several threads sharing the same data and resources but taking different paths through the program code. Linux provides a clone() system call to generate threads.
Example uses of kernel threads are: data synchronization of RAM, helping the scheduler to distribute processes among CPUs, etc.
Answer: Briefly : Kernel runs in Kernel Space, the kernel space has full access to all memory and resources, you can say the memory divide into two parts, part for kernel , and part for user own process, (user space) runs normal programs, user space cannot access directly to kernel space so it request from kernel to use resources. by syscall (predefined system call in glibc)
there is a statement that simplify the different "User Space is Just a test load for the Kernel " ...
To be very clear : processor architecture allow CPU to operate in two mode, Kernel Mode and User Mode, the Hardware instruction allow switching from one mode to the other.
memory can be marked as being part of user space or kernel space.
When CPU running in User Mode, the CPU can access only memory that is being in user space, while cpu attempts to access memory in Kernel space the result is a "hardware exception", when CPU running in Kernel mode, the CPU can access directly to both kernel space and user space ...
Answer: By Sunil Yadav, on Quora:

The Linux Kernel refers to everything that  runs in Kernel mode and is
  made up of several distinct layers.  At the  lowest layer, the Kernel
  interacts with the hardware via the HAL.  At the  middle level, the
  UNIX Kernel is divided into 4 distinct areas.  The first  of the four
  areas handles character devices, raw and cooked TTY and terminal
  handling.  The second area handles network device drivers, routing
  protocols  and sockets.  The third area handles disk device drivers,
  page and buffer  caches, file system, virtual memory, file naming and
  mapping.  The fourth  and last area handles process dispatching,
  scheduling, creation and  termination as well as signal handling.
  Above all this we have the top  layer of the Kernel which includes
  system calls, interrupts and traps.  This  level serves as the
  interface to each of the lower level functions.  A  programmer uses
  the various system calls and interrupts to interact with the  features
  of the operating system.
Answer: IN short kernel space is the portion of memory where linux kernel runs (top 1 GB virtual space in case of linux) and user space is the portion of memory where user application runs( bottom 3 GB of virtual memory in case of Linux. If you wanna know more the see the link given below :)
http://learnlinuxconcepts.blogspot.in/2014/02/kernel-space-and-user-space.html
Answer: The kernel space means a memory space can only be touched by kernel. On 32bit linux it is 1G(from 0xC0000000 to 0xffffffff as virtual memory address).Every process created by kernel is also a kernel thread, So for one process, there are two stacks: one stack in user space for this process and another in kernel space for kernel thread.
the kernel stack occupied 2 pages(8k in 32bit linux), include a task_struct(about 1k) and the real stack(about 7k). The latter is used to store some auto variables or function call params or function address in kernel functions. Here is the code(Processor.h (linux\include\asm-i386)):
#define THREAD_SIZE (2*PAGE_SIZE)
#define alloc_task_struct() ((struct task_struct *) __get_free_pages(GFP_KERNEL,1))
#define free_task_struct(p) free_pages((unsigned long) (p), 1)

__get_free_pages(GFP_KERNEL,1)) means alloc memory as 2^1=2 pages.
But the process stack is another thing, its address is just bellow 0xC0000000(32bit linux), the size of it can be quite bigger, used for the user space function calls.
So here is a question come for system call, it is running in kernel space but was called by process in user space, how does it work? Will linux put its params and function address in kernel stack or process stack? Linux's solution: all system call are triggered by software interruption INT 0x80.
Defined in entry.S (linux\arch\i386\kernel), here is some lines for example:
ENTRY(sys_call_table)
.long SYMBOL_NAME(sys_ni_syscall)   /* 0  -  old "setup()" system call*/
.long SYMBOL_NAME(sys_exit)
.long SYMBOL_NAME(sys_fork)
.long SYMBOL_NAME(sys_read)
.long SYMBOL_NAME(sys_write)
.long SYMBOL_NAME(sys_open)     /* 5 */
.long SYMBOL_NAME(sys_close)

Comment: The last question is very good you put forward. But just  software interruption INT 0x80 ,and then?   It is not a good explanation for me .  Could you explain in detail how the solution works for the question you put forward by yourself?
Answer: Kernel Space and User Space are logical spaces.
Most of the modern processors are designed to run in different privileged mode. x86 machines can run in 4 different privileged modes.

And a particular machine instruction can be executed when in/above particular privileged mode.
Because of this design you are giving a system protection or sand-boxing the execution environment.
Kernel is a piece of code, which manages your hardware and provide system abstraction. So it needs to have access for all the machine instruction. And it is most trusted piece of software. So i should be executed with the highest privilege. And Ring level 0 is the most privileged mode. So Ring Level 0 is also called as Kernel Mode.
User Application are piece of software which comes from any third party vendor, and you can't completely trust them. Someone with malicious intent can write a code to crash your system if he had complete access to all the machine instruction. So application should be provided with access to limited set of instructions. And Ring Level 3 is the least privileged mode. So all your application run in that mode. Hence that Ring Level 3 is also called User Mode.
Note: I am not getting Ring Levels 1 and 2. They are basically modes with intermediate privilege. So may be device driver code are executed with this privilege. AFAIK, linux uses only Ring Level 0 and 3 for kernel code execution and user application respectively.
So any operation happening in kernel mode can be considered as kernel space.
And any operation happening in user mode can be considered as user space.
Answer: Trying to give a very simplified explanation
Virtual Memory is divided into kernel space and the user space.
Kernel space is that area of virtual memory where kernel processes will run and user space is that area of virtual memory where user processes will be running.
This division is required for memory access protections.
Whenever a bootloader starts a kernel after loading it to a location in RAM, (on an ARM based controller typically)it needs to make sure that the controller is in supervisor mode with FIQ's and IRQ's disabled.
Answer: The correct answer is: There is no such thing as kernel space and user space. The processor instruction set has special permissions to set destructive things like the root of the page table map, or access hardware device memory, etc.
Kernel code has the highest level privileges, and user code the lowest. This prevents user code from crashing the system, modifying other programs, etc.
Generally kernel code is kept under a different memory map than user code (just as user spaces are kept in different memory maps than each other). This is where the "kernel space" and "user space" terms come from. But that is not a hard and fast rule. For example, since the x86 indirectly requires its interrupt/trap handlers to be mapped at all times, part (or some OSes all) of the kernel must be mapped into user space. Again, this does not mean that such code has user privileges.
Why is the kernel/user divide necessary? Some designers disagree that it is, in fact, necessary. Microkernel architecture is based on the idea that the highest privileged sections of code should be as small as possible, with all significant operations done in user privileged code. You would need to study why this might be a good idea, it is not a simple concept (and is famous for both having advantages and drawbacks).
Answer: This demarcation need architecture support there are some instructions that are accessed in privileged mode.
In pagetables we have access details if user process try to access address which lies in kernel address range then it will give privilege violation fault.
So to enter privileged mode it is required to run instruction like trap which change CPU mode to privilege and give access to instructions as well as memory regions
Answer: In Linux there are two space 1st is user space and another one is kernal space. user space consist of only user application which u want to run. as the kernal service there is process management, file management, signal handling, memory management, thread management, and so many services are present there. if u run the application from the user space that appliction interact with only kernal service. and that service is interact with device driver which is present between hardware and kernal.
      the main benefit of kernal space and user space seperation is  we can acchive a security by the virus.bcaz of all user application present in user space, and service is present in kernal space. thats why linux doesn,t affect from the virus.
Comment: Beside the fact that it is "kernel" not "kernal" your answer is not entirely correct. Modern viruses (and with modern I mean everything after Windows 98) don't interact with the "kernel service" at all, everything's done within the user space. The fact that Linux has not much viruses (there are of course viruses for Linux) is that it has a pretty good permission management and - the most important fact - the most Linux users aren't those: "omaigosh JustinBieber.NewSong.exe! I MUST hear it NAO!!!1111" users which click and install everything without any clue.
Comment: Also, Linux is not that much used as Windows - writing viruses for it would not cause as much damage as the authors of viruses want to achieve.

User space applications don't communicate with the kernel service, they call special functions provided by the kernel called syscalls.


No Disk Utility

Question: I get that you made it small, clean, and simple. But why would you not include a disk utility already incorporated? Or am I missing something?
Answer: You are right. It is missing by default, you aren't missing anything. But why its is not added has to be answered by the team. I am just a user.
Answer: I think you answered question yourself. It's simple, it's elementary, not everyone needs it out of the box.
Answer: Just add Gnome Disks from the app center.  Done.
It is an interesting question though.  Isn't GParted on the live disk?
Comment: I know how to get one. Just found it odd as every other system I have tried always has one. And I had to download granted but it's in the app store.

No Disk Utility


Unable to start a Wasp test chain on WSL

Question: While trying to deploy a wasp chain I am receiving the following timeout error:
wasp-cli chain deploy --committee=0 --quorum=1 --ch
ain=mychain --description="My chain"
creating new chain. Owner address: 1BsTvwN9jqFnF2t8....MbF3J1hza7. State controller: KsKvhbyBhHJQw....5uFcT51mLSsmBu8h, N = 1, T = 1
creating chain origin and init transaction 4GCMCGzzwUdzEVd1X1WB....GZYBwADUssw.. OK
sending committee record to nodes.. OK
activating chain ia4oztPgHCQJKyAy2zvVGsoFGQAyoxUhrrVCc6urEBGU.. FAILED: ActivateChainOnAccessNodes: #0: MultiCall: timeout

I have followed both wiki and the video tutorials but still facing the same issue.
I am running only 1 wasp node on WSL and receiving the following nodeconn warning:
2021-12-17T14:35:03+05:30       WARN    NodeConn        client/connection.go:56     can't connect with the server: dial tcp 127.0.0.1:5000: connect: connection refused

I am super new here and don't know how to resolve this error. Any help will be appreciated, please.
My environment setup:

Windows Subsystem for Linux (Ubuntu-20.04)
Go 1.16.4
wasp-cli.json

{
  "wallet": {
    "seed": "<<seed-value>>"
  },
  "goshimmer": {
    "api": "shimmer.chrysalis2.com:8080",
    "faucetpowtarget": -1
  },
  "wasp": {
    "0": {
      "api": "127.0.0.1:9090",
      "nanomsg": "127.0.0.1:5550",
      "peering": "127.0.0.1:4000"
    }
  }
}

Answer: Please use the goshimmer api as per the testnet endpoints, which should be https://api.goshimmer.sc.iota.org/.
Also, for now, you can use "faucetpowtarget": 21 instead.
Alternatively, if you can, setup everything locally for now. The testnet is highly experimental right now and might be down for upgrades or tests quite often.


Start spacemacs with specific layout open

Question: I have a custom layout, which I can open with SPC l o f. Is there a way to start Emacs with a flag that would automatically load it at startup? I tried this way: emacs --eval '(persp-switch "Asd")' but it yields an error: Wrong type argument: hash-table-p, nil. I've also tried with "Default" with the same result.
Answer: you can't switch perspectives until the according elisp code is loaded… and command-line evals are evaluated immediately, before anything else.  so don't do it as an eval in the cmd line, but do it as the last command in ~/.emacs.d/init.el.
Comment: …correction: as the last command in ~/.emacs.d/init.el.


Is Bank responsible for protecting me from fraud?

Question: I applied for a part time job on Indeed to be a "Secret Shopper for Walmart". I took the bait and was sent a check for 2k and given an assignment to buy iTune cards at two Walmart and do a customer service report. I was highly suspicious so I went to my bank and informed them of everything. The teller took it to her supervisor who called the other bank and came back to me saying it was good, go ahead and do your shopping. I asked when the funds would clear and they said it's in your account and accessible now. I asked what my limit was (1000) and then asked them to raise it as I again needed to shop for 2k and they made the change for only one day. I was defrauded and my bank says I am 100% responsible. My full-time job provided me with a one time legal consultation for free in which the lawyer said I have a 50-50 shot in small claims court to get my money back as I went to them as experts in fraud. I am looking for an opinions as to whether I should drop it or proceed to small claims court. I am clueless to the process but currently out 2k.
Comment: Please elaborate on (1) who employed you (and under what circumstances) to be "Secret Shopper"; (2) your statement that you were defrauded; and (3) *who* are "experts in fraud" (the bank or whoever advertised on Indeed). Proceedings in Small Claims court are pretty straight-forward, but maybe with additional context your chances for recovery might be better than 50-50.
Comment: https://money.stackexchange.com/questions/98957/is-my-bank-responsible-at-all-seeing-i-came-to-them-as-the-experts-because-i-sus
Comment: There is generally little downside (other then your time) going to a small claims court - I'd go for it.  Before doing that though, get as much supporting evidence as you can - eg bank notes on your file, and notes about who said what.    That they raised your limit the same day is a lot better then just here-say (and I expect the bank has recorded reasons related to why).   You should post which jurisdiction you are in as this is quite important.  For example, in New Zealand you might well be covered by the consumer guarantees act as you acted on a representation by the bank.
Answer: The law does generally hold the depositor liable for bad checks that they deposit, which includes the situation where a check is fraudulent. This is a frequent scam, where a forged check is presented and the victim is asked to buy something of value, and sent it to the scammers. (This is called the "secret shopper scam"). The bank making money available is not a guarantee that the check is legitimate.
The problem with suing the bank in small claims court is that there will be an important question of fact, namely exactly what the bank's agent said to you. It is unlikely that they actually said "The other bank has promised that this is a legitimate check which they will honor, so you can safely spend the money". More likely, they implied that there is such an account, that there are funds to cover the check, an so on. It's only weeks later after the dust has settled (the account-holder has notified their bank that the check was forged) that the bank can apply the higher-level forensic tools needed to determine that the check was bogus. It is not particularly reasonable that people have to know how long it can take to be sure that a check is legit, but that's the way it is. The judge might be sympathetic to your plight, given that your bank was not highly diligent in warning you about the possible risks, but these risks are widely advertised, so the judge might also find that "you should have known".
Comment: Thank you for your insight.  If I did decide to move forward and go to small claims court are you aware of any cases I should study first?  I am no legal beagle.


What Is the MATLAB `imreconstruct()` Useful For?

Question: Could some one tell reasons to use the MATLAB imreconstruct function when processing images? I already have studied the topic and what the function actually does to the image. However, I cannot figure what we would use it for. What output should we expect from calling doing this function?
Comment: It seems the user is not active any more.
Comment: Could you please review my answer?
Answer: It could be useful in the field of OCR as a pre processing step.
Think about badly scanned data.
You'd like to convert it into binary image.
So the first step would be applying some kind of thresholding.
Since no thresholding is perfect, There will be some "Holes" / "Gaps" within the text.
Closing those "Holes" / "Gaps" can be done using morphological operations.
See example here: StackOverlfow - Adaptive Thresholding - Implementation of the Minimum Error Thresholding Method.
Answer: Look at MathWorks - Technical Articles and Newsletters - Morphological Reconstruction and MATLAB Digest | Academic Edition - Morphological Reconstruction.
Some applications are scanned text document (OCR as mentioned previously), fluorescently stained cell nuclei, or galaxies in a far-infrared telescope image. It can be used for extract marked objects, find bright regions surrounded by dark pixels, detect or remove objects touching the image border, detect or fill in object holes, filter out spurious high or low points, and perform many other operations.


How does my bank knows my second and forth chars of my password

Question: I see that the new login mechanism used by some banks in UK and also used by visa debit authentication is to ask for three random characters from your password at login (for example second, ninth and forth) but this surely mean that the password is not hashed, right? Maybe encrypted at best...
This is very bad, right? Or is there a way to hash a password and still calculate these characters? I cannot think of anything...
Answer: This stems from the times people would still use phone banking and an operator was required to ask a password. To prevent the operator from knowing the complete password, he would only receive three characters of the password and their positions.
It's actually not necessarily a bad thing if implemented correctly. You are correct stating that the password is not hashed. This scheme is called a masked or partial password. Some banks use this and the idea behind it is that in the event a client has a keylogger installed on his system, you will never get the complete password. It prevents the user also from storing it in an autocomplete or autofill tool.
Most implementations actually relay the passwords to another service running in the backend (meaning you don't talk directly to the database but to a seperate webservice).
Personally I'm not a fan of these schemes if they are not implemented together with a second factor of authentication. They completely fail at addressing most other malware than keyloggers as well as most social engineering attacks.
Comment: Yeah, I don't think I'm a very big fan especially because if you do have a keylogger in you pc, from what I experienced, there is a big chance that after three user logins the hacker has the necessary data for the forth one...
Answer: From what I've seen, they usually ask for your username (or account ID) and password, then three characters from a second passphrase. This helps prevent a vast majority of non-targeted keyloggers and form-grabbers, as capturing one login will likely not get you enough information to log in a second time.
In terms of the security, there are a few ways this can work. The most secure common method is a Hardware Security Module (HSM), which is essentially a black-box device that allows limited operations to be performed on data within it, with both software and hardware security measures. The idea is that you can tell the HSM to set the user's passphrase, or verify three characters of it, but you can't ask it to tell you the whole passphrase.
Another option is to encrypt the passwords in a database which is accessible via an internal web service that emulates the write/verify functionality of the HSM. It's less secure, but has improved cost options, and can be more flexible if the bank has an internal development team.


Properties of moment generating function of random walk on unit sphere

Question: Question in brief
Let $a$ and $b$ be unit vectors in $\mathbb{R}^d$. Let $f$ be the $1-step$ transition function of a random walk on the $d$ dimensional unit sphere.
I am interested in evaluating $\mathrm{E}[\exp(a^T f(b))]$ and one of things I want to know is any transition function/distribution exist where this quantity can be computed in closed form? The transition function should not be "trivial" e.g. it should be dependent on the input and it should not be identity.
More Details
I will also love to know which papers/textbooks deal with this problem? If there is no way to get an exact form, then what methods have people used to study the behavior of $\mathrm{E}[\exp(a^Tf(b))]$ as a function of $a$ and $b$? Is it possible to compute this or approximate this when $f$ is a random orthonormal matrix from the Haar measure?
What I did
I tried to evaluate this quantity in two "simple" cases but both of them turned out to be intractable.
In the first case, I assumed $f$ to be a random householder reflection, so I assumed that the walk proceeded by first sampling a vector $x$ from $U_{S^{d-1}}$, i.e. the uniform distribution over $S^{d-1}$. Then $f = I - 2xx^T$. But finding the marginal of a single projection of $U_{S^{d-1}}$ is itself difficult, and I could not figure out the value of $\mathrm{E}[\exp( (a^Tx)(b^Tx))]$ which requires a joint distribution of two projections of $x$.
The second case I tried was with random givens rotations. I chose the indices $i,j$ uniformly randomly from the $\binom d2$ possible pairs and then chose the rotation angle $\theta$ from a distribution that was symmetric about $\pi$. But this formulation boils down to the following computation $\mathrm{E}_{\theta}[\exp(\alpha \cos(\theta) + \beta \sin(\theta))]$. I couldn't think of any distribution over $\theta$ such that this expression could be evaluated.
Answer: Just found out that $\int_0^{2\pi} \exp(\alpha \cos\theta  + \beta \sin\theta) = 2\pi I_0(\alpha^2 + \beta^2)$. So random givens rotations seem to be amenable to analysis.


Which PC software does live effects on video from a tethered camera?

Question: Which software for Windows/Mac/Linux allow me to connect a DSLR (any DSLR brand is fine) and see in realtime (and record) the result of passing the live video feed through a filter?
Answer: If software is all you're interested in, here are a few options:

Quartz Composer
Pixel Conduit
Resolume
VDMX
Arkaos
Modul8

Personally I've only tried Quartz. It's hugely powerful and free, but the learning curve can be quite steep. It's more of a node programming language for video graphics, that's what makes it so powerful.
Some downsides are that it's not actively developed anymore and that it only runs on OSX.
I'm excited to try Pixel Conduit soon. It seems to be an attempt at a modern version of quartz, and the free version seems pretty powerful.
If you want to record the video as well you might have to look at a separate program called Syphon.
I used a Blackmagic Intensity Extreme box to get the live video from our Sony XDCAMs into my Macbook Pro. I had to use Black Syphon to get the feed from the Blackmagic box and send it into Quartz for live processing.
UPDATE
I've been using Resolume to do exactly that. It works really well and is way more user friendly than Quartz. Though you can also use Quartz in it. Resolume also can record the video to an output file out of the box.
Pixel Conduit didn't seem to have gained much traction unfortunately. So I never used it in a production environment, I only played with it.
Answer: A great tool that I personally work with is vvvv. A very mighty visual programming toolkit somewhat comparable to Quartz Composer on Mac but available for Windows (only for Windows for now but future versions might be multi plattform according to the devs).
For getting started I highly recommend this cheat sheet http://vvvv.org/sites/default/files/uploads/dontpanic_45beta25_1_0.pdf
Nice thing is that you can capture video over USB with a few canon DSRLs and don't necessarily need an HDMI capture card.
While you can capture frame with the "Writer" node, usually you would utilize Fraps for capturing the renderer (which can be lossless or in h264)
Answer: There isn't any single package to do this for most cameras.  On Canon DSLRs for example, you need EOS Utility to interface with the camera's LivePreview, then need another piece of software to adapt the EOS Utility's feed in to a live video stream that can be operated on by the operating system (such as a Windows Media Capture stream).  Then you need a piece of software to actually apply effects in real time to such a stream.
Alternately, the higher quality/higher budget option is to use something like an HDMI capture device or better yet, an ATEM video mixer to provide hardware assisted capture and alteration of the stream.  This is much more reliable and higher quality since video is pretty intense to work on in real time and specialized hardware does the best job of dealing with it.


What are unified addition and differential addition in elliptic curve point arithmetic?

Question: A lot of papers use these terms but I do not find a proper explanation of them. Can somebody tell the meaning / difference / intuition / application and if possible with an example.
Answer: Unified addition means that the formula you use for adding two points doesn't depend on whether they are equal. Simplifying point addition in the Weierstrass form somewhat $s=(y_A-y_b)/(x_A-x_b)$ when $A\neq B$ - this is "Adding". Otherwise $s=(3x_A^2-p)/{2y_A}$ when doubling a point.
The implementation of these steps would normally involve different code paths and this can lead to problems as information about the private key is leaked if you can monitor the power consumption or timing to work out which path was taken even if you can't see the numbers involved. See section one of Barbosa & Page. Also, Bernstein ,on page 3 talks about a stronger but related property called "completeness".
Page 15 of the same Bernstein paper explains "differential additions". Another Bernstein quote is

Differential addition chains (also known as strong addition chains, Lucas chains, and Chebyshev chains) are addition chains in which every sum is already accompanied by a difference.

They are used to support fast addition on elliptic curves in the Edwards form.
Answer: Beware: This is the way I understand it from x25519 code, I have very little background in formal math, so apologies if I speak like a caveman.
The way i understood it is:

You know x coordinate of point P
You know x coordinate of point Q
You know x coordinate of point P-Q (which you obtained somehow, ie previous ladder step)
And only all of the above gives you answer to P+Q (which is the whole point)

Looking at x25519 montgomery ladder code, P and Q start as same point initially, but soon may differ depending on the further bits of the scalar. This works, because you know P-Q from previous rung (apparently), but you can't use this for explicit point addition alone, as you don't know P-Q in that case.
Note that all of this works X/Z -> x projection, but we can basically just think of z as "extended" part of the X input.


Combine multiple species trees

Question: I have five species trees run using starBeast and Beauti. Here is a link to the paper discussing both,
http://journals.plos.org/ploscompbiol/article/file?type=supplementary&id=info:doi/10.1371/journal.pcbi.1003537.s006
 Each of these trees has the same individuals, and each locus used (10 loci per tree) has individual models set to it. All the trees used a relaxed log clock normal. I would like to be able to combine these trees into one. I have attempted to find a way to do this within Densitree and starBeast, but to no avail. When all loci are run with all trees, the program simply dies, leading me to believe that running the trees together will all parameters is computationally impossible for my hardware. Is there a way to combine these trees?
Comment: I am not familiar with trees but what are these software that you use? Could you provide a link to see what are they capable? What is a "relaxed log clock normal"? Why don't you use all 30 loci to build a single tree by combining the individual models? What do you mean that is computationally impossible: how much time do you expect to take (with how many cpus?) ?
Answer: Although I've never tried it myself, I think what you need can be achieved through the LogCombiner program from the BEAST package -- assuming the species trees files are comparable (ran with same parameters, same species names, etc.) I am also assuming that you meant 'five species tree files', each file with the posterior sample of species trees.
However, I do believe you should try to run all loci within the same analysis, or at least do some prior check to see if the distributions between data sets are comparable. LogCombiner assumes independent runs from the same data.
I would also recommend taking a look (and following) the BEAST google group (which includes starBEAST discussions).

Combine multiple species trees


Why is FeCl3 covalent?

Question: There is an electronegativity difference of 1.2 between $\ce{Fe}$ and $\ce{Cl}$. Then why it is covalent?
Comment: Electronegativity alone can't tell you everything. For example, $\ce{MnO}$ is mostly ionic, while $\ce{Mn2O7}$ is markedly covalent.
Comment: Even from basic electronegativity difference you can tell it - 1,2 < 1,7 so why it  should be unusual according to you?
Answer: usually when metal is bonded to a non-metal, they are bonded together by ionic bond but this is not the only condition , the more important condition is the electronegativity that must be greater than 1.7 to be sure that the bond is ionic if not like in your example 1.2 then the bond will be polar covalent bond which means that the electronegativity difference is not enough for the electrons to be lost by iron and gained by chlorine but they are shared and shifted toward the chlorine atom as it has the greater electronegativity.

Why is FeCl3 covalent?


Global warming and winter temperatures

Question: What causes cold temperatures to move earlier than they usually move? Here in Buffalo the weather was 9 °C. However, everyone had winter coats and hats on. There was no snow, but it was very very cold. I have a feeling that the Great Lakes may have something to do with it.
Comment: 9 degrees celsius is "very very cold"?  It's really hard to tell what you are asking
Answer: The Great Lakes contribute to a huge thermal inertia, which will even out short-term temperature fluctuations, and delay the smoothed seasonal temperature peak. On the other hand, more sinuous looping of the jet stream  is likely to have a comparable, if not larger, effect upon the temperatures in Buffalo. The process is this: As global warming progresses there is a disproportionate warming towards the polar regions. This results in a reduced temperature gradient with respect to latitude. It is this gradient which is largely responsible for the jet stream intensity. As the jet stream weakens it becomes more sluggish and sinuous, resulting in regional hot and cold anomalies. If Buffalo happens to get caught in one of these jet stream loops, it is quite possible to have periods of anomalously low temperature, even though there is an overall North American warming. It is also possible for Buffalo to get caught in a negative loop, and hence experience anomalously hot temperatures.
Answer: I'm guessing you're talking about the cold-snap centered around October 2 and 3.  We got it here too in NYC.  It was surprisingly cold for 2 days for this time of year and it came on rather suddenly.
http://www.accuweather.com/en/us/buffalo-ny/14202/october-weather/349726
I don't remember, and haven't been able to find a weather report from 4 days ago, so the precise reason for that cold snap escapes me, but it hit a significant part of the North-East US and perhaps a bit more than that.
Generally when wind blows in from the North, we get cold air, so that's probably about what happened.  The great lakes probably kept Buffalo slightly warmer during that period, not colder cause the late water was probably warmer than the air temperature.
This article is somewhat related, though I'm not sure how well it applies to the dates I think you're talking about.

Global warming and winter temperatures


if my alternator was tested and functioning properly why does my battery and brake light keep coming on in a 08 Nissan Altima 3.5

Question: started my 08 Altima and put it in gear and it didn't have the power to go anywhere and then the car just died. bought a new battery and everything worked fine. now my battery and brake light on the dash keeps coming on. I tested the alternator last night and it seemed to be charging like it should. what is the problem?
Answer: I would get the alternator looked at by a professional. Just searching around on this site, there are a number of reported issues with the alternators on various Altima model years. Some appear to be mechanical failures, where presumably the charging system was ok but the pully failed, sometimes damaging the belt and/or other components.
It's also possible for the charging system to appear to be outputting good voltage at idle, but once there is significant current load on the system the alternator might fail to keep up with the demands of the system. This requires more than just a volt-meter to test.
The initial battery dying could itself be a symptom of a faulty charging system as well. And if that's the case, you would see similar behavior where things seemed "fixed" for a while when the new battery was installed, but as the alternator can't keep the battery charged, you'll again start to see more electrical symptoms over time.
Answer: as a quick check I would start the car and remove battery to check if car can sustain itself on just an alternator also check for voltage change.
It could be that you installed a new battery and while checking for voltage out from alternator you receieve battery voltage
Comment: Absolutely do not do this! This is a sure fire way to kill ECUs and other control modules. In some cases when you remove a large load or battery from a running alternator it can cause a spike reaching hundreds of volts. It is well documented and reasonably common, many people have killed ECUs jump starting vehicles because of the same reason


Is it planned to use SPIP as a basis CMS for CIVICRM?

Question: SPIP is a multilingual open-source CMS created in 2001, and a lot of non-profit use it as their website tool in France and other countries. Is it planned, or do you heard about some people willing to use civicrm together with SPIP ?
Many thanks in advance,
Cyril
Answer: From what I can see, it seems that SPIP is a CMS and not a CRM.  While there are no plans for native integration between CiviCRM and other CMSes beyond the four currently supported, many organizations still integrate CiviCRM with their existing CMS.  Simple integration options include remote profile submissions using snippets.  You can also use remoteform, which also works with contribution pages.
If you wanted a deeper integration, you could use CiviMRF, but that would take development work.
Comment: Thank you Jon.
Is there a place where I can understand why CiviCRM is built **over** a standard CMS such as Drupal or Wordpress, and how I could imagine to participate to the development of an integration with SPIP ?
Comment: @CyrilMarion The decision to integrate over a CMS was made back in the beginning, and I believe was mainly because a) it was a selling point to offer deeper integration, b) it meant not having to manage user sessions etc.  However, many people run CiviCRM "standalone" with just a barebones Drupal or WP install with no other plugins.  I believe the CiviCRM core team has ruled out supporting more CMSes because of the testing/maintenance overhead of supporting them.


How to create an offset polyline in arcpy?

Question: I am trying to create an offset polyline using arcpy, identical to the function in ArcObjects (constructoffset). After trying to access ArcObjects in arcpy, which I found difficult for those not well-versed in COM languages, and after much searching for functionality in the regular geoprocessing toolboxes, I discovered that this functionality seems to only exist in ArcObjects. There may be ways to program this functionality in arcpy using trig, but that seems really hard. Essentially, the product I'd like is an offset polyline that preserves all original geometry and curvature. Simply using a SearchCursor on the input and building a new feature class based on its geometry requires some algorithm I don't know. This is because without an algorithm based on slope, etc., a one-size-fits-all addition or subtraction will not preserve an offset shape for all slopes. Any help?
Comment: When you mean slope, do you mean that you have a PolyLineZ feature class with Z values at each vertex? And if so, how would offsetting the line affect the Z values? Wouldn't simply preserving them be what you want?
Comment: Also are your features in projected coordinates? If so you could simply add/subtract your offset to each vertex coordinate.
Comment: This doesn't work because if my offset is 5 meters, I would need to have that 5 meter offset extend from each line perpendicular from any point on the line, else a 5 meter x offset on a horizontal line just moves the whole line west 5 meters, as opposed to extending in the y-direction as well. Therefore, the offset calculation is more complex than that, and I think it's what the Buffer function does.
Answer: We came up with this technique at work that uses geoprocessing tools to do the job:
First off, make sure your line segs have unique IDs.

Buffer "FLAT" in each direction of the line, add a new field of the same name to each and give them a direction ("L","R").
Merge the buffers together.
Buffer the original line again, this time "FULL".
Convert the FULL buffer to lines (PolygonToLine: "IGNORE_NEIGHBORS"), then convert its vertices to points (FeatureVerticesToPoints: "BOTH_ENDS").
Buffer each point by a very small width (e.g. 0.1 m).
Split the lines by vertex (SplitLine).
Select by location to select all lines that intersect with the point buffers.
Delete these lines.
Dissolve ("SINGLE_PART") on the segment unique ID.
Spatial Join ("SHARE_A_LINE_SEGMENT_WITH") the new lines to the merged "LEFT" and "RIGHT" buffers to attribute them with direction.

Voila! Offset lines without ArcObjects.
Answer: Here is the code to do the same in arcpy
<code>import arcpy

tmpwrkspace = "C:/tempgdb/temp.gdb/"
fc_line = tmpwrkspace + "MultiLineLayer"

# Set some variables
tempFeatureClass = tmpwrkspace + "temp_pline"

#set the offset to +n or -n for direction
xOffset = 0.2
yOffset = 0.2

if arcpy.Exists(tempFeatureClass):
    arcpy.Delete_management(tempFeatureClass)

arcpy.CopyFeatures_management(fc_line, tempFeatureClass)

# Perform the move
with arcpy.da.UpdateCursor(tempFeatureClass, ["SHAPE@XY"]) as cursor:
    for row in cursor:
        cursor.updateRow([[row[0][0] + xOffset, row[0][1] + yOffset]])
</code>
Comment: this takes offset as a decimal degree. is there any to input offset distance in meters. lets say i want to take offset around 20 meters of Line ??
Comment: It depend on liner unit in projection system. If liner unit is meter then it will take meter.
Comment: isn't there any way to forcefully give desired unit into offset ?
Comment: check this [Linear unit](http://gis.stackexchange.com/a/3382/25696) and to change projection system [define projection](http://help.arcgis.com/EN/ArcGISDesktop/10.0/Help/index.html#//001700000077000000).
Comment: I can't get this to work, it offsets my entire feature class. Also I have a grid of lines (street centerlines) so I would assume the X and Y offset would vary based on the orientation of the line? also I have varied distances for each line, I have the values stored in an attribute field. I tried to pull those using a search cursor wiith the original layer with the updateCursor nested below.


Creating some fields for a taxonomy menu with the active trail CSS classes?

Question: I have a taxonomy vocabulary which I want to use to create some navigation on my site.
Terms:

Weather
Clothes
Calendar
Sports

I want to be able to pull these terms and put them in the  navigation of the site. However, I want to be able to rewrite the links that these terms go to, so that rather than going to the taxonomy terms default page they go to:
/topic/[insert_taxonomy_term_here]/step-2
This is because I have a view with the [name] of the taxonomy term using that term as a contextual filter.
I'm having no problem creating such a menu tree in Views, but when I grab the taxonomy terms, as a views field, they are output without the standard Drupal active trail css classes, so that I cannot style them to show them as active.
Is there a way therefore to create a taxonomy menu in a view where the fields output the Drupal active trail?
Answer: Silly me!! This is how you do it, without even thinking


Application of cryptographic hash functions which do not require collision resistance property

Question: I can not understand why collision resistance of a cryptographic hash function is not required for some applications. for example, if we store the trusted hash of a file or program, and later when we open the file and recalculate the hash and compare it to the trusted one, do we need it to be collision resistant?
Answer: The two cases for stored files/programs;

On your files/programs
In this case it is the secondary pre-image attack that is given an input $m$ and a hash value $h =Hash(m)$ find another input $\bar m$ such that $m \neq m'$ and $h = Hash(m')$. As long as the hash value $h$ is not under the control of the attackers, they need to find the second input. In this case, we don't need the collision attack that is

Collision attack is finding two inputs $a$ and $b$ with $a\neq b$ such that $Hash(a) = Hash(b)$. To have collision resistance, finding such a pair must not be lower than $\mathcal{O}(2^{n/2})$ for hash functions with $n$ bit output size for any probabilistic polynomial-time adversaries. The bound comes from the birthday attack on the hash functions.

If the attackers can control the hash value, it may be possible to use to their advantage. To prevent this we need to use a keyed hash like HMAC, KMAC.

Third-party files/programs
If you accept the files/programs from the third parties, the classic attack that uses collision of two or more files/programs works as in Luis Casillas's answer and addressed well in Squeamish Ossifrage answer with good, bad, and sneaky versions. Therefore a collision resistance is required. You can mitigate this with HMAC.

Collision resistance is not necessary all the time.

A good example is the HMAC  expanded as either keyed-hash message authentication code or hash-based message authentication code). HMAC is a PRF under the sole assumption that the compression function is a PRF [1] proved by Mihir Bellare in 2006. A PRF doesn't need to have collision resistance. And, usually, we instantiate the HMAC with good hash functions like HMAC-SHA256 or, HMAC-SHA3-256.

Another example is password hashing, although we don't use standard cryptographic hash functions since they are fast and not memory-hard functions - Scrypt, PBKDF2, or Argon2 is preferred -  they are still considered hash functions. In password hashing, the pre-image and secondary pre-image attacks are considered to be important. The collisions are not applicable in password hashing.
Comment: @John I've added the definition of the collision, too. As you can see, in the collision attack, the attackers can choose any hash value as they want to collide. If they cannot control the output, but they need to find one that matches, then they need to execute the secondary image attack on the hash function. If you use SHA256 then you will be fine since you will get 256-bit security. For your case, a don't see a reason  for the collision resistance since the hash is fixed.
Comment: Thank for your reply. let's focus on my example. let's say that the primary calculated hash is unchangeable. for this problem we just want to make sure that this app or file is not modified. under what scenarios we need collision resistance property. if it is an operating system app? or it same for all?
Comment: Thank you so much
Answer: You are right that not every application for a cryptographic hash function will need collision resistance. But on the other hand, you need to think of your example more critically in order to rule out the risk of such attack. Think of this scenario:

Eve crafts two program executables, $A$ and $B$, such that:

$A$ is benign;
$B$ is malicious;
The two files' hashes collide.

Eve gives $A$ to Alice.
Alice audits $A$, determines it's benign
Alice hashes $A$ and stores the digest securely so that Eve cannot modify it.
Alice stores $A$ at path $P$ in a shared volume that Eve can modify.

Alice reasons that even if Eve could modify the file stored at $P$, she can always detect it by checking against her secure copy of the digest for $A$.
But since Eve crafted $A$ and $B$ together she was able to pick them so that they collide. Eve just replaces the contents at $P$ with $B$, and when Alice accesses the path and checks the content against her copy of $A$'s digest, it checks out, runs the malicious executable, and gets pwned.
Turns out Alice would have benefited from collision resistance after all, which stops step #1 of this scenario.
Note that a lot of collision attacks have more or less this flavor, where they hinge on the fact that the bad guys get to craft both the "good" and the "bad" file as a colliding pair. I wager the reason you thought your scenario is secure is because you're implicitly assuming that the "good" file is authored by an honest party, and the bad guys must try to independently craft a file that hashes the same as it.
Comment: Hmm, I think I overread the _trusted_ here. Yes, this is the classic attack that one accepts files/programs from the 3rd parties then this executes well.