
(FPCore (x y z) :precision binary64 (* x (- 1.0 (* (- 1.0 y) z))))
double code(double x, double y, double z) {
return x * (1.0 - ((1.0 - 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 * (1.0d0 - ((1.0d0 - y) * z))
end function
public static double code(double x, double y, double z) {
return x * (1.0 - ((1.0 - y) * z));
}
def code(x, y, z): return x * (1.0 - ((1.0 - y) * z))
function code(x, y, z) return Float64(x * Float64(1.0 - Float64(Float64(1.0 - y) * z))) end
function tmp = code(x, y, z) tmp = x * (1.0 - ((1.0 - y) * z)); end
code[x_, y_, z_] := N[(x * N[(1.0 - N[(N[(1.0 - y), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (* x (- 1.0 (* (- 1.0 y) z))))
double code(double x, double y, double z) {
return x * (1.0 - ((1.0 - 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 * (1.0d0 - ((1.0d0 - y) * z))
end function
public static double code(double x, double y, double z) {
return x * (1.0 - ((1.0 - y) * z));
}
def code(x, y, z): return x * (1.0 - ((1.0 - y) * z))
function code(x, y, z) return Float64(x * Float64(1.0 - Float64(Float64(1.0 - y) * z))) end
function tmp = code(x, y, z) tmp = x * (1.0 - ((1.0 - y) * z)); end
code[x_, y_, z_] := N[(x * N[(1.0 - N[(N[(1.0 - y), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
\end{array}
(FPCore (x y z) :precision binary64 (fma (+ y -1.0) (* x z) x))
double code(double x, double y, double z) {
return fma((y + -1.0), (x * z), x);
}
function code(x, y, z) return fma(Float64(y + -1.0), Float64(x * z), x) end
code[x_, y_, z_] := N[(N[(y + -1.0), $MachinePrecision] * N[(x * z), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y + -1, x \cdot z, x\right)
\end{array}
Initial program 98.8%
distribute-rgt-out--98.8%
*-lft-identity98.8%
cancel-sign-sub-inv98.8%
+-commutative98.8%
distribute-lft-neg-in98.8%
associate-*l*99.6%
fma-def99.6%
neg-sub099.6%
associate--r-99.6%
metadata-eval99.6%
+-commutative99.6%
*-commutative99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (- (* x z))))
(if (<= z -1.0)
t_0
(if (<= z 5.9e-86)
x
(if (or (<= z 4.2e+155) (and (not (<= z 7.6e+227)) (<= z 2.35e+266)))
(* y (* x z))
t_0)))))
double code(double x, double y, double z) {
double t_0 = -(x * z);
double tmp;
if (z <= -1.0) {
tmp = t_0;
} else if (z <= 5.9e-86) {
tmp = x;
} else if ((z <= 4.2e+155) || (!(z <= 7.6e+227) && (z <= 2.35e+266))) {
tmp = y * (x * z);
} 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 = -(x * z)
if (z <= (-1.0d0)) then
tmp = t_0
else if (z <= 5.9d-86) then
tmp = x
else if ((z <= 4.2d+155) .or. (.not. (z <= 7.6d+227)) .and. (z <= 2.35d+266)) then
tmp = y * (x * z)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = -(x * z);
double tmp;
if (z <= -1.0) {
tmp = t_0;
} else if (z <= 5.9e-86) {
tmp = x;
} else if ((z <= 4.2e+155) || (!(z <= 7.6e+227) && (z <= 2.35e+266))) {
tmp = y * (x * z);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = -(x * z) tmp = 0 if z <= -1.0: tmp = t_0 elif z <= 5.9e-86: tmp = x elif (z <= 4.2e+155) or (not (z <= 7.6e+227) and (z <= 2.35e+266)): tmp = y * (x * z) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(-Float64(x * z)) tmp = 0.0 if (z <= -1.0) tmp = t_0; elseif (z <= 5.9e-86) tmp = x; elseif ((z <= 4.2e+155) || (!(z <= 7.6e+227) && (z <= 2.35e+266))) tmp = Float64(y * Float64(x * z)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = -(x * z); tmp = 0.0; if (z <= -1.0) tmp = t_0; elseif (z <= 5.9e-86) tmp = x; elseif ((z <= 4.2e+155) || (~((z <= 7.6e+227)) && (z <= 2.35e+266))) tmp = y * (x * z); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = (-N[(x * z), $MachinePrecision])}, If[LessEqual[z, -1.0], t$95$0, If[LessEqual[z, 5.9e-86], x, If[Or[LessEqual[z, 4.2e+155], And[N[Not[LessEqual[z, 7.6e+227]], $MachinePrecision], LessEqual[z, 2.35e+266]]], N[(y * N[(x * z), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -x \cdot z\\
\mathbf{if}\;z \leq -1:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 5.9 \cdot 10^{-86}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 4.2 \cdot 10^{+155} \lor \neg \left(z \leq 7.6 \cdot 10^{+227}\right) \land z \leq 2.35 \cdot 10^{+266}:\\
\;\;\;\;y \cdot \left(x \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if z < -1 or 4.2e155 < z < 7.60000000000000071e227 or 2.3499999999999999e266 < z Initial program 97.2%
Taylor expanded in y around 0 79.7%
Taylor expanded in z around inf 76.9%
mul-1-neg76.9%
distribute-rgt-neg-out76.9%
Simplified76.9%
if -1 < z < 5.89999999999999998e-86Initial program 100.0%
Taylor expanded in z around 0 85.2%
if 5.89999999999999998e-86 < z < 4.2e155 or 7.60000000000000071e227 < z < 2.3499999999999999e266Initial program 98.3%
Taylor expanded in y around inf 62.8%
Final simplification77.6%
(FPCore (x y z)
:precision binary64
(if (<= y -3.4e+164)
(* z (* y x))
(if (<= y 3.8e+79)
(* x (- 1.0 z))
(if (<= y 1.38e+178)
(* y (* x z))
(if (<= y 2.15e+213) x (* x (* y z)))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -3.4e+164) {
tmp = z * (y * x);
} else if (y <= 3.8e+79) {
tmp = x * (1.0 - z);
} else if (y <= 1.38e+178) {
tmp = y * (x * z);
} else if (y <= 2.15e+213) {
tmp = x;
} else {
tmp = x * (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 <= (-3.4d+164)) then
tmp = z * (y * x)
else if (y <= 3.8d+79) then
tmp = x * (1.0d0 - z)
else if (y <= 1.38d+178) then
tmp = y * (x * z)
else if (y <= 2.15d+213) then
tmp = x
else
tmp = x * (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -3.4e+164) {
tmp = z * (y * x);
} else if (y <= 3.8e+79) {
tmp = x * (1.0 - z);
} else if (y <= 1.38e+178) {
tmp = y * (x * z);
} else if (y <= 2.15e+213) {
tmp = x;
} else {
tmp = x * (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3.4e+164: tmp = z * (y * x) elif y <= 3.8e+79: tmp = x * (1.0 - z) elif y <= 1.38e+178: tmp = y * (x * z) elif y <= 2.15e+213: tmp = x else: tmp = x * (y * z) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3.4e+164) tmp = Float64(z * Float64(y * x)); elseif (y <= 3.8e+79) tmp = Float64(x * Float64(1.0 - z)); elseif (y <= 1.38e+178) tmp = Float64(y * Float64(x * z)); elseif (y <= 2.15e+213) tmp = x; else tmp = Float64(x * Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -3.4e+164) tmp = z * (y * x); elseif (y <= 3.8e+79) tmp = x * (1.0 - z); elseif (y <= 1.38e+178) tmp = y * (x * z); elseif (y <= 2.15e+213) tmp = x; else tmp = x * (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3.4e+164], N[(z * N[(y * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 3.8e+79], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.38e+178], N[(y * N[(x * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.15e+213], x, N[(x * N[(y * z), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.4 \cdot 10^{+164}:\\
\;\;\;\;z \cdot \left(y \cdot x\right)\\
\mathbf{elif}\;y \leq 3.8 \cdot 10^{+79}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{elif}\;y \leq 1.38 \cdot 10^{+178}:\\
\;\;\;\;y \cdot \left(x \cdot z\right)\\
\mathbf{elif}\;y \leq 2.15 \cdot 10^{+213}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y \cdot z\right)\\
\end{array}
\end{array}
if y < -3.4000000000000001e164Initial program 92.3%
Taylor expanded in y around inf 78.5%
associate-*r*74.7%
*-commutative74.7%
associate-*l*78.6%
Simplified78.6%
if -3.4000000000000001e164 < y < 3.8000000000000002e79Initial program 99.4%
Taylor expanded in y around 0 91.9%
if 3.8000000000000002e79 < y < 1.37999999999999994e178Initial program 99.8%
Taylor expanded in y around inf 73.0%
if 1.37999999999999994e178 < y < 2.14999999999999997e213Initial program 100.0%
Taylor expanded in z around 0 85.2%
if 2.14999999999999997e213 < y Initial program 100.0%
Taylor expanded in y around inf 100.0%
mul-1-neg100.0%
distribute-lft-neg-out100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in z around 0 99.8%
Taylor expanded in y around inf 99.8%
associate-*r*100.0%
Simplified100.0%
Final simplification89.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -4.8e+24) (not (<= z 1.15e-13))) (* z (- (* y x) x)) (- x (* x z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -4.8e+24) || !(z <= 1.15e-13)) {
tmp = z * ((y * x) - x);
} else {
tmp = x - (x * 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 ((z <= (-4.8d+24)) .or. (.not. (z <= 1.15d-13))) then
tmp = z * ((y * x) - x)
else
tmp = x - (x * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -4.8e+24) || !(z <= 1.15e-13)) {
tmp = z * ((y * x) - x);
} else {
tmp = x - (x * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -4.8e+24) or not (z <= 1.15e-13): tmp = z * ((y * x) - x) else: tmp = x - (x * z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -4.8e+24) || !(z <= 1.15e-13)) tmp = Float64(z * Float64(Float64(y * x) - x)); else tmp = Float64(x - Float64(x * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -4.8e+24) || ~((z <= 1.15e-13))) tmp = z * ((y * x) - x); else tmp = x - (x * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -4.8e+24], N[Not[LessEqual[z, 1.15e-13]], $MachinePrecision]], N[(z * N[(N[(y * x), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision], N[(x - N[(x * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.8 \cdot 10^{+24} \lor \neg \left(z \leq 1.15 \cdot 10^{-13}\right):\\
\;\;\;\;z \cdot \left(y \cdot x - x\right)\\
\mathbf{else}:\\
\;\;\;\;x - x \cdot z\\
\end{array}
\end{array}
if z < -4.8000000000000001e24 or 1.1499999999999999e-13 < z Initial program 97.4%
Taylor expanded in z around inf 98.7%
*-commutative98.7%
sub-neg98.7%
metadata-eval98.7%
distribute-rgt-in98.7%
neg-mul-198.7%
unsub-neg98.7%
Simplified98.7%
if -4.8000000000000001e24 < z < 1.1499999999999999e-13Initial program 99.9%
Taylor expanded in y around 0 82.5%
*-commutative82.5%
distribute-rgt-out--82.5%
*-lft-identity82.5%
Simplified82.5%
Final simplification89.5%
(FPCore (x y z) :precision binary64 (if (<= z -4.8e+24) (* z (- (* y x) x)) (if (<= z 2.5e-14) (- x (* x z)) (* (* x z) (+ y -1.0)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -4.8e+24) {
tmp = z * ((y * x) - x);
} else if (z <= 2.5e-14) {
tmp = x - (x * z);
} else {
tmp = (x * z) * (y + -1.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) :: tmp
if (z <= (-4.8d+24)) then
tmp = z * ((y * x) - x)
else if (z <= 2.5d-14) then
tmp = x - (x * z)
else
tmp = (x * z) * (y + (-1.0d0))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -4.8e+24) {
tmp = z * ((y * x) - x);
} else if (z <= 2.5e-14) {
tmp = x - (x * z);
} else {
tmp = (x * z) * (y + -1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -4.8e+24: tmp = z * ((y * x) - x) elif z <= 2.5e-14: tmp = x - (x * z) else: tmp = (x * z) * (y + -1.0) return tmp
function code(x, y, z) tmp = 0.0 if (z <= -4.8e+24) tmp = Float64(z * Float64(Float64(y * x) - x)); elseif (z <= 2.5e-14) tmp = Float64(x - Float64(x * z)); else tmp = Float64(Float64(x * z) * Float64(y + -1.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -4.8e+24) tmp = z * ((y * x) - x); elseif (z <= 2.5e-14) tmp = x - (x * z); else tmp = (x * z) * (y + -1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -4.8e+24], N[(z * N[(N[(y * x), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 2.5e-14], N[(x - N[(x * z), $MachinePrecision]), $MachinePrecision], N[(N[(x * z), $MachinePrecision] * N[(y + -1.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.8 \cdot 10^{+24}:\\
\;\;\;\;z \cdot \left(y \cdot x - x\right)\\
\mathbf{elif}\;z \leq 2.5 \cdot 10^{-14}:\\
\;\;\;\;x - x \cdot z\\
\mathbf{else}:\\
\;\;\;\;\left(x \cdot z\right) \cdot \left(y + -1\right)\\
\end{array}
\end{array}
if z < -4.8000000000000001e24Initial program 97.7%
Taylor expanded in z around inf 100.0%
*-commutative100.0%
sub-neg100.0%
metadata-eval100.0%
distribute-rgt-in100.0%
neg-mul-1100.0%
unsub-neg100.0%
Simplified100.0%
if -4.8000000000000001e24 < z < 2.5000000000000001e-14Initial program 99.9%
Taylor expanded in y around 0 82.5%
*-commutative82.5%
distribute-rgt-out--82.5%
*-lft-identity82.5%
Simplified82.5%
if 2.5000000000000001e-14 < z Initial program 97.2%
Taylor expanded in z around inf 98.0%
*-commutative98.0%
associate-*l*98.0%
sub-neg98.0%
metadata-eval98.0%
*-commutative98.0%
Simplified98.0%
Final simplification89.5%
(FPCore (x y z) :precision binary64 (if (<= z -1.1) (* z (- (* y x) x)) (if (<= z 3700.0) (* x (+ 1.0 (* y z))) (* (* x z) (+ y -1.0)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.1) {
tmp = z * ((y * x) - x);
} else if (z <= 3700.0) {
tmp = x * (1.0 + (y * z));
} else {
tmp = (x * z) * (y + -1.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) :: tmp
if (z <= (-1.1d0)) then
tmp = z * ((y * x) - x)
else if (z <= 3700.0d0) then
tmp = x * (1.0d0 + (y * z))
else
tmp = (x * z) * (y + (-1.0d0))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.1) {
tmp = z * ((y * x) - x);
} else if (z <= 3700.0) {
tmp = x * (1.0 + (y * z));
} else {
tmp = (x * z) * (y + -1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.1: tmp = z * ((y * x) - x) elif z <= 3700.0: tmp = x * (1.0 + (y * z)) else: tmp = (x * z) * (y + -1.0) return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.1) tmp = Float64(z * Float64(Float64(y * x) - x)); elseif (z <= 3700.0) tmp = Float64(x * Float64(1.0 + Float64(y * z))); else tmp = Float64(Float64(x * z) * Float64(y + -1.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.1) tmp = z * ((y * x) - x); elseif (z <= 3700.0) tmp = x * (1.0 + (y * z)); else tmp = (x * z) * (y + -1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.1], N[(z * N[(N[(y * x), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 3700.0], N[(x * N[(1.0 + N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * z), $MachinePrecision] * N[(y + -1.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.1:\\
\;\;\;\;z \cdot \left(y \cdot x - x\right)\\
\mathbf{elif}\;z \leq 3700:\\
\;\;\;\;x \cdot \left(1 + y \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;\left(x \cdot z\right) \cdot \left(y + -1\right)\\
\end{array}
\end{array}
if z < -1.1000000000000001Initial program 97.9%
Taylor expanded in z around inf 95.7%
*-commutative95.7%
sub-neg95.7%
metadata-eval95.7%
distribute-rgt-in95.8%
neg-mul-195.8%
unsub-neg95.8%
Simplified95.8%
if -1.1000000000000001 < z < 3700Initial program 99.9%
Taylor expanded in y around inf 99.9%
mul-1-neg99.9%
distribute-lft-neg-out99.9%
*-commutative99.9%
Simplified99.9%
Taylor expanded in z around 0 99.2%
Taylor expanded in x around 0 99.9%
if 3700 < z Initial program 97.1%
Taylor expanded in z around inf 97.9%
*-commutative97.9%
associate-*l*98.0%
sub-neg98.0%
metadata-eval98.0%
*-commutative98.0%
Simplified98.0%
Final simplification98.6%
(FPCore (x y z) :precision binary64 (if (<= y -450.0) (+ x (* y (* x z))) (if (<= y 1.5e-5) (* x (- 1.0 z)) (* x (+ 1.0 (* y z))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -450.0) {
tmp = x + (y * (x * z));
} else if (y <= 1.5e-5) {
tmp = x * (1.0 - 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 (y <= (-450.0d0)) then
tmp = x + (y * (x * z))
else if (y <= 1.5d-5) then
tmp = x * (1.0d0 - 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 (y <= -450.0) {
tmp = x + (y * (x * z));
} else if (y <= 1.5e-5) {
tmp = x * (1.0 - z);
} else {
tmp = x * (1.0 + (y * z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -450.0: tmp = x + (y * (x * z)) elif y <= 1.5e-5: tmp = x * (1.0 - z) else: tmp = x * (1.0 + (y * z)) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -450.0) tmp = Float64(x + Float64(y * Float64(x * z))); elseif (y <= 1.5e-5) tmp = Float64(x * Float64(1.0 - 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 (y <= -450.0) tmp = x + (y * (x * z)); elseif (y <= 1.5e-5) tmp = x * (1.0 - z); else tmp = x * (1.0 + (y * z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -450.0], N[(x + N[(y * N[(x * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.5e-5], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 + N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -450:\\
\;\;\;\;x + y \cdot \left(x \cdot z\right)\\
\mathbf{elif}\;y \leq 1.5 \cdot 10^{-5}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 + y \cdot z\right)\\
\end{array}
\end{array}
if y < -450Initial program 94.8%
Taylor expanded in y around inf 94.1%
mul-1-neg94.1%
distribute-lft-neg-out94.1%
*-commutative94.1%
Simplified94.1%
Taylor expanded in z around 0 97.5%
if -450 < y < 1.50000000000000004e-5Initial program 100.0%
Taylor expanded in y around 0 99.6%
if 1.50000000000000004e-5 < y Initial program 99.9%
Taylor expanded in y around inf 99.6%
mul-1-neg99.6%
distribute-lft-neg-out99.6%
*-commutative99.6%
Simplified99.6%
Taylor expanded in z around 0 99.5%
Taylor expanded in x around 0 99.6%
Final simplification99.1%
(FPCore (x y z) :precision binary64 (* x (+ 1.0 (* z (+ y -1.0)))))
double code(double x, double y, double z) {
return x * (1.0 + (z * (y + -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 + (z * (y + (-1.0d0))))
end function
public static double code(double x, double y, double z) {
return x * (1.0 + (z * (y + -1.0)));
}
def code(x, y, z): return x * (1.0 + (z * (y + -1.0)))
function code(x, y, z) return Float64(x * Float64(1.0 + Float64(z * Float64(y + -1.0)))) end
function tmp = code(x, y, z) tmp = x * (1.0 + (z * (y + -1.0))); end
code[x_, y_, z_] := N[(x * N[(1.0 + N[(z * N[(y + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(1 + z \cdot \left(y + -1\right)\right)
\end{array}
Initial program 98.8%
Final simplification98.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.0) (not (<= z 1.15e-13))) (- (* x z)) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 1.15e-13)) {
tmp = -(x * 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.0d0)) .or. (.not. (z <= 1.15d-13))) then
tmp = -(x * 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.0) || !(z <= 1.15e-13)) {
tmp = -(x * z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.0) or not (z <= 1.15e-13): tmp = -(x * z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.0) || !(z <= 1.15e-13)) tmp = Float64(-Float64(x * z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.0) || ~((z <= 1.15e-13))) tmp = -(x * z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.0], N[Not[LessEqual[z, 1.15e-13]], $MachinePrecision]], (-N[(x * z), $MachinePrecision]), x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 1.15 \cdot 10^{-13}\right):\\
\;\;\;\;-x \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1 or 1.1499999999999999e-13 < z Initial program 97.5%
Taylor expanded in y around 0 64.4%
Taylor expanded in z around inf 61.6%
mul-1-neg61.6%
distribute-rgt-neg-out61.6%
Simplified61.6%
if -1 < z < 1.1499999999999999e-13Initial program 99.9%
Taylor expanded in z around 0 81.8%
Final simplification72.6%
(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 98.8%
Taylor expanded in z around 0 46.4%
Final simplification46.4%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (- 1.0 (* (- 1.0 y) z))))
(t_1 (+ x (* (- 1.0 y) (* (- z) x)))))
(if (< t_0 -1.618195973607049e+50)
t_1
(if (< t_0 3.892237649663903e+134) (- (* (* x y) z) (- (* x z) x)) t_1))))
double code(double x, double y, double z) {
double t_0 = x * (1.0 - ((1.0 - y) * z));
double t_1 = x + ((1.0 - y) * (-z * x));
double tmp;
if (t_0 < -1.618195973607049e+50) {
tmp = t_1;
} else if (t_0 < 3.892237649663903e+134) {
tmp = ((x * y) * z) - ((x * z) - x);
} else {
tmp = t_1;
}
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) :: t_1
real(8) :: tmp
t_0 = x * (1.0d0 - ((1.0d0 - y) * z))
t_1 = x + ((1.0d0 - y) * (-z * x))
if (t_0 < (-1.618195973607049d+50)) then
tmp = t_1
else if (t_0 < 3.892237649663903d+134) then
tmp = ((x * y) * z) - ((x * z) - x)
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * (1.0 - ((1.0 - y) * z));
double t_1 = x + ((1.0 - y) * (-z * x));
double tmp;
if (t_0 < -1.618195973607049e+50) {
tmp = t_1;
} else if (t_0 < 3.892237649663903e+134) {
tmp = ((x * y) * z) - ((x * z) - x);
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z): t_0 = x * (1.0 - ((1.0 - y) * z)) t_1 = x + ((1.0 - y) * (-z * x)) tmp = 0 if t_0 < -1.618195973607049e+50: tmp = t_1 elif t_0 < 3.892237649663903e+134: tmp = ((x * y) * z) - ((x * z) - x) else: tmp = t_1 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(1.0 - Float64(Float64(1.0 - y) * z))) t_1 = Float64(x + Float64(Float64(1.0 - y) * Float64(Float64(-z) * x))) tmp = 0.0 if (t_0 < -1.618195973607049e+50) tmp = t_1; elseif (t_0 < 3.892237649663903e+134) tmp = Float64(Float64(Float64(x * y) * z) - Float64(Float64(x * z) - x)); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * (1.0 - ((1.0 - y) * z)); t_1 = x + ((1.0 - y) * (-z * x)); tmp = 0.0; if (t_0 < -1.618195973607049e+50) tmp = t_1; elseif (t_0 < 3.892237649663903e+134) tmp = ((x * y) * z) - ((x * z) - x); else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(1.0 - N[(N[(1.0 - y), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x + N[(N[(1.0 - y), $MachinePrecision] * N[((-z) * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[Less[t$95$0, -1.618195973607049e+50], t$95$1, If[Less[t$95$0, 3.892237649663903e+134], N[(N[(N[(x * y), $MachinePrecision] * z), $MachinePrecision] - N[(N[(x * z), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\\
t_1 := x + \left(1 - y\right) \cdot \left(\left(-z\right) \cdot x\right)\\
\mathbf{if}\;t_0 < -1.618195973607049 \cdot 10^{+50}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;t_0 < 3.892237649663903 \cdot 10^{+134}:\\
\;\;\;\;\left(x \cdot y\right) \cdot z - \left(x \cdot z - x\right)\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
herbie shell --seed 2023238
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, J"
:precision binary64
:herbie-target
(if (< (* x (- 1.0 (* (- 1.0 y) z))) -1.618195973607049e+50) (+ x (* (- 1.0 y) (* (- z) x))) (if (< (* x (- 1.0 (* (- 1.0 y) z))) 3.892237649663903e+134) (- (* (* x y) z) (- (* x z) x)) (+ x (* (- 1.0 y) (* (- z) x)))))
(* x (- 1.0 (* (- 1.0 y) z))))