Re: [Hol-info] Improve EXISTS_TAC with by taking hints from the assumption list

2012-12-28 Thread Vincent Aravantinos

Le 27/12/12 06:55, Ramana Kumar a écrit :
Do you have a clone of the HOL4 git repository? You could make a pull 
request on github after adding HINT_EXISTS_TAC in an appropriate place.


I'd totally be ready to do this, but I would like, first of all, to be 
sure people share my interest in the features of HINT_EXISTS_TAC: I 
don't want to pollute the repo with new tactics that I am the only one 
to find useful.
In particular, it seems from this discussion that there are several 
"close" solutions in HOL4.
However, none of them allows to just make progress in a goal without 
solving it completely.
In my opinion, that's an essential aspect of HINT_EXISTS_TAC, but I'm 
not sure this opinion is shared by any of you guys? :-)


In addition to match_assum_abbrev_tac, there is 
match_assum_rename_tac. Both of them could do with some improvement, 
e.g. see https://github.com/mn200/HOL/issues/81. If you happen to 
delve into this code, your patches would be warmly welcomed :)
On Thu, Dec 27, 2012 at 6:48 PM, Vincent Aravantinos 
mailto:vincent.aravanti...@gmail.com>> 
wrote:


Hi Michael,

I'm regularly amazed by the pearls that HOL4 contains...
I did not know about the SatisfySimps module!

Now, from my first tests, this can only be used to conclude a goal.
Concretely, if I have a goal of the following form:

?x. P x /\ Q x

  0. P t
  ...

where Q x cannot be solved immediatly (assume it can be solved
from other theorems or the other assumptions, but not automatically).
Then SATISFY_ss won't do anything because of Q x.
On the other hand, HINT_EXISTS_TAC will instantiate x by t, just
leaving Q t as a new goal to prove (of course the new goal is not
equivalent to the previous one, but the purpose of the tactic is
just to make some progress and help the user reducing parts of the
goal easily).

Am I right about this behaviour of SATISFY_ss or did I miss something?

V.

Le 26/12/12 23:17, Michael Norrish a écrit :

HOL4’s SATISFY_ss (from SatisfySimps) should solve this problem
(particularly now that Thomas Türk has fixed a bug in its code).

Michael

On 27/12/2012, at 11:42, Ramana Kumar mailto:ram...@member.fsf.org>> wrote:


For what it's worth, my usual move in this situation is to do

qmatch_assum_abbrev_tac 'P t' >>
qexists_tac 't' >>
simp[Abbr'X']

Note that P is a metavariable, i.e. I have to type it out, but I
avoid typing the large term abbreviated by t. The X stands for
pieces of P I want unabbreviated after.

HINT_EXISTS_TAC might still be an improvement.

Sorry for no proper backquotes, using my phone.

On Dec 26, 2012 10:57 PM, "Vincent Aravantinos"
mailto:vincent.aravanti...@gmail.com>> wrote:

Hi list,

here is another situation which I don't like and often meet
(both in
HOL-Light and HOL4), and a potential solution.
Please tell me if you also often meet the situation, if you
agree that
it is annoying, and if there is already a solution which I
don't know of
(I'm pretty sure there is no solution in HOL-Light, but I'm
not familiar
with all its extensions over there).

SITUATION:

   goal of the form `?x. ... /\ P x /\ ...`
   + one of the assumptions is of the form `P t` (t is a big
a term)
   + one wants to use t as the witness for x


USUAL MOVE:

   e (EXISTS_TAC `t`)
   (*Then rewrite with the assumptions in order to remove
the now
trivial P t:*)
   e(ASM_REWRITE_TAC[])


PROBLEM WITH THIS:

   Annoying to write explicitly the big term t.
   Plus the subsequent ASM_REWRITE_TAC is trivial and can
thus be
systematized.
   Not really annoying if it only appears from time to time,
but I
personally often face this situation.


SOLUTION:

   A tactic HINT_EXISTS_TAC which looks for an assumption
matching one
(or more) of the conjuncts in the conclusion and applies
EXISTS_TAC with
the corresponding term.


EXAMPLE IN HOL-LIGHT:

  (* Consider the following goal:*)

 0 [`P m`]
 1 [`!x. P x ==> x <= m`]

   `?x. P x`

   (* Usual move: *)
   # e (EXISTS_TAC `m:num`);;
   val it : goalstack = 1 subgoal (1 total)

 0 [`P m`]
 1 [`!x. P x ==> x <= m`]

   `P m`

   # e (ASM_REWRITE_TAC[]);;
   val it : goalstack = No subgoals

   (* New solution, which finds the witness automatically
and removes
the trivial conjunct : *)

   # b (); b (); e HINT_EXISTS_TAC;;
   val it : goalstack = No subgoals

   (* Notes:
* - The use case gets more interesting when m is
actually a big term.

Re: [Hol-info] Improve EXISTS_TAC with by taking hints from the assumption list

2012-12-28 Thread Vincent Aravantinos
Hi Thomas,

Le 27/12/12 07:30, Thomas Tuerk a écrit :
> On Thu, 2012-12-27 at 19:55 +0800, Ramana Kumar wrote:
>> There might be something in quantHeuristicsLib that can help, but I'm
>> not sure.
> quantHeuristicsLib can do it (see below), but has other restrictions.
>
> SATISFY_ss allows to instantiate multiple variables at the same time.
> So, it can for example handle:
>
> ?x y. P x y /\ Q y x
> -
> 0. P 1 2
> 1. !x. Q 2 x
>
> Notice, assumption 1. SATISFY_ss does not use matching but unification
> with restriction to the variables occurring all-quantified
> in an assumption or existentially in the current goal.
> quantHeuristicsLib can currently only handle one variable at a time.
I thought of this problem (handling more than 1 variable at a time) while
writing HINT_EXISTS_TAC but came to the conclusion that I just wanted
a pragmatic solution that does not claim to solve all the problems but
just to be useful in many situations. Therefore, solving for one variable
only seemed sufficient to me.

> However, using consequence conversions it can do your kind of
> instantiation guessing also at subpositions.
>
> Getting quantHeuristicLib to do what you want requires writing some
> ML-code, though. By default, it only searches for guesses with
> justification, i.e. it only instantiates a quantifier, if it can
> prove that the resulting term is really equivalent.
> For example:
>
> ?x. P x /\ Q x
> ---
> P 2
>
> would not be instantated with 2, because Q 2 might be false, but there
> may still be a "x" that satisfies both. In order to get it working for
> your case, you need to "tell" it to use unjustified guesses for
> conjunction. Given ?x. X x /\ Y x, it should search for guesses for X x
> and Y x and return all found guesses, even if it can't prove that they
> are not guesses for the overall conjunct.
>
> "implication_concl_qp" in
> "src/quantHeuristicsLib/quantHeuristicsParameter" does this for the
> right hand side of implications. One could use that code as a basis or
> generalise it.

I see. I'll have a look for my culture, but I think in the end that it 
will be
simpler, if I need it, to just translate my current HINT_EXISTS_TAC to
HOL4 (roughly nothing more than Ocaml->SML). I'll have a look at
quantHeuristicsLib when I get the time though, because maybe the
my problem will actually happen to be useless in the end.

Thanks,
V.

-- 
Vincent ARAVANTINOS - PostDoctoral Fellow - Concordia University, Hardware
Verification Group
http://users.encs.concordia.ca/~vincent/


--
Master HTML5, CSS3, ASP.NET, MVC, AJAX, Knockout.js, Web API and
much more. Get web development skills now with LearnDevNow -
350+ hours of step-by-step video tutorials by Microsoft MVPs and experts.
SALE $99.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122812
___
hol-info mailing list
hol-info@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/hol-info


Re: [Hol-info] Improve EXISTS_TAC with by taking hints from the assumption list

2012-12-28 Thread Michael Norrish
On 28/12/2012, at 23:07, Vincent Aravantinos  
wrote:

> Le 27/12/12 06:55, Ramana Kumar a écrit :
>> Do you have a clone of the HOL4 git repository? You could make a pull 
>> request on github after adding HINT_EXISTS_TAC in an appropriate place.
> 
> I'd totally be ready to do this, but I would like, first of all, to be sure 
> people share my interest in the features of HINT_EXISTS_TAC: I don't want to 
> pollute the repo with new tactics that I am the only one to find useful.

> In particular, it seems from this discussion that there are several "close" 
> solutions in HOL4.
> However, none of them allows to just make progress in a goal without solving 
> it completely.
> In my opinion, that's an essential aspect of HINT_EXISTS_TAC, but I'm not 
> sure this opinion is shared by any of you guys? :-)

I think my first reaction to a clean implementation with test cases (in a 
selftest.sml file, say) and documentation (a .doc file) would be to accept 
first and ask questions later.  If it turns out that something really is 
redundant or otherwise unloved given other facilities in the system it can 
always be removed.

Michael
--
Master HTML5, CSS3, ASP.NET, MVC, AJAX, Knockout.js, Web API and
much more. Get web development skills now with LearnDevNow -
350+ hours of step-by-step video tutorials by Microsoft MVPs and experts.
SALE $99.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122812
___
hol-info mailing list
hol-info@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/hol-info


Re: [Hol-info] Improve EXISTS_TAC with by taking hints from the assumption list

2012-12-28 Thread Vincent Aravantinos
Le 28/12/12 08:01, Thomas Tuerk a écrit :
> Dear Vincent,
>
>> I see. I'll have a look for my culture, but I think in the end that it
>> will be simpler, if I need it, to just translate my current HINT_EXISTS_TAC 
>> to
>> HOL4 (roughly nothing more than Ocaml->SML). I'll have a look at
>> quantHeuristicsLib when I get the time though, because maybe the
>> my problem will actually happen to be useless in the end.
> this makes sense. Using quantHeuristicsLib or consequence conversions would 
> provide
> you with a bit more power. However, to solve exactly the problem you 
> described,
> it is really easier to just port your OCaml code.
>
> I might be interested in your problem in general, though. I still look for
> users for my quantifier heuristic library. I implemented this library as
> an extensible one than can easily be extended by the user.
> What kind of quantifier problems do you have?
> Is there some other kind of automation you might be interested in.
I don't know yet. It will depend on my practical needs. I'll tell you if 
I find something that can be of interest.


Cheers,
V.

--
Master HTML5, CSS3, ASP.NET, MVC, AJAX, Knockout.js, Web API and
much more. Get web development skills now with LearnDevNow -
350+ hours of step-by-step video tutorials by Microsoft MVPs and experts.
SALE $99.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122812
___
hol-info mailing list
hol-info@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/hol-info


Re: [Hol-info] Learning HOL Light

2012-12-28 Thread Bill Richter
I finally understand how to translate between miz3 and straight HOL Light.  I 
profited from the Mizar-like code in the HOL Light tutorial p 76--78, which I 
modified to 

let consider th pf = SUBGOAL_THEN th CHOOSE_TAC THENL [pf; ALL_TAC];;
let state th pf = SUBGOAL_THEN th ASSUME_TAC THENL [pf; ALL_TAC];;
let statelab th lab pf = SUBGOAL_THEN th (LABEL_TAC lab) THENL [pf; ALL_TAC];;
let toprove th = SUBGOAL_THEN th ASSUME_TAC;;
let mby labs MesonList = MAP_EVERY (fun l -> USE_THEN l MP_TAC) labs THEN 
(MESON_TAC MesonList);;
let soby labs MesonList = FIRST_ASSUM MP_TAC THEN MAP_EVERY 
   (fun l -> USE_THEN l MP_TAC) labs THEN (MESON_TAC MesonList);;

Using this code I mechanically turned a 35-line miz3 proof of 

UniversalPropertyProduct
  |- ∀ M A B f g.
 f ∈ M → A ∧ g ∈ M → B
 ⇒ (∃! h. h ∈ M → A ∏ B  ∧  FST ∘ (h,M) = f  ∧  SND ∘ (h,M) = g)

into a 28-line tactics script with almost identical MESON solved at numbers: 
42063, 42992, 2590, 2687, 4515, 70020
42063, 42992, 1757 1854 4173, 70020

The only purpose of my Mizar-like code is to replace long lines with much 
shorter ones, as in

e(FIRST_ASSUM MP_TAC THEN USE_THEN "hDef" MP_TAC  THEN USE_THEN "kOffM" MP_TAC 
THEN 
   MESON_TAC[FUN_EQ_THM; ∉]);;
soby ["hDef"; "kOffM"] [FUN_EQ_THM; ∉]

As Rob explained, STRIP_ASSUME_TAC handles the miz3 cases, so there's no need 
for special coding.  My `toprove' could easily be removed, and `state th pf' 
could be replaced by `statelab th "" pf'.  

Here's my tactics script for UniversalPropertyProduct, together with the 
definitions and lemmas needed and my modification of John's Mizar-like code, 
first with more readable math characters, with working HOL Light code below.  
I'm including the miz3 proof, and you can see it's practically the same as my 
tactics script except the miz3 proof is prettier, far fewer backquotes, 
double-quotes, square braces, parentheses and type annotations.  I impressed 
that Freek made the miz3 code so pretty, and got Ocaml to cache results, but 
it's basically what I'm doing in my tactics script.

parse_as_infix("∉",(11, "right"));;
parse_as_infix("∏",(20, "right"));;
parse_as_infix("∘",(20, "right"));;
parse_as_infix("→",(13,"right"));;

let ∉ = new_definition
  `∀ a:A l:A->bool. a ∉ l ⇔ ¬(a ∈ l)`;;

let CartesianProduct = new_definition
   `∀ X Y. X ∏ Y = {x,y | x ∈ X ∧ y ∈ Y}`;;

let IN_CartesianProduct = prove
 (`∀ X Y x y. x,y ∈ X ∏ Y  ⇔  x ∈ X ∧ y ∈ Y`,
  REWRITE_TAC[IN_ELIM_THM; CartesianProduct] THEN MESON_TAC[PAIR_EQ]);;

let FunctionSpace = new_definition
   `∀ s t. s → t = {f | (∀ x. x ∈ s ⇒ f x  ∈ t) ∧
  ∀ x. x ∉ s ⇒ f x  = @y. T}`;;

let IN_FunctionSpace = prove
  (`∀ s t f. f ∈ s → t  
  ⇔  (∀ x. x ∈ s ⇒ f x ∈ t)  ∧  ∀ x. x ∉ s ⇒ f x  = @y. T`,
  REWRITE_TAC[IN_ELIM_THM; FunctionSpace]);;

let FunctionComposition = new_definition
  `∀ f:A->B s:A->bool g:B->C x.
  (g ∘ (f,s)) x = if x ∈ s then g (f x) else @y:C. T`;;

let UniversalPropertyProduct = prove
  (`∀ M:μ->bool A:α->bool B:β->bool f:μ->α g:μ->β .
 f ∈ M → A ∧ g ∈ M → B
 ⇒ (∃! h. h ∈ M → A ∏ B  ∧  FST ∘ (h,M) = f  ∧  SND ∘ (h,M) = g)`,
   REPEAT GEN_TAC THEN DISCH_THEN(LABEL_TAC "H1") THEN
   consider `?h:μ->α#β.  h = λx:μ. if x ∈ M then f x,g x else @y. T` (mby [] 
[]) THEN
   statelab `∀ x:μ. (x ∈ M  ⇒  (h:μ->α#β) x = f x,g x) ∧ (x ∉ M  ⇒  h x = @y. 
T)` "hDef"
   (soby [] [∉]) THEN
   statelab `∀ x:μ. x ∈ M  ⇒  (h:μ->α#β) x ∈ A ∏ B` "hProd" (soby ["H1"] 
[IN_FunctionSpace; IN_CartesianProduct]) THEN
   state `∀ x:μ. x ∈ M  ⇒  FST ((h:μ->α#β) x) = f x  ∧  SND (h x) = g x` 
   (mby ["hDef"] [FST_DEF; SND_DEF; PAIR_EQ]) THEN
   state `∀ x:μ. (x ∈ M  ⇒  (FST ∘ ((h:μ->α#β),M)) x = f x) ∧ (x ∉ M  ⇒  (FST ∘ 
(h,M)) x = f x)  ∧ 
(x ∈ M  ⇒  (SND ∘ (h,M)) x = g x) ∧ (x ∉ M  ⇒  (SND ∘ (h,M)) x = g x)`
   (soby ["H1"] [FunctionComposition; ∉; IN_FunctionSpace]) THEN
   statelab `(h:μ->α#β) ∈ M → A ∏ B  ∧  FST ∘ (h,M) = f  ∧  SND ∘ (h,M) = g` 
"hWorks"
   (soby ["hDef"; "hProd"] [IN_FunctionSpace; ∉; FUN_EQ_THM]) THEN
   toprove `∀ (k:μ->α#β). (k ∈ M → A ∏ B  ∧  FST ∘ (k,M) = f  ∧  SND ∘ (k,M) = 
g)  ⇒ h = k`
THENL[GEN_TAC THEN DISCH_THEN(LABEL_TAC "kWorks");
soby ["hWorks"] [EXISTS_UNIQUE_THM]] THEN
statelab `∀ x:μ. x ∉ M  ⇒  (k:μ->α#β) x = @y. T` "kOffM" (soby [] 
[IN_FunctionSpace]) THEN
toprove `∀ x:μ. x ∈ M ⇒ (k:μ->α#β) x = f x,g x ` THENL[
GEN_TAC THEN DISCH_THEN(LABEL_TAC "xM");
soby ["hDef"; "kOffM"] [FUN_EQ_THM; ∉]] THEN
state `FST ((k:μ->α#β) x) = f x  ∧  SND (k x) = g x` (soby ["kWorks"] 
[FunctionComposition]) THEN
state `(k:μ->α#β) x = FST (k x), SND (k x)  ∧ FST (k x) = f x  ∧ SND (k x) 
= g x` 
   (soby ["kWorks"] [PAIR]) THEN
   soby [] [PAIR_EQ]);;


Here's my original miz3 proof, which I mechanically turned into the above 
tactics script.  I think they look very similar, and I think this shows that I 
understand miz3 in terms of HOL LIGHT. 


let UniversalPropertyProduct = thm `;
  ∀ M:μ->bool A:α->bool B:β->bool 

Re: [Hol-info] Improve EXISTS_TAC with by taking hints from the assumption list

2012-12-28 Thread Vincent Aravantinos
Le 28/12/12 08:20, Michael Norrish a écrit :
> I think my first reaction to a clean implementation with test cases 
> (in a selftest.sml file, say) and documentation (a .doc file) would be 
> to accept first and ask questions later. If it turns out that 
> something really is redundant or otherwise unloved given other 
> facilities in the system it can always be removed. Michael 
Ok. For now, here is a fast translation of HINT_EXISTS_TAC for HOL4:


fun HINT_EXISTS_TAC g =
   let
 val (hs,c) = g
 val (v,c') = dest_exists c
 val (vs,c') = strip_exists c'
 fun hyp_match c h =
   if exists (C mem vs) (free_vars c)
   then fail ()
   else (match_term c h,h)
 val ((subs,_),h) = tryfind (C tryfind hs o hyp_match) (strip_conj c')
 val witness =
   case subs of
  [] => v
 |[{redex = u, residue = t}] =>
 if u = v then t else failwith "GEN_HINT_EXISTS_TAC not 
applicable"
 |_ => failwith "GEN_HINT_EXISTS_TAC not applicable"
   in
 (EXISTS_TAC witness THEN ASM_REWRITE_TAC[]) g
   end;


Cheers,
V.

-- 
Vincent ARAVANTINOS - PostDoctoral Fellow - Concordia University, Hardware
Verification Group
http://users.encs.concordia.ca/~vincent/


--
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. SALE $99.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122912
___
hol-info mailing list
hol-info@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/hol-info