Skip to content

Commit 85e5958

Browse files
committed
Fixed formatting. Corrected errors
1 parent 99bf665 commit 85e5958

File tree

5 files changed

+19
-9
lines changed

5 files changed

+19
-9
lines changed

lib/symengine.rb

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ def evalf(operand, prec=53, real=false)
3636
_evalf(operand, prec, real)
3737
end
3838
def lambdify(exp, *syms)
39+
syms.flatten!
40+
if exp.free_symbols.count > syms.length
41+
raise ArgumentError, "Formula contains #{exp.free_symbols.count} free s"\
42+
"ymbols. You should provide at least this numb"\
43+
"er of arguments (only #{syms.length} given)."
44+
end
3945
eval(SymEngine::Utils::lambdify_code(exp, syms))
4046
end
4147
end
@@ -55,11 +61,10 @@ def evalf_zeta(exp)
5561
SymEngine::evalf(SymEngine::zeta(exp))
5662
end
5763
def lambdify_code(exp, syms)
58-
str = exp.to_s
64+
body = exp.to_s.gsub(/[\d\.]+/, 'Rational(\0,1)')
5965
sym_map = syms.join(",")
60-
str.gsub!(/[\d\.]+/, 'Rational(\0,1)')
61-
str = REPLACEMENTS.inject(str) { |res, (from, to)| res.gsub(from, to)}
62-
"proc { | #{sym_map} | #{str} }"
66+
rubified_body = REPLACEMENTS.inject(body) { |res, (from, to)| res.gsub(from, to)}
67+
"proc { | #{sym_map} | #{rubified_body} }"
6368
end
6469
end
6570
end

lib/symengine/basic.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,17 @@ def abs
1616
def to_proc(*args)
1717
if args.empty?
1818
if free_symbols.count > 1
19-
raise ArgumentError, "You should provide symbols order for #to_proc. Only formulae with 1 free symbol can deduce its name automatically (#{free_symbols.count} found in #{self})."
19+
raise ArgumentError, "You should provide symbols order for #to_proc"\
20+
". Only formulae with 1 free symbol can deduce"\
21+
" its name automatically (#{free_symbols.count}"\
22+
" found in #{self})."
2023
end
2124
SymEngine::lambdify(self, free_symbols.map {|s| s})
2225
else
2326
if free_symbols.count > args.length
24-
raise ArgumentError, "Formula contains #{free_symbols.count} free symbols. You should provide at least this number of arguments (only #{args.length} given)."
27+
raise ArgumentError, "Formula contains #{free_symbols.count} free s"\
28+
"ymbols. You should provide at least this numb"\
29+
"er of arguments (only #{args.length} given)."
2530
end
2631
SymEngine::lambdify(self, args)
2732
end

spec/functions_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
expect(SymEngine::asinh(0)).to eq(0)
8787
expect(SymEngine::acosh(1)).to eq(0)
8888
expect(SymEngine::atanh(0)).to eq(0)
89-
expect(SymEngine::acsch(1).to_s).to eq('log(1 + 2**(1/2))')
89+
expect(SymEngine::acsch(1).to_s).to eq('log(1 + sqrt(2))')
9090
expect(SymEngine::asech(1)).to eq(0)
9191
expect(SymEngine::acoth(1).to_s).to eq('acoth(1)')
9292

spec/lambdify_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def l(code)
4242

4343
describe 'lambda for Addition' do
4444
let(:func) { x + y + z }
45-
let(:lamb) { SymEngine::lambdify(func, [x, y, z]) }
45+
let(:lamb) { SymEngine::lambdify(func, x, y, z) }
4646
it 'performs addition with a lambda function' do
4747
expect(lamb.call(1, 1, 1)).to eq(3)
4848
expect(lamb.call(1, -1, 1)).to eq(1)

symengine_version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
bb18f1c1f4cbc29765fe1bcbd2dbe9345279b659
1+
ab5f5da3a9aa501a7a5bf7889a68f67c21a3b9c8

0 commit comments

Comments
 (0)