[mathicgb] 210/393: More division code.
Doug Torrance
dtorrance-guest at moszumanska.debian.org
Fri Apr 3 15:59:03 UTC 2015
This is an automated email from the git hooks/post-receive script.
dtorrance-guest pushed a commit to branch upstream
in repository mathicgb.
commit a89952b985f8237585e5699d7de0995abb804716
Author: Bjarke Hammersholt Roune <bjarkehr.code at gmail.com>
Date: Fri Mar 29 14:47:40 2013 +0100
More division code.
---
src/mathicgb/MonoMonoid.hpp | 21 ++++++++++++++++++++-
src/test/MonoMonoid.cpp | 14 ++++++++++++++
2 files changed, 34 insertions(+), 1 deletion(-)
diff --git a/src/mathicgb/MonoMonoid.hpp b/src/mathicgb/MonoMonoid.hpp
index db7182d..247f50b 100755
--- a/src/mathicgb/MonoMonoid.hpp
+++ b/src/mathicgb/MonoMonoid.hpp
@@ -196,12 +196,14 @@ public:
// *** Monomial mutating computations
+ /// Copes the parameter from to the parameter to.
void copy(ConstMonoRef from, MonoRef to) const {
MATHICGB_ASSERT(debugValid(from));
std::copy_n(rawPtr(from), entryCount(), rawPtr(to));
MATHICGB_ASSERT(debugValid(to));
}
+ /// Set the exponent of var to newExponent in mono.
void setExponent(
const VarIndex var,
const Exponent newExponent,
@@ -217,12 +219,14 @@ public:
MATHICGB_ASSERT(debugValid(mono));
}
+ /// Sets mono to 1, which is the identity for multiplication.
void setIdentity(MonoRef mono) const {
std::fill_n(rawPtr(mono), entryCount(), static_cast<Exponent>(0));
MATHICGB_ASSERT(debugValid(mono));
MATHICGB_ASSERT(isIdentity(mono));
}
+ /// Sets the component of mono to newComponent.
void setComponent(Component newComponent, MonoRef mono) const {
auto& component = access(mono, componentIndex());
const auto oldComponent = component;
@@ -231,6 +235,7 @@ public:
MATHICGB_ASSERT(debugValid(mono));
}
+ /// Sets prod to a*b.
void multiply(ConstMonoRef a, ConstMonoRef b, MonoRef prod) const {
MATHICGB_ASSERT(debugValid(a));
MATHICGB_ASSERT(debugValid(b));
@@ -238,10 +243,10 @@ public:
for (auto i = 0; i < entryCount(); ++i)
access(prod, i) = access(a, i) + access(b, i);
- MATHICGB_ASSERT(hashOfProduct(a, b) == hash(prod));
MATHICGB_ASSERT(debugValid(prod));
}
+ /// Sets prod to a*prod.
void multiplyInPlace(ConstMonoRef a, MonoRef prod) const {
MATHICGB_ASSERT(debugValid(a));
MATHICGB_ASSERT(debugValid(prod));
@@ -252,6 +257,7 @@ public:
MATHICGB_ASSERT(debugValid(prod));
}
+ /// Sets quo to num/by. by must divide num.
void divide(ConstMonoRef by, ConstMonoRef num, MonoRef quo) const {
MATHICGB_ASSERT(divides(by, num));
MATHICGB_ASSERT(debugValid(num));
@@ -263,6 +269,7 @@ public:
MATHICGB_ASSERT(debugValid(quo));
}
+ /// Sets num to num/by. by must divide num.
void divideInPlace(ConstMonoRef by, MonoRef num) const {
MATHICGB_ASSERT(divides(by, num));
MATHICGB_ASSERT(debugValid(by));
@@ -274,6 +281,18 @@ public:
MATHICGB_ASSERT(debugValid(num));
}
+ /// Sets quo to num/by. If by does not divide num then quo will have
+ /// negative exponents.
+ void divideToNegative(ConstMonoRef by, ConstMonoRef num, MonoRef quo) const {
+ MATHICGB_ASSERT(debugValid(num));
+ MATHICGB_ASSERT(debugValid(by));
+
+ for (auto i = 0; i < entryCount(); ++i)
+ access(quo, i) = access(num, i) - access(by, i);
+
+ MATHICGB_ASSERT(debugValid(quo));
+ }
+
/// Parses a monomial out of a string. Valid examples: 1 abc a2bc
/// aA. Variable names are case sensitive. Whitespace terminates the
/// parse as does any other character that is not a letter or a
diff --git a/src/test/MonoMonoid.cpp b/src/test/MonoMonoid.cpp
index ee167dc..8d4f2c5 100755
--- a/src/test/MonoMonoid.cpp
+++ b/src/test/MonoMonoid.cpp
@@ -375,6 +375,20 @@ TEST(MonoMonoid, MultiplyDivide) {
ASSERT_TRUE(m.compare(a, mono) == Monoid::EqualTo);
ASSERT_TRUE(m.divides(mono, a));
}
+
+ // Check that aliased parameters work.
+ m.multiply(mono, mono, mono);
+ m.divide(mono, mono, mono);
+ MATHICGB_ASSERT(m.isIdentity(mono));
+
+ // Check that negative exponents work
+ m.divideToNegative(a, b, mono);
+ m.multiply(a, mono, mono);
+ ASSERT_TRUE(m.equal(mono, b));
+
+ m.divideToNegative(b, a, mono);
+ m.multiply(b, mono, mono);
+ ASSERT_TRUE(m.equal(mono, a));
};
check("1 1 1");
check("a 1 a");
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/mathicgb.git
More information about the debian-science-commits
mailing list