Questions tagged [simplify]

This tag refers to the process of making something simpler or smaller in order to increase its efficiency, usability, or operation speed.

Use this tag for questions related to making something simpler or smaller in order to increase its efficiency, usability, or operation speed.

770 questions
7
votes
5 answers

Efficient finding primitive roots modulo n using Python?

I'm using the following code for finding primitive roots modulo n in Python: Code: def gcd(a,b): while b != 0: a, b = b, a % b return a def primRoots(modulo): roots = [] required_set = set(num for num in range (1, modulo) if…
Erba Aitbayev
  • 4,167
  • 12
  • 46
  • 81
7
votes
2 answers

Prolog - simplify derivative

so I just got started with Prolog this semester, and got the homework to implement a pretty basic d(function, variable, derivative) which I did like this: d(X,X,1) :- !. d(C,X,0) :- atomic(C). %, (C \= X). d(X**E,X,E*X**(E-1)). d(U+V,X,A+B) :-…
4cello
  • 73
  • 1
  • 5
7
votes
5 answers

Simplify my jQuery code, which is growing huge and redundant

I am no jQuery expert, but I'm learning. I'm using a bit (growing to a LOT) of jQuery to hide some images and show a single image when a thumb is clicked. While this bit of jQuery works, it's horribly inefficient but I am unsure of how to simplify…
liquilife
  • 193
  • 3
  • 11
6
votes
8 answers

PHP Make a simple if-isset-empty function

I'm coding a worksheet app for a printer company. I'm getting flood of forms. For every single input field I have to check if the $_POST variables are set, and if, so echo back the value. (In case of some error, for example after a validation…
Kael
  • 565
  • 2
  • 8
  • 18
6
votes
4 answers

Simplify this regular expression

I'm doing some pre-exam exercises for my compilers class, and needed to simplify this regular expression. (a U b)*(a U e)b* U (a U b)*(b U e)a* Quite obviously, the e is the empty string, and the U stands for union. So far, I think one of the (a U…
6
votes
10 answers

Simplification / optimization of GPS track

I've got a GPS track produced by gpxlogger(1) (supplied as a client for gpsd). GPS receiver updates its coordinates every 1 second, gpxlogger's logic is very simple, it writes down location (lat, lon, ele) and a timestamp (time) received from GPS…
GreyCat
  • 16,622
  • 18
  • 74
  • 112
6
votes
2 answers

Python: List algebraic simplification

Hi I am trying to get the common terms of a list to simplify it for example if the list I have…
user3671704
  • 161
  • 7
6
votes
5 answers

How to avoid "Math." in front of every math function in C#?

I'm writing some C# heavy in mathematics. Many lines in sequence using plenty of abs(), min(), max(), sqrt(), etc. Using C# is the plain normal way, I must preface each function with "Math." For example double x =…
DarenW
  • 16,549
  • 7
  • 63
  • 102
6
votes
3 answers

Simplifying nested Maybe pattern matching

I have the following construct in my code: f :: Maybe A -> X f a = case a of Nothing -> x (Just b) -> case b of Nothing -> y (Just c) -> case c of Nothing -> z (Just d) -> d I'm not seeing an obvious way to simplify this…
Philip Kamenarsky
  • 2,757
  • 2
  • 24
  • 30
6
votes
5 answers

Java: if statement can be simplified (box contains point)

I have the following statement to check if a Vector2D is within a box, and IntelliJ gives me a warning: "if statement can be simplified". if(point.x < minX || point.x > maxX || point.y < minY || point.y > maxY) return false; How can I simplify…
kiel814
  • 106
  • 1
  • 1
  • 8
6
votes
1 answer

Automatically simplifying/refactoring Python code (e.g. for loops -> list comprehension)?

In Python, I really enjoy how concise an implementation can be when using list comprehension. I love to do concise list comprehensions this: myList = [1, 5, 11, 20, 30, 35] #input data bigNumbers = [x for x in myList if x > 10] However, I often…
5
votes
2 answers

In Mathematica, how to simplify expressions like a == +/- b into a^2 == b^2?

In Mathematica, how can I simplify expressions like a == b || a == -b into a^2 = b^2? Every function that I have tried (including Reduce, Simplify, and FullSimplify) does not do it. Note that I want this to work for an arbitrary (polynomial)…
Tyson Williams
  • 1,630
  • 15
  • 35
5
votes
3 answers

negation of boolean expressions with XOR

I have this: // returns true if both are equal (independent of scale) and also checks against null public static boolean isEqual(BigDecimal val1, BigDecimal val2) { // 1. check: both will be null or both will be non-null. if (val1 !=…
nimo23
  • 5,170
  • 10
  • 46
  • 75
5
votes
4 answers

Combine an IF LET with an OR in Swift

Is there a graceful way to combine two if let statements by an or operator. For instance, I need to check for the strings "pass", "true", or the integer 1. The following function, does just that... func test(content: Any) -> String { if let…
Caleb Rudnicki
  • 345
  • 8
  • 17
5
votes
2 answers

Defining a range for a symbol in Sympy

In Sympy it is possible to define constraints on what values a symbol may take x = symbols('x', real=True) Is it possible to say that a symbol should take values only in a certain range, say -1 < x < 1? The reason why I am interested in this is…
D R
  • 21,936
  • 38
  • 112
  • 149
1
2
3
51 52