Skip to content

Commit

Permalink
Consolidate Greek character searches
Browse files Browse the repository at this point in the history
Searching for keys in a map is just like searching for elements in a set
so we can have everything use the same list of Greek characters.

Signed-off-by: Connor Behan <connor.behan@gmail.com>
  • Loading branch information
cbehan committed Feb 7, 2024
1 parent 8c98d09 commit b26a25e
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 112 deletions.
4 changes: 2 additions & 2 deletions core/DisplayTeX.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ bool DisplayTeX::reads_as_operator(Ex::iterator obj, Ex::iterator arg) const
// FIXME: this needs fine-tuning; there are more cases where
// no brackets are needed.
const LaTeXForm *lf = kernel.properties.get<LaTeXForm>(arg);
if((*arg->name).size()==1 || lf || cadabra::symbols::greek.find(*arg->name)!=cadabra::symbols::greek.end()) return true;
if((*arg->name).size()==1 || lf || cadabra::symbols::greekmap.find(*arg->name)!=cadabra::symbols::greekmap.end()) return true;
}

if(*obj->name=="\\cos" || *obj->name=="\\sin" || *obj->name=="\\tan" || *obj->name=="\\exp") {
const LaTeXForm *lf = kernel.properties.get<LaTeXForm>(arg);
if(*arg->multiplier==1)
if((*arg->name).size()==1 || lf || cadabra::symbols::greek.find(*arg->name)!=cadabra::symbols::greek.end()) return true;
if((*arg->name).size()==1 || lf || cadabra::symbols::greekmap.find(*arg->name)!=cadabra::symbols::greekmap.end()) return true;
}

auto it=curly_bracket_operators.find(*obj->name);
Expand Down
58 changes: 3 additions & 55 deletions core/DisplayTerminal.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

#include "Algorithm.hh"
#include "DisplayTerminal.hh"
#include "Symbols.hh"
#include "properties/Accent.hh"

using namespace cadabra;
Expand All @@ -18,59 +19,6 @@ DisplayTerminal::DisplayTerminal(const Kernel& k, const Ex& e, bool uuc)
{"\\int", "" },
{"\\sum", "" }
};

greekmap = {
{"\\alpha", "α" },
{"\\beta", "β" }, // beta seems to be reserved
{"\\gamma", "γ" }, // gamma seems to be reserved
{"\\delta", "δ" },
{"\\epsilon", "ε" },
{"\\zeta", "ζ" },
{"\\eta", "η" },
{"\\theta", "θ" },
{"\\iota", "ι" },
{"\\kappa", "κ" },
{"\\lambda", "λ" }, // lambda is reserved
{"\\mu", "μ" },
{"\\nu", "ν" },
{"\\xi", "ξ" },
{"\\omicron", "ο" },
{"\\pi", "π" },
{"\\rho", "ρ" },
{"\\sigma", "σ" },
{"\\tau", "τ" },
{"\\upsilon", "υ" },
{"\\phi", "φ" },
{"\\chi", "χ" },
{"\\psi", "ψ" },
{"\\omega", "ω" },

{"\\Alpha", "Α" },
{"\\Beta", "Β" },
{"\\Gamma", "Γ" },
{"\\Delta", "Δ" },
{"\\Epsilon", "Ε" },
{"\\Zeta", "Ζ" },
{"\\Eta", "Η" },
{"\\Theta", "ϴ" },
{"\\Iota", "Ι" },
{"\\Kappa", "Κ" },
{"\\Lambda", "Λ" },
{"\\Mu", "Μ" },
{"\\Nu", "Ν" },
{"\\Xi", "Ξ" },
{"\\Omicron", "Ο" },
{"\\Pi", "Π" },
{"\\Rho", "Ρ" },
{"\\Sigma", "Σ" },
{"\\Tau", "Τ" },
{"\\Upsilon", "Υ" },
{"\\Phi", "Φ" },
{"\\Chi", "Χ" },
{"\\Psi", "Ψ" },
{"\\Omega", "Ω" },

};
}

// Logic: each node should check whether it needs to have brackets printed around
Expand Down Expand Up @@ -665,8 +613,8 @@ void DisplayTerminal::print_other(std::ostream& str, Ex::iterator it)
auto rn1 = symmap.find(sbit);
if(rn1!=symmap.end())
sbit = rn1->second;
auto rn = greekmap.find(sbit);
if(rn!=greekmap.end())
auto rn = cadabra::symbols::greekmap.find(sbit);
if(rn!=cadabra::symbols::greekmap.end())
sbit = rn->second;
}
str << sbit;
Expand Down
2 changes: 1 addition & 1 deletion core/DisplayTerminal.hh
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ namespace cadabra {

bool children_have_brackets(Ex::iterator ch) const;

std::map<std::string, std::string> symmap, greekmap;
std::map<std::string, std::string> symmap;
};

const char *unichar(kunichar c);
Expand Down
52 changes: 0 additions & 52 deletions core/Symbols.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,6 @@
#include "Symbols.hh"


const std::set<std::string> cadabra::symbols::greek {
"\\alpha",
"\\beta",
"\\gamma",
"\\delta",
"\\epsilon",
"\\zeta",
"\\eta",
"\\theta",
"\\iota",
"\\kappa",
"\\lambda",
"\\mu",
"\\nu",
"\\xi",
"\\omicron",
"\\pi",
"\\rho",
"\\sigma",
"\\tau",
"\\upsilon",
"\\phi",
"\\varphi",
"\\chi",
"\\psi",
"\\omega",
"\\Alpha",
"\\Beta",
"\\Gamma",
"\\Delta",
"\\Epsilon",
"\\Zeta",
"\\Eta",
"\\Theta",
"\\Iota",
"\\Kappa",
"\\Lambda",
"\\Mu",
"\\Nu",
"\\Xi",
"\\Omicron",
"\\Pi",
"\\Rho",
"\\Sigma",
"\\Tau",
"\\Upsilon",
"\\Phi",
"\\Chi",
"\\Psi",
"\\Omega"
};

const std::map<std::string, std::string> cadabra::symbols::greekmap {
{"\\alpha", "α" },
{"\\beta", "β" }, // beta seems to be reserved
Expand Down
2 changes: 0 additions & 2 deletions core/Symbols.hh
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@

#pragma once

#include <set>
#include <map>
#include <string>

namespace cadabra {
namespace symbols {
extern const std::set<std::string> greek;
extern const std::map<std::string, std::string> greekmap;
}
}

0 comments on commit b26a25e

Please sign in to comment.