Euler's Identity in 3

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Euler's Identity in 3

gepr
So, I'm trying to learn Rust. And in thinking about the ontological status of mathematical representations of waves (https://arxiv.org/abs/2101.10873), I figured I'd validate Euler's identity:

fn main() {
  let e = num::complex::Complex::new(std::f32::consts::E,0.);
  let e2ip = e.powc(num::complex::Complex::new(0.,std::f32::consts::PI));
  let i = num::complex::Complex::new(0.,1.);
  println!("ln(e^iπ) = {}",e2ip.ln());
  println!("ln(-1) = {}", i.powi(2).ln());
}
$ cargo run
ln(e^iπ) = 0+3.1415925i
ln(-1) = 0+3.141592653589793i

I don't have any idea if that's a reasonable way to do that, since I'm ignorant of Rust. But it's interesting to contrast it with R and Sage:

$ Rscript -e "log(exp(1)^((0+1i)*pi));log((0+1i)^2)"
[1] 0+3.141593i
[1] 0+3.141593i

sage: numerical_approx(ln(e^(i*pi)));numerical_approx(ln(i^2))
3.14159265358979*I
3.14159265358979*I

The precision difference between the 2 results in Rust is interesting. It's the same if I use powf() instead of powi(). Any clues? Or should I simply RTFM?

--
↙↙↙ uǝlƃ

- .... . -..-. . -. -.. -..-. .. ... -..-. .... . .-. .
FRIAM Applied Complexity Group listserv
Zoom Fridays 9:30a-12p Mtn GMT-6  bit.ly/virtualfriam
un/subscribe http://redfish.com/mailman/listinfo/friam_redfish.com
FRIAM-COMIC http://friam-comic.blogspot.com/
archives: http://friam.471366.n2.nabble.com/
uǝʃƃ ⊥ glen
Reply | Threaded
Open this post in threaded view
|

Re: Euler's Identity in 3

gepr
Bah! I'm an idiot. If I use f64, I get:

ln(e^iπ) = 0+3.141592653589793i
ln(-1) = 0+3.141592653589793i


On 3/9/21 12:54 PM, uǝlƃ ↙↙↙ wrote:

> So, I'm trying to learn Rust. And in thinking about the ontological status of mathematical representations of waves (https://arxiv.org/abs/2101.10873), I figured I'd validate Euler's identity:
>
> fn main() {
>   let e = num::complex::Complex::new(std::f32::consts::E,0.);
>   let e2ip = e.powc(num::complex::Complex::new(0.,std::f32::consts::PI));
>   let i = num::complex::Complex::new(0.,1.);
>   println!("ln(e^iπ) = {}",e2ip.ln());
>   println!("ln(-1) = {}", i.powi(2).ln());
> }
> $ cargo run
> ln(e^iπ) = 0+3.1415925i
> ln(-1) = 0+3.141592653589793i
>
> I don't have any idea if that's a reasonable way to do that, since I'm ignorant of Rust. But it's interesting to contrast it with R and Sage:
>
> $ Rscript -e "log(exp(1)^((0+1i)*pi));log((0+1i)^2)"
> [1] 0+3.141593i
> [1] 0+3.141593i
>
> sage: numerical_approx(ln(e^(i*pi)));numerical_approx(ln(i^2))
> 3.14159265358979*I
> 3.14159265358979*I
>
> The precision difference between the 2 results in Rust is interesting. It's the same if I use powf() instead of powi(). Any clues? Or should I simply RTFM?
>

--
↙↙↙ uǝlƃ

- .... . -..-. . -. -.. -..-. .. ... -..-. .... . .-. .
FRIAM Applied Complexity Group listserv
Zoom Fridays 9:30a-12p Mtn GMT-6  bit.ly/virtualfriam
un/subscribe http://redfish.com/mailman/listinfo/friam_redfish.com
FRIAM-COMIC http://friam-comic.blogspot.com/
archives: http://friam.471366.n2.nabble.com/
uǝʃƃ ⊥ glen
Reply | Threaded
Open this post in threaded view
|

Re: Euler's Identity in 3

Marcus G. Daniels
In reply to this post by gepr
Or,

$ ginsh
ginsh - GiNaC Interactive Shell (GiNaC V1.7.11)
  __,  _______  Copyright (C) 1999-2020 Johannes Gutenberg University Mainz,
 (__) *       | Germany.  This is free software with ABSOLUTELY NO WARRANTY.
  ._) i N a C | You are welcome to redistribute it under certain conditions.
<-------------' For details type `warranty;'.

Type ?? for a list of help topics.
> exp(Pi*I);
-1
>

-----Original Message-----
From: Friam <[hidden email]> On Behalf Of u?l? ???
Sent: Tuesday, March 9, 2021 12:55 PM
To: FriAM <[hidden email]>
Subject: [FRIAM] Euler's Identity in 3

So, I'm trying to learn Rust. And in thinking about the ontological status of mathematical representations of waves (https://arxiv.org/abs/2101.10873), I figured I'd validate Euler's identity:

fn main() {
  let e = num::complex::Complex::new(std::f32::consts::E,0.);
  let e2ip = e.powc(num::complex::Complex::new(0.,std::f32::consts::PI));
  let i = num::complex::Complex::new(0.,1.);
  println!("ln(e^iπ) = {}",e2ip.ln());
  println!("ln(-1) = {}", i.powi(2).ln()); } $ cargo run
ln(e^iπ) = 0+3.1415925i
ln(-1) = 0+3.141592653589793i

I don't have any idea if that's a reasonable way to do that, since I'm ignorant of Rust. But it's interesting to contrast it with R and Sage:

$ Rscript -e "log(exp(1)^((0+1i)*pi));log((0+1i)^2)"
[1] 0+3.141593i
[1] 0+3.141593i

sage: numerical_approx(ln(e^(i*pi)));numerical_approx(ln(i^2))
3.14159265358979*I
3.14159265358979*I

The precision difference between the 2 results in Rust is interesting. It's the same if I use powf() instead of powi(). Any clues? Or should I simply RTFM?

--
↙↙↙ uǝlƃ

- .... . -..-. . -. -.. -..-. .. ... -..-. .... . .-. .
FRIAM Applied Complexity Group listserv
Zoom Fridays 9:30a-12p Mtn GMT-6  bit.ly/virtualfriam un/subscribe http://redfish.com/mailman/listinfo/friam_redfish.com
FRIAM-COMIC http://friam-comic.blogspot.com/
archives: http://friam.471366.n2.nabble.com/
- .... . -..-. . -. -.. -..-. .. ... -..-. .... . .-. .
FRIAM Applied Complexity Group listserv
Zoom Fridays 9:30a-12p Mtn GMT-6  bit.ly/virtualfriam
un/subscribe http://redfish.com/mailman/listinfo/friam_redfish.com
FRIAM-COMIC http://friam-comic.blogspot.com/
archives: http://friam.471366.n2.nabble.com/
Reply | Threaded
Open this post in threaded view
|

Re: Euler's Identity in 3

gepr
From the (hilarious) FAQ:

$ for i in `seq 1 100`; do echo "a = x; b = y; x-y;"|ginsh; done |sort -n |uniq
x
x-y
y
-y+x

I think I'm in love!

On 3/9/21 2:20 PM, Marcus Daniels wrote:

> Or,
>
> $ ginsh
> ginsh - GiNaC Interactive Shell (GiNaC V1.7.11)
>   __,  _______  Copyright (C) 1999-2020 Johannes Gutenberg University Mainz,
>  (__) *       | Germany.  This is free software with ABSOLUTELY NO WARRANTY.
>   ._) i N a C | You are welcome to redistribute it under certain conditions.
> <-------------' For details type `warranty;'.
>
> Type ?? for a list of help topics.
>> exp(Pi*I);
> -1
>>
>

--
↙↙↙ uǝlƃ

- .... . -..-. . -. -.. -..-. .. ... -..-. .... . .-. .
FRIAM Applied Complexity Group listserv
Zoom Fridays 9:30a-12p Mtn GMT-6  bit.ly/virtualfriam
un/subscribe http://redfish.com/mailman/listinfo/friam_redfish.com
FRIAM-COMIC http://friam-comic.blogspot.com/
archives: http://friam.471366.n2.nabble.com/
uǝʃƃ ⊥ glen