Skip to content

Commit b45d182

Browse files
committed
Lambdify for i
1 parent a5221d8 commit b45d182

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

lib/symengine.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ def symbols ary_or_string, *params
2828
end
2929
end
3030
def Function(n)
31-
return SymEngine::UndefFunction.new(n)
31+
SymEngine::UndefFunction.new(n)
3232
end
3333
def evalf(operand, prec=53, real=false)
34-
return _evalf(operand, prec, real)
34+
_evalf(operand, prec, real)
3535
end
3636
def lambdify(exp, *syms)
3737
eval(SymEngine::Utils::lambdify_code(exp, syms))
@@ -43,7 +43,7 @@ class << self
4343
asin: 'Math.asin', acos: 'Math.acos', atan: 'Math.atan',
4444
sinh: 'Math.sinh', cosh: 'Math.cosh', tanh: 'Math.tanh',
4545
asinh: 'Math.asinh', acosh: 'Math.acosh', atanh: 'Math.atanh',
46-
pi: 'Math::PI', E: 'Math::E',
46+
pi: 'Math::PI', E: 'Math::E', I: '::Complex::I',
4747
dirichlet_eta: 'SymEngine::Utils::evalf_dirichlet_eta',
4848
zeta: 'SymEngine::Utils::evalf_zeta', gamma: 'Math.gamma' }.map { |from, to| [/(\b#{from}\b)/, to] }.to_h.freeze
4949
def evalf_dirichlet_eta(exp)
@@ -53,7 +53,7 @@ def evalf_zeta(exp)
5353
SymEngine::evalf(SymEngine::zeta(exp))
5454
end
5555
def lambdify_code(exp, syms)
56-
str = exp.to_s
56+
str = exp.to_s
5757
sym_map = syms.join(",")
5858
str.gsub!(/[\d\.]+/, 'Rational(\0,1)')
5959
str = REPLACEMENTS.inject(str) { |res, (from, to)| res.gsub(from, to)}

spec/lambdify_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def l(code)
2626
expect(l( SymEngine::gamma(x) )).to eq("lambda { | x | Math.gamma(x) }")
2727
expect(l( x + SymEngine::PI )).to eq("lambda { | x | x + Math::PI }")
2828
expect(l( x + SymEngine::E )).to eq("lambda { | x | x + Math::E }")
29+
expect(l( x * SymEngine::I )).to eq("lambda { | x | ::Complex::I*x }")
2930
expect(l( SymEngine::dirichlet_eta(x) )).to eq("lambda { | x | SymEngine::Utils::evalf_dirichlet_eta(x) }")
3031
expect(l( SymEngine::zeta(x) )).to eq("lambda { | x | SymEngine::Utils::evalf_zeta(x, Rational(1,1)) }")
3132

0 commit comments

Comments
 (0)