
(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 (fma (sin y) x (* z (cos y))))
double code(double x, double y, double z) {
return fma(sin(y), x, (z * cos(y)));
}
function code(x, y, z) return fma(sin(y), x, Float64(z * cos(y))) end
code[x_, y_, z_] := N[(N[Sin[y], $MachinePrecision] * x + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\sin y, x, z \cdot \cos y\right)
\end{array}
Initial program 99.8%
lift-sin.f64N/A
lift-cos.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.8
Applied egg-rr99.8%
(FPCore (x y z) :precision binary64 (fma (cos y) z (* (sin y) x)))
double code(double x, double y, double z) {
return fma(cos(y), z, (sin(y) * x));
}
function code(x, y, z) return fma(cos(y), z, Float64(sin(y) * x)) end
code[x_, y_, z_] := N[(N[Cos[y], $MachinePrecision] * z + N[(N[Sin[y], $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\cos y, z, \sin y \cdot x\right)
\end{array}
Initial program 99.8%
lift-sin.f64N/A
lift-*.f64N/A
lift-cos.f64N/A
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.8
Applied egg-rr99.8%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (cos y))))
(if (<= y -0.32)
t_0
(if (<= y 0.27)
(fma
(fma
(fma
(* y y)
(fma (* y y) -0.0001984126984126984 0.008333333333333333)
-0.16666666666666666)
(* y (* y y))
y)
x
(fma z (* (* y y) -0.5) z))
(if (<= y 3.7e+106) t_0 (* (sin y) x))))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double tmp;
if (y <= -0.32) {
tmp = t_0;
} else if (y <= 0.27) {
tmp = fma(fma(fma((y * y), fma((y * y), -0.0001984126984126984, 0.008333333333333333), -0.16666666666666666), (y * (y * y)), y), x, fma(z, ((y * y) * -0.5), z));
} else if (y <= 3.7e+106) {
tmp = t_0;
} else {
tmp = sin(y) * x;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(z * cos(y)) tmp = 0.0 if (y <= -0.32) tmp = t_0; elseif (y <= 0.27) tmp = fma(fma(fma(Float64(y * y), fma(Float64(y * y), -0.0001984126984126984, 0.008333333333333333), -0.16666666666666666), Float64(y * Float64(y * y)), y), x, fma(z, Float64(Float64(y * y) * -0.5), z)); elseif (y <= 3.7e+106) tmp = t_0; else tmp = Float64(sin(y) * x); end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -0.32], t$95$0, If[LessEqual[y, 0.27], N[(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] * x + N[(z * N[(N[(y * y), $MachinePrecision] * -0.5), $MachinePrecision] + z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 3.7e+106], t$95$0, N[(N[Sin[y], $MachinePrecision] * x), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;y \leq -0.32:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.27:\\
\;\;\;\;\mathsf{fma}\left(\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), x, \mathsf{fma}\left(z, \left(y \cdot y\right) \cdot -0.5, z\right)\right)\\
\mathbf{elif}\;y \leq 3.7 \cdot 10^{+106}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\sin y \cdot x\\
\end{array}
\end{array}
if y < -0.320000000000000007 or 0.27000000000000002 < y < 3.69999999999999995e106Initial program 99.5%
Taylor expanded in x around 0
lower-*.f64N/A
lower-cos.f6460.5
Simplified60.5%
if -0.320000000000000007 < y < 0.27000000000000002Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6499.6
Simplified99.6%
Taylor expanded in y around 0
+-commutativeN/A
distribute-rgt-inN/A
associate-*l*N/A
*-lft-identityN/A
lower-fma.f64N/A
Simplified99.6%
Applied egg-rr99.6%
if 3.69999999999999995e106 < y Initial program 99.6%
Taylor expanded in x around inf
lower-*.f64N/A
lower-sin.f6459.3
Simplified59.3%
Final simplification81.1%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* z (cos y)))) (if (<= z -5.2e+27) t_0 (if (<= z 1.15e-64) (+ z (* (sin y) x)) t_0))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double tmp;
if (z <= -5.2e+27) {
tmp = t_0;
} else if (z <= 1.15e-64) {
tmp = z + (sin(y) * x);
} 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 = z * cos(y)
if (z <= (-5.2d+27)) then
tmp = t_0
else if (z <= 1.15d-64) then
tmp = z + (sin(y) * x)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = z * Math.cos(y);
double tmp;
if (z <= -5.2e+27) {
tmp = t_0;
} else if (z <= 1.15e-64) {
tmp = z + (Math.sin(y) * x);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * math.cos(y) tmp = 0 if z <= -5.2e+27: tmp = t_0 elif z <= 1.15e-64: tmp = z + (math.sin(y) * x) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z * cos(y)) tmp = 0.0 if (z <= -5.2e+27) tmp = t_0; elseif (z <= 1.15e-64) tmp = Float64(z + Float64(sin(y) * x)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * cos(y); tmp = 0.0; if (z <= -5.2e+27) tmp = t_0; elseif (z <= 1.15e-64) tmp = z + (sin(y) * x); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -5.2e+27], t$95$0, If[LessEqual[z, 1.15e-64], N[(z + N[(N[Sin[y], $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;z \leq -5.2 \cdot 10^{+27}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 1.15 \cdot 10^{-64}:\\
\;\;\;\;z + \sin y \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -5.20000000000000018e27 or 1.1500000000000001e-64 < z Initial program 99.7%
Taylor expanded in x around 0
lower-*.f64N/A
lower-cos.f6482.2
Simplified82.2%
if -5.20000000000000018e27 < z < 1.1500000000000001e-64Initial program 99.9%
Taylor expanded in y around 0
Simplified92.0%
Final simplification87.1%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* z (cos y)))) (if (<= z -5.2e+27) t_0 (if (<= z 1.15e-64) (fma (sin y) x z) t_0))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double tmp;
if (z <= -5.2e+27) {
tmp = t_0;
} else if (z <= 1.15e-64) {
tmp = fma(sin(y), x, z);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(z * cos(y)) tmp = 0.0 if (z <= -5.2e+27) tmp = t_0; elseif (z <= 1.15e-64) tmp = fma(sin(y), x, z); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -5.2e+27], t$95$0, If[LessEqual[z, 1.15e-64], N[(N[Sin[y], $MachinePrecision] * x + z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;z \leq -5.2 \cdot 10^{+27}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 1.15 \cdot 10^{-64}:\\
\;\;\;\;\mathsf{fma}\left(\sin y, x, z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -5.20000000000000018e27 or 1.1500000000000001e-64 < z Initial program 99.7%
Taylor expanded in x around 0
lower-*.f64N/A
lower-cos.f6482.2
Simplified82.2%
if -5.20000000000000018e27 < z < 1.1500000000000001e-64Initial program 99.9%
lift-sin.f64N/A
lift-*.f64N/A
lift-cos.f64N/A
lift-*.f64N/A
flip-+N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
flip-+N/A
lift-+.f64N/A
lower-/.f6499.6
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
Applied egg-rr99.6%
Taylor expanded in y around 0
Simplified91.7%
lift-sin.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
remove-double-div92.0
lift-fma.f64N/A
*-rgt-identityN/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6492.0
Applied egg-rr92.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (sin y) x)))
(if (<= y -0.39)
t_0
(if (<= y 4.5e+16)
(fma
(fma
(fma
(* y y)
(fma (* y y) -0.0001984126984126984 0.008333333333333333)
-0.16666666666666666)
(* y (* y y))
y)
x
(fma z (* (* y y) -0.5) z))
t_0))))
double code(double x, double y, double z) {
double t_0 = sin(y) * x;
double tmp;
if (y <= -0.39) {
tmp = t_0;
} else if (y <= 4.5e+16) {
tmp = fma(fma(fma((y * y), fma((y * y), -0.0001984126984126984, 0.008333333333333333), -0.16666666666666666), (y * (y * y)), y), x, fma(z, ((y * y) * -0.5), z));
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(sin(y) * x) tmp = 0.0 if (y <= -0.39) tmp = t_0; elseif (y <= 4.5e+16) tmp = fma(fma(fma(Float64(y * y), fma(Float64(y * y), -0.0001984126984126984, 0.008333333333333333), -0.16666666666666666), Float64(y * Float64(y * y)), y), x, fma(z, Float64(Float64(y * y) * -0.5), z)); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Sin[y], $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[y, -0.39], t$95$0, If[LessEqual[y, 4.5e+16], N[(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] * x + N[(z * N[(N[(y * y), $MachinePrecision] * -0.5), $MachinePrecision] + z), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin y \cdot x\\
\mathbf{if}\;y \leq -0.39:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 4.5 \cdot 10^{+16}:\\
\;\;\;\;\mathsf{fma}\left(\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), x, \mathsf{fma}\left(z, \left(y \cdot y\right) \cdot -0.5, z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -0.39000000000000001 or 4.5e16 < y Initial program 99.5%
Taylor expanded in x around inf
lower-*.f64N/A
lower-sin.f6447.1
Simplified47.1%
if -0.39000000000000001 < y < 4.5e16Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6498.3
Simplified98.3%
Taylor expanded in y around 0
+-commutativeN/A
distribute-rgt-inN/A
associate-*l*N/A
*-lft-identityN/A
lower-fma.f64N/A
Simplified98.3%
Applied egg-rr98.3%
Final simplification74.7%
(FPCore (x y z) :precision binary64 (if (<= x -6e+139) (* y x) z))
double code(double x, double y, double z) {
double tmp;
if (x <= -6e+139) {
tmp = y * x;
} 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 (x <= (-6d+139)) then
tmp = y * x
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -6e+139) {
tmp = y * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -6e+139: tmp = y * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -6e+139) tmp = Float64(y * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -6e+139) tmp = y * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -6e+139], N[(y * x), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6 \cdot 10^{+139}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -5.9999999999999999e139Initial program 99.6%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6460.1
Simplified60.1%
Taylor expanded in y around inf
lower-*.f6442.9
Simplified42.9%
if -5.9999999999999999e139 < x Initial program 99.8%
lift-sin.f64N/A
lift-*.f64N/A
lift-cos.f64N/A
lift-*.f64N/A
flip-+N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
flip-+N/A
lift-+.f64N/A
lower-/.f6499.5
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
Applied egg-rr99.5%
Taylor expanded in y around 0
lower-/.f6445.1
Simplified45.1%
remove-double-div45.3
Applied egg-rr45.3%
Final simplification44.8%
(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.f6455.6
Simplified55.6%
(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%
lift-sin.f64N/A
lift-*.f64N/A
lift-cos.f64N/A
lift-*.f64N/A
flip-+N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
flip-+N/A
lift-+.f64N/A
lower-/.f6499.5
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
Applied egg-rr99.5%
Taylor expanded in y around 0
lower-/.f6439.9
Simplified39.9%
remove-double-div40.0
Applied egg-rr40.0%
herbie shell --seed 2024208
(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))))