plurimath 0.11.16 → 0.11.18

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 (189) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/dependent-tests.yml +2 -2
  3. data/.github/workflows/docs.yml +26 -0
  4. data/.github/workflows/gum-reference.yml +48 -0
  5. data/.github/workflows/performance-ci-legs.yml +54 -0
  6. data/.github/workflows/performance.yml +99 -0
  7. data/.github/workflows/roundtrip-cases.yml +33 -0
  8. data/.rubocop_todo.yml +0 -138
  9. data/Gemfile +13 -0
  10. data/Rakefile +2 -0
  11. data/docs/asciimath.adoc +578 -0
  12. data/docs/core-model-contract.adoc +748 -0
  13. data/docs/gum-evaluation.adoc +368 -0
  14. data/docs/latex.adoc +335 -0
  15. data/docs/mathml.adoc +638 -0
  16. data/docs/native-evaluation-request.md +28 -0
  17. data/docs/numeric-request.md +19 -0
  18. data/docs/omml.adoc +589 -0
  19. data/docs/performance-contract.adoc +279 -0
  20. data/docs/pma.adoc +949 -0
  21. data/docs/quantity-request.md +19 -0
  22. data/docs/uncertainty-asciimath-tree.md +2 -3
  23. data/docs/uncertainty.adoc +401 -425
  24. data/docs/unicodemath.adoc +453 -0
  25. data/docs/unitsml.adoc +414 -0
  26. data/lib/plurimath/asciimath/constants.rb +0 -98
  27. data/lib/plurimath/asciimath/mapper/rules.rb +1400 -0
  28. data/lib/plurimath/asciimath/mapper.rb +148 -0
  29. data/lib/plurimath/asciimath/parse.rb +26 -18
  30. data/lib/plurimath/asciimath/parser.rb +25 -11
  31. data/lib/plurimath/asciimath/slice_adapter.rb +1 -1
  32. data/lib/plurimath/asciimath.rb +1 -1
  33. data/lib/plurimath/catalog.rb +4 -5
  34. data/lib/plurimath/cli/convert.rb +3 -2
  35. data/lib/plurimath/cli.rb +2 -1
  36. data/lib/plurimath/configuration.rb +3 -0
  37. data/lib/plurimath/evaluation_request/quantity.rb +254 -0
  38. data/lib/plurimath/evaluation_request.rb +160 -0
  39. data/lib/plurimath/latex/constants.rb +0 -84
  40. data/lib/plurimath/latex/mapper.rb +418 -0
  41. data/lib/plurimath/latex/parse.rb +28 -288
  42. data/lib/plurimath/latex/parser.rb +49 -4
  43. data/lib/plurimath/latex.rb +1 -1
  44. data/lib/plurimath/math/core.rb +266 -1
  45. data/lib/plurimath/math/evaluation/accuracy.rb +62 -0
  46. data/lib/plurimath/math/evaluation/calibration.rb +85 -0
  47. data/lib/plurimath/math/evaluation/compiled_polynomial.rb +99 -0
  48. data/lib/plurimath/math/evaluation/compiled_rational.rb +131 -0
  49. data/lib/plurimath/math/evaluation/conformity.rb +133 -0
  50. data/lib/plurimath/math/evaluation/correlated_normal_sampler.rb +74 -0
  51. data/lib/plurimath/math/evaluation/covariance.rb +173 -0
  52. data/lib/plurimath/math/evaluation/distribution_sampler.rb +126 -0
  53. data/lib/plurimath/math/evaluation/evaluator.rb +236 -22
  54. data/lib/plurimath/math/evaluation/grouped_statistics.rb +56 -0
  55. data/lib/plurimath/math/evaluation/gum.rb +410 -0
  56. data/lib/plurimath/math/evaluation/implicit_model.rb +66 -0
  57. data/lib/plurimath/math/evaluation/monte_carlo.rb +198 -0
  58. data/lib/plurimath/math/evaluation/quantity_evaluator.rb +127 -0
  59. data/lib/plurimath/math/evaluation/result.rb +45 -0
  60. data/lib/plurimath/math/evaluation/statistics.rb +102 -0
  61. data/lib/plurimath/math/evaluation/taylor.rb +162 -0
  62. data/lib/plurimath/math/evaluation/wichmann_hill.rb +40 -0
  63. data/lib/plurimath/math/evaluation.rb +22 -0
  64. data/lib/plurimath/math/formula/mrow.rb +6 -1
  65. data/lib/plurimath/math/formula.rb +22 -4
  66. data/lib/plurimath/math/function/abs.rb +3 -1
  67. data/lib/plurimath/math/function/arccos.rb +1 -1
  68. data/lib/plurimath/math/function/arcsin.rb +1 -1
  69. data/lib/plurimath/math/function/arctan.rb +1 -1
  70. data/lib/plurimath/math/function/bar.rb +2 -1
  71. data/lib/plurimath/math/function/base.rb +2 -1
  72. data/lib/plurimath/math/function/binary_function.rb +1 -1
  73. data/lib/plurimath/math/function/ceil.rb +3 -1
  74. data/lib/plurimath/math/function/color.rb +2 -1
  75. data/lib/plurimath/math/function/cos.rb +1 -1
  76. data/lib/plurimath/math/function/cosh.rb +1 -1
  77. data/lib/plurimath/math/function/cot.rb +1 -1
  78. data/lib/plurimath/math/function/coth.rb +1 -1
  79. data/lib/plurimath/math/function/csc.rb +1 -1
  80. data/lib/plurimath/math/function/csch.rb +1 -1
  81. data/lib/plurimath/math/function/ddot.rb +2 -1
  82. data/lib/plurimath/math/function/dot.rb +2 -1
  83. data/lib/plurimath/math/function/exp.rb +1 -1
  84. data/lib/plurimath/math/function/fenced.rb +5 -3
  85. data/lib/plurimath/math/function/floor.rb +3 -1
  86. data/lib/plurimath/math/function/font_style/bold.rb +1 -1
  87. data/lib/plurimath/math/function/font_style/double_struck.rb +1 -1
  88. data/lib/plurimath/math/function/font_style/fraktur.rb +1 -1
  89. data/lib/plurimath/math/function/font_style/italic.rb +1 -1
  90. data/lib/plurimath/math/function/font_style/monospace.rb +1 -1
  91. data/lib/plurimath/math/function/font_style/normal.rb +22 -1
  92. data/lib/plurimath/math/function/font_style/sans-serif.rb +1 -1
  93. data/lib/plurimath/math/function/font_style/script.rb +1 -1
  94. data/lib/plurimath/math/function/frac.rb +2 -1
  95. data/lib/plurimath/math/function/hat.rb +2 -1
  96. data/lib/plurimath/math/function/int.rb +3 -2
  97. data/lib/plurimath/math/function/lg.rb +1 -1
  98. data/lib/plurimath/math/function/linebreak.rb +2 -1
  99. data/lib/plurimath/math/function/ln.rb +1 -1
  100. data/lib/plurimath/math/function/log.rb +4 -1
  101. data/lib/plurimath/math/function/longdiv.rb +3 -0
  102. data/lib/plurimath/math/function/mpadded.rb +2 -1
  103. data/lib/plurimath/math/function/msgroup.rb +3 -0
  104. data/lib/plurimath/math/function/multiscript.rb +4 -0
  105. data/lib/plurimath/math/function/nary.rb +9 -3
  106. data/lib/plurimath/math/function/norm.rb +3 -1
  107. data/lib/plurimath/math/function/obrace.rb +2 -1
  108. data/lib/plurimath/math/function/oint.rb +3 -2
  109. data/lib/plurimath/math/function/overleftrightarrow.rb +2 -1
  110. data/lib/plurimath/math/function/overset.rb +2 -1
  111. data/lib/plurimath/math/function/power.rb +1 -1
  112. data/lib/plurimath/math/function/power_base.rb +1 -1
  113. data/lib/plurimath/math/function/prod.rb +3 -2
  114. data/lib/plurimath/math/function/sec.rb +1 -1
  115. data/lib/plurimath/math/function/sech.rb +1 -1
  116. data/lib/plurimath/math/function/semantics.rb +35 -0
  117. data/lib/plurimath/math/function/sin.rb +1 -1
  118. data/lib/plurimath/math/function/sinh.rb +1 -1
  119. data/lib/plurimath/math/function/sqrt.rb +3 -2
  120. data/lib/plurimath/math/function/sum.rb +3 -2
  121. data/lib/plurimath/math/function/table/align.rb +1 -1
  122. data/lib/plurimath/math/function/table/bmatrix.rb +1 -1
  123. data/lib/plurimath/math/function/table/cases.rb +4 -0
  124. data/lib/plurimath/math/function/table/multline.rb +1 -1
  125. data/lib/plurimath/math/function/table/pmatrix.rb +1 -1
  126. data/lib/plurimath/math/function/table/split.rb +1 -1
  127. data/lib/plurimath/math/function/table/vmatrix.rb +1 -1
  128. data/lib/plurimath/math/function/table.rb +19 -2
  129. data/lib/plurimath/math/function/tan.rb +1 -1
  130. data/lib/plurimath/math/function/tanh.rb +1 -1
  131. data/lib/plurimath/math/function/td.rb +4 -0
  132. data/lib/plurimath/math/function/ternary_function.rb +2 -2
  133. data/lib/plurimath/math/function/text.rb +3 -0
  134. data/lib/plurimath/math/function/tilde.rb +2 -1
  135. data/lib/plurimath/math/function/tr.rb +3 -0
  136. data/lib/plurimath/math/function/ubrace.rb +2 -1
  137. data/lib/plurimath/math/function/ul.rb +2 -1
  138. data/lib/plurimath/math/function/unary_function.rb +1 -1
  139. data/lib/plurimath/math/function/uncertainty.rb +26 -11
  140. data/lib/plurimath/math/function/underset.rb +2 -1
  141. data/lib/plurimath/math/function/unitsml.rb +18 -6
  142. data/lib/plurimath/math/function/vec.rb +2 -1
  143. data/lib/plurimath/math/number.rb +30 -12
  144. data/lib/plurimath/math/symbol_index.rb +10254 -0
  145. data/lib/plurimath/math/symbol_table.rb +89 -0
  146. data/lib/plurimath/math/symbols/paren.rb +7 -0
  147. data/lib/plurimath/math/symbols/symbol.rb +30 -3
  148. data/lib/plurimath/math/symbols.rb +81 -5
  149. data/lib/plurimath/math.rb +8 -0
  150. data/lib/plurimath/mathml/parser.rb +2 -0
  151. data/lib/plurimath/mathml/translator.rb +17 -3
  152. data/lib/plurimath/native_kernel.rb +64 -0
  153. data/lib/plurimath/omml/parser.rb +1 -0
  154. data/lib/plurimath/omml/translator.rb +2 -1
  155. data/lib/plurimath/pma.rb +19 -0
  156. data/lib/plurimath/unicode_math/constants.rb +0 -258
  157. data/lib/plurimath/unicode_math/mapper/capture_order.rb +142 -0
  158. data/lib/plurimath/unicode_math/mapper/rules.rb +4086 -0
  159. data/lib/plurimath/unicode_math/mapper.rb +146 -0
  160. data/lib/plurimath/unicode_math/parse.rb +54 -294
  161. data/lib/plurimath/unicode_math/parser.rb +71 -2
  162. data/lib/plurimath/unicode_math.rb +1 -2
  163. data/lib/plurimath/unitsml.rb +0 -1
  164. data/lib/plurimath/utility.rb +34 -12
  165. data/lib/plurimath/version.rb +1 -1
  166. data/lib/plurimath.rb +42 -3
  167. data/plurimath.gemspec +3 -1
  168. data/scripts/check_gum_references.rb +69 -0
  169. data/scripts/check_suite_budget.rb +329 -0
  170. data/scripts/docs/asciimath_tables.rb +363 -0
  171. data/scripts/docs/core_inventory.rb +432 -0
  172. data/scripts/docs/format_specs.rb +672 -0
  173. data/scripts/generate_symbol_index.rb +118 -0
  174. data/scripts/measure_require.rb +362 -0
  175. data/scripts/replay_asciimath_corpus.rb +7 -7
  176. data/scripts/replay_stage_roundtrips.rb +242 -0
  177. data/scripts/require_baseline.json +34 -0
  178. data/scripts/roundtrip_cases.rb +462 -0
  179. metadata +97 -16
  180. data/lib/plurimath/asciimath/transform.rb +0 -1395
  181. data/lib/plurimath/latex/transform.rb +0 -1006
  182. data/lib/plurimath/unicode_math/parsing_rules/absence_rules.rb +0 -150
  183. data/lib/plurimath/unicode_math/parsing_rules/common_rules.rb +0 -136
  184. data/lib/plurimath/unicode_math/parsing_rules/constants_rules.rb +0 -136
  185. data/lib/plurimath/unicode_math/parsing_rules/helper.rb +0 -13
  186. data/lib/plurimath/unicode_math/parsing_rules/masked.rb +0 -84
  187. data/lib/plurimath/unicode_math/parsing_rules/sub_sup.rb +0 -281
  188. data/lib/plurimath/unicode_math/parsing_rules.rb +0 -14
  189. data/lib/plurimath/unicode_math/transform.rb +0 -4058
@@ -1,1006 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Plurimath
4
- class Latex
5
- class Transform < Parsanol::Transform
6
- include Plurimath::BaseNumberPrefix::Transform
7
-
8
- rule(base: simple(:base)) { base }
9
- rule(over: simple(:over)) { over }
10
- rule(number: simple(:num)) { Math::Number.new(Utility.html_entity_to_unicode(num.to_s)) }
11
- rule(power: simple(:power)) { power }
12
- rule(unary: simple(:unary)) { Utility.get_class(unary).new }
13
- rule(space: simple(:space)) { Math::Function::Text.new(" ") }
14
- rule(operant: simple(:oper)) do
15
- Utility.symbols_class(oper, lang: :latex)
16
- end
17
- rule(symbol: simple(:symbol)) do
18
- Utility.symbols_class(symbol, lang: :latex)
19
- end
20
- rule(lparen: simple(:lparen)) do
21
- Utility.symbols_class(lparen, lang: :latex)
22
- end
23
- rule(rparen: simple(:rparen)) do
24
- Utility.symbols_class(rparen, lang: :latex)
25
- end
26
- rule(limits: simple(:limits)) { limits }
27
- rule("\\\\" => simple(:slash)) { Math::Function::Linebreak.new }
28
- # Native named captures use symbol keys; Ruby retains the declared string.
29
- rule("\\\\": simple(:slash)) { Math::Function::Linebreak.new }
30
- rule(expression: simple(:expr)) { expr }
31
- rule(environment: simple(:env)) { env }
32
- rule(ternary: simple(:ternary)) { Utility.get_class(ternary).new }
33
-
34
- rule(unary_functions: simple(:unary)) { unary }
35
- rule(ternary_class: simple(:ternary)) { ternary }
36
- rule(left_right: simple(:left_right)) { left_right }
37
- rule(under_over: simple(:under_over)) { under_over }
38
- rule(power_base: simple(:power_base)) { power_base }
39
- rule(table_data: simple(:table_data)) { table_data }
40
- rule(three_per_em_space: simple(:space)) { Math::Symbols::ThreePerEmSpace.new }
41
-
42
- rule(intermediate_exp: simple(:int_exp)) { int_exp }
43
-
44
- rule(numeric_values: simple(:value)) do
45
- Utility.symbols_class(value, lang: :latex)
46
- end
47
-
48
- rule(text: simple(:text)) do
49
- Math::Function::Text.new(text)
50
- end
51
-
52
- rule(unicode_symbols: simple(:unicode)) do
53
- Utility.symbols_class(unicode, lang: :latex)
54
- end
55
-
56
- rule(binary: simple(:binary)) do
57
- binary.is_a?(Parsanol::Slice) ? Utility.get_class(binary).new : binary
58
- end
59
-
60
- rule(symbols: simple(:sym)) do
61
- Utility.symbols_class(sym, lang: :latex)
62
- end
63
-
64
- rule(lparen: simple(:lparen),
65
- rparen: simple(:rparen)) do
66
- []
67
- end
68
-
69
- rule(left_right: simple(:left_right),
70
- subscript: simple(:subscript)) do
71
- Math::Function::Base.new(
72
- left_right,
73
- subscript,
74
- )
75
- end
76
-
77
- rule(left_right: simple(:left_right),
78
- supscript: simple(:supscript)) do
79
- Math::Function::Power.new(
80
- left_right,
81
- supscript,
82
- )
83
- end
84
-
85
- rule(left: simple(:left),
86
- left_paren: simple(:lparen),
87
- expression: sequence(:expr),
88
- right: simple(:right),
89
- right_paren: simple(:rparen)) do
90
- Math::Formula.new(
91
- [
92
- Utility.left_right_objects(lparen, "left"),
93
- Math::Formula.new(expr),
94
- Utility.left_right_objects(rparen, "right"),
95
- ],
96
- )
97
- end
98
-
99
- rule(left: simple(:left),
100
- left_paren: simple(:lparen),
101
- expression: sequence(:expr),
102
- right: simple(:right)) do
103
- Math::Formula.new(
104
- [
105
- Utility.left_right_objects(lparen, "left"),
106
- Math::Formula.new(expr),
107
- Math::Function::Right.new,
108
- ],
109
- )
110
- end
111
-
112
- rule(left: simple(:left),
113
- left_paren: simple(:lparen),
114
- expression: simple(:expr),
115
- right: simple(:right)) do
116
- Math::Formula.new(
117
- [
118
- Utility.left_right_objects(lparen, "left"),
119
- expr,
120
- Math::Function::Right.new,
121
- ],
122
- )
123
- end
124
-
125
- rule(left: simple(:left),
126
- left_paren: simple(:lparen),
127
- right: simple(:right)) do
128
- Math::Formula.new(
129
- [
130
- Utility.left_right_objects(lparen, "left"),
131
- Math::Function::Right.new,
132
- ],
133
- )
134
- end
135
-
136
- rule(left: simple(:left),
137
- left_paren: simple(:lparen),
138
- right: simple(:right),
139
- right_paren: simple(:rparen)) do
140
- Math::Formula.new(
141
- [
142
- Utility.left_right_objects(lparen, "left"),
143
- Utility.left_right_objects(rparen, "right"),
144
- ],
145
- )
146
- end
147
-
148
- rule(left: simple(:left),
149
- left_paren: simple(:lparen)) do
150
- Utility.left_right_objects(lparen, "left")
151
- end
152
-
153
- rule(left: simple(:left),
154
- left_paren: simple(:lparen),
155
- expression: simple(:expr),
156
- right: simple(:right),
157
- right_paren: simple(:rparen)) do
158
- Math::Formula.new(
159
- [
160
- Utility.left_right_objects(lparen, "left"),
161
- expr,
162
- Utility.left_right_objects(rparen, "right"),
163
- ],
164
- )
165
- end
166
-
167
- rule(left: simple(:left),
168
- expression: simple(:expr),
169
- right: simple(:right)) do
170
- Math::Formula.new(
171
- [
172
- Math::Function::Left.new,
173
- expr,
174
- Math::Function::Right.new,
175
- ],
176
- )
177
- end
178
-
179
- rule(left: simple(:left),
180
- expression: sequence(:expr),
181
- right: simple(:right)) do
182
- Math::Formula.new(
183
- [
184
- Math::Function::Left.new,
185
- Math::Formula.new(expr),
186
- Math::Function::Right.new,
187
- ],
188
- )
189
- end
190
-
191
- rule(power: simple(:power),
192
- number: simple(:number)) do
193
- Math::Function::Power.new(
194
- power,
195
- Math::Number.new(Utility.html_entity_to_unicode(number.to_s)),
196
- )
197
- end
198
-
199
- rule(power: simple(:power),
200
- symbols: simple(:sym)) do
201
- Math::Function::Power.new(
202
- power,
203
- Utility.symbols_class(sym, lang: :latex),
204
- )
205
- end
206
-
207
- rule(power: simple(:power),
208
- expression: simple(:expr)) do
209
- Math::Function::Power.new(
210
- power,
211
- expr,
212
- )
213
- end
214
-
215
- rule(base: simple(:base),
216
- expression: simple(:expr)) do
217
- Math::Function::Base.new(
218
- base,
219
- expr,
220
- )
221
- end
222
-
223
- rule(base: simple(:base),
224
- expression: sequence(:expr)) do
225
- Math::Function::Base.new(
226
- base,
227
- Utility.filter_values(expr),
228
- )
229
- end
230
-
231
- rule(power: simple(:power),
232
- expression: sequence(:expr)) do
233
- Math::Function::Power.new(
234
- power,
235
- Utility.filter_values(expr),
236
- )
237
- end
238
-
239
- rule(left: simple(:left),
240
- left_paren: simple(:lparen),
241
- dividend: subtree(:dividend),
242
- divisor: subtree(:divisor),
243
- right: simple(:right),
244
- right_paren: simple(:rparen)) do
245
- Math::Formula.new(
246
- [
247
- Utility.left_right_objects(lparen, "left"),
248
- Math::Function::Over.new(
249
- Math::Formula.new(
250
- Array(dividend).flatten,
251
- ),
252
- Math::Formula.new(
253
- Array(divisor).flatten,
254
- ),
255
- ),
256
- Utility.left_right_objects(rparen, "right"),
257
- ],
258
- )
259
- end
260
-
261
- rule(dividend: subtree(:dividend),
262
- divisor: subtree(:divisor)) do
263
- Math::Function::Over.new(
264
- Math::Formula.new(
265
- Array(dividend).flatten,
266
- ),
267
- Math::Formula.new(
268
- Array(divisor).flatten,
269
- ),
270
- )
271
- end
272
-
273
- rule(over: simple(:over),
274
- subscript: simple(:subscript)) do
275
- Math::Function::Base.new(
276
- over,
277
- subscript,
278
- )
279
- end
280
-
281
- rule(over: simple(:over),
282
- supscript: simple(:supscript)) do
283
- Math::Function::Power.new(
284
- over,
285
- supscript,
286
- )
287
- end
288
-
289
- rule(operant: simple(:operant),
290
- subscript: simple(:subscript)) do
291
- Math::Function::Base.new(
292
- Utility.symbols_class(operant, lang: :latex),
293
- subscript,
294
- )
295
- end
296
-
297
- rule(operant: simple(:operant),
298
- supscript: simple(:supscript)) do
299
- Math::Function::Power.new(
300
- Utility.symbols_class(operant, lang: :latex),
301
- supscript,
302
- )
303
- end
304
-
305
- rule(sequence: simple(:sequence),
306
- expression: simple(:expr)) do
307
- if sequence.is_a?(Math::Function::PowerBase) && sequence.parameter_one.is_nary_symbol?
308
- Math::Function::Nary.new(
309
- sequence.parameter_one,
310
- sequence.parameter_two,
311
- sequence.parameter_three,
312
- expr,
313
- )
314
- else
315
- [sequence, expr].compact
316
- end
317
- end
318
-
319
- rule(sequence: simple(:sequence),
320
- expression: sequence(:expr)) do
321
- if sequence.is_a?(Math::Function::PowerBase) && sequence.parameter_one.is_nary_symbol?
322
- Math::Function::Nary.new(
323
- sequence.parameter_one,
324
- sequence.parameter_two,
325
- sequence.parameter_three,
326
- Utility.filter_values(expr),
327
- )
328
- else
329
- [sequence] + expr
330
- end
331
- end
332
-
333
- rule(unary_functions: simple(:unary),
334
- subscript: simple(:subscript)) do
335
- unary_function = if unary.is_a?(Parsanol::Slice)
336
- Utility.get_class(unary).new
337
- else
338
- unary
339
- end
340
- Math::Function::Base.new(
341
- unary_function,
342
- subscript,
343
- )
344
- end
345
-
346
- rule(binary_functions: simple(:binary),
347
- supscript: simple(:supscript)) do
348
- Math::Function::Power.new(
349
- binary,
350
- supscript,
351
- )
352
- end
353
-
354
- rule(ternary_functions: simple(:ternary),
355
- subscript: simple(:subscript)) do
356
- Utility.get_class(ternary).new(subscript)
357
- end
358
-
359
- rule(unary_functions: simple(:unary),
360
- supscript: simple(:supscript)) do
361
- unary_function = if unary.is_a?(Parsanol::Slice)
362
- Utility.get_class(unary).new
363
- else
364
- unary
365
- end
366
- Math::Function::Power.new(
367
- unary_function,
368
- supscript,
369
- )
370
- end
371
-
372
- rule(ternary_functions: simple(:ternary),
373
- subscript: simple(:subscript),
374
- third_value: simple(:third_value)) do
375
- Utility.get_class(ternary).new(
376
- subscript,
377
- nil,
378
- third_value,
379
- )
380
- end
381
-
382
- rule(ternary_functions: simple(:ternary),
383
- subscript: simple(:subscript),
384
- supscript: simple(:supscript)) do
385
- Utility.get_class(ternary).new(
386
- subscript,
387
- supscript,
388
- )
389
- end
390
-
391
- rule(unary_functions: simple(:unary),
392
- subscript: simple(:subscript),
393
- supscript: simple(:supscript)) do
394
- unary_function = if unary.is_a?(Parsanol::Slice)
395
- Utility.get_class(unary).new
396
- else
397
- unary
398
- end
399
- Math::Function::PowerBase.new(
400
- unary_function,
401
- subscript,
402
- supscript,
403
- )
404
- end
405
-
406
- rule(ternary_functions: simple(:ternary),
407
- subscript: simple(:subscript),
408
- supscript: simple(:supscript),
409
- third_value: simple(:third_value)) do
410
- Utility.get_class(ternary).new(
411
- subscript,
412
- supscript,
413
- third_value,
414
- )
415
- end
416
-
417
- rule(fonts: simple(:fonts),
418
- intermediate_exp: simple(:int_exp)) do
419
- if Utility::FONT_STYLES[fonts.to_sym]
420
- Utility::FONT_STYLES[fonts.to_sym].new(
421
- int_exp,
422
- fonts.to_s,
423
- )
424
- else
425
- Math::Function::FontStyle.new(
426
- int_exp,
427
- fonts.to_s,
428
- )
429
- end
430
- end
431
-
432
- rule(number: simple(:number),
433
- subscript: simple(:subscript)) do
434
- Math::Function::Base.new(
435
- Math::Number.new(Utility.html_entity_to_unicode(number.to_s)),
436
- subscript,
437
- )
438
- end
439
-
440
- rule(number: simple(:number),
441
- supscript: simple(:supscript)) do
442
- Math::Function::Power.new(
443
- Math::Number.new(Utility.html_entity_to_unicode(number.to_s)),
444
- supscript,
445
- )
446
- end
447
-
448
- rule(number: simple(:number),
449
- subscript: simple(:subscript),
450
- supscript: simple(:supscript)) do
451
- Math::Function::PowerBase.new(
452
- Math::Number.new(Utility.html_entity_to_unicode(number.to_s)),
453
- subscript,
454
- supscript,
455
- )
456
- end
457
-
458
- rule(symbols: simple(:sym),
459
- subscript: simple(:subscript)) do
460
- Math::Function::Base.new(
461
- Utility.symbols_class(sym, lang: :latex),
462
- subscript,
463
- )
464
- end
465
-
466
- rule(numeric_values: simple(:value),
467
- subscript: simple(:subscript)) do
468
- Math::Function::Base.new(
469
- Utility.symbols_class(value, lang: :latex),
470
- subscript,
471
- )
472
- end
473
-
474
- rule(symbols: simple(:sym),
475
- supscript: simple(:supscript)) do
476
- Math::Function::Power.new(
477
- Utility.symbols_class(sym, lang: :latex),
478
- supscript,
479
- )
480
- end
481
-
482
- rule(intermediate_exp: simple(:int_exp),
483
- supscript: simple(:supscript)) do
484
- Math::Function::Power.new(
485
- int_exp,
486
- supscript,
487
- )
488
- end
489
-
490
- rule(intermediate_exp: simple(:int_exp),
491
- subscript: simple(:subscript)) do
492
- Math::Function::Base.new(
493
- int_exp,
494
- subscript,
495
- )
496
- end
497
-
498
- rule(unicode_symbols: simple(:sym),
499
- subscript: simple(:subscript)) do
500
- Math::Function::Base.new(
501
- Utility.symbols_class(sym, lang: :latex),
502
- subscript,
503
- )
504
- end
505
-
506
- rule(unicode_symbols: simple(:sym),
507
- supscript: simple(:supscript)) do
508
- Math::Function::Power.new(
509
- Utility.symbols_class(sym, lang: :latex),
510
- supscript,
511
- )
512
- end
513
-
514
- rule(numeric_values: simple(:value),
515
- supscript: simple(:supscript)) do
516
- Math::Function::Power.new(
517
- Utility.symbols_class(value, lang: :latex),
518
- supscript,
519
- )
520
- end
521
-
522
- rule(text: simple(:text),
523
- first_value: simple(:first_value)) do
524
- Utility.get_class(text).new(first_value)
525
- end
526
-
527
- rule(text: simple(:text),
528
- first_value: sequence(:first_value)) do
529
- Utility.get_class(text).new(first_value.join)
530
- end
531
-
532
- rule(text: simple(:text),
533
- first_value: simple(:first_value),
534
- supscript: simple(:supscript)) do
535
- Math::Function::Power.new(
536
- Utility.get_class(text).new(first_value),
537
- supscript,
538
- )
539
- end
540
-
541
- rule(text: simple(:text),
542
- first_value: sequence(:first_value),
543
- supscript: simple(:supscript)) do
544
- Math::Function::Power.new(
545
- Utility.get_class(text).new(first_value.join),
546
- supscript,
547
- )
548
- end
549
-
550
- rule(text: simple(:text),
551
- first_value: sequence(:first_value),
552
- subscript: simple(:subscript)) do
553
- Math::Function::Base.new(
554
- Utility.get_class(text).new(first_value.join),
555
- subscript,
556
- )
557
- end
558
-
559
- rule(text: simple(:text),
560
- first_value: simple(:first_value),
561
- subscript: simple(:subscript)) do
562
- Math::Function::Base.new(
563
- Utility.get_class(text).new(first_value),
564
- subscript,
565
- )
566
- end
567
-
568
- rule(text: simple(:text),
569
- first_value: simple(:first_value),
570
- subscript: simple(:subscript),
571
- supscript: simple(:supscript)) do
572
- Math::Function::PowerBase.new(
573
- Utility.get_class(text).new(first_value),
574
- subscript,
575
- supscript,
576
- )
577
- end
578
-
579
- rule(unary: simple(:unary),
580
- first_value: simple(:first_value)) do
581
- Utility.get_class(
582
- unary == "overline" ? "bar" : unary,
583
- ).new(first_value)
584
- end
585
-
586
- rule(sqrt: simple(:sqrt),
587
- intermediate_exp: simple(:int_exp)) do
588
- Math::Function::Sqrt.new(int_exp)
589
- end
590
-
591
- rule(fonts: simple(:fonts),
592
- intermediate_exp: simple(:int_exp),
593
- supscript: simple(:supscript)) do
594
- font_style = if Utility::FONT_STYLES[fonts.to_sym].nil?
595
- Math::Function::FontStyle.new(
596
- int_exp,
597
- fonts.to_s,
598
- )
599
- else
600
- Utility::FONT_STYLES[fonts.to_sym].new(
601
- int_exp,
602
- fonts.to_s,
603
- )
604
- end
605
- Math::Function::Power.new(
606
- font_style,
607
- supscript,
608
- )
609
- end
610
-
611
- rule(fonts: simple(:fonts),
612
- intermediate_exp: simple(:int_exp),
613
- subscript: simple(:subscript)) do
614
- font_style = if Utility::FONT_STYLES[fonts.to_sym].nil?
615
- Math::Function::FontStyle.new(
616
- int_exp,
617
- fonts.to_s,
618
- )
619
- else
620
- Utility::FONT_STYLES[fonts.to_sym].new(
621
- int_exp,
622
- fonts.to_s,
623
- )
624
- end
625
- Math::Function::Base.new(
626
- font_style,
627
- subscript,
628
- )
629
- end
630
-
631
- rule(fonts: simple(:fonts),
632
- intermediate_exp: simple(:int_exp),
633
- subscript: simple(:subscript),
634
- supscript: simple(:supscript)) do
635
- font_style = if Utility::FONT_STYLES[fonts.to_sym].nil?
636
- Math::Function::FontStyle.new(
637
- int_exp,
638
- fonts.to_s,
639
- )
640
- else
641
- Utility::FONT_STYLES[fonts.to_sym].new(
642
- int_exp,
643
- fonts.to_s,
644
- )
645
- end
646
- Math::Function::PowerBase.new(
647
- font_style,
648
- subscript,
649
- supscript,
650
- )
651
- end
652
-
653
- rule(root: simple(:root),
654
- first_value: simple(:first_value),
655
- second_value: simple(:second_value)) do
656
- second = second_value.nil? ? Math::Formula.new : second_value
657
- Math::Function::Root.new(
658
- first_value,
659
- second,
660
- )
661
- end
662
-
663
- rule(root: simple(:root),
664
- first_value: sequence(:first_value),
665
- second_value: simple(:second_value)) do
666
- first = Utility.filter_values(first_value)
667
- first = Math::Formula.new if first.nil?
668
- Math::Function::Root.new(
669
- first,
670
- second_value,
671
- )
672
- end
673
-
674
- rule(first_value: simple(:first_value),
675
- base: simple(:base),
676
- power: simple(:power)) do
677
- Math::Function::Limits.new(
678
- first_value,
679
- base,
680
- power,
681
- )
682
- end
683
-
684
- rule(lparen: simple(:lparen),
685
- expression: sequence(:expr),
686
- rparen: simple(:rparen)) do
687
- Math::Formula.new(expr)
688
- end
689
-
690
- rule(left_paren: simple(:lparen),
691
- expression: simple(:expr),
692
- right_paren: simple(:rparen)) do
693
- Math::Function::Fenced.new(
694
- Utility.symbols_class(lparen, lang: :latex),
695
- [expr],
696
- Utility.symbols_class(rparen, lang: :latex),
697
- )
698
- end
699
-
700
- rule(left_paren: simple(:lparen),
701
- expression: sequence(:expr),
702
- right_paren: simple(:rparen)) do
703
- Math::Function::Fenced.new(
704
- Utility.symbols_class(lparen, lang: :latex),
705
- expr,
706
- Utility.symbols_class(rparen, lang: :latex),
707
- )
708
- end
709
-
710
- rule(expression: sequence(:expr)) do
711
- Math::Formula.new(expr)
712
- end
713
-
714
- rule(rule: simple(:rule),
715
- first_value: simple(:first_value),
716
- second_value: simple(:second_value),
717
- third_value: simple(:third_value)) do
718
- Math::Function::Rule.new(
719
- first_value,
720
- second_value,
721
- third_value,
722
- )
723
- end
724
-
725
- rule(expression: simple(:expression),
726
- subscript: simple(:subscript)) do
727
- Math::Function::Base.new(
728
- expression,
729
- subscript,
730
- )
731
- end
732
-
733
- rule(expression: simple(:expr),
734
- supscript: simple(:supscript)) do
735
- Math::Function::Power.new(
736
- expr,
737
- supscript,
738
- )
739
- end
740
-
741
- rule(expression: sequence(:expr),
742
- supscript: simple(:supscript)) do
743
- Math::Function::Power.new(
744
- Utility.filter_values(expr),
745
- supscript,
746
- )
747
- end
748
-
749
- rule(binary: simple(:binary),
750
- subscript: simple(:subscript),
751
- supscript: simple(:supscript)) do
752
- Utility.get_class(binary).new(
753
- subscript,
754
- supscript,
755
- )
756
- end
757
-
758
- rule(binary: simple(:binary),
759
- subscript: simple(:subscript),
760
- supscript: simple(:supscript)) do
761
- if binary.is_a?(Parsanol::Slice)
762
- Utility.get_class(binary).new(
763
- subscript,
764
- supscript,
765
- )
766
- else
767
- Math::Function::PowerBase.new(
768
- binary,
769
- subscript,
770
- subscript,
771
- )
772
- end
773
- end
774
-
775
- rule(binary: simple(:binary),
776
- subscript: simple(:subscript)) do
777
- if binary.is_a?(Parsanol::Slice)
778
- Utility.get_class(binary).new(subscript)
779
- else
780
- Math::Function::Base.new(
781
- binary,
782
- subscript,
783
- )
784
- end
785
- end
786
-
787
- rule(symbols: simple(:sym),
788
- subscript: simple(:subscript),
789
- supscript: simple(:supscript)) do
790
- Math::Function::PowerBase.new(
791
- Utility.symbols_class(sym, lang: :latex),
792
- subscript,
793
- supscript,
794
- )
795
- end
796
-
797
- rule(unicode_symbols: simple(:sym),
798
- subscript: simple(:subscript),
799
- supscript: simple(:supscript)) do
800
- Math::Function::PowerBase.new(
801
- Utility.symbols_class(sym, lang: :latex),
802
- subscript,
803
- supscript,
804
- )
805
- end
806
-
807
- rule(binary: simple(:binary),
808
- first_value: simple(:first_value),
809
- second_value: simple(:second_value)) do
810
- if binary == "binom"
811
- Math::Function::Table.new(
812
- [
813
- Math::Function::Tr.new(
814
- Utility.table_td(first_value),
815
- ),
816
- Math::Function::Tr.new(
817
- Utility.table_td(second_value),
818
- ),
819
- ],
820
- Plurimath::Math::Symbols::Paren::Lcurly.new,
821
- Plurimath::Math::Symbols::Paren::Rcurly.new,
822
- )
823
- else
824
- Utility.get_class(
825
- binary.to_s.include?("mod") ? "mod" : binary,
826
- ).new(
827
- first_value,
828
- second_value,
829
- )
830
- end
831
- end
832
-
833
- rule(binary: simple(:binary),
834
- first_value: simple(:first_value),
835
- second_value: sequence(:second_value)) do
836
- Utility.get_class(
837
- binary.to_s.include?("mod") ? "mod" : binary,
838
- ).new(
839
- first_value,
840
- Utility.filter_values(second_value),
841
- )
842
- end
843
-
844
- rule(underover: simple(:function),
845
- first_value: simple(:first),
846
- subscript: simple(:subscript),
847
- supscript: simple(:supscript)) do
848
- Math::Function::PowerBase.new(
849
- Utility.get_class(function).new(first),
850
- subscript,
851
- supscript,
852
- )
853
- end
854
-
855
- rule(environment: simple(:environment),
856
- table_data: sequence(:table_data),
857
- ending: simple(:ending)) do
858
- open_paren = Constants::MATRICES[environment.to_sym]
859
- Utility.get_table_class(environment).new(
860
- Utility.organize_table(table_data),
861
- Utility.symbols_class(open_paren, lang: :latex, table: true),
862
- Utility.symbols_class(
863
- Constants::MATRICES_PARENTHESIS[open_paren&.to_sym]&.to_s, lang: :latex, table: true
864
- ),
865
- {},
866
- )
867
- end
868
-
869
- rule(environment: simple(:environment),
870
- args: simple(:args),
871
- table_data: simple(:table_data),
872
- ending: simple(:ending)) do
873
- third_value = args ? [args] : []
874
- open_paren = Constants::MATRICES[environment.to_sym]
875
- table = Utility.organize_table(
876
- [table_data],
877
- column_align: third_value,
878
- )
879
- Utility.get_table_class(environment).new(
880
- table,
881
- Utility.symbols_class(open_paren, lang: :latex, table: true),
882
- Utility.symbols_class(
883
- Constants::MATRICES_PARENTHESIS[open_paren&.to_sym]&.to_s, lang: :latex, table: true
884
- ),
885
- Utility.table_options(table),
886
- )
887
- end
888
-
889
- rule(environment: simple(:environment),
890
- table_data: simple(:table_data),
891
- ending: simple(:ending)) do
892
- open_paren = Constants::MATRICES[environment.to_sym]
893
- Utility.get_table_class(environment).new(
894
- Utility.organize_table([table_data]),
895
- Utility.symbols_class(open_paren, lang: :latex, table: true),
896
- Utility.symbols_class(
897
- Constants::MATRICES_PARENTHESIS[open_paren&.to_sym]&.to_s, lang: :latex, table: true
898
- ),
899
- )
900
- end
901
-
902
- rule(environment: simple(:environment),
903
- args: sequence(:args),
904
- table_data: sequence(:table_data),
905
- ending: simple(:ending)) do
906
- open_paren = Constants::MATRICES[environment.to_sym]
907
- table = Utility.organize_table(table_data, column_align: args)
908
- Utility.get_table_class(environment).new(
909
- table,
910
- Utility.symbols_class(open_paren, lang: :latex, table: true),
911
- Utility.symbols_class(
912
- Constants::MATRICES_PARENTHESIS[open_paren&.to_sym]&.to_s, lang: :latex, table: true
913
- ),
914
- Utility.table_options(table),
915
- )
916
- end
917
-
918
- rule(environment: simple(:environment),
919
- args: simple(:args),
920
- table_data: sequence(:table_data),
921
- ending: simple(:ending)) do
922
- third_value = args ? [args] : []
923
- open_paren = Constants::MATRICES[environment.to_sym]
924
- table = Utility.organize_table(table_data, column_align: third_value)
925
- Utility.get_table_class(environment).new(
926
- table,
927
- Utility.symbols_class(open_paren, lang: :latex, table: true),
928
- Utility.symbols_class(
929
- Constants::MATRICES_PARENTHESIS[open_paren&.to_sym]&.to_s, lang: :latex, table: true
930
- ),
931
- Utility.table_options(table),
932
- )
933
- end
934
-
935
- rule(environment: simple(:environment),
936
- asterisk: simple(:asterisk),
937
- options: simple(:options),
938
- table_data: sequence(:table_data),
939
- ending: simple(:ending)) do
940
- third_value = options ? [options] : []
941
- open_paren = Constants::MATRICES[environment.to_sym]
942
- table = Utility.organize_table(
943
- table_data,
944
- column_align: third_value,
945
- options: true,
946
- )
947
- Utility.get_table_class(environment).new(
948
- table,
949
- Utility.symbols_class(open_paren, lang: :latex, table: true),
950
- Utility.symbols_class(
951
- Constants::MATRICES_PARENTHESIS[open_paren&.to_sym]&.to_s, lang: :latex, table: true
952
- ),
953
- { asterisk: true },
954
- )
955
- end
956
-
957
- rule(environment: simple(:environment),
958
- asterisk: simple(:asterisk),
959
- table_data: sequence(:table_data),
960
- ending: simple(:ending)) do
961
- open_paren = Constants::MATRICES[environment.to_sym]
962
- Utility.get_table_class(environment).new(
963
- Utility.organize_table(table_data),
964
- Utility.symbols_class(open_paren, lang: :latex, table: true),
965
- Utility.symbols_class(
966
- Constants::MATRICES_PARENTHESIS[open_paren&.to_sym]&.to_s, lang: :latex, table: true
967
- ),
968
- { asterisk: true },
969
- )
970
- end
971
-
972
- rule(environment: simple(:env),
973
- expression: simple(:expr)) do
974
- open_paren = Constants::MATRICES[env.to_sym]
975
- Utility.get_table_class(env).new(
976
- Utility.organize_table(expr.nil? ? [] : [expr]),
977
- Utility.symbols_class(open_paren, lang: :latex, table: true),
978
- Utility.symbols_class(
979
- Constants::MATRICES_PARENTHESIS[open_paren&.to_sym]&.to_s, lang: :latex, table: true
980
- ),
981
- {},
982
- )
983
- end
984
-
985
- rule(environment: simple(:env),
986
- expression: sequence(:expr)) do
987
- open_paren = Constants::MATRICES[env.to_sym]
988
- Utility.get_table_class(env).new(
989
- Utility.organize_table(expr.compact),
990
- Utility.symbols_class(open_paren, lang: :latex, table: true),
991
- Utility.symbols_class(
992
- Constants::MATRICES_PARENTHESIS[open_paren&.to_sym]&.to_s, lang: :latex, table: true
993
- ),
994
- {},
995
- )
996
- end
997
-
998
- rule(substack: simple(:substack),
999
- expression: sequence(:value)) do
1000
- Math::Function::Substack.new(
1001
- Utility.organize_table(value),
1002
- )
1003
- end
1004
- end
1005
- end
1006
- end