<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Aditya Srinivasan on Medium]]></title>
        <description><![CDATA[Stories by Aditya Srinivasan on Medium]]></description>
        <link>https://medium.com/@adisrini?source=rss-8b2671a37ec3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*y4MGIjvu6FqxiODvymEYyg.jpeg</url>
            <title>Stories by Aditya Srinivasan on Medium</title>
            <link>https://medium.com/@adisrini?source=rss-8b2671a37ec3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 05:26:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@adisrini/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[What is Quantiscope?]]></title>
            <link>https://medium.com/quantiscope/what-is-quantiscope-328f5953f876?source=rss-8b2671a37ec3------2</link>
            <guid isPermaLink="false">https://medium.com/p/328f5953f876</guid>
            <category><![CDATA[ideas]]></category>
            <category><![CDATA[writing]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[blog]]></category>
            <dc:creator><![CDATA[Aditya Srinivasan]]></dc:creator>
            <pubDate>Sat, 04 Jan 2020 15:58:25 GMT</pubDate>
            <atom:updated>2020-01-04T16:04:17.440Z</atom:updated>
            <content:encoded><![CDATA[<p>My roommate and I often like to discuss interesting ideas we learn about from articles, videos, or books. While the topics have ranged from the theoretical domain of pure mathematics, to more applied fields such as political science, they all have one thing in common: the ability to be represented or reasoned about quantitatively.</p><p>Inspired by channels such as <a href="https://www.3blue1brown.com/">3Blue1Brown</a>, <a href="https://www.youtube.com/channel/UCoxcjq-8xIDTYp3uz647V5A">Numberphile</a>, and <a href="https://www.youtube.com/channel/UCSju5G2aFaWMqn-_0YBtq5A">standupmaths</a>, the blogs of individuals such as <a href="http://math.ucr.edu/home/baez/">John Baez</a>, and <a href="https://vitalik.ca/">Vitalik Buterin</a>, and many other fantastic sources of thought-provoking material, we decided to start our own blog, Quantiscope. The name is a concatenation of the Latin <strong>quant</strong>,<strong> </strong>which is used in referring to the <em>amount</em> or <em>number</em> of something,<strong> </strong>and the suffix <strong>-scope</strong>, from the Greek <strong>-skopion</strong> meaning <em>to observe</em>. Thus, in each post we’ll be looking at a concept we find intriguing, and explain it through a quantitative lens.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/747/1*QtLNMYRPRlgy80uq-yjbGg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=328f5953f876" width="1" height="1" alt=""><hr><p><a href="https://medium.com/quantiscope/what-is-quantiscope-328f5953f876">What is Quantiscope?</a> was originally published in <a href="https://medium.com/quantiscope">Quantiscope</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Year Million]]></title>
            <link>https://medium.com/@adisrini/the-year-million-d5bfc529fab2?source=rss-8b2671a37ec3------2</link>
            <guid isPermaLink="false">https://medium.com/p/d5bfc529fab2</guid>
            <category><![CDATA[philosophy]]></category>
            <category><![CDATA[mathematics]]></category>
            <dc:creator><![CDATA[Aditya Srinivasan]]></dc:creator>
            <pubDate>Mon, 26 Aug 2019 10:06:18 GMT</pubDate>
            <atom:updated>2019-08-26T10:06:18.176Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>You’re not special.</strong> This is what, in essence, the Copernican principle asserts. Also known as the mediocrity principle, it represents the philosophical stance of assuming nothing exceptional about a particular entity, event, or process.</p><p>This principle is rooted in basic statistics: if an item is drawn at random from one of several sets of categories, it is likelier to come from the most numerous category than from any one of the less numerous categories. Applied to time, it implies that the observation of an entity takes place in the middle of its lifetime which forms a majority, as opposed to the extremities (the beginning or end) that form the minority.</p><p>One of the most intriguing applications of the Copernican principle is in predicting expected longevity based solely on how long it has existed using simple calculations, a method pioneered by Princeton astrophysicist John Richard Gott.</p><p>Let us assume that the principle is true, and that there is nothing special about the particular moment when we make an observation of something during its lifetime. Concretely, let us say that we are not observing the first 2.5% of it’s life, nor are we observing the last 2.5%; instead we are observing something in the middle 95%.</p><p>Now, imagine that at some moment you observe the existence of some entity or process, which has existed for <em>n</em> years. According to our assumption, we cannot be observing the first 2.5% of its existence, and so its entire lifetime must be at most 40<em>n</em>. Similarly, we cannot be observing the last 2.5% of it’s existence, and so it’s entire lifetime must be at least <em>n</em> + (<em>n</em>/39). These simple calculations allow us to astoundingly deduce its longevity with a confidence interval of 95%: namely, at least <em>n</em>/39 and at most 39<em>n</em>.</p><p>The Copernican Interval also has a profound, and somewhat counter-intuitive implication: things that have existed for longer are likely to continue to exist for longer — in other words, <strong>old things endure</strong>.</p><p>I was first introduced to this idea in Jim Holt’s thought-provoking <em>When Einstein Walked with Gödel</em>, and was intrigued by his application of this method. Holt employs the intervals to predict what life will be like in Year Million. He asserts that mathematics and comedy will both endure. We share laughter with chimpanzees, with whom our lineage split approximately 5 to 7 million years ago. If we conservatively assume laughter spawned around then, they should persist for at least another 154,000 to 234,000,000 years. We share the ability to reason numerically with even more species, indicating that mathematic intuition is older than laughter. Thus, we can expect our distant descents to dabble in both equations and entertainment.</p><p>What about the negation of the question? What <em>won’t</em> life be like in Year Million? According to the principle, we almost certainly won’t have the Internet as it exists in its present form, which is 29 years old: it’s Copernican interval suggests it is likely to survive between three-quarters of a year and 1131 years. A similar statement can be made about basketball (72 years old), and the automobile (249 years old).</p><p>One may imagine a distant world without such luxuries. But what about core ideologies that frame and guide the modern world, in politics, economics, and religion? As the following figure suggests, their survival into the year 125,000 — let alone Year Million — seems unlikely.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_47J_Nj1IU-g4GJVMH0HJQ.png" /><figcaption>What will replace our beliefs?</figcaption></figure><p>It is uplifting, however, to apply this technique to the realm of unsolved problems in math, science, and philosophy, which have boggled the minds of great contemporary thinkers for decades, if not centuries.</p><p>Take the P versus NP problem in computer science, for example. It asks whether computational problems that can be verified quickly can also be solved quickly (by “quickly”, I mean within polynomial time). A solution to this problem, whether it concludes P = NP or its negation, would have profound, revolutionary consequences in many other fields of study.</p><p>If we consider the life of this problem to have begun when it was first publicly and precisely formalized in 1971, then its age so far is 47 years. Our Copernican method therefore suggests this problem will be solved within the next 1.2 — 1833 years. One can only imagine how far its conclusion will have taken society by Year Million. Similarly, the Riemann hypothesis may likely be solved in the next 4.1 — 6201 years, the Hodge conjecture in the next 1.74 — 2652 years, and the unique games conjecture in the next 0.4 — 624 years.</p><p>It is quite unfathomable to imagine what life will be like in Year Million. We can only hope that what replaces the species, systems, religions, and problems of today are for the better. And if you’re reading this in the Year Million, let me know what it’s like — although, given Medium’s young age of 6 years, it’s unlikely this message will even reach the latter half of this millennium.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d5bfc529fab2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How a Compiler Works [Part 1/2]]]></title>
            <link>https://medium.com/@adisrini/how-a-compiler-works-part-1-2-36fce5f8f0d0?source=rss-8b2671a37ec3------2</link>
            <guid isPermaLink="false">https://medium.com/p/36fce5f8f0d0</guid>
            <category><![CDATA[how-to]]></category>
            <category><![CDATA[compilers]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[language]]></category>
            <dc:creator><![CDATA[Aditya Srinivasan]]></dc:creator>
            <pubDate>Sat, 20 Jan 2018 23:53:33 GMT</pubDate>
            <atom:updated>2018-01-20T23:53:33.492Z</atom:updated>
            <content:encoded><![CDATA[<p>In the spring of 2017, I took a course on compiler construction from Dr. Drew Hilton, based on the content of Andrew Appel’s canonical “Modern Compiler Implementation in ML”. Compilers are <a href="https://en.wikipedia.org/wiki/Full_employment_theorem">infinitely optimizable</a> making them an inherently interesting and active field of study.</p><p>This article will describe the various components of a compiler and how they come together. I will also go through examples to make it clear how various components function.</p><h3>What is a Compiler?</h3><p>In the most general sense, a compiler can be considered a translator from one language, the <strong>source</strong>, to another language, the <strong>target</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*41LxdxzkPmN1KxNQCmws5A.png" /></figure><p>A compiler whose source and target languages are both at similar levels of abstraction are called <strong>transpilers</strong>, whereas traditional compilers translate from a high-level language to a low-level one, such as assembly.</p><blockquote><strong><em>Note:</em></strong><em> in this article, I will consider a compiler designed for a statically-typed language as the source and an assembly language as the target. However, many of the concepts are applicable to other kinds of compilers too.</em></blockquote><h3>Compiler Mountain</h3><p>So, how do we get from the source to the target? We can compare this translation to the act of scaling and descending a mountain.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oXWx71_2IOD3-KPqKx8qgg.png" /><figcaption>Compiler Mountain</figcaption></figure><p>Each section of the mountain represents an independent module, each of which accepts some input from the previous and passes on some output to the next.</p><p>The mountain is also divided into two larger independent components, the <strong>front-end</strong> and the <strong>back-end</strong>. The rationale for this is increased flexibility and modularity. In between the two components, information exists in a form called <strong>intermediate representation</strong>, which is independent of the semantics of the source and target languages. To see why this is useful, imagine the task of compiling from any one of 5 source languages to any one of 5 target languages. Ordinarily, you may build 25 separate compilers to handle every combination. With an intermediate representation, only 10 half-compilers must be built, one for each language in question. Front-ends and back-ends can then be swapped out to handle all combinations.</p><h3>Lexer</h3><blockquote><em>Input</em>: code written in the source language<br><em>Output</em>: stream of tokens</blockquote><p>The first phase of compilation is lexical analysis, or tokenization, performed by the <strong>lexer</strong>. The role of the lexer is to extract meaningful <strong>tokens</strong>, or symbols, from the source code.</p><p>Let’s step away from the context of programming languages for a second. Consider how we as humans interpret written language: we read a sentence and extract information at the word-level, subsequently constructing meaning from their relative positioning. The initial scanning happens so naturally that we often overlook it, but we are actually performing <strong>tokenization</strong>. We use <a href="https://en.wikipedia.org/wiki/Word_divider">word dividers</a> (typically spaces in Latin scripts) to delimit words, thereby gaining information from where there is none. Classical Greek and Latin scripts lacked word dividers, punctuation, and letter case, in a form known as <a href="https://en.wikipedia.org/wiki/Scriptio_continua">scriptio continua</a>, but they were clear benefits to introducing such constructs, and the writing form declined. Unsurprisingly, most programming languages (barring esoteric ones) employ similar frameworks: symbols separated by whitespace (also, programmers can add comments to their code, which are not tokenized as they have no functional impact on the program).</p><p>Let’s see an example of lexical analysis being performed on a snippet of code. For reference, the examples will be written in <a href="https://www.lrde.epita.fr/~tiger//tiger.pdf">Tiger</a>, although I will make sure they are understandable even to a reader unfamiliar with the language.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d0d622b119e144a87fcf4e440476c5f6/href">https://medium.com/media/d0d622b119e144a87fcf4e440476c5f6/href</a></iframe><p>We would expect our lexer to output the following stream of tokens</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6NbvmtP4JKPSPryp_f-UHA.png" /><figcaption><strong>Lexer output</strong>: a stream of tokens (orange blocks represent keywords or symbols inherent to the language; blocks with black underbars represent constructs with an attached value, such as literals or variable names)</figcaption></figure><p>The lexer can also catch basic syntax errors such as misspelled keywords, unclosed string literals, unclosed comments, or unbalanced parentheses. Other syntax errors, such as invalid if-then-else structures or function declarations, require a more involved analysis, bringing us to the next phase.</p><h3>Parser</h3><blockquote><em>Input</em>: stream of tokens<br><em>Output</em>: abstract syntax tree (AST)</blockquote><p>The lexer produces a linear stream of tokens, but code has a hierarchical structure requiring the compiler to perform a transformation. The result is an <a href="https://en.wikipedia.org/wiki/Abstract_syntax_tree">abstract syntax tree</a> (AST). Let’s break this down: the AST is a tree due to its structure. For example, consider the following Tiger:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d45b349083dd4dcddc21b083c7c1c202/href">https://medium.com/media/d45b349083dd4dcddc21b083c7c1c202/href</a></iframe><p>The abstract syntax tree for this code would look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JfRmsL7FbCIQMPcUz1j9sQ.png" /><figcaption><strong>Parser output</strong>: structured tree</figcaption></figure><p>In the diagram above, the orange squares represent value-containing data nodes, the blue squares represent expression-containing data nodes, the purple squares represent values of an enumerative datatype (in this case operation types), and the green squares represent declaration-containing data nodes. The distinction between values, expressions, and declarations is unimportant, but for now it’s worthwhile to note how the linear stream of tokens has been given a hierarchical structure in the form of a tree.</p><p>Next, what does the phrase “abstract syntax” imply? Upon closer observation of the diagram, one may find that any concrete references to the syntax of our language have been shed. Instead we reference expressions in a general sense. Thus, the tree represents our program in some <strong>abstract syntax</strong>, hence the term. For example, one could imagine the function definition in the following Python (3) code to have a similar, if not identical, representation in an AST to the function definition in the diagram above despite having a vastly different concrete syntax:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/65ab31dd656ec8533ef7d6606ca6e1da/href">https://medium.com/media/65ab31dd656ec8533ef7d6606ca6e1da/href</a></iframe><p>So, the parser provides structure to our code in the form of an abstract syntax tree. However, how does this transformation actually happen? This is done by defining formal grammars known as <a href="https://en.wikipedia.org/wiki/Context-free_grammar">context-free grammars</a>. Put simply, CFGs are sets of rules that define the possible strings in a language.</p><blockquote><strong><em>Note</em></strong>: if you’re interested in learning how these grammars are expressed and how they construct the AST, read ahead. Otherwise, you may skip ahead to the last paragraph of this section.</blockquote><p>A common notation for CFGs is <a href="https://en.wikipedia.org/wiki/Backus%E2%80%93Naur_form">Backus-Naur form</a> (BNF). To define a grammar, we must define sets of rules. Within these rules, we use <a href="https://en.wikipedia.org/wiki/Terminal_and_nonterminal_symbols">terminal and nonterminal symbols</a>. A <strong>terminal</strong> symbol is a symbol of the language, typically denoted in lowercase. A <strong>nonterminal</strong> symbol is replaced by terminal and nonterminal symbols according to the grammar rules, and is typically denoted in uppercase. The left-hand side of a rule is a nonterminal, and the right-hand side consists of a series of terminals and/or nonterminals. The rule therefore defines a substitution. As usual, let’s consider a simple toy example with the following CFG expressed in BNF.</p><pre>E ::= T + E     (1)<br>   |  T         (2)</pre><pre>T ::= F * T     (3)<br>   |  F         (4)</pre><pre>F ::= ( E )     (5)<br>   |  C         (6)</pre><pre>C ::= integer   (7)</pre><p>The grammar above defines arithmetic expressions including addition, multiplication, and parenthesization. The parenthesized numbers on each line serve to enumerate the rules and are not part of the actual grammar. Is the following string valid in the language defined by the grammar above?</p><pre>5 + (6 * 7)</pre><p>We can perform a series of <strong>shifts</strong> (reading in tokens) and <strong>reductions</strong> (substituting tokens by our grammar rules) to determine whether strings are valid in the language:</p><pre>initial                =&gt; .5 + (6 * 7)<br>shifting &#39;5&#39;           =&gt; 5. + (6 * 7)<br>reducing by rule 7     =&gt; C. + (6 * 7)<br>reducing by rule 6     =&gt; F. + (6 * 7)<br>reducing by rule 4     =&gt; T. + (6 * 7)<br>shifting &#39;+&#39;           =&gt; T +. (6 * 7)           <br>shifting &#39;(&#39;           =&gt; T + (.6 * 7)<br>shifting &#39;6&#39;           =&gt; T + (6. * 7)<br>reducing by rule 7     =&gt; T + (C. * 7)<br>reducing by rule 6     =&gt; T + (F. * 7)<br>shifting &#39;*&#39;           =&gt; T + (F *. 7)<br>shifting &#39;7&#39;           =&gt; T + (F * 7.)<br>reducing by rule 7     =&gt; T + (F * C.)<br>reducing by rule 6     =&gt; T + (F * F.)<br>reducing by rule 4     =&gt; T + (F * T.)<br>reducing by rule 3     =&gt; T + (T.)<br>reducing by rule 2     =&gt; T + (E.)<br>reducing by rule 5     =&gt; T + F.<br>reducing by rule 4     =&gt; T + T.<br>reducing by rule 2     =&gt; T + E.<br>reducing by rule 1     =&gt; E.</pre><p>The derivation above shows that the string is in fact valid. Further, by nature of the grammar rules our expression can be represented by a parse tree:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/884/1*pZcHcmTqHaUTaBn95vXQog.png" /><figcaption>A segment of the parse tree</figcaption></figure><p>In the tree above, each edge represents a rule, where the parent is the nonterminal on the left-hand side and the child is the series of terminals and/or nonterminals on the right-hand side. Note that all leaves are terminals.</p><p>An interesting fact to note is that by virtue of our grammar definition, certain operator precedence rules are defined. For example, when evaluating this expression, we would begin from the bottom of our tree and evaluate upwards simultaneously collapsing nodes into their new evaluated values. In this way, we would evaluate the multiplication prior to the addition. It turns out that the expression without parentheses would also result in the same numerical value, thereby adhering to conventional precedence rules of arithmetic.</p><p>The parser thus has two main functions: firstly, it utilizes a formal grammar to define which strings are valid in the language; and secondly, it leverages the grammar to transform the linear stream of tokens into an AST.</p><blockquote><strong><em>Note: </em></strong>CFGs are a rich and interesting field of study and this section does not touch on many additional complexities and features. Refer to the following list for starting points for further reading:<br> <br><a href="https://en.wikipedia.org/wiki/Ambiguous_grammar">https://en.wikipedia.org/wiki/Ambiguous_grammar</a><br><a href="https://en.wikipedia.org/wiki/LL_parser">https://en.wikipedia.org/wiki/LL_parser</a><br><a href="https://en.wikipedia.org/wiki/LR_parser">https://en.wikipedia.org/wiki/LR_parser</a><br><a href="https://en.wikipedia.org/wiki/Context-sensitive_grammar">https://en.wikipedia.org/wiki/Context-sensitive_grammar</a></blockquote><h3>Type Checker</h3><blockquote><em>Input</em>: AST<br><em>Output</em>: type-checked AST</blockquote><p>After the parser has finished executing, we have a structured representation of the expressions in our program. While the parser catches errors in syntax, it is not responsible for identifying errors in typing; this is the responsibility of the <strong>type checker</strong>.</p><p>We note here that type checking only occurs at compile-time for statically-typed languages (Java, C, and SML for instance). Thus, type checking is not a part of all compilers, but we will elaborate on it in this piece.</p><p>In programming languages, the use of type systems help classify values and expressions into different ‘categories’ (or <strong>types</strong>) according to certain rules. Further, type systems help enforce whether expressions are valid or not based on the types of subexpressions.</p><blockquote><strong><em>Note: </em></strong>The distinction between values and expressions is important. A value is information that cannot be evaluated any further. An expression is information that can take further steps of evaluation, eventually resulting in a value.</blockquote><p>Some common examples of types are integers, booleans, strings, and arrays. In Java, we know that true and false are of type boolean. On the other hand, 42 and 1008 are of type int. Rules in our typing system help determine and assign the type of values such as these.</p><p>In addition to determining the types of values, we may determine the type of expressions that may even contain subexpressions. For example, consider the Java expression e1 &amp;&amp; e2 where e1 and e2 are subexpressions. There are a few things we may deduce from this:</p><ol><li>e1 must be of type boolean</li><li>e2 must be of type boolean</li><li>e1 &amp;&amp; e2 must be of type boolean</li></ol><p>We can summarize these three conditions as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FRUGgPn2Jv5U9Qr8PvJpdA.png" /><figcaption>A sample inference rule</figcaption></figure><p>The figure above is an <a href="https://en.wikipedia.org/wiki/Rule_of_inference">inference rule</a>. The statements above the line are the premises for the inference, and the statement below the line is the conclusion. Roughly, if all the premises are true then the conclusion is true. We use such inference rules in our type checker to ensure that subexpressions are correctly typed, and to propagate the type of more complex expressions.</p><p>For example, consider the following SML expression:</p><pre>if f(points) &gt; threshold<br>then &quot;level passed!&quot;<br>else &quot;try again&quot;</pre><p>The typing derivation of this is shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w3u434J9c1kVXu8IR6hELA.png" /></figure><p>The statements that contain the Greek symbol gamma followed by the turnstile can be read as ‘the variable environment says that…’. For example, the top-leftmost statement is read as ‘the variable environment says that the function f has type int to int (the function accepts an int as an argument and returns an int. We can perform this derivation algorithmically to determine whether the expression is well-typed. An example of an expression that is not well-typed (in SML) is as follows:</p><pre>&quot;hello&quot; + 42</pre><p>This is because the addition operator requires both operands to be of type int which is evidently not the case.</p><p>Another name for this phase of compilation is ‘semantic analysis’, since the semantics, or meaning, of the program code is being evaluated. The type checker recurses over the AST and type-checks each expression, reporting any errors it encounters.</p><h3>Frame Analysis</h3><blockquote><em>Input</em>: type-checked AST<br><em>Output</em>: intermediate-representation (IR) tree and frames</blockquote><p>At this point, we begin to consider how the assembly code will actually be generated. Every time a function is created, a <strong>stack frame</strong> is allocated in which arguments, local variables, the return address, and other temporary data is stored. As functions may call other functions, stack frames are “pushed” onto a large array of memory called the <strong>stack</strong>. When a function call terminates, its stack frame is “popped” off and we shift our context to the frame that came before it (the frame belonging to the function that called the function that just exited). During this phase, we generate these stack frames for each of our function calls and allocate variables to where they belong.</p><p>In addition to the generation of stack frames, we perform a translation on the AST from an abstract syntax to abstract machine code. This is a representation of the program in the language of machines (operations on registers, memory accesses, jumps, branches, etc.) that does not commit to a single ISA (hence the term ‘abstract’). This representation is known as the <strong>intermediate representation</strong>: it is neither bound to the source nor the target language. This is highly desirable in order to create modular front- and back-ends.</p><p><em>This concludes part 1 of ‘How a Compiler Works’. In the second part, we continue examining the back-end of the compiler and how intermediate representation trees are transformed into optimized assembly code.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=36fce5f8f0d0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Recommendation System from Unreliable Information]]></title>
            <link>https://medium.com/@adisrini/building-a-recommendation-system-from-unreliable-information-f7936b08fe70?source=rss-8b2671a37ec3------2</link>
            <guid isPermaLink="false">https://medium.com/p/f7936b08fe70</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[recommendation-system]]></category>
            <dc:creator><![CDATA[Aditya Srinivasan]]></dc:creator>
            <pubDate>Thu, 11 Aug 2016 18:46:05 GMT</pubDate>
            <atom:updated>2016-08-11T18:48:39.377Z</atom:updated>
            <content:encoded><![CDATA[<h4>An exercise in heuristics</h4><h3>Foreword</h3><p>This summer, I’ve been working as a software engineer at Cinchapi, a technology startup based in Atlanta. The company’s product is a platform for gleaning insights from data, through real-time analytics, natural language querying, and machine learning.</p><p>The underlying back-end technology making the whole thing possible is ConcourseDB, an open-sourced, self-tuning, NoSQL database that offers a more intuitive approach to managing data.</p><p>In my first few weeks of the internship, I spent time getting familiar with the massive codebase, implementing new features and fixing bugs along the way.</p><p>However, the meat of the work I have done has been in developing a recommendation system for visualizations, which we commonly refer to as the <strong>visualization engine</strong>. To understand the motivation behind this project, consider the following scenario.</p><h3>Motivation</h3><p>Imagine you’re the owner of a mid-sized fashion retailer in a busy metropolitan area. Since opening up shop, you have been using a database to keep track of a variety of factors and statistics, including store prices, exchange rates, competitor prices, weather, customer preferences, and more.</p><p>One day, you notice your revenues are dropping. <em>But why? </em>You remember you recently changed the layout of the store, that could be it! Hmm, but it’s also approaching Winter and that affects customers’ tastes, maybe it’s that. Well, of course you may need to consider the fact that your competitor across the street just released a new line of designer handbags, and that’s a plausible cause.</p><p>It’s a catch-22. With such large amounts of data being accumulated through sensors in mobiles, computers, cameras, buildings, cars, and more, it’s increasingly difficult to understand relationships and correlations. At the same time, collecting insufficient amounts of data may lead you to miss out on important problems that you’d miss otherwise, like the fact that customers spend 40% less time in a particular section of your store.</p><p>This is where the power of visualization comes into play. Often overlooked, visualizations allow us to digest data as information. It’s a simple transformation that converts raw, unintelligible matter into actionable, intuitive insight.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*QCE2zU-R9MKX6Sqj5lZNyQ.png" /><figcaption>Maybe not the best example</figcaption></figure><p>Well, “simple” to the extent that individuals understand which visualizations will serve them best. See, there are an abundance of plots and graphs and charts and figures out there, each of which is suited for a particular kind of dataset. Got some categorical data indexed by frequency? Throw that on a bar chart! What about bivariate numerical data abiding by a non-functional relationship? Best use a scatter plot!</p><p>But being able to characterize data as such is difficult for a human, especially if that data contains thousands, if not millions, of entries. Enter the <strong>visualization engine</strong>.</p><h3><strong>Understanding the Problem</strong></h3><p>The objective of the project was fairly clear: help users understand which visualizations will benefit them, based on their data. However, the nature of the solution was open-ended, and related to the problem. Recommendation systems are a highly researched and published topic, and have seen widespread implementation, most notably in consumer-facing products from companies such as Google, Netflix, Amazon, Spotify, and Apple. But each of these companies employ their systems slightly differently.</p><p>They implement their systems to solve the same general problem of recommending something (whatever it may be) to the user. If this sounds ambiguous, it’s because it is. The specifics of a recommendation system often rely on the problem being solved, and differ from one use case to the next. We can broadly classify systems into a dichotomy: dynamic recommendation vs. static recommendation.</p><h4><strong>Dynamic</strong></h4><p>This is the category of recommendation system employed by Google search, Netflix, Amazon, and Spotify. These systems collect data to profile the user, through past transactions and behavior, and recommend items viewed/bought by others with similar profiles. Alternatively, the system characterizes items and recommends items with similar profiles to those viewed/bought by the user in the past.</p><p>For example, after a bout of researching Apache Spark on Google, I began to type the letters <strong>‘ho</strong>’ and search autocompletion provided the rest:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FrEvO9PieRMLUKgHjG4tPQ.png" /><figcaption>Google search: recommendations based on user history</figcaption></figure><p>Of course, Hortonworks is a company focusing on the development of other Apache platforms, such as Hadoop. Google understands the topic I’m interested in through my history, and decides to open some related doors.</p><p>After that, I decided to look up a recipe for Eggs Benedict. Then, I typed the same letters and autocompletion offered to finish my sentence:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9os9HdBGphWat-oEqmkBEA.png" /><figcaption>Contextual recommendations</figcaption></figure><p>Immediately, I’m offered with suggestions relating to my most recent searches.</p><p>This system is dynamic in the sense that the user’s profile is ever-changing as they continue to use the product, and the recommendation evolves to suit the newest and latest information.</p><h4><strong>Static</strong></h4><p>On the other hand, the systems employed by Google images and Apple’s predictive text can be described as largely static recommenders. These systems do process user behavior and history, but do not use these (to a large extent) to influence their recommendations.</p><p>For example, observe the following stream of messages and the Predictive Text output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*CRkNcnQRzgkR7BwLDH6jLg.png" /><figcaption>Trying to get Siri’s attention</figcaption></figure><p>Unlike the example from Google search earlier, it seems as if Predictive Text does not completely base recommendations on user history. I say “completely”, because Predictive Text actually suggested ‘Siri’ after I had typed ‘Hi Siri’ twice, but reverted to a generic array of predictions after I sent the the third one (maybe Siri got annoyed).</p><p>It is extremely important to note here that Predictive Text is in no way worse than Google’s search suggestions. They are both trying to solve <em>completely</em> different problems.</p><h4>The Google Search Problem</h4><p>The problem that Search is addressing is a way to improve search experience for users by opening them to new, yet related, doors. After looking up a recipe to Eggs Benedict, I was serenaded with recipes for home fries, poached eggs, hollandaise sauce, and more. This kind of system, building on the user’s cues and profile, makes perfect sense.</p><h4><strong>The Predictive Text Problem</strong></h4><p>The problem that Predictive Text is addressing is quick, yet coherent, sentence construction. Many individuals use shorthand, improper grammar, and unknown words when texting. To train a system to propagate this kind of language would lead to a broken system. No, I don’t want to type “soz”, I’d actually prefer “sorry” in this case. This kind of system needs a separate set of rules, if you will, by which it operates. The user is unreliable and the system should not mimic them. For this case, this design makes perfect sense.</p><h3>The Customer is Not Always Right</h3><p>Classification helps when breaking down problems. If I can find a problem to which mine is similar, I can abstract similar concepts and apply them to my case. I kept this in mind when ideating the solution that my visualization engine would embody.</p><p>Thinking about the two classifications above, I identified that my solution would take the form of a static recommender. The underlying assumption motivating the project was that users have trouble picking appropriate visualizations for their data, so it would not make sense to build a model that recommended choices based on their behavior. If a user picked a bar chart for absolutely everything, would it make sense for the model to also recommend a bar chart for everything? In this case, the customer is not always right.</p><h3>The Item-User Feature Matrix</h3><p>It’s a mouthful, but it’s an important concept. Let’s back up a bit.</p><p>As I mentioned earlier, a common way to produce recommendations is to compare the tastes of one user to other users. Let’s say User A is most similar to User Z. The system will then determine the items that User Z liked the most that User A has not yet seen, and recommend those. The issue with this approach for our use case is that there is no community of users between which profiles can be compared.</p><p>Alternatively, recommendations can be made on the basis of comparisons between items themselves. Let’s say User A loves Item P. Each item is given its own profile, through which it is quantifiably characterized across several ‘features’. Then, suppose Item Q is very similar to Item P. User A would probably like Item Q, right? So, the system recommends it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rd1dB7GR5QGGgF5tsfDwfw.png" /><figcaption>Example Item Feature Matrix</figcaption></figure><p>The figure above is called an item feature matrix, since each item offered is characterized along several different features. This is closer to what we want, but it’s not perfect. We can’t base our recommendations on what the user likes, since the user may not be right. We must incorporate another dimension.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WANzj05iI0M3pMpzD3S3ug.png" /><figcaption>Example User Feature Matrix</figcaption></figure><p>The above matrix is called a user feature matrix, as it depicts the preferences of each user along the same features as the items.</p><p>Combining the two concepts, we have two matrices, one for characterizing the user and one for characterizing the items. Collectively, these are considered the item-user feature matrix.</p><p>In our case, we don’t characterize the user’s preferences, but rather their data within ConcourseDB. Further, we don’t characterize by the number of characters, action scenes, length, and rating, but a series of data characteristics relating to data types, variable types, uniqueness, and more. This provides a framework to quantifiably determine the similarity between the user’s data and possible visualizations. This is one piece of our system, the DataCharacterizer, which serves to characterize the user’s data across some set of characteristics. But how do we characterize the items, in our case the visualizations, themselves? We employ a heuristic.</p><h3>Heuristics</h3><p>So, considering the case of Predictive Text, there is some core ‘rulebook’ from which recommendations originate. For a language predictor in general, this may be in the form of an expression graph or Markov model, where vertices are words, a connection represents a logical next word in a sentence, and each edge is weighted by a certain probability or likelihood.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uPqr7P5g4AiwWvgJO6-pNg.png" /><figcaption>Expression graph</figcaption></figure><p>This could explain why repeatedly tapping Predictive Text suggestions produce something like this as a result of a cycle in the graph:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*txkiPvabU8eqxrhKmO4ICg.png" /><figcaption>Nonsen-cycle</figcaption></figure><p>In the case of a visualization engine, however, where is the literature? There is no ‘rulebook’ of any sorts that a model can be trained upon, at least not of a size or magnitude that would produce meaningful results.</p><p>This is where the heuristic process comes into action. Loosely defined, a heuristic is an approximation. More formally, it is an algorithm designed to find an approximate solution when an exact solution cannot be found.</p><p>This formed the basis of my recommendation system, and resolved the problem of having incomplete or unreliable data from which to learn. I developed a table, where the rows represented the same features as in the matrices above, and the columns represented different visualizations. Each visualization was characterized based on the kind of data that it would best represent.</p><p>This is another piece of the system, a HeuristicTable, which holds pre-defined, static characterization across the same set of characteristics as the user’s data for each visualization.</p><h3>Pulling the Pieces Together</h3><p>The bulk of the system is comprised of the two aforementioned components. I’m glossing over the details of the DataCharacterizer, but it measures a series of characteristics of the user’s data, namely the percentage of Strings, Numbers, and Booleans, whether or not there are linkages between entries, whether or not the data is bijective, the uniqueness of values, and the number of unique values (dichtomous, nominal, or continuous).</p><p>Treating a particular characterization as a vector, a cosine similarity function is executed on the user’s data and each column of the HeuristicTable, which measures the similarity between two vectors on a scale from zero to one.</p><p>From this point, it’s a matter of sorting the results in descending order of similarity and the recommendation set is ready.</p><p>Below is an overview of the system’s design:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1F8fufM451JtsOPtv_Y-Qw.png" /></figure><h3>Closing Thoughts</h3><p>Recommendation systems come in all shapes and sizes. Although the problems seem similar from a 10,000 feet view, each use case requires a unique solution to propose the best experience for users.</p><p>This was how I built a recommendation system from unreliable data, and I hope it inspires some new ideas.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f7936b08fe70" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MedTech or FedTech?]]></title>
            <link>https://medium.com/@adisrini/medtech-or-fedtech-5b7582e66d1c?source=rss-8b2671a37ec3------2</link>
            <guid isPermaLink="false">https://medium.com/p/5b7582e66d1c</guid>
            <category><![CDATA[startup]]></category>
            <category><![CDATA[venture-capital]]></category>
            <category><![CDATA[healthcare]]></category>
            <category><![CDATA[medicine]]></category>
            <category><![CDATA[medical-devices]]></category>
            <dc:creator><![CDATA[Aditya Srinivasan]]></dc:creator>
            <pubDate>Wed, 06 Jul 2016 07:11:34 GMT</pubDate>
            <atom:updated>2018-01-20T23:54:39.209Z</atom:updated>
            <content:encoded><![CDATA[<p>Technology is a field defined by symbiosis. While the field itself has seen leaps and bounds in progress, it has also fostered advancements in many other realms. Transportation, communication, education, and recreation are common facets of our routine, and have all been enhanced by the boon of technology. One of the most productive recent trends in technology has been that of medical innovation. It is a kind of ingenuity that saves or extends lives. Breakthroughs in <a href="http://newsroom.ucla.edu/releases/cutting-edge-technology-optimizes-cancer-therapy-with-nanomedicine-drug-combinations">drug development</a>, <a href="http://www.govtech.com/health/Technology-is-Changing-How-Doctors-Diagnose-Treat-Patients.html">patient diagnosis</a>, <a href="http://www.chicagotribune.com/business/ct-drug-interactions-signal-detection-met-20160209-story.html">synergy determination</a>, and even <a href="https://www.nibib.nih.gov/sites/default/files/Ballpoint%20Laparoscope%20Project.pdf">surgical procedures</a> have all been facilitated by technological innovations. But with high costs of pharmaceutical and medical R&amp;D and stringent regulations, how long can this <a href="https://www.aei.org/publication/the-golden-age-of-medical-innovation/">Golden Age of Medicine</a> continue?</p><h4>Venture capitalism to the rescue</h4><p>The road to biotech and pharmaceutical commercialization is long, and expensive, and hurdles are abundant, as depicted by the timeline below, demonstrating the average development process for a drug.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/845/1*S1A4x3jM9s1a4Xd_2KbCIg.jpeg" /><figcaption>The long and treacherous road.</figcaption></figure><p>But at the same time, many of the medical innovations heralded today spawned from small startups. How do a dozen ambitious individuals provide the millions of dollars necessary for medical development? Well, they don’t; at least not by themselves.</p><p>According to a <a href="http://nvca.org/research/stats-studies/">report</a> written by the National Venture Capital Association (NVCA), venture capitalists have been responsible for an estimated $108 billion of investment between 1980 and 2012 in 4,600 life science companies, such as Genentech, 23andMe, and Onyx. This comprises 19% of venture investment in that period. When one looks at the costs of development, it is understood why the big wallets of VC firms are needed to sustain the proliferation of medical technology.</p><p>But if current trends continue, the bills to pay may completely outgrow the size of their wallets. As highlighted by an <a href="http://www.scientificamerican.com/article/cost-to-develop-new-pharmaceutical-drug-now-exceeds-2-5b/">article</a> in Scientific American, the cost of developing and commercializing a prescription drug has climbed to $2.9 billion. After correcting for inflation, this translates to a 162% increase on the estimate made in 2003. Understandably, venture investment in the life science sector has seen a decline in recent years, with many VCs unwilling to allocate their resources. The big question is “what is the problem that is causing this decline”? And the answer does not have a simple solution.</p><h4>FDA: friend or foe?</h4><p>According to the report by the NVCA, the time and cost of backing med-tech startups has been steadily increasing, illustrated by the charts below. This has prompted many VCs to shift focus from the sector of life sciences to others with less risk and greater return. Good for them, bad for medical entrepreneurs. At this point, you’re probably thinking “Okay, the increase in cost and risk regarding med-tech investment caused the decline in VC investment, but what causes the increase in the first place?” Ultimately, it comes down to the draconian regulations of the Food &amp; Drug Administration, commonly referred to as the FDA.</p><p>In a <a href="https://audreysnetwork.files.wordpress.com/2012/01/vital_signs_full_data_deck.pdf">survey</a> named Vital Signs, conducted by the MedIC coalition of NVCA comprised of venture capitalists and portfolio life science companies, it was found that 60% of VCs “identified the increasing cost and uncertainty in obtaining FDA approvals as having the highest impact on venture investment.” This risk is evident; according to a study by the Independent Institute, only 8% of drugs in development make it to the stage of approval. The rate of success of drugs eventually entering the market is even lower, given approval has to then be obtained. It is alarming to imagine that masses of growing investment costs are spent on products that never make it to market more than 92% of the time. So the FDA must be evil right?</p><p>Not exactly. While FDA regulations are harsh, they are warranted. When it comes down to innovations that claim to save lives, it is important that this claim is supported. The subdivision responsible for the regulation and safety of medical devices, the Center for Devices and Radiological Health (CDRH), classifies medical devices as one of three classes according to the level of risk involved. Each class has its own set of hoops through which companies must jump in order to attain FDA approval. All devices require sufficient clinical data from trials to prove its efficacy, large populations of volunteers to treat, and volumes of paperwork to complete. Costly? Yes. But in the context of human lives? Necessary.</p><h4>What to do?</h4><p>It seems that there is an inherent tradeoff and complex relationship between the amount of innovation inspired and/or approved, and the safety of those using them. In recent years, the MedIC coalition has worked closely with the FDA to foster meaningful reform that would promote investment in the life science sector. Solutions have included increasing predictability, efficiency, and speed of FDA decisions, allowing communication between the FDA and medical innovators to be more transparent. Despite common belief, the two entities are ultimately working as one, with the common goal of propagating efficient and reliable medical technology.</p><p>On a related note, the landscape of medical technology innovation is often competitive; this is the root of another problem. By increasing transparency within the network of med-tech companies, better informed decisions can be made. Open sourcing technology and information eliminate duplication of studies and development, thereby reducing costs of development.</p><p>The future of medical technology is bright, and when we realize that we are all working towards the same goal, we will make our way towards it.</p><p>If you want to check out any more of my work, or learn more about me, please check out <a href="http://adisrini.github.io/">my website</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5b7582e66d1c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>