Skip to content

Commit 970afec

Browse files
authored
Fix float ops 8.15 (#769)
* Support for printing floating point primitive values (#767) * Fix defs in PCUICPrimitive
1 parent adc60da commit 970afec

File tree

6 files changed

+50
-23
lines changed

6 files changed

+50
-23
lines changed

pcuic/theories/PCUICCanonicity.v

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,8 @@ End Spines.
562562

563563
Tactic Notation "redt" uconstr(y) := eapply (CRelationClasses.transitivity (R:=red _ _) (y:=y)).
564564

565+
Require Import Equations.Type.Relation_Properties.
566+
565567
Section WeakNormalization.
566568
Context {cf:checker_flags} {Σ : global_env_ext}.
567569
Context {wfΣ : wf Σ}.
@@ -772,8 +774,6 @@ Section WeakNormalization.
772774
False.
773775
Proof. eauto using wh_neutral_empty_gen. Qed.
774776

775-
Require Import Equations.Type.Relation_Properties.
776-
777777
(* TODO move *)
778778
Lemma invert_red_axiom {Γ cst u cdecl T} :
779779
declared_constant Σ cst cdecl ->

pcuic/theories/utils/PCUICPrimitive.v

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ Proof.
5353
now destruct (uip p q).
5454
Qed.
5555

56-
#[global]
57-
Instance reflect_eq_Z : ReflectEq Z := EqDec_ReflectEq _.
58-
5956
Local Obligation Tactic := idtac.
6057
#[program]
6158
#[global]
@@ -84,25 +81,43 @@ Next Obligation.
8481
intros neq; constructor => H'; apply neq; now subst x.
8582
Qed. *)
8683

87-
(** Propositional UIP is needed below *)
88-
Set Equations With UIP.
89-
90-
#[global]
91-
Instance prim_model_eqdec {term} (*e : EqDec term*) : forall p : prim_tag, EqDec (prim_model term p).
92-
Proof. eqdec_proof. Qed.
84+
Equations eqb_prim_model {term} {t : prim_tag} (x y : prim_model term t) : bool :=
85+
| primIntModel x, primIntModel y := ReflectEq.eqb x y
86+
| primFloatModel x, primFloatModel y := ReflectEq.eqb x y.
87+
88+
#[global, program]
89+
Instance prim_model_reflecteq {term} {p : prim_tag} : ReflectEq (prim_model term p) :=
90+
{| ReflectEq.eqb := eqb_prim_model |}.
91+
Next Obligation.
92+
intros. depelim x; depelim y; simp eqb_prim_model.
93+
case: ReflectEq.eqb_spec; constructor; subst; auto. congruence.
94+
case: ReflectEq.eqb_spec; constructor; subst; auto. congruence.
95+
Qed.
9396

9497
#[global]
95-
Instance prim_tag_model_eqdec term : EqDec (prim_val term).
96-
Proof. eqdec_proof. Defined.
98+
Instance prim_model_eqdec {term} : forall p : prim_tag, EqDec (prim_model term p) := _.
99+
100+
Equations eqb_prim_val {term} (x y : prim_val term) : bool :=
101+
| (primInt; i), (primInt; i') := ReflectEq.eqb i i'
102+
| (primFloat; f), (primFloat; f') := ReflectEq.eqb f f'
103+
| x, y := false.
104+
105+
#[global, program]
106+
Instance prim_val_reflect_eq {term} : ReflectEq (prim_val term) :=
107+
{| ReflectEq.eqb := eqb_prim_val |}.
108+
Next Obligation.
109+
intros. funelim (eqb_prim_val x y); simp eqb_prim_val.
110+
case: ReflectEq.eqb_spec; constructor; subst; auto. intros H; noconf H. cbn in n. auto.
111+
constructor. intros H; noconf H; auto.
112+
constructor. intros H; noconf H; auto.
113+
case: ReflectEq.eqb_spec; constructor; subst; auto. intros H; noconf H; auto.
114+
Qed.
97115

98116
#[global]
99-
Instance prim_val_reflect_eq term : ReflectEq (prim_val term) := EqDec_ReflectEq _.
117+
Instance prim_tag_model_eqdec term : EqDec (prim_val term) := _.
100118

101119
(** Printing *)
102120

103-
Definition string_of_float64_model (f : float64_model) :=
104-
"<>".
105-
106121
Definition string_of_prim {term} (soft : term -> string) (p : prim_val term) : string :=
107122
match p.π2 return string with
108123
| primIntModel f => "(int: " ^ string_of_prim_int f ^ ")"

template-coq/_PluginProject

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,10 @@ gen-src/mCReflect.mli
120120
gen-src/mCReflect.ml
121121
gen-src/primFloat.mli
122122
gen-src/primFloat.ml
123-
#gen-src/decimalString.mli
124-
#gen-src/decimalString.ml
123+
gen-src/decimalString.mli
124+
gen-src/decimalString.ml
125+
gen-src/hexadecimalString.mli
126+
gen-src/hexadecimalString.ml
125127
gen-src/mCString.ml
126128
gen-src/mCString.mli
127129
gen-src/mCUtils.ml

template-coq/gen-src/metacoq_template_plugin.mlpack

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ Signature
7777
All_Forall
7878
Config0
7979
Kernames
80+
DecimalString
81+
HexadecimalString
8082
Primitive
8183
BasicAst
8284
Universes0

template-coq/theories/EnvironmentTyping.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1149,7 +1149,7 @@ Module GlobalMaps (T: Term) (E: EnvironmentSig T) (TU : TermUtils T E) (ET: EnvT
11491149
Definition fresh_global (s : kername) (g : global_declarations) : Prop :=
11501150
Forall (fun g => g.1 <> s) g.
11511151

1152-
Record on_global_decls_data {cf:checker_flags} (univs : ContextSet.t) retro (Σ : global_declarations) (kn : kername) (d : global_decl) :=
1152+
Record on_global_decls_data (univs : ContextSet.t) retro (Σ : global_declarations) (kn : kername) (d : global_decl) :=
11531153
{
11541154
kn_fresh : fresh_global kn Σ ;
11551155
udecl := universes_decl_of_decl d ;

template-coq/theories/Primitive.v

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(* Primitive types *)
22

3-
From Coq Require Import Uint63 PrimFloat.
3+
From Coq Require Import Uint63 PrimFloat SpecFloat FloatOps ZArith Numbers.HexadecimalString.
44
From MetaCoq.Template Require Import bytestring MCString.
55
Local Open Scope bs.
66

@@ -14,5 +14,13 @@ Definition string_of_prim_int (i:Uint63.int) : string :=
1414
(* Better? DecimalString.NilZero.string_of_uint (BinNat.N.to_uint (BinInt.Z.to_N (Int63.to_Z i))). ? *)
1515
string_of_Z (Uint63.to_Z i).
1616

17-
Definition string_of_float (f : PrimFloat.float) :=
18-
"<float>".
17+
Definition string_of_float (f : PrimFloat.float) : string :=
18+
match Prim2SF f with
19+
| S754_zero sign => if sign then "-0" else "0"
20+
| S754_infinity sign => if sign then "-INFINITY" else "INFINITY"
21+
| S754_nan => "NAN"
22+
| S754_finite sign p z =>
23+
let abs := "0x" ++ bytestring.String.of_string (Numbers.HexadecimalString.NilZero.string_of_uint (Pos.to_hex_uint p)) ++ "p" ++
24+
bytestring.String.of_string (Numbers.DecimalString.NilZero.string_of_int (Z.to_int z))
25+
in if sign then "-" ++ abs else abs
26+
end.

0 commit comments

Comments
 (0)