{"id":75,"date":"2022-01-31T21:05:00","date_gmt":"2022-01-31T20:05:00","guid":{"rendered":"https:\/\/noiseonthenet.space\/noise\/?p=75"},"modified":"2022-02-08T15:02:41","modified_gmt":"2022-02-08T14:02:41","slug":"polynomial-basics","status":"publish","type":"post","link":"https:\/\/noiseonthenet.space\/noise\/2022\/01\/polynomial-basics\/","title":{"rendered":"Polynomial basics"},"content":{"rendered":"<div id=\"orgd61662c\" class=\"figure\">\n\n<img decoding=\"async\" src=\"https:\/\/i0.wp.com\/noiseonthenet.space\/noise\/wp-content\/uploads\/2022\/01\/post002_plot1.png\" alt=\"post002_plot1.png\" style=\"float:center;\">\n\n<\/div>\nPolynomials post list:\n<ul class=\"org-ul\">\n \t<li>post 1: Polynomial Basics<\/li>\n \t<li>post 2: Polynomials Ring<\/li>\n<\/ul>\nEDITED on February 5th, 2022 to fix the call to polynomials\n\nThis post is the first of a series of about polynomials.  I'm using it as a mean to explore the rust programming language (especially how generic traits relate to algebra) while also learning math subjects.\n\nThe code in this post is available <a href=\"https:\/\/github.com\/noiseOnTheNet\/polynomials001\">on GitHub<\/a> with MIT license.\n\nPolynomials are a fundamental mathematical entity used for a number of interesting applications including:\n<ul class=\"org-ul\">\n \t<li>approximation of more complex functions<\/li>\n \t<li>interpolation<\/li>\n \t<li>error correction codes<\/li>\n \t<li>graphical interpolation of curves (splines)<\/li>\n<\/ul>\nI'm going to work with monovariate polynomials, i.e. polynomials of one variable only\n<div id=\"outline-container-org52ce9e9\" class=\"outline-2\">\n<h2 id=\"org52ce9e9\">the structure<\/h2>\n<div class=\"outline-text-2\" id=\"text-org52ce9e9\">\n\n a polynomial is completely defined by a vector of values in a ring. These represents the polynomial coefficient from the lowest to the highest grade (let's call it <img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=n&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"n\" class=\"latex\" \/>); the highest grade coeddicient is supposed to be different from the zero of the ring, and all coefficient of degree greather than <img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=n&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"n\" class=\"latex\" \/> are supposed to be zero.\n\nMain operation needed to define a polynomial are sum and multiplication thus it can be possible to use rings different from usual built-in types (integer and floating point numbers) as long as multiplication and sum are defined.\n\nThus the data structure will contain a vector of values where sum and multiplication are defined. The vector is needed because we cannot know the length of the coefficient string in advance.\n\nAt first I will add only a public constructor: coefficients should be immutable from the user perspective.\n<div class=\"org-src-container\">\n<label class=\"org-src-name\"><em> Name: poly0-struct.<\/em><\/label>\n<pre class=\"src src-rust\" id=\"poly0-struct\"><span style=\"color: #23d7d7;\">#[derive(Debug)]<\/span>\n<span style=\"color: #ffad29; font-weight: bold;\">pub<\/span> <span style=\"color: #ffad29; font-weight: bold;\">struct<\/span> <span style=\"color: #34cae2;\">Poly<\/span> &lt;<span style=\"color: #34cae2;\">T<\/span>&gt;{\n    <span style=\"color: #dbdb95;\">coeff<\/span> : <span style=\"color: #34cae2;\">Vec<\/span>&lt;<span style=\"color: #34cae2;\">T<\/span>&gt;\n}\n\n<span style=\"color: #ffad29; font-weight: bold;\">impl<\/span>&lt;<span style=\"color: #34cae2;\">T<\/span>&gt; <span style=\"color: #34cae2;\">Poly<\/span>&lt;<span style=\"color: #34cae2;\">T<\/span>&gt;{\n    <span style=\"color: #ffad29; font-weight: bold;\">pub<\/span> <span style=\"color: #ffad29; font-weight: bold;\">fn<\/span> <span style=\"color: #00ede1; font-weight: bold;\">new<\/span>(<span style=\"color: #dbdb95;\">coeff<\/span> : <span style=\"color: #34cae2;\">Vec<\/span>&lt;<span style=\"color: #34cae2;\">T<\/span>&gt;) -&gt; <span style=\"color: #34cae2;\">Poly<\/span>&lt;<span style=\"color: #34cae2;\">T<\/span>&gt;{\n        <span style=\"color: #34cae2;\">Poly<\/span>{ <span style=\"color: #dbdb95;\">coeff<\/span>:coeff }\n    }\n}\n<\/pre>\n<\/div>\nI can also add a test to this file in order to make sure it is compiled properly. I will import Write in order to use a print debug and check all is ok\n<div class=\"org-src-container\">\n<label class=\"org-src-name\"><em> Name: poly0-test.<\/em><\/label>\n<pre class=\"src src-rust\" id=\"poly0-test\"><span style=\"color: #23d7d7;\">#[cfg(test)]<\/span>\n<span style=\"color: #ffad29; font-weight: bold;\">mod<\/span> <span style=\"color: #008b8b;\">tests<\/span> {\n    <span style=\"color: #ffad29; font-weight: bold;\">use<\/span> <span style=\"color: #ffad29; font-weight: bold;\">super<\/span>::<span style=\"color: #34cae2;\">Poly<\/span>;\n    <span style=\"color: #23d7d7;\">#[test]<\/span>\n    <span style=\"color: #ffad29; font-weight: bold;\">fn<\/span> <span style=\"color: #00ede1; font-weight: bold;\">creation_and_debug<\/span>() {\n        <span style=\"color: #ffad29; font-weight: bold;\">let<\/span> <span style=\"color: #dbdb95;\">x<\/span> = <span style=\"color: #34cae2;\">Poly<\/span>::new(<span style=\"color: #23d7d7;\">vec!<\/span>[1,2,3]);\n        <span style=\"color: #23d7d7;\">assert_eq!<\/span>(<span style=\"color: #23d7d7;\">format!<\/span>(<span style=\"color: #e67128;\">\"<\/span><span style=\"color: #e67128; font-style: italic;\">{:?}<\/span><span style=\"color: #e67128;\">\"<\/span>, x), <span style=\"color: #e67128;\">\"Poly { coeff: [1, 2, 3] }\"<\/span>);\n    }\n}\n<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<div id=\"outline-container-org266b3f5\" class=\"outline-2\">\n<h2 id=\"org266b3f5\">the basic operations<\/h2>\n<div class=\"outline-text-2\" id=\"text-org266b3f5\">\n\n I'd like to evaluate a polynomial in a point of its coefficients' ring. In order to do that I need to use the following properties:\n<ul class=\"org-ul\">\n \t<li>sum is defined<\/li>\n \t<li>multiplication is defined<\/li>\n \t<li>there is a zero (neutral element of the sum)<\/li>\n \t<li>the ring values can be copied (i.e. there is a way to safely copy their binary representation)<\/li>\n<\/ul>\nIn order to evaluate the value of a polynomial of degree n I will make use of the following equivalence:\n<p style=\"text-align:center\"> <img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=%5Csum_%7Bi%3D0%7D%5E%7Bn%7Dc_%7Bi%7Dx%5E%7Bi%7D+%3D+%5Clambda+%28x%29+%3A+fold%28%5Clambda+%28a%2Cb%29+%3A+xa%2Bb%2C+rev%28%5Cmathbf%7Bc%7D%29%2C0%29++++&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"&#92;sum_{i=0}^{n}c_{i}x^{i} = &#92;lambda (x) : fold(&#92;lambda (a,b) : xa+b, rev(&#92;mathbf{c}),0)    \" class=\"latex\" \/><\/p>\n Moreover I'd like to print a textual version of the object in a human-readable way, maybe not as pretty as formatted <img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=%5CLaTeX&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"&#92;LaTeX\" class=\"latex\" \/>. By implementing the <code>Display<\/code> trait it would be easier to use the format functions later.\n<div class=\"org-src-container\">\n<label class=\"org-src-name\"><em> Name: poly1-struct.<\/em><\/label>\n<pre class=\"src src-rust\" id=\"poly1-struct\"><span style=\"color: #ffad29; font-weight: bold;\">use<\/span> <span style=\"color: #008b8b;\">std<\/span>::<span style=\"color: #008b8b;\">ops<\/span>::{<span style=\"color: #34cae2;\">Mul<\/span>, <span style=\"color: #34cae2;\">Add<\/span>};\n<span style=\"color: #ffad29; font-weight: bold;\">use<\/span> <span style=\"color: #008b8b;\">std<\/span>::fmt;\n\n<span style=\"color: #23d7d7;\">#[derive(Debug)]<\/span>\n<span style=\"color: #ffad29; font-weight: bold;\">pub<\/span> <span style=\"color: #ffad29; font-weight: bold;\">struct<\/span> <span style=\"color: #34cae2;\">Poly<\/span> &lt;<span style=\"color: #34cae2;\">T<\/span>&gt;{\n    <span style=\"color: #dbdb95;\">coeff<\/span> : <span style=\"color: #34cae2;\">Vec<\/span>&lt;<span style=\"color: #34cae2;\">T<\/span>&gt;\n}\n\n<span style=\"color: #74af68;\">\/\/ <\/span><span style=\"color: #74af68;\">I need to guarantee that a type has a neutral element for sum<\/span>\n<span style=\"color: #ffad29; font-weight: bold;\">pub<\/span> <span style=\"color: #ffad29; font-weight: bold;\">trait<\/span> <span style=\"color: #34cae2;\">Zero<\/span>{\n    <span style=\"color: #ffad29; font-weight: bold;\">fn<\/span> <span style=\"color: #00ede1; font-weight: bold;\">zero<\/span>() -&gt; <span style=\"color: #34cae2;\">Self<\/span>;\n}\n\n<span style=\"color: #ffad29; font-weight: bold;\">impl<\/span>&lt;<span style=\"color: #dbdb95;\">T<\/span>: <span style=\"color: #34cae2;\">Mul<\/span>&lt;<span style=\"color: #34cae2;\">Output<\/span> = <span style=\"color: #34cae2;\">T<\/span>&gt; + <span style=\"color: #34cae2;\">Add<\/span>&lt;<span style=\"color: #34cae2;\">Output<\/span> = <span style=\"color: #34cae2;\">T<\/span>&gt; + <span style=\"color: #34cae2;\">Copy<\/span> + <span style=\"color: #34cae2;\">Zero<\/span>&gt; <span style=\"color: #34cae2;\">Poly<\/span>&lt;<span style=\"color: #34cae2;\">T<\/span>&gt;{\n    <span style=\"color: #ffad29; font-weight: bold;\">pub<\/span> <span style=\"color: #ffad29; font-weight: bold;\">fn<\/span> <span style=\"color: #00ede1; font-weight: bold;\">new<\/span>(<span style=\"color: #dbdb95;\">coeff<\/span> : <span style=\"color: #34cae2;\">Vec<\/span>&lt;<span style=\"color: #34cae2;\">T<\/span>&gt;) -&gt; <span style=\"color: #34cae2;\">Poly<\/span>&lt;<span style=\"color: #34cae2;\">T<\/span>&gt;{\n        <span style=\"color: #34cae2;\">Poly<\/span>{ <span style=\"color: #dbdb95;\">coeff<\/span>:coeff }\n    }\n    <span style=\"color: #ffad29; font-weight: bold;\">pub<\/span> <span style=\"color: #ffad29; font-weight: bold;\">fn<\/span> <span style=\"color: #00ede1; font-weight: bold;\">eval<\/span>(<span style=\"color: #ffad29; font-weight: bold;\">self<\/span> : &amp;<span style=\"color: #34cae2;\">Poly<\/span>&lt;<span style=\"color: #34cae2;\">T<\/span>&gt;, <span style=\"color: #dbdb95;\">x<\/span> : <span style=\"color: #34cae2;\">T<\/span>) -&gt; <span style=\"color: #34cae2;\">T<\/span> {\n        <span style=\"color: #ffad29; font-weight: bold;\">self<\/span>.coeff.iter()\n            .rev()\n            .fold(<span style=\"color: #34cae2;\">T<\/span>::zero(), |acc, c| acc * x + *c)\n    }\n}\n\n<span style=\"color: #ffad29; font-weight: bold;\">impl<\/span>&lt;<span style=\"color: #dbdb95;\">T<\/span>: <span style=\"color: #008b8b;\">fmt<\/span>::<span style=\"color: #34cae2;\">Debug<\/span>&gt; <span style=\"color: #008b8b;\">fmt<\/span>::<span style=\"color: #34cae2;\">Display<\/span> <span style=\"color: #ffad29; font-weight: bold;\">for<\/span> <span style=\"color: #34cae2;\">Poly<\/span>&lt;<span style=\"color: #34cae2;\">T<\/span>&gt; {\n    <span style=\"color: #ffad29; font-weight: bold;\">fn<\/span> <span style=\"color: #00ede1; font-weight: bold;\">fmt<\/span>(&amp;<span style=\"color: #ffad29; font-weight: bold;\">self<\/span>, <span style=\"color: #dbdb95;\">f<\/span>: &amp;<span style=\"color: #ffad29; font-weight: bold;\">mut<\/span> <span style=\"color: #008b8b;\">fmt<\/span>::<span style=\"color: #34cae2;\">Formatter<\/span>&lt;'<span style=\"color: #dbdb95;\">_<\/span>&gt;) -&gt; <span style=\"color: #008b8b;\">fmt<\/span>::<span style=\"color: #34cae2;\">Result<\/span> {\n        <span style=\"color: #ffad29; font-weight: bold;\">let<\/span> <span style=\"color: #dbdb95;\">result<\/span> : <span style=\"color: #34cae2;\">Vec<\/span>&lt;<span style=\"color: #34cae2;\">String<\/span>&gt; = <span style=\"color: #ffad29; font-weight: bold;\">self<\/span>.coeff.iter()\n            .enumerate()\n            .map(|(i, c)| <span style=\"color: #23d7d7;\">format!<\/span>(<span style=\"color: #e67128;\">\"(<\/span><span style=\"color: #e67128; font-style: italic;\">{:?}<\/span><span style=\"color: #e67128;\">)x^<\/span><span style=\"color: #e67128; font-style: italic;\">{}<\/span><span style=\"color: #e67128;\">\"<\/span>,c,i))\n            .collect();\n        <span style=\"color: #23d7d7;\">write!<\/span>(f, <span style=\"color: #e67128;\">\"<\/span><span style=\"color: #e67128; font-style: italic;\">{}<\/span><span style=\"color: #e67128;\">\"<\/span>, result.join(<span style=\"color: #e67128;\">\" + \"<\/span>))\n    }\n}\n\n<span style=\"color: #74af68;\">\/\/ <\/span><span style=\"color: #74af68;\">here are a couple of implementation of general use<\/span>\n<span style=\"color: #ffad29; font-weight: bold;\">impl<\/span> <span style=\"color: #34cae2;\">Zero<\/span> <span style=\"color: #ffad29; font-weight: bold;\">for<\/span> <span style=\"color: #34cae2;\">u32<\/span>{\n    <span style=\"color: #ffad29; font-weight: bold;\">fn<\/span> <span style=\"color: #00ede1; font-weight: bold;\">zero<\/span>() -&gt; <span style=\"color: #34cae2;\">u32<\/span> {\n        0\n    }\n}\n\n<span style=\"color: #ffad29; font-weight: bold;\">impl<\/span> <span style=\"color: #34cae2;\">Zero<\/span> <span style=\"color: #ffad29; font-weight: bold;\">for<\/span> <span style=\"color: #34cae2;\">i32<\/span>{\n    <span style=\"color: #ffad29; font-weight: bold;\">fn<\/span> <span style=\"color: #00ede1; font-weight: bold;\">zero<\/span>() -&gt; <span style=\"color: #34cae2;\">i32<\/span> {\n        0\n    }\n}\n\n<span style=\"color: #ffad29; font-weight: bold;\">impl<\/span> <span style=\"color: #34cae2;\">Zero<\/span> <span style=\"color: #ffad29; font-weight: bold;\">for<\/span> <span style=\"color: #34cae2;\">f32<\/span>{\n    <span style=\"color: #ffad29; font-weight: bold;\">fn<\/span> <span style=\"color: #00ede1; font-weight: bold;\">zero<\/span>() -&gt; <span style=\"color: #34cae2;\">f32<\/span> {\n        0.0\n    }\n}\n<\/pre>\n<\/div>\nlet's check if the current implementation works\n<div class=\"org-src-container\">\n<label class=\"org-src-name\"><em> Name: poly1-test.<\/em><\/label>\n<pre class=\"src src-rust\" id=\"poly1-test\"><span style=\"color: #23d7d7;\">#[test]<\/span>\n<span style=\"color: #ffad29; font-weight: bold;\">fn<\/span> <span style=\"color: #00ede1; font-weight: bold;\">test_evaluation<\/span>() {\n    <span style=\"color: #ffad29; font-weight: bold;\">let<\/span> <span style=\"color: #dbdb95;\">p<\/span> = <span style=\"color: #34cae2;\">Poly<\/span>::new(<span style=\"color: #23d7d7;\">vec!<\/span>[1,2,3]);\n    <span style=\"color: #23d7d7;\">assert_eq!<\/span>(p.eval(10), 321);\n}\n\n<span style=\"color: #23d7d7;\">#[test]<\/span>\n<span style=\"color: #ffad29; font-weight: bold;\">fn<\/span> <span style=\"color: #00ede1; font-weight: bold;\">test_formatting<\/span>() {\n    <span style=\"color: #ffad29; font-weight: bold;\">let<\/span> <span style=\"color: #dbdb95;\">x<\/span> = <span style=\"color: #34cae2;\">Poly<\/span>::new(<span style=\"color: #23d7d7;\">vec!<\/span>[1,2,3]);\n    <span style=\"color: #23d7d7;\">assert_eq!<\/span>(<span style=\"color: #23d7d7;\">format!<\/span>(<span style=\"color: #e67128;\">\"<\/span><span style=\"color: #e67128; font-style: italic;\">{}<\/span><span style=\"color: #e67128;\">\"<\/span>, x), <span style=\"color: #e67128;\">\"(1)x^0 + (2)x^1 + (3)x^2\"<\/span>);\n}\n<\/pre>\n<\/div>\n#+name poly1-test-display\n\n<\/div>\n<\/div>\n<div id=\"outline-container-orgc8c8fce\" class=\"outline-2\">\n<h2 id=\"orgc8c8fce\">a polynomial can be a function too<\/h2>\n<div class=\"outline-text-2\" id=\"text-orgc8c8fce\">\n\n Current implementations of rust expose some traits to pass functions and lambdas as objects in the <code>std::ops<\/code> module:\n<ul class=\"org-ul\">\n \t<li><code>Fn<\/code> when the data structure is borrowed without mutability<\/li>\n \t<li><code>FnMut<\/code> when the data structure is borrowed with mutability<\/li>\n \t<li><code>FnOne<\/code> when the ownership is transferred to the data structure<\/li>\n<\/ul>\nToday (Feb 2022) to implement these traits we need to use unstable features\n<div class=\"org-src-container\">\n<label class=\"org-src-name\"><em> Name: poly2-prelude.<\/em><\/label>\n<pre class=\"src src-rust\" id=\"poly2-prelude\"><span style=\"color: #23d7d7;\">#![feature(unboxed_closures)]<\/span>\n<span style=\"color: #23d7d7;\">#![feature(fn_traits)]<\/span>\n<\/pre>\n<\/div>\nThe following code creates the needed trait implementations. It can be compiled with\n<div class=\"org-src-container\">\n<label class=\"org-src-name\"><em><\/em><\/label>\n<pre class=\"src src-bash\" id=\"nil\">cargo +nightly build\n<\/pre>\n<\/div>\n<div class=\"org-src-container\">\n<label class=\"org-src-name\"><em> Name: poly2-function-implementation.<\/em><\/label>\n<pre class=\"src src-rust\" id=\"poly2-function-implementation\"><span style=\"color: #ffad29; font-weight: bold;\">use<\/span> <span style=\"color: #008b8b;\">std<\/span>::<span style=\"color: #008b8b;\">ops<\/span>::{<span style=\"color: #34cae2;\">Fn<\/span>,<span style=\"color: #34cae2;\">FnOnce<\/span>,<span style=\"color: #34cae2;\">FnMut<\/span>};\n\n<span style=\"color: #ffad29; font-weight: bold;\">impl<\/span>&lt;<span style=\"color: #dbdb95;\">T<\/span>: <span style=\"color: #34cae2;\">Mul<\/span>&lt;<span style=\"color: #34cae2;\">Output<\/span> = <span style=\"color: #34cae2;\">T<\/span>&gt; + <span style=\"color: #34cae2;\">Add<\/span>&lt;<span style=\"color: #34cae2;\">Output<\/span> = <span style=\"color: #34cae2;\">T<\/span>&gt; + <span style=\"color: #34cae2;\">Copy<\/span> + <span style=\"color: #34cae2;\">Zero<\/span>&gt; <span style=\"color: #34cae2;\">Fn<\/span>&lt;(<span style=\"color: #34cae2;\">T<\/span>, )&gt; <span style=\"color: #ffad29; font-weight: bold;\">for<\/span> <span style=\"color: #34cae2;\">Poly<\/span>&lt;<span style=\"color: #34cae2;\">T<\/span>&gt; {\n    <span style=\"color: #ffad29; font-weight: bold;\">extern<\/span> <span style=\"color: #e67128;\">\"rust-call\"<\/span> <span style=\"color: #ffad29; font-weight: bold;\">fn<\/span> <span style=\"color: #00ede1; font-weight: bold;\">call<\/span>(&amp;<span style=\"color: #ffad29; font-weight: bold;\">self<\/span>, <span style=\"color: #dbdb95;\">args<\/span>: (<span style=\"color: #34cae2;\">T<\/span>,)) -&gt; <span style=\"color: #34cae2;\">T<\/span> {\n        <span style=\"color: #ffad29; font-weight: bold;\">self<\/span>.eval(args.0)\n    }\n}\n\n<span style=\"color: #ffad29; font-weight: bold;\">impl<\/span>&lt;<span style=\"color: #dbdb95;\">T<\/span>: <span style=\"color: #34cae2;\">Mul<\/span>&lt;<span style=\"color: #34cae2;\">Output<\/span> = <span style=\"color: #34cae2;\">T<\/span>&gt; + <span style=\"color: #34cae2;\">Add<\/span>&lt;<span style=\"color: #34cae2;\">Output<\/span> = <span style=\"color: #34cae2;\">T<\/span>&gt; + <span style=\"color: #34cae2;\">Copy<\/span> + <span style=\"color: #34cae2;\">Zero<\/span>&gt; <span style=\"color: #34cae2;\">FnMut<\/span>&lt;(<span style=\"color: #34cae2;\">T<\/span>, )&gt; <span style=\"color: #ffad29; font-weight: bold;\">for<\/span> <span style=\"color: #34cae2;\">Poly<\/span>&lt;<span style=\"color: #34cae2;\">T<\/span>&gt; {\n    <span style=\"color: #ffad29; font-weight: bold;\">extern<\/span> <span style=\"color: #e67128;\">\"rust-call\"<\/span> <span style=\"color: #ffad29; font-weight: bold;\">fn<\/span> <span style=\"color: #00ede1; font-weight: bold;\">call_mut<\/span>(&amp;<span style=\"color: #ffad29; font-weight: bold;\">mut<\/span> <span style=\"color: #ffad29; font-weight: bold;\">self<\/span>, <span style=\"color: #dbdb95;\">args<\/span>: (<span style=\"color: #34cae2;\">T<\/span>,)) -&gt; <span style=\"color: #34cae2;\">T<\/span> {\n        <span style=\"color: #ffad29; font-weight: bold;\">self<\/span>.call(args)\n    }\n}\n\n<span style=\"color: #ffad29; font-weight: bold;\">impl<\/span>&lt;<span style=\"color: #dbdb95;\">T<\/span>: <span style=\"color: #34cae2;\">Mul<\/span>&lt;<span style=\"color: #34cae2;\">Output<\/span> = <span style=\"color: #34cae2;\">T<\/span>&gt; + <span style=\"color: #34cae2;\">Add<\/span>&lt;<span style=\"color: #34cae2;\">Output<\/span> = <span style=\"color: #34cae2;\">T<\/span>&gt; + <span style=\"color: #34cae2;\">Copy<\/span> + <span style=\"color: #34cae2;\">Zero<\/span>&gt; <span style=\"color: #34cae2;\">FnOnce<\/span>&lt;(<span style=\"color: #34cae2;\">T<\/span>, )&gt; <span style=\"color: #ffad29; font-weight: bold;\">for<\/span> <span style=\"color: #34cae2;\">Poly<\/span>&lt;<span style=\"color: #34cae2;\">T<\/span>&gt; {\n    <span style=\"color: #ffad29; font-weight: bold;\">type<\/span> <span style=\"color: #34cae2;\">Output<\/span> = <span style=\"color: #34cae2;\">T<\/span>;\n\n    <span style=\"color: #ffad29; font-weight: bold;\">extern<\/span> <span style=\"color: #e67128;\">\"rust-call\"<\/span> <span style=\"color: #ffad29; font-weight: bold;\">fn<\/span> <span style=\"color: #00ede1; font-weight: bold;\">call_once<\/span>(<span style=\"color: #ffad29; font-weight: bold;\">self<\/span>, <span style=\"color: #dbdb95;\">args<\/span>: (<span style=\"color: #34cae2;\">T<\/span>,)) -&gt; <span style=\"color: #34cae2;\">T<\/span> {\n        <span style=\"color: #ffad29; font-weight: bold;\">self<\/span>.call(args)\n    }\n}\n<\/pre>\n<\/div>\nnow we can call the polynomial directly as a function. let's add a few test also here:\n<div class=\"org-src-container\">\n<label class=\"org-src-name\"><em> Name: poly2-test.<\/em><\/label>\n<pre class=\"src src-rust\" id=\"poly2-test\"><span style=\"color: #23d7d7;\">#[test]<\/span>\n<span style=\"color: #ffad29; font-weight: bold;\">fn<\/span> <span style=\"color: #00ede1; font-weight: bold;\">test_call<\/span>() {\n    <span style=\"color: #ffad29; font-weight: bold;\">let<\/span> <span style=\"color: #dbdb95;\">p<\/span> = <span style=\"color: #34cae2;\">Poly<\/span>::new(<span style=\"color: #23d7d7;\">vec!<\/span>[1,2,3]);\n    <span style=\"color: #23d7d7;\">assert_eq!<\/span>(p(10), 321);\n}\n<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<div id=\"outline-container-orgcefbe30\" class=\"outline-2\">\n<h2 id=\"orgcefbe30\">let's see how it looks like<\/h2>\n<div class=\"outline-text-2\" id=\"text-orgcefbe30\">\n\n I'm going to plot a few polynomials using the popular <code>plotters<\/code> library.\n<div class=\"org-src-container\">\n<label class=\"org-src-name\"><em><\/em><\/label>\n<pre class=\"src src-rust\" id=\"nil\"><span style=\"color: #ffad29; font-weight: bold;\">use<\/span> <span style=\"color: #008b8b;\">plotters<\/span>::<span style=\"color: #008b8b;\">prelude<\/span>::*;\n<span style=\"color: #ffad29; font-weight: bold;\">use<\/span> <span style=\"color: #008b8b;\">poly<\/span>::<span style=\"color: #008b8b;\">poly2<\/span>::*;\n\n\n<span style=\"color: #ffad29; font-weight: bold;\">fn<\/span> <span style=\"color: #00ede1; font-weight: bold;\">main<\/span>() -&gt; <span style=\"color: #34cae2;\">Result<\/span>&lt;(), <span style=\"color: #34cae2;\">Box<\/span>&lt;<span style=\"color: #ffad29; font-weight: bold;\">dyn<\/span> <span style=\"color: #008b8b;\">std<\/span>::<span style=\"color: #008b8b;\">error<\/span>::<span style=\"color: #34cae2;\">Error<\/span>&gt;&gt; {\n\n    <span style=\"color: #74af68;\">\/\/<\/span><span style=\"color: #74af68;\">polynomial definition<\/span>\n    <span style=\"color: #ffad29; font-weight: bold;\">let<\/span> <span style=\"color: #dbdb95;\">p0<\/span> = <span style=\"color: #34cae2;\">Poly<\/span>::new(<span style=\"color: #23d7d7;\">vec!<\/span>[0.0, 2.0, 0.0, -3.0]);\n\n    <span style=\"color: #74af68;\">\/\/<\/span><span style=\"color: #74af68;\">start of the plot<\/span>\n    <span style=\"color: #ffad29; font-weight: bold;\">let<\/span> <span style=\"color: #dbdb95;\">root<\/span> = <span style=\"color: #34cae2;\">BitMapBackend<\/span>::new(<span style=\"color: #e67128;\">\"post002_plot0.png\"<\/span>, (640, 480)).into_drawing_area();\n    root.fill(&amp;<span style=\"color: #34cae2;\">WHITE<\/span>)<span style=\"color: #23d7d7; font-weight: bold;\">?<\/span>;\n\n    <span style=\"color: #74af68;\">\/\/<\/span><span style=\"color: #74af68;\">the polynomial is formatted in the caption<\/span>\n    <span style=\"color: #ffad29; font-weight: bold;\">let<\/span> <span style=\"color: #ffad29; font-weight: bold;\">mut<\/span> <span style=\"color: #dbdb95;\">chart<\/span> = <span style=\"color: #34cae2;\">ChartBuilder<\/span>::on(&amp;root)\n        .caption(<span style=\"color: #23d7d7;\">format!<\/span>(<span style=\"color: #e67128;\">\"y=<\/span><span style=\"color: #e67128; font-style: italic;\">{}<\/span><span style=\"color: #e67128;\">\"<\/span>,p0), (<span style=\"color: #e67128;\">\"sans-serif\"<\/span>, 25).into_font())\n        .margin(5)\n        .x_label_area_size(30)\n        .y_label_area_size(30)\n        .build_cartesian_2d(-1f32..1f32, -1f32..1f32)<span style=\"color: #23d7d7; font-weight: bold;\">?<\/span>;\n\n    chart.configure_mesh().draw()<span style=\"color: #23d7d7; font-weight: bold;\">?<\/span>;\n\n    <span style=\"color: #74af68;\">\/\/<\/span><span style=\"color: #74af68;\">here the polynomial is evaluated<\/span>\n    <span style=\"color: #74af68;\">\/\/<\/span><span style=\"color: #74af68;\">the polynomial is formatted in the plot label<\/span>\n    chart\n        .draw_series(<span style=\"color: #34cae2;\">LineSeries<\/span>::new(\n            (-50..=50).map(|x| x <span style=\"color: #ffad29; font-weight: bold;\">as<\/span> <span style=\"color: #34cae2;\">f32<\/span> \/ 50.0).map(|x| (x, p0(x))),\n            &amp;<span style=\"color: #34cae2;\">RED<\/span>,\n        ))<span style=\"color: #23d7d7; font-weight: bold;\">?<\/span>\n        .label(<span style=\"color: #23d7d7;\">format!<\/span>(<span style=\"color: #e67128;\">\"y = <\/span><span style=\"color: #e67128; font-style: italic;\">{}<\/span><span style=\"color: #e67128;\">\"<\/span>,p0))\n        .legend(|(x, y)| <span style=\"color: #34cae2;\">PathElement<\/span>::new(<span style=\"color: #23d7d7;\">vec!<\/span>[(x, y), (x + 20, y)], &amp;<span style=\"color: #34cae2;\">RED<\/span>));\n\n    chart\n        .configure_series_labels()\n        .background_style(&amp;<span style=\"color: #34cae2;\">WHITE<\/span>.mix(0.8))\n        .border_style(&amp;<span style=\"color: #34cae2;\">BLACK<\/span>)\n        .draw()<span style=\"color: #23d7d7; font-weight: bold;\">?<\/span>;\n\n    <span style=\"color: #34cae2;\">Ok<\/span>(())\n}\n<\/pre>\n<\/div>\n<div id=\"org4b76267\" class=\"figure\">\n\n<img decoding=\"async\" src=\"https:\/\/i0.wp.com\/noiseonthenet.space\/noise\/wp-content\/uploads\/2022\/01\/post002_plot0.png\" alt=\"post002_plot0.png\" style=\"float:center;\">\n\n<\/div>\nThis code was used to create the post initial image.\n\nIt uses the famous Taylor series expansion of the <code>sin<\/code>\n<p style=\"text-align:center\"> <img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=sin%28x%29+%3D+%5Csum_%7Bn%3D0%7D%5E%7B%5Cinfty%7D+%5Cfrac%7B%28-1%29%5En%7D%7B%282n%2B1%29%21%7Dx%5E%7B2n%2B1%7D++++&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"sin(x) = &#92;sum_{n=0}^{&#92;infty} &#92;frac{(-1)^n}{(2n+1)!}x^{2n+1}    \" class=\"latex\" \/><\/p>\n\n<div class=\"org-src-container\">\n<label class=\"org-src-name\"><em><\/em><\/label>\n<pre class=\"src src-rust\" id=\"nil\"><span style=\"color: #ffad29; font-weight: bold;\">use<\/span> <span style=\"color: #008b8b;\">plotters<\/span>::<span style=\"color: #008b8b;\">prelude<\/span>::*;\n<span style=\"color: #ffad29; font-weight: bold;\">use<\/span> <span style=\"color: #008b8b;\">poly<\/span>::<span style=\"color: #008b8b;\">poly2<\/span>::*;\n\n<span style=\"color: #74af68;\">\/\/ <\/span><span style=\"color: #74af68;\">this evaluates the factorial of n<\/span>\n<span style=\"color: #ffad29; font-weight: bold;\">fn<\/span> <span style=\"color: #00ede1; font-weight: bold;\">fac<\/span>(<span style=\"color: #dbdb95;\">n<\/span> : <span style=\"color: #34cae2;\">i32<\/span>) -&gt; <span style=\"color: #34cae2;\">i32<\/span>{\n    <span style=\"color: #ffad29; font-weight: bold;\">let<\/span> <span style=\"color: #ffad29; font-weight: bold;\">mut<\/span> <span style=\"color: #dbdb95;\">result<\/span> = 1;\n    <span style=\"color: #ffad29; font-weight: bold;\">for<\/span> <span style=\"color: #dbdb95;\">i<\/span> <span style=\"color: #ffad29; font-weight: bold;\">in<\/span> 1..=n{\n        result = result * i\n    }\n    result\n}\n\n<span style=\"color: #ffad29; font-weight: bold;\">fn<\/span> <span style=\"color: #00ede1; font-weight: bold;\">main<\/span>() -&gt; <span style=\"color: #34cae2;\">Result<\/span>&lt;(), <span style=\"color: #34cae2;\">Box<\/span>&lt;<span style=\"color: #ffad29; font-weight: bold;\">dyn<\/span> <span style=\"color: #008b8b;\">std<\/span>::<span style=\"color: #008b8b;\">error<\/span>::<span style=\"color: #34cae2;\">Error<\/span>&gt;&gt; {\n\n    <span style=\"color: #74af68;\">\/\/<\/span><span style=\"color: #74af68;\">start of the plot<\/span>\n    <span style=\"color: #ffad29; font-weight: bold;\">let<\/span> <span style=\"color: #dbdb95;\">root<\/span> = <span style=\"color: #34cae2;\">BitMapBackend<\/span>::new(<span style=\"color: #e67128;\">\"post002_plot1.png\"<\/span>, (640, 480)).into_drawing_area();\n    root.fill(&amp;<span style=\"color: #34cae2;\">WHITE<\/span>)<span style=\"color: #23d7d7; font-weight: bold;\">?<\/span>;\n\n    <span style=\"color: #74af68;\">\/\/<\/span><span style=\"color: #74af68;\">the polynomial is formatted in the caption<\/span>\n    <span style=\"color: #ffad29; font-weight: bold;\">let<\/span> <span style=\"color: #ffad29; font-weight: bold;\">mut<\/span> <span style=\"color: #dbdb95;\">chart<\/span> = <span style=\"color: #34cae2;\">ChartBuilder<\/span>::on(&amp;root)\n        .caption(<span style=\"color: #e67128;\">\"Approximations of sin\"<\/span>, (<span style=\"color: #e67128;\">\"sans-serif\"<\/span>, 25).into_font())\n        .margin(5)\n        .x_label_area_size(30)\n        .y_label_area_size(30)\n        .build_cartesian_2d(-7f32..7f32, -1.2f32..1.2f32)<span style=\"color: #23d7d7; font-weight: bold;\">?<\/span>;\n\n    chart.configure_mesh().draw()<span style=\"color: #23d7d7; font-weight: bold;\">?<\/span>;\n\n    <span style=\"color: #74af68;\">\/\/<\/span><span style=\"color: #74af68;\">here the polynomial is evaluated<\/span>\n    <span style=\"color: #74af68;\">\/\/<\/span><span style=\"color: #74af68;\">the polynomial is formatted in the plot label<\/span>\n    <span style=\"color: #ffad29; font-weight: bold;\">for<\/span> (deg,color) <span style=\"color: #ffad29; font-weight: bold;\">in<\/span> [(1,<span style=\"color: #34cae2;\">RED<\/span>),(3,<span style=\"color: #34cae2;\">BLUE<\/span>),(5,<span style=\"color: #34cae2;\">MAGENTA<\/span>),(7,<span style=\"color: #34cae2;\">GREEN<\/span>),(9,<span style=\"color: #34cae2;\">CYAN<\/span>)].iter(){\n        <span style=\"color: #ffad29; font-weight: bold;\">let<\/span> <span style=\"color: #dbdb95;\">coeff<\/span> : <span style=\"color: #34cae2;\">Vec<\/span>&lt;<span style=\"color: #34cae2;\">f32<\/span>&gt; = (0..=*deg)\n            .map(|n| <span style=\"color: #ffad29; font-weight: bold;\">if<\/span> n % 2 == 0 { 0.0 }\n                 <span style=\"color: #ffad29; font-weight: bold;\">else<\/span> {\n                     <span style=\"color: #ffad29; font-weight: bold;\">let<\/span> <span style=\"color: #dbdb95;\">nf<\/span> = fac(n) <span style=\"color: #ffad29; font-weight: bold;\">as<\/span> <span style=\"color: #34cae2;\">f32<\/span>;\n                     <span style=\"color: #ffad29; font-weight: bold;\">let<\/span> <span style=\"color: #dbdb95;\">sign<\/span> = <span style=\"color: #ffad29; font-weight: bold;\">if<\/span> ((n - 1) \/ 2) % 2 == 0 { 1.0 } <span style=\"color: #ffad29; font-weight: bold;\">else<\/span> { -1.0 } ;\n                     sign\/nf\n                 })\n            .collect();\n        <span style=\"color: #ffad29; font-weight: bold;\">let<\/span> <span style=\"color: #dbdb95;\">p0<\/span> = <span style=\"color: #34cae2;\">Poly<\/span>::new(coeff);\n        chart\n            .draw_series(<span style=\"color: #34cae2;\">LineSeries<\/span>::new(\n                (-50..=50).map(|x| x <span style=\"color: #ffad29; font-weight: bold;\">as<\/span> <span style=\"color: #34cae2;\">f32<\/span> * 7.0 \/ 50.0).map(|x| (x, p0(x))),\n                &amp;color,\n            ))<span style=\"color: #23d7d7; font-weight: bold;\">?<\/span>\n            .label(<span style=\"color: #23d7d7;\">format!<\/span>(<span style=\"color: #e67128;\">\"sin<\/span><span style=\"color: #e67128; font-style: italic;\">{}<\/span><span style=\"color: #e67128;\">\"<\/span>,deg))\n            .legend(|(x, y)| <span style=\"color: #34cae2;\">PathElement<\/span>::new(<span style=\"color: #23d7d7;\">vec!<\/span>[(x, y), (x + 20, y)], &amp;color.clone()));\n    }\n    chart\n        .draw_series(<span style=\"color: #34cae2;\">LineSeries<\/span>::new(\n            (-50..=50).map(|x| x <span style=\"color: #ffad29; font-weight: bold;\">as<\/span> <span style=\"color: #34cae2;\">f32<\/span> * 7.0 \/ 50.0).map(|x| (x, x.sin())),\n            &amp;<span style=\"color: #34cae2;\">BLACK<\/span>,\n        ))<span style=\"color: #23d7d7; font-weight: bold;\">?<\/span>\n        .label(<span style=\"color: #e67128;\">\"sin\"<\/span>)\n        .legend(|(x, y)| <span style=\"color: #34cae2;\">PathElement<\/span>::new(<span style=\"color: #23d7d7;\">vec!<\/span>[(x, y), (x + 20, y)], &amp;<span style=\"color: #34cae2;\">BLACK<\/span>));\n    chart\n        .configure_series_labels()\n        .background_style(&amp;<span style=\"color: #34cae2;\">WHITE<\/span>.mix(0.8))\n        .border_style(&amp;<span style=\"color: #34cae2;\">BLACK<\/span>)\n        .draw()<span style=\"color: #23d7d7; font-weight: bold;\">?<\/span>;\n\n    <span style=\"color: #34cae2;\">Ok<\/span>(())\n}\n<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<div id=\"outline-container-org1a9a52d\" class=\"outline-2\">\n<h2 id=\"org1a9a52d\">conclusions<\/h2>\n<div class=\"outline-text-2\" id=\"text-org1a9a52d\">\n\n Polynomials are simple yet powerful structures which can dig into a language syntax and features.\n\nThis is just the beginning of this journey: stay tuned for more.\n\n<\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"This post is the first of a series of about polynomials.  I'm using it as a mean to explore the rust programming language (especially how generic traits relate to algebra) while also learning math subjects.","protected":false},"author":1,"featured_media":82,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","inline_featured_image":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[8],"tags":[5],"class_list":["post-75","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-series","tag-rust"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Polynomial basics - Noise On The Net<\/title>\n<meta name=\"description\" content=\"This post is the first of a series of about polynomials in the programming language Rust . I&#039;m using it as a mean to explore the rust programming language (especially how generic traits relate to algebra) while also learning math subjects.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/noiseonthenet.space\/noise\/2022\/01\/polynomial-basics\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Polynomial basics - Noise On The Net\" \/>\n<meta property=\"og:description\" content=\"This post is the first of a series of about polynomials in the programming language Rust . I&#039;m using it as a mean to explore the rust programming language (especially how generic traits relate to algebra) while also learning math subjects.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/noiseonthenet.space\/noise\/2022\/01\/polynomial-basics\/\" \/>\n<meta property=\"og:site_name\" content=\"Noise On The Net\" \/>\n<meta property=\"article:published_time\" content=\"2022-01-31T20:05:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-02-08T14:02:41+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/noiseonthenet.space\/noise\/wp-content\/uploads\/2022\/01\/post002_plot1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"640\" \/>\n\t<meta property=\"og:image:height\" content=\"480\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"marco.p.v.vezzoli\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"marco.p.v.vezzoli\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/noiseonthenet.space\\\/noise\\\/2022\\\/01\\\/polynomial-basics\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/noiseonthenet.space\\\/noise\\\/2022\\\/01\\\/polynomial-basics\\\/\"},\"author\":{\"name\":\"marco.p.v.vezzoli\",\"@id\":\"https:\\\/\\\/noiseonthenet.space\\\/noise\\\/#\\\/schema\\\/person\\\/88c3a70f2b23480197bc61d6e1e2e982\"},\"headline\":\"Polynomial basics\",\"datePublished\":\"2022-01-31T20:05:00+00:00\",\"dateModified\":\"2022-02-08T14:02:41+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/noiseonthenet.space\\\/noise\\\/2022\\\/01\\\/polynomial-basics\\\/\"},\"wordCount\":635,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/noiseonthenet.space\\\/noise\\\/#\\\/schema\\\/person\\\/88c3a70f2b23480197bc61d6e1e2e982\"},\"image\":{\"@id\":\"https:\\\/\\\/noiseonthenet.space\\\/noise\\\/2022\\\/01\\\/polynomial-basics\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/noiseonthenet.space\\\/noise\\\/wp-content\\\/uploads\\\/2022\\\/01\\\/post002_plot1.png?fit=640%2C480&ssl=1\",\"keywords\":[\"Rust\"],\"articleSection\":[\"Series\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/noiseonthenet.space\\\/noise\\\/2022\\\/01\\\/polynomial-basics\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/noiseonthenet.space\\\/noise\\\/2022\\\/01\\\/polynomial-basics\\\/\",\"url\":\"https:\\\/\\\/noiseonthenet.space\\\/noise\\\/2022\\\/01\\\/polynomial-basics\\\/\",\"name\":\"Polynomial basics - Noise On The Net\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/noiseonthenet.space\\\/noise\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/noiseonthenet.space\\\/noise\\\/2022\\\/01\\\/polynomial-basics\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/noiseonthenet.space\\\/noise\\\/2022\\\/01\\\/polynomial-basics\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/noiseonthenet.space\\\/noise\\\/wp-content\\\/uploads\\\/2022\\\/01\\\/post002_plot1.png?fit=640%2C480&ssl=1\",\"datePublished\":\"2022-01-31T20:05:00+00:00\",\"dateModified\":\"2022-02-08T14:02:41+00:00\",\"description\":\"This post is the first of a series of about polynomials in the programming language Rust . I'm using it as a mean to explore the rust programming language (especially how generic traits relate to algebra) while also learning math subjects.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/noiseonthenet.space\\\/noise\\\/2022\\\/01\\\/polynomial-basics\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/noiseonthenet.space\\\/noise\\\/2022\\\/01\\\/polynomial-basics\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/noiseonthenet.space\\\/noise\\\/2022\\\/01\\\/polynomial-basics\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/noiseonthenet.space\\\/noise\\\/wp-content\\\/uploads\\\/2022\\\/01\\\/post002_plot1.png?fit=640%2C480&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/noiseonthenet.space\\\/noise\\\/wp-content\\\/uploads\\\/2022\\\/01\\\/post002_plot1.png?fit=640%2C480&ssl=1\",\"width\":640,\"height\":480},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/noiseonthenet.space\\\/noise\\\/2022\\\/01\\\/polynomial-basics\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/noiseonthenet.space\\\/noise\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Polynomial basics\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/noiseonthenet.space\\\/noise\\\/#website\",\"url\":\"https:\\\/\\\/noiseonthenet.space\\\/noise\\\/\",\"name\":\"Noise On The Net\",\"description\":\"Sharing adventures in code\",\"publisher\":{\"@id\":\"https:\\\/\\\/noiseonthenet.space\\\/noise\\\/#\\\/schema\\\/person\\\/88c3a70f2b23480197bc61d6e1e2e982\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/noiseonthenet.space\\\/noise\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/noiseonthenet.space\\\/noise\\\/#\\\/schema\\\/person\\\/88c3a70f2b23480197bc61d6e1e2e982\",\"name\":\"marco.p.v.vezzoli\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b9d9aab1df560bc14d73b0b442198f196ce39e7c7a38df1dc22fec0b97f17da9?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b9d9aab1df560bc14d73b0b442198f196ce39e7c7a38df1dc22fec0b97f17da9?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b9d9aab1df560bc14d73b0b442198f196ce39e7c7a38df1dc22fec0b97f17da9?s=96&d=mm&r=g\",\"caption\":\"marco.p.v.vezzoli\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b9d9aab1df560bc14d73b0b442198f196ce39e7c7a38df1dc22fec0b97f17da9?s=96&d=mm&r=g\"},\"description\":\"Self taught assembler programming at 11 on my C64 (1983). Never stopped since then -- always looking up for curious things in the software development, data science and AI. Linux and FOSS user since 1994. MSc in physics in 1996. Working in large semiconductor companies since 1997 (STM, Micron) developing analytics and full stack web infrastructures, microservices, ML solutions\",\"sameAs\":[\"https:\\\/\\\/noiseonthenet.space\\\/noise\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/marco-paolo-valerio-vezzoli-0663835\\\/\"],\"url\":\"https:\\\/\\\/noiseonthenet.space\\\/noise\\\/author\\\/marco-p-v-vezzoli\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Polynomial basics - Noise On The Net","description":"This post is the first of a series of about polynomials in the programming language Rust . I'm using it as a mean to explore the rust programming language (especially how generic traits relate to algebra) while also learning math subjects.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/noiseonthenet.space\/noise\/2022\/01\/polynomial-basics\/","og_locale":"en_US","og_type":"article","og_title":"Polynomial basics - Noise On The Net","og_description":"This post is the first of a series of about polynomials in the programming language Rust . I'm using it as a mean to explore the rust programming language (especially how generic traits relate to algebra) while also learning math subjects.","og_url":"https:\/\/noiseonthenet.space\/noise\/2022\/01\/polynomial-basics\/","og_site_name":"Noise On The Net","article_published_time":"2022-01-31T20:05:00+00:00","article_modified_time":"2022-02-08T14:02:41+00:00","og_image":[{"width":640,"height":480,"url":"https:\/\/noiseonthenet.space\/noise\/wp-content\/uploads\/2022\/01\/post002_plot1.png","type":"image\/png"}],"author":"marco.p.v.vezzoli","twitter_card":"summary_large_image","twitter_misc":{"Written by":"marco.p.v.vezzoli","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/noiseonthenet.space\/noise\/2022\/01\/polynomial-basics\/#article","isPartOf":{"@id":"https:\/\/noiseonthenet.space\/noise\/2022\/01\/polynomial-basics\/"},"author":{"name":"marco.p.v.vezzoli","@id":"https:\/\/noiseonthenet.space\/noise\/#\/schema\/person\/88c3a70f2b23480197bc61d6e1e2e982"},"headline":"Polynomial basics","datePublished":"2022-01-31T20:05:00+00:00","dateModified":"2022-02-08T14:02:41+00:00","mainEntityOfPage":{"@id":"https:\/\/noiseonthenet.space\/noise\/2022\/01\/polynomial-basics\/"},"wordCount":635,"commentCount":0,"publisher":{"@id":"https:\/\/noiseonthenet.space\/noise\/#\/schema\/person\/88c3a70f2b23480197bc61d6e1e2e982"},"image":{"@id":"https:\/\/noiseonthenet.space\/noise\/2022\/01\/polynomial-basics\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/noiseonthenet.space\/noise\/wp-content\/uploads\/2022\/01\/post002_plot1.png?fit=640%2C480&ssl=1","keywords":["Rust"],"articleSection":["Series"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/noiseonthenet.space\/noise\/2022\/01\/polynomial-basics\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/noiseonthenet.space\/noise\/2022\/01\/polynomial-basics\/","url":"https:\/\/noiseonthenet.space\/noise\/2022\/01\/polynomial-basics\/","name":"Polynomial basics - Noise On The Net","isPartOf":{"@id":"https:\/\/noiseonthenet.space\/noise\/#website"},"primaryImageOfPage":{"@id":"https:\/\/noiseonthenet.space\/noise\/2022\/01\/polynomial-basics\/#primaryimage"},"image":{"@id":"https:\/\/noiseonthenet.space\/noise\/2022\/01\/polynomial-basics\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/noiseonthenet.space\/noise\/wp-content\/uploads\/2022\/01\/post002_plot1.png?fit=640%2C480&ssl=1","datePublished":"2022-01-31T20:05:00+00:00","dateModified":"2022-02-08T14:02:41+00:00","description":"This post is the first of a series of about polynomials in the programming language Rust . I'm using it as a mean to explore the rust programming language (especially how generic traits relate to algebra) while also learning math subjects.","breadcrumb":{"@id":"https:\/\/noiseonthenet.space\/noise\/2022\/01\/polynomial-basics\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/noiseonthenet.space\/noise\/2022\/01\/polynomial-basics\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/noiseonthenet.space\/noise\/2022\/01\/polynomial-basics\/#primaryimage","url":"https:\/\/i0.wp.com\/noiseonthenet.space\/noise\/wp-content\/uploads\/2022\/01\/post002_plot1.png?fit=640%2C480&ssl=1","contentUrl":"https:\/\/i0.wp.com\/noiseonthenet.space\/noise\/wp-content\/uploads\/2022\/01\/post002_plot1.png?fit=640%2C480&ssl=1","width":640,"height":480},{"@type":"BreadcrumbList","@id":"https:\/\/noiseonthenet.space\/noise\/2022\/01\/polynomial-basics\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/noiseonthenet.space\/noise\/"},{"@type":"ListItem","position":2,"name":"Polynomial basics"}]},{"@type":"WebSite","@id":"https:\/\/noiseonthenet.space\/noise\/#website","url":"https:\/\/noiseonthenet.space\/noise\/","name":"Noise On The Net","description":"Sharing adventures in code","publisher":{"@id":"https:\/\/noiseonthenet.space\/noise\/#\/schema\/person\/88c3a70f2b23480197bc61d6e1e2e982"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/noiseonthenet.space\/noise\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/noiseonthenet.space\/noise\/#\/schema\/person\/88c3a70f2b23480197bc61d6e1e2e982","name":"marco.p.v.vezzoli","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/b9d9aab1df560bc14d73b0b442198f196ce39e7c7a38df1dc22fec0b97f17da9?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/b9d9aab1df560bc14d73b0b442198f196ce39e7c7a38df1dc22fec0b97f17da9?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/b9d9aab1df560bc14d73b0b442198f196ce39e7c7a38df1dc22fec0b97f17da9?s=96&d=mm&r=g","caption":"marco.p.v.vezzoli"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/b9d9aab1df560bc14d73b0b442198f196ce39e7c7a38df1dc22fec0b97f17da9?s=96&d=mm&r=g"},"description":"Self taught assembler programming at 11 on my C64 (1983). Never stopped since then -- always looking up for curious things in the software development, data science and AI. Linux and FOSS user since 1994. MSc in physics in 1996. Working in large semiconductor companies since 1997 (STM, Micron) developing analytics and full stack web infrastructures, microservices, ML solutions","sameAs":["https:\/\/noiseonthenet.space\/noise\/","https:\/\/www.linkedin.com\/in\/marco-paolo-valerio-vezzoli-0663835\/"],"url":"https:\/\/noiseonthenet.space\/noise\/author\/marco-p-v-vezzoli\/"}]}},"jetpack_featured_media_url":"https:\/\/i0.wp.com\/noiseonthenet.space\/noise\/wp-content\/uploads\/2022\/01\/post002_plot1.png?fit=640%2C480&ssl=1","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pdDUZ5-1d","jetpack-related-posts":[],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/noiseonthenet.space\/noise\/wp-json\/wp\/v2\/posts\/75","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/noiseonthenet.space\/noise\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/noiseonthenet.space\/noise\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/noiseonthenet.space\/noise\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/noiseonthenet.space\/noise\/wp-json\/wp\/v2\/comments?post=75"}],"version-history":[{"count":6,"href":"https:\/\/noiseonthenet.space\/noise\/wp-json\/wp\/v2\/posts\/75\/revisions"}],"predecessor-version":[{"id":103,"href":"https:\/\/noiseonthenet.space\/noise\/wp-json\/wp\/v2\/posts\/75\/revisions\/103"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/noiseonthenet.space\/noise\/wp-json\/wp\/v2\/media\/82"}],"wp:attachment":[{"href":"https:\/\/noiseonthenet.space\/noise\/wp-json\/wp\/v2\/media?parent=75"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/noiseonthenet.space\/noise\/wp-json\/wp\/v2\/categories?post=75"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/noiseonthenet.space\/noise\/wp-json\/wp\/v2\/tags?post=75"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}