Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logic Toolbox #308

Open
wants to merge 5 commits into
base: upsilon-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions apps/calculation/additional_outputs/integer_list_controller.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "integer_list_controller.h"
#include <poincare/based_integer.h>
#include <poincare/opposite.h>
#include <poincare/integer.h>
#include <poincare/logarithm.h>
#include <poincare/empty_layout.h>
#include <poincare/factor.h>
#include "../app.h"
Expand All @@ -26,10 +28,30 @@ Integer::Base baseAtIndex(int index) {
void IntegerListController::setExpression(Poincare::Expression e) {
ExpressionsListController::setExpression(e);
static_assert(k_maxNumberOfRows >= k_indexOfFactorExpression + 1, "k_maxNumberOfRows must be greater than k_indexOfFactorExpression");
assert(!m_expression.isUninitialized() && m_expression.type() == ExpressionNode::Type::BasedInteger);
Integer integer = static_cast<BasedInteger &>(m_expression).integer();
for (int index = 0; index < k_indexOfFactorExpression; ++index) {
m_layouts[index] = integer.createLayout(baseAtIndex(index));
assert(!m_expression.isUninitialized() && m_expression.type() == ExpressionNode::Type::BasedInteger || (m_expression.type() == ExpressionNode::Type::Opposite && m_expression.childAtIndex(0).type() == ExpressionNode::Type::BasedInteger));
assert(!m_expression.isUninitialized());

if (m_expression.type() == ExpressionNode::Type::BasedInteger) {
Integer integer = static_cast<BasedInteger &>(m_expression).integer();
for (int index = 0; index < k_indexOfFactorExpression; ++index) {
m_layouts[index] = integer.createLayout(baseAtIndex(index));
}
}
else
{
Opposite b = static_cast<Opposite &>(m_expression);
Expression e = b.childAtIndex(0);
Integer childInt = static_cast<BasedInteger &>(e).integer();
childInt.setNegative(true);
Integer num_bits = Integer::CeilingLog2(childInt);
Integer integer = Integer::TwosComplementToBits(childInt, num_bits);
for (int index = 0; index < k_indexOfFactorExpression; ++index) {
if(baseAtIndex(index) == Integer::Base::Decimal) {
m_layouts[index] = childInt.createLayout(baseAtIndex(index));
} else {
m_layouts[index] = integer.createLayout(baseAtIndex(index));
}
}
}
// Computing factorExpression
Expression factor = Factor::Builder(m_expression.clone());
Expand Down
2 changes: 1 addition & 1 deletion apps/calculation/calculation.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ friend CalculationStore;
AdditionalInformationType additionalInformationType(Poincare::Context * context);
private:
static constexpr KDCoordinate k_heightComputationFailureHeight = 50;
static constexpr const char * k_maximalIntegerWithAdditionalInformation = "10000000000000000";
static constexpr const char * k_maximalIntegerWithAdditionalInformation = "18446744073709551617"; // 2^64 + 1

void setHeights(KDCoordinate height, KDCoordinate expandedHeight);

Expand Down
32 changes: 30 additions & 2 deletions apps/math_toolbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,34 @@ const ToolboxMessageTree matricesChildren[] = {
const ToolboxMessageTree vectorsChildren[] = {
ToolboxMessageTree::Leaf(I18n::Message::DotCommandWithArg, I18n::Message::Dot),
ToolboxMessageTree::Leaf(I18n::Message::CrossCommandWithArg, I18n::Message::Cross),
ToolboxMessageTree::Leaf(I18n::Message::NormVectorCommandWithArg, I18n::Message::NormVector),
ToolboxMessageTree::Leaf(I18n::Message::NormVectorCommandWithArg, I18n::Message::NormVector)
};

const ToolboxMessageTree logicExplicitChildren[] = {
ToolboxMessageTree::Leaf(I18n::Message::LogicalNotExplicitCommandWithArg, I18n::Message::LogicalNot),
ToolboxMessageTree::Leaf(I18n::Message::LogicalShiftRightArithmeticExplicitCommandWithArg, I18n::Message::LogicalShiftRightArithmetic),
ToolboxMessageTree::Leaf(I18n::Message::LogicalRotateLeftExplicitCommandWithArg, I18n::Message::LogicalRotateLeft),
ToolboxMessageTree::Leaf(I18n::Message::LogicalRotateRightExplicitCommandWithArg, I18n::Message::LogicalRotateRight),
ToolboxMessageTree::Leaf(I18n::Message::LogicalBitsClearExplicitCommandWithArg, I18n::Message::LogicalBitsClear)};

const ToolboxMessageTree logicChildren[] = {
ToolboxMessageTree::Node(I18n::Message::ExplicitNumberOfBits, logicExplicitChildren),
ToolboxMessageTree::Leaf(I18n::Message::LogicalAndCommandWithArg, I18n::Message::LogicalAnd),
ToolboxMessageTree::Leaf(I18n::Message::LogicalOrCommandWithArg, I18n::Message::LogicalOr),
ToolboxMessageTree::Leaf(I18n::Message::LogicalXorCommandWithArg, I18n::Message::LogicalXor),
ToolboxMessageTree::Leaf(I18n::Message::LogicalNotCommandWithArg, I18n::Message::LogicalNot),
ToolboxMessageTree::Leaf(I18n::Message::LogicalShiftLeftCommandWithArg, I18n::Message::LogicalShiftLeft),
ToolboxMessageTree::Leaf(I18n::Message::LogicalShiftRightCommandWithArg, I18n::Message::LogicalShiftRight),
ToolboxMessageTree::Leaf(I18n::Message::LogicalShiftRightArithmeticCommandWithArg, I18n::Message::LogicalShiftRightArithmetic),
ToolboxMessageTree::Leaf(I18n::Message::LogicalRotateLeftCommandWithArg, I18n::Message::LogicalRotateLeft),
ToolboxMessageTree::Leaf(I18n::Message::LogicalRotateRightCommandWithArg, I18n::Message::LogicalRotateRight),
ToolboxMessageTree::Leaf(I18n::Message::LogicalBitGetCommandWithArg, I18n::Message::LogicalBitGet),
ToolboxMessageTree::Leaf(I18n::Message::LogicalBitSetCommandWithArg, I18n::Message::LogicalBitSet),
ToolboxMessageTree::Leaf(I18n::Message::LogicalBitClearCommandWithArg, I18n::Message::LogicalBitClear),
ToolboxMessageTree::Leaf(I18n::Message::LogicalBitFlipCommandWithArg, I18n::Message::LogicalBitFlip),
ToolboxMessageTree::Leaf(I18n::Message::LogicalBitsClearCommandWithArg, I18n::Message::LogicalBitsClear),
ToolboxMessageTree::Leaf(I18n::Message::TwosComplementToBitsCommandWithArg, I18n::Message::TwosComplementToBits),
ToolboxMessageTree::Leaf(I18n::Message::CeilingLog2CommandWithArg, I18n::Message::CeilingLog2)
};

#if LIST_ARE_DEFINED
Expand Down Expand Up @@ -867,7 +894,8 @@ const ToolboxMessageTree menu[] = {
ToolboxMessageTree::Node(I18n::Message::HyperbolicTrigonometry, trigonometryChildren),
ToolboxMessageTree::Node(I18n::Message::Fluctuation, predictionChildren),
ToolboxMessageTree::Node(I18n::Message::Chemistry, chemistry),
ToolboxMessageTree::Node(I18n::Message::Physics, Physics)
ToolboxMessageTree::Node(I18n::Message::Physics, Physics),
ToolboxMessageTree::Node(I18n::Message::Logic, logicChildren),
};

const ToolboxMessageTree toolboxModel = ToolboxMessageTree::Node(I18n::Message::Toolbox, menu);
Expand Down
25 changes: 25 additions & 0 deletions apps/shared.universal.i18n
Original file line number Diff line number Diff line change
Expand Up @@ -485,3 +485,28 @@ Rstvt_Water = "1.01·10^3_Ω_m"
Rstvt_Air = "1.00·10^9_Ω_m"
Rstvt_Glass = "5.00·10^14_Ω_m"
Rstvt_Wood = "1.00·10^3_Ω_m"
LogicalAnd = "a AND b"
LogicalAndCommandWithArg = "and(a,b)"
LogicalBitClearCommandWithArg = "bclr(a,b)"
LogicalBitFlipCommandWithArg = "bflp(a,b)"
LogicalBitGetCommandWithArg = "bit(a,b)"
LogicalBitSetCommandWithArg = "bset(a,b)"
LogicalBitsClearCommandWithArg = "bic(a,b)"
LogicalBitsClearExplicitCommandWithArg = "bic(a,b,n)"
LogicalNot = "NOT a"
LogicalNotCommandWithArg = "not(a)"
LogicalNotExplicitCommandWithArg = "not(a,n)"
LogicalOr = "a OR b"
LogicalOrCommandWithArg = "or(a,b)"
LogicalShiftLeftCommandWithArg = "sll(a,s)"
LogicalShiftRightArithmeticCommandWithArg = "sra(a,s)"
LogicalShiftRightArithmeticExplicitCommandWithArg = "sra(a,s,n)"
LogicalShiftRightCommandWithArg = "srl(a,s)"
LogicalRotateLeftCommandWithArg = "rol(a,r)"
LogicalRotateLeftExplicitCommandWithArg = "rol(a,r,n)"
LogicalRotateRightCommandWithArg = "ror(a,r)"
LogicalRotateRightExplicitCommandWithArg = "ror(a,r,n)"
LogicalXor = "a XOR b"
LogicalXorCommandWithArg = "xor(a,r)"
TwosComplementToBitsCommandWithArg = "tc(a,n)"
CeilingLog2CommandWithArg = "clog2(a)"
14 changes: 14 additions & 0 deletions apps/toolbox.de.i18n
Original file line number Diff line number Diff line change
Expand Up @@ -510,3 +510,17 @@ HartreeConstantTag = "Hartbaum-Konstante"
MagneticFluxQuantumTag = "Magnetisches Fluss-Quantum"
ConductanceQuantumTag = "Leitwertquantum"
CirculationQuantumTag = "Auflage-Quantum"
Logic = "Logik"
LogicalBitClear = "Bit b in a löschen"
LogicalBitFlip = "Bit b in a umkehren"
LogicalBitGet = "Bit b aus a lesen"
LogicalBitSet = "Bit b in a setzen"
LogicalBitsClear = "a AND NOT b"
LogicalShiftLeft = "Bitverschiebung links von a um s"
LogicalShiftRightArithmetic = "Arithm. Versch. rechts von a um s"
LogicalShiftRight = "Bitverschiebung rechts von a um s"
LogicalRotateLeft = "Rotieren von a um r Bit n. links"
LogicalRotateRight= "Rotieren von a um r Bit n. rechts"
TwosComplementToBits = "Äquivalent im Zweierkomplement"
CeilingLog2 = "Anzahl der Bits, die zum Speichern von a benötigt werden"
ExplicitNumberOfBits = "Explizite Bitbreite"
14 changes: 14 additions & 0 deletions apps/toolbox.en.i18n
Original file line number Diff line number Diff line change
Expand Up @@ -510,3 +510,17 @@ HartreeConstantTag = "Hartree Constant"
MagneticFluxQuantumTag = "Magnetic Flux Quantum"
ConductanceQuantumTag = "Conductance Quantum"
CirculationQuantumTag = "Circulation Quantum"
Logic = "Logic"
LogicalBitClear = "Clear bit b in a"
LogicalBitFlip = "Flip bit b in a"
LogicalBitGet = "Get bit b in a"
LogicalBitSet = "Set bit b in a"
LogicalBitsClear = "Clear a with b [a AND NOT b]"
LogicalShiftLeft = "Logical shift left [a << s]"
LogicalShiftRightArithmetic = "Arithmetic shift right [a >>> s]"
LogicalShiftRight = "Logical shift right [a >> s]"
LogicalRotateLeft = "Rotate r bits of a to the left"
LogicalRotateRight= "Rotate r bits of a to the right"
TwosComplementToBits = "Two's complement equivalent"
CeilingLog2 = "Number of bits needed to store a"
ExplicitNumberOfBits = "Explicit number of bits"
14 changes: 14 additions & 0 deletions apps/toolbox.es.i18n
Original file line number Diff line number Diff line change
Expand Up @@ -510,3 +510,17 @@ HartreeConstantTag = "Constante de Hartree"
MagneticFluxQuantumTag = "Flujo Magnético Cuántico"
ConductanceQuantumTag = "Conductancia Quantum"
CirculationQuantumTag = "Circulación Quantum"
Logic = "Lógico"
LogicalBitClear = "Borrar bit número b en a"
LogicalBitFlip = "Voltear el bit número b en a"
LogicalBitGet = "Obtener el bit número b en a"
LogicalBitSet = "Establecer el número de bit b en a"
LogicalBitsClear = "Borrar a con bits en b"
LogicalShiftLeft = "Desplazamiento lógico izquierda"
LogicalShiftRightArithmetic = "Desplazamiento aritmético derecha"
LogicalShiftRight = "Desplazamiento lógico derecha"
LogicalRotateLeft = "Gire r bits de a hacia izquierda"
LogicalRotateRight= "Gire r bits de a hacia derecha"
TwosComplementToBits = "Equivalente en complemento a dos"
CeilingLog2 = "Número de bits necesarios para almacenar a"
ExplicitNumberOfBits = "Número explícito de bits"
14 changes: 14 additions & 0 deletions apps/toolbox.fr.i18n
Original file line number Diff line number Diff line change
Expand Up @@ -514,3 +514,17 @@ HartreeConstantTag = "Constante de Hartree"
MagneticFluxQuantumTag = "Quantum de Flux Magnétique"
ConductanceQuantumTag = "Quantum de Conductance"
CirculationQuantumTag = "Quantum de Circulation"
Logic = "Logique"
LogicalBitClear = "Effacer le bit numéro b dans a"
LogicalBitFlip = "Inverser le bit numéro b dans a"
LogicalBitGet = "Obtenir le bit numéro b dans a"
LogicalBitSet = "Mettre le bit numéro b dans a"
LogicalBitsClear = "Effacer bits b ds a [a AND NOT b]"
LogicalShiftLeft = "Décalage logique gauche [a << s]"
LogicalShiftRightArithmetic = "Décalage arith. droite [a >>> s]"
LogicalShiftRight = "Décalage logique droite [a >> s]"
LogicalRotateLeft = "Rotation gauche de a par r bits"
LogicalRotateRight= "Rotation droite de a par r bits"
TwosComplementToBits = "Equivalent en complément à deux"
CeilingLog2 = "Nb de bits nécessaires pour stocker a"
ExplicitNumberOfBits = "Nombre indiqué de bits"
14 changes: 14 additions & 0 deletions apps/toolbox.hu.i18n
Original file line number Diff line number Diff line change
Expand Up @@ -510,3 +510,17 @@ HartreeConstantTag = "Hartree Állandó"
MagneticFluxQuantumTag = "Mágneses Fluxuskvantum"
ConductanceQuantumTag = "Vezetőképesség Kvantum"
CirculationQuantumTag = "Keringési Kvantum"
Logic = "Logika"
LogicalBitClear = "Tiszta bit b ban ben a"
LogicalBitFlip = "Flip bit b ban ben a"
LogicalBitGet = "Kap bit b ban ben a"
LogicalBitSet = "Készlet bit b ban ben a"
LogicalBitsClear = "Tiszta a val vel b [a AND NOT b]"
LogicalShiftLeft = "Logikai eltolás balra [a << s]"
LogicalShiftRightArithmetic = "Aritmetikai eltolás jobbra [a >>> s]"
LogicalShiftRight = "Logikai eltolás jobbra [a >> s]"
LogicalRotateLeft = "Forog r bitek nak a balra"
LogicalRotateRight= "Forog r bitek nak a jobbra"
TwosComplementToBits = "Kettő komplementere egyenértékű"
CeilingLog2 = "Az a tárolásához szükséges bitek száma"
ExplicitNumberOfBits = "Explicit bitszám"
14 changes: 14 additions & 0 deletions apps/toolbox.it.i18n
Original file line number Diff line number Diff line change
Expand Up @@ -510,3 +510,17 @@ HartreeConstantTag = "Costante di Hartree"
MagneticFluxQuantumTag = "Flusso magnetico quantico"
ConductanceQuantumTag = "Conduttanza quantistica"
CirculationQuantumTag = "Circolazione quantistica"
Logic = "Logica"
LogicalBitClear = "Cancella il numero di bit b in a"
LogicalBitFlip = "Capovolgere il bit numero b in a"
LogicalBitGet = "Ottieni il bit numero b in a"
LogicalBitSet = "Impostare il numero di bit b in a"
LogicalBitsClear = "Cancella a con b [a AND NOT b]"
LogicalShiftLeft = "Spostamento logico a sinistra"
LogicalShiftRightArithmetic = "Spostamento aritmetico a destra"
LogicalShiftRight = "Spostamento logico a destra"
LogicalRotateLeft = "Ruota r bit di a verso sinistra"
LogicalRotateRight= "Ruota r bit di a verso destra"
TwosComplementToBits = "Equivalente in complemento di due"
CeilingLog2 = "Numero di bit necessari per memorizzare a"
ExplicitNumberOfBits = "Numero esplicito di bit"
14 changes: 14 additions & 0 deletions apps/toolbox.nl.i18n
Original file line number Diff line number Diff line change
Expand Up @@ -510,3 +510,17 @@ HartreeConstantTag = "Hartreeconstante"
MagneticFluxQuantumTag = "Magnetische flux kwantum"
ConductanceQuantumTag = "Kwantumgeleiding"
CirculationQuantumTag = "Kwantumcirculatie"
Logic = "Logica"
LogicalBitClear = "Wis bitnummer b in a"
LogicalBitFlip = "Draai bitnummer b om in a"
LogicalBitGet = "Haal bit nummer b op in a"
LogicalBitSet = "Stel bitnummer b in a"
LogicalBitsClear = "Wis a met bits in b [a AND NOT b]"
LogicalShiftLeft = "Logische verschuiving naar links"
LogicalShiftRightArithmetic = "Rekenkundige verschuiving naar rechts"
LogicalShiftRight = "Logische verschuiving naar rechts"
LogicalRotateLeft = "Draai r stukjes a naar links"
LogicalRotateRight= "Draai r stukjes a naar rechts"
TwosComplementToBits = "Tweeën vullen equivalent aan"
CeilingLog2 = "Aantal bits dat nodig is om a op te slaan"
ExplicitNumberOfBits = "Expliciet aantal bits"
14 changes: 14 additions & 0 deletions apps/toolbox.pt.i18n
Original file line number Diff line number Diff line change
Expand Up @@ -510,3 +510,17 @@ HartreeConstantTag = "Constante de Hartree"
MagneticFluxQuantumTag = "Fluxo Magnético Quântico"
ConductanceQuantumTag = "Quantum de Conduta"
CirculationQuantumTag = "Quantum de Circulação"
Logic = "Lógica"
LogicalBitClear = "Limpar o bit b em a"
LogicalBitFlip = "Virar o bit em a"
LogicalBitGet = "Obter o bit b em a"
LogicalBitSet = "Definir o bit b em a"
LogicalBitsClear = "Limpar a com b [a AND NOT b]"
LogicalShiftLeft = "Mudar lógica à esquerda"
LogicalShiftRightArithmetic = "Mudar aritmético para a direita"
LogicalShiftRight = "Mudar lógica para a direita"
LogicalRotateLeft = "Girar r bits de a para a esquerda"
LogicalRotateRight= "Girar r bits de a para a direita"
TwosComplementToBits = "Complementar de dois equivalente"
CeilingLog2 = "Número de bits necessários para armazenar a"
ExplicitNumberOfBits = "Número explícito de bits"
2 changes: 2 additions & 0 deletions poincare/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ poincare_src += $(addprefix poincare/src/,\
arc_tangent.cpp \
arithmetic.cpp \
based_integer.cpp \
binary_operation.cpp \
binom_cdf.cpp \
binomial_coefficient.cpp \
binomial_distribution_function.cpp \
Expand Down Expand Up @@ -188,6 +189,7 @@ tests_src += $(addprefix poincare/test/,\
layout_cursor.cpp\
layout_serialization.cpp\
layout_to_expression.cpp\
logic.cpp\
parsing.cpp\
print_float.cpp\
print_int.cpp\
Expand Down
Loading