Introduction to Programming in ATS: | ||
---|---|---|
<<< Previous | Theorem-Proving in ATS/LF | Next >>> |
The distributivity of multiplication over addition means that the following equation holds
for m, n1 and n2 ranging over integers. Clearly, a direct encoding of the equation is given by the following (proof) function interface:extern prfun mul_distribute {m:int} {n1,n2:int} {p1,p2:int} (pf1: MUL (m, n1, p1), pf2: MUL (m, n2, p2)): MUL (m, n1+n2, p1+p2) // end of [mul_distribute] |
implement mul_distribute {m} {n1,n2} {p1,p2} (pf1, pf2) = let prfun aux {m:nat} {n1,n2:int} {p1,p2:int} .<m>. ( pf1: MUL (m, n1, p1), pf2: MUL (m, n2, p2) ) : MUL (m, n1+n2, p1+p2) = case+ (pf1, pf2) of | (MULbas (), MULbas ()) => MULbas () | (MULind pf1, MULind pf2) => MULind (aux (pf1, pf2)) // end of [aux] in sif m >= 0 then aux (pf1, pf2) else let prval MULneg (pf1) = pf1 prval MULneg (pf2) = pf2 in MULneg (aux (pf1, pf2)) end end // end of [mul_distribute] |
<<< Previous | Home | Next >>> |
Constructing Proofs as Total Functions | Up | Datasorts |