
(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%
fma-def99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (+ (* z (cos y)) (* x (sin y))))
double code(double x, double y, double z) {
return (z * cos(y)) + (x * sin(y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (z * cos(y)) + (x * sin(y))
end function
public static double code(double x, double y, double z) {
return (z * Math.cos(y)) + (x * Math.sin(y));
}
def code(x, y, z): return (z * math.cos(y)) + (x * math.sin(y))
function code(x, y, z) return Float64(Float64(z * cos(y)) + Float64(x * sin(y))) end
function tmp = code(x, y, z) tmp = (z * cos(y)) + (x * sin(y)); end
code[x_, y_, z_] := N[(N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision] + N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z \cdot \cos y + x \cdot \sin y
\end{array}
Initial program 99.8%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (cos y))))
(if (<= z -2.5e-59)
t_0
(if (<= z -3.2e-141)
(+ z (* x y))
(if (or (<= z -5.5e-143) (not (<= z 5.8e-123))) t_0 (* x (sin y)))))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double tmp;
if (z <= -2.5e-59) {
tmp = t_0;
} else if (z <= -3.2e-141) {
tmp = z + (x * y);
} else if ((z <= -5.5e-143) || !(z <= 5.8e-123)) {
tmp = t_0;
} else {
tmp = x * sin(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) :: t_0
real(8) :: tmp
t_0 = z * cos(y)
if (z <= (-2.5d-59)) then
tmp = t_0
else if (z <= (-3.2d-141)) then
tmp = z + (x * y)
else if ((z <= (-5.5d-143)) .or. (.not. (z <= 5.8d-123))) then
tmp = t_0
else
tmp = x * sin(y)
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 <= -2.5e-59) {
tmp = t_0;
} else if (z <= -3.2e-141) {
tmp = z + (x * y);
} else if ((z <= -5.5e-143) || !(z <= 5.8e-123)) {
tmp = t_0;
} else {
tmp = x * Math.sin(y);
}
return tmp;
}
def code(x, y, z): t_0 = z * math.cos(y) tmp = 0 if z <= -2.5e-59: tmp = t_0 elif z <= -3.2e-141: tmp = z + (x * y) elif (z <= -5.5e-143) or not (z <= 5.8e-123): tmp = t_0 else: tmp = x * math.sin(y) return tmp
function code(x, y, z) t_0 = Float64(z * cos(y)) tmp = 0.0 if (z <= -2.5e-59) tmp = t_0; elseif (z <= -3.2e-141) tmp = Float64(z + Float64(x * y)); elseif ((z <= -5.5e-143) || !(z <= 5.8e-123)) tmp = t_0; else tmp = Float64(x * sin(y)); end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * cos(y); tmp = 0.0; if (z <= -2.5e-59) tmp = t_0; elseif (z <= -3.2e-141) tmp = z + (x * y); elseif ((z <= -5.5e-143) || ~((z <= 5.8e-123))) tmp = t_0; else tmp = x * sin(y); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -2.5e-59], t$95$0, If[LessEqual[z, -3.2e-141], N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[z, -5.5e-143], N[Not[LessEqual[z, 5.8e-123]], $MachinePrecision]], t$95$0, N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;z \leq -2.5 \cdot 10^{-59}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -3.2 \cdot 10^{-141}:\\
\;\;\;\;z + x \cdot y\\
\mathbf{elif}\;z \leq -5.5 \cdot 10^{-143} \lor \neg \left(z \leq 5.8 \cdot 10^{-123}\right):\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;x \cdot \sin y\\
\end{array}
\end{array}
if z < -2.5000000000000001e-59 or -3.2000000000000001e-141 < z < -5.50000000000000041e-143 or 5.80000000000000007e-123 < z Initial program 99.8%
Taylor expanded in x around 0 80.6%
if -2.5000000000000001e-59 < z < -3.2000000000000001e-141Initial program 99.9%
Taylor expanded in y around 0 80.0%
*-commutative80.0%
Simplified80.0%
if -5.50000000000000041e-143 < z < 5.80000000000000007e-123Initial program 99.9%
Taylor expanded in x around inf 80.2%
Final simplification80.5%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (cos y))))
(if (<= z -3.5e-58)
t_0
(if (<= z -3.2e-141)
(fma y x z)
(if (or (<= z -7e-143) (not (<= z 9e-125))) t_0 (* x (sin y)))))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double tmp;
if (z <= -3.5e-58) {
tmp = t_0;
} else if (z <= -3.2e-141) {
tmp = fma(y, x, z);
} else if ((z <= -7e-143) || !(z <= 9e-125)) {
tmp = t_0;
} else {
tmp = x * sin(y);
}
return tmp;
}
function code(x, y, z) t_0 = Float64(z * cos(y)) tmp = 0.0 if (z <= -3.5e-58) tmp = t_0; elseif (z <= -3.2e-141) tmp = fma(y, x, z); elseif ((z <= -7e-143) || !(z <= 9e-125)) tmp = t_0; else tmp = Float64(x * sin(y)); end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -3.5e-58], t$95$0, If[LessEqual[z, -3.2e-141], N[(y * x + z), $MachinePrecision], If[Or[LessEqual[z, -7e-143], N[Not[LessEqual[z, 9e-125]], $MachinePrecision]], t$95$0, N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;z \leq -3.5 \cdot 10^{-58}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -3.2 \cdot 10^{-141}:\\
\;\;\;\;\mathsf{fma}\left(y, x, z\right)\\
\mathbf{elif}\;z \leq -7 \cdot 10^{-143} \lor \neg \left(z \leq 9 \cdot 10^{-125}\right):\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;x \cdot \sin y\\
\end{array}
\end{array}
if z < -3.4999999999999999e-58 or -3.2000000000000001e-141 < z < -7.00000000000000011e-143 or 9.00000000000000024e-125 < z Initial program 99.8%
Taylor expanded in x around 0 80.6%
if -3.4999999999999999e-58 < z < -3.2000000000000001e-141Initial program 99.9%
Taylor expanded in y around 0 80.0%
+-commutative80.0%
*-commutative80.0%
fma-def80.0%
Simplified80.0%
if -7.00000000000000011e-143 < z < 9.00000000000000024e-125Initial program 99.9%
Taylor expanded in x around inf 80.2%
Final simplification80.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.1e-83) (not (<= x 6.4e-149))) (+ z (* x (sin y))) (* z (cos y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.1e-83) || !(x <= 6.4e-149)) {
tmp = z + (x * sin(y));
} else {
tmp = z * cos(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.1d-83)) .or. (.not. (x <= 6.4d-149))) then
tmp = z + (x * sin(y))
else
tmp = z * cos(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.1e-83) || !(x <= 6.4e-149)) {
tmp = z + (x * Math.sin(y));
} else {
tmp = z * Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.1e-83) or not (x <= 6.4e-149): tmp = z + (x * math.sin(y)) else: tmp = z * math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.1e-83) || !(x <= 6.4e-149)) tmp = Float64(z + Float64(x * sin(y))); else tmp = Float64(z * cos(y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.1e-83) || ~((x <= 6.4e-149))) tmp = z + (x * sin(y)); else tmp = z * cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.1e-83], N[Not[LessEqual[x, 6.4e-149]], $MachinePrecision]], N[(z + N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.1 \cdot 10^{-83} \lor \neg \left(x \leq 6.4 \cdot 10^{-149}\right):\\
\;\;\;\;z + x \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;z \cdot \cos y\\
\end{array}
\end{array}
if x < -1.10000000000000004e-83 or 6.40000000000000004e-149 < x Initial program 99.9%
Taylor expanded in y around 0 88.7%
if -1.10000000000000004e-83 < x < 6.40000000000000004e-149Initial program 99.7%
Taylor expanded in x around 0 92.6%
Final simplification90.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.00082) (not (<= y 2.85e-5))) (* x (sin y)) (+ z (* y (+ x (* y (* z -0.5)))))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.00082) || !(y <= 2.85e-5)) {
tmp = x * sin(y);
} else {
tmp = z + (y * (x + (y * (z * -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 <= (-0.00082d0)) .or. (.not. (y <= 2.85d-5))) then
tmp = x * sin(y)
else
tmp = z + (y * (x + (y * (z * (-0.5d0)))))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.00082) || !(y <= 2.85e-5)) {
tmp = x * Math.sin(y);
} else {
tmp = z + (y * (x + (y * (z * -0.5))));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.00082) or not (y <= 2.85e-5): tmp = x * math.sin(y) else: tmp = z + (y * (x + (y * (z * -0.5)))) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.00082) || !(y <= 2.85e-5)) tmp = Float64(x * sin(y)); else tmp = Float64(z + Float64(y * Float64(x + Float64(y * Float64(z * -0.5))))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.00082) || ~((y <= 2.85e-5))) tmp = x * sin(y); else tmp = z + (y * (x + (y * (z * -0.5)))); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.00082], N[Not[LessEqual[y, 2.85e-5]], $MachinePrecision]], N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision], N[(z + N[(y * N[(x + N[(y * N[(z * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.00082 \lor \neg \left(y \leq 2.85 \cdot 10^{-5}\right):\\
\;\;\;\;x \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;z + y \cdot \left(x + y \cdot \left(z \cdot -0.5\right)\right)\\
\end{array}
\end{array}
if y < -8.1999999999999998e-4 or 2.8500000000000002e-5 < y Initial program 99.6%
Taylor expanded in x around inf 49.2%
if -8.1999999999999998e-4 < y < 2.8500000000000002e-5Initial program 100.0%
+-commutative100.0%
*-commutative100.0%
add-sqr-sqrt53.2%
associate-*r*53.2%
fma-def53.2%
Applied egg-rr53.2%
Taylor expanded in y around 0 99.9%
*-commutative99.9%
associate-*r*99.9%
metadata-eval99.9%
distribute-rgt-out99.9%
unpow299.9%
associate-*l*99.9%
*-commutative99.9%
distribute-lft-out99.9%
distribute-rgt-out99.9%
metadata-eval99.9%
Simplified99.9%
Final simplification77.4%
(FPCore (x y z) :precision binary64 (+ z (* x y)))
double code(double x, double y, double z) {
return z + (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 = z + (x * y)
end function
public static double code(double x, double y, double z) {
return z + (x * y);
}
def code(x, y, z): return z + (x * y)
function code(x, y, z) return Float64(z + Float64(x * y)) end
function tmp = code(x, y, z) tmp = z + (x * y); end
code[x_, y_, z_] := N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + x \cdot y
\end{array}
Initial program 99.8%
Taylor expanded in y around 0 58.0%
*-commutative58.0%
Simplified58.0%
Final simplification58.0%
(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 58.0%
*-commutative58.0%
Simplified58.0%
Taylor expanded in z around 0 20.6%
*-commutative20.6%
Simplified20.6%
Final simplification20.6%
herbie shell --seed 2023271
(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))))