Macaulay2 Engine
Loading...
Searching...
No Matches
RingTowerTest.cpp
Go to the documentation of this file.
1// Copyright 2013 Michael E. Stillman
2
30
31#include <cstdio>
32#include <string>
33#include <iostream>
34#include <sstream>
35#include <memory>
36#include <gtest/gtest.h>
37#include <mpfr.h>
38
39#include "RingTest.hpp"
40#include "tower.hpp"
41#include "../util.hpp"
42
43// First: we need a routine to read a polynomial from a string.
44// Format: variables are a..zA..Z, and then [1], [2], ...
45// Need both input and output routines for reading/writing polynomials in this
46// format.
47// coefficients: (+ or - or nothing) (number) (optional: . or /, followed by
48// another (number)
49// for GF, do we mix the a^r in?
50
51template <>
52ring_elem getElement<Tower>(const Tower& R, int index)
53{
54 return R.random();
55}
56
58TEST(RingTower, create)
59{
60 std::vector<std::string> vars = {"a", "b"};
61 M2_ArrayString varnames = stdvector_to_M2_ArrayString(vars);
62 const Tower* R = Tower::create(101, varnames);
63 EXPECT_TRUE(R != nullptr);
64 EXPECT_EQ(ringName(*R), "Tower[ZZ/101[a,b]]");
65 EXPECT_EQ(R->n_vars(), 2);
66 for (int i = 1; i < 1; i++)
67 {
68 ring_elem f = R->random();
69 buffer o;
70 o << "f = ";
71 R->elem_text_out(o, f);
72 std::cout << o.str() << std::endl;
73 }
74}
75
76TEST(RingTower, elems)
77{
78 std::vector<std::string> vars = {"a", "b"};
79 M2_ArrayString varnames = stdvector_to_M2_ArrayString(vars);
80 const Tower* R = Tower::create(101, varnames);
81
82 ring_elem a = R->var(0);
83 ring_elem b = R->var(1);
84
85 buffer o;
86 o << "a=";
87 R->elem_text_out(o, a);
88 o << " b=";
89 R->elem_text_out(o, b);
90 ring_elem c = R->add(a, R->from_long(2));
91 c = R->add(c, b);
92 o << " c=";
93 R->elem_text_out(o, c);
94 ring_elem d = R->power(c, 2);
95 o << " d=";
96 R->elem_text_out(o, d);
97 o << newline;
98
99 std::cout << o.str();
100}
101
102// Local Variables:
103// compile-command: "make -C $M2BUILDDIR/Macaulay2/e/unit-tests check "
104// indent-tabs-mode: nil
105// End:
std::string ringName(const T &R)
Shared gtest fixture for the legacy Ring-based Ring*Test.cpp suite.
TEST(RingTower, create)
ring_elem getElement< Tower >(const Tower &R, int index)
virtual ring_elem power(const ring_elem f, mpz_srcptr n) const
Exponentiation. This is the default function, if a class doesn't define this.
Definition ring.cpp:109
virtual ring_elem random() const
Definition tower.cpp:246
virtual ring_elem from_long(long n) const
Definition tower.cpp:106
static Tower * create(int charac, M2_ArrayString names)
Definition tower.cpp:46
virtual ring_elem var(int v) const
Definition tower.cpp:128
virtual ring_elem add(const ring_elem f, const ring_elem g) const
Definition tower.cpp:187
virtual void elem_text_out(buffer &o, const ring_elem f, bool p_one=true, bool p_plus=false, bool p_parens=false) const
Definition tower.cpp:254
int n_vars() const
Definition tower.hpp:79
Ring subclass for tower polynomial rings (Z/p)[x_0][x_1]...[x_{n-1}] modulo a chain of algebraic exte...
Definition tower.hpp:59
char * str()
Definition buffer.hpp:72
char newline[]
Definition m2-types.cpp:49
Legacy Tower — Ring-derived iterated extension of Z/p (pre-aring).
M2_ArrayString stdvector_to_M2_ArrayString(const std::vector< std::string > &strs)
Definition util.hpp:67
Conversion helpers between M2 boundary types and standard C++ containers.