
(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}
\\
\left(x + \cos y\right) - 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}
\\
\left(x + \cos y\right) - z \cdot \sin y
\end{array}
(FPCore (x y z) :precision binary64 (- (+ (cos y) x) (* (sin y) z)))
double code(double x, double y, double z) {
return (cos(y) + x) - (sin(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 = (cos(y) + x) - (sin(y) * z)
end function
public static double code(double x, double y, double z) {
return (Math.cos(y) + x) - (Math.sin(y) * z);
}
def code(x, y, z): return (math.cos(y) + x) - (math.sin(y) * z)
function code(x, y, z) return Float64(Float64(cos(y) + x) - Float64(sin(y) * z)) end
function tmp = code(x, y, z) tmp = (cos(y) + x) - (sin(y) * z); end
code[x_, y_, z_] := N[(N[(N[Cos[y], $MachinePrecision] + x), $MachinePrecision] - N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\cos y + x\right) - \sin y \cdot z
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (let* ((t_0 (- (+ (cos y) x) (* (sin y) z))) (t_1 (- x (fma z y -1.0)))) (if (<= t_0 -50.0) t_1 (if (<= t_0 0.98) (cos y) t_1))))
double code(double x, double y, double z) {
double t_0 = (cos(y) + x) - (sin(y) * z);
double t_1 = x - fma(z, y, -1.0);
double tmp;
if (t_0 <= -50.0) {
tmp = t_1;
} else if (t_0 <= 0.98) {
tmp = cos(y);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(cos(y) + x) - Float64(sin(y) * z)) t_1 = Float64(x - fma(z, y, -1.0)) tmp = 0.0 if (t_0 <= -50.0) tmp = t_1; elseif (t_0 <= 0.98) tmp = cos(y); else tmp = t_1; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(N[Cos[y], $MachinePrecision] + x), $MachinePrecision] - N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x - N[(z * y + -1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -50.0], t$95$1, If[LessEqual[t$95$0, 0.98], N[Cos[y], $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\cos y + x\right) - \sin y \cdot z\\
t_1 := x - \mathsf{fma}\left(z, y, -1\right)\\
\mathbf{if}\;t\_0 \leq -50:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 0.98:\\
\;\;\;\;\cos y\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (-.f64 (+.f64 x (cos.f64 y)) (*.f64 z (sin.f64 y))) < -50 or 0.97999999999999998 < (-.f64 (+.f64 x (cos.f64 y)) (*.f64 z (sin.f64 y))) Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
associate-+l-N/A
lower--.f64N/A
sub-negN/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f6474.5
Applied rewrites74.5%
if -50 < (-.f64 (+.f64 x (cos.f64 y)) (*.f64 z (sin.f64 y))) < 0.97999999999999998Initial program 99.9%
Taylor expanded in z around 0
+-commutativeN/A
lower-+.f64N/A
lower-cos.f6497.0
Applied rewrites97.0%
Taylor expanded in x around 0
Applied rewrites94.5%
Final simplification76.9%
(FPCore (x y z) :precision binary64 (let* ((t_0 (- (+ 1.0 x) (* (sin y) z)))) (if (<= z -1.05e+45) t_0 (if (<= z 2.1e-15) (+ (cos y) x) t_0))))
double code(double x, double y, double z) {
double t_0 = (1.0 + x) - (sin(y) * z);
double tmp;
if (z <= -1.05e+45) {
tmp = t_0;
} else if (z <= 2.1e-15) {
tmp = cos(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 = (1.0d0 + x) - (sin(y) * z)
if (z <= (-1.05d+45)) then
tmp = t_0
else if (z <= 2.1d-15) then
tmp = cos(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 = (1.0 + x) - (Math.sin(y) * z);
double tmp;
if (z <= -1.05e+45) {
tmp = t_0;
} else if (z <= 2.1e-15) {
tmp = Math.cos(y) + x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (1.0 + x) - (math.sin(y) * z) tmp = 0 if z <= -1.05e+45: tmp = t_0 elif z <= 2.1e-15: tmp = math.cos(y) + x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(1.0 + x) - Float64(sin(y) * z)) tmp = 0.0 if (z <= -1.05e+45) tmp = t_0; elseif (z <= 2.1e-15) tmp = Float64(cos(y) + x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (1.0 + x) - (sin(y) * z); tmp = 0.0; if (z <= -1.05e+45) tmp = t_0; elseif (z <= 2.1e-15) tmp = cos(y) + x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(1.0 + x), $MachinePrecision] - N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -1.05e+45], t$95$0, If[LessEqual[z, 2.1e-15], N[(N[Cos[y], $MachinePrecision] + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 + x\right) - \sin y \cdot z\\
\mathbf{if}\;z \leq -1.05 \cdot 10^{+45}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 2.1 \cdot 10^{-15}:\\
\;\;\;\;\cos y + x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1.04999999999999997e45 or 2.09999999999999981e-15 < z Initial program 99.8%
Taylor expanded in y around 0
Applied rewrites99.8%
if -1.04999999999999997e45 < z < 2.09999999999999981e-15Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
lower-+.f64N/A
lower-cos.f6499.3
Applied rewrites99.3%
Final simplification99.6%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (- z) (sin y)))) (if (<= z -8e+138) t_0 (if (<= z 3.7e+167) (+ (cos y) x) t_0))))
double code(double x, double y, double z) {
double t_0 = -z * sin(y);
double tmp;
if (z <= -8e+138) {
tmp = t_0;
} else if (z <= 3.7e+167) {
tmp = cos(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 * sin(y)
if (z <= (-8d+138)) then
tmp = t_0
else if (z <= 3.7d+167) then
tmp = cos(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.sin(y);
double tmp;
if (z <= -8e+138) {
tmp = t_0;
} else if (z <= 3.7e+167) {
tmp = Math.cos(y) + x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = -z * math.sin(y) tmp = 0 if z <= -8e+138: tmp = t_0 elif z <= 3.7e+167: tmp = math.cos(y) + x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(-z) * sin(y)) tmp = 0.0 if (z <= -8e+138) tmp = t_0; elseif (z <= 3.7e+167) tmp = Float64(cos(y) + x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = -z * sin(y); tmp = 0.0; if (z <= -8e+138) tmp = t_0; elseif (z <= 3.7e+167) tmp = cos(y) + x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[((-z) * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -8e+138], t$95$0, If[LessEqual[z, 3.7e+167], N[(N[Cos[y], $MachinePrecision] + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(-z\right) \cdot \sin y\\
\mathbf{if}\;z \leq -8 \cdot 10^{+138}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 3.7 \cdot 10^{+167}:\\
\;\;\;\;\cos y + x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -8.0000000000000003e138 or 3.7000000000000001e167 < z Initial program 99.8%
Taylor expanded in z around inf
mul-1-negN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
lower-sin.f6480.7
Applied rewrites80.7%
if -8.0000000000000003e138 < z < 3.7000000000000001e167Initial program 99.9%
Taylor expanded in z around 0
+-commutativeN/A
lower-+.f64N/A
lower-cos.f6489.3
Applied rewrites89.3%
(FPCore (x y z) :precision binary64 (let* ((t_0 (+ (cos y) x))) (if (<= y -1.65e+16) t_0 (if (<= y 3.5e-13) (- x (fma z y -1.0)) t_0))))
double code(double x, double y, double z) {
double t_0 = cos(y) + x;
double tmp;
if (y <= -1.65e+16) {
tmp = t_0;
} else if (y <= 3.5e-13) {
tmp = x - fma(z, y, -1.0);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(cos(y) + x) tmp = 0.0 if (y <= -1.65e+16) tmp = t_0; elseif (y <= 3.5e-13) tmp = Float64(x - fma(z, y, -1.0)); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Cos[y], $MachinePrecision] + x), $MachinePrecision]}, If[LessEqual[y, -1.65e+16], t$95$0, If[LessEqual[y, 3.5e-13], N[(x - N[(z * y + -1.0), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos y + x\\
\mathbf{if}\;y \leq -1.65 \cdot 10^{+16}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 3.5 \cdot 10^{-13}:\\
\;\;\;\;x - \mathsf{fma}\left(z, y, -1\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.65e16 or 3.5000000000000002e-13 < y Initial program 99.8%
Taylor expanded in z around 0
+-commutativeN/A
lower-+.f64N/A
lower-cos.f6463.3
Applied rewrites63.3%
if -1.65e16 < y < 3.5000000000000002e-13Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
associate-+l-N/A
lower--.f64N/A
sub-negN/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f6499.3
Applied rewrites99.3%
(FPCore (x y z) :precision binary64 (if (<= y -2.35e+20) (+ 1.0 x) (if (<= y 9.1e+18) (fma (- (* -0.5 y) z) y (+ 1.0 x)) (+ 1.0 x))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.35e+20) {
tmp = 1.0 + x;
} else if (y <= 9.1e+18) {
tmp = fma(((-0.5 * y) - z), y, (1.0 + x));
} else {
tmp = 1.0 + x;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -2.35e+20) tmp = Float64(1.0 + x); elseif (y <= 9.1e+18) tmp = fma(Float64(Float64(-0.5 * y) - z), y, Float64(1.0 + x)); else tmp = Float64(1.0 + x); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -2.35e+20], N[(1.0 + x), $MachinePrecision], If[LessEqual[y, 9.1e+18], N[(N[(N[(-0.5 * y), $MachinePrecision] - z), $MachinePrecision] * y + N[(1.0 + x), $MachinePrecision]), $MachinePrecision], N[(1.0 + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.35 \cdot 10^{+20}:\\
\;\;\;\;1 + x\\
\mathbf{elif}\;y \leq 9.1 \cdot 10^{+18}:\\
\;\;\;\;\mathsf{fma}\left(-0.5 \cdot y - z, y, 1 + x\right)\\
\mathbf{else}:\\
\;\;\;\;1 + x\\
\end{array}
\end{array}
if y < -2.35e20 or 9.1e18 < y Initial program 99.8%
Taylor expanded in y around 0
lower-+.f6438.4
Applied rewrites38.4%
if -2.35e20 < y < 9.1e18Initial program 100.0%
Taylor expanded in y around 0
associate-+r+N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-+.f6496.3
Applied rewrites96.3%
(FPCore (x y z) :precision binary64 (if (<= y -3.8e+67) (+ 1.0 x) (if (<= y 1.2e+115) (- x (fma z y -1.0)) (+ 1.0 x))))
double code(double x, double y, double z) {
double tmp;
if (y <= -3.8e+67) {
tmp = 1.0 + x;
} else if (y <= 1.2e+115) {
tmp = x - fma(z, y, -1.0);
} else {
tmp = 1.0 + x;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -3.8e+67) tmp = Float64(1.0 + x); elseif (y <= 1.2e+115) tmp = Float64(x - fma(z, y, -1.0)); else tmp = Float64(1.0 + x); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -3.8e+67], N[(1.0 + x), $MachinePrecision], If[LessEqual[y, 1.2e+115], N[(x - N[(z * y + -1.0), $MachinePrecision]), $MachinePrecision], N[(1.0 + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.8 \cdot 10^{+67}:\\
\;\;\;\;1 + x\\
\mathbf{elif}\;y \leq 1.2 \cdot 10^{+115}:\\
\;\;\;\;x - \mathsf{fma}\left(z, y, -1\right)\\
\mathbf{else}:\\
\;\;\;\;1 + x\\
\end{array}
\end{array}
if y < -3.8000000000000002e67 or 1.2e115 < y Initial program 99.8%
Taylor expanded in y around 0
lower-+.f6437.7
Applied rewrites37.7%
if -3.8000000000000002e67 < y < 1.2e115Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
associate-+l-N/A
lower--.f64N/A
sub-negN/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f6487.2
Applied rewrites87.2%
(FPCore (x y z) :precision binary64 (if (<= z 4.5e+180) (+ 1.0 x) (* (- z) y)))
double code(double x, double y, double z) {
double tmp;
if (z <= 4.5e+180) {
tmp = 1.0 + x;
} else {
tmp = -z * 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 <= 4.5d+180) then
tmp = 1.0d0 + x
else
tmp = -z * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= 4.5e+180) {
tmp = 1.0 + x;
} else {
tmp = -z * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 4.5e+180: tmp = 1.0 + x else: tmp = -z * y return tmp
function code(x, y, z) tmp = 0.0 if (z <= 4.5e+180) tmp = Float64(1.0 + x); else tmp = Float64(Float64(-z) * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 4.5e+180) tmp = 1.0 + x; else tmp = -z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 4.5e+180], N[(1.0 + x), $MachinePrecision], N[((-z) * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 4.5 \cdot 10^{+180}:\\
\;\;\;\;1 + x\\
\mathbf{else}:\\
\;\;\;\;\left(-z\right) \cdot y\\
\end{array}
\end{array}
if z < 4.49999999999999981e180Initial program 99.9%
Taylor expanded in y around 0
lower-+.f6467.1
Applied rewrites67.1%
if 4.49999999999999981e180 < z Initial program 99.8%
Taylor expanded in y around 0
associate-+r+N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-+.f6446.9
Applied rewrites46.9%
Taylor expanded in z around inf
Applied rewrites40.5%
(FPCore (x y z) :precision binary64 (+ 1.0 x))
double code(double x, double y, double z) {
return 1.0 + x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 1.0d0 + x
end function
public static double code(double x, double y, double z) {
return 1.0 + x;
}
def code(x, y, z): return 1.0 + x
function code(x, y, z) return Float64(1.0 + x) end
function tmp = code(x, y, z) tmp = 1.0 + x; end
code[x_, y_, z_] := N[(1.0 + x), $MachinePrecision]
\begin{array}{l}
\\
1 + x
\end{array}
Initial program 99.9%
Taylor expanded in y around 0
lower-+.f6461.9
Applied rewrites61.9%
(FPCore (x y z) :precision binary64 1.0)
double code(double x, double y, double z) {
return 1.0;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 1.0d0
end function
public static double code(double x, double y, double z) {
return 1.0;
}
def code(x, y, z): return 1.0
function code(x, y, z) return 1.0 end
function tmp = code(x, y, z) tmp = 1.0; end
code[x_, y_, z_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 99.9%
Taylor expanded in y around 0
lower-+.f6461.9
Applied rewrites61.9%
Taylor expanded in x around 0
Applied rewrites20.1%
herbie shell --seed 2024240
(FPCore (x y z)
:name "Graphics.Rasterific.Svg.PathConverter:segmentToBezier from rasterific-svg-0.2.3.1, B"
:precision binary64
(- (+ x (cos y)) (* z (sin y))))