
(FPCore (x y z) :precision binary64 (+ (* x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
return (x * sin(y)) + (z * cos(y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * sin(y)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z): return (x * math.sin(y)) + (z * math.cos(y))
function code(x, y, z) return Float64(Float64(x * sin(y)) + Float64(z * cos(y))) end
function tmp = code(x, y, z) tmp = (x * sin(y)) + (z * cos(y)); end
code[x_, y_, z_] := N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \sin y + z \cdot \cos y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
return (x * sin(y)) + (z * cos(y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * sin(y)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z): return (x * math.sin(y)) + (z * math.cos(y))
function code(x, y, z) return Float64(Float64(x * sin(y)) + Float64(z * cos(y))) end
function tmp = code(x, y, z) tmp = (x * sin(y)) + (z * cos(y)); end
code[x_, y_, z_] := N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \sin y + z \cdot \cos y
\end{array}
(FPCore (x y z) :precision binary64 (+ (* x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
return (x * sin(y)) + (z * cos(y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * sin(y)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z): return (x * math.sin(y)) + (z * math.cos(y))
function code(x, y, z) return Float64(Float64(x * sin(y)) + Float64(z * cos(y))) end
function tmp = code(x, y, z) tmp = (x * sin(y)) + (z * cos(y)); end
code[x_, y_, z_] := N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \sin y + z \cdot \cos y
\end{array}
Initial program 99.8%
(FPCore (x y z) :precision binary64 (fma (cos y) z (* x (sin y))))
double code(double x, double y, double z) {
return fma(cos(y), z, (x * sin(y)));
}
function code(x, y, z) return fma(cos(y), z, Float64(x * sin(y))) end
code[x_, y_, z_] := N[(N[Cos[y], $MachinePrecision] * z + N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\cos y, z, x \cdot \sin y\right)
\end{array}
Initial program 99.8%
lift-sin.f64N/A
lift-cos.f64N/A
lift-*.f64N/A
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.8
Applied egg-rr99.8%
(FPCore (x y z) :precision binary64 (if (<= x -1.8e-40) (fma (sin y) x z) (if (<= x 3.3e+87) (* z (cos y)) (+ (* x (sin y)) z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.8e-40) {
tmp = fma(sin(y), x, z);
} else if (x <= 3.3e+87) {
tmp = z * cos(y);
} else {
tmp = (x * sin(y)) + z;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -1.8e-40) tmp = fma(sin(y), x, z); elseif (x <= 3.3e+87) tmp = Float64(z * cos(y)); else tmp = Float64(Float64(x * sin(y)) + z); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -1.8e-40], N[(N[Sin[y], $MachinePrecision] * x + z), $MachinePrecision], If[LessEqual[x, 3.3e+87], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.8 \cdot 10^{-40}:\\
\;\;\;\;\mathsf{fma}\left(\sin y, x, z\right)\\
\mathbf{elif}\;x \leq 3.3 \cdot 10^{+87}:\\
\;\;\;\;z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \sin y + z\\
\end{array}
\end{array}
if x < -1.8e-40Initial program 99.9%
lift-sin.f64N/A
lift-cos.f64N/A
lift-*.f64N/A
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.9
Applied egg-rr99.9%
Taylor expanded in y around 0
Simplified88.9%
lift-sin.f64N/A
lift-*.f64N/A
*-lft-identityN/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6488.9
Applied egg-rr88.9%
if -1.8e-40 < x < 3.3000000000000001e87Initial program 99.8%
Taylor expanded in x around 0
lower-*.f64N/A
lower-cos.f6482.1
Simplified82.1%
if 3.3000000000000001e87 < x Initial program 99.8%
lift-sin.f64N/A
lift-cos.f64N/A
lift-*.f64N/A
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.8
Applied egg-rr99.8%
Taylor expanded in y around 0
Simplified92.2%
lift-sin.f64N/A
lift-*.f64N/A
*-lft-identityN/A
+-commutativeN/A
lower-+.f6492.2
lift-*.f64N/A
*-commutativeN/A
lift-*.f6492.2
Applied egg-rr92.2%
Final simplification85.8%
(FPCore (x y z) :precision binary64 (let* ((t_0 (fma (sin y) x z))) (if (<= x -3.1e-40) t_0 (if (<= x 2.7e+93) (* z (cos y)) t_0))))
double code(double x, double y, double z) {
double t_0 = fma(sin(y), x, z);
double tmp;
if (x <= -3.1e-40) {
tmp = t_0;
} else if (x <= 2.7e+93) {
tmp = z * cos(y);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = fma(sin(y), x, z) tmp = 0.0 if (x <= -3.1e-40) tmp = t_0; elseif (x <= 2.7e+93) tmp = Float64(z * cos(y)); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Sin[y], $MachinePrecision] * x + z), $MachinePrecision]}, If[LessEqual[x, -3.1e-40], t$95$0, If[LessEqual[x, 2.7e+93], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\sin y, x, z\right)\\
\mathbf{if}\;x \leq -3.1 \cdot 10^{-40}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 2.7 \cdot 10^{+93}:\\
\;\;\;\;z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -3.10000000000000011e-40 or 2.6999999999999999e93 < x Initial program 99.9%
lift-sin.f64N/A
lift-cos.f64N/A
lift-*.f64N/A
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.9
Applied egg-rr99.9%
Taylor expanded in y around 0
Simplified90.3%
lift-sin.f64N/A
lift-*.f64N/A
*-lft-identityN/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6490.3
Applied egg-rr90.3%
if -3.10000000000000011e-40 < x < 2.6999999999999999e93Initial program 99.8%
Taylor expanded in x around 0
lower-*.f64N/A
lower-cos.f6482.1
Simplified82.1%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (sin y)))) (if (<= x -2.9e+30) t_0 (if (<= x 1.25e+97) (* z (cos y)) t_0))))
double code(double x, double y, double z) {
double t_0 = x * sin(y);
double tmp;
if (x <= -2.9e+30) {
tmp = t_0;
} else if (x <= 1.25e+97) {
tmp = z * cos(y);
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = x * sin(y)
if (x <= (-2.9d+30)) then
tmp = t_0
else if (x <= 1.25d+97) then
tmp = z * cos(y)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * Math.sin(y);
double tmp;
if (x <= -2.9e+30) {
tmp = t_0;
} else if (x <= 1.25e+97) {
tmp = z * Math.cos(y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * math.sin(y) tmp = 0 if x <= -2.9e+30: tmp = t_0 elif x <= 1.25e+97: tmp = z * math.cos(y) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * sin(y)) tmp = 0.0 if (x <= -2.9e+30) tmp = t_0; elseif (x <= 1.25e+97) tmp = Float64(z * cos(y)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * sin(y); tmp = 0.0; if (x <= -2.9e+30) tmp = t_0; elseif (x <= 1.25e+97) tmp = z * cos(y); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -2.9e+30], t$95$0, If[LessEqual[x, 1.25e+97], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \sin y\\
\mathbf{if}\;x \leq -2.9 \cdot 10^{+30}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.25 \cdot 10^{+97}:\\
\;\;\;\;z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -2.8999999999999998e30 or 1.25e97 < x Initial program 99.9%
Taylor expanded in x around inf
lower-*.f64N/A
lower-sin.f6475.9
Simplified75.9%
if -2.8999999999999998e30 < x < 1.25e97Initial program 99.8%
Taylor expanded in x around 0
lower-*.f64N/A
lower-cos.f6481.4
Simplified81.4%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (sin y))))
(if (<= y -0.92)
t_0
(if (<= y 0.45)
(+
(*
x
(fma
(fma
(* y y)
(fma (* y y) -0.0001984126984126984 0.008333333333333333)
-0.16666666666666666)
(* y (* y y))
y))
(fma
(* z (* y y))
(fma
(* y y)
(fma y (* y -0.001388888888888889) 0.041666666666666664)
-0.5)
z))
t_0))))
double code(double x, double y, double z) {
double t_0 = x * sin(y);
double tmp;
if (y <= -0.92) {
tmp = t_0;
} else if (y <= 0.45) {
tmp = (x * fma(fma((y * y), fma((y * y), -0.0001984126984126984, 0.008333333333333333), -0.16666666666666666), (y * (y * y)), y)) + fma((z * (y * y)), fma((y * y), fma(y, (y * -0.001388888888888889), 0.041666666666666664), -0.5), z);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * sin(y)) tmp = 0.0 if (y <= -0.92) tmp = t_0; elseif (y <= 0.45) tmp = Float64(Float64(x * fma(fma(Float64(y * y), fma(Float64(y * y), -0.0001984126984126984, 0.008333333333333333), -0.16666666666666666), Float64(y * Float64(y * y)), y)) + fma(Float64(z * Float64(y * y)), fma(Float64(y * y), fma(y, Float64(y * -0.001388888888888889), 0.041666666666666664), -0.5), z)); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -0.92], t$95$0, If[LessEqual[y, 0.45], N[(N[(x * N[(N[(N[(y * y), $MachinePrecision] * N[(N[(y * y), $MachinePrecision] * -0.0001984126984126984 + 0.008333333333333333), $MachinePrecision] + -0.16666666666666666), $MachinePrecision] * N[(y * N[(y * y), $MachinePrecision]), $MachinePrecision] + y), $MachinePrecision]), $MachinePrecision] + N[(N[(z * N[(y * y), $MachinePrecision]), $MachinePrecision] * N[(N[(y * y), $MachinePrecision] * N[(y * N[(y * -0.001388888888888889), $MachinePrecision] + 0.041666666666666664), $MachinePrecision] + -0.5), $MachinePrecision] + z), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \sin y\\
\mathbf{if}\;y \leq -0.92:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.45:\\
\;\;\;\;x \cdot \mathsf{fma}\left(\mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y \cdot y, -0.0001984126984126984, 0.008333333333333333\right), -0.16666666666666666\right), y \cdot \left(y \cdot y\right), y\right) + \mathsf{fma}\left(z \cdot \left(y \cdot y\right), \mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y, y \cdot -0.001388888888888889, 0.041666666666666664\right), -0.5\right), z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -0.92000000000000004 or 0.450000000000000011 < y Initial program 99.7%
Taylor expanded in x around inf
lower-*.f64N/A
lower-sin.f6450.4
Simplified50.4%
if -0.92000000000000004 < y < 0.450000000000000011Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
Simplified100.0%
Taylor expanded in y around 0
+-commutativeN/A
distribute-rgt-inN/A
*-commutativeN/A
associate-*l*N/A
*-lft-identityN/A
lower-fma.f64N/A
Simplified99.9%
(FPCore (x y z) :precision binary64 (if (<= x -1.14e+55) (* x y) (if (<= x 3.8e+85) z (* x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.14e+55) {
tmp = x * y;
} else if (x <= 3.8e+85) {
tmp = z;
} else {
tmp = x * y;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (x <= (-1.14d+55)) then
tmp = x * y
else if (x <= 3.8d+85) then
tmp = z
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.14e+55) {
tmp = x * y;
} else if (x <= 3.8e+85) {
tmp = z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.14e+55: tmp = x * y elif x <= 3.8e+85: tmp = z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.14e+55) tmp = Float64(x * y); elseif (x <= 3.8e+85) tmp = z; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.14e+55) tmp = x * y; elseif (x <= 3.8e+85) tmp = z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.14e+55], N[(x * y), $MachinePrecision], If[LessEqual[x, 3.8e+85], z, N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.14 \cdot 10^{+55}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 3.8 \cdot 10^{+85}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -1.1399999999999999e55 or 3.79999999999999992e85 < x Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6445.8
Simplified45.8%
Taylor expanded in y around inf
lower-*.f6432.9
Simplified32.9%
if -1.1399999999999999e55 < x < 3.79999999999999992e85Initial program 99.8%
Taylor expanded in x around 0
lower-*.f64N/A
lower-cos.f6480.8
Simplified80.8%
Taylor expanded in y around 0
Simplified48.6%
*-rgt-identity48.6
Applied egg-rr48.6%
(FPCore (x y z) :precision binary64 (fma y x z))
double code(double x, double y, double z) {
return fma(y, x, z);
}
function code(x, y, z) return fma(y, x, z) end
code[x_, y_, z_] := N[(y * x + z), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, x, z\right)
\end{array}
Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6447.9
Simplified47.9%
(FPCore (x y z) :precision binary64 z)
double code(double x, double y, double z) {
return z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z
end function
public static double code(double x, double y, double z) {
return z;
}
def code(x, y, z): return z
function code(x, y, z) return z end
function tmp = code(x, y, z) tmp = z; end
code[x_, y_, z_] := z
\begin{array}{l}
\\
z
\end{array}
Initial program 99.8%
Taylor expanded in x around 0
lower-*.f64N/A
lower-cos.f6459.1
Simplified59.1%
Taylor expanded in y around 0
Simplified35.8%
*-rgt-identity35.8
Applied egg-rr35.8%
herbie shell --seed 2024212
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutX from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ (* x (sin y)) (* z (cos y))))