1 (* Copyright (C) 2002, HELM Team.
3 * This file is part of HELM, an Hypertextual, Electronic
4 * Library of Mathematics, developed at the Computer Science
5 * Department, University of Bologna, Italy.
7 * HELM is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * HELM is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with HELM; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * For details, see the HELM World-Wide-Web page,
23 * http://cs.unibo.it/helm/.
26 open ProofEngineHelpers
29 exception NotAnInductiveTypeToEliminate
30 exception NotTheRightEliminatorShape
31 exception NoHypothesesFound
32 exception WrongUriToVariable of string
34 (* lambda_abstract newmeta ty *)
35 (* returns a triple [bo],[context],[ty'] where *)
36 (* [ty] = Pi/LetIn [context].[ty'] ([context] is a vector!) *)
37 (* and [bo] = Lambda/LetIn [context].(Meta [newmeta]) *)
38 (* So, lambda_abstract is the core of the implementation of *)
39 (* the Intros tactic. *)
40 (* howmany = -1 means Intros, howmany > 0 means Intros n *)
41 let lambda_abstract ?(howmany=(-1)) metasenv context newmeta ty mk_fresh_name =
43 let rec collect_context context howmany ty =
47 CicMkImplicit.identity_relocation_list_for_metavariable context
49 context, ty, (C.Meta (newmeta,irl))
52 C.Cast (te,_) -> collect_context context howmany te
54 let n' = mk_fresh_name metasenv context n ~typ:s in
55 let (context',ty,bo) =
56 collect_context ((Some (n',(C.Decl s)))::context) (howmany - 1) t
58 (context',ty,C.Lambda(n',s,bo))
60 let (context',ty,bo) =
61 collect_context ((Some (n,(C.Def (s,None))))::context) (howmany - 1) t
63 (context',ty,C.LetIn(n,s,bo))
66 CicMkImplicit.identity_relocation_list_for_metavariable context
68 context, t, (C.Meta (newmeta,irl))
70 collect_context context howmany ty
72 let eta_expand metasenv context t arg =
73 let module T = CicTypeChecker in
74 let module S = CicSubstitution in
78 t' when t' = S.lift n arg -> C.Rel (1 + n)
79 | C.Rel m -> if m <= n then C.Rel m else C.Rel (m+1)
80 | C.Var (uri,exp_named_subst) ->
81 let exp_named_subst' = aux_exp_named_subst n exp_named_subst in
82 C.Var (uri,exp_named_subst')
85 List.map (function None -> None | Some t -> Some (aux n t)) l
89 | C.Implicit _ as t -> t
90 | C.Cast (te,ty) -> C.Cast (aux n te, aux n ty)
91 | C.Prod (nn,s,t) -> C.Prod (nn, aux n s, aux (n+1) t)
92 | C.Lambda (nn,s,t) -> C.Lambda (nn, aux n s, aux (n+1) t)
93 | C.LetIn (nn,s,t) -> C.LetIn (nn, aux n s, aux (n+1) t)
94 | C.Appl l -> C.Appl (List.map (aux n) l)
95 | C.Const (uri,exp_named_subst) ->
96 let exp_named_subst' = aux_exp_named_subst n exp_named_subst in
97 C.Const (uri,exp_named_subst')
98 | C.MutInd (uri,i,exp_named_subst) ->
99 let exp_named_subst' = aux_exp_named_subst n exp_named_subst in
100 C.MutInd (uri,i,exp_named_subst')
101 | C.MutConstruct (uri,i,j,exp_named_subst) ->
102 let exp_named_subst' = aux_exp_named_subst n exp_named_subst in
103 C.MutConstruct (uri,i,j,exp_named_subst')
104 | C.MutCase (sp,i,outt,t,pl) ->
105 C.MutCase (sp,i,aux n outt, aux n t,
108 let tylen = List.length fl in
111 (fun (name,i,ty,bo) -> (name, i, aux n ty, aux (n+tylen) bo))
114 C.Fix (i, substitutedfl)
116 let tylen = List.length fl in
119 (fun (name,ty,bo) -> (name, aux n ty, aux (n+tylen) bo))
122 C.CoFix (i, substitutedfl)
123 and aux_exp_named_subst n =
124 List.map (function uri,t -> uri,aux n t)
127 T.type_of_aux' metasenv context arg CicUniv.empty_ugraph (* TASSI: FIXME *)
130 FreshNamesGenerator.mk_fresh_name ~subst:[]
131 metasenv context (Cic.Name "Heta") ~typ:argty
133 (C.Appl [C.Lambda (fresh_name,argty,aux 0 t) ; arg])
135 (*CSC: ma serve solamente la prima delle new_uninst e l'unione delle due!!! *)
136 let classify_metas newmeta in_subst_domain subst_in metasenv =
138 (fun (i,canonical_context,ty) (old_uninst,new_uninst) ->
139 if in_subst_domain i then
140 old_uninst,new_uninst
142 let ty' = subst_in canonical_context ty in
143 let canonical_context' =
145 (fun entry canonical_context' ->
148 Some (n,Cic.Decl s) ->
149 Some (n,Cic.Decl (subst_in canonical_context' s))
150 | Some (n,Cic.Def (s,None)) ->
151 Some (n,Cic.Def ((subst_in canonical_context' s),None))
153 | Some (_,Cic.Def (_,Some _)) -> assert false
155 entry'::canonical_context'
156 ) canonical_context []
159 ((i,canonical_context',ty')::old_uninst),new_uninst
161 old_uninst,((i,canonical_context',ty')::new_uninst)
164 (* Auxiliary function for apply: given a type (a backbone), it returns its *)
165 (* head, a META environment in which there is new a META for each hypothesis,*)
166 (* a list of arguments for the new applications and the indexes of the first *)
167 (* and last new METAs introduced. The nth argument in the list of arguments *)
168 (* is just the nth new META. *)
169 let new_metasenv_for_apply newmeta proof context ty =
170 let module C = Cic in
171 let module S = CicSubstitution in
172 let rec aux newmeta ty =
175 C.Cast (he,_) -> aux newmeta he
176 (* CSC: patch to generate ?1 : ?2 : Type in place of ?1 : Type to simulate ?1 :< Type
177 (* If the expected type is a Type, then also Set is OK ==>
178 * we accept any term of type Type *)
179 (*CSC: BUG HERE: in this way it is possible for the term of
180 * type Type to be different from a Sort!!! *)
181 | C.Prod (name,(C.Sort (C.Type _) as s),t) ->
182 (* TASSI: ask CSC if BUG HERE refers to the C.Cast or C.Propd case *)
184 CicMkImplicit.identity_relocation_list_for_metavariable context
186 let newargument = C.Meta (newmeta+1,irl) in
187 let (res,newmetasenv,arguments,lastmeta) =
188 aux (newmeta + 2) (S.subst newargument t)
191 (newmeta,[],s)::(newmeta+1,context,C.Meta (newmeta,[]))::newmetasenv,
192 newargument::arguments,lastmeta
194 | C.Prod (name,s,t) ->
196 CicMkImplicit.identity_relocation_list_for_metavariable context
198 let newargument = C.Meta (newmeta,irl) in
199 let (res,newmetasenv,arguments,lastmeta) =
200 aux (newmeta + 1) (S.subst newargument t)
202 let s' = CicReduction.normalize ~delta:false context s in
203 res,(newmeta,context,s')::newmetasenv,newargument::arguments,lastmeta
204 (** NORMALIZE RATIONALE
205 * we normalize the target only NOW since we may be in this case:
206 * A1 -> A2 -> T where T = (\lambda x.A3 -> P) k
207 * and we want a mesasenv with ?1:A1 and ?2:A2 and not
208 * ?1, ?2, ?3 (that is the one we whould get if we start from the
209 * beta-normalized A1 -> A2 -> A3 -> P **)
210 | t -> (CicReduction.normalize ~delta:false context t),[],[],newmeta
212 (* WARNING: here we are using the invariant that above the most *)
213 (* recente new_meta() there are no used metas. *)
214 let (res,newmetasenv,arguments,lastmeta) = aux newmeta ty in
215 res,newmetasenv,arguments,lastmeta
217 (* Useful only inside apply_tac *)
219 generalize_exp_named_subst_with_fresh_metas context newmeta uri exp_named_subst
221 let module C = Cic in
223 let o,_ = CicEnvironment.get_obj CicUniv.empty_ugraph uri in
224 CicUtil.params_of_obj o
226 let exp_named_subst_diff,new_fresh_meta,newmetasenvfragment,exp_named_subst'=
227 let next_fresh_meta = ref newmeta in
228 let newmetasenvfragment = ref [] in
229 let exp_named_subst_diff = ref [] in
235 let o,_ = CicEnvironment.get_obj CicUniv.empty_ugraph uri in
237 C.Variable (_,_,ty,_,_) ->
238 CicSubstitution.subst_vars !exp_named_subst_diff ty
239 | _ -> raise (WrongUriToVariable (UriManager.string_of_uri uri))
241 (* CSC: patch to generate ?1 : ?2 : Type in place of ?1 : Type to simulate ?1 :< Type
243 C.Sort (C.Type _) as s -> (* TASSI: ?? *)
244 let fresh_meta = !next_fresh_meta in
245 let fresh_meta' = fresh_meta + 1 in
246 next_fresh_meta := !next_fresh_meta + 2 ;
247 let subst_item = uri,C.Meta (fresh_meta',[]) in
248 newmetasenvfragment :=
249 (fresh_meta,[],C.Sort (C.Type (CicUniv.fresh()))) ::
251 (fresh_meta',[],C.Meta (fresh_meta,[])) :: !newmetasenvfragment ;
252 exp_named_subst_diff := !exp_named_subst_diff @ [subst_item] ;
253 subst_item::(aux (tl,[]))
257 CicMkImplicit.identity_relocation_list_for_metavariable context
259 let subst_item = uri,C.Meta (!next_fresh_meta,irl) in
260 newmetasenvfragment :=
261 (!next_fresh_meta,context,ty)::!newmetasenvfragment ;
262 exp_named_subst_diff := !exp_named_subst_diff @ [subst_item] ;
263 incr next_fresh_meta ;
264 subst_item::(aux (tl,[]))(*)*)
265 | uri::tl1,((uri',_) as s)::tl2 ->
266 assert (UriManager.eq uri uri') ;
268 | [],_ -> assert false
270 let exp_named_subst' = aux (params,exp_named_subst) in
271 !exp_named_subst_diff,!next_fresh_meta,
272 List.rev !newmetasenvfragment, exp_named_subst'
274 new_fresh_meta,newmetasenvfragment,exp_named_subst',exp_named_subst_diff
277 let new_metasenv_and_unify_and_t newmeta' metasenv' proof context term' ty termty =
278 let (consthead,newmetas,arguments,_) =
279 new_metasenv_for_apply newmeta' proof context termty
281 let newmetasenv = metasenv'@newmetas in
282 let subst,newmetasenv',_ =
283 CicUnification.fo_unif newmetasenv context consthead ty CicUniv.empty_ugraph
286 if List.length newmetas = 0 then term' else Cic.Appl (term'::arguments)
290 let apply_tac_verbose ~term (proof, goal) =
291 (* Assumption: The term "term" must be closed in the current context *)
292 let module T = CicTypeChecker in
293 let module R = CicReduction in
294 let module C = Cic in
295 let (_,metasenv,_,_) = proof in
296 let metano,context,ty = CicUtil.lookup_meta goal metasenv in
297 let newmeta = new_meta_of_proof ~proof in
298 let exp_named_subst_diff,newmeta',newmetasenvfragment,term' =
300 C.Var (uri,exp_named_subst) ->
301 let newmeta',newmetasenvfragment,exp_named_subst',exp_named_subst_diff =
302 generalize_exp_named_subst_with_fresh_metas context newmeta uri
305 exp_named_subst_diff,newmeta',newmetasenvfragment,
306 C.Var (uri,exp_named_subst')
307 | C.Const (uri,exp_named_subst) ->
308 let newmeta',newmetasenvfragment,exp_named_subst',exp_named_subst_diff =
309 generalize_exp_named_subst_with_fresh_metas context newmeta uri
312 exp_named_subst_diff,newmeta',newmetasenvfragment,
313 C.Const (uri,exp_named_subst')
314 | C.MutInd (uri,tyno,exp_named_subst) ->
315 let newmeta',newmetasenvfragment,exp_named_subst',exp_named_subst_diff =
316 generalize_exp_named_subst_with_fresh_metas context newmeta uri
319 exp_named_subst_diff,newmeta',newmetasenvfragment,
320 C.MutInd (uri,tyno,exp_named_subst')
321 | C.MutConstruct (uri,tyno,consno,exp_named_subst) ->
322 let newmeta',newmetasenvfragment,exp_named_subst',exp_named_subst_diff =
323 generalize_exp_named_subst_with_fresh_metas context newmeta uri
326 exp_named_subst_diff,newmeta',newmetasenvfragment,
327 C.MutConstruct (uri,tyno,consno,exp_named_subst')
328 | _ -> [],newmeta,[],term
330 let metasenv' = metasenv@newmetasenvfragment in
332 CicTypeChecker.type_of_aux' metasenv' context term CicUniv.empty_ugraph in
334 CicSubstitution.subst_vars exp_named_subst_diff termty
336 (* prerr_endline ("term:" ^ CicPp.ppterm term);*)
337 (* prerr_endline ("termty:" ^ CicPp.ppterm termty);*)
338 let subst,newmetasenv',t =
340 new_metasenv_and_unify_and_t newmeta' metasenv' proof context term' ty
342 with CicUnification.UnificationFailure _ ->
343 new_metasenv_and_unify_and_t newmeta' metasenv' proof context term' ty
344 (CicReduction.whd context termty)
346 let in_subst_domain i = List.exists (function (j,_) -> i=j) subst in
347 let apply_subst = CicMetaSubst.apply_subst subst in
348 let old_uninstantiatedmetas,new_uninstantiatedmetas =
349 (* subst_in doesn't need the context. Hence the underscore. *)
350 let subst_in _ = CicMetaSubst.apply_subst subst in
351 classify_metas newmeta in_subst_domain subst_in newmetasenv'
353 let bo' = apply_subst t in
354 let newmetasenv'' = new_uninstantiatedmetas@old_uninstantiatedmetas in
355 (* prerr_endline ("me: " ^ CicMetaSubst.ppmetasenv newmetasenv'' subst); *)
357 (* if we just apply the subtitution, the type is irrelevant:
358 we may use Implicit, since it will be dropped *)
359 CicMetaSubst.apply_subst ((metano,(context,bo',Cic.Implicit None))::subst)
361 let (newproof, newmetasenv''') =
362 subst_meta_and_metasenv_in_proof proof metano subst_in newmetasenv''
366 List.map (function (i,_,_) -> i) new_uninstantiatedmetas))
368 let apply_tac ~term status = snd (apply_tac_verbose ~term status)
370 let apply_tac_verbose ~term status =
372 apply_tac_verbose ~term status
373 (* TODO cacciare anche altre eccezioni? *)
374 with CicUnification.UnificationFailure _ as e ->
375 raise (Fail (Printexc.to_string e))
377 (* TODO per implementare i tatticali e' necessario che tutte le tattiche
378 sollevino _solamente_ Fail *)
379 let apply_tac ~term =
380 let apply_tac ~term status =
382 apply_tac ~term status
383 (* TODO cacciare anche altre eccezioni? *)
384 with CicUnification.UnificationFailure _ as e ->
385 raise (Fail (Printexc.to_string e))
387 mk_tactic (apply_tac ~term)
389 let intros_tac ?howmany ?(mk_fresh_name_callback = FreshNamesGenerator.mk_fresh_name ~subst:[]) ()=
391 ?(mk_fresh_name_callback = (FreshNamesGenerator.mk_fresh_name ~subst:[])) ()
394 let module C = Cic in
395 let module R = CicReduction in
396 let (_,metasenv,_,_) = proof in
397 let metano,context,ty = CicUtil.lookup_meta goal metasenv in
398 let newmeta = new_meta_of_proof ~proof in
399 let (context',ty',bo') =
400 lambda_abstract ?howmany metasenv context newmeta ty mk_fresh_name_callback
403 subst_meta_in_proof proof metano bo' [newmeta,context',ty']
405 (newproof, [newmeta])
407 mk_tactic (intros_tac ~mk_fresh_name_callback ())
409 let cut_tac?(mk_fresh_name_callback = FreshNamesGenerator.mk_fresh_name ~subst:[]) ~term=
411 ?(mk_fresh_name_callback = FreshNamesGenerator.mk_fresh_name ~subst:[])
414 let module C = Cic in
415 let curi,metasenv,pbo,pty = proof in
416 let metano,context,ty = CicUtil.lookup_meta goal metasenv in
417 let newmeta1 = new_meta_of_proof ~proof in
418 let newmeta2 = newmeta1 + 1 in
420 mk_fresh_name_callback metasenv context (Cic.Name "Hcut") ~typ:term in
421 let context_for_newmeta1 =
422 (Some (fresh_name,C.Decl term))::context in
424 CicMkImplicit.identity_relocation_list_for_metavariable
428 CicMkImplicit.identity_relocation_list_for_metavariable context
430 let newmeta1ty = CicSubstitution.lift 1 ty in
433 [C.Lambda (fresh_name,term,C.Meta (newmeta1,irl1)) ;
434 C.Meta (newmeta2,irl2)]
437 subst_meta_in_proof proof metano bo'
438 [newmeta2,context,term; newmeta1,context_for_newmeta1,newmeta1ty];
440 (newproof, [newmeta1 ; newmeta2])
442 mk_tactic (cut_tac ~mk_fresh_name_callback term)
444 let letin_tac ?(mk_fresh_name_callback=FreshNamesGenerator.mk_fresh_name ~subst:[]) ~term=
446 ?(mk_fresh_name_callback = FreshNamesGenerator.mk_fresh_name ~subst:[])
449 let module C = Cic in
450 let curi,metasenv,pbo,pty = proof in
451 let metano,context,ty = CicUtil.lookup_meta goal metasenv in
452 let _,_ = (* TASSI: FIXME *)
453 CicTypeChecker.type_of_aux' metasenv context term CicUniv.empty_ugraph in
454 let newmeta = new_meta_of_proof ~proof in
456 mk_fresh_name_callback metasenv context (Cic.Name "Hletin") ~typ:term in
457 let context_for_newmeta =
458 (Some (fresh_name,C.Def (term,None)))::context in
460 CicMkImplicit.identity_relocation_list_for_metavariable
463 let newmetaty = CicSubstitution.lift 1 ty in
464 let bo' = C.LetIn (fresh_name,term,C.Meta (newmeta,irl)) in
467 proof metano bo'[newmeta,context_for_newmeta,newmetaty]
469 (newproof, [newmeta])
471 mk_tactic (letin_tac ~mk_fresh_name_callback term)
473 (** functional part of the "exact" tactic *)
474 let exact_tac ~term =
475 let exact_tac ~term (proof, goal) =
476 (* Assumption: the term bo must be closed in the current context *)
477 let (_,metasenv,_,_) = proof in
478 let metano,context,ty = CicUtil.lookup_meta goal metasenv in
479 let module T = CicTypeChecker in
480 let module R = CicReduction in
481 let ty_term,u = T.type_of_aux' metasenv context term CicUniv.empty_ugraph in
482 let b,_ = R.are_convertible context ty_term ty u in (* TASSI: FIXME *)
485 let (newproof, metasenv') =
486 subst_meta_in_proof proof metano term [] in
490 raise (Fail "The type of the provided term is not the one expected.")
492 mk_tactic (exact_tac ~term)
494 (* not really "primitive" tactics .... *)
496 let elim_tac ~term (proof, goal) =
497 let module T = CicTypeChecker in
498 let module U = UriManager in
499 let module R = CicReduction in
500 let module C = Cic in
501 let (curi,metasenv,proofbo,proofty) = proof in
502 let metano,context,ty = CicUtil.lookup_meta goal metasenv in
503 let termty,_ = T.type_of_aux' metasenv context term CicUniv.empty_ugraph in
505 let uri,exp_named_subst,typeno,args =
507 C.MutInd (uri,typeno,exp_named_subst) -> (uri,exp_named_subst,typeno,[])
508 | C.Appl ((C.MutInd (uri,typeno,exp_named_subst))::args) ->
509 (uri,exp_named_subst,typeno,args)
510 | _ -> raise NotAnInductiveTypeToEliminate
513 let buri = U.buri_of_uri uri in
515 let o,_ = CicEnvironment.get_obj CicUniv.empty_ugraph uri in
517 C.InductiveDefinition (tys,_,_,_) ->
518 let (name,_,_,_) = List.nth tys typeno in
522 let ty_ty,_ = T.type_of_aux' metasenv context ty CicUniv.empty_ugraph in
526 C.Sort C.Prop -> "_ind"
527 | C.Sort C.Set -> "_rec"
528 | C.Sort C.CProp -> "_rec"
529 | C.Sort (C.Type _)-> "_rect"
532 U.uri_of_string (buri ^ "/" ^ name ^ ext ^ ".con")
534 let eliminator_ref = C.Const (eliminator_uri,exp_named_subst) in
536 T.type_of_aux' metasenv context eliminator_ref CicUniv.empty_ugraph in
537 let rec find_args_no =
539 C.Prod (_,_,t) -> 1 + find_args_no t
540 | C.Cast (s,_) -> find_args_no s
541 | C.LetIn (_,_,t) -> 0 + find_args_no t
544 let args_no = find_args_no ety in
546 let rec make_tl base_case =
549 | n -> (C.Implicit None)::(make_tl base_case (n - 1))
551 C.Appl (eliminator_ref :: make_tl term (args_no - 1))
553 let metasenv', term_to_refine' =
554 CicMkImplicit.expand_implicits metasenv [] context term_to_refine in
555 let refined_term,_,metasenv'',_ = (* TASSI: FIXME *)
556 CicRefine.type_of_aux' metasenv' context term_to_refine'
560 ProofEngineHelpers.compare_metasenvs
561 ~oldmetasenv:metasenv ~newmetasenv:metasenv''
563 let proof' = curi,metasenv'',proofbo,proofty in
564 let proof'', new_goals' =
565 apply_tactic (apply_tac ~term:refined_term) (proof',goal)
567 (* The apply_tactic can have closed some of the new_goals *)
568 let patched_new_goals =
569 let (_,metasenv''',_,_) = proof'' in
571 (function i -> List.exists (function (j,_,_) -> j=i) metasenv'''
572 ) new_goals @ new_goals'
574 proof'', patched_new_goals
576 mk_tactic (elim_tac ~term)
579 let elim_intros_tac ~term =
580 Tacticals.then_ ~start:(elim_tac ~term)
581 ~continuation:(intros_tac ())
584 (* The simplification is performed only on the conclusion *)
585 let elim_intros_simpl_tac ~term =
586 Tacticals.then_ ~start:(elim_tac ~term)
589 ~start:(intros_tac ())
591 [ReductionTactics.simpl_tac ~also_in_hypotheses:false ~terms:None])
594 exception NotConvertible
596 (*CSC: Bug (or feature?). [with_what] is parsed in the context of the goal, *)
597 (*CSC: while [what] can have a richer context (because of binders) *)
598 (*CSC: So it is _NOT_ possible to use those binders in the [with_what] term. *)
599 (*CSC: Is that evident? Is that right? Or should it be changed? *)
600 let change_tac ~what ~with_what =
601 let change_tac ~what ~with_what (proof, goal) =
602 let curi,metasenv,pbo,pty = proof in
603 let metano,context,ty = CicUtil.lookup_meta goal metasenv in
604 (* are_convertible works only on well-typed terms *)
606 CicTypeChecker.type_of_aux' metasenv context with_what
608 in (* TASSI: FIXME *)
610 CicReduction.are_convertible context what with_what u
615 ProofEngineReduction.replace
616 ~equality:(==) ~what:[what] ~with_what:[with_what]
618 let ty' = replace ty in
622 Some (name,Cic.Def (t,None))->
623 Some (name,Cic.Def ((replace t),None))
624 | Some (name,Cic.Decl t) -> Some (name,Cic.Decl (replace t))
626 | Some (_,Cic.Def (_,Some _)) -> assert false
632 (n,_,_) when n = metano -> (metano,context',ty')
636 (curi,metasenv',pbo,pty), [metano]
639 raise (ProofEngineTypes.Fail "Not convertible")
641 mk_tactic (change_tac ~what ~with_what)