How to solve an equation with FMOD in it

  • Context: Undergrad 
  • Thread starter Thread starter 1plus1is10
  • Start date Start date
Click For Summary

Discussion Overview

The discussion revolves around the mathematical simplification of an equation involving the FMOD function, specifically exploring whether it can be replaced with algebraic expressions. The context includes technical reasoning related to programming and mathematical functions, particularly in C and C++.

Discussion Character

  • Exploratory
  • Technical explanation
  • Mathematical reasoning

Main Points Raised

  • One participant presents the equation a = FMOD(((x*y)-z), x) / x and expresses a desire to simplify it without using FMOD.
  • Another participant suggests a transformation of the FMOD function using the formula mod(m,n) = m - n * ⌊m/n⌋.
  • A participant clarifies that in C and C++, fmod returns the floating point modulus, and questions the applicability of the proposed mod function.
  • There is a correction regarding the output of fmod(5.0, 4.0), with one participant asserting it returns 1.0 and another providing a different example to illustrate the behavior of fmod.
  • Discussion includes the challenge of performing algebra with the FLOOR function, with participants suggesting casting to integer types as a potential workaround.
  • One participant shares their "Math Notes" to illustrate their approach to algebraic manipulation, indicating a struggle with converting the FLOOR function into basic algebra.
  • A later post humorously reflects on the difficulty of replacing the FLOOR function, leading to a conclusion that it may not be feasible.

Areas of Agreement / Disagreement

Participants express differing views on the feasibility of simplifying the equation involving FMOD and the FLOOR function. There is no consensus on whether these functions can be effectively replaced with algebraic expressions.

Contextual Notes

Participants note limitations in understanding how to algebraically manipulate the FLOOR function and the implications of using floating point versus integer arithmetic in their calculations.

Who May Find This Useful

This discussion may be of interest to those working with mathematical functions in programming, particularly in C and C++, as well as individuals exploring algebraic manipulations involving modular arithmetic and floor functions.

1plus1is10
Messages
51
Reaction score
0
TL;DR
Replace FMOD with algebraic math
I have:
a = FMOD(((x*y)-z), x) / x

When I look at this, I think it could most likely be simplified algebraically if I could only replace FMOD with algebraic math.
After searching the web, I realize that this is more than I would know how to do since FMOD uses FLOOR.

Anyway, I thought I would ask here to see if my function can be simplified somehow (hopefully without FMOD).
Thanks
 
Mathematics news on Phys.org
You may transform it by function as
mod(m,n)=m-n\lfloor \frac{m}{n} \rfloor
 
  • Like
Likes   Reactions: 1plus1is10
1plus1is10 said:
Summary:: Replace FMOD with algebraic math

I have:
a = FMOD(((x*y)-z), x) / x
In C and C++, fmod is the floating point modulus. Is that how you're using this function?

If so, I don't think the mod function that @anuttarasammyak mentioned will be helpful. fmod(x, y) returns the floating point remainder of x divided by y. For example, fmod(5.0, 4.0) would return 0.25.
Correction: the return value is 1.0
 
Last edited:
  • Like
Likes   Reactions: anuttarasammyak
Actually fmod(5.0, 4.0) is 1.0 and anuttarasammyak is on the right path with converting it that way.

You can test it here
http://cpp.sh/

#include <iostream>
#include <cmath>
int main(){ std::count << fmod(5.0, 4.0); }The problem becomes, I have no idea how to do algebra with FLOOR unless it can be "transformed" or replaced somehow also.
Thanks
 
std::cout << 5.0-(4.0*floor(5.0/4.0));
 
The usual notation for FLOOR(x) is \lfloor x \rfloor.
 
Yes, I know. I just do not know math markup code.
 
1plus1is10 said:
Actually fmod(5.0, 4.0) is 1.0
Bad example from me, caused by not checking some code and from not using this function for a long time. The mod function returns an integer, but fmod's return value is a double or a float, depending on the arguments to it, that may or may not be the float/double equivalent of an integer.
Here's a better example to show what I mean:
C:
double rem = fmod(3.5, 3.0);
After execution, rem will be set to 0.5.
 
  • Like
Likes   Reactions: 1plus1is10
1plus1is10 said:
The problem becomes, I have no idea how to do algebra with FLOOR unless it can be "transformed" or replaced somehow also.
You can cast a float or double to type int, which will get rid of any fraction part, which is equivalent to what floor() does.
For example:
C:
double dVal = 4.3;
int iVal = static_cast<int>(dVal);
iVal will be set to 4 .
 
  • #10
Mark44,
I appreciate the fact you know C++ which is what I use to perform calculations. But this for me really is a "converting-to-basic-algebra" problem at the moment.

I'm posting my "Math Notes" for you to get an idea of what I typically use to help me:
[CODE title="Math Notes"] A1 A2 A3 A4
(x/y)*z = x/(y/z) = x*(z/y) = (x*z)/y
(1/2)*3 = 1/(2/3) = 1*(3/2) = (1*3)/2
0.5*3 = 1/0.666 = 1*1.5 = 3/2
1.5 = 1.5 = 1.5 = 1.5

B1 B2 B3 B4:B3 B5:B4,A3,A2 B6:B5,B1,B2 B7:B6,A3,A2
(x/y)/z = x/(y*z) = (x/z)/y = (1/y)*(x/z) = (1/y)/(z/x) = 1/(y*(z/x)) = 1/(y/(x/z))
(1/2)/3 = 1/(2*3) = (1/3)/2 = (1/2)*(1/3) = (1/2)/(3/1) = 1/(2*(3/1)) = 1/(2/(1/3))
0.5/3 = 1/6 = 0.333/2 = 0.5*0.333 = 0.5/3 = 1/(2*3) = 1/(2/0.333)
0.1666 = 0.1666 = 0.1666 = 0.1666 = 0.1666 = 0.1666 = 0.1666

1=A1 1=A2 1=A3 1=A4
a=(x/y)*z, a=x/(y/z), a=x*(z/y), a=(x*z)/y
a/z=(x/y), a*(y/z)=x, a/(z/y)=x, a*y=(x*z)
1/z=(x/y), 1*(y/z)=x, 1/(z/y)=x, 1*y=(x*z)
^ (y/z)=x, <-x-^ y=(x*z)=(z*x)
^ (y/z)=1/(z/y), y/x=z
1/(y/x)=(x/y) <--substitute z---------^

1=B1 1=B2 1=B3 1=B4
a=(x/y)/z, a=x/(y*z), a=(x/z)/y, a=(1/y)/(z/x)
a*z=(x/y), a*(y*z)=x, a*y=(x/z), a*(z/x)=(1/y)
1*z=(x/y), 1*(y*z)=x, 1*y=(x/z), 1*(z/x)=(1/y)
z=(x/y), (y*z)=x, y=(x/z), (z/x)=(1/y) sub y (z/x)=1/(x/z)
z*y=x, y=x/z, y*z=x z=(1/y)*x sub z (x/y)=(1/y)*x[/CODE]

And, of course, I am aware that not everything can be converted to basic algebra (oh well).
But if FLOOR can be, then that would be nice.
Thanks, again.
 
  • #11

Similar threads

  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 14 ·
Replies
14
Views
2K
  • · Replies 8 ·
Replies
8
Views
1K
  • · Replies 26 ·
Replies
26
Views
3K
  • · Replies 3 ·
Replies
3
Views
1K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 13 ·
Replies
13
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 16 ·
Replies
16
Views
3K