Math Is Fun Forum

  Discussion about math, puzzles, games and fun.   Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ -¹ ² ³ °

You are not logged in.

#1 2020-06-29 01:19:25

pi_cubed
Member
From: A rhombicosidodecahedron
Registered: 2020-06-22
Posts: 115

How would I write an if statement in an equation?

I am wondering how you would write if statements, as shown below in Python, in an equation.

a = 1+2
b = 2+1
if a == b:
    print('1+2=2+1')
elif not a == b:
    print('1+2 does not equal 2+1 and this will never be printed')
else:
    print('This will never be printed just like the above')

Does anyone know how to do this (maybe with the sign function)?


pi³

Offline

#2 2020-06-29 13:48:55

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,996
Website

Re: How would I write an if statement in an equation?

is this related? https://www.mathsisfun.com/sets/functions-piecewise.html


'And fun? If maths is fun, then getting a tooth extraction is fun. A viral infection is fun. Rabies shots are fun.'
'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'
I'm not crazy, my mother had me tested.

Offline

#3 2020-06-29 19:32:19

Bob
Administrator
Registered: 2010-06-20
Posts: 10,623

Re: How would I write an if statement in an equation?

hi pi_cubed

What do you want this for?  That might help me to provide an answer.

An 'equation' in algebra has a left hand expression and a right hand expression that evaluate to the same thing.  'If' isn't part of any equation I've met in algebra.  If … then does form part of the language of maths but not in the way you want (I think).

In logic there's a connective, =>  implies  that might fit the bill.  And you can form logic equations with implies in them. But the truth table for implies is simply described as TRUE unless the LHS is TRUE and the RHS FALSE.  I could probably construct a logic equivalent to your code if that would help.

Bob


Children are not defined by school ...........The Fonz
You cannot teach a man anything;  you can only help him find it within himself..........Galileo Galilei
Sometimes I deliberately make mistakes, just to test you!  …………….Bob smile

Offline

#4 2020-06-30 01:14:45

pi_cubed
Member
From: A rhombicosidodecahedron
Registered: 2020-06-22
Posts: 115

Re: How would I write an if statement in an equation?

Agnishom wrote:

is this related? https://www.mathsisfun.com/sets/functions-piecewise.html

Yes, that was exactly what I was talking about.


pi³

Offline

#5 2020-06-30 01:22:30

pi_cubed
Member
From: A rhombicosidodecahedron
Registered: 2020-06-22
Posts: 115

Re: How would I write an if statement in an equation?

bob bundy wrote:

hi pi_cubed

What do you want this for?  That might help me to provide an answer.

An 'equation' in algebra has a left hand expression and a right hand expression that evaluate to the same thing.  'If' isn't part of any equation I've met in algebra.  If … then does form part of the language of maths but not in the way you want (I think).

In logic there's a connective, =>  implies  that might fit the bill.  And you can form logic equations with implies in them. But the truth table for implies is simply described as TRUE unless the LHS is TRUE and the RHS FALSE.  I could probably construct a logic equivalent to your code if that would help.

Bob

I don't mean that it has to be an equation, it could be a type of function or a relationship. Piecewise functions should be enough.


pi³

Offline

#6 2020-06-30 12:56:02

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,996
Website

Re: How would I write an if statement in an equation?

Actually, piecewise functions are really just notation. Do you know how functions are usually viewed in modern mathematics?


'And fun? If maths is fun, then getting a tooth extraction is fun. A viral infection is fun. Rabies shots are fun.'
'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'
I'm not crazy, my mother had me tested.

Offline

Board footer

Powered by FluxBB