text
stringlengths
1
2.1M
//----------------------------------------------------------------------------- // Pretend to be an ISO 14443 tag. We will do this by alternately short- // circuiting and open-circuiting the antenna coil, with the tri-state // pins. // // We communicate over the SSP, as a bitstream (i.e., might as well be // unframed, though we still generate the word sync signal). The output // (ARM -> FPGA) tells us whether to modulate or not. The input (FPGA // -> ARM) is us using the A/D as a fancy comparator; this is with // (software-added) hysteresis, to undo the high-pass filter. // // At this point only Type A is implemented. This means that we are using a // bit rate of 106 kbit/s, or fc/128. Oversample by 4, which ought to make // things practical for the ARM (fc/32, 423.8 kbits/s, ~50 kbytes/s) // // Jonathan Westhues, October 2006 //----------------------------------------------------------------------------- module hi_simulate( pck0, ck_1356meg, ck_1356megb, pwr_lo, pwr_hi, pwr_oe1, pwr_oe2, pwr_oe3, pwr_oe4, adc_d, adc_clk, ssp_frame, ssp_din, ssp_dout, ssp_clk, cross_hi, cross_lo, dbg, mod_type ); input pck0, ck_1356meg, ck_1356megb; output pwr_lo, pwr_hi, pwr_oe1, pwr_oe2, pwr_oe3, pwr_oe4; input [7:0] adc_d; output adc_clk; input ssp_dout; output ssp_frame, ssp_din, ssp_clk; input cross_hi, cross_lo; output dbg; input [2:0] mod_type; // Power amp goes between LOW and tri-state, so pwr_hi (and pwr_lo) can // always be low. assign pwr_hi = 1'b0; assign pwr_lo = 1'b0; // The comparator with hysteresis on the output from the peak detector. reg after_hysteresis; assign adc_clk = ck_1356meg; always @(negedge adc_clk) begin if(& adc_d[7:5]) after_hysteresis = 1'b1; else if(~(| adc_d[7:5])) after_hysteresis = 1'b0; end // Divide 13.56 MHz by 32 to produce the SSP_CLK // The register is bigger to allow higher division factors of up to /128 reg [10:0] ssp_clk_divider; always @(posedge adc_clk) ssp_clk_divider <= (ssp_clk_divider + 1); reg ssp_clk; reg ssp_frame; always @(negedge adc_clk) begin //If we're in 101, we only need a new bit every 8th carrier bit (53Hz). Otherwise, get next bit at 424Khz if(mod_type == 3'b101) begin \tif(ssp_clk_divider[7:0] == 8'b00000000) \t ssp_clk <= 1'b0; \tif(ssp_clk_divider[7:0] == 8'b10000000) \t ssp_clk <= 1'b1; end else begin \tif(ssp_clk_divider[4:0] == 5'd0)//[4:0] == 5'b00000) \t ssp_clk <= 1'b1; \tif(ssp_clk_divider[4:0] == 5'd16) //[4:0] == 5'b10000) \t ssp_clk <= 1'b0; end end //assign ssp_clk = ssp_clk_divider[4]; // Divide SSP_CLK by 8 to produce the byte framing signal; the phase of // this is arbitrary, because it's just a bitstream. // One nasty issue, though: I can't make it work with both rx and tx at // once. The phase wrt ssp_clk must be changed. TODO to find out why // that is and make a better fix. reg [2:0] ssp_frame_divider_to_arm; always @(posedge ssp_clk) ssp_frame_divider_to_arm <= (ssp_frame_divider_to_arm + 1); reg [2:0] ssp_frame_divider_from_arm; always @(negedge ssp_clk) ssp_frame_divider_from_arm <= (ssp_frame_divider_from_arm + 1); always @(ssp_frame_divider_to_arm or ssp_frame_divider_from_arm or mod_type) if(mod_type == 3'b000) // not modulating, so listening, to ARM ssp_frame = (ssp_frame_divider_to_arm == 3'b000); else \tssp_frame = (ssp_frame_divider_from_arm == 3'b000); // Synchronize up the after-hysteresis signal, to produce DIN. reg ssp_din; always @(posedge ssp_clk) ssp_din = after_hysteresis; // Modulating carrier frequency is fc/16, reuse ssp_clk divider for that reg modulating_carrier; always @(mod_type or ssp_clk or ssp_dout) if(mod_type == 3'b000) modulating_carrier <= 1'b0; // no modulation else if(mod_type == 3'b001) modulating_carrier <= ssp_dout ^ ssp_clk_divider[3]; // XOR means BPSK else if(mod_type == 3'b010) \tmodulating_carrier <= ssp_dout & ssp_clk_divider[5]; // switch 212kHz subcarrier on/off else if(mod_type == 3'b100 || mod_type == 3'b101) \tmodulating_carrier <= ssp_dout & ssp_clk_divider[4]; // switch 424kHz modulation on/off else modulating_carrier <= 1'b0; // yet unused // This one is all LF, so doesn't matter assign pwr_oe2 = modulating_carrier; // Toggle only one of these, since we are already producing much deeper // modulation than a real tag would. assign pwr_oe1 = modulating_carrier; assign pwr_oe4 = modulating_carrier; // This one is always on, so that we can watch the carrier. assign pwr_oe3 = 1'b0; assign dbg = modulating_carrier; //reg dbg; //always @(ssp_dout) // dbg <= ssp_dout; endmodule
(* To test PP of fixpoints *) Require Import Arith. Check fix a(n: nat): n<5 -> nat := match n return n<5 -> nat with | 0 => fun _ => 0 | S n => fun h => S (a n (lt_S_n _ _ (lt_S _ _ h))) end.
(*subtyping verification in presence of pseudo-circularity at functor application *) Module Type S. End S. Module Type T. Declare Module M:S. End T. Module N:S. End N. Module F (X:S) (Y:T with Module M:=X). End F. Module G := F N N.
(* Simple let-in's *) Definition l1 := let P := 0 in P. Definition l2 := let P := nat in P. Definition l3 := let P := True in P. Definition l4 := let P := Prop in P. Definition l5 := let P := Type in P. (* Check casting of let-in *) Definition l6 := let P := 0:nat in P. Definition l7 := let P := True:Prop in P. Definition l8 := let P := True:Type in P.
Module A. Section\tB. End A. End A.
(* lazy delta unfolding used to miss delta on rels and vars (fixed in 10172) *) Check let g := fun _ => 0 in fix f (n : nat) := match n with | 0 => g f | S n' => 0 end.
(* Last line should not loop, even in the presence of eta-expansion in the *) (* printing mechanism *) (* Expected time < 1.00s *) Notation "\'bind\' x <- y ; z" :=(y (fun x => z)) (at level 99, x at level 0, y at level 0,format "\'[hv\' \'bind\' x <- y ; \'/\' z \']\'"). Definition f (g : (nat -> nat) -> nat) := g (fun x => 0). Time Check (fun g => f g).
Definition Berry (x y z : bool) := match x, y, z with | true, false, _ => 0 | false, _, true => 1 | _, true, false => 2 end.
(* Check that no toplevel "unresolved evar" flees through Declare Implicit Tactic support (bug #1229) *) Goal True. (* should raise an error, not an anomaly *) set (x := _).
(* Check that types are not uselessly unfolded *) (* Check here that P returns something of type "option L" and not "option (list nat)" *) Definition L := list nat. Definition P (e:option L) := match e with | None => None | Some cl => Some cl end. Print P.
Set Printing Existential Instances. Set Printing All. Goal let y:=0 in exists x:y=y, x = x. intros. eexists. rename y into z. unfold z at 1 2. (* should fail because the evar type depends on z *) clear z.
(* subtyping verification in presence of pseudo-circularity*) Module Type S. End S. Module Type T. Declare Module M:S. End T. Module N:S. End N. Module NN <: T. Module M:=N. End NN. Module P <: T with Module M:=NN := NN.
(* Test printing of Tactic Notation *) Tactic Notation "a" constr(x) := apply x. Tactic Notation "e" constr(x) := exact x. Ltac f H := split; [a H|e H]. Print Ltac f. (* Test printing of match context *) (* Used to fail after translator removal (see bug #1070) *) Ltac g := match goal with |- context [if ?X then _ else _ ] => case X end. Print Ltac g.
(* It is forbidden to erase a variable (or a local def) that is used in the current goal. *) Section S. Let a := 0. Definition b := a. Goal b = b. clear a.
Module Type TA. Parameter t : Set. End TA. Module Type TB. Declare Module A: TA. End TB. Module Type TC. Declare Module B : TB. End TC. Module Type TD. Declare Module B: TB . Declare Module C: TC with Module B := B . End TD. Module Type TE. Declare Module D : TD. End TE. Module Type TF. Declare Module E: TE. End TF. Module G (D: TD). Module B' := D.C.B. End G. Module H (F: TF). Module I := G(F.E.D). End H. Declare Module F: TF. Module K := H(F).
Definition a := 1.
Require all_stdlib. Print Sorted Universes "universes.txt".
(* Test visibility of imported objects *) Require Import make_local. (* Check local implicit arguments are not imported *) Check (f nat 0). (* Check local arguments scopes are not imported *) Check (f nat (0*0)).
(* Soumis par Pierre *) Print sig2. Check (exists x : nat, x = x). Check (fun b : bool => if b then b else b).
Type (fun x : nat => match x return nat with | S x as b => S b x end).
Require Import BigQ. Open Scope int31_scope. Check I31. (* Would be nice to have I31 : digits->digits->...->int31 For the moment, I31 : digits31 int31, which is better \t than (fix nfun .....) size int31 *) Check 2. Check 1000000000000000000. (* = 660865024, after modulo 2^31 *) Check (add31 2 2). Check (2+2). Eval vm_compute in 2+2. Eval vm_compute in 65675757 * 565675998. Close Scope int31_scope. Open Scope bigN_scope. Check 2. Check 1000000000000000000. Check (BigN.add 2 2). Check (2+2). Eval vm_compute in 2+2. Eval vm_compute in 65675757 * 565675998. Eval vm_compute in 2^100. Close Scope bigN_scope. Open Scope bigZ_scope. Check 2. Check -1000000000000000000. Check (BigZ.add 2 2). Check (2+2). Eval vm_compute in 2+2. Eval vm_compute in 65675757 * 565675998. Eval vm_compute in (-2)^100. Close Scope bigZ_scope. Open Scope bigQ_scope. Check 2. Check -1000000000000000000. Check (BigQ.add 2 2). Check (2+2). Eval vm_compute in 2+2. Eval vm_compute in 65675757 * 565675998. (* fractions *) Check (6562 # 456). (* Nota: # is BigQ.Qq i.e. base fractions *) Eval vm_compute in (BigQ.red (6562 # 456)). Eval vm_compute in (1/-10000). Eval vm_compute in (BigQ.red (1/(1/100))). (* back to integers... *) Eval vm_compute in ((2/3)^(-100)). Eval vm_compute in BigQ.red ((2/3)^(-1000) * (2/3)^(1000)). Close Scope bigQ_scope.
Require Export plik. Definition tutu (X : Set) := toto X.
(* The synthesis of the elimination predicate may fail if algebric *) (* universes are not cautiously treated *) Check (fun b : bool => if b then Type else nat). (* Check correct use of if-then-else predicate annotation (cf bug 690) *) Check fun b : bool => if b as b0 return (if b0 then b0 = true else b0 = false) then refl_equal true else refl_equal false.
(* Check that Match arguments are forbidden *) Ltac E x := apply x. Goal True -> True. E ltac:(match goal with | |- _ => intro H end).
(* A few tests to check Global Argument Scope command *) Section A. Variable a : bool -> bool. Definition negb' := negb. Section B. Variable b : bool -> bool. Definition negb'' := negb. About a. About b. About negb''. About negb'. About negb. Global Arguments Scope negb'' [ _ ]. Global Arguments Scope negb' [ _ ]. Global Arguments Scope negb [ _ ]. Global Arguments Scope a [ _ ]. Global Arguments Scope b [ _ ]. About a. About b. About negb. About negb'. About negb''. End B. About a. End A. About negb. About negb'. About negb''.
(* This example checks the efficiency of pattern-matching compilation on simple cases *) (* Expected time < 1.00s *) Time Definition a400 n := match n with S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S x))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) => x | _ => 0 end.
Definition id (T:Type) := Eval vm_compute in T.
(* Bug #1172 *) Structure foo : Type := Foo { A : Set; Aopt := option A; unopt : Aopt -> A }. Canonical Structure unopt_nat := @Foo nat (fun _ => O). (* Granted wish #1187 *) Record Silly (X : Set) : Set := mkSilly { x : X }. Definition anotherMk := mkSilly. Definition struct := anotherMk nat 3. Canonical Structure struct. (* Intertwinning canonical structures and delta-expansion *) (* Assia\'s short example *) Open Scope bool_scope. Set Implicit Arguments. Structure test_struct : Type := mk_test {dom :> Type; f : dom -> dom -> bool}. Notation " x != y":= (f _ x y)(at level 10). Canonical Structure bool_test := mk_test (fun x y => x || y). Definition b := bool. Check (fun x : b => x != x).
(* Bug in the computation of generalization *) (* The following bug, elaborated by Bruno Barras, is solved from r11083 *) Parameter P : unit -> Prop. Definition T := sig P. Parameter Q : T -> Prop. Definition U := sig Q. Parameter a : U. Check (match a with exist (exist tt e2) e3 => e3=e3 end). (* There is still a form submitted by Pierre Corbineau (#1834) which fails *)
(* Check all variables are different in a Context *) Ltac X := match goal with | x:_,x:_ |- _ => apply x end. Goal True -> True -> True. intros. X.
(* Check that the syntax for options works *) Set Implicit Arguments. Unset Strict Implicit. Set Strict Implicit. Unset Implicit Arguments. Test Implicit Arguments. Set Printing Coercions. Unset Printing Coercions. Test Printing Coercions. Set Silent. Unset Silent. Test Silent. Set Printing Depth 100. Test Printing Depth. Parameter i : bool -> nat. Coercion i : bool >-> nat. Add Printing Coercion i. Remove Printing Coercion i. Test Printing Coercion for i. Test Printing Let. Test Printing If. Remove Printing Let sig. Remove Printing If bool. Unset Printing Synth. Set Printing Synth. Test Printing Synth. Unset Printing Wildcard. Set Printing Wildcard. Test Printing Wildcard.
Module Type S. Parameter empty: Set. End S. Module D (M:S). Import M. Definition empty:=nat. End D. Module D' (M:S). Import M. Definition empty:Set. exact nat. Save. End D'.
Type match 0 with | x => 0 | O => 1 end.
Module Type TA. Parameter t : Set. End TA. Module Type TB. Declare Module A: TA. End TB. Module Type TC. Declare Module B : TB. End TC. Module Type TD. Declare Module B: TB . Declare Module C: TC with Module B := B . End TD. Module Type TE. Declare Module D : TD. End TE. Module Type TF. Declare Module E: TE. End TF. Module G (D: TD). Module B' := D.C.B. End G. Module H (F: TF). Module I := G(F.E.D). End H. Declare Module F: TF. Module K := H(F).
Require Import List. Program Fixpoint f a : { x : nat | x > 0 } := match a with | 0 => 1 | S a' => g a a' end with g a b : { x : nat | x > 0 } := match b with | 0 => 1 | S b' => f b' end. Check f. Check g.
(* L'algo d'inf\xe9rence du pr\xe9dicat doit g\xe9rer le K-r\xe9dex dans le type de b *) (* Probl\xe8me rapport\xe9 par Solange Coupet *) Section A. Variables (Alpha : Set) (Beta : Set). Definition nodep_prod_of_dep (c : sigS (fun a : Alpha => Beta)) : Alpha * Beta := match c with | existS a b => (a, b) end. End A.
(* Syntax test - all possible kinds of module parameters *) Module Type SIG. End SIG. Module Type FSIG (X: SIG). End FSIG. Module F (X: SIG). End F. Module Q. End Q. (* #trace Nametab.push;; #trace Nametab.push_short_name;; #trace Nametab.freeze;; #trace Nametab.unfreeze;; #trace Nametab.exists_cci;; *) Module M01. End M01. Module M02 (X: SIG). End M02. Module M03 (X Y: SIG). End M03. Module M04 (X: SIG) (Y: SIG). End M04. Module M05 (X Y: SIG) (Z1 Z: SIG). End M05. Module M06 (X: SIG) (Y: SIG). End M06. Module M07 (X Y: SIG) (Z1 Z: SIG). End M07. Module M08 : SIG. End M08. Module M09 (X: SIG) : SIG. End M09. Module M10 (X Y: SIG) : SIG. End M10. Module M11 (X: SIG) (Y: SIG) : SIG. End M11. Module M12 (X Y: SIG) (Z1 Z: SIG) : SIG. End M12. Module M13 (X: SIG) (Y: SIG) : SIG. End M13. Module M14 (X Y: SIG) (Z1 Z: SIG) : SIG. End M14. Module M15 := F Q. Module M16 (X: FSIG) := X Q. Module M17 (X Y: FSIG) := X Q. Module M18 (X: FSIG) (Y: SIG) := X Y. Module M19 (X Y: FSIG) (Z1 Z: SIG) := X Z. Module M20 (X: FSIG) (Y: SIG) := X Y. Module M21 (X Y: FSIG) (Z1 Z: SIG) := X Z. Module M22 : SIG := F Q. Module M23 (X: FSIG) : SIG := X Q. Module M24 (X Y: FSIG) : SIG := X Q. Module M25 (X: FSIG) (Y: SIG) : SIG := X Y. Module M26 (X Y: FSIG) (Z1 Z: SIG) : SIG := X Z. Module M27 (X: FSIG) (Y: SIG) : SIG := X Y. Module M28 (X Y: FSIG) (Z1 Z: SIG) : SIG := X Z.
(* Error message was not printed in the correct environment *) Fail Parameters (A:Prop) (a:A A). (* This is a variant (reported as part of bug #2347) *) Require Import EquivDec. Fail Program Instance bool_eq_eqdec : EqDec bool eq := {equiv_dec x y := (fix aux (x y : bool) {struct x}:= aux _ y) x y}.
Type (fun x : nat => match x return nat with | S x as b => match x with | x => S b x end end).
Module Type S. End S. Module Type T. Declare Module M:S. End T. Module N:S. End N. Module NN:T. Module M:=N. End NN. Module Type U := T with Module M:=NN.
Structure S : Type := {Dom : Type; Op : Dom -> Dom -> Dom}. Check (fun s : S => Dom s). Check (fun s : S => Op s). Check (fun (s : S) (a b : Dom s) => Op s a b). (* v8 Check fun s:S => s.(Dom). Check fun s:S => s.(Op). Check fun (s:S) (a b:s.(Dom)) => s.(Op) a b. *) Set Implicit Arguments. Unset Strict Implicit. Unset Strict Implicit. Structure S' (A : Set) : Type := {Dom' : Type; Op' : A -> Dom' -> Dom'}. Check (fun s : S' nat => Dom' s). Check (fun s : S' nat => Op' (s:=s)). Check (fun s : S' nat => Op' (A:=nat) (s:=s)). Check (fun (s : S' nat) (a : nat) (b : Dom' s) => Op' a b). Check (fun (s : S' nat) (a : nat) (b : Dom' s) => Op' (A:=nat) (s:=s) a b). (* v8 Check fun s:S' => s.(Dom'). Check fun s:S' => s.(Op'). Check fun (s:S') (a b:s.(Dom')) => _.(Op') a b. Check fun (s:S') (a b:s.(Dom')) => s.(Op') a b. Set Implicit Arguments. Unset Strict Implicits. Structure S' (A:Set) : Type := {Dom' : Type; Op' : A -> Dom' -> Dom'}. Check fun s:S' nat => s.(Dom'). Check fun s:S' nat => s.(Op'). Check fun (s:S' nat) (a:nat) (b:s.(Dom')) => _.(@Op' nat) a b. Check fun (s:S' nat) (a:nat) (b:s.(Dom')) => s.(Op') a b. *)
(* test the strength of pretyping unification *) Require Import List. Definition listn A n := {l : list A | length l = n}. Definition make_ln A n (l : list A) (h : (fun l => length l = n) l) := exist _ l h.
(* Compatibility of Require with backtracking at interactive module end *) Module A. Require List. End A.
(* Non exhaustive pattern-matching *) Check (fun x => match x, x with | O, S (S y) => true | O, S x => false | S y, O => true end).
(* Check that constraints on definitions are preserved by discharging *) Section A. Definition Type2 := Type. Definition Type1 : Type2 := Type. End A. Definition Inconsistency : Type1 := Type2.
Set Implicit Arguments. Unset Strict Implicit. Module M. Definition a (s : Set) := s. Print a. End M. Print M.a. Module K. Definition app (A B : Set) (f : A -> B) (x : A) := f x. Module N. Definition apap (A B : Set) := app (app (A:=A) (B:=B)). Print app. Print apap. End N. Print N.apap. End K. Print K.app. Print K.N.apap. Module W := K.N. Print W.apap.
Generalizable All Variables. Check `(a = 0). Check `(a = 0)%type. Definition relation A := A -> A -> Prop. Definition equivalence `(R : relation A) := True. Check (`(@equivalence A R)). Definition a_eq_b : `( a = 0 /\\ a = b /\\ b > c \\/ d = e /\\ d = 1). Admitted. Print a_eq_b.
(* Test of inference of elimination predicate for "if" *) (* submitted by Robert R Schneck *) Axiom bad : false = true. Definition try1 : False := match bad in (_ = b) return (if b then False else True) with | refl_equal => I end. Definition try2 : False := match bad in (_ = b) return ((if b then False else True):Prop) with | refl_equal => I end. Definition try3 : False := match bad in (_ = b) return ((fun b\' : bool => if b\' then False else True) b) with | refl_equal => I end.
(* Some tests of the Search command *) Search le.\t\t\t\t(* app nodes *) Search bool. \t\t\t\t(* no apps *) Search (@eq nat).\t\t\t(* complex pattern *)
Definition Type2 := Type. Definition Type1 : Type2 := Type. Definition Inconsistency : Type1 := Type2.
(* Non exhaustive pattern-matching *) Check (fun x => match x, x with | O, S (S y) => true | O, S x => false | S y, O => true end).
(* Test error messages *) (* Test non-regression of bug fixed in r13486 (bad printer for module names) *) Module Type S. Parameter t:Type. End S. Module M : S. Fail End M.
Type (fun x : nat => match x return nat with | S x as b => S b end).
(* Examples to check that the guard condition does not evaluate irrelevant subterms *) (* Expected time < 1.00s *) Require Import Bool. Fixpoint slow n := match n with | 0 => true | S k => andb (slow k) (slow k) end. Timeout 5 Time Fixpoint F n := match n with | 0 => 0 | S k => if slow 100 then F k else 0 end. Fixpoint slow2 n := match n with | 0 => 0 | S k => slow2 k + slow2 k end. Timeout 5 Time Fixpoint F' n := match n with | 0 => 0 | S k => if slow2 100 then F' k else 0 end.
Module Q. Module N. Module K. Definition foo := Set. End K. End N. End Q. (* Bad *) Locate foo. (* Bad *) Locate K.foo. (* Bad *) Locate N.K.foo. (* OK *) Locate Q.N.K.foo. (* OK *) Locate Top.Q.N.K.foo. (* Bad *) Locate Module K. (* Bad *) Locate Module N.K. (* OK *) Locate Module Q.N.K. (* OK *) Locate Module Top.Q.N.K. (* Bad *) Locate Module N. (* OK *) Locate Module Q.N. (* OK *) Locate Module Top.Q.N. (* OK *) Locate Module Q. (* OK *) Locate Module Top.Q. Import Q.N. (* Bad *) Locate foo. (* OK *) Locate K.foo. (* Bad *) Locate N.K.foo. (* OK *) Locate Q.N.K.foo. (* OK *) Locate Top.Q.N.K.foo. (* OK *) Locate Module K. (* Bad *) Locate Module N.K. (* OK *) Locate Module Q.N.K. (* OK *) Locate Module Top.Q.N.K. (* Bad *) Locate Module N. (* OK *) Locate Module Q.N. (* OK *) Locate Module Top.Q.N. (* OK *) Locate Module Q. (* OK *) Locate Module Top.Q.
(* Specific tests about guard condition *) (* f must unfold to x, not F (de Bruijn mix-up!) *) Check let x (f:nat->nat) k := f k in fun (y z:nat->nat) => let f:=x in (* f := Rel 3 *) fix F (n:nat) : nat := match n with | 0 => 0 | S k => f F k (* here Rel 3 = F ! *) end.
(* Simple let-patterns *) Variable A B : Type. Definition l1 (t : A * B * B) : A := let \'(x, y, z) := t in x. Print l1. Definition l2 (t : (A * B) * B) : A := let \'((x, y), z) := t in x. Definition l3 (t : A * (B * B)) : A := let \'(x, (y, z)) := t in x. Print l3. Record someT (A : Type) := mkT { a : nat; b: A }. Definition l4 A (t : someT A) : nat := let \'mkT x y := t in x. Print l4. Print sigT. Definition l5 A (B : A -> Type) (t : sigT B) : B (projT1 t) := let \'existT x y := t return B (projT1 t) in y. Definition l6 A (B : A -> Type) (t : sigT B) : B (projT1 t) := let \'existT x y as t\' := t return B (projT1 t\') in y. Definition l7 A (B : A -> Type) (t : sigT B) : B (projT1 t) := let \'existT x y as t\' in sigT _ := t return B (projT1 t\') in y. Definition l8 A (B : A -> Type) (t : sigT B) : B (projT1 t) := match t with existT x y => y end. (** An example from algebra, using let\' and inference of return clauses to deconstruct contexts. *) Record a_category (A : Type) (hom : A -> A -> Type) := { }. Definition category := { A : Type & { hom : A -> A -> Type & a_category A hom } }. Record a_functor (A : Type) (hom : A -> A -> Type) (C : a_category A hom) := { }. Notation " x :& y " := (@existT _ _ x y) (right associativity, at level 55) : core_scope. Definition functor (c d : category) := let \' A :& homA :& CA := c in let \' B :& homB :& CB := d in A -> B. Definition identity_functor (c : category) : functor c c := let \'A :& homA :& CA := c in fun x => x. Definition functor_composition (a b c : category) : functor a b -> functor b c -> functor a c := let \'A :& homA :& CA := a in let \'B :& homB :& CB := b in let \'C :& homB :& CB := c in fun f g => fun x => g (f x).
(* Used in Notation.v to test import of notations from files in sections *) Notation "\'Z\'" := O (at level 9). Notation plus := plus. Notation succ := S. Notation mult := mult (only parsing). Notation less := le (only parsing). (* Test bug 2168: ending section of some name was removing objects of the same name *) Notation add2 n:=(S n). Section add2. End add2.
Class Zero (A : Type) := zero : A. Notation "0" := zero. Class One (A : Type) := one : A. Notation "1" := one. Class Addition (A : Type) := addition : A -> A -> A. Notation "_+_" := addition. Notation "x + y" := (addition x y). Class Multiplication {A B : Type} := multiplication : A -> B -> B. Notation "_*_" := multiplication. Notation "x * y" := (multiplication x y). Class Subtraction (A : Type) := subtraction : A -> A -> A. Notation "_-_" := subtraction. Notation "x - y" := (subtraction x y). Class Opposite (A : Type) := opposite : A -> A. Notation "-_" := opposite. Notation "- x" := (opposite(x)). Class Equality {A : Type}:= equality : A -> A -> Prop. Notation "_==_" := equality. Notation "x == y" := (equality x y) (at level 70, no associativity). Class Bracket (A B: Type):= bracket : A -> B. Notation "[ x ]" := (bracket(x)). Class Power {A B: Type} := power : A -> B -> A. Notation "x ^ y" := (power x y).
(* ============================================== *) (* To test compilation of dependent case *) (* Nested patterns *) (* ============================================== *) Type match 0 as n return (n = n) with | O => refl_equal 0 | m => refl_equal m end.
Implicit Arguments eq [A]. Check (bool = true).
(* Check if omission of "as" in return clause works w/ section variables too *) Section sec. Variable b: bool. Definition d\' := (match b return b = true \\/ b = false with | true => or_introl _ (refl_equal true) | false => or_intror _ (refl_equal false) end).
Module Type SET. Axiom T : Set. Axiom x : T. End SET. Set Implicit Arguments. Unset Strict Implicit. Module M (X: SET). Definition T := nat. Definition x := 0. Definition f (A : Set) (x : A) := X.x. End M. Module N := M. Module Nat. Definition T := nat. Definition x := 0. End Nat. Module Z := N Nat. Check (Z.f 0). Module P (Y: SET) := N. Module Y := P Z Nat. Check (Y.f 0).
Goal 0 = 1. match goal with | |- context [?v] => idtac v ; fail | _ => idtac 2 end.
Module Type SIG. Axiom A : Set. Axiom B : Set. End SIG. Module M : SIG. Definition A := nat. Definition B := nat. End M. Module N <: SIG := M. Module TranspId (X: SIG) <: SIG with Definition A := X.A := X. Module OpaqueId (X: SIG) : SIG with Definition A := X.A := X. Module TrM := TranspId M. Module OpM := OpaqueId M. Print TrM.A. Print OpM.A. Print TrM.B. Print OpM.B.
Module Type T. Module Type U. Module Type V. Variable b : nat. End V. Variable a : nat. End U. Declare Module u : U. Declare Module v : u.V. End T. Module F (t:T). End F. Module M:T. Module Type U. Module Type V. Variable b : nat. End V. Variable a : nat. End U. Declare Module u : U. Declare Module v : u.V. End M. Module FM := F M.
(* Some tests of the SearchRewrite command *) SearchRewrite (_+0). \t\t\t(* left *) SearchRewrite (0+_). \t\t\t(* right *)
(* Check that "apply eq_refl" is not exported as an interactive tactic but as a statically globalized one *) (* (this is a simplification of the original bug report) *) Module A. Hint Rewrite eq_sym using apply eq_refl : foo. End A.
(* Check for redundant clauses *) Check (fun x => match x, x with | O, S (S y) => true | S _, S (S y) => true | _, S (S x) => false | S y, O => true | _, _ => true end).
Module M. Module Type SIG. Parameter T : Set. Parameter x : T. End SIG. Module N : SIG. Definition T := nat. Definition x := 0. End N. End M. Module N := M. Module Type SPRYT. Module N. Definition T := M.N.T. Parameter x : T. End N. End SPRYT. Module K : SPRYT := N. Module K' : SPRYT := M. Module Type SIG. Definition T : Set := M.N.T. Parameter x : T. End SIG. Module J : SIG := M.N.
Type (fun x : nat => match x return nat with | S x as b => match x with | x => x end end).
(* Check that reset remains synchronised with the compilation unit cache *) (* See bug #1030 *) Section multiset_defs. Require Import Plus. End multiset_defs. Unset Implicit Arguments. Back 1.
(* This failed in 8.3pl2 *) Scheme Induction for eq Sort Prop. Check eq_ind_dep.
(* Test the behaviour of hnf and simpl introduced in revision *) Variable n:nat. Definition a:=0. Eval simpl in (fix plus (n m : nat) {struct n} : nat := match n with | 0 => m | S p => S (p + m) end) a a. Eval hnf in match (plus (S n) O) with S n => n | _ => O end.
(* Declare Module in Module Type *) Module Type A. Record t : Set := { something : unit }. End A. Module Type B. Declare Module BA : A. End B. Module Type C. Declare Module CA : A. Declare Module CB : B with Module BA := CA. End C. Module Type D. Declare Module DA : A. (* Next line gives: "Anomaly: uncaught exception Not_found. Please report." *) Declare Module DC : C with Module CA := DA. End D.
(* ClearBody must check that removing the body of definition does not invalidate the well-typabilility of the visible goal *) Goal True. set (n := 0) in *. set (I := refl_equal 0) in *. change (n = 0) in (type of I). clearbody n.
Module M. Definition t := nat. Definition x := 0. End M. Print M.t. Module Type SIG. Parameter t : Set. Parameter x : t. End SIG. Module F (X: SIG). Definition t := X.t -> X.t. Definition x : t. intro. exact X.x. Defined. Definition y := X.x. End F. Module N := F M. Print N.t. Eval compute in N.t. Module N' : SIG := N. Print N'.t. Eval compute in N'.t. Module N'' <: SIG := F N. Print N''.t. Eval compute in N''.t. Eval compute in N''.x. Module N''' : SIG with Definition t := nat -> nat := N. Print N'''.t. Eval compute in N'''.t. Print N'''.x. Import N'''. Print t.
Require Export Reals. Parameter toto : nat -> nat -> nat. Notation " e # f " := (toto e f) (at level 30, f at level 0).
Require Import FSetList. Require Import OrderedTypeEx. Module NatSet := FSetList.Make (Nat_as_OT). Recursive Extraction NatSet.fold. Module FSetHide (X : FSetInterface.S). Include X. End FSetHide. Module NatSet\' := FSetHide NatSet. Recursive Extraction NatSet\'.fold. (* Extraction "test2141.ml" NatSet\'.fold. *)
Print Tables. Print ML Path. Print ML Modules. Print LoadPath. Print Graph. Print Coercions. Print Classes. Print nat. Print Term O. Print All. Print Grammar constr. Inspect 10. Section A. Coercion f (x : nat) : Prop := True. Print Coercion Paths nat Sortclass. Print Section A.
Require Reals. Print Sorted Universes.
Module Type T. Parameter Inline t : Type. End T. Module M. Definition t := nat. End M. Module Make (X:T). Include X. (* here t is : (Top.Make.t,Top.X.t) *) (* in libobject HEAD : EvalConstRef (Top.X.t,Top.X.t) which is substituted by : {Top.X |-> Top.Make [, Top.Make.t=>Top.X.t]} which gives : EvalConstRef (Top.Make.t,Top.X.t) *) End Make. Module P := Make M. (* resolver returned by add_module : Top.P.t=>inline *) (* then constant_of_delta_kn P.t produces (Top.P.t,Top.P.t) *) (* in libobject HEAD : EvalConstRef (Top.Make.t,Top.X.t) given to subst = {<X#1> |-> Top.M [, Top.M.t=>inline]} which used to give : EvalConstRef (Top.Make.t,Top.M.t) given to subst = {Top.Make |-> Top.P [, Top.P.t=>inline]} which used to give : EvalConstRef (Top.P.t,Top.M.t) *) Definition u := P.t. (* was raising Not_found since Heads.head_map knows of (Top.P.t,Top.M.t) and not of (Top.P.t,Top.P.t) *)
(* Check correct handling of unsupported notations *) Notation "\'\xc2\x92\'" := (fun x => x) (at level 20). Definition crash_the_rooster f := \xc2\x92.
(* Check that non logical object loading is done after registration of the logical objects in the environment *) (* Bug #1118 (simplified version), submitted by Evelyne Contejean (used to failed in pre-V8.1 trunk because of a call to lookup_mind for structure objects) *) Module Type S. Record t : Set := { a : nat; b : nat }. End S. Module Make (X:S). Module Y:=X. End Make.
Record test := build { field : nat }. Record test_r := build_r { field_r : nat }. Record test_c := build_c { field_c : nat }. Add Printing Constructor test_c. Add Printing Record test_r. Set Printing Records. Check build 5. Check {| field := 5 |}. Check build_r 5. Check build_c 5. Unset Printing Records. Check build 5. Check {| field := 5 |}. Check build_r 5. Check build_c 5.
(* This example checks if printing nested let-in's stays in linear time *) (* Expected time < 1.00s *) Definition f (x : nat * nat) := let (a,b) := x in let (a,b) := x in let (a,b) := x in let (a,b) := x in let (a,b) := x in let (a,b) := x in let (a,b) := x in let (a,b) := x in let (a,b) := x in let (a,b) := x in let (a,b) := x in let (a,b) := x in let (a,b) := x in let (a,b) := x in let (a,b) := x in let (a,b) := x in let (a,b) := x in let (a,b) := x in let (a,b) := x in let (a,b) := x in let (a,b) := x in let (a,b) := x in 0. Timeout 5 Time Print f.
Section A. Notation "*" := O (at level 8). Notation "**" := O (at level 99). Notation "***" := O (at level 9). End A. Notation "*" := O (at level 8). Notation "**" := O (at level 99). Notation "***" := O (at level 9).
Check (nat + nat + {True}). Check ({True} + {True} + {True}). Check (nat + {True} + {True}).
(************************************************************************* PROJET RNRT Calife - 2001 Author: Pierre Cr\xc3\xa9gut - France T\xc3\xa9l\xc3\xa9com R&D Licence : LGPL version 2.1 *************************************************************************) Require Import ReflOmegaCore. Require Export Setoid. Require Export PreOmega. Require Export ZArith_base. Require Import OmegaPlugin. Declare ML Module "romega_plugin".
Definition T := Type. Definition U := Type. Module Type MT. Parameter t : T. End MT. Module Type MU. Parameter t : U. End MU. Module F (E : MT). Definition elt :T := E.t. End F. Module G (E : MU). Include F E. Print Universes. (* U <= T *) End G. Print Universes. (* Check if constraint is lost *) Module Mt. Definition t := T. End Mt. Module P := G Mt. (* should yield Universe inconsistency *) (* ... otherwise the following command will show that T has type T! *) Eval cbv delta [P.elt Mt.t] in P.elt.
(* Used in Import.v to test the locality flag *) Definition f (A:Type) (a:A) := a. Local Arguments Scope f [type_scope type_scope]. Local Implicit Arguments f [A]. (* Used in ImportedCoercion.v to test the locality flag *) Local Coercion g (b:bool) := if b then 0 else 1.
Module N. Definition f := plus. (* <Warning> : Syntax is discontinued *) Check (f 0 0). End N. Check (N.f 0 0). Import N. Check (f 0 0). Check (f 0 0). Module M := N. Check (f 0 0). Check (f 0 0). Import M. Check (f 0 0). Check (N.f 0 0).
Require Import ZArith. Check 32%Z. Check (fun f : nat -> Z => (f 0%nat + 0)%Z). Check (fun x : positive => Zpos (xO x)). Check (fun x : positive => (Zpos x + 1)%Z). Check (fun x : positive => Zpos x). Check (fun x : positive => Zneg (xO x)). Check (fun x : positive => (Zpos (xO x) + 0)%Z). Check (fun x : positive => (- Zpos (xO x))%Z). Check (fun x : positive => (- Zpos (xO x) + 0)%Z). Check (Z.of_nat 0 + 1)%Z. Check (0 + Z.of_nat (0 + 0))%Z. Check (Z.of_nat 0 = 0%Z). (* Submitted by Pierre Casteran *) Require Import Arith. Check (0 + Z.of_nat 11)%Z.
Require Import Reals. Check 32%R. Check (-31)%R.
Module M. Definition T := nat. Definition x : T := 0. End M. Module Type SIG. Module M := Top.M. Module Type SIG. Parameter T : Set. End SIG. Declare Module N: SIG. End SIG. Module Z. Module M := Top.M. Module Type SIG. Parameter T : Set. End SIG. Module N := M. End Z. Module A : SIG := Z.
Definition a := 0.
(**********************************************************************) (* Test dependencies in constructors *) (**********************************************************************) Check (fun x : {b : bool | if b then True else False} => match x return (let (b, _) := x in if b then True else False) with | exist true y => y | exist false z => z end).
(* Check exportation of Argument Scopes even without import of modules *) Require Import ZArith. Module A. Definition opp := Z.opp. End A. Check (A.opp 3).
Definition toto (x : Set) := x. (* <Warning> : Grammar is replaced by Notation *)