
(FPCore (x y z) :precision binary64 (+ (* x y) (* z (- 1.0 y))))
double code(double x, double y, double z) {
return (x * y) + (z * (1.0 - 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) + (z * (1.0d0 - y))
end function
public static double code(double x, double y, double z) {
return (x * y) + (z * (1.0 - y));
}
def code(x, y, z): return (x * y) + (z * (1.0 - y))
function code(x, y, z) return Float64(Float64(x * y) + Float64(z * Float64(1.0 - y))) end
function tmp = code(x, y, z) tmp = (x * y) + (z * (1.0 - y)); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(z * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + z \cdot \left(1 - y\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x y) (* z (- 1.0 y))))
double code(double x, double y, double z) {
return (x * y) + (z * (1.0 - 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) + (z * (1.0d0 - y))
end function
public static double code(double x, double y, double z) {
return (x * y) + (z * (1.0 - y));
}
def code(x, y, z): return (x * y) + (z * (1.0 - y))
function code(x, y, z) return Float64(Float64(x * y) + Float64(z * Float64(1.0 - y))) end
function tmp = code(x, y, z) tmp = (x * y) + (z * (1.0 - y)); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(z * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + z \cdot \left(1 - y\right)
\end{array}
(FPCore (x y z) :precision binary64 (+ z (* y (- x z))))
double code(double x, double y, double z) {
return z + (y * (x - z));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z + (y * (x - z))
end function
public static double code(double x, double y, double z) {
return z + (y * (x - z));
}
def code(x, y, z): return z + (y * (x - z))
function code(x, y, z) return Float64(z + Float64(y * Float64(x - z))) end
function tmp = code(x, y, z) tmp = z + (y * (x - z)); end
code[x_, y_, z_] := N[(z + N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + y \cdot \left(x - z\right)
\end{array}
Initial program 98.4%
+-commutative98.4%
+-lft-identity98.4%
cancel-sign-sub98.4%
cancel-sign-sub98.4%
+-lft-identity98.4%
distribute-lft-out--98.4%
*-rgt-identity98.4%
associate-+l-98.4%
distribute-rgt-out--100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (or (<= x -4.8e+100)
(not (or (<= x -9.5e-86) (and (not (<= x -7e-114)) (<= x 9.5e+63)))))
(* y (- x z))
(* z (- 1.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.8e+100) || !((x <= -9.5e-86) || (!(x <= -7e-114) && (x <= 9.5e+63)))) {
tmp = y * (x - z);
} else {
tmp = z * (1.0 - 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 <= (-4.8d+100)) .or. (.not. (x <= (-9.5d-86)) .or. (.not. (x <= (-7d-114))) .and. (x <= 9.5d+63))) then
tmp = y * (x - z)
else
tmp = z * (1.0d0 - y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -4.8e+100) || !((x <= -9.5e-86) || (!(x <= -7e-114) && (x <= 9.5e+63)))) {
tmp = y * (x - z);
} else {
tmp = z * (1.0 - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.8e+100) or not ((x <= -9.5e-86) or (not (x <= -7e-114) and (x <= 9.5e+63))): tmp = y * (x - z) else: tmp = z * (1.0 - y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.8e+100) || !((x <= -9.5e-86) || (!(x <= -7e-114) && (x <= 9.5e+63)))) tmp = Float64(y * Float64(x - z)); else tmp = Float64(z * Float64(1.0 - y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -4.8e+100) || ~(((x <= -9.5e-86) || (~((x <= -7e-114)) && (x <= 9.5e+63))))) tmp = y * (x - z); else tmp = z * (1.0 - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.8e+100], N[Not[Or[LessEqual[x, -9.5e-86], And[N[Not[LessEqual[x, -7e-114]], $MachinePrecision], LessEqual[x, 9.5e+63]]]], $MachinePrecision]], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision], N[(z * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.8 \cdot 10^{+100} \lor \neg \left(x \leq -9.5 \cdot 10^{-86} \lor \neg \left(x \leq -7 \cdot 10^{-114}\right) \land x \leq 9.5 \cdot 10^{+63}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(1 - y\right)\\
\end{array}
\end{array}
if x < -4.80000000000000023e100 or -9.4999999999999996e-86 < x < -7e-114 or 9.5000000000000003e63 < x Initial program 96.3%
Taylor expanded in y around inf 88.1%
mul-1-neg88.1%
sub-neg88.1%
Simplified88.1%
if -4.80000000000000023e100 < x < -9.4999999999999996e-86 or -7e-114 < x < 9.5000000000000003e63Initial program 100.0%
Taylor expanded in x around 0 88.8%
Final simplification88.5%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (- x z))))
(if (<= y -4e-20)
t_0
(if (<= y 6.5e-220)
z
(if (<= y 6.8e-174) (* y x) (if (<= y 1.18e-7) z t_0))))))
double code(double x, double y, double z) {
double t_0 = y * (x - z);
double tmp;
if (y <= -4e-20) {
tmp = t_0;
} else if (y <= 6.5e-220) {
tmp = z;
} else if (y <= 6.8e-174) {
tmp = y * x;
} else if (y <= 1.18e-7) {
tmp = 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 = y * (x - z)
if (y <= (-4d-20)) then
tmp = t_0
else if (y <= 6.5d-220) then
tmp = z
else if (y <= 6.8d-174) then
tmp = y * x
else if (y <= 1.18d-7) then
tmp = z
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y * (x - z);
double tmp;
if (y <= -4e-20) {
tmp = t_0;
} else if (y <= 6.5e-220) {
tmp = z;
} else if (y <= 6.8e-174) {
tmp = y * x;
} else if (y <= 1.18e-7) {
tmp = z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (x - z) tmp = 0 if y <= -4e-20: tmp = t_0 elif y <= 6.5e-220: tmp = z elif y <= 6.8e-174: tmp = y * x elif y <= 1.18e-7: tmp = z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(x - z)) tmp = 0.0 if (y <= -4e-20) tmp = t_0; elseif (y <= 6.5e-220) tmp = z; elseif (y <= 6.8e-174) tmp = Float64(y * x); elseif (y <= 1.18e-7) tmp = z; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * (x - z); tmp = 0.0; if (y <= -4e-20) tmp = t_0; elseif (y <= 6.5e-220) tmp = z; elseif (y <= 6.8e-174) tmp = y * x; elseif (y <= 1.18e-7) tmp = z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -4e-20], t$95$0, If[LessEqual[y, 6.5e-220], z, If[LessEqual[y, 6.8e-174], N[(y * x), $MachinePrecision], If[LessEqual[y, 1.18e-7], z, t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x - z\right)\\
\mathbf{if}\;y \leq -4 \cdot 10^{-20}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 6.5 \cdot 10^{-220}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 6.8 \cdot 10^{-174}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 1.18 \cdot 10^{-7}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -3.99999999999999978e-20 or 1.18e-7 < y Initial program 96.8%
Taylor expanded in y around inf 97.5%
mul-1-neg97.5%
sub-neg97.5%
Simplified97.5%
if -3.99999999999999978e-20 < y < 6.50000000000000005e-220 or 6.8000000000000004e-174 < y < 1.18e-7Initial program 100.0%
Taylor expanded in y around 0 74.0%
if 6.50000000000000005e-220 < y < 6.8000000000000004e-174Initial program 100.0%
Taylor expanded in x around inf 81.0%
*-commutative81.0%
Simplified81.0%
Final simplification85.7%
(FPCore (x y z) :precision binary64 (if (<= y -5.2e+268) (* y x) (if (or (<= y -56.0) (not (<= y 1.0))) (* z (- y)) z)))
double code(double x, double y, double z) {
double tmp;
if (y <= -5.2e+268) {
tmp = y * x;
} else if ((y <= -56.0) || !(y <= 1.0)) {
tmp = z * -y;
} else {
tmp = 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 <= (-5.2d+268)) then
tmp = y * x
else if ((y <= (-56.0d0)) .or. (.not. (y <= 1.0d0))) then
tmp = z * -y
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -5.2e+268) {
tmp = y * x;
} else if ((y <= -56.0) || !(y <= 1.0)) {
tmp = z * -y;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -5.2e+268: tmp = y * x elif (y <= -56.0) or not (y <= 1.0): tmp = z * -y else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -5.2e+268) tmp = Float64(y * x); elseif ((y <= -56.0) || !(y <= 1.0)) tmp = Float64(z * Float64(-y)); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -5.2e+268) tmp = y * x; elseif ((y <= -56.0) || ~((y <= 1.0))) tmp = z * -y; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -5.2e+268], N[(y * x), $MachinePrecision], If[Or[LessEqual[y, -56.0], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(z * (-y)), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.2 \cdot 10^{+268}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -56 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;z \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -5.19999999999999986e268Initial program 99.8%
Taylor expanded in x around inf 87.3%
*-commutative87.3%
Simplified87.3%
if -5.19999999999999986e268 < y < -56 or 1 < y Initial program 96.5%
Taylor expanded in x around 0 62.7%
Taylor expanded in y around inf 61.8%
mul-1-neg61.8%
distribute-lft-neg-out61.8%
*-commutative61.8%
Simplified61.8%
if -56 < y < 1Initial program 100.0%
Taylor expanded in y around 0 68.2%
Final simplification65.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -56.0) (not (<= y 1.0))) (* y (- x z)) (+ z (* y x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -56.0) || !(y <= 1.0)) {
tmp = y * (x - z);
} else {
tmp = z + (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) :: tmp
if ((y <= (-56.0d0)) .or. (.not. (y <= 1.0d0))) then
tmp = y * (x - z)
else
tmp = z + (y * x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -56.0) || !(y <= 1.0)) {
tmp = y * (x - z);
} else {
tmp = z + (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -56.0) or not (y <= 1.0): tmp = y * (x - z) else: tmp = z + (y * x) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -56.0) || !(y <= 1.0)) tmp = Float64(y * Float64(x - z)); else tmp = Float64(z + Float64(y * x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -56.0) || ~((y <= 1.0))) tmp = y * (x - z); else tmp = z + (y * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -56.0], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision], N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -56 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z + y \cdot x\\
\end{array}
\end{array}
if y < -56 or 1 < y Initial program 96.7%
Taylor expanded in y around inf 98.9%
mul-1-neg98.9%
sub-neg98.9%
Simplified98.9%
if -56 < y < 1Initial program 100.0%
+-commutative100.0%
+-lft-identity100.0%
cancel-sign-sub100.0%
cancel-sign-sub100.0%
+-lft-identity100.0%
distribute-lft-out--100.0%
*-rgt-identity100.0%
associate-+l-100.0%
distribute-rgt-out--100.0%
Simplified100.0%
Taylor expanded in z around 0 98.6%
mul-1-neg98.6%
distribute-lft-neg-out98.6%
*-commutative98.6%
Simplified98.6%
Final simplification98.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -6.2e+100) (not (<= x 2e+64))) (* y x) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6.2e+100) || !(x <= 2e+64)) {
tmp = y * x;
} else {
tmp = 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 <= (-6.2d+100)) .or. (.not. (x <= 2d+64))) then
tmp = y * x
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -6.2e+100) || !(x <= 2e+64)) {
tmp = y * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -6.2e+100) or not (x <= 2e+64): tmp = y * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -6.2e+100) || !(x <= 2e+64)) tmp = Float64(y * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -6.2e+100) || ~((x <= 2e+64))) tmp = y * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -6.2e+100], N[Not[LessEqual[x, 2e+64]], $MachinePrecision]], N[(y * x), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.2 \cdot 10^{+100} \lor \neg \left(x \leq 2 \cdot 10^{+64}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -6.20000000000000014e100 or 2.00000000000000004e64 < x Initial program 96.0%
Taylor expanded in x around inf 78.0%
*-commutative78.0%
Simplified78.0%
if -6.20000000000000014e100 < x < 2.00000000000000004e64Initial program 100.0%
Taylor expanded in y around 0 51.5%
Final simplification61.7%
(FPCore (x y z) :precision binary64 z)
double code(double x, double y, double z) {
return z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z
end function
public static double code(double x, double y, double z) {
return z;
}
def code(x, y, z): return z
function code(x, y, z) return z end
function tmp = code(x, y, z) tmp = z; end
code[x_, y_, z_] := z
\begin{array}{l}
\\
z
\end{array}
Initial program 98.4%
Taylor expanded in y around 0 37.8%
Final simplification37.8%
(FPCore (x y z) :precision binary64 (- z (* (- z x) y)))
double code(double x, double y, double z) {
return z - ((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 - ((z - x) * y)
end function
public static double code(double x, double y, double z) {
return z - ((z - x) * y);
}
def code(x, y, z): return z - ((z - x) * y)
function code(x, y, z) return Float64(z - Float64(Float64(z - x) * y)) end
function tmp = code(x, y, z) tmp = z - ((z - x) * y); end
code[x_, y_, z_] := N[(z - N[(N[(z - x), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z - \left(z - x\right) \cdot y
\end{array}
herbie shell --seed 2024079
(FPCore (x y z)
:name "Diagrams.TwoD.Segment:bezierClip from diagrams-lib-1.3.0.3"
:precision binary64
:alt
(- z (* (- z x) y))
(+ (* x y) (* z (- 1.0 y))))