Skip to content

Commit

Permalink
feat: initial implementation of summation syntax
Browse files Browse the repository at this point in the history
Tests and virtual keyboard button needs to be added. Indexing of matrices within a sum also needs to be fixed.
  • Loading branch information
mgreminger committed Oct 25, 2024
1 parent 8ea04e2 commit 88db36e
Show file tree
Hide file tree
Showing 6 changed files with 422 additions and 343 deletions.
6 changes: 5 additions & 1 deletion public/dimensional_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@
ceiling,
sign,
sqrt,
factorial
factorial,
summation
)

class ExprWithAssumptions(Expr):
Expand Down Expand Up @@ -1183,6 +1184,8 @@ def custom_integral_dims(local_expr: Expr, global_expr: Expr, dummy_integral_var
else:
return global_expr * integral_var # type: ignore

def custom_summation(operand: Expr, dummy_var: Symbol, start: Expr, end: Expr):
return summation(operand, (dummy_var, start, end))

CP = None

Expand Down Expand Up @@ -1491,6 +1494,7 @@ def get_next_id(self):
cast(Function, Function('_Integral')) : {"dim_func": custom_integral_dims, "sympy_func": custom_integral},
cast(Function, Function('_range')) : {"dim_func": custom_range, "sympy_func": custom_range},
cast(Function, Function('_factorial')) : {"dim_func": factorial, "sympy_func": CustomFactorial},
cast(Function, Function('_summation')) : {"dim_func": custom_summation, "sympy_func": custom_summation},
}

global_placeholder_set = set(global_placeholder_map.keys())
Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const INLINE_SHORTCUTS = {
'~': '\\approx',
'sqrt': '\\sqrt{#?}',
'$int': '\\int _{#?}^{#?}\\left(#?\\right)\\mathrm{d}\\left(#?\\right)',
'$sum': '\\sum_{#?=#?}^{#?}\left(#?\\right)',
'$prime': '\\frac{\\mathrm{d}}{\\mathrm{d}\\left(#?\\right)}\\left(#?\\right)',
'$doubleprime': '\\frac{\\mathrm{d}^{2}}{\\mathrm{d}\\left(#?\\right)^{2}}\\left(#?\\right)',
'$tripleprime': '\\frac{\\mathrm{d}^{3}}{\\mathrm{d}\\left(#?\\right)^{3}}\\left(#?\\right)',
Expand Down
1 change: 1 addition & 0 deletions src/parser/LatexParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ expr: <assoc=right> id CARET_SINGLE_CHAR_ID_UNDERSCORE_SUBSCRIPT #exp
| integral_cmd #integral
| derivative_cmd #derivative
| n_derivative_cmd #nDerivative
| summation_cmd #summation
| BACKSLASH? CMD_LN L_PAREN expr R_PAREN #ln
| BACKSLASH? CMD_LOG L_PAREN expr R_PAREN #log
| CMD_SLASH_LOG_UNDERSCORE L_BRACE expr R_BRACE L_PAREN expr R_PAREN #baseLog
Expand Down
Loading

0 comments on commit 88db36e

Please sign in to comment.