Skip to content

Instantly share code, notes, and snippets.

@bollu
Created December 15, 2016 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bollu/586f3c2699f25eb37dc5092664761c3c to your computer and use it in GitHub Desktop.
Save bollu/586f3c2699f25eb37dc5092664761c3c to your computer and use it in GitHub Desktop.
error with distributivity of * over + in SymEngine with symbols
#!/usr/bin/env bash
clang main.c -lsymengine && ./a.out
#include "gmp.h"
#include <symengine/cwrapper.h>
int main() {
basic_struct* x = basic_new_heap();
basic_struct* v = basic_new_heap();
basic_const_set(x, "x");
basic_const_set(v, "v");
basic_struct *minus_one = basic_new_heap();
basic_const_minus_one(minus_one);
basic_struct *a = basic_new_heap();
basic_add(a, v, minus_one);
basic_mul(a, x, a);
printf("a: %s", basic_str(a));
basic_struct *b = basic_new_heap();
basic_struct *xv = basic_new_heap();
basic_struct *minus_x = basic_new_heap();
basic_mul(xv, x, v);
basic_mul(minus_x, x, minus_one);
basic_add(b, xv, minus_x);
printf("\nb: %s", basic_str(b));
printf("\na == b ? %s", basic_eq(a, b) == 1 ? "true" : "false");
return 0;
}
a: x*(-1 + v)
b: x*v - x
a == b ? false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment