2 questions about Twelf
Oct. 11th, 2008 02:22 pmIf I want to assert that a function could be specified either as
Can one declare in Twelf that a function is commutative? i.e., if f takes two arguments of the same type, I'd like to declare that for all a,b, f(a,b) is equal to f(b,a). Is this possible? While one can imagine doing static analysis, I just want to be able to declare it.
a -> b -> c or b -> a -> c, I would like to write it as (a * b) -> c, or some similar notation. Is this supported?Can one declare in Twelf that a function is commutative? i.e., if f takes two arguments of the same type, I'd like to declare that for all a,b, f(a,b) is equal to f(b,a). Is this possible? While one can imagine doing static analysis, I just want to be able to declare it.
(no subject)
Date: 2008-10-11 09:38 pm (UTC)(no subject)
Date: 2008-10-11 09:48 pm (UTC)But I don't want to prove it. I just want to declare it.
Is
exp"expression"? Isevalsa relation? Is it a function? (I'm confused by a function that returns something of type type)(no subject)
Date: 2008-10-11 09:52 pm (UTC)evals : exp -> nat -> type
as a function. Read is as a declaration of a dependent type. A more natural example might be this:
nat: type.
z : nat.
s : nat.
indexed_list : nat -> type.
nil : list z.
cons : item -> list N -> list (s N).
So I'm defining an indexed list, and saying that nil is a list of length zero and cons is a constructor that takes an item and a list of length N and returns a list of length N + 1.
(no subject)
Date: 2008-10-11 10:02 pm (UTC)I want to use such properties to prove theorems in the language, and save computation.
When an expression evaluates to f(a,b) - f(b,a), I want to check whether f is commutative, and if it is, the above should evaluate to 0. Lovely laziness.
(no subject)
Date: 2008-10-11 10:24 pm (UTC)(no subject)
Date: 2008-10-12 05:58 am (UTC)(no subject)
Date: 2008-10-12 06:18 am (UTC)Design philosophy of Twelf: if you can do it with a simpler underlying theory and it's shockingly more difficult to use the result, then do it with the simpler underlying theory. Having no pairs in the constructor language simplifies the underlying theory, and it's not really any more annoying to use Twelf as a result.
(no subject)
Date: 2008-10-11 09:42 pm (UTC)* Twelf doesn't have "functions," it has "constructors"
* All functions in Twelf are injective
The exception are the constraint domains, but those play badly with the theorem-proving part of Twelf that we all know and love.
(no subject)
Date: 2008-10-11 09:53 pm (UTC)Constructors? Wouldn't that mean that f(a,b) does not equal f(a,b)? (i.e. f constructs a new object each time it's called)
(no subject)
Date: 2008-10-11 09:56 pm (UTC)(no subject)
Date: 2008-10-12 01:12 am (UTC)(no subject)
Date: 2008-10-12 01:18 am (UTC)(no subject)
Date: 2008-10-11 10:07 pm (UTC)I want to have a theorem-prover that *uses* those constraints.
(no subject)
Date: 2008-10-11 10:23 pm (UTC)(no subject)
Date: 2008-10-12 01:08 am (UTC)you can sort of specify that you want (and have twelf check) such things to behave as functions by giving them modes, indicating which arguments to the relation are "inputs" and which are "outputs". you can also have it check totality of such a thing. uniqueness of output for a given input is something you have to prove as a theorem.
i'm still not sure any of this actually inhibits you from what you want to do. specifically, i'm curious why you'd want to "declare" commutativity.
(no subject)
Date: 2008-10-12 01:16 am (UTC)%use equality/integers.
id : integer -> integer -> type.
id/refl : id X X.
%abbrev _ : id (A + (B + C)) ((C + A) + B) = id/refl.
This is part of why constraint domains don't get along with metatheorems - they add so gosh-darn many equalities to the langauge.
why declare commutativity
Date: 2008-10-12 06:07 am (UTC)This is partly for the sake of clarity, partly to help me catch errors, and partly to automate mathematical work (e.g. by using theorem-provers).
Formalizing a domain completely is usually unnecessary work. Therefore, I want to declare high-level axioms, such as the commutativity of multiplication... or even higher level, like the central limit theorem. (The system gives no guarantee that they're true).
Re: why declare commutativity
Date: 2008-10-12 06:14 am (UTC)Rule of thumb: Twelf is a programming language through-and-through, and so if you're going to expect it to believe f(a,b) = f(b,a) then the absolute least you'll have to do is write a program that explains why on earth that is the case. You can tell it "assume this is true and I'll explain why later/never," but this isn't done elegantly in Twelf and seems, in Twelf at least, to lead to making a lot of the problematic errors that you wanted formalization to avoid in the first place.