'Is this a valid way to use the Zarith Library

I was wondering if this Printf.printf "%d \n" Z.(s1 num2) is a valid way to use the Zarith Library. Don't know if more context is needed, but the function s1 is about Schroder sequence and when I use a number > 25 it won't show any number (because the number is way too big right? that's where Zarith enters) but I'm not sure if it is really working.



Solution 1:[1]

I loaded Zarith into my OCaml toplevel (REPL for OCaml). Here's what I see if I try what you give:

# Printf.printf "%d\n" Z.(s1 num2);;
Error: Unbound value s1

This makes sense, there's no symbol named s1 in the Z module (the big integer module of Zarith). If you have your own definition of s1 you have to show its definition to get help with it.

If you want to print out a big integer, you can't print it as an integer (with %d format). You have to convert to a string and print that. Here is a toplevel session that prints out 2 ^ 101:

# #load "zarith.cma";;
# #load "zarith_top.cma";;
# let big = Z.(of_int 1 lsl 101);;
val big : Z.t = 2535301200456458802993406410752
# Printf.printf "{{%s}}" (Z.to_string big);;
{{2535301200456458802993406410752}}- : unit = ()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1