Questions tagged [algebra]

Algebra is the branch of mathematics concerning the study of the rules of operations and relations, and the constructions and concepts arising from them. Questions about algebra that are not related to programming are off-topic at Stack Overflow.

Together with geometry, analysis, topology, combinatorics, and number theory, algebra is one of the main branches of pure mathematics.

Elementary algebra, often part of the curriculum in secondary education, introduces the concept of variables representing numbers. Statements based on these variables are manipulated using the rules of operations that apply to numbers, such as addition. This can be done for a variety of reasons, including equation solving. Algebra is much broader than elementary algebra and studies what happens when different rules of operations are used and when operations are devised for things other than numbers. Addition and multiplication can be generalized and their precise definitions lead to structures such as groups, rings and fields, studied in the area of mathematics called abstract algebra.

873 questions
6
votes
4 answers

How can I simplify a basic arithmetic expression?

How can I simplify a basic arithmetic expression? e.g. module ExprOps where simplify :: Expr -> Expr simplify (Plus(Var"x") (Const 0)) = Var "x" What do I have to do? module Expr where -- Variables are named by strings, assumed to be…
user41000
  • 285
  • 1
  • 6
  • 13
6
votes
2 answers

Fast multiplication modulo 2^16 + 1

The IDEA cipher uses multiplication modulo 2^16 + 1. Is there an algorithm to perform this operation without general modulo operator (only modulo 2^16 (truncation))? In the context of IDEA, zero is interpreted as 2^16 (it means zero isn't an…
ciechowoj
  • 914
  • 6
  • 26
6
votes
6 answers

How can one check for "safe" conversions between value types in .NET?

Back to the basics... For reference types, one can do this: SomeType someObject = firstObject as SomeType; if (someObject == null) { // Handle the situation gracefully } else { …
d..
  • 1,063
  • 1
  • 10
  • 18
6
votes
3 answers

How to reflect a line over another line

For a collision algorithm I am developing, I need to find out how to reflect a line over another. Line 1: y=ax+b Line 2: y=cx+d Line 3: (a result of reflecting line 1 over line 2) y=ex+f Is there any algebraic way to determine e and f in…
A Parikh
  • 146
  • 1
  • 1
  • 10
5
votes
4 answers

Statistics and matrix algebra in Ruby

I need to inverse a variance-covariance matrix in Ruby and vector by matrix multiplication. Which numerical Ruby library/Gem should I use?
Hekje
  • 441
  • 3
  • 12
5
votes
1 answer

find length of individual dashed lines as well as the gaps between them

i have the following png with me: [![enter image description here][1]][1] in the above image i want to find the length of every dash and also the length between every 2 dashes ie the gaps. Parallely, i have this code which gives me length of a…
quest1001
  • 81
  • 5
5
votes
2 answers

Solve very large system of linear equations with Numpy

I'm trying to solve a system of equations that is a 1 Million x 1 Million square matrix and one 1 Million solution vector. To do this, I'm using np.linalg.solve(matrix, answers) but it's taking a very long time. Is there a way to speed it up? Thanks…
ortunoa
  • 345
  • 4
  • 11
5
votes
2 answers

Message parity check

Can someone help me out with implementing this sequence of calculations in C#?
redfrogsbinary
  • 619
  • 5
  • 13
  • 26
5
votes
2 answers

Semigroup/Monoid/Group type class hierarchy in Haskell errors

I'm trying to create a "hierarchy" of algebraic type classes, as follows: class Semigroup a where (.*) :: a -> a -> a foldr1 (.*) = foldl1 (.*) -- GHCi error: "`foldr1' is not a (visible) method of class `Semigroup'" class (Semigroup a) =>…
user842209
5
votes
3 answers

How to use nested for-loops to find the x and y of a linear equation

I'm trying to find how many 10 and 50 dollar bills go into $1760 if there are only 160 bills. I figured, with the help of a friend, that using a nested for-loop is the best way to go but I'm having issues with implementation. My idea is to iterate…
user10851318
5
votes
1 answer

Why is sparse-dense multiplication faster than dense-sparse multiplication?

I am curious to why multiplying a sparse-matrix by a dense-matrix takes a different time than the reverse. Are the algorithms significantly different? Here's an example in matlab 2018a:…
avgn
  • 982
  • 6
  • 19
5
votes
3 answers

Drawing arrowheads which follow the direction of the line in PyGame

In Pygame, how can I calculate the coordinates for the three points of the head of an arrow, given a start point and an end point for the arrow, so that the arrowhead points in the same direction as the line? def __draw_arrow(self, screen, colour,…
CFJ
  • 51
  • 1
  • 2
5
votes
1 answer

Find a root of a polynomial modulo 2^r

I have a polynomial P and I would like to find y such that P(y) = 0 modulo 2^r. I have tried something along the lines of Hensel lifting, but I don't know if this could even work, because of the usual condition f'(y mod 2) != 0 mod 2 which is not…
Monica
  • 53
  • 2
5
votes
3 answers

The equation -e**-((-log(7)/100.0)*(100-x))+7 returns NaN

I'm trying to implement this curve as part of the leveling system of a small game I'm currently working on. The equation is as follows f(x) = -e^-((-log(7)/100)*(100-x))+7 Which in python can be defined as f=lambda…
5
votes
5 answers

How could one implement multiplication in finite fields?

If F := GF(p^n) is the finite field with p^n elements, where p is a prime number and n a natural number, is there any efficient algorithm to work out the product of two elements in F? Here are my thoughts so far: I know that the standard…
Benno
  • 5,288
  • 5
  • 42
  • 60