256 else (HOLogic.mk_binop "op *" (norm_zero_one c,norm_zero_one t)) |
170 else (HOLogic.mk_binop "op *" (norm_zero_one c,norm_zero_one t)) |
257 |(node $ rest) => ((norm_zero_one node)$(norm_zero_one rest)) |
171 |(node $ rest) => ((norm_zero_one node)$(norm_zero_one rest)) |
258 |(Abs(x,T,p)) => (Abs(x,T,(norm_zero_one p))) |
172 |(Abs(x,T,p)) => (Abs(x,T,(norm_zero_one p))) |
259 |_ => fm; |
173 |_ => fm; |
260 |
174 |
261 |
|
262 (* ------------------------------------------------------------------------- *) |
|
263 (* Intended to tell that here we changed the structure of the formula with respect to the posineq theorem : ~(0 < t) = 0 < 1-t*) |
|
264 (* ------------------------------------------------------------------------- *) |
|
265 fun adjustcoeffeq_wp x l fm = |
|
266 case fm of |
|
267 (Const("Not",_)$(Const("op <",_) $(Const("0",_)) $(rt as (Const ("op +", _)$(Const ("op *",_) $ c $ y ) $z )))) => |
|
268 if (x = y) |
|
269 then let |
|
270 val m = l div (dest_numeral c) |
|
271 val n = abs (m) |
|
272 val xtm = (HOLogic.mk_binop "op *" ((mk_numeral ((m div n)*l) ), x)) |
|
273 val rs = (HOLogic.mk_binrel "op <" (zero,linear_sub [] (mk_numeral n) (HOLogic.mk_binop "op +" ( xtm ,( linear_cmul n z) )))) |
|
274 in (ACPI(n,fm),rs) |
|
275 end |
|
276 else let val rs = (HOLogic.mk_binrel "op <" (zero,linear_sub [] one rt )) |
|
277 in (ACPI(1,fm),rs) |
|
278 end |
|
279 |
|
280 |(Const(p,_) $d $( Const ("op +", _)$(Const ("op *",_) $ |
|
281 c $ y ) $z )) => if (is_arith_rel fm) andalso (x = y) then |
|
282 let val m = l div (dest_numeral c) |
|
283 val n = (if p = "op <" then abs(m) else m) |
|
284 val xtm = (HOLogic.mk_binop "op *" ((mk_numeral ((m div n)*l) ), x)) |
|
285 val rs = (HOLogic.mk_binrel p ((linear_cmul n d),(HOLogic.mk_binop "op +" ( xtm ,( linear_cmul n z) )))) |
|
286 in (ACAt(n,fm),rs) |
|
287 end |
|
288 else (ACfm(fm),fm) |
|
289 |( Const ("Not", _) $ p) => let val (rsp,rsr) = adjustcoeffeq_wp x l p |
|
290 in (ACNeg(rsp),HOLogic.Not $ rsr) |
|
291 end |
|
292 |( Const ("op &",_) $ p $ q) =>let val (rspp,rspr) = adjustcoeffeq_wp x l p |
|
293 val (rsqp,rsqr) = adjustcoeffeq_wp x l q |
|
294 |
|
295 in (ACConst ("CJ",rspp,rsqp), HOLogic.mk_conj (rspr,rsqr)) |
|
296 end |
|
297 |( Const ("op |",_) $ p $ q) =>let val (rspp,rspr) = adjustcoeffeq_wp x l p |
|
298 val (rsqp,rsqr) = adjustcoeffeq_wp x l q |
|
299 |
|
300 in (ACConst ("DJ",rspp,rsqp), HOLogic.mk_disj (rspr,rsqr)) |
|
301 end |
|
302 |
|
303 |_ => (ACfm(fm),fm); |
|
304 |
|
305 |
|
306 (*_________________________________________*) |
|
307 (*-----------------------------------------*) |
|
308 (* Protocol generation for the liform step *) |
|
309 (*_________________________________________*) |
|
310 (*-----------------------------------------*) |
|
311 |
|
312 |
|
313 fun linform_wp fm = |
|
314 let fun at_linform_wp at = |
|
315 case at of |
|
316 (Const("op <=",_)$s$t) => LfAt(at) |
|
317 |(Const("op <",_)$s$t) => LfAt(at) |
|
318 |(Const("op =",_)$s$t) => LfAt(at) |
|
319 |(Const("Divides.op dvd",_)$s$t) => LfAtdvd(at) |
|
320 in |
|
321 if is_arith_rel fm |
|
322 then at_linform_wp fm |
|
323 else case fm of |
|
324 (Const("Not",_) $ A) => LfNot(linform_wp A) |
|
325 |(Const("op &",_)$ A $ B) => LfConst("CJ",linform_wp A, linform_wp B) |
|
326 |(Const("op |",_)$ A $ B) => LfConst("DJ",linform_wp A, linform_wp B) |
|
327 |(Const("op -->",_)$ A $ B) => LfConst("IM",linform_wp A, linform_wp B) |
|
328 |(Const("op =",Type ("fun",[Type ("bool", []),_]))$ A $ B) => LfConst("EQ",linform_wp A, linform_wp B) |
|
329 |Const("Ex",_)$Abs(x,T,p) => |
|
330 let val (xn,p1) = variant_abs(x,T,p) |
|
331 in LfQ("Ex",xn,T,linform_wp p1) |
|
332 end |
|
333 |Const("All",_)$Abs(x,T,p) => |
|
334 let val (xn,p1) = variant_abs(x,T,p) |
|
335 in LfQ("All",xn,T,linform_wp p1) |
|
336 end |
|
337 end; |
|
338 |
|
339 |
|
340 (* ------------------------------------------------------------------------- *) |
|
341 (*For simlified formulas we just notice the original formula, for whitch we habe been |
|
342 intendes to make the proof.*) |
|
343 (* ------------------------------------------------------------------------- *) |
|
344 fun simpl_wp (fm,pr) = let val fm2 = simpl fm |
|
345 in (fm2,Simp(fm,pr)) |
|
346 end; |
|
347 |
|
348 |
|
349 (* ------------------------------------------------------------------------- *) |
|
350 (*Help function for the generation of the proof EX.P_{minus \infty} --> EX. P(x) *) |
|
351 (* ------------------------------------------------------------------------- *) |
|
352 fun minusinf_wph x fm = let fun mk_atomar_minusinf_proof x fm = (Modd_minf(x,fm),Eq_minf(x,fm)) |
|
353 |
|
354 fun combine_minusinf_proofs opr (ppr1,ppr2) (qpr1,qpr2) = case opr of |
|
355 "CJ" => (Modd_minf_conjI(ppr1,qpr1),Eq_minf_conjI(ppr2,qpr2)) |
|
356 |"DJ" => (Modd_minf_disjI(ppr1,qpr1),Eq_minf_disjI(ppr2,qpr2)) |
|
357 in |
|
358 |
|
359 case fm of |
|
360 (Const ("Not", _) $ (Const("op =",Type ("fun",[Type ("IntDef.int", []),_])) $ c1 $ (Const ("op +", _) $(Const ("op *",_) $ c2 $ y) $z))) => |
|
361 if (x=y) andalso (c1= zero) andalso (c2= one) then (HOLogic.true_const ,(mk_atomar_minusinf_proof x fm)) |
|
362 else (fm ,(mk_atomar_minusinf_proof x fm)) |
|
363 |(Const("op =",Type ("fun",[Type ("IntDef.int", []),_])) $ c1 $(Const ("op +", _) $(Const ("op *",_) $ c2 $ y) $z)) => |
|
364 if (is_arith_rel fm) andalso (x=y) andalso (c1= zero) andalso (c2= one) |
|
365 then (HOLogic.false_const ,(mk_atomar_minusinf_proof x fm)) |
|
366 else (fm,(mk_atomar_minusinf_proof x fm)) |
|
367 |(Const("op <",_) $ c1 $(Const ("op +", _) $(Const ("op *",_) $ c2 $ y ) $ z )) => |
|
368 if (y=x) andalso (c1 = zero) then |
|
369 if c2 = one then (HOLogic.false_const,(mk_atomar_minusinf_proof x fm)) else |
|
370 (HOLogic.true_const,(mk_atomar_minusinf_proof x fm)) |
|
371 else (fm,(mk_atomar_minusinf_proof x fm)) |
|
372 |
|
373 |(Const("Not",_)$(Const ("Divides.op dvd",_) $_ )) => (fm,mk_atomar_minusinf_proof x fm) |
|
374 |
|
375 |(Const ("Divides.op dvd",_) $_ ) => (fm,mk_atomar_minusinf_proof x fm) |
|
376 |
|
377 |(Const ("op &",_) $ p $ q) => let val (pfm,ppr) = minusinf_wph x p |
|
378 val (qfm,qpr) = minusinf_wph x q |
|
379 val pr = (combine_minusinf_proofs "CJ" ppr qpr) |
|
380 in |
|
381 (HOLogic.conj $ pfm $qfm , pr) |
|
382 end |
|
383 |(Const ("op |",_) $ p $ q) => let val (pfm,ppr) = minusinf_wph x p |
|
384 val (qfm,qpr) = minusinf_wph x q |
|
385 val pr = (combine_minusinf_proofs "DJ" ppr qpr) |
|
386 in |
|
387 (HOLogic.disj $ pfm $qfm , pr) |
|
388 end |
|
389 |
|
390 |_ => (fm,(mk_atomar_minusinf_proof x fm)) |
|
391 |
|
392 end; |
|
393 (* ------------------------------------------------------------------------- *) (* Protokol for the Proof of the property of the minusinfinity formula*) |
|
394 (* Just combines the to protokols *) |
|
395 (* ------------------------------------------------------------------------- *) |
|
396 fun minusinf_wp x fm = let val (fm2,pr) = (minusinf_wph x fm) |
|
397 in (fm2,Minusinf(pr)) |
|
398 end; |
|
399 |
|
400 (* ------------------------------------------------------------------------- *) |
|
401 (*Help function for the generation of the proof EX.P_{plus \infty} --> EX. P(x) *) |
|
402 (* ------------------------------------------------------------------------- *) |
|
403 |
|
404 fun plusinf_wph x fm = let fun mk_atomar_plusinf_proof x fm = (Modd_minf(x,fm),Eq_minf(x,fm)) |
|
405 |
|
406 fun combine_plusinf_proofs opr (ppr1,ppr2) (qpr1,qpr2) = case opr of |
|
407 "CJ" => (Modd_minf_conjI(ppr1,qpr1),Eq_minf_conjI(ppr2,qpr2)) |
|
408 |"DJ" => (Modd_minf_disjI(ppr1,qpr1),Eq_minf_disjI(ppr2,qpr2)) |
|
409 in |
|
410 |
|
411 case fm of |
|
412 (Const ("Not", _) $ (Const("op =",Type ("fun",[Type ("IntDef.int", []),_])) $ c1 $ (Const ("op +", _) $(Const ("op *",_) $ c2 $ y) $z))) => |
|
413 if (x=y) andalso (c1= zero) andalso (c2= one) then (HOLogic.true_const ,(mk_atomar_plusinf_proof x fm)) |
|
414 else (fm ,(mk_atomar_plusinf_proof x fm)) |
|
415 |(Const("op =",Type ("fun",[Type ("IntDef.int", []),_])) $ c1 $(Const ("op +", _) $(Const ("op *",_) $ c2 $ y) $z)) => |
|
416 if (is_arith_rel fm) andalso (x=y) andalso (c1= zero) andalso (c2= one) |
|
417 then (HOLogic.false_const ,(mk_atomar_plusinf_proof x fm)) |
|
418 else (fm,(mk_atomar_plusinf_proof x fm)) |
|
419 |(Const("op <",_) $ c1 $(Const ("op +", _) $(Const ("op *",_) $ c2 $ y ) $ z )) => |
|
420 if (y=x) andalso (c1 = zero) then |
|
421 if c2 = one then (HOLogic.true_const,(mk_atomar_plusinf_proof x fm)) else |
|
422 (HOLogic.false_const,(mk_atomar_plusinf_proof x fm)) |
|
423 else (fm,(mk_atomar_plusinf_proof x fm)) |
|
424 |
|
425 |(Const("Not",_)$(Const ("Divides.op dvd",_) $_ )) => (fm,mk_atomar_plusinf_proof x fm) |
|
426 |
|
427 |(Const ("Divides.op dvd",_) $_ ) => (fm,mk_atomar_plusinf_proof x fm) |
|
428 |
|
429 |(Const ("op &",_) $ p $ q) => let val (pfm,ppr) = plusinf_wph x p |
|
430 val (qfm,qpr) = plusinf_wph x q |
|
431 val pr = (combine_plusinf_proofs "CJ" ppr qpr) |
|
432 in |
|
433 (HOLogic.conj $ pfm $qfm , pr) |
|
434 end |
|
435 |(Const ("op |",_) $ p $ q) => let val (pfm,ppr) = plusinf_wph x p |
|
436 val (qfm,qpr) = plusinf_wph x q |
|
437 val pr = (combine_plusinf_proofs "DJ" ppr qpr) |
|
438 in |
|
439 (HOLogic.disj $ pfm $qfm , pr) |
|
440 end |
|
441 |
|
442 |_ => (fm,(mk_atomar_plusinf_proof x fm)) |
|
443 |
|
444 end; |
|
445 (* ------------------------------------------------------------------------- *) (* Protokol for the Proof of the property of the minusinfinity formula*) |
|
446 (* Just combines the to protokols *) |
|
447 (* ------------------------------------------------------------------------- *) |
|
448 fun plusinf_wp x fm = let val (fm2,pr) = (plusinf_wph x fm) |
|
449 in (fm2,Minusinf(pr)) |
|
450 end; |
|
451 |
|
452 |
|
453 (* ------------------------------------------------------------------------- *) |
|
454 (*Protocol that we here uses Bset.*) |
|
455 (* ------------------------------------------------------------------------- *) |
|
456 fun bset_wp x fm = let val bs = bset x fm in |
|
457 (bs,Bset(x,fm,bs,mk_numeral (divlcm x fm))) |
|
458 end; |
|
459 |
|
460 (* ------------------------------------------------------------------------- *) |
|
461 (*Protocol that we here uses Aset.*) |
|
462 (* ------------------------------------------------------------------------- *) |
|
463 fun aset_wp x fm = let val ast = aset x fm in |
|
464 (ast,Aset(x,fm,ast,mk_numeral (divlcm x fm))) |
|
465 end; |
|
466 |
|
467 |
|
468 |
|
469 (* ------------------------------------------------------------------------- *) |
175 (* ------------------------------------------------------------------------- *) |
470 (*function list to Set, constructs a set containing all elements of a given list.*) |
176 (*function list to Set, constructs a set containing all elements of a given list.*) |
471 (* ------------------------------------------------------------------------- *) |
177 (* ------------------------------------------------------------------------- *) |
472 fun list_to_set T1 l = let val T = (HOLogic.mk_setT T1) in |
178 fun list_to_set T1 l = let val T = (HOLogic.mk_setT T1) in |
473 case l of |
179 case l of |
474 [] => Const ("{}",T) |
180 [] => Const ("{}",T) |
475 |(h::t) => Const("insert", T1 --> (T --> T)) $ h $(list_to_set T1 t) |
181 |(h::t) => Const("insert", T1 --> (T --> T)) $ h $(list_to_set T1 t) |
476 end; |
182 end; |
477 |
183 |
478 |
|
479 (*====================================================================*) |
|
480 (* ------------------------------------------------------------------------- *) |
|
481 (* ------------------------------------------------------------------------- *) |
|
482 (*Protocol for the proof of the backward direction of the cooper theorem.*) |
|
483 (* Helpfunction - Protokols evereything about the proof reconstruction*) |
|
484 (* ------------------------------------------------------------------------- *) |
|
485 fun not_bst_p_wph fm = case fm of |
|
486 Const("Not",_) $ R => if (is_arith_rel R) then (Not_bst_p_atomic (fm)) else CpLogError |
|
487 |Const("op &",_) $ ls $ rs => Not_bst_p_conjI((not_bst_p_wph ls),(not_bst_p_wph rs)) |
|
488 |Const("op |",_) $ ls $ rs => Not_bst_p_disjI((not_bst_p_wph ls),(not_bst_p_wph rs)) |
|
489 |_ => Not_bst_p_atomic (fm); |
|
490 (* ------------------------------------------------------------------------- *) |
|
491 (* Main protocoling function for the backward direction gives the Bset and the divlcm and the Formula herself. Needed as inherited attributes for the proof reconstruction*) |
|
492 (* ------------------------------------------------------------------------- *) |
|
493 fun not_bst_p_wp x fm = let val prt = not_bst_p_wph fm |
|
494 val D = mk_numeral (divlcm x fm) |
|
495 val B = map norm_zero_one (bset x fm) |
|
496 in (Not_bst_p (x,fm,D,(list_to_set HOLogic.intT B) , prt)) |
|
497 end; |
|
498 (*====================================================================*) |
|
499 (* ------------------------------------------------------------------------- *) |
|
500 (* ------------------------------------------------------------------------- *) |
|
501 (*Protocol for the proof of the backward direction of the cooper theorem.*) |
|
502 (* Helpfunction - Protokols evereything about the proof reconstruction*) |
|
503 (* ------------------------------------------------------------------------- *) |
|
504 fun not_ast_p_wph fm = case fm of |
|
505 Const("Not",_) $ R => if (is_arith_rel R) then (Not_ast_p_atomic (fm)) else CpLogError |
|
506 |Const("op &",_) $ ls $ rs => Not_ast_p_conjI((not_ast_p_wph ls),(not_ast_p_wph rs)) |
|
507 |Const("op |",_) $ ls $ rs => Not_ast_p_disjI((not_ast_p_wph ls),(not_ast_p_wph rs)) |
|
508 |_ => Not_ast_p_atomic (fm); |
|
509 (* ------------------------------------------------------------------------- *) |
|
510 (* Main protocoling function for the backward direction gives the Bset and the divlcm and the Formula herself. Needed as inherited attributes for the proof reconstruction*) |
|
511 (* ------------------------------------------------------------------------- *) |
|
512 fun not_ast_p_wp x fm = let val prt = not_ast_p_wph fm |
|
513 val D = mk_numeral (divlcm x fm) |
|
514 val B = map norm_zero_one (aset x fm) |
|
515 in (Not_ast_p (x,fm,D,(list_to_set HOLogic.intT B) , prt)) |
|
516 end; |
|
517 |
|
518 (*======================================================*) |
|
519 (* Protokolgeneration for the formula evaluation process*) |
|
520 (*======================================================*) |
|
521 |
|
522 fun evalc_wp fm = |
|
523 let fun evalc_atom_wp at =case at of |
|
524 (Const (p,_) $ s $ t) =>( |
|
525 case assoc (operations,p) of |
|
526 Some f => ((if (f ((dest_numeral s),(dest_numeral t))) then EvalAt(HOLogic.mk_eq(at,HOLogic.true_const)) else EvalAt(HOLogic.mk_eq(at, HOLogic.false_const))) |
|
527 handle _ => Evalfm(at)) |
|
528 | _ => Evalfm(at)) |
|
529 |Const("Not",_)$(Const (p,_) $ s $ t) =>( |
|
530 case assoc (operations,p) of |
|
531 Some f => ((if (f ((dest_numeral s),(dest_numeral t))) then |
|
532 EvalAt(HOLogic.mk_eq(at, HOLogic.false_const)) else EvalAt(HOLogic.mk_eq(at,HOLogic.true_const))) |
|
533 handle _ => Evalfm(at)) |
|
534 | _ => Evalfm(at)) |
|
535 | _ => Evalfm(at) |
|
536 |
|
537 in |
|
538 case fm of |
|
539 (Const("op &",_)$A$B) => EvalConst("CJ",evalc_wp A,evalc_wp B) |
|
540 |(Const("op |",_)$A$B) => EvalConst("DJ",evalc_wp A,evalc_wp B) |
|
541 |(Const("op -->",_)$A$B) => EvalConst("IM",evalc_wp A,evalc_wp B) |
|
542 |(Const("op =", Type ("fun",[Type ("bool", []),_]))$A$B) => EvalConst("EQ",evalc_wp A,evalc_wp B) |
|
543 |_ => evalc_atom_wp fm |
|
544 end; |
|
545 |
|
546 |
|
547 |
|
548 (*======================================================*) |
|
549 (* Protokolgeneration for the NNF Transformation *) |
|
550 (*======================================================*) |
|
551 |
|
552 fun cnnf_wp f = |
|
553 let fun hcnnf_wp fm = |
|
554 case fm of |
|
555 (Const ("op &",_) $ p $ q) => NNFConst("CJ",hcnnf_wp p,hcnnf_wp q) |
|
556 | (Const ("op |",_) $ p $ q) => NNFConst("DJ",hcnnf_wp p,hcnnf_wp q) |
|
557 | (Const ("op -->",_) $ p $q) => NNFConst("IM",hcnnf_wp (HOLogic.Not $ p),hcnnf_wp q) |
|
558 | (Const ("op =",Type ("fun",[Type ("bool", []),_])) $ p $ q) => NNFConst("EQ",hcnnf_wp (HOLogic.mk_conj(p,q)),hcnnf_wp (HOLogic.mk_conj((HOLogic.Not $ p), (HOLogic.Not $ q)))) |
|
559 |
|
560 | (Const ("Not",_) $ (Const("Not",_) $ p)) => NNFNN(hcnnf_wp p) |
|
561 | (Const ("Not",_) $ (Const ("op &",_) $ p $ q)) => NNFConst ("NCJ",(hcnnf_wp(HOLogic.Not $ p)),(hcnnf_wp(HOLogic.Not $ q))) |
|
562 | (Const ("Not",_) $(Const ("op |",_) $ (A as (Const ("op &",_) $ p $ q)) $ |
|
563 (B as (Const ("op &",_) $ p1 $ r)))) => if p1 = negate p then |
|
564 NNFConst("SDJ", |
|
565 NNFConst("CJ",hcnnf_wp p,hcnnf_wp(HOLogic.Not $ q)), |
|
566 NNFConst("CJ",hcnnf_wp p1,hcnnf_wp(HOLogic.Not $ r))) |
|
567 else NNFConst ("NDJ",(hcnnf_wp(HOLogic.Not $ A)),(hcnnf_wp(HOLogic.Not $ B))) |
|
568 |
|
569 | (Const ("Not",_) $ (Const ("op |",_) $ p $ q)) => NNFConst ("NDJ",(hcnnf_wp(HOLogic.Not $ p)),(hcnnf_wp(HOLogic.Not $ q))) |
|
570 | (Const ("Not",_) $ (Const ("op -->",_) $ p $q)) => NNFConst ("NIM",(hcnnf_wp(p)),(hcnnf_wp(HOLogic.Not $ q))) |
|
571 | (Const ("Not",_) $ (Const ("op =",Type ("fun",[Type ("bool", []),_])) $ p $ q)) =>NNFConst ("NEQ",(NNFConst("CJ",hcnnf_wp p,hcnnf_wp(HOLogic.Not $ q))),(NNFConst("CJ",hcnnf_wp(HOLogic.Not $ p),hcnnf_wp q))) |
|
572 | _ => NNFAt(fm) |
|
573 in NNFSimp(hcnnf_wp f) |
|
574 end; |
|
575 |
|
576 |
|
577 |
|
578 |
|
579 |
|
580 |
|
581 (* ------------------------------------------------------------------------- *) |
|
582 (*Cooper decision Procedure with proof protocoling*) |
|
583 (* ------------------------------------------------------------------------- *) |
|
584 |
|
585 fun coopermi_wp vars fm = |
|
586 case fm of |
|
587 Const ("Ex",_) $ Abs(xo,T,po) => let |
|
588 val (xn,np) = variant_abs(xo,T,po) |
|
589 val x = (Free(xn , T)) |
|
590 val p = np (* Is this a legal proof for the P=NP Problem??*) |
|
591 val (p_inf,miprt) = simpl_wp (minusinf_wp x p) |
|
592 val (bset,bsprt) = bset_wp x p |
|
593 val nbst_p_prt = not_bst_p_wp x p |
|
594 val dlcm = divlcm x p |
|
595 val js = 1 upto dlcm |
|
596 fun p_element j b = linrep vars x (linear_add vars b (mk_numeral j)) p |
|
597 fun stage j = list_disj (linrep vars x (mk_numeral j) p_inf :: map (p_element j) bset) |
|
598 in (list_disj (map stage js),Cooper(mk_numeral dlcm,miprt,bsprt,nbst_p_prt)) |
|
599 end |
|
600 |
|
601 | _ => (error "cooper: not an existential formula",No); |
|
602 |
|
603 fun cooperpi_wp vars fm = |
|
604 case fm of |
|
605 Const ("Ex",_) $ Abs(xo,T,po) => let |
|
606 val (xn,np) = variant_abs(xo,T,po) |
|
607 val x = (Free(xn , T)) |
|
608 val p = np (* Is this a legal proof for the P=NP Problem??*) |
|
609 val (p_inf,piprt) = simpl_wp (plusinf_wp x p) |
|
610 val (aset,asprt) = aset_wp x p |
|
611 val nast_p_prt = not_ast_p_wp x p |
|
612 val dlcm = divlcm x p |
|
613 val js = 1 upto dlcm |
|
614 fun p_element j a = linrep vars x (linear_sub vars a (mk_numeral j)) p |
|
615 fun stage j = list_disj (linrep vars x (mk_numeral j) p_inf :: map (p_element j) aset) |
|
616 in (list_disj (map stage js),Cooper(mk_numeral dlcm,piprt,asprt,nast_p_prt)) |
|
617 end |
|
618 | _ => (error "cooper: not an existential formula",No); |
|
619 |
|
620 |
|
621 |
|
622 |
|
623 |
|
624 (*-----------------------------------------------------------------*) |
|
625 (*-----------------------------------------------------------------*) |
|
626 (*-----------------------------------------------------------------*) |
|
627 (*--- ---*) |
|
628 (*--- ---*) |
|
629 (*--- Interpretation and Proofgeneration Part ---*) |
|
630 (*--- ---*) |
|
631 (*--- Protocole interpretation functions ---*) |
|
632 (*--- ---*) |
|
633 (*--- and proofgeneration functions ---*) |
|
634 (*--- ---*) |
|
635 (*--- ---*) |
|
636 (*--- ---*) |
|
637 (*--- ---*) |
|
638 (*-----------------------------------------------------------------*) |
|
639 (*-----------------------------------------------------------------*) |
|
640 (*-----------------------------------------------------------------*) |
|
641 |
|
642 (* ------------------------------------------------------------------------- *) |
184 (* ------------------------------------------------------------------------- *) |
643 (* Returns both sides of an equvalence in the theorem*) |
185 (* Returns both sides of an equvalence in the theorem*) |
644 (* ------------------------------------------------------------------------- *) |
186 (* ------------------------------------------------------------------------- *) |
645 fun qe_get_terms th = let val (_$(Const("op =",Type ("fun",[Type ("bool", []),_])) $ A $ B )) = prop_of th in (A,B) end; |
187 fun qe_get_terms th = let val (_$(Const("op =",Type ("fun",[Type ("bool", []),_])) $ A $ B )) = prop_of th in (A,B) end; |
646 |
|
647 |
|
648 (*-------------------------------------------------------------*) |
|
649 (*-------------------------------------------------------------*) |
|
650 (*-------------------------------------------------------------*) |
|
651 (*-------------------------------------------------------------*) |
|
652 |
188 |
653 (* ------------------------------------------------------------------------- *) |
189 (* ------------------------------------------------------------------------- *) |
654 (* Modified version of the simple version with minimal amount of checking and postprocessing*) |
190 (* Modified version of the simple version with minimal amount of checking and postprocessing*) |
655 (* ------------------------------------------------------------------------- *) |
191 (* ------------------------------------------------------------------------- *) |
656 |
192 |
740 val ct = cert_Trueprop sg fm2 |
282 val ct = cert_Trueprop sg fm2 |
741 in |
283 in |
742 simple_prove_goal_cterm2 ct [simp_tac ss 1, TRY (simple_arith_tac 1)] |
284 simple_prove_goal_cterm2 ct [simp_tac ss 1, TRY (simple_arith_tac 1)] |
743 end; |
285 end; |
744 |
286 |
745 |
287 (*=============================================================*) |
746 |
288 (*-------------------------------------------------------------*) |
747 (* ------------------------------------------------------------------------- *) |
289 (* The new compact model *) |
748 (* This function return an Isabelle proof, of the adjustcoffeq result.*) |
290 (*-------------------------------------------------------------*) |
749 (* The proofs are in Presburger.thy and are generally based on the arithmetic *) |
291 (*=============================================================*) |
750 (* ------------------------------------------------------------------------- *) |
292 |
751 fun proof_of_adjustcoeffeq sg (prt,rs) = case prt of |
293 fun thm_of sg decomp t = |
752 ACfm fm => instantiate' [Some cboolT] |
294 let val (ts,recomb) = decomp t |
753 [Some (cterm_of sg fm)] refl |
295 in recomb (map (thm_of sg decomp) ts) |
754 | ACAt (k,at as (Const(p,_) $a $( Const ("op +", _)$(Const ("op *",_) $ |
296 end; |
755 c $ x ) $t ))) => |
297 |
756 let |
298 (*==================================================*) |
757 val ck = cterm_of sg (mk_numeral k) |
299 (* Compact Version for adjustcoeffeq *) |
758 val cc = cterm_of sg c |
300 (*==================================================*) |
759 val ct = cterm_of sg t |
301 |
760 val cx = cterm_of sg x |
302 fun decomp_adjustcoeffeq sg x l fm = case fm of |
761 val ca = cterm_of sg a |
303 (Const("Not",_)$(Const("op <",_) $(Const("0",_)) $(rt as (Const ("op +", _)$(Const ("op *",_) $ c $ y ) $z )))) => |
762 in case p of |
304 let |
763 "op <" => let val pre = prove_elementar sg "lf" |
305 val m = l div (dest_numeral c) |
764 (HOLogic.mk_binrel "op <" (Const("0",HOLogic.intT),(mk_numeral k))) |
306 val n = if (x = y) then abs (m) else 1 |
765 val th1 = (pre RS (instantiate' [] [Some ck,Some ca,Some cc, Some cx, Some ct] (ac_lt_eq))) |
307 val xtm = (HOLogic.mk_binop "op *" ((mk_numeral ((m div n)*l) ), x)) |
766 in [th1,(prove_elementar sg "lf" (HOLogic.mk_eq (snd (qe_get_terms th1) ,rs)))] MRS trans |
308 val rs = if (x = y) |
767 end |
309 then (HOLogic.mk_binrel "op <" (zero,linear_sub [] (mk_numeral n) (HOLogic.mk_binop "op +" ( xtm ,( linear_cmul n z) )))) |
768 |"op =" =>let val pre = prove_elementar sg "lf" |
310 else HOLogic.mk_binrel "op <" (zero,linear_sub [] one rt ) |
|
311 val ck = cterm_of sg (mk_numeral n) |
|
312 val cc = cterm_of sg c |
|
313 val ct = cterm_of sg z |
|
314 val cx = cterm_of sg y |
|
315 val pre = prove_elementar sg "lf" |
|
316 (HOLogic.mk_binrel "op <" (Const("0",HOLogic.intT),(mk_numeral n))) |
|
317 val th1 = (pre RS (instantiate' [] [Some ck,Some cc, Some cx, Some ct] (ac_pi_eq))) |
|
318 in ([], fn [] => [th1,(prove_elementar sg "sa" (HOLogic.mk_eq (snd (qe_get_terms th1) ,rs)))] MRS trans) |
|
319 end |
|
320 |
|
321 |(Const(p,_) $a $( Const ("op +", _)$(Const ("op *",_) $ |
|
322 c $ y ) $t )) => |
|
323 if (is_arith_rel fm) andalso (x = y) |
|
324 then |
|
325 let val m = l div (dest_numeral c) |
|
326 val k = (if p = "op <" then abs(m) else m) |
|
327 val xtm = (HOLogic.mk_binop "op *" ((mk_numeral ((m div k)*l) ), x)) |
|
328 val rs = (HOLogic.mk_binrel p ((linear_cmul k a),(HOLogic.mk_binop "op +" ( xtm ,( linear_cmul k t) )))) |
|
329 |
|
330 val ck = cterm_of sg (mk_numeral k) |
|
331 val cc = cterm_of sg c |
|
332 val ct = cterm_of sg t |
|
333 val cx = cterm_of sg x |
|
334 val ca = cterm_of sg a |
|
335 |
|
336 in |
|
337 case p of |
|
338 "op <" => |
|
339 let val pre = prove_elementar sg "lf" |
|
340 (HOLogic.mk_binrel "op <" (Const("0",HOLogic.intT),(mk_numeral k))) |
|
341 val th1 = (pre RS (instantiate' [] [Some ck,Some ca,Some cc, Some cx, Some ct] (ac_lt_eq))) |
|
342 in ([], fn [] => [th1,(prove_elementar sg "lf" (HOLogic.mk_eq (snd (qe_get_terms th1) ,rs)))] MRS trans) |
|
343 end |
|
344 |
|
345 |"op =" => |
|
346 let val pre = prove_elementar sg "lf" |
769 (HOLogic.Not $ (HOLogic.mk_binrel "op =" (Const("0",HOLogic.intT),(mk_numeral k)))) |
347 (HOLogic.Not $ (HOLogic.mk_binrel "op =" (Const("0",HOLogic.intT),(mk_numeral k)))) |
770 in let val th1 = (pre RS(instantiate' [] [Some ck,Some ca,Some cc, Some cx, Some ct] (ac_eq_eq))) |
348 val th1 = (pre RS(instantiate' [] [Some ck,Some ca,Some cc, Some cx, Some ct] (ac_eq_eq))) |
771 in [th1,(prove_elementar sg "lf" (HOLogic.mk_eq (snd (qe_get_terms th1) ,rs)))] MRS trans |
349 in ([], fn [] => [th1,(prove_elementar sg "lf" (HOLogic.mk_eq (snd (qe_get_terms th1) ,rs)))] MRS trans) |
772 end |
350 end |
773 end |
351 |
774 |"Divides.op dvd" =>let val pre = prove_elementar sg "lf" |
352 |"Divides.op dvd" => |
|
353 let val pre = prove_elementar sg "lf" |
775 (HOLogic.Not $ (HOLogic.mk_binrel "op =" (Const("0",HOLogic.intT),(mk_numeral k)))) |
354 (HOLogic.Not $ (HOLogic.mk_binrel "op =" (Const("0",HOLogic.intT),(mk_numeral k)))) |
776 val th1 = (pre RS (instantiate' [] [Some ck,Some ca,Some cc, Some cx, Some ct]) (ac_dvd_eq)) |
355 val th1 = (pre RS (instantiate' [] [Some ck,Some ca,Some cc, Some cx, Some ct]) (ac_dvd_eq)) |
777 in [th1,(prove_elementar sg "lf" (HOLogic.mk_eq (snd (qe_get_terms th1) ,rs)))] MRS trans |
356 in ([], fn [] => [th1,(prove_elementar sg "lf" (HOLogic.mk_eq (snd (qe_get_terms th1) ,rs)))] MRS trans) |
778 |
357 |
779 end |
|
780 end |
|
781 |ACPI(k,at as (Const("Not",_)$(Const("op <",_) $a $( Const ("op +", _)$(Const ("op *",_) $ c $ x ) $t )))) => |
|
782 let |
|
783 val ck = cterm_of sg (mk_numeral k) |
|
784 val cc = cterm_of sg c |
|
785 val ct = cterm_of sg t |
|
786 val cx = cterm_of sg x |
|
787 val pre = prove_elementar sg "lf" |
|
788 (HOLogic.mk_binrel "op <" (Const("0",HOLogic.intT),(mk_numeral k))) |
|
789 val th1 = (pre RS (instantiate' [] [Some ck,Some cc, Some cx, Some ct] (ac_pi_eq))) |
|
790 |
|
791 in [th1,(prove_elementar sg "sa" (HOLogic.mk_eq (snd (qe_get_terms th1) ,rs)))] MRS trans |
|
792 end |
|
793 |ACNeg(pr) => let val (Const("Not",_)$nrs) = rs |
|
794 in (proof_of_adjustcoeffeq sg (pr,nrs)) RS (qe_Not) |
|
795 end |
358 end |
796 |ACConst(s,pr1,pr2) => |
359 end |
797 let val (Const(_,_)$rs1$rs2) = rs |
360 else ([], fn [] => instantiate' [Some cboolT] [Some (cterm_of sg fm)] refl) |
798 val th1 = proof_of_adjustcoeffeq sg (pr1,rs1) |
361 |
799 val th2 = proof_of_adjustcoeffeq sg (pr2,rs2) |
362 |( Const ("Not", _) $ p) => ([p], fn [th] => th RS qe_Not) |
800 in case s of |
363 |( Const ("op &",_) $ p $ q) => ([p,q], fn [th1,th2] => [th1,th2] MRS qe_conjI) |
801 "CJ" => [th1,th2] MRS (qe_conjI) |
364 |( Const ("op |",_) $ p $ q) =>([p,q], fn [th1,th2] => [th1,th2] MRS qe_disjI) |
802 |"DJ" => [th1,th2] MRS (qe_disjI) |
365 |
803 |"IM" => [th1,th2] MRS (qe_impI) |
366 |_ => ([], fn [] => instantiate' [Some cboolT] [Some (cterm_of sg fm)] refl); |
804 |"EQ" => [th1,th2] MRS (qe_eqI) |
367 |
805 end; |
368 (*==================================================*) |
806 |
369 (* Finding rho for modd_minusinfinity *) |
807 |
370 (*==================================================*) |
808 |
371 fun rho_for_modd_minf x dlcm sg fm1 = |
809 |
372 let |
810 |
|
811 |
|
812 (* ------------------------------------------------------------------------- *) |
|
813 (* This function return an Isabelle proof, of some properties on the atoms*) |
|
814 (* The proofs are in Presburger.thy and are generally based on the arithmetic *) |
|
815 (* This function doese only instantiate the the theorems in the theory *) |
|
816 (* ------------------------------------------------------------------------- *) |
|
817 fun atomar_minf_proof_of sg dlcm (Modd_minf (x,fm1)) = |
|
818 let |
|
819 (*Some certified Terms*) |
373 (*Some certified Terms*) |
820 |
374 |
821 val ctrue = cterm_of sg HOLogic.true_const |
375 val ctrue = cterm_of sg HOLogic.true_const |
822 val cfalse = cterm_of sg HOLogic.false_const |
376 val cfalse = cterm_of sg HOLogic.false_const |
823 val fm = norm_zero_one fm1 |
377 val fm = norm_zero_one fm1 |
1034 |
546 |
1035 |_ => (instantiate' [Some cboolT] [Some (cterm_of sg fm)] (fm_eq_pinf)) |
547 |_ => (instantiate' [Some cboolT] [Some (cterm_of sg fm)] (fm_eq_pinf)) |
1036 end; |
548 end; |
1037 |
549 |
1038 |
550 |
1039 (* ------------------------------------------------------------------------- *) |
551 |
1040 (* This function combines proofs of some special form already synthetised from the subtrees to make*) |
552 fun minf_proof_of_c sg x dlcm t = |
1041 (* a new proof of the same form. The combination occures whith isabelle theorems which have been already prooved *) |
553 let val minf_eqth = thm_of sg (decomp_minf_eq x dlcm sg) t |
1042 (*these Theorems are in Presburger.thy and mostly do not relay on the arithmetic.*) |
554 val minf_moddth = thm_of sg (decomp_minf_modd x dlcm sg) t |
1043 (* These are Theorems for the Property of P_{+infty}*) |
555 in (minf_eqth, minf_moddth) |
1044 (* ------------------------------------------------------------------------- *) |
|
1045 fun combine_pinf_proof s pr1 pr2 = case s of |
|
1046 "ECJ" => [pr1 , pr2] MRS (eq_pinf_conjI) |
|
1047 |
|
1048 |"EDJ" => [pr1 , pr2] MRS (eq_pinf_disjI) |
|
1049 |
|
1050 |"MCJ" => [pr1 , pr2] MRS (modd_pinf_conjI) |
|
1051 |
|
1052 |"MDJ" => [pr1 , pr2] MRS (modd_pinf_disjI); |
|
1053 |
|
1054 (* ------------------------------------------------------------------------- *) |
|
1055 (*This function return an isabelle Proof for the minusinfinity theorem*) |
|
1056 (* It interpretates the protool and gives the protokoles property of P_{...} as a theorem*) |
|
1057 (* ------------------------------------------------------------------------- *) |
|
1058 fun pinf_proof_ofh sg dlcm prl = case prl of |
|
1059 |
|
1060 Eq_minf (_) => atomar_pinf_proof_of sg dlcm prl |
|
1061 |
|
1062 |Modd_minf (_) => atomar_pinf_proof_of sg dlcm prl |
|
1063 |
|
1064 |Eq_minf_conjI (prl1,prl2) => let val pr1 = pinf_proof_ofh sg dlcm prl1 |
|
1065 val pr2 = pinf_proof_ofh sg dlcm prl2 |
|
1066 in (combine_pinf_proof "ECJ" pr1 pr2) |
|
1067 end |
|
1068 |
|
1069 |Eq_minf_disjI (prl1,prl2) => let val pr1 = pinf_proof_ofh sg dlcm prl1 |
|
1070 val pr2 = pinf_proof_ofh sg dlcm prl2 |
|
1071 in (combine_pinf_proof "EDJ" pr1 pr2) |
|
1072 end |
|
1073 |
|
1074 |Modd_minf_conjI (prl1,prl2) => let val pr1 = pinf_proof_ofh sg dlcm prl1 |
|
1075 val pr2 = pinf_proof_ofh sg dlcm prl2 |
|
1076 in (combine_pinf_proof "MCJ" pr1 pr2) |
|
1077 end |
|
1078 |
|
1079 |Modd_minf_disjI (prl1,prl2) => let val pr1 = pinf_proof_ofh sg dlcm prl1 |
|
1080 val pr2 = pinf_proof_ofh sg dlcm prl2 |
|
1081 in (combine_pinf_proof "MDJ" pr1 pr2) |
|
1082 end; |
|
1083 (* ------------------------------------------------------------------------- *) |
|
1084 (* Main function For the rest both properies of P_{..} are needed and here both theorems are returned.*) |
|
1085 (* ------------------------------------------------------------------------- *) |
|
1086 fun pinf_proof_of sg dlcm (Minusinf (prl1,prl2)) = |
|
1087 let val pr1 = pinf_proof_ofh sg dlcm prl1 |
|
1088 val pr2 = pinf_proof_ofh sg dlcm prl2 |
|
1089 in (pr1, pr2) |
|
1090 end; |
556 end; |
1091 |
557 |
1092 |
558 (*=========== pinf proofs with the compact version==========*) |
1093 |
559 fun decomp_pinf_eq x dlcm sg t = case t of |
1094 (* ------------------------------------------------------------------------- *) |
560 Const ("op &",_) $ p $q => ([p,q],fn [th1,th2] => [th1,th2] MRS eq_pinf_conjI) |
1095 (* Protokol interpretation function for the backwards direction for cooper's Theorem*) |
561 |Const ("op |",_) $ p $q => ([p,q],fn [th1,th2] => [th1,th2] MRS eq_pinf_disjI) |
|
562 |_ =>([],fn [] => rho_for_eq_pinf x dlcm sg t) ; |
|
563 |
|
564 fun decomp_pinf_modd x dlcm sg t = case t of |
|
565 Const ("op &",_) $ p $q => ([p,q],fn [th1,th2] => [th1,th2] MRS modd_pinf_conjI) |
|
566 |Const ("op |",_) $ p $q => ([p,q],fn [th1,th2] => [th1,th2] MRS modd_pinf_disjI) |
|
567 |_ => ([],fn [] => rho_for_modd_pinf x dlcm sg t); |
|
568 |
|
569 fun pinf_proof_of_c sg x dlcm t = |
|
570 let val pinf_eqth = thm_of sg (decomp_pinf_eq x dlcm sg) t |
|
571 val pinf_moddth = thm_of sg (decomp_pinf_modd x dlcm sg) t |
|
572 in (pinf_eqth,pinf_moddth) |
|
573 end; |
|
574 |
|
575 |
|
576 (* ------------------------------------------------------------------------- *) |
|
577 (* Here we generate the theorem for the Bset Property in the simple direction*) |
|
578 (* It is just an instantiation*) |
|
579 (* ------------------------------------------------------------------------- *) |
|
580 (* |
|
581 fun bsetproof_of sg (x as Free(xn,xT)) fm bs dlcm = |
|
582 let |
|
583 val cp = cterm_of sg (absfree (xn,xT,(norm_zero_one fm))) |
|
584 val cdlcm = cterm_of sg dlcm |
|
585 val cB = cterm_of sg (list_to_set HOLogic.intT (map norm_zero_one bs)) |
|
586 in instantiate' [] [Some cdlcm,Some cB, Some cp] (bst_thm) |
|
587 end; |
|
588 |
|
589 fun asetproof_of sg (x as Free(xn,xT)) fm ast dlcm = |
|
590 let |
|
591 val cp = cterm_of sg (absfree (xn,xT,(norm_zero_one fm))) |
|
592 val cdlcm = cterm_of sg dlcm |
|
593 val cA = cterm_of sg (list_to_set HOLogic.intT (map norm_zero_one ast)) |
|
594 in instantiate' [] [Some cdlcm,Some cA, Some cp] (ast_thm) |
|
595 end; |
|
596 *) |
1096 |
597 |
1097 (* For the generation of atomic Theorems*) |
598 (* For the generation of atomic Theorems*) |
1098 (* Prove the premisses on runtime and then make RS*) |
599 (* Prove the premisses on runtime and then make RS*) |
1099 (* ------------------------------------------------------------------------- *) |
600 (* ------------------------------------------------------------------------- *) |
|
601 |
|
602 (*========= this is rho ============*) |
1100 fun generate_atomic_not_bst_p sg (x as Free(xn,xT)) fm dlcm B at = |
603 fun generate_atomic_not_bst_p sg (x as Free(xn,xT)) fm dlcm B at = |
1101 let |
604 let |
1102 val cdlcm = cterm_of sg dlcm |
605 val cdlcm = cterm_of sg dlcm |
1103 val cB = cterm_of sg B |
606 val cB = cterm_of sg B |
1104 val cfma = cterm_of sg (absfree (xn,xT,(norm_zero_one fm))) |
607 val cfma = cterm_of sg (absfree (xn,xT,(norm_zero_one fm))) |
1248 else (instantiate' [] [Some cfma, Some cdlcm, Some cA,Some cat] (not_ast_p_fm)) |
747 else (instantiate' [] [Some cfma, Some cdlcm, Some cA,Some cat] (not_ast_p_fm)) |
1249 |
748 |
1250 |_ => (instantiate' [] [Some cfma, Some cdlcm, Some cA,Some cat] (not_ast_p_fm)) |
749 |_ => (instantiate' [] [Some cfma, Some cdlcm, Some cA,Some cat] (not_ast_p_fm)) |
1251 |
750 |
1252 end; |
751 end; |
1253 |
752 |
1254 (* ------------------------------------------------------------------------- *) |
753 (* ------------------------------------------------------------------------ *) |
1255 (* Main interpretation function for this backwards dirction*) |
754 (* Main interpretation function for this backwards dirction*) |
1256 (* if atomic do generate atomis formulae else Construct theorems and then make RS with the construction theorems*) |
755 (* if atomic do generate atomis formulae else Construct theorems and then make RS with the construction theorems*) |
1257 (*Help Function*) |
756 (*Help Function*) |
1258 (* ------------------------------------------------------------------------- *) |
757 (* ------------------------------------------------------------------------- *) |
1259 fun not_ast_p_proof_of_h sg x fm dlcm A prt = case prt of |
758 |
1260 (Not_ast_p_atomic(fm2)) => (generate_atomic_not_ast_p sg x fm dlcm A fm2) |
759 fun decomp_nastp sg x dlcm A fm t = case t of |
1261 |
760 Const("op &",_) $ ls $ rs => ([ls,rs],fn [th1,th2] => [th1,th2] MRS not_ast_p_conjI ) |
1262 |(Not_ast_p_conjI(pr1,pr2)) => |
761 |Const("op |",_) $ ls $ rs => ([ls,rs],fn [th1,th2] => [th1,th2] MRS not_ast_p_disjI) |
1263 let val th1 = (not_ast_p_proof_of_h sg x fm dlcm A pr1) |
762 |_ => ([], fn [] => generate_atomic_not_ast_p sg x fm dlcm A t); |
1264 val th2 = (not_ast_p_proof_of_h sg x fm dlcm A pr2) |
763 |
1265 in ([th1,th2] MRS (not_ast_p_conjI)) |
764 fun not_ast_p_proof_of_c sg (x as Free(xn,xT)) fm dlcm A t = |
1266 end |
765 let |
1267 |
766 val th = thm_of sg (decomp_nastp sg x dlcm (list_to_set xT (map norm_zero_one A)) fm) t |
1268 |(Not_ast_p_disjI(pr1,pr2)) => |
|
1269 let val th1 = (not_ast_p_proof_of_h sg x fm dlcm A pr1) |
|
1270 val th2 = (not_ast_p_proof_of_h sg x fm dlcm A pr2) |
|
1271 in ([th1,th2] MRS (not_ast_p_disjI)) |
|
1272 end; |
|
1273 (* Main function*) |
|
1274 fun not_ast_p_proof_of sg (Not_ast_p(x as Free(xn,xT),fm,dlcm,A,prl)) = |
|
1275 let val th = not_ast_p_proof_of_h sg x fm dlcm A prl |
|
1276 val fma = absfree (xn,xT, norm_zero_one fm) |
767 val fma = absfree (xn,xT, norm_zero_one fm) |
1277 val th1 = prove_elementar sg "ss" (HOLogic.mk_eq (fma,fma)) |
768 in let val th1 = prove_elementar sg "ss" (HOLogic.mk_eq (fma,fma)) |
1278 in [th,th1] MRS (not_ast_p_Q_elim) |
769 in [th,th1] MRS (not_ast_p_Q_elim) |
|
770 end |
|
771 end; |
|
772 |
|
773 |
|
774 (* -------------------------------*) |
|
775 (* Finding rho and beta for evalc *) |
|
776 (* -------------------------------*) |
|
777 |
|
778 fun rho_for_evalc sg at = case at of |
|
779 (Const (p,_) $ s $ t) =>( |
|
780 case assoc (operations,p) of |
|
781 Some f => |
|
782 ((if (f ((dest_numeral s),(dest_numeral t))) |
|
783 then prove_elementar sg "ss" (HOLogic.mk_eq(at,HOLogic.true_const)) |
|
784 else prove_elementar sg "ss" (HOLogic.mk_eq(at, HOLogic.false_const))) |
|
785 handle _ => instantiate' [Some cboolT] [Some (cterm_of sg at)] refl |
|
786 | _ => instantiate' [Some cboolT] [Some (cterm_of sg at)] refl )) |
|
787 |Const("Not",_)$(Const (p,_) $ s $ t) =>( |
|
788 case assoc (operations,p) of |
|
789 Some f => |
|
790 ((if (f ((dest_numeral s),(dest_numeral t))) |
|
791 then prove_elementar sg "ss" (HOLogic.mk_eq(at, HOLogic.false_const)) |
|
792 else prove_elementar sg "ss" (HOLogic.mk_eq(at,HOLogic.true_const))) |
|
793 handle _ => instantiate' [Some cboolT] [Some (cterm_of sg at)] refl) |
|
794 | _ => instantiate' [Some cboolT] [Some (cterm_of sg at)] refl ) |
|
795 | _ => instantiate' [Some cboolT] [Some (cterm_of sg at)] refl; |
|
796 |
|
797 |
|
798 (*=========================================================*) |
|
799 fun decomp_evalc sg t = case t of |
|
800 (Const("op &",_)$A$B) => ([A,B], fn [th1,th2] => [th1,th2] MRS qe_conjI) |
|
801 |(Const("op |",_)$A$B) => ([A,B], fn [th1,th2] => [th1,th2] MRS qe_disjI) |
|
802 |(Const("op -->",_)$A$B) => ([A,B], fn [th1,th2] => [th1,th2] MRS qe_impI) |
|
803 |(Const("op =", Type ("fun",[Type ("bool", []),_]))$A$B) => ([A,B], fn [th1,th2] => [th1,th2] MRS qe_eqI) |
|
804 |_ => ([], fn [] => rho_for_evalc sg t); |
|
805 |
|
806 |
|
807 fun proof_of_evalc sg fm = thm_of sg (decomp_evalc sg) fm; |
|
808 |
|
809 (*==================================================*) |
|
810 (* Proof of linform with the compact model *) |
|
811 (*==================================================*) |
|
812 |
|
813 |
|
814 fun decomp_linform sg vars t = case t of |
|
815 (Const("op &",_)$A$B) => ([A,B], fn [th1,th2] => [th1,th2] MRS qe_conjI) |
|
816 |(Const("op |",_)$A$B) => ([A,B], fn [th1,th2] => [th1,th2] MRS qe_disjI) |
|
817 |(Const("op -->",_)$A$B) => ([A,B], fn [th1,th2] => [th1,th2] MRS qe_impI) |
|
818 |(Const("op =", Type ("fun",[Type ("bool", []),_]))$A$B) => ([A,B], fn [th1,th2] => [th1,th2] MRS qe_eqI) |
|
819 |(Const("Not",_)$p) => ([p],fn [th] => th RS qe_Not) |
|
820 |(Const("Divides.op dvd",_)$d$r) => ([], fn [] => (prove_elementar sg "lf" (HOLogic.mk_eq (r, lint vars r))) RS (instantiate' [] [None , None, Some (cterm_of sg d)](linearize_dvd))) |
|
821 |_ => ([], fn [] => prove_elementar sg "lf" (HOLogic.mk_eq (t, linform vars t))); |
|
822 |
|
823 fun proof_of_linform sg vars f = thm_of sg (decomp_linform sg vars) f; |
|
824 |
|
825 (* ------------------------------------------------------------------------- *) |
|
826 (* Interpretaion of Protocols of the cooper procedure : minusinfinity version*) |
|
827 (* ------------------------------------------------------------------------- *) |
|
828 fun coopermi_proof_of sg (x as Free(xn,xT)) fm B dlcm = |
|
829 (* Get the Bset thm*) |
|
830 let val (minf_eqth, minf_moddth) = minf_proof_of_c sg x dlcm fm |
|
831 val dpos = prove_elementar sg "ss" (HOLogic.mk_binrel "op <" (zero,dlcm)); |
|
832 val nbstpthm = not_bst_p_proof_of_c sg x fm dlcm B fm |
|
833 in (dpos,minf_eqth,nbstpthm,minf_moddth) |
1279 end; |
834 end; |
1280 |
835 |
1281 |
836 (* ------------------------------------------------------------------------- *) |
1282 |
837 (* Interpretaion of Protocols of the cooper procedure : plusinfinity version *) |
1283 |
838 (* ------------------------------------------------------------------------- *) |
1284 (* ------------------------------------------------------------------------- *) |
839 fun cooperpi_proof_of sg (x as Free(xn,xT)) fm A dlcm = |
1285 (* Interpretaion of Protocols of the cooper procedure : minusinfinity version*) |
840 let val (pinf_eqth,pinf_moddth) = pinf_proof_of_c sg x dlcm fm |
1286 (* ------------------------------------------------------------------------- *) |
|
1287 |
|
1288 |
|
1289 fun coopermi_proof_of sg x (Cooper (dlcm,Simp(fm,miprt),bsprt,nbst_p_prt)) = |
|
1290 (* Get the Bset thm*) |
|
1291 let val (mit1,mit2) = minf_proof_of sg dlcm miprt |
|
1292 val fm1 = norm_zero_one (simpl fm) |
|
1293 val dpos = prove_elementar sg "ss" (HOLogic.mk_binrel "op <" (zero,dlcm)); |
841 val dpos = prove_elementar sg "ss" (HOLogic.mk_binrel "op <" (zero,dlcm)); |
1294 val nbstpthm = not_bst_p_proof_of sg nbst_p_prt |
842 val nastpthm = not_ast_p_proof_of_c sg x fm dlcm A fm |
1295 (* Return the four theorems needed to proove the whole Cooper Theorem*) |
843 in (dpos,pinf_eqth,nastpthm,pinf_moddth) |
1296 in (dpos,mit2,nbstpthm,mit1) |
|
1297 end; |
844 end; |
1298 |
845 |
1299 |
|
1300 (* ------------------------------------------------------------------------- *) |
|
1301 (* Interpretaion of Protocols of the cooper procedure : plusinfinity version *) |
|
1302 (* ------------------------------------------------------------------------- *) |
|
1303 |
|
1304 |
|
1305 fun cooperpi_proof_of sg x (Cooper (dlcm,Simp(fm,miprt),bsprt,nast_p_prt)) = |
|
1306 let val (mit1,mit2) = pinf_proof_of sg dlcm miprt |
|
1307 val fm1 = norm_zero_one (simpl fm) |
|
1308 val dpos = prove_elementar sg "ss" (HOLogic.mk_binrel "op <" (zero,dlcm)); |
|
1309 val nastpthm = not_ast_p_proof_of sg nast_p_prt |
|
1310 in (dpos,mit2,nastpthm,mit1) |
|
1311 end; |
|
1312 |
|
1313 |
|
1314 (* ------------------------------------------------------------------------- *) |
846 (* ------------------------------------------------------------------------- *) |
1315 (* Interpretaion of Protocols of the cooper procedure : full version*) |
847 (* Interpretaion of Protocols of the cooper procedure : full version*) |
1316 (* ------------------------------------------------------------------------- *) |
848 (* ------------------------------------------------------------------------- *) |
1317 |
849 fun cooper_thm sg s (x as Free(xn,xT)) cfm dlcm ast bst= case s of |
1318 |
850 "pi" => let val (dpsthm,pinf_eqth,nbpth,pinf_moddth) = cooperpi_proof_of sg x cfm ast dlcm |
1319 |
851 in [dpsthm,pinf_eqth,nbpth,pinf_moddth] MRS (cppi_eq) |
1320 fun cooper_thm sg s (x as Free(xn,xT)) vars cfm = case s of |
|
1321 "pi" => let val (rs,prt) = cooperpi_wp (xn::vars) (HOLogic.mk_exists(xn,xT,cfm)) |
|
1322 val (dpsthm,th1,nbpth,th3) = cooperpi_proof_of sg x prt |
|
1323 in [dpsthm,th1,nbpth,th3] MRS (cppi_eq) |
|
1324 end |
852 end |
1325 |"mi" => let val (rs,prt) = coopermi_wp (xn::vars) (HOLogic.mk_exists(xn,xT,cfm)) |
853 |"mi" => let val (dpsthm,minf_eqth,nbpth,minf_moddth) = coopermi_proof_of sg x cfm bst dlcm |
1326 val (dpsthm,th1,nbpth,th3) = coopermi_proof_of sg x prt |
854 in [dpsthm,minf_eqth,nbpth,minf_moddth] MRS (cpmi_eq) |
1327 in [dpsthm,th1,nbpth,th3] MRS (cpmi_eq) |
|
1328 end |
855 end |
1329 |_ => error "parameter error"; |
856 |_ => error "parameter error"; |
1330 |
857 |
1331 (* ------------------------------------------------------------------------- *) |
858 (* ------------------------------------------------------------------------- *) |
1332 (* This function should evoluate to the end prove Procedure for one quantifier elimination for Presburger arithmetic*) |
859 (* This function should evoluate to the end prove Procedure for one quantifier elimination for Presburger arithmetic*) |
1333 (* It shoud be plugged in the qfnp argument of the quantifier elimination proof function*) |
860 (* It shoud be plugged in the qfnp argument of the quantifier elimination proof function*) |
1334 (* ------------------------------------------------------------------------- *) |
861 (* ------------------------------------------------------------------------- *) |
1335 |
862 |
1336 fun cooper_prv sg (x as Free(xn,xT)) efm vars = let |
863 fun cooper_prv sg (x as Free(xn,xT)) efm = let |
1337 val l = formlcm x efm |
864 val lfm_thm = proof_of_linform sg [xn] efm |
1338 val ac_thm = proof_of_adjustcoeffeq sg (adjustcoeffeq_wp x l efm) |
865 val efm2 = snd(qe_get_terms lfm_thm) |
|
866 val l = formlcm x efm2 |
|
867 val ac_thm = [lfm_thm , (thm_of sg (decomp_adjustcoeffeq sg x l) efm2)] MRS trans |
1339 val fm = snd (qe_get_terms ac_thm) |
868 val fm = snd (qe_get_terms ac_thm) |
1340 val cfm = unitycoeff x fm |
869 val cfm = unitycoeff x fm |
1341 val afm = adjustcoeff x l fm |
870 val afm = adjustcoeff x l fm |
1342 val P = absfree(xn,xT,afm) |
871 val P = absfree(xn,xT,afm) |
1343 val ss = presburger_ss addsimps |
872 val ss = presburger_ss addsimps |
1344 [simp_from_to] delsimps [P_eqtrue, P_eqfalse, bex_triv, insert_iff] |
873 [simp_from_to] delsimps [P_eqtrue, P_eqfalse, bex_triv, insert_iff] |
1345 val uth = instantiate' [] [Some (cterm_of sg P) , Some (cterm_of sg (mk_numeral l))] (unity_coeff_ex) |
874 val uth = instantiate' [] [Some (cterm_of sg P) , Some (cterm_of sg (mk_numeral l))] (unity_coeff_ex) |
1346 val e_ac_thm = (forall_intr (cterm_of sg x) ac_thm) COMP (qe_exI) |
875 val e_ac_thm = (forall_intr (cterm_of sg x) ac_thm) COMP (qe_exI) |
1347 val cms = if ((length (aset x cfm)) < (length (bset x cfm))) then "pi" else "mi" |
876 val A = aset x cfm |
1348 val cp_thm = cooper_thm sg cms x vars cfm |
877 val B = bset x cfm |
|
878 val dlcm = mk_numeral (divlcm x cfm) |
|
879 val cms = if ((length A) < (length B )) then "pi" else "mi" |
|
880 val cp_thm = cooper_thm sg cms x cfm dlcm A B |
1349 val exp_cp_thm = refl RS (simplify ss (cp_thm RSN (2,trans))) |
881 val exp_cp_thm = refl RS (simplify ss (cp_thm RSN (2,trans))) |
1350 val (lsuth,rsuth) = qe_get_terms (uth) |
882 val (lsuth,rsuth) = qe_get_terms (uth) |
1351 val (lseacth,rseacth) = qe_get_terms(e_ac_thm) |
883 val (lseacth,rseacth) = qe_get_terms(e_ac_thm) |
1352 val (lscth,rscth) = qe_get_terms (exp_cp_thm) |
884 val (lscth,rscth) = qe_get_terms (exp_cp_thm) |
1353 val u_c_thm = [([uth,prove_elementar sg "ss" (HOLogic.mk_eq (rsuth,lscth))] MRS trans),exp_cp_thm] MRS trans |
885 val u_c_thm = [([uth,prove_elementar sg "ss" (HOLogic.mk_eq (rsuth,lscth))] MRS trans),exp_cp_thm] MRS trans |
1354 in ([e_ac_thm,[(prove_elementar sg "ss" (HOLogic.mk_eq (rseacth,lsuth))),u_c_thm] MRS trans] MRS trans) |
886 in ([e_ac_thm,[(prove_elementar sg "ss" (HOLogic.mk_eq (rseacth,lsuth))),u_c_thm] MRS trans] MRS trans) |
1355 end |
887 end |
1356 |cooper_prv _ _ _ _ = error "Parameters format"; |
888 |cooper_prv _ _ _ = error "Parameters format"; |
1357 |
889 |
1358 |
890 |
1359 (*====================================================*) |
891 |
1360 (*Interpretation function for the evaluation protokol *) |
892 fun decomp_cnnf sg lfnp P = case P of |
1361 (*====================================================*) |
893 Const ("op &",_) $ p $q => ([p,q] , fn [th1,th2] => [th1,th2] MRS qe_conjI ) |
1362 |
894 |Const ("op |",_) $ p $q => ([p,q] , fn [th1,th2] => [th1,th2] MRS qe_disjI) |
1363 fun proof_of_evalc sg fm = |
895 |Const ("Not",_) $ (Const("Not",_) $ p) => ([p], fn [th] => th RS nnf_nn) |
1364 let |
896 |Const("Not",_) $ (Const(opn,T) $ p $ q) => |
1365 fun proof_of_evalch prt = case prt of |
897 if opn = "op |" |
1366 EvalAt(at) => prove_elementar sg "ss" at |
898 then case (p,q) of |
1367 |Evalfm(fm) => instantiate' [Some cboolT] [Some (cterm_of sg fm)] refl |
899 (A as (Const ("op &",_) $ r $ s),B as (Const ("op &",_) $ r1 $ t)) => |
1368 |EvalConst(s,pr1,pr2) => |
900 if r1 = negate r |
1369 let val th1 = proof_of_evalch pr1 |
901 then ([r,HOLogic.Not$s,r1,HOLogic.Not$t],fn [th1_1,th1_2,th2_1,th2_2] => [[th1_1,th1_1] MRS qe_conjI,[th2_1,th2_2] MRS qe_conjI] MRS nnf_sdj) |
1370 val th2 = proof_of_evalch pr2 |
902 |
1371 in case s of |
903 else ([HOLogic.Not $ p,HOLogic.Not $ q ], fn [th1,th2] => [th1,th2] MRS nnf_ndj) |
1372 "CJ" =>[th1,th2] MRS (qe_conjI) |
904 |(_,_) => ([HOLogic.Not $ p,HOLogic.Not $ q ], fn [th1,th2] => [th1,th2] MRS nnf_ndj) |
1373 |"DJ" =>[th1,th2] MRS (qe_disjI) |
905 else ( |
1374 |"IM" =>[th1,th2] MRS (qe_impI) |
906 case (opn,T) of |
1375 |"EQ" =>[th1,th2] MRS (qe_eqI) |
907 ("op &",_) => ([HOLogic.Not $ p,HOLogic.Not $ q ], fn [th1,th2] =>[th1,th2] MRS nnf_ncj ) |
1376 end |
908 |("op -->",_) => ([p,HOLogic.Not $ q ], fn [th1,th2] =>[th1,th2] MRS nnf_nim ) |
1377 in proof_of_evalch (evalc_wp fm) |
909 |("op =",Type ("fun",[Type ("bool", []),_])) => |
|
910 ([HOLogic.conj $ p $ (HOLogic.Not $ q),HOLogic.conj $ (HOLogic.Not $ p) $ q], fn [th1,th2] => [th1,th2] MRS nnf_neq) |
|
911 |(_,_) => ([], fn [] => lfnp P) |
|
912 ) |
|
913 |
|
914 |(Const ("op -->",_) $ p $ q) => ([HOLogic.Not$p,q], fn [th1,th2] => [th1,th2] MRS nnf_im) |
|
915 |
|
916 |(Const ("op =", Type ("fun",[Type ("bool", []),_])) $ p $ q) => |
|
917 ([HOLogic.conj $ p $ q,HOLogic.conj $ (HOLogic.Not $ p) $ (HOLogic.Not $ q) ], fn [th1,th2] =>[th1,th2] MRS nnf_eq ) |
|
918 |_ => ([], fn [] => lfnp P); |
|
919 |
|
920 |
|
921 |
|
922 |
|
923 fun proof_of_cnnf sg p lfnp = |
|
924 let val th1 = thm_of sg (decomp_cnnf sg lfnp) p |
|
925 val rs = snd(qe_get_terms th1) |
|
926 val th2 = prove_elementar sg "ss" (HOLogic.mk_eq(rs,simpl rs)) |
|
927 in [th1,th2] MRS trans |
|
928 end; |
|
929 |
1378 end; |
930 end; |
1379 |
|
1380 (*============================================================*) |
|
1381 (*Interpretation function for the NNF-Transformation protokol *) |
|
1382 (*============================================================*) |
|
1383 |
|
1384 fun proof_of_cnnf sg fm pf = |
|
1385 let fun proof_of_cnnfh prt pat = case prt of |
|
1386 NNFAt(at) => pat at |
|
1387 |NNFSimp (pr) => let val th1 = proof_of_cnnfh pr pat |
|
1388 in let val fm2 = snd (qe_get_terms th1) |
|
1389 in [th1,prove_elementar sg "ss" (HOLogic.mk_eq(fm2 ,simpl fm2))] MRS trans |
|
1390 end |
|
1391 end |
|
1392 |NNFNN (pr) => (proof_of_cnnfh pr pat) RS (nnf_nn) |
|
1393 |NNFConst (s,pr1,pr2) => |
|
1394 let val th1 = proof_of_cnnfh pr1 pat |
|
1395 val th2 = proof_of_cnnfh pr2 pat |
|
1396 in case s of |
|
1397 "CJ" => [th1,th2] MRS (qe_conjI) |
|
1398 |"DJ" => [th1,th2] MRS (qe_disjI) |
|
1399 |"IM" => [th1,th2] MRS (nnf_im) |
|
1400 |"EQ" => [th1,th2] MRS (nnf_eq) |
|
1401 |"SDJ" => let val (Const("op &",_)$A$_) = fst (qe_get_terms th1) |
|
1402 val (Const("op &",_)$C$_) = fst (qe_get_terms th2) |
|
1403 in [th1,th2,prove_elementar sg "ss" (HOLogic.mk_eq (A,HOLogic.Not $ C))] MRS (nnf_sdj) |
|
1404 end |
|
1405 |"NCJ" => [th1,th2] MRS (nnf_ncj) |
|
1406 |"NIM" => [th1,th2] MRS (nnf_nim) |
|
1407 |"NEQ" => [th1,th2] MRS (nnf_neq) |
|
1408 |"NDJ" => [th1,th2] MRS (nnf_ndj) |
|
1409 end |
|
1410 in proof_of_cnnfh (cnnf_wp fm) pf |
|
1411 end; |
|
1412 |
|
1413 |
|
1414 |
|
1415 |
|
1416 (*====================================================*) |
|
1417 (* Interpretation function for the linform protokol *) |
|
1418 (*====================================================*) |
|
1419 |
|
1420 |
|
1421 fun proof_of_linform sg vars f = |
|
1422 let fun proof_of_linformh prt = |
|
1423 case prt of |
|
1424 (LfAt (at)) => prove_elementar sg "lf" (HOLogic.mk_eq (at, linform vars at)) |
|
1425 |(LfAtdvd (Const("Divides.op dvd",_)$d$t)) => (prove_elementar sg "lf" (HOLogic.mk_eq (t, lint vars t))) RS (instantiate' [] [None , None, Some (cterm_of sg d)](linearize_dvd)) |
|
1426 |(Lffm (fm)) => (instantiate' [Some cboolT] [Some (cterm_of sg fm)] refl) |
|
1427 |(LfConst (s,pr1,pr2)) => |
|
1428 let val th1 = proof_of_linformh pr1 |
|
1429 val th2 = proof_of_linformh pr2 |
|
1430 in case s of |
|
1431 "CJ" => [th1,th2] MRS (qe_conjI) |
|
1432 |"DJ" =>[th1,th2] MRS (qe_disjI) |
|
1433 |"IM" =>[th1,th2] MRS (qe_impI) |
|
1434 |"EQ" =>[th1,th2] MRS (qe_eqI) |
|
1435 end |
|
1436 |(LfNot(pr)) => |
|
1437 let val th = proof_of_linformh pr |
|
1438 in (th RS (qe_Not)) |
|
1439 end |
|
1440 |(LfQ(s,xn,xT,pr)) => |
|
1441 let val th = forall_intr (cterm_of sg (Free(xn,xT)))(proof_of_linformh pr) |
|
1442 in if s = "Ex" |
|
1443 then (th COMP(qe_exI) ) |
|
1444 else (th COMP(qe_ALLI) ) |
|
1445 end |
|
1446 in |
|
1447 proof_of_linformh (linform_wp f) |
|
1448 end; |
|
1449 |
|
1450 end; |
|