I want to proof that there exist an rational which is less than some rational. for example..
v : ℚ
v = + 1 ÷ 2
thm : (Σ[ x ∈ ℚ ] (x Data.Rational.≤ v))
thm = ?
What to write in second line??
And what is the meaning of x ∈ ℚ, will it give an element of ℚ or what.
And where is it defined over Set as i found this in Stream and there it defined over stream.
You just need to follow the definitions.
First of all, we take a look at what the
Σpart ofΣ[ x ∈ ℚ ] x ≤ vis. This data type is defined in the moduleData.Productsimply asΣ. The whole thing with∈is just a syntactic sugar, as can be seen from the following line:So what we really need to construct is something of type
Σ ℚ λ x → x ≤ v. Taking a look at the definition ofΣ:It's a pair, constructed using
_,_. The first element is the number (a witness) and the second element is the proof that the first element satisfies the given proposition (≤). So,thmshould look like this:We already know that the first element is a number (or, more precisely, something of type
ℚ). So here we pick a suitable number - I picked+ 1 ÷ 3, which should hopefully be less than+ 1 ÷ 2.This leaves us with the second question mark. There, we need something of type
+ 1 ÷ 3 ≤ v. Again, we'll take a look at the definition of≤:Okay, this makes it easy: the only constructor is
*≤*so we can't possibly pick the wrong one:The
?has now this type:+ 2 ≤ + 3(where≤comes fromData.Integer). Again, let's take a look at definition of≤:This gets slightly more interesting, as there are three possible constructors. However, taking a closer look, the only relevant one is
+≤+, because the numbers on both sides are positive.The only thing that is left is to write a term of type
2 ≤ 3(for≤fromData.Nat). I'll leave that as an exercise for the reader.If the choice of constructor is unambiguous, you can use Agda's Emacs mode to do most of the work for you - you just keep pressing
C-c C-R(refine) and Agda just writes the proof term for you.I don't like writing silly proof terms like that, the computer should be more than able to write a proof of
x ≤ vfor me - after all,≤is decidable.Decidableis defined in the standard library:So, a binary relation
~is decidable if you can write a binary function (let's call the argumentsxandy), that returns either a proof ofx ~ yor a refutation ofx ~ y(that isx ~ y → ⊥).Luckily for us, the proof of
≤'s decidability is available in the standard library and can be found under the name≤?- I just need to write fairly simple machinery to extract the proof from there (if it exists):fromDecextracts the proof fromDec A; if the proof is not there (i.e. the argument wasno ¬pfor some¬p), it just returns the empty tuple.Now we can just let the computer figure out whether
+ 1 ÷ 3 ≤ vholds or not. If it does - great, we just extract the computed proof withfromDecand we're done; if it doesn't,fromDecreturns the empty tuple and we get a type error.