
(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 (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%
+-commutative99.8%
*-commutative99.8%
fma-define99.8%
Applied egg-rr99.8%
(FPCore (x y z) :precision binary64 (fma x (sin y) (* (cos y) z)))
double code(double x, double y, double z) {
return fma(x, sin(y), (cos(y) * z));
}
function code(x, y, z) return fma(x, sin(y), Float64(cos(y) * z)) end
code[x_, y_, z_] := N[(x * N[Sin[y], $MachinePrecision] + N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, \sin y, \cos y \cdot z\right)
\end{array}
Initial program 99.8%
fma-define99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (+ (* x (sin y)) (* (cos y) z)))
double code(double x, double y, double z) {
return (x * sin(y)) + (cos(y) * z);
}
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)) + (cos(y) * z)
end function
public static double code(double x, double y, double z) {
return (x * Math.sin(y)) + (Math.cos(y) * z);
}
def code(x, y, z): return (x * math.sin(y)) + (math.cos(y) * z)
function code(x, y, z) return Float64(Float64(x * sin(y)) + Float64(cos(y) * z)) end
function tmp = code(x, y, z) tmp = (x * sin(y)) + (cos(y) * z); end
code[x_, y_, z_] := N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \sin y + \cos y \cdot z
\end{array}
Initial program 99.8%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (cos y) z)))
(if (<= y -4.2e+119)
t_0
(if (<= y -1.55e+43)
(* x (sin y))
(if (<= y 1.06e+41) (+ (* y x) (* z (+ (+ (cos y) 1.0) -1.0))) t_0)))))
double code(double x, double y, double z) {
double t_0 = cos(y) * z;
double tmp;
if (y <= -4.2e+119) {
tmp = t_0;
} else if (y <= -1.55e+43) {
tmp = x * sin(y);
} else if (y <= 1.06e+41) {
tmp = (y * x) + (z * ((cos(y) + 1.0) + -1.0));
} 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 = cos(y) * z
if (y <= (-4.2d+119)) then
tmp = t_0
else if (y <= (-1.55d+43)) then
tmp = x * sin(y)
else if (y <= 1.06d+41) then
tmp = (y * x) + (z * ((cos(y) + 1.0d0) + (-1.0d0)))
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = Math.cos(y) * z;
double tmp;
if (y <= -4.2e+119) {
tmp = t_0;
} else if (y <= -1.55e+43) {
tmp = x * Math.sin(y);
} else if (y <= 1.06e+41) {
tmp = (y * x) + (z * ((Math.cos(y) + 1.0) + -1.0));
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = math.cos(y) * z tmp = 0 if y <= -4.2e+119: tmp = t_0 elif y <= -1.55e+43: tmp = x * math.sin(y) elif y <= 1.06e+41: tmp = (y * x) + (z * ((math.cos(y) + 1.0) + -1.0)) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(cos(y) * z) tmp = 0.0 if (y <= -4.2e+119) tmp = t_0; elseif (y <= -1.55e+43) tmp = Float64(x * sin(y)); elseif (y <= 1.06e+41) tmp = Float64(Float64(y * x) + Float64(z * Float64(Float64(cos(y) + 1.0) + -1.0))); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = cos(y) * z; tmp = 0.0; if (y <= -4.2e+119) tmp = t_0; elseif (y <= -1.55e+43) tmp = x * sin(y); elseif (y <= 1.06e+41) tmp = (y * x) + (z * ((cos(y) + 1.0) + -1.0)); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[y, -4.2e+119], t$95$0, If[LessEqual[y, -1.55e+43], N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.06e+41], N[(N[(y * x), $MachinePrecision] + N[(z * N[(N[(N[Cos[y], $MachinePrecision] + 1.0), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos y \cdot z\\
\mathbf{if}\;y \leq -4.2 \cdot 10^{+119}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -1.55 \cdot 10^{+43}:\\
\;\;\;\;x \cdot \sin y\\
\mathbf{elif}\;y \leq 1.06 \cdot 10^{+41}:\\
\;\;\;\;y \cdot x + z \cdot \left(\left(\cos y + 1\right) + -1\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -4.19999999999999966e119 or 1.06e41 < y Initial program 99.6%
fma-define99.6%
Simplified99.6%
Taylor expanded in x around 0 60.1%
if -4.19999999999999966e119 < y < -1.5500000000000001e43Initial program 99.4%
fma-define99.4%
Simplified99.4%
Taylor expanded in x around inf 73.5%
if -1.5500000000000001e43 < y < 1.06e41Initial program 99.9%
expm1-log1p-u99.9%
Applied egg-rr99.9%
expm1-undefine99.9%
log1p-undefine99.9%
rem-exp-log99.9%
+-commutative99.9%
Applied egg-rr99.9%
Taylor expanded in y around 0 94.2%
Final simplification80.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.9e+68) (not (<= x 6.2e+140))) (* x (sin y)) (* (cos y) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.9e+68) || !(x <= 6.2e+140)) {
tmp = x * sin(y);
} else {
tmp = cos(y) * 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 <= (-2.9d+68)) .or. (.not. (x <= 6.2d+140))) then
tmp = x * sin(y)
else
tmp = cos(y) * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -2.9e+68) || !(x <= 6.2e+140)) {
tmp = x * Math.sin(y);
} else {
tmp = Math.cos(y) * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.9e+68) or not (x <= 6.2e+140): tmp = x * math.sin(y) else: tmp = math.cos(y) * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.9e+68) || !(x <= 6.2e+140)) tmp = Float64(x * sin(y)); else tmp = Float64(cos(y) * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.9e+68) || ~((x <= 6.2e+140))) tmp = x * sin(y); else tmp = cos(y) * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.9e+68], N[Not[LessEqual[x, 6.2e+140]], $MachinePrecision]], N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision], N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.9 \cdot 10^{+68} \lor \neg \left(x \leq 6.2 \cdot 10^{+140}\right):\\
\;\;\;\;x \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;\cos y \cdot z\\
\end{array}
\end{array}
if x < -2.90000000000000011e68 or 6.2000000000000001e140 < x Initial program 99.8%
fma-define99.8%
Simplified99.8%
Taylor expanded in x around inf 77.4%
if -2.90000000000000011e68 < x < 6.2000000000000001e140Initial program 99.8%
fma-define99.8%
Simplified99.8%
Taylor expanded in x around 0 80.0%
Final simplification79.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -4.4e-8) (not (<= y 0.00095))) (* x (sin y)) (+ z (* y (+ x (* z (* y -0.5)))))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -4.4e-8) || !(y <= 0.00095)) {
tmp = x * sin(y);
} else {
tmp = z + (y * (x + (z * (y * -0.5))));
}
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 ((y <= (-4.4d-8)) .or. (.not. (y <= 0.00095d0))) then
tmp = x * sin(y)
else
tmp = z + (y * (x + (z * (y * (-0.5d0)))))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -4.4e-8) || !(y <= 0.00095)) {
tmp = x * Math.sin(y);
} else {
tmp = z + (y * (x + (z * (y * -0.5))));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -4.4e-8) or not (y <= 0.00095): tmp = x * math.sin(y) else: tmp = z + (y * (x + (z * (y * -0.5)))) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -4.4e-8) || !(y <= 0.00095)) tmp = Float64(x * sin(y)); else tmp = Float64(z + Float64(y * Float64(x + Float64(z * Float64(y * -0.5))))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -4.4e-8) || ~((y <= 0.00095))) tmp = x * sin(y); else tmp = z + (y * (x + (z * (y * -0.5)))); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -4.4e-8], N[Not[LessEqual[y, 0.00095]], $MachinePrecision]], N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision], N[(z + N[(y * N[(x + N[(z * N[(y * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.4 \cdot 10^{-8} \lor \neg \left(y \leq 0.00095\right):\\
\;\;\;\;x \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;z + y \cdot \left(x + z \cdot \left(y \cdot -0.5\right)\right)\\
\end{array}
\end{array}
if y < -4.3999999999999997e-8 or 9.49999999999999998e-4 < y Initial program 99.6%
fma-define99.6%
Simplified99.6%
Taylor expanded in x around inf 48.3%
if -4.3999999999999997e-8 < y < 9.49999999999999998e-4Initial program 100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in y around 0 100.0%
associate-*r*100.0%
Simplified100.0%
Final simplification74.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -6.2e+114) (not (<= x 1.3e+136))) (* y x) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6.2e+114) || !(x <= 1.3e+136)) {
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 <= (-6.2d+114)) .or. (.not. (x <= 1.3d+136))) 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 <= -6.2e+114) || !(x <= 1.3e+136)) {
tmp = y * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -6.2e+114) or not (x <= 1.3e+136): tmp = y * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -6.2e+114) || !(x <= 1.3e+136)) tmp = Float64(y * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -6.2e+114) || ~((x <= 1.3e+136))) tmp = y * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -6.2e+114], N[Not[LessEqual[x, 1.3e+136]], $MachinePrecision]], N[(y * x), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.2 \cdot 10^{+114} \lor \neg \left(x \leq 1.3 \cdot 10^{+136}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -6.2000000000000001e114 or 1.3000000000000001e136 < x Initial program 99.8%
fma-define99.8%
Simplified99.8%
Taylor expanded in y around 0 45.6%
+-commutative45.6%
Simplified45.6%
Taylor expanded in x around inf 35.4%
if -6.2000000000000001e114 < x < 1.3000000000000001e136Initial program 99.8%
+-commutative99.8%
*-commutative99.8%
fma-define99.8%
Applied egg-rr99.8%
Taylor expanded in y around 0 50.5%
Final simplification46.0%
(FPCore (x y z) :precision binary64 (+ z (* y x)))
double code(double x, double y, double z) {
return z + (y * x);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z + (y * x)
end function
public static double code(double x, double y, double z) {
return z + (y * x);
}
def code(x, y, z): return z + (y * x)
function code(x, y, z) return Float64(z + Float64(y * x)) end
function tmp = code(x, y, z) tmp = z + (y * x); end
code[x_, y_, z_] := N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + y \cdot x
\end{array}
Initial program 99.8%
fma-define99.8%
Simplified99.8%
Taylor expanded in y around 0 53.7%
+-commutative53.7%
Simplified53.7%
Final simplification53.7%
(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%
+-commutative99.8%
*-commutative99.8%
fma-define99.8%
Applied egg-rr99.8%
Taylor expanded in y around 0 39.6%
herbie shell --seed 2024150
(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))))