math

Can the Diffie-Hellman protocol be used as a base for digital signatures?

I am implementing a custo crypto library using the Diffie-Hellman protocol (yes, i know about rsa/ssl/and the likes - i am using it specific purposes) and so far it turned out better than i original expected - using GMP, it's very fast. My question is, besides the obvious key exchange part, if this protocol can be used for digital signa...

Algorithm to determine non-negative-values solution existance for linear diophantine equation

Hello, I am looking for a method to determine if there is a solution to equations such as: 3n1+4n2+5n3=456, where n1,n2,n3 are positive integers. Or more general: are there zero or positive integers n1,n2,n3... that solves the equation k1n1+k2n2+k3n3...=m where k1,k2,k3... and m are known positive integers. I don't need to find a solut...

Logic question (universal and existential quantifications)

Hi there, I have a logical statement that says "If everyone plays the game, we will have fun". In formal logic we can write this as: Let D mean the people playing. Let G be the predicate for play the game. Let F be the predicate for having fun. Thus [VxeD, G(x)] -> [VyeD, F(y)] V is the computer science symbol for universal quantifi...

Calculating vertices of a rotated rectangle

Hey guys, I am trying to calculate the vertices of a rotated rectangle (2D). It's easy enough if the rectangle has not been rotated, I figured that part out. If the rectangle has been rotated, I thought of two possible ways to calculate the vertices. 1) Figure out how to transform the vertices from local/object/model space (the ones I ...

Normalizing from [0.5 - 1] to [0 - 1]

Hi all, I'm kind of stuck here, I guess it's a bit of a brain teaser. If I have numbers in the range between 0.5 to 1 how can I normalize it to be between 0 to 1? Thanks for any help, maybe I'm just a bit slow since I've been working for the past 24 hours straight O_O ...

Mathematica's Tables and Modifications in Octave?

How can I do Mathematica-style a = Table[2^(2 k) + 1, {k, 1, 3}] Last[a], First[a] Append[a,3] in Octave? ...

check if two integers sum to a third

Ok I'm doing this programming assignment and need a little help. Here is the problem: Given three ints, a b c, return true if it is possible to add two of the ints to get the third. twoAsOne(1, 2, 3) → true twoAsOne(3, 1, 2) → true twoAsOne(3, 2, 2) → false Here's the what I have gotten so far: public boolean twoAsOne(int a, int b,...

Math calculation with decimal isn't correct

I have a C# method and which accepts three string parameters. After converting them to decimal, I am trying to perform a simple math calculation. I don't understand, why isn't the result correct? decimal d = MyFunction(x, y, z); public decimal MyFunction(string x, string y, string z) { decimal dx = 0; decimal dy = 0; decim...

How to generate a lower frequency version of a signal in Matlab?

With a sine input, I tried to modify it's frequency cutting some lower frequencies in the spectrum, shifting the main frequency towards zero. As the signal is not fftshifted I tried to do that by eliminating some samples at the begin and at the end of the fft vector: interval = 1; samplingFrequency = 44100; signalFrequency = 440; sample...

Calculating the value of pi-what is wrong with my code

Hi, I'm doing another C++ exercise. I have to calculate the value of pi from the infinite series: pi=4 - 4/3 + 4/5 – 4/7 + 4/9 -4/11+ . . . The program has to print the approximate value of pi after each of the first 1,000 terms of this series. Here is my code: #include <iostream> using namespace std; int main() { double pi=0.0;...

Fast formula for a "high contrast" curve.

My inner loop contains a calculation that profiling shows to be problematic. The idea is to take a greyscale pixel x (0 <= x <= 1), and "increase its contrast". My requirements are fairly loose, just the following: for x < .5, 0 <= f(x) < x for x > .5, x < f(x) <= 1 f(0) = 0 f(x) = 1 - f(1 - x), i.e. it should be "symmetric" Preferabl...

Making a list of divisors in Haskell

Hi I am doing problem 21 in eulerproject. One part requires finding the list of proper divisors of a number. i.e. where there is remainder of n and some number of less than n. So I made this Haskell, but GHCI gets angry at me. divisors n =[ n | n <- [1..(n-1)], n `rem` [1..(n-1)] ==0 ] The problem is that I don't know how to make: n ...

Merging two statistical result sets

I have two sets of statistics generated from processing. The data from the processing can be a large amount of results so I would rather not have to store all of the data to recalculate the additional data later on. Say I have two sets of statistics that describe two different sessions of runs over a process. Each set contains Stati...

Better approximation of e with Java

I would like to approximate the value of e to any desired precision. What is the best way to do this? The most I've been able to get is e = 2.7182818284590455. Any examples on a modification of the following code would be appreciated. public static long fact(int x){ long prod = 1; for(int i = 1; i <= x; i++) prod = prod * i; retu...

Compacting mathematical graph

I want to draw a graph that will be something like this: You can see 3 pathes: a, b & c. How can I change position of elements (1,2,3...,9) to make long of the path as short as possible? I mean this lines should be as short as possible. Im very interested in it becouse I am drawing a graph with question, some kind of infographic like...

Math questions at a programmer interview?

So I went to an interview at Samsung here in Dallas, Texas. The way the recruiter described the job, he didn't make it sound like it was too math-oriented. The job basically involved graphics programming and C++. Yes, math is implied in graphics programming, especially shaders, but I still wasn't expecting this... The whole interview la...

"Concrete Mathematics" companion text? (Knuth light IOW)

I'm interested in learning more of the math behind computer science, partly so I can dip into Knuth's TAOCP without my head spinning too much. I've tried going through Concrete Mathematics but it's a little too much for me unfortunately. Are there books out there below this one but well above Math for Dummies? I own discrete math book...

Force-directed graphing

Hello, I'm trying to write a force-directed or force-atlas code base for a graphing application I'm building for myself. Here is an example of what I'm attempting: http://sawamuland.com/flash/graph.html I managed to find some pseudo code to accomplish what I'd like on the Wiki Force-atlas article. I've converted this into ActionScript ...

Why log(1000)/log(10) isn't the same as log10(1000)?

Today, I came across quite strange problem. I needed to calculate string length of a number, so I came up with this solution // say the number is 1000 (int)(log(1000)/log(10)) + 1 This is based on mathematical formula log10x = lognx/logn10 (explained here) But I found out, that in C, (int)(log(1000)/log(10)) + 1 is NOT equal to ...

Find Lines in a cloud of points

Hi I have an array of Points. I KNOW that these points represent many lines in my page. How can I find them? Do I need to find the spacing between clouds of points? Thanks Jonathan ...