With Reals library imported
Require Import Reals.
How can I define constants such as 3.14 or 10.1 and use them for function definition or computation ?
With Reals library imported
Require Import Reals.
How can I define constants such as 3.14 or 10.1 and use them for function definition or computation ?
Copyright © 2021 Jogjafile Inc.
You can define your constants like so:
Note, however, that the standard library defines reals axiomatically. You can find the main definitions here. Observe that the definitions are given as
Parameter
s, which is a synonym forAxiom
. For instance,R0
andR1
stand for the real numbers 0 and 1,Rplus
andRmult
represent addition and multiplication, but those definitions are not inductive datatypes and functions as they lack definitions. To be able to deal with reals we need axioms, governing the interactions between them (given here).You can think of the real numbers in the standard library as ASTs, made with nodes marked
R0
,R1
,Rplus
, and so on. And you are given some rules (axioms) which specify the (only) transformations you can perform on those ASTs.Let's see how Coq represents real numbers:
Among the consequences of this axiomatic approach there is the fact that the following goal cannot be proved by
reflexivity
anymore (as it could be done fornat
s in an analogous situation):This fails because the ASTs (terms) on the both sides of the equality are different and Coq doesn't convert them to some canonical values to compare them at the end. This time we need to show that the two ASTs are mutually convertible.
Now we need to prove
9 + 1 = 10
:Fortunately for us there is a tactic, which can do this tedious job for us:
The standard library approach is not the only one possible, however. This answer by @gallais can help you with exploring your other options.