symath 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +12 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +7 -0
  5. data/CODE_OF_CONDUCT.md +74 -0
  6. data/Gemfile +8 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +616 -0
  9. data/Rakefile +6 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +8 -0
  12. data/lib/symath/definition/abs.rb +48 -0
  13. data/lib/symath/definition/arccos.rb +25 -0
  14. data/lib/symath/definition/arccot.rb +23 -0
  15. data/lib/symath/definition/arccsc.rb +24 -0
  16. data/lib/symath/definition/arcsec.rb +24 -0
  17. data/lib/symath/definition/arcsin.rb +25 -0
  18. data/lib/symath/definition/arctan.rb +23 -0
  19. data/lib/symath/definition/bounds.rb +39 -0
  20. data/lib/symath/definition/codiff.rb +31 -0
  21. data/lib/symath/definition/constant.rb +111 -0
  22. data/lib/symath/definition/cos.rb +17 -0
  23. data/lib/symath/definition/cot.rb +17 -0
  24. data/lib/symath/definition/csc.rb +17 -0
  25. data/lib/symath/definition/curl.rb +27 -0
  26. data/lib/symath/definition/d.rb +62 -0
  27. data/lib/symath/definition/div.rb +27 -0
  28. data/lib/symath/definition/exp.rb +112 -0
  29. data/lib/symath/definition/fact.rb +55 -0
  30. data/lib/symath/definition/flat.rb +31 -0
  31. data/lib/symath/definition/function.rb +197 -0
  32. data/lib/symath/definition/grad.rb +23 -0
  33. data/lib/symath/definition/hodge.rb +23 -0
  34. data/lib/symath/definition/int.rb +75 -0
  35. data/lib/symath/definition/laplacian.rb +23 -0
  36. data/lib/symath/definition/lmd.rb +97 -0
  37. data/lib/symath/definition/ln.rb +45 -0
  38. data/lib/symath/definition/number.rb +51 -0
  39. data/lib/symath/definition/operator.rb +228 -0
  40. data/lib/symath/definition/sec.rb +17 -0
  41. data/lib/symath/definition/sharp.rb +31 -0
  42. data/lib/symath/definition/sin.rb +17 -0
  43. data/lib/symath/definition/sqrt.rb +62 -0
  44. data/lib/symath/definition/tan.rb +17 -0
  45. data/lib/symath/definition/trig.rb +95 -0
  46. data/lib/symath/definition/variable.rb +284 -0
  47. data/lib/symath/definition/xd.rb +28 -0
  48. data/lib/symath/definition.rb +205 -0
  49. data/lib/symath/equation.rb +67 -0
  50. data/lib/symath/fraction.rb +177 -0
  51. data/lib/symath/matrix.rb +252 -0
  52. data/lib/symath/minus.rb +125 -0
  53. data/lib/symath/operation/differential.rb +167 -0
  54. data/lib/symath/operation/distributivelaw.rb +367 -0
  55. data/lib/symath/operation/exterior.rb +64 -0
  56. data/lib/symath/operation/integration.rb +329 -0
  57. data/lib/symath/operation/match.rb +166 -0
  58. data/lib/symath/operation/normalization.rb +458 -0
  59. data/lib/symath/operation.rb +36 -0
  60. data/lib/symath/operator.rb +163 -0
  61. data/lib/symath/parser.rb +473 -0
  62. data/lib/symath/parser.y +129 -0
  63. data/lib/symath/poly/dup.rb +835 -0
  64. data/lib/symath/poly/galois.rb +621 -0
  65. data/lib/symath/poly.rb +142 -0
  66. data/lib/symath/power.rb +224 -0
  67. data/lib/symath/product.rb +183 -0
  68. data/lib/symath/sum.rb +174 -0
  69. data/lib/symath/type.rb +282 -0
  70. data/lib/symath/value.rb +372 -0
  71. data/lib/symath/version.rb +3 -0
  72. data/lib/symath/wedge.rb +48 -0
  73. data/lib/symath.rb +157 -0
  74. data/symath.gemspec +39 -0
  75. metadata +160 -0
data/lib/symath.rb ADDED
@@ -0,0 +1,157 @@
1
+ require "symath/version"
2
+ require "symath/parser"
3
+
4
+ require 'symath/type'
5
+ require 'symath/operator'
6
+ require 'symath/sum'
7
+ require 'symath/minus'
8
+ require 'symath/product'
9
+ require 'symath/wedge'
10
+ require 'symath/fraction'
11
+ require 'symath/power'
12
+ require 'symath/definition'
13
+ require 'symath/value'
14
+ require 'symath/matrix'
15
+ require 'symath/equation'
16
+ require 'symath/poly'
17
+ require 'symath/poly/dup'
18
+ require 'symath/poly/galois'
19
+
20
+ module SyMath
21
+ @@global_settings = {
22
+ # Symbol used to represent the differential operator
23
+ # on variables
24
+ :d_symbol => 'd',
25
+ # Symbol used to represent vector variables
26
+ :vector_symbol => '\'',
27
+ # Symbol used to represent covector variables
28
+ :covector_symbol => '.',
29
+
30
+ # Show all parantheses on +, *, / and ^ operators.
31
+ :expl_parentheses => false,
32
+ # Represent square roots with the root symbol or as a fraction exponent
33
+ :sq_exponent_form => false,
34
+ # Represent fraction of scalars as a negative exponent
35
+ :fraction_exponent_form => false,
36
+ # Show the multiplication sign in LaTeX output
37
+ :ltx_product_sign => false,
38
+
39
+ # Simplify expression at the time they are composed
40
+ :compose_with_simplify => true,
41
+
42
+ # Use complex arithmetic. Negative square roots are reduced to i*square
43
+ # root of the positive part. The complex infinity is used rather than the
44
+ # positive and negative real infinities.
45
+ :complex_arithmetic => true,
46
+
47
+ # Override inspect for value objects. This makes expression dumps more
48
+ # readable, but less precise.
49
+ :inspect_to_s => true,
50
+
51
+ # Biggest factorial that we calculate to a value
52
+ :max_calculated_factorial => 100,
53
+ }
54
+
55
+ # Note: No type checking here, although the library code expects the various
56
+ # parameters to be of specific types (boolean, string, etc.). Failure and/or
57
+ # strange behaviour must be expected if they are set to different types.
58
+ def self.setting(name, value = nil)
59
+ name = name.to_sym
60
+ if !@@global_settings.key?(name)
61
+ raise "Setting #{name} does not exist"
62
+ end
63
+
64
+ if !value.nil?
65
+ @@global_settings[name] = value
66
+ end
67
+
68
+ return @@global_settings[name]
69
+ end
70
+
71
+ def self.settings()
72
+ return @@global_settings
73
+ end
74
+
75
+ @@special_variables = {
76
+ :basis.to_m => 1,
77
+ :g.to_m => 1,
78
+ }
79
+
80
+ @@variable_assignments = {
81
+ # Some variables with special meanings
82
+
83
+ # Row matrix of variable names used as the coordinates in differential
84
+ # geometry analyses. These define the dimension of the manifold, and
85
+ # also as the default names of the basis vectors and co-vectors of the
86
+ # tangent space.
87
+ :basis.to_m => [:x1, :x2, :x3].to_m,
88
+
89
+ # Metric tensor, relative to the chosen basis (subscript indexes)
90
+ :g.to_m => [[1, 0, 0],
91
+ [0, 1, 0],
92
+ [0, 0, 1]].to_m,
93
+ }
94
+
95
+ def self.define_equation(exp1, exp2)
96
+ return SyMath::Equation.new(exp1, exp2)
97
+ end
98
+
99
+ def self.get_variables()
100
+ return @@variable_assignments
101
+ end
102
+
103
+ def self.get_variable(var)
104
+ return @@variable_assignments[var.to_m]
105
+ end
106
+
107
+ def self.assign_variable(var, value)
108
+ var = var.to_m
109
+ value = value.to_m
110
+
111
+ # Check that name is a variable
112
+ if !var.is_a?(SyMath::Definition::Variable)
113
+ raise "#{var} is not a variable"
114
+ end
115
+
116
+ if !value.is_a?(SyMath::Value)
117
+ raise "#{value} is not a SyMath::Value"
118
+ end
119
+
120
+ @@variable_assignments[var] = value
121
+
122
+ # Re-calculate basis vectors if the basis or the metric tensor
123
+ # changes
124
+ if var.name.to_sym == :g or var.name.to_sym == :basis
125
+ SyMath::Definition::Variable.recalc_basis_vectors
126
+ end
127
+ end
128
+
129
+ def self.set_metric(g, basis = nil)
130
+ @@variable_assignments[:g.to_m] = g
131
+ if !basis.nil?
132
+ @@variable_assignments[:basis.to_m] = basis
133
+ end
134
+
135
+ SyMath::Definition::Variable.recalc_basis_vectors
136
+ end
137
+
138
+ def self.clear_variable(var)
139
+ @@variable_assignments.delete(var.to_m)
140
+ end
141
+
142
+ @@parser = SyMath::Parser.new
143
+
144
+ def self.parse(str)
145
+ return @@parser.parse(str)
146
+ end
147
+
148
+ # Initialize various static data used by the operation
149
+ # modules.
150
+ SyMath::Definition.init_builtin
151
+ SyMath::Definition::Trig.initialize
152
+ SyMath::Operation::Differential.initialize
153
+ SyMath::Operation::Integration.initialize
154
+
155
+ # Calculate basis vectors on startup
156
+ SyMath::Definition::Variable.recalc_basis_vectors
157
+ end
data/symath.gemspec ADDED
@@ -0,0 +1,39 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "symath/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "symath"
8
+ spec.version = SyMath::VERSION
9
+ spec.authors = ["erikoest"]
10
+ spec.email = ["erik.ostlyngen@norid.no"]
11
+
12
+ spec.summary = "Rudimentary symbolic math library"
13
+ spec.license = "MIT"
14
+
15
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
16
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
17
+ if spec.respond_to?(:metadata)
18
+ spec.metadata["allowed_push_host"] = 'https://rubygems.org'
19
+
20
+ spec.metadata["source_code_uri"] = "https://github.com/erikoest/symath"
21
+ # spec.metadata["changelog_uri"] = ""
22
+ else
23
+ raise "RubyGems 2.0 or newer is required to protect against " \
24
+ "public gem pushes."
25
+ end
26
+
27
+ # Specify which files should be added to the gem when it is released.
28
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
29
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
30
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
31
+ end
32
+ spec.bindir = "exe"
33
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
34
+ spec.require_paths = ["lib"]
35
+
36
+ spec.add_development_dependency "bundler", "~> 2.0"
37
+ spec.add_development_dependency "rake", ">= 10.0"
38
+ spec.add_development_dependency "rspec", "~> 3.0"
39
+ end
metadata ADDED
@@ -0,0 +1,160 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: symath
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - erikoest
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-11-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description:
56
+ email:
57
+ - erik.ostlyngen@norid.no
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - CODE_OF_CONDUCT.md
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bin/console
71
+ - bin/setup
72
+ - lib/symath.rb
73
+ - lib/symath/definition.rb
74
+ - lib/symath/definition/abs.rb
75
+ - lib/symath/definition/arccos.rb
76
+ - lib/symath/definition/arccot.rb
77
+ - lib/symath/definition/arccsc.rb
78
+ - lib/symath/definition/arcsec.rb
79
+ - lib/symath/definition/arcsin.rb
80
+ - lib/symath/definition/arctan.rb
81
+ - lib/symath/definition/bounds.rb
82
+ - lib/symath/definition/codiff.rb
83
+ - lib/symath/definition/constant.rb
84
+ - lib/symath/definition/cos.rb
85
+ - lib/symath/definition/cot.rb
86
+ - lib/symath/definition/csc.rb
87
+ - lib/symath/definition/curl.rb
88
+ - lib/symath/definition/d.rb
89
+ - lib/symath/definition/div.rb
90
+ - lib/symath/definition/exp.rb
91
+ - lib/symath/definition/fact.rb
92
+ - lib/symath/definition/flat.rb
93
+ - lib/symath/definition/function.rb
94
+ - lib/symath/definition/grad.rb
95
+ - lib/symath/definition/hodge.rb
96
+ - lib/symath/definition/int.rb
97
+ - lib/symath/definition/laplacian.rb
98
+ - lib/symath/definition/lmd.rb
99
+ - lib/symath/definition/ln.rb
100
+ - lib/symath/definition/number.rb
101
+ - lib/symath/definition/operator.rb
102
+ - lib/symath/definition/sec.rb
103
+ - lib/symath/definition/sharp.rb
104
+ - lib/symath/definition/sin.rb
105
+ - lib/symath/definition/sqrt.rb
106
+ - lib/symath/definition/tan.rb
107
+ - lib/symath/definition/trig.rb
108
+ - lib/symath/definition/variable.rb
109
+ - lib/symath/definition/xd.rb
110
+ - lib/symath/equation.rb
111
+ - lib/symath/fraction.rb
112
+ - lib/symath/matrix.rb
113
+ - lib/symath/minus.rb
114
+ - lib/symath/operation.rb
115
+ - lib/symath/operation/differential.rb
116
+ - lib/symath/operation/distributivelaw.rb
117
+ - lib/symath/operation/exterior.rb
118
+ - lib/symath/operation/integration.rb
119
+ - lib/symath/operation/match.rb
120
+ - lib/symath/operation/normalization.rb
121
+ - lib/symath/operator.rb
122
+ - lib/symath/parser.rb
123
+ - lib/symath/parser.y
124
+ - lib/symath/poly.rb
125
+ - lib/symath/poly/dup.rb
126
+ - lib/symath/poly/galois.rb
127
+ - lib/symath/power.rb
128
+ - lib/symath/product.rb
129
+ - lib/symath/sum.rb
130
+ - lib/symath/type.rb
131
+ - lib/symath/value.rb
132
+ - lib/symath/version.rb
133
+ - lib/symath/wedge.rb
134
+ - symath.gemspec
135
+ homepage:
136
+ licenses:
137
+ - MIT
138
+ metadata:
139
+ allowed_push_host: https://rubygems.org
140
+ source_code_uri: https://github.com/erikoest/symath
141
+ post_install_message:
142
+ rdoc_options: []
143
+ require_paths:
144
+ - lib
145
+ required_ruby_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ requirements: []
156
+ rubygems_version: 3.1.2
157
+ signing_key:
158
+ specification_version: 4
159
+ summary: Rudimentary symbolic math library
160
+ test_files: []