
(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 8 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 (fma (sin y) (- z) (+ (cos y) x)))
double code(double x, double y, double z) {
return fma(sin(y), -z, (cos(y) + x));
}
function code(x, y, z) return fma(sin(y), Float64(-z), Float64(cos(y) + x)) end
code[x_, y_, z_] := N[(N[Sin[y], $MachinePrecision] * (-z) + N[(N[Cos[y], $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\sin y, -z, \cos y + x\right)
\end{array}
Initial program 99.9%
Taylor expanded in z around 0 99.9%
associate-+r+99.9%
associate-*r*99.9%
neg-mul-199.9%
*-commutative99.9%
+-commutative99.9%
fma-def99.9%
+-commutative99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (<= x -5.5e-10) (+ (cos y) x) (if (<= x 235000.0) (- (cos y) (* (sin y) z)) (+ x (- 1.0 (* y z))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -5.5e-10) {
tmp = cos(y) + x;
} else if (x <= 235000.0) {
tmp = cos(y) - (sin(y) * z);
} else {
tmp = x + (1.0 - (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 <= (-5.5d-10)) then
tmp = cos(y) + x
else if (x <= 235000.0d0) then
tmp = cos(y) - (sin(y) * z)
else
tmp = x + (1.0d0 - (y * z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -5.5e-10) {
tmp = Math.cos(y) + x;
} else if (x <= 235000.0) {
tmp = Math.cos(y) - (Math.sin(y) * z);
} else {
tmp = x + (1.0 - (y * z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -5.5e-10: tmp = math.cos(y) + x elif x <= 235000.0: tmp = math.cos(y) - (math.sin(y) * z) else: tmp = x + (1.0 - (y * z)) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -5.5e-10) tmp = Float64(cos(y) + x); elseif (x <= 235000.0) tmp = Float64(cos(y) - Float64(sin(y) * z)); else tmp = Float64(x + Float64(1.0 - Float64(y * z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -5.5e-10) tmp = cos(y) + x; elseif (x <= 235000.0) tmp = cos(y) - (sin(y) * z); else tmp = x + (1.0 - (y * z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -5.5e-10], N[(N[Cos[y], $MachinePrecision] + x), $MachinePrecision], If[LessEqual[x, 235000.0], N[(N[Cos[y], $MachinePrecision] - N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision], N[(x + N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.5 \cdot 10^{-10}:\\
\;\;\;\;\cos y + x\\
\mathbf{elif}\;x \leq 235000:\\
\;\;\;\;\cos y - \sin y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + \left(1 - y \cdot z\right)\\
\end{array}
\end{array}
if x < -5.4999999999999996e-10Initial program 100.0%
Taylor expanded in z around 0 91.0%
+-commutative91.0%
Simplified91.0%
if -5.4999999999999996e-10 < x < 235000Initial program 99.9%
Taylor expanded in x around 0 98.3%
if 235000 < x Initial program 99.9%
Taylor expanded in y around 0 82.4%
associate-+r+82.4%
+-commutative82.4%
associate-+l+82.4%
mul-1-neg82.4%
unsub-neg82.4%
Simplified82.4%
Final simplification92.6%
(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 (* (sin y) (- z))))
(if (<= z -3.4e+162)
t_0
(if (<= z -1.9e+126)
(+ x (- 1.0 (* y z)))
(if (or (<= z -1.3e+115) (not (<= z 1.4e+149))) t_0 (+ (cos y) x))))))
double code(double x, double y, double z) {
double t_0 = sin(y) * -z;
double tmp;
if (z <= -3.4e+162) {
tmp = t_0;
} else if (z <= -1.9e+126) {
tmp = x + (1.0 - (y * z));
} else if ((z <= -1.3e+115) || !(z <= 1.4e+149)) {
tmp = t_0;
} else {
tmp = cos(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) :: t_0
real(8) :: tmp
t_0 = sin(y) * -z
if (z <= (-3.4d+162)) then
tmp = t_0
else if (z <= (-1.9d+126)) then
tmp = x + (1.0d0 - (y * z))
else if ((z <= (-1.3d+115)) .or. (.not. (z <= 1.4d+149))) then
tmp = t_0
else
tmp = cos(y) + x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = Math.sin(y) * -z;
double tmp;
if (z <= -3.4e+162) {
tmp = t_0;
} else if (z <= -1.9e+126) {
tmp = x + (1.0 - (y * z));
} else if ((z <= -1.3e+115) || !(z <= 1.4e+149)) {
tmp = t_0;
} else {
tmp = Math.cos(y) + x;
}
return tmp;
}
def code(x, y, z): t_0 = math.sin(y) * -z tmp = 0 if z <= -3.4e+162: tmp = t_0 elif z <= -1.9e+126: tmp = x + (1.0 - (y * z)) elif (z <= -1.3e+115) or not (z <= 1.4e+149): tmp = t_0 else: tmp = math.cos(y) + x return tmp
function code(x, y, z) t_0 = Float64(sin(y) * Float64(-z)) tmp = 0.0 if (z <= -3.4e+162) tmp = t_0; elseif (z <= -1.9e+126) tmp = Float64(x + Float64(1.0 - Float64(y * z))); elseif ((z <= -1.3e+115) || !(z <= 1.4e+149)) tmp = t_0; else tmp = Float64(cos(y) + x); end return tmp end
function tmp_2 = code(x, y, z) t_0 = sin(y) * -z; tmp = 0.0; if (z <= -3.4e+162) tmp = t_0; elseif (z <= -1.9e+126) tmp = x + (1.0 - (y * z)); elseif ((z <= -1.3e+115) || ~((z <= 1.4e+149))) tmp = t_0; else tmp = cos(y) + x; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Sin[y], $MachinePrecision] * (-z)), $MachinePrecision]}, If[LessEqual[z, -3.4e+162], t$95$0, If[LessEqual[z, -1.9e+126], N[(x + N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[z, -1.3e+115], N[Not[LessEqual[z, 1.4e+149]], $MachinePrecision]], t$95$0, N[(N[Cos[y], $MachinePrecision] + x), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin y \cdot \left(-z\right)\\
\mathbf{if}\;z \leq -3.4 \cdot 10^{+162}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -1.9 \cdot 10^{+126}:\\
\;\;\;\;x + \left(1 - y \cdot z\right)\\
\mathbf{elif}\;z \leq -1.3 \cdot 10^{+115} \lor \neg \left(z \leq 1.4 \cdot 10^{+149}\right):\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\cos y + x\\
\end{array}
\end{array}
if z < -3.40000000000000003e162 or -1.90000000000000008e126 < z < -1.3e115 or 1.4e149 < z Initial program 99.8%
Taylor expanded in z around inf 76.9%
associate-*r*76.9%
neg-mul-176.9%
*-commutative76.9%
Simplified76.9%
if -3.40000000000000003e162 < z < -1.90000000000000008e126Initial program 99.8%
Taylor expanded in y around 0 84.7%
associate-+r+84.7%
+-commutative84.7%
associate-+l+84.7%
mul-1-neg84.7%
unsub-neg84.7%
Simplified84.7%
if -1.3e115 < z < 1.4e149Initial program 100.0%
Taylor expanded in z around 0 92.7%
+-commutative92.7%
Simplified92.7%
Final simplification87.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -235000.0) (not (<= y 1600000.0))) (+ (cos y) x) (+ x (- 1.0 (* y z)))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -235000.0) || !(y <= 1600000.0)) {
tmp = cos(y) + x;
} else {
tmp = x + (1.0 - (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 ((y <= (-235000.0d0)) .or. (.not. (y <= 1600000.0d0))) then
tmp = cos(y) + x
else
tmp = x + (1.0d0 - (y * z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -235000.0) || !(y <= 1600000.0)) {
tmp = Math.cos(y) + x;
} else {
tmp = x + (1.0 - (y * z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -235000.0) or not (y <= 1600000.0): tmp = math.cos(y) + x else: tmp = x + (1.0 - (y * z)) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -235000.0) || !(y <= 1600000.0)) tmp = Float64(cos(y) + x); else tmp = Float64(x + Float64(1.0 - Float64(y * z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -235000.0) || ~((y <= 1600000.0))) tmp = cos(y) + x; else tmp = x + (1.0 - (y * z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -235000.0], N[Not[LessEqual[y, 1600000.0]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] + x), $MachinePrecision], N[(x + N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -235000 \lor \neg \left(y \leq 1600000\right):\\
\;\;\;\;\cos y + x\\
\mathbf{else}:\\
\;\;\;\;x + \left(1 - y \cdot z\right)\\
\end{array}
\end{array}
if y < -235000 or 1.6e6 < y Initial program 99.8%
Taylor expanded in z around 0 60.5%
+-commutative60.5%
Simplified60.5%
if -235000 < y < 1.6e6Initial program 100.0%
Taylor expanded in y around 0 98.1%
associate-+r+98.1%
+-commutative98.1%
associate-+l+98.1%
mul-1-neg98.1%
unsub-neg98.1%
Simplified98.1%
Final simplification80.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.75e+53) (not (<= y 3.5e+51))) (+ x 1.0) (+ x (- 1.0 (* y z)))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.75e+53) || !(y <= 3.5e+51)) {
tmp = x + 1.0;
} else {
tmp = x + (1.0 - (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 ((y <= (-1.75d+53)) .or. (.not. (y <= 3.5d+51))) then
tmp = x + 1.0d0
else
tmp = x + (1.0d0 - (y * z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.75e+53) || !(y <= 3.5e+51)) {
tmp = x + 1.0;
} else {
tmp = x + (1.0 - (y * z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.75e+53) or not (y <= 3.5e+51): tmp = x + 1.0 else: tmp = x + (1.0 - (y * z)) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.75e+53) || !(y <= 3.5e+51)) tmp = Float64(x + 1.0); else tmp = Float64(x + Float64(1.0 - Float64(y * z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.75e+53) || ~((y <= 3.5e+51))) tmp = x + 1.0; else tmp = x + (1.0 - (y * z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.75e+53], N[Not[LessEqual[y, 3.5e+51]], $MachinePrecision]], N[(x + 1.0), $MachinePrecision], N[(x + N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.75 \cdot 10^{+53} \lor \neg \left(y \leq 3.5 \cdot 10^{+51}\right):\\
\;\;\;\;x + 1\\
\mathbf{else}:\\
\;\;\;\;x + \left(1 - y \cdot z\right)\\
\end{array}
\end{array}
if y < -1.75000000000000009e53 or 3.5e51 < y Initial program 99.8%
Taylor expanded in y around 0 40.1%
+-commutative40.1%
Simplified40.1%
if -1.75000000000000009e53 < y < 3.5e51Initial program 100.0%
Taylor expanded in y around 0 93.0%
associate-+r+93.0%
+-commutative93.0%
associate-+l+93.0%
mul-1-neg93.0%
unsub-neg93.0%
Simplified93.0%
Final simplification72.4%
(FPCore (x y z) :precision binary64 (+ x 1.0))
double code(double x, double y, double z) {
return x + 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 = x + 1.0d0
end function
public static double code(double x, double y, double z) {
return x + 1.0;
}
def code(x, y, z): return x + 1.0
function code(x, y, z) return Float64(x + 1.0) end
function tmp = code(x, y, z) tmp = x + 1.0; end
code[x_, y_, z_] := N[(x + 1.0), $MachinePrecision]
\begin{array}{l}
\\
x + 1
\end{array}
Initial program 99.9%
Taylor expanded in y around 0 62.4%
+-commutative62.4%
Simplified62.4%
Final simplification62.4%
(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.9%
Taylor expanded in x around inf 43.2%
Final simplification43.2%
herbie shell --seed 2024031
(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))))