
(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 8 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 (fma x (sin y) (* z (cos y))))
double code(double x, double y, double z) {
return fma(x, sin(y), (z * cos(y)));
}
function code(x, y, z) return fma(x, sin(y), Float64(z * cos(y))) end
code[x_, y_, z_] := N[(x * N[Sin[y], $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, \sin y, z \cdot \cos y\right)
\end{array}
Initial program 99.8%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-sin.f64N/A
lower-*.f64N/A
lower-cos.f6499.8
Simplified99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (sin y))) (t_1 (* z (cos y))))
(if (<= y -8.5e+216)
t_0
(if (<= y -3.7e+25)
t_1
(if (<= y 4.5e+31)
(+ t_0 (fma (* y y) (* z (fma (* y y) 0.041666666666666664 -0.5)) z))
(if (<= y 1.02e+194) t_1 t_0))))))
double code(double x, double y, double z) {
double t_0 = x * sin(y);
double t_1 = z * cos(y);
double tmp;
if (y <= -8.5e+216) {
tmp = t_0;
} else if (y <= -3.7e+25) {
tmp = t_1;
} else if (y <= 4.5e+31) {
tmp = t_0 + fma((y * y), (z * fma((y * y), 0.041666666666666664, -0.5)), z);
} else if (y <= 1.02e+194) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * sin(y)) t_1 = Float64(z * cos(y)) tmp = 0.0 if (y <= -8.5e+216) tmp = t_0; elseif (y <= -3.7e+25) tmp = t_1; elseif (y <= 4.5e+31) tmp = Float64(t_0 + fma(Float64(y * y), Float64(z * fma(Float64(y * y), 0.041666666666666664, -0.5)), z)); elseif (y <= 1.02e+194) tmp = t_1; else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -8.5e+216], t$95$0, If[LessEqual[y, -3.7e+25], t$95$1, If[LessEqual[y, 4.5e+31], N[(t$95$0 + N[(N[(y * y), $MachinePrecision] * N[(z * N[(N[(y * y), $MachinePrecision] * 0.041666666666666664 + -0.5), $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.02e+194], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \sin y\\
t_1 := z \cdot \cos y\\
\mathbf{if}\;y \leq -8.5 \cdot 10^{+216}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -3.7 \cdot 10^{+25}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 4.5 \cdot 10^{+31}:\\
\;\;\;\;t\_0 + \mathsf{fma}\left(y \cdot y, z \cdot \mathsf{fma}\left(y \cdot y, 0.041666666666666664, -0.5\right), z\right)\\
\mathbf{elif}\;y \leq 1.02 \cdot 10^{+194}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -8.4999999999999997e216 or 1.02e194 < y Initial program 99.6%
Taylor expanded in x around inf
lower-*.f64N/A
lower-sin.f6467.5
Simplified67.5%
if -8.4999999999999997e216 < y < -3.6999999999999999e25 or 4.4999999999999996e31 < y < 1.02e194Initial program 99.8%
Taylor expanded in x around 0
lower-*.f64N/A
lower-cos.f6459.3
Simplified59.3%
if -3.6999999999999999e25 < y < 4.4999999999999996e31Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
associate-*r*N/A
distribute-rgt-outN/A
+-commutativeN/A
metadata-evalN/A
sub-negN/A
lower-*.f64N/A
sub-negN/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6496.9
Simplified96.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (sin y))))
(if (<= y -3.9)
t_0
(if (<= y 12500000000000.0)
(+ (* z (cos y)) (* x (fma (* y y) (* y -0.16666666666666666) y)))
t_0))))
double code(double x, double y, double z) {
double t_0 = x * sin(y);
double tmp;
if (y <= -3.9) {
tmp = t_0;
} else if (y <= 12500000000000.0) {
tmp = (z * cos(y)) + (x * fma((y * y), (y * -0.16666666666666666), y));
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * sin(y)) tmp = 0.0 if (y <= -3.9) tmp = t_0; elseif (y <= 12500000000000.0) tmp = Float64(Float64(z * cos(y)) + Float64(x * fma(Float64(y * y), Float64(y * -0.16666666666666666), y))); 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, -3.9], t$95$0, If[LessEqual[y, 12500000000000.0], N[(N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision] + N[(x * N[(N[(y * y), $MachinePrecision] * N[(y * -0.16666666666666666), $MachinePrecision] + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \sin y\\
\mathbf{if}\;y \leq -3.9:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 12500000000000:\\
\;\;\;\;z \cdot \cos y + x \cdot \mathsf{fma}\left(y \cdot y, y \cdot -0.16666666666666666, y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -3.89999999999999991 or 1.25e13 < y Initial program 99.7%
Taylor expanded in x around inf
lower-*.f64N/A
lower-sin.f6453.7
Simplified53.7%
if -3.89999999999999991 < y < 1.25e13Initial program 99.9%
Taylor expanded in y around 0
distribute-lft-inN/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
distribute-rgt-outN/A
+-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6499.1
Simplified99.1%
Final simplification78.1%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (sin y))))
(if (<= y -1.1)
t_0
(if (<= y 1.92)
(fma
z
(fma
y
(*
y
(fma
(* y y)
(fma (* y y) -0.001388888888888889 0.041666666666666664)
-0.5))
1.0)
(*
y
(fma
y
(*
y
(fma
(* y y)
(* x (fma -0.0001984126984126984 (* y y) 0.008333333333333333))
(* x -0.16666666666666666)))
x)))
(if (<= y 1.02e+194) (* z (cos y)) t_0)))))
double code(double x, double y, double z) {
double t_0 = x * sin(y);
double tmp;
if (y <= -1.1) {
tmp = t_0;
} else if (y <= 1.92) {
tmp = fma(z, fma(y, (y * fma((y * y), fma((y * y), -0.001388888888888889, 0.041666666666666664), -0.5)), 1.0), (y * fma(y, (y * fma((y * y), (x * fma(-0.0001984126984126984, (y * y), 0.008333333333333333)), (x * -0.16666666666666666))), x)));
} else if (y <= 1.02e+194) {
tmp = z * cos(y);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * sin(y)) tmp = 0.0 if (y <= -1.1) tmp = t_0; elseif (y <= 1.92) tmp = fma(z, fma(y, Float64(y * fma(Float64(y * y), fma(Float64(y * y), -0.001388888888888889, 0.041666666666666664), -0.5)), 1.0), Float64(y * fma(y, Float64(y * fma(Float64(y * y), Float64(x * fma(-0.0001984126984126984, Float64(y * y), 0.008333333333333333)), Float64(x * -0.16666666666666666))), x))); elseif (y <= 1.02e+194) tmp = Float64(z * cos(y)); 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, -1.1], t$95$0, If[LessEqual[y, 1.92], N[(z * N[(y * N[(y * N[(N[(y * y), $MachinePrecision] * N[(N[(y * y), $MachinePrecision] * -0.001388888888888889 + 0.041666666666666664), $MachinePrecision] + -0.5), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision] + N[(y * N[(y * N[(y * N[(N[(y * y), $MachinePrecision] * N[(x * N[(-0.0001984126984126984 * N[(y * y), $MachinePrecision] + 0.008333333333333333), $MachinePrecision]), $MachinePrecision] + N[(x * -0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.02e+194], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \sin y\\
\mathbf{if}\;y \leq -1.1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.92:\\
\;\;\;\;\mathsf{fma}\left(z, \mathsf{fma}\left(y, y \cdot \mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y \cdot y, -0.001388888888888889, 0.041666666666666664\right), -0.5\right), 1\right), y \cdot \mathsf{fma}\left(y, y \cdot \mathsf{fma}\left(y \cdot y, x \cdot \mathsf{fma}\left(-0.0001984126984126984, y \cdot y, 0.008333333333333333\right), x \cdot -0.16666666666666666\right), x\right)\right)\\
\mathbf{elif}\;y \leq 1.02 \cdot 10^{+194}:\\
\;\;\;\;z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.1000000000000001 or 1.02e194 < y Initial program 99.7%
Taylor expanded in x around inf
lower-*.f64N/A
lower-sin.f6457.4
Simplified57.4%
if -1.1000000000000001 < y < 1.9199999999999999Initial program 100.0%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-sin.f64N/A
lower-*.f64N/A
lower-cos.f64100.0
Simplified100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
lower-cos.f64N/A
lower-*.f64N/A
lower-sin.f64100.0
Simplified100.0%
Taylor expanded in y around 0
+-commutativeN/A
unpow2N/A
associate-*l*N/A
lower-fma.f64N/A
lower-*.f64N/A
sub-negN/A
metadata-evalN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6499.8
Simplified99.8%
Taylor expanded in y around 0
lower-*.f64N/A
+-commutativeN/A
unpow2N/A
associate-*l*N/A
lower-fma.f64N/A
Simplified99.3%
if 1.9199999999999999 < y < 1.02e194Initial program 99.8%
Taylor expanded in x around 0
lower-*.f64N/A
lower-cos.f6456.3
Simplified56.3%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (sin y))))
(if (<= y -1.1)
t_0
(if (<= y 0.65)
(fma
z
(fma
y
(*
y
(fma
(* y y)
(fma (* y y) -0.001388888888888889 0.041666666666666664)
-0.5))
1.0)
(*
y
(fma
y
(*
y
(fma
(* y y)
(* x (fma -0.0001984126984126984 (* y y) 0.008333333333333333))
(* x -0.16666666666666666)))
x)))
t_0))))
double code(double x, double y, double z) {
double t_0 = x * sin(y);
double tmp;
if (y <= -1.1) {
tmp = t_0;
} else if (y <= 0.65) {
tmp = fma(z, fma(y, (y * fma((y * y), fma((y * y), -0.001388888888888889, 0.041666666666666664), -0.5)), 1.0), (y * fma(y, (y * fma((y * y), (x * fma(-0.0001984126984126984, (y * y), 0.008333333333333333)), (x * -0.16666666666666666))), x)));
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * sin(y)) tmp = 0.0 if (y <= -1.1) tmp = t_0; elseif (y <= 0.65) tmp = fma(z, fma(y, Float64(y * fma(Float64(y * y), fma(Float64(y * y), -0.001388888888888889, 0.041666666666666664), -0.5)), 1.0), Float64(y * fma(y, Float64(y * fma(Float64(y * y), Float64(x * fma(-0.0001984126984126984, Float64(y * y), 0.008333333333333333)), Float64(x * -0.16666666666666666))), x))); 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, -1.1], t$95$0, If[LessEqual[y, 0.65], N[(z * N[(y * N[(y * N[(N[(y * y), $MachinePrecision] * N[(N[(y * y), $MachinePrecision] * -0.001388888888888889 + 0.041666666666666664), $MachinePrecision] + -0.5), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision] + N[(y * N[(y * N[(y * N[(N[(y * y), $MachinePrecision] * N[(x * N[(-0.0001984126984126984 * N[(y * y), $MachinePrecision] + 0.008333333333333333), $MachinePrecision]), $MachinePrecision] + N[(x * -0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \sin y\\
\mathbf{if}\;y \leq -1.1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.65:\\
\;\;\;\;\mathsf{fma}\left(z, \mathsf{fma}\left(y, y \cdot \mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y \cdot y, -0.001388888888888889, 0.041666666666666664\right), -0.5\right), 1\right), y \cdot \mathsf{fma}\left(y, y \cdot \mathsf{fma}\left(y \cdot y, x \cdot \mathsf{fma}\left(-0.0001984126984126984, y \cdot y, 0.008333333333333333\right), x \cdot -0.16666666666666666\right), x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.1000000000000001 or 0.650000000000000022 < y Initial program 99.7%
Taylor expanded in x around inf
lower-*.f64N/A
lower-sin.f6453.3
Simplified53.3%
if -1.1000000000000001 < y < 0.650000000000000022Initial program 100.0%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-sin.f64N/A
lower-*.f64N/A
lower-cos.f64100.0
Simplified100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
lower-cos.f64N/A
lower-*.f64N/A
lower-sin.f64100.0
Simplified100.0%
Taylor expanded in y around 0
+-commutativeN/A
unpow2N/A
associate-*l*N/A
lower-fma.f64N/A
lower-*.f64N/A
sub-negN/A
metadata-evalN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6499.8
Simplified99.8%
Taylor expanded in y around 0
lower-*.f64N/A
+-commutativeN/A
unpow2N/A
associate-*l*N/A
lower-fma.f64N/A
Simplified99.8%
(FPCore (x y z) :precision binary64 (if (<= z -1.7e-113) z (if (<= z -1.05e-299) (* x y) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.7e-113) {
tmp = z;
} else if (z <= -1.05e-299) {
tmp = x * y;
} else {
tmp = z;
}
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 (z <= (-1.7d-113)) then
tmp = z
else if (z <= (-1.05d-299)) then
tmp = x * y
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.7e-113) {
tmp = z;
} else if (z <= -1.05e-299) {
tmp = x * y;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.7e-113: tmp = z elif z <= -1.05e-299: tmp = x * y else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.7e-113) tmp = z; elseif (z <= -1.05e-299) tmp = Float64(x * y); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.7e-113) tmp = z; elseif (z <= -1.05e-299) tmp = x * y; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.7e-113], z, If[LessEqual[z, -1.05e-299], N[(x * y), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.7 \cdot 10^{-113}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq -1.05 \cdot 10^{-299}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -1.7000000000000001e-113 or -1.05000000000000005e-299 < z Initial program 99.8%
Taylor expanded in x around 0
lower-*.f64N/A
lower-cos.f6467.5
Simplified67.5%
Taylor expanded in y around 0
Simplified45.3%
if -1.7000000000000001e-113 < z < -1.05000000000000005e-299Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f6457.8
Simplified57.8%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6448.9
Simplified48.9%
Final simplification45.7%
(FPCore (x y z) :precision binary64 (fma x y z))
double code(double x, double y, double z) {
return fma(x, y, z);
}
function code(x, y, z) return fma(x, y, z) end
code[x_, y_, z_] := N[(x * y + z), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, y, z\right)
\end{array}
Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f6454.8
Simplified54.8%
(FPCore (x y z) :precision binary64 (* x y))
double code(double x, double y, double z) {
return x * 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 * y
end function
public static double code(double x, double y, double z) {
return x * y;
}
def code(x, y, z): return x * y
function code(x, y, z) return Float64(x * y) end
function tmp = code(x, y, z) tmp = x * y; end
code[x_, y_, z_] := N[(x * y), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y
\end{array}
Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f6454.8
Simplified54.8%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6417.0
Simplified17.0%
Final simplification17.0%
herbie shell --seed 2024215
(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))))