Skip to content
Snippets Groups Projects
Commit 9729c5a4 authored by Tobias Winkler's avatar Tobias Winkler
Browse files

fixed/improved equality/zero checking of Dist

now uses Ginac's numer().is_zero() instead of just is_zero() which is not always clever enough to detect zero-ness
parent 78fd4ee9
No related branches found
No related tags found
No related merge requests found
......@@ -6,7 +6,7 @@ add_library(${BINARY}_lib STATIC
Formula.h Formula.cpp
Dist.h Dist.cpp
DistributionFactory.h DistributionFactory.cpp
Exceptions.h macros.h troolean.h)
Exceptions.h macros.h troolean.h troolean.cpp)
target_link_libraries(${BINARY}_lib PUBLIC ${GINAC_LIBRARIES})
target_link_libraries(${BINARY}_demo PUBLIC ${BINARY}_lib)
......@@ -388,7 +388,9 @@ namespace prodigy {
}
bool operator==(const Dist &lhs, const Dist &rhs) {
return lhs._gf.normal() == rhs._gf.normal();
// numer() rewrites to rational expression (a fraction) a returns numerator
// otherwise is_zero() does not always yield correct result
return (lhs._gf - rhs._gf).numer().is_zero();
}
Dist operator*(const Dist &lhs, const std::string &rhs) {
......
//
// Created by Tobias Winkler on 09.11.21.
//
#include "troolean.h"
namespace prodigy {
troolean makeTroolean(bool b) {
if(b) return troolean::YES;
return troolean::NO;
}
std::ostream& operator<<(std::ostream& os, troolean tr) {
if(tr == troolean::YES) {
return os << "yes";
} else if(tr == troolean::NO) {
return os << "no";
} else {
return os << "unknown";
}
}
}
......@@ -5,6 +5,8 @@
#ifndef PRODIGY_TROOLEAN_H
#define PRODIGY_TROOLEAN_H
#include <ostream>
namespace prodigy {
enum class troolean {
......@@ -13,10 +15,9 @@ namespace prodigy {
UNKNOWN
};
constexpr troolean makeTroolean(bool b) {
if(b) return troolean::YES;
return troolean::NO;
}
troolean makeTroolean(bool b);
std::ostream& operator<<(std::ostream& os, troolean tr);
}
......
......@@ -85,8 +85,8 @@ TEST(EquivalenceCheck, geometricSum) {
4: x := 0
*
*/
// l0 = DistributionFactory::geometric("x", "p") * DistributionFactory::geometric("c", "q");
l0 = Dist {"1/(1 - p*x)", "p"} * Dist {"1/ (1 - q*c)", "q"};
l0 = DistributionFactory::geometric("x", "p") * DistributionFactory::geometric("c", "q");
// l0 = Dist {"1/(1 - p*x)", "p"} * Dist {"1/ (1 - q*c)", "q"};
l1 = l0.updateIid("tmp", DistributionFactory::geometric("TMP", "1/2"), "x");
l2 = l1.update("c", "c + tmp");
l3 = l2.update("tmp", "0");
......@@ -107,7 +107,8 @@ TEST(EquivalenceCheck, geometricSum) {
*
*
*/
l0 = Dist {"1/(1 - p*x)", "p"} * Dist {"1/ (1 - q*c)", "q"};
l0 = DistributionFactory::geometric("x", "p") * DistributionFactory::geometric("c", "q");
// l0 = Dist {"1/(1 - p*x)", "p"} * Dist {"1/ (1 - q*c)", "q"};
l1 = l0.filterGreater("x", "0");
l2 = "1/2" * l1.update("x", "x - 1") + "1/2" * l1.update("c", "c + 1");
l3 = l2.updateIid("tmp", DistributionFactory::geometric("TMP", "1/2"), "x");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment