<?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 Christian Ang on Medium]]></title>
        <description><![CDATA[Stories by Christian Ang on Medium]]></description>
        <link>https://medium.com/@christianang86?source=rss-b971c70e1db4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*cuZN5PKNTGCHdLkO5WmUOQ.jpeg</url>
            <title>Stories by Christian Ang on Medium</title>
            <link>https://medium.com/@christianang86?source=rss-b971c70e1db4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 14:37:38 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@christianang86/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[Open Sourcing my 3b1b Doppel Solution: A Math Agentic Framework]]></title>
            <link>https://medium.com/@christianang86/open-sourcing-my-3b1b-doppel-solution-a-math-agentic-framework-49ecee5db269?source=rss-b971c70e1db4------2</link>
            <guid isPermaLink="false">https://medium.com/p/49ecee5db269</guid>
            <category><![CDATA[kl-divergence]]></category>
            <category><![CDATA[kkt-conditions]]></category>
            <category><![CDATA[doppels]]></category>
            <category><![CDATA[mathematics]]></category>
            <category><![CDATA[ai-agent]]></category>
            <dc:creator><![CDATA[Christian Ang]]></dc:creator>
            <pubDate>Sat, 19 Sep 2026 14:59:55 GMT</pubDate>
            <atom:updated>2026-09-19T14:59:55.372Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi everyone! While I’ve been updating my ChatGPT Chef recently, I came across a really interesting problem found from 3b1b’s page. Since Math is open source, I shall state it below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/744/1*9CpD2_SNIWuG_hHDpuUZ8A.png" /><figcaption>Credit: 3blue1brown website</figcaption></figure><h3>Intuition and Initial Thoughts</h3><p>During my time at Moonworks working on model distillation algorithms, I came across a a concept to help to determine how different 2 softmaxed logits are when distilling audio models. This measured how “different” 2 data points are to improve the overall knowledge of the smaller model.</p><p>This concept was called KL-divergence, and I instantly recognized this in the alarm function above. Well this meant that we can reduce the problem to finding the maximal attacker distribution <em>p</em> for the KL-divergence problem given a known <em>q</em>.</p><p>This instantly gives us the intuition that we would expect some element of inverse exponential functions to reward those with higher <em>sᵢ</em> and disincetivize those with lower <em>sᵢ</em>. Combining this with my 10–301 knowledge immediately led me to the Softmax function and turns out this is essentially the solution that ChatGPT gave me.</p><p>No way it was this simple right… And that’s why I built an AI agent to verify the logic and formalize the proof <a href="https://github.com/porkboi/doppel-3b1b-solution">here</a>.</p><h3>Architecture of Agent</h3><p>The agent has a particular “Review mode” which follows a propose → challenge → revise workflow controlled by Python, with four Claude agent roles:</p><ul><li>Alternative: independently derives a solution without seeing the proposer’s answer or the reference solution.</li><li>Proposer: writes the main solution and revises it when problems are found.</li><li>Critic: looks for mistakes, counterexamples, and better answers.</li><li>Proof verifier: checks whether the proof establishes global optimality.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JsRZmG8KR1mK54ybN_iK0w.png" /><figcaption>Agent Architecture</figcaption></figure><h3>Findings</h3><p>The agent loops were done using LangChain, and turned out really really well, producing JSONs of explored ideas, and rejecting non-watertight ideas. Even though I was merely using Claude Sonnet 4.6 on my credits from YC Startup School.</p><p>Mathematically, it did identify 3 different cases, where C = 0, 0 &lt; C* &lt; C, and 0 &lt; C &lt; C*, and it did manage to use the Karush–Kuhn–Tucker (KKT) conditions to solve for and prove that this is a global minimum, derived directly from the KL-divergence equation, and arrived at the same answer.</p><p>Moreso, the Agentic system did make only 1 glaring mistake — which was actually really funny because it made a sweeping statement that if C&gt;0, then we follow the derived condition. This is clearly false as if C* &lt; C, then we can just keep sending the message with maximum payoff repeatedly. And honestly, it made me wonder how we could improve agentic systems to reference minute details like these more effectively.</p><p>Tags: Doppel, 3b1b, KKT, KL-divergence</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=49ecee5db269" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ChatGPT Chef Adventures]]></title>
            <link>https://medium.com/@christianang86/chatgpt-chef-adventures-64c3132a7cc3?source=rss-b971c70e1db4------2</link>
            <guid isPermaLink="false">https://medium.com/p/64c3132a7cc3</guid>
            <dc:creator><![CDATA[Christian Ang]]></dc:creator>
            <pubDate>Sat, 08 Nov 2025 19:47:33 GMT</pubDate>
            <atom:updated>2026-08-29T17:38:01.437Z</atom:updated>
            <content:encoded><![CDATA[<p>As I share what I cook with my friends, i have often gotten a lot of requests for recipes and stuff. Well lo and behold, as a self-declared expert prompt engineer, I actually ChatGPT most of my recipes and pray it works out. I decided to include some of the recipes below so that my fellow Asian Diaspora kids can learn some relatively simple recipes!</p><p>This will also be live updated.</p><ol><li>Char Siew: <a href="https://chatgpt.com/s/t_690f9c9f44bc8191965cdf6c78cc054b">https://chatgpt.com/s/t_690f9c9f44bc8191965cdf6c78cc054b</a></li></ol><p>Christian’s Strange Tip: I dont know why but if you add sake it increases the flavour depth and actually marinate overnight trust.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4MMlsuJwKoLxZYH3tuRgWA.png" /></figure><p>2. Bulgolgi Beef: <a href="https://chatgpt.com/s/t_690f9d9e7e508191ac27f3a6a390dd08">https://chatgpt.com/s/t_690f9d9e7e508191ac27f3a6a390dd08</a></p><p>Christian’s Strange Tip: Keep the beef moist, try to use shabu shabu if you like silky texture, but if you use sirloin top, trust you should keep these moist. Also do the Chinese Resturant Wagyu hack.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/575/1*ZpaOhwDmF22e7pjaqHlnvQ.png" /></figure><p>3. Dill and Lemon Salmon: <a href="https://chatgpt.com/s/t_690f9dc2ddd881918247bda44c3ff550">https://chatgpt.com/s/t_690f9dc2ddd881918247bda44c3ff550</a></p><p>Christian’s Strange Tip: Dill brings out this interesting herbal side to the dish.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jk2HRqDJmVcU6Tgr65awOw.png" /></figure><p>4. Stir-fried beef horfun: <a href="https://chatgpt.com/s/t_6a93184a09ac819191faf6ad4d796343">https://chatgpt.com/s/t_6a93184a09ac819191faf6ad4d796343</a></p><p>Christian Strange Tip: Marinate the noodles ahead of time for a nicer char; also replace the water in the recipe with chicken stock and add pepper at the end.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*FKHPQQC3G2M2bIik1B_s6Q.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=64c3132a7cc3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A quick but not too simple introduction to Lattice-based Cryptography and the LLL Algorithm.]]></title>
            <link>https://medium.com/@christianang86/a-quick-but-not-too-simple-introduction-to-lattice-based-cryptography-and-the-lll-algorithm-e3ba4b427c1c?source=rss-b971c70e1db4------2</link>
            <guid isPermaLink="false">https://medium.com/p/e3ba4b427c1c</guid>
            <category><![CDATA[polynomial]]></category>
            <category><![CDATA[modules]]></category>
            <category><![CDATA[cryptography]]></category>
            <dc:creator><![CDATA[Christian Ang]]></dc:creator>
            <pubDate>Sat, 20 Apr 2024 15:10:31 GMT</pubDate>
            <atom:updated>2024-04-20T15:10:31.342Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi guys, welcome to another complicated article after a long hiatus. Just started college so I guess updates will be more frequent.</p><p>Anyways, in our previous article, we discovered and analysed commutative encryption which works but impractically. Wow that sucks! Since today is opposite day again, I shall introduce an encryption algorithm that actually works, and how we could try to break it, and SUPRISE!! it can’t be broken, just yet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*u5vmJh0xXZyjEgZq" /></figure><h3>Star Wars Recap</h3><p>The Star Wars Lightsabre is made of up 2 main parts — Dithilium, the gas in the light sabre; and Kyber, the crystals in light sabre. As sus as this sounds, Dithilium and Kyber are the names of post-quantum encryption algorithms by PQ-Crystals (PQC), which is kinda troll if you ask me.</p><p>Kyber is what we’ll be focusing on today. Built around the shortest vector problem and perturbation theory, it is the current NIST standard for PQC.</p><p>I worked on this encryption system 3–4 months ago, where I barely understood the true meaning of what it was really doing. But after some insightful classes with the diet-coke addicted John Mackey at CMU, I saw the real beauty of Kyber on so many more levels.</p><p>As such, without further ado, take it away Mary Sue.</p><h3>Kyber</h3><p>For those of y’all familiar with computational complexity, Kyber is built around the shortest vector problem (SVP), which essentially claims that the shortest vector of a lattice cannot be found in Polynomial Time, O(n^i), for linearly independent basis matrices of dim &gt; 2. This is a non-trivial finding as without this shortest vector, we are unable to compute secrets embedded within vectors.</p><p>As such, enter RING THEORY {skull emoji}.</p><p>Kyber operates about two modulo groups, namely:</p><ol><li><em>q</em> — A large (enough) number, let’s say this is 3329, and;</li><li><em>p</em>— A polynomial with (actually) large degrees.</li></ol><p>By taking some <em>n</em> by <em>n</em> matrix <strong><em>A</em></strong><em> </em>with each<em> </em><strong><em>A</em></strong><em>ᵢ,ⱼ </em>a polynomial of some degree, as well as out secret key <em>s</em>, which is an <em>n</em>-dimensional vector, and finally, some <strong>small </strong>perturbation parameter <em>e</em>, another <em>n</em>-dimensional vector. We get a public key (tuple), (<strong><em>A</em></strong>, <em>t</em>) , defined by:</p><p><em>t</em> = <strong><em>A</em></strong><em>s</em> + <em>e</em></p><p>Where quite clearly, e perturbates the vector to prevent recovery of A through matrix inversion algorithms. (which are largely polynomial time through diagonalisation).</p><p>And yes the nerd talk does not end here, we instead head from the comforts of 21–241 to 21–128!</p><p>We can encode some message desired to be sent in terms of binary. As I am horny and down bad, consider <em>m</em> = 69. 69 in binary is 1000101, which suggests we will be dealing some polynomial of degree 6 minimally. By taking every binary input multiplied by <em>floor</em>(<em>q</em>/2) as a coefficient of a polynomial, we get:</p><p>69 := 1664x⁶ + 0 x⁵ + 0x⁴ + 0x³ + 1664x² + 0x + 1664</p><p>So much for a 69. Then, let’s generate some more small vectors to perturbate the vector even more because seecurereetee. Let’s generate:</p><p><strong><em>r</em> </strong>— some n x 1 list</p><p><strong><em>e1</em></strong> — another n x 1 list, and,</p><p><em>e2</em> — a integer</p><p>And we get another tuple as our output (<strong><em>u</em></strong>, <em>v</em>):</p><p><strong><em>u</em></strong> = <strong>A</strong>ᵗ <strong><em>r</em></strong> + <strong><em>e1</em></strong></p><p><em>v</em> = <strong><em>t</em></strong>ᵗ <strong><em>r + </em></strong><em>e2</em></p><p>The decryption process begins with obtaining some noisy message mₙ:</p><p><em>m</em><strong><em>ₙ</em></strong> = <em>v</em> — <strong><em>s</em></strong>ᵗ<strong><em>u</em></strong></p><p>The result is some large, noisy polynomial, and for every coefficient of the polynomial, we determine if it is closer to (0 or <em>q</em>) or <em>q</em>/2 to recover the message in binary, to 0 and 1 respectively.</p><p>TLDR: <a href="https://cryptopedia.dev/posts/kyber/">https://cryptopedia.dev/posts/kyber/</a></p><p>We haven’t even reached the hardest part of this article yet.</p><h3>The Lenstra-Lenstra-Lovatz Algorithm:</h3><p>When I first told my friends I was looking at the LLL Algorithm, I started seeing numerous orthogonal finger appendages on their foreheads. And yes, very many Ls did I take.</p><p>This Algorithm aims to find a small integer vector in a given lattice formed by some matrix, and there’s probably some other medium writer better than me that has probably explained this better than I possibly can. But TDLR, it uses orthogonalisation processes to estimate projections from 1 vector to another, and rounds off the coefficients (length of the vector /projectiom length).</p><p>This has 1 issue: It does not guarantee the shortest possible vector. BUT YES! It is an O(n^2) complexity algorithm when implemented in its essence.</p><p>Originally, Lensta used the Gram-Schmidt Orthogonalisation, which I credit my learning of it to Jason Howell, but I don’t like that. For real, floating points are not fun to deal with. Since matrices are full-rank in this example, then we can use this other orthogonalisation function, called the Givens’ Rotation. What makes this fun? The visualisation of orthogonalisation. This can be found in my paper at <a href="https://github.com/porkboi/LLL/blob/main/Internship%20Report.pdf">https://github.com/porkboi/LLL/blob/main/Internship%20Report.pdf</a> but lowkey it does the same thing as LLL but with better space efficiency.</p><p>But yes, the LLL-algorithm with the Givens’ Rotation proves to be extremely effective at finding a short vector in a lattice defined by the 256 x 256 matrix formed in Kyber-256, and all the more this makes sense through the homogenization of the matrix.</p><p>Most notably:</p><p><em>t</em> ≡ <strong>A</strong><em>s</em> + <em>e</em> (mod q)</p><p>This means that it can be represented in some Linear Diophantine equations, and hence some vector subspace defined by:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/248/1*mpcsI2-Arpsst2HNrV7rdw.png" /><figcaption>Stolen from my paper</figcaption></figure><p>Naturally, through the process of homogenisation, we have:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/321/1*MWEAt8cVlzBkohd278MZLg.png" /><figcaption>More stolen stuff</figcaption></figure><p>And the shortest vector that exists within this B matrix proves to the reversed-engineered secret key and perturbation vector.</p><p>So, what is the significance of this finding? It trivialises the entire Kyber Cryptosystem if some Polynomial-time SVP algorithms. Though such algorithms exists, they are not NP-deterministic, and example include the Ajtai’s Markov Chain Algorithm, which I lowkey think is alluding to the usage of reinforcement learning in hacking (why don’t we actually weight the output by the proximity of the output of some input to a small vector).</p><p>Anyway, the LLL vector rounds down the projection of <em>u</em> onto <em>v</em> in the GSO to the nearest integer, because lattices are discrete. This allows the triangle inequality and Cauchy-Schwartz inequality to be satisfied, and most notably, causes vectors to be reduced by a “discretised” Pythagoras Theorem defined by:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/343/1*uqSxIWoSzgC4ZppmqhKToQ.png" /><figcaption>Honestly this explanation is too technical to be funny, please read my paper is you are actually interested in learning about the Algorithm.</figcaption></figure><p>The LLL-Algorithm guarantees that vectors are (1) size-reduced and (2) satisfy the Lovatz Condition:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/1*3cNN8uU3cI6tc0w6b_ULOQ.png" /><figcaption>LLL Algorithm stuff</figcaption></figure><p>With a guarantee that it returns some short vector:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/211/1*HTBx3YY7aFf3WfNN0Mi3wA.png" /></figure><p>And terminates in O(n²) time, as defined by the monovariant:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/108/1*2cG28ImLjc0vTwfkQZbTDg.png" /></figure><p>This is just about as far as math can get us theoretically, but by inspection, we observe that there are very many more optimisations that can be made to return a shorter vector, and via the definition of some SVP Oracle, determine if the vector returned is really short enough to hack Kyber.</p><h3>Deep Insertion:</h3><p>When considering the LLL algorithm, one notices that an inherent limitation is that “redundant” moves are done, that is, if vectors are going to be swapped and scaled in the future, is there a need to make trivial swaps and scales right now?</p><p>To circumvent this, one simple but unprovably effective fix could be looking <em>n </em>steps forward, called the <em>n-LLL </em>or deep insertion algorithm.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/886/1*J_hxgRMrIpWQd5u9960N9Q.png" /><figcaption>Modified Lovatsz condition</figcaption></figure><p>In this way, by temporarily breaking and achieving this invariant (just like AVL trees), the algorithm runs faster to the end point.</p><h3>Final Notes:</h3><p>Code and research document can be found here and FINALLY THIS ARTICLE IS DONE AFTER 1 YEAR!!</p><p><a href="https://github.com/porkboi/LLL">https://github.com/porkboi/LLL</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e3ba4b427c1c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What are Abelian Groups and can Functions Commute?]]></title>
            <link>https://medium.com/@christianang86/abelian-groups-and-functions-that-commute-63e5c5aea182?source=rss-b971c70e1db4------2</link>
            <guid isPermaLink="false">https://medium.com/p/63e5c5aea182</guid>
            <category><![CDATA[commutativity]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[commutations]]></category>
            <category><![CDATA[mathematics]]></category>
            <category><![CDATA[abelian-group]]></category>
            <dc:creator><![CDATA[Christian Ang]]></dc:creator>
            <pubDate>Wed, 12 Apr 2023 15:51:28 GMT</pubDate>
            <atom:updated>2023-07-21T09:35:29.660Z</atom:updated>
            <content:encoded><![CDATA[<p>Well, welcome to another confusing article!</p><p>I would guess that you are once again here seeking help from unlicensed, underpaid medium writers because you have trawled through the internet in search of “Commuting Functions” or have spent hours on Crypto exchange only to yield with next to nothing. Well fear not, I was in that position and this article condenses what you need to know about commutative functions.</p><p>In previous article, I had iterated the non-commutative nature of certain mathematical functions, such as the Vector Cross functions, causing vector “spins” in different direction with each transformation. As such, since it’s opposite day, we shall discuss and explore some examples of commutative functions and how these can be used as encryption types.</p><h3>What Commutes?</h3><p>Well, I do and you do on the train, but so do Abelian Groups in the Mathematical Realm!</p><p>Such groups can be said to be “non-sequentially affective”, wherein order does not matter when operations are applied to the set of numbers. For example, three groups of integers (<em>a</em>, <em>b</em> and <em>c</em>) are commutative (or more specifically, associative) about multiplicative functions, such that:</p><p><em>(a × b) </em>× c<em>= c × (a × b)</em></p><p>As opposed to the vector cross in the article <a href="https://medium.com/@christianang86/alternative-means-of-solving-euler-angles-without-gimbal-lock-edbc0502d168">here</a>.</p><p>A particular use case for this could be in network packet encryption, as reliability and consistency in output results allow for maintaining the confidentiality and integrity of encryption environments when packets are in transit. An example of a Network Set-up that requires such encryption ciphers could be:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/889/1*KScHZ672eDdQcfUeZeLVgg.png" /><figcaption>Figure 1: Commutative Encryption network setup</figcaption></figure><p>In other words, the difficulty in getting such ciphers and functions to work lie in the difficulty of decrypting and “inner” environment 1, with environment 2 still intact.</p><p>Think of it as a multi-layered cake (which is absolutely not a lie). The challenge? Removing an inner layer without touching the outer layer. Now while that’s impossible tangibly, numbers are intangible, meaning we can bash any physical laws we know when dealing with them!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*g-k_E8ilhZAHFz3R.gif" /><figcaption>Figure 2: Gravity Falls reference</figcaption></figure><h3>Encryption and Decryption in Mathematical Terms</h3><p>Now I am aware that this is primarily a Math article, so I shall break down the concepts of encryption and decryption. In infosec, these mean “to encode” and “to decode” respectively, showing a direct causal undoing relationship between the two terms. As such, a lose definition in Math could be:</p><p>Encrypting x: <em>f(x) = y</em></p><p>Decrypting y: <em>f ⁻¹(y) = x</em></p><p>Yes, inverse functions are what come to mind. So now that that’s set, let’s start with the real Math.</p><h3>The Commutative Function</h3><p>Assuming x is the initial packet of data to be transmitted, the most basic form of commutative encryption involving two functions being applied to x can be defined as:</p><p><em>f ⁻¹ g f(x) = g(x)</em></p><p>Naturally, this implies the need for inversing functions in one way of another. Since such functions will have to yield in the same outcome when inversed, suggesting the need for periodicity of some sort, with exactly one non-zero solution yielded.</p><p>In particular, trigonometric functions and their inverses would come to mind, but only the cosine an arccosine curve, possesses one non-zero solution, as shown in Figure 3. This intersection point is important, as it determines the presence of a non-stationary Points of Inflexion (POI) in later chained functions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/538/1*imUR0G1APcFFSRZiqg38jg.png" /><figcaption>Figure 3: Screenshot from Desmos.com showing the correlation between the two</figcaption></figure><p>This suggests how the baseline of commutative functions could be built on:</p><p>(1):<em> cos ⁻¹ (cos (x)) = x</em></p><p>But that would be too easy for hackers, wont it? Looking at you APT13.</p><p>As such, in some research paper that I accidentally lost the citation to, it states the need for functions that possess half-periods (<em>ω</em>), which are functions that are symmetrical about their periods divided by 2.</p><h3>What are half-periods? No I’ll do you one better. How are half-periods?</h3><p>Half-periods are important in this solution as they often indicate the limits of a 1–1 function. These are made with the exception of non-symmetrical sinusoidal functions (like sine curves), causing periods to repeat when used as a function through each other. As such, proven mathematically, chaining a symmetrical sinusoidal function through an asymmetrical function leads to a circular function generated.</p><p><em>f(x) = sin(cos ⁻¹ (x)) = x∙tan(cos ⁻¹ (x)) = x∙±</em>√{1/[(<em>cos⁻¹ x</em>)² -1]}<em> = </em>|1+(1/x²–1)|</p><p>Logically, the function becomes a non-1–1 function, causing recursion over a range in the middle of both chained graphs fg and gf, which I would call “mirroring”. This proves to be problematic as non-stationary POIs cannot be exploited to determine the values of x and y. Within this in mind, it may not be a good idea to mix two sinusoidal functions together.</p><h3>Types of half-periodic functions</h3><p>As such, half-periods need to define a 1–1 range for the given function in order for the function to be used in this situation, such that f(m,x)=y for Dx=(0,1) are non-convergent.</p><p>An important feature of symmetric half-periods is that they cause a distortion in functions, preventing functions from mirroring themselves, as explained earlier.</p><p>Controversially, this currently only includes four base functions:</p><ol><li>Cosines (cos <em>x</em>), of <em>ω = </em>π</li><li>Exponential Functions (e<em>ˣ / xˣ)</em>, that can be proved in polar form of <em>ω = </em>πi</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/359/1*G9Y4MKdgg_wckWprpcz09A.png" /><figcaption>Figure 4: Exponential Function</figcaption></figure><p>3. Weierstrass Functions (Wα(<em>x</em>)), that I STRONGLY SUGGEST YOU DO NOT TOUCH. But nonetheless, its a continuous fractal curve for <em>ω = </em>1. (Not so fun fact: they include the use of imaginary numbers!)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/509/1*0AKLuIzTOjJGJzJIn-qG1A.png" /><figcaption>Figure 5: Weierstrass Function (Source: Chebfun)</figcaption></figure><p>4. Clausen Functions (Cl(θ) / Sl(θ)), that I also suggest not to touch. These are cosine graph derivatives. (Not so fun fact: their correlations through calculus affect its commutative properties, and only odd derivations should be used)</p><h3>Which got me thinking, what if we started chaining the functions together?</h3><p>That means that (1) could be used as a “bridge” between f and g, allowing for a function pattern that could resemble:</p><p><em>e</em>ᵏ (<em>cos ⁻¹ (cos (k(x)))</em></p><p>Where <em>k</em> is an arbitrary constant. The above function however, would not be fully commutative if there was no symmetry in its composition, which is how proposed commutative encryption function is derived.</p><p>(3):<em> y = cos(e</em>ᵏ (<em>cos ⁻¹ (cos (k(cos ⁻¹(x)))))</em></p><p>(4): <em>y = cos(k</em> (<em>cos ⁻¹ (cos (e</em>ᵏ<em>(cos ⁻¹(x)))))</em></p><p><em>f(k,x) = cos (M(k) ∙ cos ⁻¹ (x))</em></p><p><em>g(k,x) = cos (N(k) ∙ cos ⁻¹ (x))</em></p><p>It works, you can punch the calculator.</p><p>Most interesting for (3) and (4), they possess one particular non-stationary POI, which is the crux of data transmission, as the coordinates of that point allow for value referencing.</p><p>As trigonometric functions, <em>f(k,x)</em> and <em>g(k,x)</em> would have clearly defined local maxima and minima, and these can be computed through calculus and range solving, allowing for <em>y</em> (in black) to be solved. Solution can also be scaled to allow for a 1–1 function about Dx=[0,1)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/517/0*vSG1E3pIvQINpUyh" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ciXm2XoAU-WSyDnb" /><figcaption>Figure 6: Plots of functions</figcaption></figure><p>Additionally, variable <em>k</em> will have to play a part in altering periods in <em>M(k)</em> and <em>N(k)</em> to have a necessary impact on ω, or functions will end up mirroring each other with the same output, for example, derivatives or integrals of Clausen functions have the same summation patterns. More practically, <em>k</em> could be a symmetric key in the PKI.</p><h3>Conclusion</h3><p>In conclusion, this commutative proof satisfies the need for reliability in the transit of information through different functions, regardless of order.</p><p>Moreso, in the context of commutative encryption, the non-1–1 properties of the black graph also prevent the reverse engineering of the algorithm. In a sense, protecting the confidentiality of the data in transit, as shown in the figure below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/806/1*MM-HRjrUBt8JTqL4UPsY4w.png" /><figcaption>Figure 7: The Black Graph’s inverse</figcaption></figure><p>This algorithm, however, has its flaws, and too many to be listed below. As such, this such only be used for demonstration and creative purposes.</p><p>Wow demonstrations! Is there code? Absolutely yes to boost my Medium reach. Do take note however, that the code below only processes strings up to 5 characters long due to Python processing limitations.</p><pre>import math<br><br>def zero_round(integer):<br>    if integer &lt; 0.0001:<br>        integer = 0<br>    else:<br>        integer = integer<br>    return integer<br><br>def txt_to_dec(txt):<br>    a = &#39;&#39;.join(format(ord(x), &#39;b&#39;) for x in txt)<br>    b = float(&quot;0.&quot; + str(int(a, 2)))<br>    return b<br><br>def dec_to_txt(dec):<br>    a = bin(int(str(dec)[2:]))<br>    b = str(a)[2:]<br>    c = &#39;&#39;.join(chr(int(b[i*7:i*7+7],2)) for i in range(len(b)//7))<br>    return c<br>    <br>def scaled_decimal(txt):<br>    c = txt_to_dec(txt)<br>    d = 0.5*c+0.4035<br>    return d<br><br>def unscale_decimal(dec):<br>    c = (dec-0.4035)*2<br>    return c<br><br>def ikey(message):<br>    decimal = scaled_decimal(message)<br>    m = math.log(math.pi/math.acos(decimal))/10<br>    return m<br><br>def encryption_linear(ikey, u):<br>    enc_l_message = math.cos(ikey*math.acos(u))<br>    return enc_l_message<br><br>def encryption_exp(ikey, u):<br>    enc_e_message = math.cos(math.exp(ikey)*math.acos(u))<br>    return enc_e_message<br><br>def decryption_linear(ikey, u):<br>    if u &lt; 0:<br>        dec_l_message = math.cos(1/ikey*(math.acos(u)))<br>    else:<br>        dec_l_message = math.cos(1/ikey*math.acos(u))<br>    return dec_l_message<br><br>def decryption_exp(ikey, u):<br>    dec_e_message = math.cos(1/math.exp(ikey)*math.acos(u))<br>    return dec_e_message<br><br>import re<br><br>def rounding_logic(decimal):<br>    dec_str = str(decimal)<br>    e = &quot;&quot;<br>    x1 = re.search(r&quot;000&quot;, dec_str)<br>    x2 = re.search(r&quot;001&quot;, dec_str)<br>    y1 = re.search(r&quot;999&quot;, dec_str)<br>    y2 = re.search(r&quot;998&quot;, dec_str)<br><br>    if x1:<br>        a,b = x1.span()<br>        e = e+str(dec_str[:a])<br>    if x2:<br>        a,b = x2.span()<br>        e = e+str(dec_str[:a])<br>    elif y1:<br>        k,l = y1.span()<br>        d = dec_str[:k]<br>        e = e+str(d[:-1]+str(int(d[-1:])+1))<br>    elif y2:<br>        k,l = y2.span()<br>        d = dec_str[:k]<br>        e = e+str(d[:-1]+str(int(d[-1:])+1))<br>    else:<br>        print(&quot;Rounding Error: &quot; + str(decimal))<br>    return e<br><br>#Driver Code<br>message = &quot;Apple&quot;<br>print(&quot;Original Message: &quot; + message)<br>print(&quot;Ikey: &quot; + str(ikey(message)))<br>print(&quot;Original Message Decimal: &quot; + str(txt_to_dec(message)))<br>print(&quot;Message Decimal: &quot; + str(scaled_decimal(message)))<br>single_enc = encryption_linear(ikey(message), scaled_decimal(message))<br>print(&quot;1st Enc: &quot; + str(single_enc))<br>double_enc = encryption_exp(ikey(message), single_enc)<br>print(&quot;2nd Enc: &quot; + str(double_enc))<br>single_decrypt = decryption_linear(ikey(message), double_enc)<br>print(&quot;1st Dec: &quot; + str(single_decrypt))<br>double_decrypt = decryption_exp(ikey(message), single_decrypt)<br>print(&quot;2nd Dec: &quot; + str(double_decrypt))<br>unscaledec = unscale_decimal(double_decrypt)<br>print(unscaledec)<br>rounded = rounding_logic(unscaledec)<br>print(rounded)<br>text = dec_to_txt(rounded)<br>print(text)</pre><p>This an an extremely rudimentary, yet fascinating find into the world of commutative sets and Abelian Groups, which hopefully could be refined in further research.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=63e5c5aea182" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Are there alternative means of computing Euler Angles without Gimbal Lock?]]></title>
            <link>https://medium.com/@christianang86/alternative-means-of-solving-euler-angles-without-gimbal-lock-edbc0502d168?source=rss-b971c70e1db4------2</link>
            <guid isPermaLink="false">https://medium.com/p/edbc0502d168</guid>
            <category><![CDATA[mathematics]]></category>
            <category><![CDATA[trigonometry]]></category>
            <category><![CDATA[quaternion]]></category>
            <dc:creator><![CDATA[Christian Ang]]></dc:creator>
            <pubDate>Sun, 19 Mar 2023 14:00:03 GMT</pubDate>
            <atom:updated>2023-07-21T09:36:15.789Z</atom:updated>
            <content:encoded><![CDATA[<p>If you are here, you probably fear the monstrosity that are Quaternions, and are desperately seeking alternative methods to solve the Perspective Problem. Fortunately, using nothing but Junior-College level mathematics, it is interestingly, very possible to do so.</p><h3><strong>Part 1: Quaternions — What are they, and why you fear them</strong></h3><p>I would assume you have gone through 3blue1brown and/or Numberphile’s in depth explanation of this. But as Miles Morales once said “for the last time…”, let’s take a look at what Quaternions do.</p><p>(1):<em> h = cos(θ)·a + sin(θ)·(bi + cj + dk)</em></p><p>Imagine poking a stick through a paper, they rotate 3 dimensional planes about a defined line vector, allowing you to choose the perspective of the plane you desire through the parameters <em>θ, a, b, c, </em>and <em>d</em>. What are all these in the context of x, y, z planes? I have no idea. And that’s why I tried to find an alternative.</p><h3><strong>Part 2: Trigo-ing the Results</strong></h3><p>Comparing (1) resembled the structure of complex numbers, in the “cis” form:</p><p>(2): <em>z = a+bi</em></p><p>As such, that is where the basis of this proof begins from:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*z8BPAEX5MTDpdJeG_RCo4g.png" /><figcaption>Rotation of points about 2 dimensional x-y plane.</figcaption></figure><p>Point P is rotated about an angle of <em>θ </em>to P’, with the coordinates translated from (<em>a, b</em>) to (<em>a’, b’</em>). RedBeanieMath on Youtube explains this pretty clearly, as such, I shall skip through this proof.</p><p><em>R cos α = a; R sin α = b</em></p><p><em>R cos (α+θ) = a’; R sin (α+θ) = b’</em></p><p>Applying the Addition Formula,</p><p><em>R (cos α·cos θ -sin α·sin θ) = a’; R (cos α·sin θ -sin α·cos θ) = b’</em></p><p>If <em>α = 0 =&gt; R = a,</em></p><p>(3): <em>a’ = R cos θ ; b’ = R sin θ</em></p><p>Equation (3) tells us that a rotated point that exists in 2-dimensional space can be modeled from its “original state”, that is where the initial angle <em>α = 0. </em>Logically, the same can happen in a 3-D plane, where a 3-D rotation can literally be mapped once in the <em>x-y</em> plane, then the <em>x-z</em> plane. Chopping up 3D-rotations assuming <em>α = 0 </em>is crucial to the solution, as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/886/1*l6O6Y8sE9JeUGRk0Za_Glw.png" /><figcaption>Step 1 and Step 2 of 3D-trandformations in a 2-D space</figcaption></figure><p>Given that a starting vector, ṽ = [a, b, c], it is possible to re-map the axes of the vector, such that ṽ starts at the origin. In a sense, creating a micro-graph within a macro-graph, and we can compute the following:</p><p>Step 1:</p><p><em>R = sqrt(a² + b² + c²)</em>, from (3):</p><p><em>d’ = R cos θ₁ ; e’ = R sin θ₁</em></p><p>Step 2:</p><p><em>R = d’ = R cos θ₁, </em>from (3):</p><p><em>d’’ = R cos θ₁ cos θ</em>₂ <em>; e’ = R sin θ₁ ; f = R cos θ₁ sin θ</em>₂</p><p>If you look carefully, this implicitly shows us the rotational rules of Quaternions as well!</p><p>With this, the vector rotated about <em>θ₁ </em>in the x-y plane and<em> θ</em>₂ in the x-z plane is computed. Let’s call this ũ, where ũ = [d’’, e’, f]. ũ “would have been the rotated vector if the starting vector was one-dimensional”, which can also represent another vector in the desired rotation direction of ṽ.</p><blockquote>This would have been the rotated vector if the starting vector was one-dimensional.</blockquote><p>With ũ, the next question would be how to rotate the ũ from the micro-graph, back into the macro-graph, as a 90 degree rotation in the micro-graph would definitely not be the same as that in the macro-graph. And one way this can be done is by calculating an intermediary vector.</p><p>Interestingly, this can include taking the cross product of ṽ and ũ, forming a common normal, which can also be seen as an “Axle” for the movement of ṽ about its imaginary plane, formed with ũ. This will be called ñ.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/543/1*hZDOB0TeAA81blwr9D01Lg.png" /><figcaption>ṽ and ũ in the same plane, and their normal ñ.</figcaption></figure><p>ñ now defines the plane that ṽ can be rotated about, but ṽ will require an upper bound, and fortunately, with our knowledge on how sine waves work, an upper bound can be determined by finding the vector 90 degrees anticlockwise to ṽ, through another cross product of ñ and ṽ, yielding in W̃.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/541/1*CFftaDZQlvF43yqGxYhOiA.png" /><figcaption>Transformation of ṽ to W̃.</figcaption></figure><p>On a whole, the transformation from ṽ to W̃ would be:</p><p>(4): W̃ = (ṽ × ũ) × ṽ</p><p>And it is interesting to note that (4) does not commute, and bears an interesting resemblance to Quaternion rules,.</p><p>With ṽ and W̃, upper and lower bounds of a rotation are defined, and it will be possible to determine the vector of the desired angle (<em>θ</em>)<em> </em>from starting vector ṽ. With the common knowledge that z = cis <em>θ </em>is true, the same logic would apply in a three dimensional plane.</p><p>(5): <em>Õ = ṽ cos θ + W̃ sin θ</em></p><p>With this, we have successfully found the rotated vector, <em>Õ, </em>under the conditions of (1) What is the axis of rotation? (2) What is the angle of rotation about this axis?</p><h3>Part 3: Application to planes</h3><p>Now it would not come as a surprise for me to end off by connecting this to the only real-life use of Quaternions that I am aware of — computer graphics.</p><p>CONCLUSION: For a plane to be rotated, only a point, or the “anchor point” and the plane normal is required for the rotation of the plane, requiring only 1 more parameter as compared to quaternions.</p><p>In a sense, this can provide more precision than Quaternions, as their coefficients tend to be interlinked, causing a calculation nightmare on the developer’s side. Speaking of developers, I have included the code required for vector computation below:</p><pre>import math<br>import numpy as np<br><br>def zero_round(a):<br>    if a &lt; 0.001:<br>        a = 0<br>    else:<br>        a = a<br>    return a<br><br>def normalise(lst):<br>    R = math.sqrt(lst[0]**2 + lst[1]**2 + lst[2]**2)<br>    norm_vector = [1/R*lst[0], 1/R*lst[1], 1/R*lst[2]]<br>    return norm_vector<br><br>def vectorise(a,b,c):<br>    vector_lst = [a,b,c]<br>    print(&quot;Original Vector: &quot; + str(vector_lst))<br>    return vector_lst<br><br>def new_vector(a, b, c, alpha, beta):<br>    R = math.sqrt(a**2 + b**2 + c**2)<br>    a_prime = zero_round(R*math.cos(alpha)*math.cos(beta))<br>    b_prime = zero_round(R*math.sin(alpha))<br>    c_prime = zero_round(R*math.cos(alpha)*math.sin(beta))<br>    new_vector_lst = [a_prime, b_prime, c_prime]<br>    print(&quot;Planar Vector: &quot; + str(new_vector_lst))<br>    return new_vector_lst<br><br>def chain_cross_product(vector_lst, new_vector_lst):<br>    p = np.cross(vector_lst, new_vector_lst)<br>    p1 = p.tolist()<br>    print(&quot;Axle: &quot; + str(p1))<br>    p1_normalised = normalise(p1)<br>    print(&quot;Axle_n: &quot; + str(p1_normalised))<br>    final_vector = np.cross(p1_normalised, vector_lst)<br>    final_vector_lst = final_vector.tolist()<br>    print(&quot;90 deg vector: &quot; + str(final_vector_lst))<br>    #R = math.sqrt(final_vector_lst[0]**2 + final_vector_lst[1]**2 + final_vector_lst[2]**2)<br>    #normalised_final_vector_lst = [1/R*final_vector_lst[0],1/R*final_vector_lst[1],1/R*final_vector_lst[2]]<br>    return final_vector_lst<br><br>def angle_vector(vector_lst, final_vector_lst, theta):<br>    c = zero_round(math.cos(theta))<br>    d = zero_round(math.sin(theta))<br>    angled_vector_x = c*vector_lst[0] + d*final_vector_lst[0]<br>    angled_vector_y = c*vector_lst[1] + d*final_vector_lst[1]<br>    angled_vector_z = c*vector_lst[2] + d*final_vector_lst[2]<br>    angled_vector = [angled_vector_x, angled_vector_y, angled_vector_z]<br>    print(str(math.degrees(theta))+ &quot; degree angled vector: &quot; + str(angled_vector))<br>    return angled_vector<br><br>#Define constants here:<br>a=2.0<br>b=3.0<br>c=1.0<br>alpha = math.radians(90)<br>beta = math.radians(90)<br>theta = math.radians(60)<br>#<br><br>final = angle_vector(vectorise(a,b,c), chain_cross_product(vectorise(a,b,c), new_vector(a,b,c, alpha, beta)), theta)</pre><p>So have fun and don’t fear Quaternions!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=edbc0502d168" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>