Skip to content

Commit

Permalink
tests/OK/natural.lp: add builtins for printing Peano numbers in decim…
Browse files Browse the repository at this point in the history
…al notation (#1186)
  • Loading branch information
fblanqui authored Jan 27, 2025
1 parent 9a8550d commit 956dcf7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/core/print.ml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ let var : 'a Bindlib.var pp = fun ppf x -> uid ppf (Bindlib.name_of x)

(** Exception raised when trying to convert a term into a nat. *)
exception Not_a_nat

let builtin name =
try StrMap.find name (!sig_state).builtins with Not_found -> raise Not_a_nat

Expand Down
11 changes: 8 additions & 3 deletions tests/OK/natural.lp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ with (s $m) × $n ↪ $n + $m × $n
with _ × z ↪ z
with $m × (s $n) ↪ $m + $m × $n;

// Enabling decimal notation
// Enabling parsing of decimal notation

symbol n1 ≔ s z;
symbol n2 ≔ s n1;
Expand Down Expand Up @@ -57,14 +57,19 @@ builtin "*" ≔ ×;

symbol forty_two ≔ 42;

//print forty_two;

assert ⊢ forty_two
≡ let two ≔ s(s z) in
let four ≔ two + two in
let ten ≔ four + four + two in
four × ten + two;

// Enabling printing of decimal notation

builtin "nat_zero" ≔ z;
builtin "nat_succ" ≔ s;

compute 4 + 5;

// Doubling function.

symbol double n ≔ n × 2;
Expand Down
2 changes: 1 addition & 1 deletion tests/OK/perf_rw_fib-nonRightLin.lp
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ with fib3 (s (s (s $x))) ↪ (fib3 ($x + 2)) + (fib3 ($x + 1)) + (fib3 $x);

assert ⊢ fib 15 ≡ 610;
compute fib 24; // ≡ 46368;
compute fib3 21;
//compute fib3 21;

0 comments on commit 956dcf7

Please sign in to comment.