
(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 7 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
*-commutativeN/A
lift-cos.f64N/A
lift-*.f64N/A
lower-fma.f6499.8
Applied egg-rr99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (cos y))))
(if (<= z -2.35e+100)
t_0
(if (<= z 27000000000000.0) (* z (fma x (/ (sin y) z) 1.0)) t_0))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double tmp;
if (z <= -2.35e+100) {
tmp = t_0;
} else if (z <= 27000000000000.0) {
tmp = z * fma(x, (sin(y) / z), 1.0);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(z * cos(y)) tmp = 0.0 if (z <= -2.35e+100) tmp = t_0; elseif (z <= 27000000000000.0) tmp = Float64(z * fma(x, Float64(sin(y) / z), 1.0)); 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, -2.35e+100], t$95$0, If[LessEqual[z, 27000000000000.0], N[(z * N[(x * N[(N[Sin[y], $MachinePrecision] / z), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;z \leq -2.35 \cdot 10^{+100}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 27000000000000:\\
\;\;\;\;z \cdot \mathsf{fma}\left(x, \frac{\sin y}{z}, 1\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -2.35e100 or 2.7e13 < z Initial program 99.8%
Taylor expanded in x around 0
lower-*.f64N/A
lower-cos.f6489.5
Simplified89.5%
if -2.35e100 < z < 2.7e13Initial program 99.8%
lift-sin.f64N/A
*-commutativeN/A
lift-cos.f64N/A
lift-*.f64N/A
lower-fma.f6499.9
Applied egg-rr99.9%
Taylor expanded in z around inf
lower-*.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lower-cos.f6490.5
Simplified90.5%
Taylor expanded in y around 0
Simplified76.7%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (cos y))))
(if (<= y -0.0046)
t_0
(if (<= y 0.5)
(fma y (fma y (fma z -0.5 (* -0.16666666666666666 (* y x))) x) z)
t_0))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double tmp;
if (y <= -0.0046) {
tmp = t_0;
} else if (y <= 0.5) {
tmp = fma(y, fma(y, fma(z, -0.5, (-0.16666666666666666 * (y * x))), x), z);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(z * cos(y)) tmp = 0.0 if (y <= -0.0046) tmp = t_0; elseif (y <= 0.5) tmp = fma(y, fma(y, fma(z, -0.5, Float64(-0.16666666666666666 * Float64(y * x))), 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[y, -0.0046], t$95$0, If[LessEqual[y, 0.5], N[(y * N[(y * N[(z * -0.5 + N[(-0.16666666666666666 * N[(y * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision] + z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;y \leq -0.0046:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.5:\\
\;\;\;\;\mathsf{fma}\left(y, \mathsf{fma}\left(y, \mathsf{fma}\left(z, -0.5, -0.16666666666666666 \cdot \left(y \cdot x\right)\right), x\right), z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -0.0045999999999999999 or 0.5 < y Initial program 99.6%
Taylor expanded in x around 0
lower-*.f64N/A
lower-cos.f6459.9
Simplified59.9%
if -0.0045999999999999999 < y < 0.5Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6499.4
Simplified99.4%
Final simplification80.6%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (sin y) x)))
(if (<= y -75000000.0)
t_0
(if (<= y 0.145)
(+
(* (fma y (* x -0.16666666666666666) (* z -0.5)) (* y y))
(fma y x z))
t_0))))
double code(double x, double y, double z) {
double t_0 = sin(y) * x;
double tmp;
if (y <= -75000000.0) {
tmp = t_0;
} else if (y <= 0.145) {
tmp = (fma(y, (x * -0.16666666666666666), (z * -0.5)) * (y * y)) + fma(y, x, z);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(sin(y) * x) tmp = 0.0 if (y <= -75000000.0) tmp = t_0; elseif (y <= 0.145) tmp = Float64(Float64(fma(y, Float64(x * -0.16666666666666666), Float64(z * -0.5)) * Float64(y * y)) + fma(y, x, 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, -75000000.0], t$95$0, If[LessEqual[y, 0.145], N[(N[(N[(y * N[(x * -0.16666666666666666), $MachinePrecision] + N[(z * -0.5), $MachinePrecision]), $MachinePrecision] * N[(y * y), $MachinePrecision]), $MachinePrecision] + N[(y * x + z), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin y \cdot x\\
\mathbf{if}\;y \leq -75000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.145:\\
\;\;\;\;\mathsf{fma}\left(y, x \cdot -0.16666666666666666, z \cdot -0.5\right) \cdot \left(y \cdot y\right) + \mathsf{fma}\left(y, x, z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -7.5e7 or 0.14499999999999999 < y Initial program 99.6%
Taylor expanded in x around inf
lower-*.f64N/A
lower-sin.f6443.5
Simplified43.5%
if -7.5e7 < y < 0.14499999999999999Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6497.0
Simplified97.0%
lift-*.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
lift-fma.f64N/A
lift-fma.f64N/A
distribute-lft-inN/A
lift-*.f64N/A
associate-+l+N/A
lift-*.f64N/A
lift-fma.f64N/A
lower-+.f64N/A
Applied egg-rr97.0%
Final simplification72.4%
(FPCore (x y z) :precision binary64 (if (<= x -1.3e+165) (* y x) (if (<= x 2.55e+228) z (* y x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.3e+165) {
tmp = y * x;
} else if (x <= 2.55e+228) {
tmp = z;
} else {
tmp = y * x;
}
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.3d+165)) then
tmp = y * x
else if (x <= 2.55d+228) then
tmp = z
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.3e+165) {
tmp = y * x;
} else if (x <= 2.55e+228) {
tmp = z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.3e+165: tmp = y * x elif x <= 2.55e+228: tmp = z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.3e+165) tmp = Float64(y * x); elseif (x <= 2.55e+228) tmp = z; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.3e+165) tmp = y * x; elseif (x <= 2.55e+228) tmp = z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.3e+165], N[(y * x), $MachinePrecision], If[LessEqual[x, 2.55e+228], z, N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.3 \cdot 10^{+165}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 2.55 \cdot 10^{+228}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -1.3000000000000001e165 or 2.54999999999999986e228 < x Initial program 99.7%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6457.6
Simplified57.6%
Taylor expanded in y around inf
lower-*.f6443.5
Simplified43.5%
if -1.3000000000000001e165 < x < 2.54999999999999986e228Initial program 99.8%
Taylor expanded in x around 0
lower-*.f64N/A
lower-cos.f6478.6
Simplified78.6%
Taylor expanded in y around 0
Simplified47.6%
*-rgt-identity47.6
Applied egg-rr47.6%
Final simplification46.9%
(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.f6454.5
Simplified54.5%
(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.f6467.1
Simplified67.1%
Taylor expanded in y around 0
Simplified41.7%
*-rgt-identity41.7
Applied egg-rr41.7%
herbie shell --seed 2024207
(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))))