

{"id":225,"date":"2019-01-15T08:59:52","date_gmt":"2019-01-15T07:59:52","guid":{"rendered":"http:\/\/project.inria.fr\/coqexchange\/?p=225"},"modified":"2019-01-15T08:59:52","modified_gmt":"2019-01-15T07:59:52","slug":"a-tricky-thing-with-real-numbers","status":"publish","type":"post","link":"https:\/\/project.inria.fr\/coqexchange\/a-tricky-thing-with-real-numbers\/","title":{"rendered":"A tricky thing with real numbers"},"content":{"rendered":"<p>There are several types of numbers, and these can be arranged in two categories.<\/p>\n<ol>\n<li>The inductive types: <tt>nat<\/tt>, <tt>positive<\/tt>, <tt>Z<\/tt>, &#8230;<\/li>\n<li>the axiomatized types: <tt>R<\/tt> is the prominent one<\/li>\n<\/ol>\n<p>The difference comes in how to compute with these numbers.  If a type is <i>inductive<\/i> then we know how to describe simple rules of computation and force computations to reach simple forms, when these forms exist.<br \/>\nFor instance, the Coq system knows that <tt>3<\/tt> and <tt>1 + 1 + 1<\/tt> compute to the same value.<\/p>\n<p>In the case of the type <tt>R<\/tt>, the <i>computation properties<\/i> are only given as properties, and the inner layer of the Coq system does not have a clue that it should be using these computation properties.  So, when it sees a number of the form <tt>1 + 1 + 1 + 1<\/tt>, it does not know that it is one for which there could exist a simpler form.<\/p>\n<p>Let&#8217;s compare two computations, one in <tt>Z<\/tt> and one in <tt>R<\/tt>.<\/p>\n<p>First session:<\/p>\n<pre>\r\nRequire Import ZArith.\r\n\r\nOpen Scope Z_scope.\r\n\r\nGoal (10 + 5) * 10 + 2 = 152.\r\nProof.\r\ncompute.\r\n<\/pre>\n<p>At this point the goal is <tt>152 = 152 <\/tt> the proof can obviously be finished for instance with the tactic <tt>easy<\/tt>.<\/p>\n<p>Now let&#8217;s have another example with real numbers.<\/p>\n<pre>\r\nRequire Import Reals.\r\n\r\nOpen Scope R_scope.\r\n\r\nGoal (10 + 5) * 10 + 2 = 152.\r\nProof.\r\ncompute.\r\n<\/pre>\n<p>At this point, the goal becomes a huge formula that contains only the equality sign, additions, and multiplication.  In a sense the formula is simpler because it uses only simple concepts, but in a sense it makes things more complex to the human eye.  It feels like the <i>natural<\/i> rules of computation are not so natural after all.<\/p>\n<p>From our mathematical knowledge, we know there are natural computation rules for real numbers, but simply these have not been given to the Coq system for use by the <tt>compute<\/tt> tactic.  We need to use another tactic for this, it is called <tt>ring<\/tt>.<\/p>\n<p>At the time of writing this post, it is necessary for Coq users to be aware of the difference between these two kinds of numbers.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There are several types of numbers, and these can be arranged in two categories. The inductive types: nat, positive, Z, &#8230; the axiomatized types: R is the prominent one The difference comes in how to compute with these numbers. If a type is inductive then we know how to describe\u2026<\/p>\n<p> <a class=\"continue-reading-link\" href=\"https:\/\/project.inria.fr\/coqexchange\/a-tricky-thing-with-real-numbers\/\"><span>Continue reading<\/span><i class=\"crycon-right-dir\"><\/i><\/a> <\/p>\n","protected":false},"author":1013,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-225","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/project.inria.fr\/coqexchange\/wp-json\/wp\/v2\/posts\/225","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/project.inria.fr\/coqexchange\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/project.inria.fr\/coqexchange\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/project.inria.fr\/coqexchange\/wp-json\/wp\/v2\/users\/1013"}],"replies":[{"embeddable":true,"href":"https:\/\/project.inria.fr\/coqexchange\/wp-json\/wp\/v2\/comments?post=225"}],"version-history":[{"count":7,"href":"https:\/\/project.inria.fr\/coqexchange\/wp-json\/wp\/v2\/posts\/225\/revisions"}],"predecessor-version":[{"id":232,"href":"https:\/\/project.inria.fr\/coqexchange\/wp-json\/wp\/v2\/posts\/225\/revisions\/232"}],"wp:attachment":[{"href":"https:\/\/project.inria.fr\/coqexchange\/wp-json\/wp\/v2\/media?parent=225"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/project.inria.fr\/coqexchange\/wp-json\/wp\/v2\/categories?post=225"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/project.inria.fr\/coqexchange\/wp-json\/wp\/v2\/tags?post=225"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}