Skip to content

Commit f921948

Browse files
authored
Update examples (#218)
2 parents 474a058 + 9711e96 commit f921948

File tree

12 files changed

+130
-107
lines changed

12 files changed

+130
-107
lines changed

.github/workflows/docker-action.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,21 @@ jobs:
2929
with:
3030
opam_file: 'coq-corn.opam'
3131
custom_image: ${{ matrix.image }}
32+
after_script: |
33+
startGroup "Workaround permission issue"
34+
sudo chown -R 1000:1000 .
35+
endGroup
36+
startGroup "Test examples"
37+
if $(coqc -print-version|grep -q "^9\.")
38+
then
39+
cd examples
40+
sh build-examples.sh
41+
fi
42+
endGroup
43+
- name: Revert permissions
44+
# to avoid a warning at cleanup time
45+
if: ${{ always() }}
46+
run: sudo chown -R 1001:116 .
3247

3348

3449
# See also:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Makefile.coq.conf
99
*.vos
1010
*.d
1111
*.glob
12+
*.ppm
1213
*.pyc
1314
tree.dot
1415
tree.ps

_CoqProject

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
-R . CoRN
2+
-Q examples examples

examples/Calculemus2011.v

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,59 @@
1-
Require Import CRtrans Compress.
2-
Require Import ARtrans ARbigD.
1+
From CoRN Require Import CRtrans Compress ARtrans ARbigD.
32

43
Definition eval (n:positive) (r : CR) : Q :=
5-
let m := iter_pos n _ (Pmult 10) 1%positive in approximate r (1#m)%Qpos.
4+
let m := Pos.iter (Pmult 10) 1%positive n in approximate r (1#m :> Qpos).
65

76
Definition deval (n:positive) (r : ARbigD) : bigD :=
8-
let m := iter_pos n _ (Pmult 10) 1%positive in approximate r (1#m)%Qpos.
7+
let m := Pos.iter (Pmult 10) 1%positive n in approximate r (1#m :> Qpos).
98

10-
Let ARtest1 : ARbigD := ARpi.
11-
Let CRtest1 : CR := CRpi.
9+
Definition ARtest1 : ARbigD := ARpi.
10+
Definition CRtest1 : CR := CRpi.
1211

13-
Let ARtest2 : ARbigD := ARexp (ARcompress (ARexp (ARcompress (AQexp (1 ≪ (-1)))))).
14-
Let CRtest2 : CR := exp (compress (exp (compress (rational_exp (1#2))))).
12+
Definition ARtest2 : ARbigD := ARexp (ARcompress (ARexp (ARcompress (AQexp (1 ≪ (-1)))))).
13+
Definition CRtest2 : CR := exp (compress (exp (compress (rational_exp (1#2))))).
1514

16-
Let ARtest3 : ARbigD := ARexp (ARcompress ARpi) - ARpi.
17-
Let CRtest3 : CR := exp (compress CRpi) - CRpi.
15+
Definition ARtest3 : ARbigD := ARexp (ARcompress ARpi) - ARpi.
16+
Definition CRtest3 : CR := exp (compress CRpi) - CRpi.
1817

19-
Let ARtest4 : ARbigD := ARarctan (ARcompress ARpi).
20-
Let CRtest4 : CR := arctan (compress CRpi).
18+
Definition ARtest4 : ARbigD := ARarctan (ARcompress ARpi).
19+
Definition CRtest4 : CR := arctan (compress CRpi).
2120

22-
Let ARtest5 : ARbigD := ARcos ('(10^50)%Z).
23-
Let CRtest5 : CR := cos ('inject_Z (10^50)%Z).
21+
Definition ARtest5 : ARbigD := ARcos ('(10^50)%Z).
22+
Definition CRtest5 : CR := cos ('inject_Z (10^50)%Z).
2423

25-
Let ARtest6 : ARbigD := ARsin (ARcompress (ARsin (ARcompress (AQsin 1)))).
26-
Let CRtest6 : CR := sin (compress (sin (compress (rational_sin (1#1))))).
24+
Definition ARtest6 : ARbigD := ARsin (ARcompress (ARsin (ARcompress (AQsin 1)))).
25+
Definition CRtest6 : CR := sin (compress (sin (compress (rational_sin (1#1))))).
2726

2827
Time Eval vm_compute in (deval 300 ARtest1).
29-
Time Eval vm_compute in (eval 300 CRtest1).
30-
Time Eval vm_compute in (deval 2100 ARtest1).
28+
Time Eval vm_compute in (eval 30 CRtest1).
29+
Time Eval vm_compute in (deval 400 ARtest1).
3130

3231
Time Eval vm_compute in (deval 25 ARtest2).
33-
Time Eval vm_compute in (eval 25 CRtest2).
34-
Time Eval vm_compute in (deval 425 ARtest2).
32+
Time Eval vm_compute in (eval 7 CRtest2).
33+
Time Eval vm_compute in (deval 150 ARtest2).
3534

3635
Time Eval vm_compute in (deval 25 ARtest3).
37-
Time Eval vm_compute in (eval 25 CRtest3).
38-
Time Eval vm_compute in (deval 425 ARtest3).
36+
Time Eval vm_compute in (eval 10 CRtest3).
37+
Time Eval vm_compute in (deval 200 ARtest3).
3938

4039
Time Eval vm_compute in (deval 25 ARtest4).
41-
Time Eval vm_compute in (eval 25 CRtest4).
40+
Time Eval vm_compute in (eval 5 CRtest4).
4241
Time Eval vm_compute in (deval 85 ARtest4).
4342

4443
Time Eval vm_compute in (deval 40 ARtest5).
45-
Time Eval vm_compute in (eval 40 CRtest5).
46-
Time Eval vm_compute in (deval 3000 ARtest5).
44+
Time Eval vm_compute in (eval 10 CRtest5).
45+
Time Eval vm_compute in (deval 200 ARtest5).
4746

4847
Time Eval vm_compute in (deval 25 ARtest6).
49-
Time Eval vm_compute in (eval 25 CRtest6).
50-
Time Eval vm_compute in (deval 425 ARtest6).
48+
Time Eval vm_compute in (eval 10 CRtest6).
49+
Time Eval vm_compute in (deval 150 ARtest6).
5150

5251
(* Finally, we compare our sqrt with an implementation not using type classes *)
53-
Require Import ARroot dyadics.
52+
From CoRN Require Import ARroot.
53+
From MathClasses Require Import dyadics.
5454

55-
Let n := Eval compute in (10 * 10 * 10 * 10)%nat.
56-
Let ARroot_test : nat -> bigD * bigD := AQsqrt_loop (a:=2).
55+
Definition n := Eval compute in (10 * 10 * 10 * 10)%nat.
56+
Definition ARroot_test : nat -> bigD * bigD := AQsqrt_loop (a:=2).
5757

5858
Time Eval vm_compute in (
5959
(fun _ _ _ _ _ _ _ _ _ _ => true)
@@ -68,25 +68,25 @@ Time Eval vm_compute in (
6868
(snd (ARroot_test n))
6969
(snd (ARroot_test n))).
7070

71-
Require Import BigZ.
71+
From Bignums Require Import BigZ.
7272
Open Scope bigZ_scope.
7373

74-
Definition BigD_0 : bigD := (0 $ 0).
75-
Definition BigD_1 : bigD := (1 $ 0).
76-
Definition BigD_2 : bigD := (2 $ 0).
77-
Definition BigD_4 : bigD := (4 $ 0).
74+
Definition BigD_0 : bigD := (0 0).
75+
Definition BigD_1 : bigD := (1 0).
76+
Definition BigD_2 : bigD := (2 0).
77+
Definition BigD_4 : bigD := (4 0).
7878

7979
Definition BigD_plus (x y : bigD) : bigD :=
8080
match BigZ.compare (expo x) (expo y) with
81-
| Gt => BigZ.shiftl (mant x) (expo x - expo y) + mant y $ BigZ.min (expo x) (expo y)
82-
| _ => mant x + BigZ.shiftl (mant y) (expo y - expo x) $ BigZ.min (expo x) (expo y)
81+
| Gt => BigZ.shiftl (mant x) (expo x - expo y) + mant y BigZ.min (expo x) (expo y)
82+
| _ => mant x + BigZ.shiftl (mant y) (expo y - expo x) BigZ.min (expo x) (expo y)
8383
end.
8484

85-
Definition BigD_opp (x : bigD) : bigD := -mant x $ expo x.
85+
Definition BigD_opp (x : bigD) : bigD := -mant x expo x.
8686

87-
Definition BigD_mult (x y : bigD) : bigD := mant x * mant y $ expo x + expo y.
87+
Definition BigD_mult (x y : bigD) : bigD := mant x * mant y expo x + expo y.
8888

89-
Definition BigD_shiftl (x : bigD) (n : bigZ) : bigD := mant x $ expo x + n.
89+
Definition BigD_shiftl (x : bigD) (n : bigZ) : bigD := mant x expo x + n.
9090

9191
Definition BigD_compare (x y : bigD) : comparison :=
9292
match BigZ.compare (expo x) (expo y) with

examples/Circle.v

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
(* I define the image of a path, a [Compact] subset of the plane.*)
44
(* Finally, plot a hi-res Circle*)
55

6-
From CoRN Require Import Plot RasterQ Qmetric.
7-
Require Import CoRN.reals.fast.Interval.
8-
Require Import CoRN.metric2.MetricMorphisms.
9-
Require Import CoRN.reals.faster.ARArith.
10-
From CoRN Require Import ARplot.
11-
Require Import CoRN.reals.faster.ARcos
12-
CoRN.reals.faster.ARsin
13-
CoRN.reals.faster.ARexp
14-
CoRN.reals.faster.ARbigD
15-
CoRN.reals.faster.ARinterval.
16-
Require Import CoRN.reals.fast.CRtrans.
17-
Require Import CoRN.write_image.WritePPM.
6+
From CoRN Require Import Plot RasterQ Qmetric
7+
reals.fast.Interval
8+
metric2.MetricMorphisms
9+
reals.faster.ARArith
10+
ARplot
11+
reals.faster.ARcos
12+
reals.faster.ARsin
13+
reals.faster.ARexp
14+
reals.faster.ARbigD
15+
reals.faster.ARinterval
16+
reals.fast.CRtrans
17+
write_image.WritePPM.
1818

1919
Local Open Scope uc_scope.
2020

@@ -76,7 +76,7 @@ Definition CirclePath': UCFunction Q R2:=
7676
Definition Circle : sparse_raster _ _
7777
:= (let (_,r) := Plot.PlotPath 0 7 (-(1)) 1 (reflexivity _)
7878
(-(1)) 1 (reflexivity _) 200 CirclePath
79-
in r).
79+
in r).
8080

8181
(* 16.3 seconds on Apple M1 *)
8282
Time Elpi WritePPM "Circle2.ppm" ( Circle ).

examples/IntegrationExamples.v

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
1919
CONNECTION WITH THE PROOF OR THE USE OR OTHER DEALINGS IN THE PROOF.
2020
*)
2121

22-
Require Import Integration.
23-
Require Import AbstractIntegration.
24-
Require SimpleIntegration.
25-
(*Require SimpsonIntegration.*)
26-
Require Import CRtrans.
27-
Require QnonNeg.
22+
From Stdlib Require Import NArith.
23+
From CoRN Require Import Integration AbstractIntegration SimpleIntegration
24+
(* SimpsonIntegration *)
25+
CRtrans QnonNeg.
2826
Import QnonNeg.notations.
2927

3028
(* The answer function returns an approximation of r within 10^-n.
@@ -33,9 +31,9 @@ answer is useful for because it displays a familar list of digits rather
3331
than an unfamiliar fraction that approximate would return *)
3432

3533
Definition answer (n:positive) (r:CR) : Z :=
36-
let m := (iter_pos n _ (Pmult 10) 1%positive) in
37-
let (a,b) := (approximate r (1#m)%Qpos)*m in
38-
Zdiv a b.
34+
let m := (Pos.iter (Pmult 10) 1%positive n) in
35+
let (a,b) := (approximate r (1#m :> Qpos))*(Zpos m#1) in
36+
Z.div a (Zpos b).
3937

4038
(* This file illustrates how to use the computational integration *)
4139
(* Please review RealFast.v for examples on how to compute with CR *)
@@ -62,7 +60,7 @@ Time Eval vm_compute in answer 3 (ContinuousSup01 Cunit).
6260
(* An example of an elliptic integral that cannot be solved symbolically
6361
\int_0^1 (1-\fract{1}{4}\sin^2\phi)^{-\fract{1}{2}} d\phi *)
6462

65-
Definition sinsquare:= (uc_compose (CRpower_positive_bounded 2 (1#1)) sin_uc).
63+
Definition sinsquare:= (uc_compose (CRpower_N_bounded 2 (1#1)) sin_uc).
6664
Definition quartersinsquare:=(uc_compose (scale (1#4)) sinsquare).
6765
Definition body:=(uc_compose (translate 1) quartersinsquare).
6866
Definition rootbody:=(uc_compose CRsqrt body).

examples/LMCS2011.v

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
Require Import CRtrans Compress.
2-
Require Import ARtrans ARbigD.
1+
From CoRN Require Import CRtrans Compress ARtrans ARbigD.
32

43
Definition eval (n:positive) (r : CR) :=
5-
let m := iter_pos n _ (Pmult 10) 1%positive in let _ := approximate r (1#m)%Qpos in tt.
4+
let m := Pos.iter (Pmult 10) 1%positive n in let _ := approximate r (1#m :> Qpos) in tt.
65

76
Definition deval (n:positive) (r : ARbigD) :=
8-
let m := iter_pos n _ (Pmult 10) 1%positive in let _ := approximate r (1#m)%Qpos in tt.
7+
let m := Pos.iter (Pmult 10) 1%positive n in let _ := approximate r (1#m :> Qpos) in tt.
98

109
Definition P01 : CR := sin (compress (sin (compress (rational_sin 1)))).
1110
Definition dP01 : ARbigD := ARsin (ARsin (AQsin 1)).
@@ -28,7 +27,7 @@ Definition dP07 : ARbigD := AQexp ('1000%Z).
2827
Definition P08 : CR := cos (cast Q CR (cast Z Q (10^50)%Z)).
2928
Definition dP08 : ARbigD := AQcos ('(10^50)%Z).
3029

31-
Require Import String.
30+
From Stdlib Require Import String.
3231

3332
Eval compute in "old"%string.
3433
Time Eval vm_compute in (eval 25 P01).

examples/Picard.v

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
Require Import CRtrans.
2-
Require Import Qmetric.
1+
(* TODO: fix this example *)
2+
From CoRN Require Import CRtrans Qmetric.
33

44
(* For comparison with Pattison's paper:
55
The ODE:
@@ -9,17 +9,18 @@ f(0)=0
99

1010
Section ODE.
1111
Open Scope uc_scope.
12-
Require Import ProductMetric CompleteProduct.
13-
Require Import Unicode.Utf8.
14-
Require Import CPoly_Newton.
15-
Require Import metric2.Classified.
16-
Require Import Circle.
12+
From CoRN Require Import ProductMetric CompleteProduct.
13+
From Stdlib Require Import Unicode.Utf8.
14+
From CoRN Require Import CPoly_Newton metric2.Classified.
15+
From examples Require Import Circle.
1716
Notation "X * Y":=(ProductMS X Y).
1817
Notation " f >> g ":= (Cbind_slow f ∘ g) (at level 50).
1918
Notation " x >>= f ":= (Cbind_slow f x) (at level 50).
2019

2120
Section Picard_op.
22-
Require Import AbstractIntegration.
21+
From CoRN Require Import AbstractIntegration.
22+
From CoRN Require Import SimpleIntegration.
23+
2324
(*
2425
Require Import stdlib_omissions.Pair.
2526
For diagonal*)
@@ -29,8 +30,6 @@ Variable f:Q-->CR.
2930
Notation "( f , g )":= (together f g).
3031
Definition vxfx:= (v >> Couple ∘ (Cunit, f) ∘ diag _).
3132

32-
Require Import SimpleIntegration.
33-
3433
(* Uniformly continuous function should be a type class
3534
so that we can define functions using Program Instance *)
3635
(* Integration takes a width, need the integral from a to b.*)
@@ -204,4 +203,4 @@ F x - x = F lim F^n - lim F^n = lim F^n+1 - lim F^n.
204203

205204
Theorem PicardFPT: exists f, (Picard f) = (f ∘ Cunit).
206205
apply BanachFPT.
207-
Qed.
206+
Qed.

examples/PlotExamples.v

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
1919
CONNECTION WITH THE PROOF OR THE USE OR OTHER DEALINGS IN THE PROOF.
2020
*)
2121

22-
Require Import Plot.
23-
Require Import CRtrans.
22+
From CoRN Require Import Plot CRtrans.
2423

2524
(* `∗' is used for trival proofs that a some concrete number is less than another *)
2625
Notation star := (@refl_equal _ Lt).
@@ -34,17 +33,17 @@ Local Open Scope raster.
3433
(* PlotQ requires that we plot uniformly continuous functions.
3534
Therefore we cannot plot (sin : CR -> CR), me must instead
3635
plot the UniformlyContinuousFunction (sin_uc : Q --> CR). *)
37-
(* Here we plot sin on [-3,3] with range [-1,1] on a 36x12 raster *)
38-
Time Eval vm_compute in PlotQ (- (3)) 3 star (- (1)) 1 star sin_uc 36 12.
36+
(* Here we plot sin on [-3,3] (= [-3,-3+6]) with range [-1,1] (= [-1,-1+2]) on a 36x12 raster *)
37+
Time Eval vm_compute in PlotQ (- (3)) (- (1)) (exist _ 6 star) (exist _ 2 star) sin_uc 36 12.
3938

4039
(* Here we explore the proof that plots are correct *)
4140
Goal True.
4241
(* Plot_correct is a proof that the plot is correct.*)
4342
(* below we plot exp on [-3, 0] with range [0,1] *)
4443
(* (exp_bound_uc 0) is exp on ]-inf,0] which is one domain where it is uniformly continuous *)
45-
assert (X:=@Plot_correct (-(3)) 0 star 0 1 star
44+
assert (X:=@Plot_correct (-(3)) 0 (exist _ 3 star) (exist _ 1 star)
4645
(exp_bound_uc 0)
47-
45 15 refl_equal refl_equal).
46+
45 15).
4847
(* No plot is seen. It is hidden in the uncomputed
4948
PlotQ (- (3)) 0 ∗ 0 1 ∗ (exp_bound_uc 0) 45 15 *)
5049
(* We use patern matchin to extract the parts of the statement we

examples/RealFast.v

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
1818
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
1919
CONNECTION WITH THE PROOF OR THE USE OR OTHER DEALINGS IN THE PROOF.
2020
*)
21-
Require Import CRtrans.
21+
From CoRN Require Import CRtrans.
2222

2323
Local Open Scope Q_scope.
2424

@@ -78,24 +78,23 @@ Time Eval vm_compute in answer 10 (rational_sin (10^14))%CR.
7878
(* exp (exp (exp (1/2))) *)
7979
Time Eval vm_compute in answer 10 (exp (compress (exp (compress (rational_exp (1#2))))))%CR.
8080

81-
Require Import CRsign.
81+
From CoRN Require Import CRsign.
8282

8383
(* This example shows how to automatically solve inequalites for CR *)
8484
Example xkcd217A : (exp (CRpi) - CRpi < '(20#1))%CR.
8585
unfold CRlt.
8686
Time CR_solve_pos (1#1000)%Qpos.
8787
Qed.
8888

89-
Require Import Exponential.
90-
Require Import Pi.
89+
From CoRN Require Import Exponential Pi.
9190

9291
(* This example shows how to automatically solve inequalites for IR *)
9392

9493
Example xkcd217B : (Exp Pi [-] Pi [<] (nring 20)).
9594
Time IR_solve_ineq (1#1000)%Qpos.
9695
Qed.
9796

98-
Require Import MultivariatePolynomials.
97+
From CoRN Require Import MultivariatePolynomials.
9998

10099
(* approximate 4*(1/e)*(1-(1/e)) while sharing the expression (1/e)
101100
using multivariable polynomial library (which only uses one variable

0 commit comments

Comments
 (0)