square root - How do I the calculate the sqrt of a natural or rational number in coq? -
i'm learning coq , i'm trying make own point , line data types. i'd make function returns length of line, can't seem find sqrt function return calculation. tried used coq.reals.r_sqrt
, apparently that's used abstract math, won't run calculation.
so tried importing coq.numbers.natural.abstract.nsqrt
, coq.numbers.natint.nzsqrt.
neither put sqrt function environment.
this have far...
require import coq.qarith.qarith_base. require import coq.numbers.natint.nzsqrt. require import coq.numbers.natural.abstract.nsqrt. require import coq.zarith.binint. inductive point : type := point : q -> q -> point. inductive line : type := line : point -> point -> line. definition line_fst (l:line) := match l | line x y => x end. definition line_snd (l:line) := match l | line x y => y end. definition point_fst (p:point) := match p | point x y => x end. definition point_snd (p:point) := match p | point x y => y end. (* reference sqrt not found in current environment. *) definition line_length (l:line) := sqrt( (minus (point_snd(line_fst l)) (point_fst(line_fst l)))^2 + (minus (point_snd(line_snd l)) (point_fst(line_snd l)))^2 ). example line_example : ( line_length (line (point 0 0) (point 0 2)) = 2 ).
if want square root compute, there 2 things can do.
use corn library. real number functions compute. however, real numbers functions can ask approximations precision, might not looking for. also, think corn not terribly maintained nowadays.
use natural number square root standard library mentioned, , use calculate square roots want precision yourself. function importing
binnat
:coq < require import binnat. [loading ml file z_syntax_plugin.cmxs ... done] coq < eval compute in n.sqrt 1000. = 31%n : n
Comments
Post a Comment