Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jtcoolen committed Jun 10, 2024
1 parent cca8161 commit 3de8dbf
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
24 changes: 24 additions & 0 deletions examples/number_fields.ml
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,27 @@ let q, r = Number_field.divrem gaussian_integers a b
let () =
Printf.eprintf "%b\n"
Number_field.(equal a (add gaussian_integers (mul gaussian_integers b q) r))

let _nf2 =
Number_field.create (Option.get @@ Polynomial.of_string "x^4-2" |> inj_rat)

let a = Vector.((Number_field.z_basis _nf2).%[2])
let a2 = Number_field.mul _nf2 a a
let _ = Printf.eprintf "%s\n" (gentostr a2)
let a4 = Number_field.mul _nf2 a2 a2
let _ = Printf.eprintf "a4=%s\n" (gentostr a4)

let mp =
nf_to_scalar_or_alg (Obj.magic _nf2)
(Number_field.add _nf2 a2
(Number_field.elt
[|
Integer.of_int (-3) |> Integer.inj_rat;
Integer.of_int 0 |> Integer.inj_rat;
Integer.of_int 0 |> Integer.inj_rat;
Integer.of_int 0 |> Integer.inj_rat;
|]))

let _ = Printf.eprintf "mp=%s\n" (gentostr mp)
let _ = Printf.eprintf "mp=%s\n" (gentostr (Number_field.splitting (`F _nf2)))
let _ = Printf.eprintf "mp=%s\n" (gentostr (polred (Obj.magic mp)))
6 changes: 6 additions & 0 deletions src/pari.ml
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,11 @@ module Polynomial = struct
register_gc p;
p

let of_string s =
let g = gp_read_str s in
let typ = gentostr (type0 g) in
if typ = "\"t_POL\"" then Some g else None

let var t = function Some var -> Signed.Long.(of_int var) | None -> gvar t
let deriv ?indeterminate t = deriv t (var t indeterminate)

Expand Down Expand Up @@ -336,6 +341,7 @@ module Number_field = struct
let discriminant nf = nf_get_disc nf
let z_basis nf = nf_get_zk nf
let elt a = Vector.(transpose_row (of_array a))
let inj_ring x = x
let add nf a b = nfadd nf a b
let mul nf a b = nfmul nf a b

Expand Down
3 changes: 3 additions & 0 deletions src/pari.mli
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ module rec Polynomial : sig
]}
*)

val of_string : string -> 'a t option
val deriv : ?indeterminate:int -> 'a t -> 'a t
val derivn : ?indeterminate:int -> 'a t -> int -> 'a t
val cyclotomic : Signed.long -> Integer.t t
Expand Down Expand Up @@ -477,6 +478,7 @@ module Number_field : sig
val discriminant : t -> Integer.t
val z_basis : t -> (elt, [ `ROW ]) Vector.t
val elt : Rational.t array -> elt
val inj_ring : elt -> (number_field, ring) typ
val add : t -> elt -> elt -> elt
val mul : t -> elt -> elt -> elt
val equal : elt -> elt -> bool
Expand Down Expand Up @@ -16114,6 +16116,7 @@ val gtovecsmall0 :
('kind, 'structure) typ -> Signed.long -> ('kind, 'structure) typ

val gtrunc : ('kind, 'structure) typ -> ('kind, 'structure) typ
val gvar : ('kind, 'structure) typ -> Signed.long
val gvar2 : ('kind, 'structure) typ -> Signed.long

val hqfeval :
Expand Down

0 comments on commit 3de8dbf

Please sign in to comment.