Hi, we are discussing secant method for capturing isolated root of a non-linear equation. In the last class, we have introduced the method and in this class, we will study the convergence theorem of the secant method. We have two assumptions on the convergence of the secant method. One is that the function f which defines our equation is a C 2 function. What is mean by a C 2 function?  This is what we meant by saying f is a C 2 function and also we have to assume that the root that we are going to capture denoted by R is a simple root of the non-linear equation f of x equal to 0. What it means? It means f dash of R should not be equal to 0. That is what we meant by saying that the root R is a simple root. Once if these two assumptions are satisfied by the function f, then we can say that there exists a delta such that for every x naught and x 1 in the neighborhood of R that is the delta neighborhood of R, we can say that the secant method iterative sequence is well defined and the second thing is that we can say that the sequence belongs to the interval R minus delta to R plus delta. That is the delta neighborhood from where we have taken our initial guesses and the third one which is what we are mostly interested in is that the sequence x n will converge to R as n tends to infinity and finally, the conclusion is also that the order of convergence of the secant method is something approximately 1.62. That is what we meant by saying that limit n tends to infinity mod x n plus 1 minus R divided by x n minus R to the power of alpha is equal to some constant. Remember f dash of R is not equal to 0. Therefore, this is some constant non-negative constant. So, if you recall what is mean by the order of convergence, we say that a sequence converges with order at least alpha if there exist a constant such that x n plus 1 minus R is less than or equal to the constant times x n minus R to the power of alpha. Another way of defining order is limit n tends to infinity mod x n plus 1 minus R divided by mod x n minus R to the power of alpha is equal to some constant. So, this is what the condition that we are putting here and that says that the secant method is going to converge with order alpha and in fact, in our derivation we will also get the value of alpha as root 5 plus 1 by 2 which is approximately equal to 1.62. That shows that the secant method has a super linear convergence. In fact, bisection method has a linear convergence. In that way you can see that secant method is slightly faster than bisection method. Of course bisection method has its own disadvantage also that it is a bracketing method. Whereas, secant method is a open domain method. Therefore, the initial guesses can be chosen arbitrarily in secant method. This is a very good advantage of secant method. In addition to that it is also nice to see that secant method has super linear convergence. Let us try to prove this theorem. If you are not very good at calculus maybe in the first go you can omit this proof. However, I will strongly recommend you to go through the proof of this theorem very carefully because the techniques that are used in proving this theorem is very important for you to do any convergence analysis on a iterative method especially iterative method for non-linear equations. Therefore, it is very important for you to understand the proof of this theorem at least once. With this note let us go into the proof of this theorem. As a first step let us claim that for every n equal to 2, 3 and so on we can find a zeta n and a xi n such that this expression holds. That is x n plus 1 minus r into f dash of xi n is equal to x n minus 1 minus r into x n minus r by 2 into f double dash of zeta n. This expression will be used in arriving at all the conclusions that we have listed in this statement of the theorem. Therefore, first deriving this expression is very important for us. Let us see how to derive this. Note that to derive this we have to also assume that x n is not equal to x n minus 1 and both are not equal to r. Now, let us start our derivation with the formula of the secant method. Recall that the secant method is given by this expression and this expression can be rewritten like this. You can easily see this. Now, what I will do is in this expression I will replace x n plus 1 by x and then I will define this expression that is the left hand side expression as a function denoted by g of x. Now, you can see that if you plug in x equal to x n plus 1 then clearly this is equal to 0 because that is the way we have defined the function g. Therefore, g has a root which is x n plus 1. So, let us keep this in mind and go ahead also see that g is a linear polynomial. So, it depends on x with degree 1. So, these are the two observations that is g is a linear polynomial and g has the root x equal to x n plus 1 with these two properties in mind let us go to define a function psi as f of t minus g of t. Remember psi is a function of t where we have fixed x n minus 1 and that is not equal to x n. Of course, both of these are not equal to r and now we are also fixing x in such a way that x is not equal to any of these two numbers and then defining psi as a function of t. Therefore, x is fixed as for us this expression is concerned that you keep in mind and how psi of t is defined psi of t is defined with this expression and now let us see some important properties of the function psi. First thing is psi is a c 2 function why it is so because f is a c 2 function this is what we have assumed in our theorem and g is a linear polynomial and also you can see that this third term involves a quadratic term. Therefore, psi is a c 2 function very clearly also you can check that psi of t equal to 0 that is this equation psi of t equal to 0 has three distinct roots what are they one is t equal to x is a root of this equation t equal to x n minus 1 is a root of this equation and t equal to x n is a root of this equation they all are distinct because we have chosen x not equal to x n minus 1 and that is not equal to x n. Now, apply rolls theorem what rolls theorem says if you have a function which has three roots something like this then its derivative that is psi dash of t equal to 0 will have at least two roots distinct roots that is what rolls theorem says because you have three distinct roots for psi. Therefore, in between these two if you apply rolls theorem you will see that there exist at least one point at which psi dash of t equal to 0 and similarly in between these two points you can find at least one point at which psi dash vanishes. So, rolls theorem says that there exist at least two points at which psi dash vanishes. Now, psi dash is something like this at least two points psi 1 and psi 2 at which psi dash vanishes. Now, again apply rolls theorem on psi dash to see that there exist at least one point say eta at which psi double dash vanishes that is what the rolls theorem when applied to psi dash will give us. So, again applying rolls theorem on psi dash we can get a zeta n such that psi double dash of zeta n equal to 0 that is what the rolls theorem says. Now, we got zeta n now what are we going to do with this let us see well we got the zeta n let us compute psi double dash from its expression and plug in zeta n and see what is happening you can see that psi double dash is equal to f double dash right and g double dash that is equal to 0 because g is a linear polynomial. Therefore, second derivative of g is 0 and remember this is a constant because x is not a variable for us as far as this expression is concerned right therefore, this is a constant. So, do not differentiate it because we are differentiating with respect to t not with respect to x and what will happen to this term this term will simply give you two if you differentiate it twice right. Therefore, we have psi double dash of t is equal to f double dash of t minus this expression times 2 right. Now, from there what you can write is f of x minus g of x that is this term is equal to 1 by 2 2 is going to the other side right into this term is also going to the other side after shifting this to the left hand side right. Therefore, we will get f of x minus g of x is equal to 1 by 2 into x minus x n minus 1 into x x minus x n into f double dash of zeta n. What I am doing I am just plugging in t is equal to zeta n and then doing this simple manipulation to get this expression right. Now, let us see how to go ahead I will put x equal to r in this expression remember I have chosen x not equal to x n minus 1 and not equal to x n already these two are chosen such that this is not equal to r. Therefore, I may choose my x equal to r right that is not a problem for me now when I choose x equal to r in this expression you can see that this will go to 0 because f of r equal to 0 right. So, the first term will go off and you will have minus g of r is equal to 1 by 2 into instead of x I am putting r here right that is what I got here. Now, let us see how it goes if you recall we have defined our g such that g of x n plus 1 equal to 0 this is how we have defined g in our first step. Therefore, I can as well write this expression as g of x n plus 1 minus this equal to this because this is just going to contribute 0 here. Therefore, no problem I can write like this and now what happens I got this expression where g is 0 keep in mind. Now, what I will do is I will put mean value theorem for this expression because x n plus 1 is not equal to r that is our assumption as well. Therefore, you can put the mean value theorem and get x n plus 1 minus r into g dash of xi there exist a xi between x n plus 1 and r such that the left hand side can be written like this that is what the mean value theorem and that is equal to I am just keeping the right hand side as it is well we got this expression now. Now, we will also see that g dash of xi is equal to this how will you get that well you directly differentiate the expression g that we have taken in the first slide that is this one differentiate with respect to x and put x equal to xi here. You will see that this is 0 because this is a constant. So, when you differentiate with respect to x this will be 0 and you will be left out with this term only that is what I am writing g dash of xi equal to f of x n minus f of x n minus 1 divided by x n minus x n minus 1. Now, you apply the mean value theorem for this term you can see that there exist a xi n between x n and x n minus 1 such that this is equal to f dash of xi n into x n minus x n minus 1 right this numerator equal to this therefore, x n minus x n minus 1 will get cancelled and you will have g dash of xi equal to f dash of xi n. Now, you put this term into the expression that you got here you will see that x n plus 1 that is this term. Now, instead of g xi you are putting f dash of xi n and the right hand side is kept as it is. So, this is what we wanted to derive right. So, our first part of the proof is over we have derived a expression remember this expression is basically coming from the secant method formula. How we have taken the secant method formula from there we have defined g and through that we have derived this expression therefore, the secant method formula gives us a sequence right that sequence will surely satisfy this expression for some zeta n and xi n that is what we have seen. Now, remember r is a simple root of our equation and f dash is continuous it means what you have a function f say its graph is like this and r is the root of the equation f of x equal to 0 right this is the graph of the function f of x and we know that f dash of r is not equal to 0 right since f dash is continuous by intermediate value theorem you can see that in a small neighborhood of r f dash will remind non 0 that is what the intermediate value theorem tells us that is what we are writing here you can find a small neighborhood of r say r minus delta naught to r plus delta naught in which the function f dash will remind non 0. Remember in the statement of our theorem we have to find a delta neighborhood of r right you remember we have to find a delta neighborhood of r in which if you start your iteration that is if you choose your x naught and x 1 in that delta neighborhood then all these conclusions will hold. Therefore, our aim is to find such a delta that is what we are trying to do now. So, the intermediate value theorem and the assumption that r is a simple root will give us a delta, but remember this is not the delta that we want something which is lesser than this. So, we have to choose some other delta suitably which is less than this delta such that all our conclusion should hold. Now the question is how to choose this delta that is the question let us see how are we going to get this delta let us have some notation here I am just assuming that I got a delta and then I am just defining the notation that is all. This is not something which I am deriving or something it is just a notation I am fixing small m means the minimum of f dash over the delta neighborhood that I am supposed to get now. So, delta is yet to be found, but whenever there is a m it means I am just taking the minimum of f dash in that neighborhood and similarly capital M is the maximum of f double dash. Now let us see how are we going to choose our delta this is where precisely I am going to choose my delta I will choose my delta in such a way that whenever I choose x naught and x 1 in that neighborhood such that x naught and x 1 are not equal to r then the maximum of this term should be less than 1. So, this is how I am going to choose my delta. Now if I choose my delta in such a way then what happens let us see recall we have already derived this expression just as the first part of our proof. Now I am going to use this expression how am I going to use this expression well I will take n equal to 1 in this expression then you can see that mod x 2 because I took n equal to 1 and I took the modulus and that is actually going to be less than or equal to this term why it is so you can see that this is less than or equal to norm x 2 minus r into minimum of f dash what is minimum of f dash minimum of f dash is denoted by m here and similarly I will take the modulus on the right hand side and that is going to be less than or equal to I will replace this by the maximum. Therefore, I will have m by 2 into mod x 1 minus r that is this term and mod x naught minus r that is this term because I have taken n is equal to 1. Therefore, we have this inequality by taking n equal to 1 and now what happens let us see this term is less than epsilon right because epsilon is taken as the maximum of these two. Therefore, this term is something less than epsilon and the other term is surely less than or equal to delta why because x 1 is chosen from the delta neighbor root therefore, mod x 1 minus r is less than or equal to delta. Therefore, this whole quantity is less than or equal to epsilon into delta and remember epsilon is less than 1 that is the way I have chosen my delta right. So, therefore, with that delta my epsilon is less than 1 therefore, this is less than delta and now what does this mean? This means that x 2 belongs to the delta neighbor root of r right that is what it means by saying that x 2 minus r is less than or equal to delta or may be less than delta means it is a open interval that is not important here x 2 lies in this delta neighbor root that is more important and similarly from here you can show that x n also belongs to this delta neighbor root for each n. So, if you go back you can see that this is what we wanted to show as one of the conclusions that the whole sequence belongs to the delta neighbor root remember this delta is chosen such that f dash of xi is not equal to 0 for all xi is not equal to 0. So, f dash of xi in this neighbor root r minus delta to r plus delta right this is how we have chosen delta. So, you keep that in mind you can see that f dash is not equal to 0 in this interval and therefore, f dash is either positive or negative in this neighbor root right it means f is a strictly monotonic function. If f is strictly monotonic then it has this situation where x n minus 1 is not equal to f of x n right because the second conclusion says that all x n belongs to this neighbor root and since all this x n are belonging to this neighbor root f dash will not vanish at x n's it means f of x n minus 1 will not be equal to f of x n because f will be a monotonic function. So, therefore, this conclusion is also done now we have to prove the convergence and this order of convergence also. Let us see how to prove this. So, we have already discussed this let us go to prove the convergence first you observe that mod x 2 minus r is less than or equal to we have already shown here mod x 2 minus r is less than or equal to this quantity.  Therefore, this term is less than or equal to epsilon square now take x 3 mod x 3 minus r is nothing, but m by 2 m into x 1 minus r into x 2 minus r and then you multiply both sides by 1 m divided by 2 small m and that will give you epsilon this is less than or equal to epsilon and this is less than or equal to epsilon square how we have just now proved here. Therefore, this entire term is less than or equal to epsilon cube similarly, you can see that m by 2 small m of mod x 4 minus r is less than equal to epsilon 5 and so on.  Now, you take m divided by 2 m into mod x 1 minus r which is less than or equal to epsilon 1 therefore, q 2 is also 1. Now, q 3 from here you can see that q 3 is equal to 2 which can be seen as the sum of these two terms now what is q 4 q 4 is coming from here q 4 is equal to 3 that can be seen as the sum of these two terms here and what is q 5 q 5 is equal to 5 that can be seen as the sum of these two terms in general q n plus 1 is seen as the sum of its immediate previous term that is q n plus the previous to previous term that is q n minus 1 with the understanding that q naught is equal to 1 maybe I should start with 0 here 1 2 3 4 and so on sorry therefore, q naught is 1 q 1 is 1 and q 2 onwards we are defining like this. What is this sequence this is the well known Fibonacci sequence right and once you realize that you have a Fibonacci sequence as the power of epsilon now you recall that Fibonacci sequence tends to infinity as n tends to infinity also recall that we have chosen our delta in such a way that epsilon is less than 1 therefore, you have epsilon to the power of something and that is going to infinity as n tends to infinity that implies that the right hand side goes to 0 as n tends to infinity and what is on the left hand side you have constant times this term this is fixed therefore, you can in fact push it to the right hand side and therefore, you can see that this term goes to 0 as n tends to infinity that is precisely what we want as the convergence. Now all reminds is to get the order of convergence get the order of convergence how are we going to get the order of convergence let us see again I will recall what is the definition of order of convergence I have already told this at the beginning of the lecture the definition of the order of convergence is that there should exist a constant c such that mod x n plus 1 minus r is less than equal to c times mod x n minus r to the power of alpha then we say that the sequence converges with order at least alpha that is what we have seen and that should happen as n tends to infinity. Another way to define order of convergence is to use the following definition called asymptotic order of convergence this says that limit n tends to infinity this term should be constant right this both are often used for defining order of convergence let us try to derive or find the constant c such that this happens with an appropriate alpha let us see both of this again you start with the expression that we have derived at the beginning of the proof and then you just take this f dash on the other side with the understanding that f dash never vanishes in the neighborhood that we are working with right remember we are working with r minus delta to r plus delta this is the neighborhood in which we are working all our x n belongs to this neighborhood therefore, xi n which lies between x n and x n minus 1 and also between r in whatever it is it belongs to this interval therefore, f dash of xi n will not vanish right therefore, you can just divide both sides by f dash of xi n and that gives you this expression now take modulus on both sides and divide by mod x n minus r to the power of alpha we have to find what is alpha, but just take alpha and divide both sides you can see when you take modulus you are taking modulus here and also here since you are dividing both sides by x n minus r to the power of alpha you will have x n minus r to the power of 1 minus alpha right where alpha has to be chosen appropriately. So, we have this expression now what we will do is we will write this term in this form I am just rewriting it with an appropriate beta that is all if that is so then what should be our beta you can see that beta should satisfy that beta should be equal to 1 minus alpha why because x n minus r to the power of beta will come and that should be equal to 1 minus alpha from this expression therefore, we want beta to be 1 minus alpha and in the denominator we have alpha into beta that when you compare with this term you want alpha into beta to be minus 1 right now you just have to find alpha such that these two things happen simultaneously that implies that alpha should come as the root of this equation why because alpha should be equal to minus 1 by beta or beta equal to minus 1 by alpha that value of beta you can put here to get this equation. Therefore, the alpha that we want should come as the root of this quadratic equation remember this quadratic equation has two roots and one root is given like this and the other root of this quadratic equation is a negative number we are concerned about the order of convergence therefore, we will not choose the negative value of the alpha. So, we will choose this alpha and this number will surely satisfy this expression which is precisely satisfied by the secant method right because the expression that we have derived if you recall we started with this expression and this expression is derived from the secant method and from this expression only we have landed up with this and further rewritten that expression in this form and that is further written like this therefore, everything is coming from the secant method and the alpha is therefore, chosen very naturally from the secant method and that shows that the secant method if it converges will converge with order alpha and what is this value this value is approximately 1.618 all reminds is to now find the constant c right how will you find it recall that xi n will converge to r and also zeta n will converge to r how can you see you can see it from the sandwich theorem because how we have chosen xi n and zeta n well xi n and zeta n both lies between x n and x n minus 1 right. But we know that x n converges to r that we have already shown and also x n minus converges to r right and these two numbers always lie between these two numbers therefore, they will also converge to r as n tends to infinity that is what is very clear from the sandwich theorem. Now you take the limit n tends to infinity in this expression you can see that this is equal to f double dash of r divided by 2 into f dash of r now putting that into your expression because you are taking limit as n tends to infinity it will become like this into this term remember we had beta here, but beta is equal to minus 1 by alpha that is what I am putting here and therefore, we want the constant c such that see remember you want the whole thing to be equal to some constant right and that constant should be such that you have c which is this one this should be equal to c therefore, c is equal to this term and this is nothing, but this right this to the power of minus 1 by alpha therefore, we want the constant c such that c equal to this term into c to the power of minus 1 by alpha that will immediately give us what is c, c is given by this this is precisely what we wanted to show in the statement of our theorem well this is little long, but very interesting and important for us to understand with this I will end this lecture thank you for your attention.


Rwy'n meddwl i'r next item of business, which is a member's debate on the part of Emma Harper on 100 years of insulin. I would ask those members who are wishing to speak in the debate to press their request to speak buttons now. I call on Emma Harper up to seven minutes, please. I welcome the opportunity to bring this 100 years of insulin debate to chamber this evening, and I thank all colleagues who have supported it. Thanks to Diabetes Scotland for the briefing ahead of this debate, and I want to thank them for the amazing work that they do to continually support people living with diabetes, especially during this Covid pandemic. People with diabetes have exposed to Covid are at a higher risk of severe illness, hospitalisation and even death. Figures released early in the pandemic showed that 20 per cent of Covid-related deaths were people who had diabetes. Insulin is life-saving for all persons diagnosed with type 1 diabetes. Insulin is a hormone excreted by the pancreas directly into the bloodstream so that glucose can move from the blood circulation into the cells of our body. Insulin is vital for metabolism and vital for survival. Type 1 diabetes occurs when the beta cells in the pancreas fail and the pancreas is unable to produce any insulin at all. I am one of those people with type 1 diabetes, and therefore note this for the record. My two sisters and my mum also have type 1, but that is a whole other story. This year is 100 years since the discovery of insulin. It is one of the most significant advances in the history of medicine. Insulin was discovered in April 1921. Frederick Banting, Charles Best and Scotsman John James Rickard Macleod isolated insulin from the pancreatic islets of dogs. Initially, James Collop assisted with purified cattle insulin so that it could be administered to human patients with type 1. Before 1921, it was extremely rare for people with type 1 diabetes to live more than a year or two. In 1921 injection was the only delivery method for insulin, and in 2021 it still is. My mum sterilised and reused a small glass syringe and sterile needles in boiling water from a wee sister when Buffy was diagnosed at nine years old in 1977. It worked, but it was not the most practical. By the time I was diagnosed in 79, plastic syringes were supposed to be one time use were available—less pain and easier to use. Scotland has played its part in supporting the development of technology to treat diabetes. As well as Scotsman John Macleod, my motion mentions Dr Sheila Reith, consultant at Southern General in Glasgow. Her daughter had type 1, and Dr Reith had the idea for a more portable insulin cartridge, pen-like delivery device. Dr Reith worked with a colleague at Dr Ireland in the late 70s, and the Penject device, as it was called then, was subsequently created. Insulin pen delivery devices have evolved and are still used today as part of multi-dose therapy for type 1s and type 2s. So 100 years on from the discovery of insulin, where are we now? Well, insulin is still the safest method of reducing blood glucose levels, and things have improved significantly. Technology advancements, such as insulin pumps, closed-loop systems, basically an external pancreas, and digital blood glucose monitoring devices, buttons in our arms—they are helping people to live better with less complications, and today, green is good for me. Apologies for the prop, Presiding Officer. Diabetes complications pose a huge cost burden on the NHS. In Scotland, the advancements have been so good with the pumps and everything, so we can reduce complications that have a huge cost burden, such as that. In Scotland, there are 312,000 people with diabetes, and the rates of diabetes are 80 per cent higher in the most deprived communities. Type 2 diabetes is a health inequality issue. Estimates are that £1 billion is spent in Scottish NHS on diabetes—that is 10 per cent of the budget. Avoiding complications will help benefit the people with diabetes and also benefit our NHS. Managing type 1 is a complex issue. A 2014 Stanford study found that people living with type 1 make an extra 180 decisions each day than someone who is not diabetic. That is one extra decision every five minutes while awake. Decisions like what is my glucose level now, how many carbs are on my plate, are the fast carbs or slow carbs, should I eat now, should I wait for two hours, what happens when I am driving home, I do not want to go hypoglycemic, should my programme, my pump, deliver in so slowly or quickly, do I have replacement supplies in my car, in my home, in my office, in case the pump canula gets pulled out. Having diabetes is not a piece of cake, presiding officer. It is complicated. We have amazing support from our NHS staff, our endocrinologists, our dieticians, specialist nurses and healthcare support workers. They are fantastic in supporting patients and I thank them for their work. There is a lot in the Scottish Government's refresh of the diabetes improvement plan, which I welcome, including continued collaboration with third sector and stakeholders. I would like to bring attention to the minister, the work of brothers Anthony and Ian Whittingdon and their fixing dad, fixing families and fixing us programmes. They helped their dad lose five stone in weight and he reversed his type two by engaging in the family in the fixing dad social prescribing programme, which was created by Ian and Anthony. It worked. Maybe fixing dad could help inform actions to include in the diabetes refresh strategy as it evolves. I agree with Diabetes Scotland that everyone should have free and equal access to what they need to live healthy lives. In a recent survey of over 1,000 people living with diabetes in Scotland, one in five said that they were having difficult to get in key diabetes technology devices. I therefore welcome that the diabetes plan mentions access to diabetes technology in priority number two and the commitment to review access to diabetes technology. I would ask the minister if she can provide information as to the timescales for this review and when the review of the data will be available that will no doubt help inform future care approaches. I would also like to ask if guidance could be produced for all Scottish health boards to ensure that all who could benefit from diabetes tech can access it free of charge. Now is the time to ensure that everyone can access what they need, and I would be grateful if the minister could commit to doing that in closing. There are so many issues to address and speak about, and many I couldn't cover, but I look forward to hearing colleagues' contributions this evening on the 100-year anniversary of insulin. Thank you, Ms Harper. I now call David Torrance to be followed by Sandish Gohani. Thank you, Presiding Officer. I would like to thank Emma Harper for bringing such a noteworthy motion to Parliament today, an acknowledgement and celebration of a 100-year anniversary of the discovery of insulin. In November of 1920, a group of highly talented and determined individuals came together at the University of Toronto, Canada, to help each other in the pursuit of a single purpose. That purpose was to understand the cause of type 1 diabetes, for the understanding and cause meant having a chance of treating the condition and drastically improving the lives of millions across the world. The discovery of insulin and its rapid clinical deployment effectively transformed type 1 diabetes from a fatal diagnosis into a medical manageable chronic condition, becoming the first life-saving treatment for diabetes. Scotland has a rich history and a tradition of innovation, as Scots have always been at the forefront of the advancement of humanity. Scotland's legacy when it comes to the development of insulin pen is no exception, as Dr Sewell Reef, Dr John Island and John Payton, all medical specialists within the Greater Glasgow area, began their journey into improving the lives of those with diabetes roughly 60 years after the first pioneers from the University of Toronto discovered insulin. The invention and subsequently refinement of the insulin pen has been such a success that the vast majority of insulin used worldwide is now administered for the use of an insulin pen, increasing doses of accuracy, reducing pain and, most importantly, promoting the ease of use. Insulin pen has had the effect of allowing those with diabetes to more constantly manage their condition and reduce serious complications related to disease. However, it is not merely enough to refine ways of managing diabetes, there is still much work to be done in reducing the number of people in Scotland with the diabetes. The prevalence of type 2 diabetes remains a significant health challenge that we face as a country and is the leading cause of ill health in Scotland. The latest data has shown us that the all-time high of roughly 312,000 individuals of Scotland now live with diabetes, while 6,400 people died from complications related to diabetes in 2019 alone. In addition to those figures, it is estimated that roughly 10 per cent of those with diabetes remain undiagnosed. The Scottish Government has taken positive steps towards tackling those issues and has made significant progress in introducing a previous diabetes improvement plan in 2014, with ever-increasing access to technologies to help both adults and children, as well as prevention campaigns such as Think, Check, Act and a £42 million worth of investment in the type 2 diabetes prevention framework. The Scottish Government is committed to making Scotland a healthier country. However, there is more that we can do and progress must continue. The centenary of the discovery of insulin represents an important opportunity to improve the prevention, treatment and care for all people in Scotland who are affected by diabetes. The diabetes improvement plan of 2021 to 2026 reflects the current challenges facing people who are living with diabetes, and it is an important step forward, building on all the progress to date and supporting continued improvements in diabetes care. However, those improvements will only be meaningful if there is a fair and equal actress for everyone living in Scotland. That is why I am so pleased to see equality of access identified and listed as one of the eight priority areas in the improvement plan. There are many factors that can impact and disadvantage diabetes care and outcomes for people, and it is vital that those are addressed. Back in 2018, I met with a number of patients living with type 1 diabetes in my constituency, and I campaigned alongside them to have free-style labour systems approved for use in Fife following the receiving Scottish approval in 2017. The system has been shown to offer life-changing improvements for people with diabetes intensively using insulin, reducing complications of diabetes, including blindness, amputations and renal failure, and helping them to live healthier and fewer lives. They will never forget the strength of feeling and overwhelming emotion response from local people living with diabetes to news that supplement approval by NHS Fife of a free-style labour system. To conclude, I once again like to thank Emma Harper for bringing this motion to Parliament and acknowledging its celebration of the 100-year anniversary of the discovery of insulin, and I hope that the future of medical innovation surrounding the care and treatment of diabetes is groundbreaking and will bring about a world in which diabetes can do no harm. Thank you, Deputy Presiding Officer, and thank you for bringing this debate to the chamber, declaration of interest. I am a practicing doctor as on the register. You've all heard about insulin and its invention from many of the other MSPs who have spoken, so instead I would like to answer this simple question. What actually is insulin and why is it so important?  In a healthy person, it makes insulin in response to your blood sugar levels. Your insulin drops the blood glucose levels and it drives it into your cells, giving the cells energy. People with type 1 diabetes, unfortunately, cannot produce insulin because their own immune system is attacking and destroying the cells that produce insulin in this pancreas. It is autoimmune and there is nothing patients can do about contracting type 1 diabetes. We have incredible new delivery methods that improve people's lives, but not everyone has access to them, so I urge the Scottish Government to look at this as mentioned earlier. But type 1 diabetes is less than 10% of the story. Type 2 diabetes presents a huge and growing concern here in Scotland and across the world. In Scotland, new cases have been growing year on year with the majority of cases being in the over 40s. Diabetes is a huge problem for us in the NHS. It accounts for 10% of the entire NHS budget and of this money 80%, that's 8% of the entire NHS budget, is spent on complications of diabetes such as loss of sight, loss of feeling, heart attacks and strokes. It also affects our black and Asian communities far more with large numbers completely undiagnosed. We need to prevent people from contracting type 2 diabetes, so I have been working hard to get people active. I visited the Woodland Trust in Dunbarton, which provides an incredible area for our families to explore. I visited the RSPB, close to Beersden, where people with anxiety can be referred, but also provides wonderful areas for exploration and even picnics. I'm also the path champion for the Ramblers to encourage the upkeep of paths so that we can enjoy the countryside. By doing this, I hope to promote simple activity and mindfulness to get Scotland moving, especially with such amazing nature on our doorstep. I have met supermarkets to promote healthy eating and to promote healthy foods rather than unhealthy foods. I thank the member for taking an intervention. What you are describing with Ramblers and outdoor access is often referred to as social prescribing. Do you think that there are some challenges in how we market that language, because some people do not know that outdoor access might be social prescribing? Social prescribing is a very important part of the armory that we as GP have. It is getting patients to understand the importance of eating well, of being able to go and do some exercise. People think that exercise is going to the gym and sweating and feeling horrible at the end of that session. That is not what we want for exercise. We are just talking about going for a walk and enjoying the walk. Social prescribing is something, and if you look at the Lothian, they are actually being able to refer patients in to get this, so this is something that we can take forward as a profession. I would hope that the Scottish Government supports what I am doing to help to prevent people contracting type 2 diabetes. In conclusion, the invention of insulin by doctors, McLeod and Banting, has quite simply saved millions of lives. It is a testament to how amazing this discovery is that, 100 years on, it is still the mainstay of treatment and being quite rightly uploaded in this chamber as a medical miracle. Let us not pat ourselves on the back. Let us actually try to reduce and prevent new cases of type 2 diabetes. That would be a legacy that Drs McLeod and Banting would be proud of. Thank you, Deputy Presiding Officer, and I begin by thanking Emma Harper for helping to bring this debate to the chamber. I recognise how close the issue is to her heart. Indeed, I thank Diabetes Scotland for their work and for their very informative briefing. We often forget how far scientifically we have come in comparison to 100 years ago. We have already heard that 100 years ago, diabetics did not have many ways to treat their condition and indeed did not lead long lives, as there was very little medicine that could provide for them at that time. Thankfully, we have seen a remarkable leap in technology and medicine to help people to live with diabetes. As we have already heard the statistic tonight, that 312,000 people in Scotland have diabetes, which equates to one in 20 people in Scotland. With that in mind, it is very likely that we all in the chamber know people whose lives are affected by it. I myself have close family and friends who are diabetic and rely on insulin to live their daily lives. Indeed, my dad has been diabetic for many years and I have seen firsthand the changes that have come as he has lived with his condition, particularly technological advances in monitoring his blood sugars and administering insulin. Indeed, I have also seen the universal power of insulin to un-sending borders. Once when I was on a family holiday to Rome, my dad forgot his insulin. I am not sure if Emma Harper has ever had that experience. The Italian medics advised that we should go to the Vatican pharmacy to see if they had any of the insulin that is prescribed here in the UK. Alas, they did not have any, but the medical staff ensured that Italian insulin works just as well and that it prescribed them some. Deputy Presiding Officer, I also want to mention one of my younger constituents this evening, Louisa Galt, from Port Glasgow. Louisa is eight and was diagnosed as a type 1 diabetic during lockdown, having been rushed to A&E thanks to the quick action of her GP and practice nurse. After her mum and dad, Jan and Jo, noticed the forties, toilets, tired, thinner and thirsty. During an extremely challenging time for the NHS, the family have embarked on a roller coaster journey in which insulin has played a huge part. Louisa is now insulin dependent and her intake of carbohydrates is closely monitored. She makes many of the decisions at age eight that Emma Harper referred to. Indeed, the family has described all of that as a huge learning curve, but they have commended the support of our NHS, particularly at the Royal hospital for children in Glasgow and at Inverclyde Royal hospital. Charities such as the juvenile diabetes research foundation, the GDRF. At a young age, she is showing great courage and a desire to show that she won't let diabetes hold her back. She is a budding gymnast and she tells her mum and dad that she wants to be a diabetic nurse one day. I hope that the minister will take note to reserve a future training place for her. The reason that I mention Louisa tonight is to reflect on how far we have come in the past 100 years. Life has been changed and dramatically improved by developments in medicine such as insulin. Just think where we can be when Louisa is an adult and beyond that with another 100 years of research and development, but we must ensure that access to advances are available to everyone who needs them. We know that constant glucose monitors, for example, allow a greater level of freedom for people with diabetes, allowing them to understand their bodies and what works for them. However, as we have already heard alluded to, access to those technologies is not always equal due to variations in what health boards are able to provide. I know that members in the chamber this evening will agree with me that we must do better to bring a greater equal level of quality care to those living with diabetes in Scotland. The Government has the opportunity to issue strong guidance to health boards to ensure that high-tech monitoring equipment is available to all patients who require it. In concluding, Diabetes Scotland has also called for a greater public health approach to be taken to help our children to understand their foods and to make healthier choices to reduce the risk of developing type 2 diabetes. We have to see far more work in that field to help us to develop as a healthy society. I hope that the minister will say something on that in her closing remarks. With actions such as those, we can help people to have healthier lives and make Scotland a happier place and create a world where children like Louisa can thrive. I thank my friend and colleague Emma Harper for bringing it to the chamber. Emma is passionate about the education, care and treatment of diabetes, and no better person could have introduced it to Parliament today. Thanks to a helpful briefing from Diabetes Scotland, we learned that more than 312,000 people in Scotland live with diabetes and that it is one of the fastest-growing and potentially most devastating health crisis of our time. The number of people diagnosed has more than doubled in the last 20 years. That is the bad news. The better news is that, with advancements in tech from blood glucose monitors to insulin pumps and looping, there is a range of options that can support someone in taking insulin, checking blood sugars and managing their condition. For people living with diabetes type 1, thanks to 100 years of insulin, it is no longer the death sentence that was prior to 1923, when Scottish doctor John McLeod and a Canadian colleague Frederick Banting jointly received the Nobel Prize for the discovery of insulin. Prior to the discovery, it was exceptional for people with type 1 diabetes to live for more than a year or two. Despite the great medical and technological advances that have been made since then, sadly, people living with diabetes are being hit hard by Covid. Almost 20 per cent of coronavirus-related deaths in Scottish hospitals are people with diabetes. Those figures were released at the start of the pandemic, so they may be a bit higher now. The condition has exacerbated inequality, as we have heard, with rates of diabetes 80 per cent higher in our most deprived communities. In addition, people living in poverty are more than twice as likely to develop life-changing complications such as heart problems and strokes. In Diabetes Scotland's recent survey of over 1,000 people living with diabetes, one in five said that they are having difficulty accessing key diabetes technology. While we celebrate 100 years of insulin, we must look to the improvements that can be made for all people, whether they live wherever they live and whatever their background and if they are living with diabetes now. I was shocked to learn just how many people are living with diabetes to 90 per cent, according to the briefing. Almost as shocked as I was when I was diagnosed with it two years ago. Fortunately, after a short spell on medication, a change in diet and lifestyle, I managed to reverse it in three months. It is preventable and can be reversed. The care and advice that I receive from diagnosis at my GP to the NHS support services for eye care and dietary advice was exemplary. Of course, no one could have predicted lockdown lifestyle in early 2019, and now many of us find that a lot of repair work is needed to reduce sugar levels, but it can be done and I am determined to do it again. We must recognise that structural factors make it difficult, sometimes impossible, for people to make healthy choices. The Government must continue to address the social determinants of health inequality and the reality of the damage that poverty can do. I have family members living with type 1 diabetes and I hear from them how relentless and overwhelming it can feel, and Emma Harper particularly outlined those difficulties. Diabetics must be supported at every level. Thankfully, much support can be found online from Diabetes Scotland, NHS Inform, information websites by way of dietary advice, which includes some delicious healthy eating recipes, exercise and lifestyle advice. In conclusion, we must ensure that the best diabetes care for everyone, no matter their post-coror background. Of course, we know that new technologies can change lives for diabetes once sufferers. Indeed, I feel fortunate that I can keep my condition at bay without the need for insulin that so many people rely on. However, the onus is on me. Diabetes type 2 is preventable, so let's stem the tide of this mushrooming condition by making healthy food and lifestyle information available for everyone. We can save the NHS of fortune and take control of our own wellbeing. Thank you, Emma, for bringing the debate to the chamber. I was really interested to see it on the agenda and really interested to hear Emma's contribution this evening on her motion, knowing the expertise that she brings in her role as a nurse. I didn't know also as a patient, so I have learned. I too, in a previous role, have some experience of working with patients using insulin. I spent many years in the NHS working as a dietician, and in my early career I covered diabetic clinics along with the specialist diabetic nurse and other members of the multidisciplinary team. Diabetes is a condition that patients manage and live with, and I learned so much about the adaptability, resilience and the humour of people following diagnosis of such a life-changing condition. It also gave me a lifelong admiration for the dedication of NHS staff, building relationships with patients who have enormous hurdles in many years of treatment to overcome. I give a big shout-out to all the staff, from the porters to the caterers, the medical and clinical staff and, in particular, my own colleagues and allied health professionals, a group of incredibly dedicated health service workers. As the motion points out, insulin is one of the greatest medical breakthroughs in history. It changed life for many millions of people, changing diagnosis of type 1 diabetes from a death sentence to a life worth living. Before insulin, it would have been unusual to live past two years, as people have said. Yes, 100 years of insulin is definitely worth celebrating. There are so many elements that we could bring to tonight's debate, as people have around diabetes diagnosis, diabetes treatment and diabetes as a life. They are such a short debate that we have a chance to raise one or two issues. For the short time that I have, I want to talk just a little about tackling the inequalities around diabetes care, in particular the link between inequality and diabetes outcomes. I thank Diabetes Scotland for the briefing notch, which reminded me of the realities of living with diabetes, particularly if you come from a more deprived background. While insulin means type 1 diabetes is no longer necessarily a death sentence, type 2 diabetes remains a disease on the increase. The day-to-day complications around heart health, eye care and foot care mean that it is an incredibly hard condition to live with. Living with diabetes can be relentless and managing it can feel overwhelming, and it is important that we acknowledge that. Managing lifelong conditions can take its toll on individuals and their families, so it is important that, as parliamentarians, we acknowledge our role in fighting for services and every possible advance to be made and made accessible to all. The poorest people in Scotland are actually over twice as likely to have diabetes at any age than the average person, and once they have the condition, those in the most deprived homes are twice as likely to develop complications of diabetes than those in less deprived areas. Those stark figures show the reality for so many. Where you are born and live unfairly lays out your future, particularly when it comes to health. Tackling the root causes of health inequalities has to be a key fight here in the Scottish Parliament. We need to tackle inequality and income, access to suitable housing and access to healthy food. We need to acknowledge the role that we all have here. We need to have policies which transfer power and wealth. The great achievement in diabetes care can continue. We just have to work hard in this place of power to ensure that the factors are in place to give economic justice to all. The briefing from Diabetes Scotland gives us the stark figures. Rates of diabetes are 80 per cent higher in most deprived communities in Scotland, and that is unacceptable, and we must act. Let's celebrate the 100 years of Vincent and let it remind us that things can change. With the creative structural changes in society, we can head towards Diabetes Scotland's vision of a world where diabetes can do no harm. I would like to thank Emma Harper for bringing this debate to Parliament. As the motion states, there are more than 312,000 people living with diabetes in Scotland, with this number having more than doubled in the last 20 years. My younger cousin was also diagnosed with type 1 diabetes at a similar age to Paul O'Kane's constituent, and many of the decisions that Emma Harper has talked about this evening, I very much recognise that my aunt had to take and that we are not popular with a cousin that had three non-diabetic cousins. We need a greater focus on prevention if we are to reduce the number of people being diagnosed with diabetes. Ninety per cent of people with diabetes have type 2, and reducing levels of obesity will help to prevent further diagnosis. Tackling the obesogenic environment will be central to achieving that, and I look forward to the Government introducing legislation to restrict the use of promotions on food and drink high in fat, sugar and salt. We must also address the health inequalities that continue to plague Scotland. Obesity rates are highest among those from the most deprived communities, and no one should be subject to food insecurities in 21st century Scotland, but it is still the case that food banks are being used. According to a report published by the UK Parliament's select committee on food, poverty, health and the environment, the inability to access a healthy balanced diet places people at greater risk of developing obesity as they may be overnourished with calories at the same time as being undernourished due to a lack of nutrients. As I have mentioned, our food environment is also saturated with low-cost unhealthy foods. The select committee found that healthy food has been shown to be three times more expensive calorie for calorie than less healthy alternatives. We cannot expect people to eat healthier diets until we address the fundamental issues of poverty and access to affordable healthy food. We also need to address unequal access to care that has been highlighted tonight. Many complications arising from diabetes are preventable as they mainly arise through poor glycemic control, where blood sugar levels are too high. In the last few years, great advancement has been made in the development of technologies that help people to maintain good glycemic control. However, those technologies are not available to all, and we have a postcode lottery in Scotland. Constituents have written to me about being unable to access this technology, which monitors glucose levels day and night and can make a substantial difference to high people with diabetes manage their condition. Some people with diabetes have had to pay for those technologies themselves, but not everyone is able to do so. Diabetes Scotland is calling for clear guidance to health boards that technologies such as glucose monitors, insulin pumps and looping should be made available to all those who need them. I urge the cabinet secretary to give serious consideration to that, and I would be grateful if the minister had anything to see. Covid-19 has highlighted the health inequalities that continue to plague Scotland, and we cannot afford those to widen further. Health and wealth are inextricably linked to the poorest people in the UK who are two and a half times more likely to have diabetes at any age than the average person. It is also the case that people with diabetes in deprived areas or for minority ethnic backgrounds are less likely to have key health checks, putting them at increased risk of developing complications. We need to ensure that everyone has access to the resources that they need to manage their condition and prevent complications, but also dedicated information campaigns that raise awareness of the symptoms and encourage people to get checked. Having a long-term health condition can undoubtedly take a huge toll on your mental health, and giving having diabetes makes you more vulnerable to developing a serious illness. If you catch Covid-19, the pandemic may have been a particularly distressing time for people with diabetes. Some people with diabetes will have been shielding, which may put them at greater risk of isolation and loneliness. Others may have had appointments postponed, all of which can have a serious impact on mental health. People with diabetes are more likely to experience anxiety and depression, and research conducted by Diabetes UK found that seven out of 10 people with diabetes feel overwhelmed by their condition and are not getting the emotional support that they need. It is vital that we do not view diabetes as simply a physical condition in isolation from mental health. We need to talk more openly about how long-term conditions can affect mental health and ensure that emotional support is integrated into physical healthcare. There have been incredible advancements in diabetes care and treatments since the discovery of insulin, and now we must do more work to ensure that everyone can benefit from those. If we give people the tools, resources and support that they need to manage their diabetes, we can substantially improve their quality of life. I am absolutely delighted to respond on behalf of the Government to the debate, and I thank Emma Harper for lodging the motion. I note that this evening in the chamber we have almost the full multidisciplinary team, so I should declare that I am a pharmacist. I hope that that ensures that we make better policy in this place. I want to join Ms Harper in celebrating 100 years since the discovery of insulin and to take the opportunity to highlight the progress that is made in diabetes treatment and care in Scotland. Diabetes is a significant challenge across the world, and Scotland is no exception. We know from the 2019 Diabetes Survey that approximately 312,000 people in Scotland had a diagnosis of diabetes. Of those, just under 88 per cent have type 2 diabetes. The Scottish Government is committed to delivering safe and effective person-centred healthcare treatment and support to people who are living with diabetes. We all know that the most effective treatment for diabetes is insulin, and we have heard about the group of scientists in Canada, one of whom was Scottish, John James Richard McLeod, a Scottish physiologist who discovered insulin. Prior to that, diabetes was a death sentence. It was exceptional to live beyond a couple of years. It is still one of the greatest medical discoveries of the last century, and, as people have commented, it is one that is still in daily use. In the 100 years since insulin discovery, diabetes treatments continued to evolve. Here in Scotland, Dr Sheila Reith, a consultant physician, worked with colleagues to develop the insulin pen in the 1970s. Like Emma Harper's mum, Sheila had a young daughter with type 1 diabetes, who found daily injections with glass syringes and steel needles extremely frustrating. She set out with colleagues to make treatment easier, creating a prototype insulin pen, a simple cheap alternative to traditional injections. After much testing, the nova pen was released to the open market in 1988. That shows you the length of time that is required to develop these innovations. We do not underestimate the impact of these discoveries for people living with diabetes. Not only have they transformed treatment and care, but they have also opened the door for many other innovations in diabetes. Diabetes is a clinical priority for the Scottish Government. In 2014, we published the First Diabetes Improvement Plan, which outlined eight priority areas and a focus set of actions overseen by the Scottish Diabetes Group. We recognise that the needs of people living with diabetes continue to change, and that has been particularly evident during the Covid-19 pandemic. We continue to respond to the needs of those living with diabetes and the services that provide the care and support. In February this year, we published a refreshed Diabetes Improvement Plan. The plan builds on significant progress made to diabetes care in Scotland, but we know that there is more that we can do, and the plan clearly sets out that ambition. We will track progress over the life of the plan to continue to demonstrate the improvements that are being made. That is why each of the commitments in the Diabetes Improvement Plan has an associated outcome measure and a plan for data collection. We are committed to sharing regular updates with the diabetes community as we progress. Emma Harper raised that during her opening speech. We collect a huge range of data on Sky Diabetes. There is not a single review point. It is about sharing that information and learning time and time again at a dynamic situation in which we continue to improve using quality improvement methodology. We will measure the data over time and track progress against the data in the Scottish Diabetes Survey and continue to improve the care, and make sure that that is shared with the wider Diabetes Society. There is no doubt that the on-going development of new technologies has transformed lives, and many members have mentioned that the Diabetes Improvement Plan sets out our continued approach to increasing the provision of technologies such as insulin pumps and continuous glucose monitors. We know that those technologies reduce clinical complications such as hyperglycemic episodes and admissions to hospital. We also know that those technologies have a positive impact on quality of life, providing more flexibility to daily life and reducing anxiety. In December 2016, the First Minister announced £10 million of additional funding to support the approach. In March this year, we allocated another £5 million to health boards to allow them to increase access to those technologies. In fact, in the latest diabetes survey, we saw insulin pump therapy in those underage of 18 was at the highest level since those data were first collected in nearly 40 per cent. That is likely to be a key factor in the substantial improvements in glycosylated hemoglobin, a measure of the good control of diabetes, which was first seen in Scottish children over the past decade. We know that advances in technology continue to benefit people living with type 1 diabetes, and we are also aware of the role of technology in type 2 diabetes care models. We know that obesity and type 2 diabetes are closely linked through targeted and evidence-based interventions. We can help people to manage their weight, improve their physical activity and reduce the risk of type 2 diabetes and its complications. We published the type 2 diabetes intervention early detection and intervention framework in 2018, with a five-year plan to take it forward. This financial year will invest £7 million for boards to implement and enhance treatment pathways for those at risk of and living with type 2 diabetes. That is 40 per cent more than last year's budget of £2 million increase. That funding enables boards to establish and deliver targeted weight management services, targeted community interventions, includes and is usually delivered in groups and specialist NHS services for more complex cases. Scotland is an international exemplar on type 2 diabetes remission due to the ground vectoring direct study, a study led by scientists at Glasgow University and funded by Diabetes UK. The direct study has changed the treatment paradigm for type 2 diabetes, showing conclusively, for the first time, that a dietary approach can put type 2 diabetes into remission, as Rona Mackayr described. For this reason, our funding to all health boards support the remission service for people living with type 2 diabetes. We know that the impact that diabetes can have on people, and as we continue to implement our diabetes improvement plan, there will be a strong focus on health inequalities. We know that both type 2 diabetes and excess weight disproportionately affect those living in deprivation, and women live with further disadvantage compared to men in terms of weight-related morbidity.  We know that people from areas of deprivation face more barriers to access that, and that will be a focus of our inequalities work. I loved hearing about Louisa Paul O'Kane. I thought that raising the story of a young person diagnosed during the pandemic with type 1 diabetes and the challenges that she faces and the ambitions that she has was wonderful to remind us of the impact that that condition has on people from a very young age to getting 180 extra decisions every day but still planning to be a gymnast and a diabetic nurse. I absolutely anything I can do to support her in our ambitions, I am more than happy to. I want to finish by acknowledging the significant advances in diabetes treatment and care over the last century. Insulin and the technologies that followed its discovery have been life-changing for people with diabetes, and we continue to support world-class innovations in that area. The Covid-19 pandemic has undoubtedly had an impact on people with diabetes. There are new challenges for the staff, new challenges for the services and new challenges for the people experiencing diabetes. We will keep on learning, we will keep on sharing our learning, and we will keep on improving the services. We are very grateful to the continued efforts of Diabetes Scotland and the clinical community for their unwavering commitment, and by combining our efforts, we can make a real difference to those living with diabetes in Scotland. I look forward to continuing those constructive and productive discussions and to continuing our improvement of diabetes care in Scotland. That concludes the debate, and I close this meeting.


We're doing everybody forest and laying here. We got a personal box of 2023 inception baseball hobby for Christopher G Here we go, buddy. Let's do it First milestones mojo first milestones mojo verbally Matt He's a redemption I've got a patch auto I don't know if it's thick enough for a milestone, but it is a patch auto in here green jeter downs rookie Purple 150 rookie Nick Proto 69 of 150 All right, here we go, Pasquitino April Moreno Trout oh, it's a Red Sox Yes, dude Tristan costs his jumbo rookie patch auto 49 of 50 Yeah, dude Do we pull them Red Sox hits that's sick dude that's a gorgeous cost is 49 of 50 There you go, Chris Heck yeah, Christopher. Thank you again for the order really good box of inception there Get out to you


Mae unig o ddaf, sydd dymuno'r technol yng Nghymru i ddiwyloedd gennym practiceddol yn ffósfiol. Mae'r begfyrdd i ffossiol yn ffordd iawn llaw wedi bod y torrizym yn Pildramech. Mae'r ddigonwch iddyn ni wedi bod yn eu hyn yn cyfnodd wedi bod yn ytwbio. in Mumbai in India to Aspect of Tourism in Ethiopia. Quite a lot of information about the Mediterranean region, particularly the eastern Mediterranean, that's to say the Holy Land in the Middle East and also the Balkan region as well, and also cover Aspect of Tourism in the United States and in Britain itself. We will visit at least three places, one of which will be London generally, and move around the streets there, another of which will be London, a particular museum of migration, and a third one will be outside London, where we will visit an ancient pilgrimage route from Winchester to Canterbury. This course is suitable for a wide range of participants of all ages and stages. People with experience and people perhaps coming to the field in a new kind of way. People interested in the theory of travel, in the philosophy of travel, in the history of travel and also in the relation between tourism and economic and political development. Our course is co-convened by myself and Dr Sania Kosovic from the Department of Finance and Marketing, and also our colleagues Safet Hadzi-Mohamedovic, who works in the anthropology department teaching gender, Reza Masouli, who teaches in the history department, Linda Coventin, who was an ambassador at the recent London Olympics, and Jeff DeVito, who works in Seaborn Cruise Company. All of their names and affiliations are on the website, and if you have any further questions, please just consult the website, and we're all ready to welcome you here to SOAS.


Hello everyone. Welcome. Nice to see that so many people are coming in for the NIM talks and not just leaving. So yeah, my presentation here is called NIM on everything. Sorry, just have to update the video stream. So yeah, NIM on everything, how to run NIM on everything from microcontrollers to servers and even in the web browser. I held the presentation here last year. I have a computer science background from University in Trumpsa which is way like above the polar circle somewhere. Mostly with C and Python, it's sort of the background that I came from. NIM has been a really great language to migrate from that starting point. But before we get into how to run NIM on everything, I think it's a bit important to say, why should we run NIM on anything? So since you all seem to come here for the presentation, how many people here have heard of NIM? Oh, wow. Okay. Almost all of you, that's great. How many here have used them, like tried it for simple project? Oh, wow. About half of you. How many of you would say that you're experienced in NIM? Actually, some people I don't know. That's fun. Okay. Yeah. So NIM has compiled statically type language. The type system is really powerful, not like C++ with just numbers and strengths and pointers to random stuff. But we have a proper type system. We have distinct types. So you could have a number, can store multiple types of information, and you can reflect that in the type system in NIM. So you could have something like this is a meter, this is a dollar, you can't add meters to dollars because that would, or maybe you can, I don't know, but for your application. But you can create distinct types, and this is actually something that helps us with another of the great features, which is metaprogramming. I'll come back to that later. It's also garbage collected, which might sound weird when I'm talking about running it on microcontrollers. But you can actually turn the garbage collector off, and you can also tune it. So you can say, for example, if you're making a game run at 60 FPS, if we have some time left over in our frame, then we do garbage collection. So it really doesn't get in the way like Java, for example, you have a game playing along and just everything suddenly freezes while it's collecting your garbage, and then you can't get back to playing. So you can avoid that. I also included a hero quote that I had last year, the speed of sea, ease of Python and flexibility of Pearl. I thought this was something that Andrea said, the creator of NIM, apparently not, and now I've seen it attributed to me in other presentations. So apparently that's a quote of my own. So yeah, one of maybe or maybe the most sort of killer feature of NIM is a metroprogramming or the strongest kind of which is macros. Dominic is going to talk a bit more on this later today. So if you want to know even more, go see his talk as well. And with metroprogramming, what we can do is that we can really optimize our code. So we can, for example, take in types and do certain things on compile time, spit out code that works better than the code we gave it. We can also create nice looking code. So we can create nice looking code that we then optimize to be ugly code, but fast running code. For example, this case, we also have a safer way or a safety element to it. So here we can write a with lock template. This is actually in the standard libraries and I would write this yourself. And with this, you can just give it a block. It will do the try finally stuff for you. Pretty much, I think everyone who's ever worked with multi-threading and locks, you know you should do this, but you probably don't. Everywhere where you use locks. But with metroprogramming, you can easily create templates to do all of that boring stuff that you know you should be doing, but you can't be bothered. So you can do all of that automatically or some way automatically. It also works on the abstract syntax tree instead of on text. So if you've used macros and for example C, they are just taking some text, do some replacements, spit out some new text. But this works on a tree structure. So it parses name code into a tree structure. Then you can play around with that tree structure and you can give it back another tree structure. And this is something that really allows us to compose these macros in a much more efficient way and we can really make them do a lot more for us or at least easier to do a lot more for us. This is just an example. Here we take in a static string. So also the type system or the type system also applies to macros. And all of the metaprogramming. So for example in C macros again, you don't really have types. You take in something and you just put it in there and then you pass it off to the type system. Here types are actually checked when you call this function or this template, this is a macros. When you call this macro, it will actually check that your type is correct before trying to do anything with it. So you won't get some weird error message from somewhere else in your system. Yeah, I can buy time, yeah. So in this case, this is a static string. That means that this is a string on compile time. If we had just a string, it's actually anything that can become a string on runtime. So if you can give it a variable that's only available on runtime. But we tell that the macro system that yes, this should be something that will be a string when we're running this code. So you can take that symbol and put it somewhere and you know that it's gonna be a string when the code is run. This is just an example from the manual. Take a string, split it up, and this will actually spit out just an array of these four elements. And you won't have to do any of the string stuff on runtime. And this is great for microcontrollers, for example. You don't want to do string splitting on a tiny microcontroller. This way you can do all that on compile time. And then on runtime, you just have your array with pre-splift and done everything. So I mentioned that name is a compile language, but it doesn't compile directly to binaries or to code that you can run or to binaries. It uses C, C++, also Objective C, and JavaScript as sort of intermediary languages. So it first compiles, so it takes away some of the abstractions. It doesn't compile your macros into like C macros. So it compiles down to C, C++, JavaScript, and then it hands that over to the compiler, which actually creates the binary for you. And because of these languages, like they've been around for so long, you can really take your name code and run it on anything that can run these languages, which is pretty much any device. We have name running on microcontrollers, as I said, servers, Android phones, iPhones, of course, servers, laptops, anything. This also means that we can very easily tie into the native libraries of that system. So you can take a C library and just say, well, call this C function or a JavaScript library and say call this JavaScript function. So you can really easily tie into the system that you're building for. It also means that, as I write here, we're standing on the shoulders of giants. Because we have the benefit of all of the work that's gone into, for example, the GCC compiler. It's been around for a long time. There's a lot of optimizations built into that thing. And we get all of that sort of for free by creating C code. So that means it's super fast and it also doesn't spit out human readable code. So it uses C more as a target. You wouldn't want to read the name C code. I know that some people do, but it's not great. And I mean, if you're working with someone on a C project and you start committing the code that namespits out, they're not going to be happy with you. And that's also, a lot of people say, well, you have the speed of C, but you're obviously doing something more than what you can do in C. So how does that work? Like, there's got to be more work here. And the answer is just, because we're spinning out stuff that no sane human would write or read or maintain, it means that our C code can be more efficient than what you would normally write as a C programmer. Another question is, why not LLVM or WebAssembly? The answer to that is pretty simple. WebAssembly didn't exist when it was created and LLVM was still sort of kind of new when no one really knew about it. And it wasn't, yeah, it wasn't proven to be what it is today. When I first discovered them, I remember I clicked into the website, I was like, oh, compiles to C and JavaScript, that can't be good. There has to be some trade-offs here. You can't do everything you can do in C and JavaScript, that doesn't work. But the way NIM solves this is that you can't run all NIM code on both JavaScript and C. Like you can't access the DOM tree when you're writing C code and you can't do pointers when you're compiling to JavaScript. So really, this is an example, two pieces of code, both in NIM. On the right-hand side, we have some JavaScript stuff. It just interfaces with regular document, create element, onload, regular JavaScript stuff. On the left side, you have some of my horrible code from a work project that interfaces with sockets and stuff on the NSE library. And it's really, it's based on, we have the same syntax, we have the same metaprogramming capabilities, we have the same type system, but it's not exactly the same language. So it really, it gives us all of the benefits of NIM, but it doesn't take away any of the benefits or sort of capabilities of the underlying language. So what we're actually here to talk about, NIM on everything. So let's start with the smallest. These are all things you can program with the Arduino ID. This one is a DigiSpark. It has four kilobytes of accessible memory, or it has six, the two of those are used for the bootloader. And NIM runs on that. You have the Arduino Boy, which is kind of fun. It's an Arduino Leonardo-based thing with just a screen and some buttons and a tiny little speaker. It has 32 kilobytes of program memory. And you can run NIM on that. I made a breakout clone for it and that's an interesting thing. With this device, when I was writing the code, I was compiling it and it comes out to the same binary sizes. Like give or take a few bytes.  But like a one-to-one rewrite from C to NIM actually turned out to be pretty much the exact same footprint on the chip. So unlike, for example, MicroPython, I've run MicroPython on some devices and I was like, why am I running out of memory? I'm reading like two sensors and this is a super capable chip. I was like, ah, yeah, I have the Python interpreter. I have a lot of string handling. Of course I'm running out of memory. And I say we're running without the garbage collector right now. Here at Faustum, we were actually able to get it to work with GCE Arc. So now you can do strings and sequences and stuff on these.  And it means that all of the standard libraries should be available at some point because now there are some points that you actually can't use. And really the benefit, like as I said, when you do a one-to-one rewrite, it's pretty much the same. But if you're doing a one-to-one rewrite, why do it in NIM? Why not just write the C code? And the thing is that you can use the metaprogramming. You can use all of the extra features. So again, for the Arduboi, I wrote a macro that loads sprites on compile time. It reads in the sprites as images on compile time. It converts them to the internal image representation that the Arduboi libraries use. And I'm using the same C libraries as the regular Arduboi code. And I'm casting them to a type that on compile time knows the size of the image. So for example, this draw-bit map. It takes a logo and a logo mask. And these have to be the same size because otherwise, like, what would it do with them? But because I do them through this load sprite function, I'm saving the size of the images in my type. So on compile time, I can check that these two sprites are actually the same size. So I can never call this function with two sprites that won't do the thing I expect them to and create crashes and stuff. So it's actually both safer. And I don't have to go through, like, a web UI to convert my sprites into an age file which I download and then put them to my project folder and run it. And I don't have to do any of that. Just load sprite, draw it, done. And it's also now running in the Arduino IDE. This was hacked together very recently. But it actually works. You can open the Arduino IDE, type name, code, hit upload. It goes straight onto your microcontroller, and it just works. There was also, and NIM forums, a Chinese Bluetooth low-energy chip producer that just out of nowhere posted that, hey, we're making Bluetooth low-energy chips and we have a NIM SDK. So it's actually catching on, even with chip manufacturers, not only users. But again, since we can use C libraries, we don't have to rewrite all our SDKs ourselves. We can just use the existing C ones and use those directly. You can also, of course, run it on a server or desktop or any regular computer. Again, we can use all the libraries, like databases, MySQL, MariaDB. We can use GUI libraries. This is a GUI library that I took. It's VX widgets. So this runs on GTK and Windows and Coco on Mac. This is just done with a macro. So the code for this looks super clean. And this runs regular programs. We also, the backend for the NIM forum is running on NIM. The backend for the NIM playground. So you can go to play.nim-lang.org and just type NIM code and head to run. Compiles it on a server since you back the results. That is written in NIM. This is another example, again, taken from the NIM forums. It created a GUI for doing some unlocking stuff and setting up servers for Battlefield, I think it was. Of course, a lot of terminal tools, NIM compiler, NIMble. A lot of stuff you can write in them. You can also run it on the web. We can compile to JavaScript, as I mentioned. Again, this is not something that you would want to look at necessarily. And again, the forums, the front end for those are also written in NIM. The playground, again, it's also written in NIM. And as I mentioned, we don't have a lot of stuff like the C pointers and all of that, but what we do have is stuff like DOM. We have JS-specific modules that are only available for the JavaScript target that only does JavaScript-specific things. But also we can use JavaScript libraries. So in the same way that we can use existing C++ code when we're running on Arduino or database code when we're running on a server, we can run JavaScript libraries in our JavaScript code. So, for example, the playground uses standard input with syntax highlighting and all of that. Don't have to re-implement that myself. Just find it like you would normally do when you're writing JavaScript. Use that, works great. And of course, we don't use the JavaScript garbage collector.  So that doesn't apply to the JavaScript target. Here's one example. Real Valley was written almost, I think, 100%, 99.99. I think it's written in a blog post somewhere. Both server frontend runs on phones, runs on web embedded on Facebook, the servers as well. These are the forums that I mentioned. Looks kind of like discourse. A lot of people think it is. But it's sort of a lightweight alternative to discourse that is written entirely in them. Yeah, that was my talk. Bit faster, but we're a bit behind schedule. So I think that's fine. Actually, we can take a couple of questions because you still have seven minutes. Yeah, yeah, yeah. And probably the next pages will come and... Yeah. Ah, templates are more like macros in C. So they are simple replacement. So if you look at the example here, this template is just... You have the lock and the body and lock and body in this code is just being replaced with whatever you pass in. But otherwise, the body is the same.  So the code that actually comes out is not the code that you see here, but the code that you generate through the AST. Yeah, sorry, I should have repeated the questions. But so you're asking, can macros access the file system? And the answer is yes. What? And yeah, you can run static exec so you can run any program on your computer as well. So you have to be careful when you run other people's code. But on the other hand, it means you can do anything in a macro. Yep. So the question is if there are plans to support LLVM, I don't... Yes, I'm getting yes from Andreas back here. Yep. So yes. So the question is, when you turn off the garbage collector, is there any sort of backup? Yeah. So you have options. You can use different garbage collectors. So you can find one that suits your need. One of them is reference counting. When you turn it off, it doesn't do anything. But you will get warnings when you're compiling that says this uses garbage collected memory. But on runtime it is just going to leak, like I said. Any more questions? Yep. So the question is, can you do manual memory management? And the answer is yes. You can use malloc. You can use free. Again, like for interfacing with C, you need them anyways. So the question is, is it feasible to write large project name in reference to compile times? I would say definitely yes. It compiles super fast. And I know there is work on doing incremental compilation. I have to say if you write super complex macros or if you do like me and write a parser that isn't very good, then you can quickly rack up some compile time. But compared to C++ or something like that, it's nothing. It's run super fast. So the question is, when you're compiling to C, can you get C errors? And does that happen often? Answer, yes, it can happen. And no, it doesn't happen often. If it happens, there's something wrong in the compiler and you should create an issue in GitHub. Yeah, no, no, yeah. You can do emit. So just emit a block of text into your code file. That, of course, will get you errors. You can also do some weird things with code gendacle stuff. But if you're using them like a normal person, then you shouldn't have any issues for that at all. There was a hand, yeah? So is the language specification out on the web? Yes, it is in the manual. There is maybe some idiosyncrasies between the implementation and the specification, but in general it's, yes. Yeah, who is the next speaker? Oh, Andreas, yeah, just come down. He's using my machine, so it's fine. Do we have any more? Yeah, just come down.