
(FPCore (x y z) :precision binary64 (+ (* x (cos y)) (* z (sin y))))
double code(double x, double y, double z) {
return (x * cos(y)) + (z * 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 = (x * cos(y)) + (z * sin(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.cos(y)) + (z * Math.sin(y));
}
def code(x, y, z): return (x * math.cos(y)) + (z * math.sin(y))
function code(x, y, z) return Float64(Float64(x * cos(y)) + Float64(z * sin(y))) end
function tmp = code(x, y, z) tmp = (x * cos(y)) + (z * sin(y)); end
code[x_, y_, z_] := N[(N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \cos y + z \cdot \sin y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x (cos y)) (* z (sin y))))
double code(double x, double y, double z) {
return (x * cos(y)) + (z * 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 = (x * cos(y)) + (z * sin(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.cos(y)) + (z * Math.sin(y));
}
def code(x, y, z): return (x * math.cos(y)) + (z * math.sin(y))
function code(x, y, z) return Float64(Float64(x * cos(y)) + Float64(z * sin(y))) end
function tmp = code(x, y, z) tmp = (x * cos(y)) + (z * sin(y)); end
code[x_, y_, z_] := N[(N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \cos y + z \cdot \sin y
\end{array}
(FPCore (x y z) :precision binary64 (fma x (cos y) (* z (sin y))))
double code(double x, double y, double z) {
return fma(x, cos(y), (z * sin(y)));
}
function code(x, y, z) return fma(x, cos(y), Float64(z * sin(y))) end
code[x_, y_, z_] := N[(x * N[Cos[y], $MachinePrecision] + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, \cos y, z \cdot \sin y\right)
\end{array}
Initial program 99.8%
fma-def99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (<= z -0.102) (+ x (* z (sin y))) (if (<= z 6.5e-131) (* x (cos y)) (fma (sin y) z x))))
double code(double x, double y, double z) {
double tmp;
if (z <= -0.102) {
tmp = x + (z * sin(y));
} else if (z <= 6.5e-131) {
tmp = x * cos(y);
} else {
tmp = fma(sin(y), z, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -0.102) tmp = Float64(x + Float64(z * sin(y))); elseif (z <= 6.5e-131) tmp = Float64(x * cos(y)); else tmp = fma(sin(y), z, x); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -0.102], N[(x + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 6.5e-131], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(N[Sin[y], $MachinePrecision] * z + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.102:\\
\;\;\;\;x + z \cdot \sin y\\
\mathbf{elif}\;z \leq 6.5 \cdot 10^{-131}:\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\sin y, z, x\right)\\
\end{array}
\end{array}
if z < -0.101999999999999993Initial program 99.7%
Taylor expanded in y around 0 90.1%
if -0.101999999999999993 < z < 6.5000000000000002e-131Initial program 99.8%
Taylor expanded in x around inf 87.2%
if 6.5000000000000002e-131 < z Initial program 99.7%
Taylor expanded in y around 0 88.8%
+-commutative88.8%
*-commutative88.8%
fma-def88.9%
Applied egg-rr88.9%
Final simplification88.4%
(FPCore (x y z) :precision binary64 (+ (* z (sin y)) (* x (cos y))))
double code(double x, double y, double z) {
return (z * sin(y)) + (x * 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 = (z * sin(y)) + (x * cos(y))
end function
public static double code(double x, double y, double z) {
return (z * Math.sin(y)) + (x * Math.cos(y));
}
def code(x, y, z): return (z * math.sin(y)) + (x * math.cos(y))
function code(x, y, z) return Float64(Float64(z * sin(y)) + Float64(x * cos(y))) end
function tmp = code(x, y, z) tmp = (z * sin(y)) + (x * cos(y)); end
code[x_, y_, z_] := N[(N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z \cdot \sin y + x \cdot \cos y
\end{array}
Initial program 99.8%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (cos y))))
(if (<= y -5.4e+250)
t_0
(if (<= y -5.2e+50)
(* z (sin y))
(if (or (<= y -0.012) (not (<= y 0.0255)))
t_0
(+ x (* y (+ z (* y (* x -0.5))))))))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double tmp;
if (y <= -5.4e+250) {
tmp = t_0;
} else if (y <= -5.2e+50) {
tmp = z * sin(y);
} else if ((y <= -0.012) || !(y <= 0.0255)) {
tmp = t_0;
} else {
tmp = x + (y * (z + (y * (x * -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) :: t_0
real(8) :: tmp
t_0 = x * cos(y)
if (y <= (-5.4d+250)) then
tmp = t_0
else if (y <= (-5.2d+50)) then
tmp = z * sin(y)
else if ((y <= (-0.012d0)) .or. (.not. (y <= 0.0255d0))) then
tmp = t_0
else
tmp = x + (y * (z + (y * (x * (-0.5d0)))))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * Math.cos(y);
double tmp;
if (y <= -5.4e+250) {
tmp = t_0;
} else if (y <= -5.2e+50) {
tmp = z * Math.sin(y);
} else if ((y <= -0.012) || !(y <= 0.0255)) {
tmp = t_0;
} else {
tmp = x + (y * (z + (y * (x * -0.5))));
}
return tmp;
}
def code(x, y, z): t_0 = x * math.cos(y) tmp = 0 if y <= -5.4e+250: tmp = t_0 elif y <= -5.2e+50: tmp = z * math.sin(y) elif (y <= -0.012) or not (y <= 0.0255): tmp = t_0 else: tmp = x + (y * (z + (y * (x * -0.5)))) return tmp
function code(x, y, z) t_0 = Float64(x * cos(y)) tmp = 0.0 if (y <= -5.4e+250) tmp = t_0; elseif (y <= -5.2e+50) tmp = Float64(z * sin(y)); elseif ((y <= -0.012) || !(y <= 0.0255)) tmp = t_0; else tmp = Float64(x + Float64(y * Float64(z + Float64(y * Float64(x * -0.5))))); end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * cos(y); tmp = 0.0; if (y <= -5.4e+250) tmp = t_0; elseif (y <= -5.2e+50) tmp = z * sin(y); elseif ((y <= -0.012) || ~((y <= 0.0255))) tmp = t_0; else tmp = x + (y * (z + (y * (x * -0.5)))); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -5.4e+250], t$95$0, If[LessEqual[y, -5.2e+50], N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, -0.012], N[Not[LessEqual[y, 0.0255]], $MachinePrecision]], t$95$0, N[(x + N[(y * N[(z + N[(y * N[(x * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
\mathbf{if}\;y \leq -5.4 \cdot 10^{+250}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -5.2 \cdot 10^{+50}:\\
\;\;\;\;z \cdot \sin y\\
\mathbf{elif}\;y \leq -0.012 \lor \neg \left(y \leq 0.0255\right):\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot \left(z + y \cdot \left(x \cdot -0.5\right)\right)\\
\end{array}
\end{array}
if y < -5.4e250 or -5.2000000000000004e50 < y < -0.012 or 0.0254999999999999984 < y Initial program 99.5%
Taylor expanded in x around inf 65.2%
if -5.4e250 < y < -5.2000000000000004e50Initial program 99.5%
Taylor expanded in x around 0 65.0%
if -0.012 < y < 0.0254999999999999984Initial program 100.0%
Taylor expanded in y around 0 99.5%
+-commutative99.5%
*-commutative99.5%
associate-*r*99.5%
unpow299.5%
associate-*r*99.5%
distribute-rgt-out99.5%
*-commutative99.5%
Simplified99.5%
Final simplification83.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (cos y))))
(if (<= y -5.5e+250)
t_0
(if (<= y -9.5e+50)
(* z (sin y))
(if (or (<= y -0.00014) (not (<= y 0.0195))) t_0 (fma y z x))))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double tmp;
if (y <= -5.5e+250) {
tmp = t_0;
} else if (y <= -9.5e+50) {
tmp = z * sin(y);
} else if ((y <= -0.00014) || !(y <= 0.0195)) {
tmp = t_0;
} else {
tmp = fma(y, z, x);
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * cos(y)) tmp = 0.0 if (y <= -5.5e+250) tmp = t_0; elseif (y <= -9.5e+50) tmp = Float64(z * sin(y)); elseif ((y <= -0.00014) || !(y <= 0.0195)) tmp = t_0; else tmp = fma(y, z, x); end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -5.5e+250], t$95$0, If[LessEqual[y, -9.5e+50], N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, -0.00014], N[Not[LessEqual[y, 0.0195]], $MachinePrecision]], t$95$0, N[(y * z + x), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
\mathbf{if}\;y \leq -5.5 \cdot 10^{+250}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -9.5 \cdot 10^{+50}:\\
\;\;\;\;z \cdot \sin y\\
\mathbf{elif}\;y \leq -0.00014 \lor \neg \left(y \leq 0.0195\right):\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, z, x\right)\\
\end{array}
\end{array}
if y < -5.4999999999999999e250 or -9.4999999999999993e50 < y < -1.3999999999999999e-4 or 0.0195 < y Initial program 99.5%
Taylor expanded in x around inf 65.2%
if -5.4999999999999999e250 < y < -9.4999999999999993e50Initial program 99.5%
Taylor expanded in x around 0 65.0%
if -1.3999999999999999e-4 < y < 0.0195Initial program 100.0%
Taylor expanded in y around 0 99.5%
+-commutative99.5%
fma-def99.5%
Simplified99.5%
Final simplification83.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -0.35) (not (<= z 2.15e-131))) (+ x (* z (sin y))) (* x (cos y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -0.35) || !(z <= 2.15e-131)) {
tmp = x + (z * sin(y));
} else {
tmp = x * 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 ((z <= (-0.35d0)) .or. (.not. (z <= 2.15d-131))) then
tmp = x + (z * sin(y))
else
tmp = x * cos(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -0.35) || !(z <= 2.15e-131)) {
tmp = x + (z * Math.sin(y));
} else {
tmp = x * Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -0.35) or not (z <= 2.15e-131): tmp = x + (z * math.sin(y)) else: tmp = x * math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -0.35) || !(z <= 2.15e-131)) tmp = Float64(x + Float64(z * sin(y))); else tmp = Float64(x * cos(y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -0.35) || ~((z <= 2.15e-131))) tmp = x + (z * sin(y)); else tmp = x * cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -0.35], N[Not[LessEqual[z, 2.15e-131]], $MachinePrecision]], N[(x + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.35 \lor \neg \left(z \leq 2.15 \cdot 10^{-131}\right):\\
\;\;\;\;x + z \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \cos y\\
\end{array}
\end{array}
if z < -0.34999999999999998 or 2.15000000000000009e-131 < z Initial program 99.7%
Taylor expanded in y around 0 89.4%
if -0.34999999999999998 < z < 2.15000000000000009e-131Initial program 99.8%
Taylor expanded in x around inf 87.2%
Final simplification88.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.0165) (not (<= y 0.035))) (* x (cos y)) (+ x (* y (+ z (* y (* x -0.5)))))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.0165) || !(y <= 0.035)) {
tmp = x * cos(y);
} else {
tmp = x + (y * (z + (y * (x * -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.0165d0)) .or. (.not. (y <= 0.035d0))) then
tmp = x * cos(y)
else
tmp = x + (y * (z + (y * (x * (-0.5d0)))))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.0165) || !(y <= 0.035)) {
tmp = x * Math.cos(y);
} else {
tmp = x + (y * (z + (y * (x * -0.5))));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.0165) or not (y <= 0.035): tmp = x * math.cos(y) else: tmp = x + (y * (z + (y * (x * -0.5)))) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.0165) || !(y <= 0.035)) tmp = Float64(x * cos(y)); else tmp = Float64(x + Float64(y * Float64(z + Float64(y * Float64(x * -0.5))))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.0165) || ~((y <= 0.035))) tmp = x * cos(y); else tmp = x + (y * (z + (y * (x * -0.5)))); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.0165], N[Not[LessEqual[y, 0.035]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x + N[(y * N[(z + N[(y * N[(x * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.0165 \lor \neg \left(y \leq 0.035\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot \left(z + y \cdot \left(x \cdot -0.5\right)\right)\\
\end{array}
\end{array}
if y < -0.016500000000000001 or 0.035000000000000003 < y Initial program 99.5%
Taylor expanded in x around inf 54.2%
if -0.016500000000000001 < y < 0.035000000000000003Initial program 100.0%
Taylor expanded in y around 0 99.5%
+-commutative99.5%
*-commutative99.5%
associate-*r*99.5%
unpow299.5%
associate-*r*99.5%
distribute-rgt-out99.5%
*-commutative99.5%
Simplified99.5%
Final simplification77.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.15e+222) (not (<= z 3.65e+130))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.15e+222) || !(z <= 3.65e+130)) {
tmp = y * z;
} else {
tmp = 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 ((z <= (-1.15d+222)) .or. (.not. (z <= 3.65d+130))) then
tmp = y * z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.15e+222) || !(z <= 3.65e+130)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.15e+222) or not (z <= 3.65e+130): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.15e+222) || !(z <= 3.65e+130)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.15e+222) || ~((z <= 3.65e+130))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.15e+222], N[Not[LessEqual[z, 3.65e+130]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.15 \cdot 10^{+222} \lor \neg \left(z \leq 3.65 \cdot 10^{+130}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.15000000000000005e222 or 3.65e130 < z Initial program 99.7%
Taylor expanded in y around 0 53.5%
+-commutative53.5%
Simplified53.5%
Taylor expanded in y around inf 39.6%
*-commutative39.6%
Simplified39.6%
if -1.15000000000000005e222 < z < 3.65e130Initial program 99.8%
Taylor expanded in y around 0 55.8%
+-commutative55.8%
Simplified55.8%
Taylor expanded in y around 0 49.8%
Final simplification47.7%
(FPCore (x y z) :precision binary64 (+ x (* y z)))
double code(double x, double y, double z) {
return x + (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 + (y * z)
end function
public static double code(double x, double y, double z) {
return x + (y * z);
}
def code(x, y, z): return x + (y * z)
function code(x, y, z) return Float64(x + Float64(y * z)) end
function tmp = code(x, y, z) tmp = x + (y * z); end
code[x_, y_, z_] := N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot z
\end{array}
Initial program 99.8%
Taylor expanded in y around 0 55.3%
+-commutative55.3%
Simplified55.3%
Final simplification55.3%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 99.8%
Taylor expanded in y around 0 55.3%
+-commutative55.3%
Simplified55.3%
Taylor expanded in y around 0 43.0%
Final simplification43.0%
herbie shell --seed 2024026
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutY from diagrams-lib-1.3.0.3"
:precision binary64
(+ (* x (cos y)) (* z (sin y))))