Skip to content

Commit 603f061

Browse files
committed
Added classes for Add, Mul, Pow
1 parent 8d03724 commit 603f061

File tree

8 files changed

+51
-32
lines changed

8 files changed

+51
-32
lines changed

ext/symengine/symengine.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,14 @@ void Init_symengine() {
5555
rb_define_const(m_symengine, "PI", cconstant_pi());
5656
rb_define_const(m_symengine, "E", cconstant_e());
5757
rb_define_const(m_symengine, "EULER_GAMMA", cconstant_euler_gamma());
58+
59+
//Add class
60+
c_add = rb_define_class_under(m_symengine, "Add", c_basic);
61+
62+
//Mul class
63+
c_mul = rb_define_class_under(m_symengine, "Mul", c_basic);
64+
65+
//Pow class
66+
c_pow = rb_define_class_under(m_symengine, "Pow", c_basic);
67+
5868
}

ext/symengine/symengine.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,8 @@ VALUE c_symbol;
1212
VALUE c_integer;
1313
VALUE c_rational;
1414
VALUE c_constant;
15+
VALUE c_add;
16+
VALUE c_mul;
17+
VALUE c_pow;
1518

1619
#endif //SYMENGINE_H_

ext/symengine/symengine_macros.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ VALUE Klass_of_Basic(const basic_struct *basic_ptr) {
4545
return c_rational;
4646
case SYMENGINE_CONSTANT:
4747
return c_constant;
48+
case SYMENGINE_ADD:
49+
return c_add;
50+
case SYMENGINE_MUL:
51+
return c_mul;
52+
case SYMENGINE_POW:
53+
return c_pow;
4854
default:
4955
return c_basic;
5056
}

spec/arit_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@
5454
f = e.expand
5555
assert e == (x + y)**2
5656
assert e != x**2 + 2 * x * y + y**2
57-
expect(e).to be_an_instance_of SymEngine::Basic
57+
expect(e).to be_a SymEngine::Basic
5858
assert f == x**2 + 2 * x * y + y**2
59-
expect(f).to be_an_instance_of SymEngine::Basic
59+
expect(f).to be_a SymEngine::Basic
6060
end
6161

6262
it 'test_arit6' do

spec/basic_spec.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
it 'returns a initialised Basic object that is result of
2828
self added to the argument' do
2929
c = @a + @b
30-
expect(c).to be_an_instance_of SymEngine::Basic
30+
expect(c).to be_a SymEngine::Basic
3131
expect(c.to_s).to eql('x + y')
3232
end
3333
end
@@ -37,7 +37,7 @@
3737
it 'returns a initialised Basic object that is result of
3838
argument subtracted from self' do
3939
c = @a - @b
40-
expect(c).to be_an_instance_of SymEngine::Basic
40+
expect(c).to be_a SymEngine::Basic
4141
expect(c.to_s).to eql('x - y')
4242
end
4343
end
@@ -47,7 +47,7 @@
4747
it 'returns a initialised Basic object that is result of
4848
self multiplied by the argument' do
4949
c = @a * @b
50-
expect(c).to be_an_instance_of SymEngine::Basic
50+
expect(c).to be_a SymEngine::Basic
5151
expect(c.to_s).to eql('x*y')
5252
end
5353
end
@@ -57,7 +57,7 @@
5757
it 'returns a initialised Basic object that is result of
5858
self divided by the argument' do
5959
c = @a / @b
60-
expect(c).to be_an_instance_of SymEngine::Basic
60+
expect(c).to be_a SymEngine::Basic
6161
expect(c.to_s).to eql('x/y')
6262
end
6363
end
@@ -67,7 +67,7 @@
6767
it 'returns a initialised Basic object that is result of
6868
self raised to the power of argument' do
6969
c = @a**@b
70-
expect(c).to be_an_instance_of SymEngine::Basic
70+
expect(c).to be_a SymEngine::Basic
7171
expect(c.to_s).to eql('x**y')
7272
end
7373
end
@@ -78,7 +78,7 @@
7878
and returns the result' do
7979
a = @a**3
8080
c = a.diff(@a)
81-
expect(c).to be_an_instance_of SymEngine::Basic
81+
expect(c).to be_a SymEngine::Basic
8282
expect(c).to eq(3 * @a**2)
8383
expect(a.diff(2)).to be_nil
8484
end
@@ -127,7 +127,7 @@
127127
context "doesn't take any argument" do
128128
it 'returns the negation of self' do
129129
p = -@x
130-
expect(p).to be_an_instance_of SymEngine::Basic
130+
expect(p).to be_a SymEngine::Basic
131131
expect(p.to_s).to eql('-a')
132132
end
133133
end
@@ -142,7 +142,7 @@
142142
z = SymEngine::Symbol.new('z')
143143
e = (x**y + z)
144144
f = e.args
145-
expect(f).to be_an_instance_of Array
145+
expect(f).to be_an Array
146146
expect(f.length).to be 2
147147
expect(f.to_set).to eql([x**y, z].to_set)
148148
end
@@ -157,7 +157,7 @@
157157
z = SymEngine::Symbol.new('z')
158158
e = (x**y / z)
159159
f = e.free_symbols
160-
expect(f).to be_an_instance_of Set
160+
expect(f).to be_a Set
161161
expect(f.length).to be 3
162162
expect(f).to eql([x, y, z].to_set)
163163
end
@@ -173,7 +173,7 @@
173173
e = (x + y + z) * (x + y + z)
174174
f = e.expand
175175
expect(e.to_s).to eql('(x + y + z)**2')
176-
expect(f).to be_an_instance_of SymEngine::Basic
176+
expect(f).to be_a SymEngine::Basic
177177
expect(f.to_s).to eql('2*x*y + 2*x*z + 2*y*z + x**2 + y**2 + z**2')
178178
expect(e == f).to be false
179179
end

spec/constant_spec.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@
1818
context 'with summation with one' do
1919
it 'returns an initialised Basic object that is equalent to 1 + pi' do
2020
f = @a + @d
21-
expect(@a).to be_an_instance_of SymEngine::Constant
22-
expect(f).to be_an_instance_of SymEngine::Basic
21+
expect(@a).to be_a SymEngine::Constant
22+
expect(f).to be_a SymEngine::Basic
2323
expect(f.to_s).to eql('1 + pi')
2424
end
2525
end
2626

2727
context 'with plus one and minus one' do
2828
it 'returns a Constant' do
29-
expect(1 + @a - 1).to be_an_instance_of SymEngine::Constant
29+
expect(1 + @a - 1).to be_a SymEngine::Constant
3030
end
3131
end
3232

@@ -36,15 +36,15 @@
3636
context 'with powered to zero' do
3737
it 'returns an initialised Basic object that is equalent 1' do
3838
f = @c ** @e
39-
expect(@c).to be_an_instance_of SymEngine::Constant
40-
expect(f).to be_an_instance_of SymEngine::Integer
39+
expect(@c).to be_a SymEngine::Constant
40+
expect(f).to be_a SymEngine::Integer
4141
expect(f.to_s).to eql('1')
4242
end
4343
end
4444

4545
context 'with plus one and minus one' do
4646
it 'returns a Constant' do
47-
expect(1 + @c - 1).to be_an_instance_of SymEngine::Constant
47+
expect(1 + @c - 1).to be_a SymEngine::Constant
4848
end
4949
end
5050

@@ -54,15 +54,15 @@
5454
context 'with summation with x' do
5555
it 'returns an initialised Basic object that is equalent to x + E' do
5656
f = @b + @x
57-
expect(@b).to be_an_instance_of SymEngine::Constant
58-
expect(f).to be_an_instance_of SymEngine::Basic
57+
expect(@b).to be_a SymEngine::Constant
58+
expect(f).to be_a SymEngine::Basic
5959
expect(f.to_s).to eql('x + E')
6060
end
6161
end
6262

6363
context 'with plus one and minus one' do
6464
it 'returns a Constant' do
65-
expect(1 + @b - 1).to be_an_instance_of SymEngine::Constant
65+
expect(1 + @b - 1).to be_a SymEngine::Constant
6666
end
6767
end
6868

spec/integer_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
it 'gives a new SymEngine::Integer instance' do
88
a = SymEngine::Integer.new(123)
99
b = SymEngine::Integer.new(-123)
10-
expect(a).to be_an_instance_of SymEngine::Integer
11-
expect(b).to be_an_instance_of SymEngine::Integer
10+
expect(a).to be_a SymEngine::Integer
11+
expect(b).to be_a SymEngine::Integer
1212
expect(a.to_s).to eq('123')
1313
expect(b.to_s).to eq('-123')
1414
c = SymEngine::Integer.new(12_345_678_912_345_678_912)
@@ -27,27 +27,27 @@
2727
context 'using a ruby integer as the second operand' do
2828
it 'succeeds with commutative operations' do
2929
b = @a * 2
30-
expect(b).to be_an_instance_of SymEngine::Basic
30+
expect(b).to be_a SymEngine::Basic
3131
expect(b).to eq(SymEngine::Integer.new(2) * @a)
3232
end
3333

3434
it 'succeeds with non commutative operations' do
3535
b = @a / 2
36-
expect(b).to be_an_instance_of SymEngine::Basic
36+
expect(b).to be_a SymEngine::Basic
3737
expect(b).to eq(@a / SymEngine::Integer.new(2))
3838
end
3939
end
4040

4141
context 'using a ruby integer as the first operand' do
4242
it 'succeeds with commutative operations' do
4343
b = 2 * @a
44-
expect(b).to be_an_instance_of SymEngine::Basic
44+
expect(b).to be_a SymEngine::Basic
4545
expect(b).to eq(@a * SymEngine::Integer.new(2))
4646
end
4747

4848
it 'succeeds with non commutative operations' do
4949
b = 2 / @a
50-
expect(b).to be_an_instance_of SymEngine::Basic
50+
expect(b).to be_a SymEngine::Basic
5151
expect(b).to eq(SymEngine::Integer.new(2) / @a)
5252
end
5353
end

spec/rational_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
it 'returns an instance of SymEngine::Rational class' do
88
a = Rational('2/3')
99
a = SymEngine::Rational.new(a)
10-
expect(a).to be_an_instance_of SymEngine::Rational
10+
expect(a).to be_a SymEngine::Rational
1111
expect(a.to_s).to eq('2/3')
1212
end
1313
end
@@ -22,27 +22,27 @@
2222
context 'using a ruby Rational as the second operand' do
2323
it 'succeeds with commutative operations' do
2424
c = @a * @b
25-
expect(c).to be_an_instance_of SymEngine::Basic
25+
expect(c).to be_a SymEngine::Basic
2626
expect(c).to eq(SymEngine::Rational.new(@b) * @a)
2727
end
2828

2929
it 'succeeds with non commutative operations' do
3030
c = @a / @b
31-
expect(c).to be_an_instance_of SymEngine::Basic
31+
expect(c).to be_a SymEngine::Basic
3232
expect(c).to eq(@a / SymEngine::Rational.new(@b))
3333
end
3434
end
3535

3636
context 'using a ruby Rational as the first operand' do
3737
it 'succeeds with commutative operations' do
3838
c = @b * @a
39-
expect(c).to be_an_instance_of SymEngine::Basic
39+
expect(c).to be_a SymEngine::Basic
4040
expect(c).to eq(@a * SymEngine::Rational.new(@b))
4141
end
4242

4343
it 'succeeds with non commutative operations' do
4444
c = @b / @a
45-
expect(c).to be_an_instance_of SymEngine::Basic
45+
expect(c).to be_a SymEngine::Basic
4646
expect(c).to eq(SymEngine::Rational.new(@b) / @a)
4747
end
4848
end

0 commit comments

Comments
 (0)