
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * 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) + ((x - 1.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
def code(x, y, z): return (x * y) + ((x - 1.0) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(x - 1.0) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((x - 1.0) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(x - 1\right) \cdot z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * 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) + ((x - 1.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
def code(x, y, z): return (x * y) + ((x - 1.0) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(x - 1.0) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((x - 1.0) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(x - 1\right) \cdot z
\end{array}
(FPCore (x y z) :precision binary64 (- (* x (+ z y)) z))
double code(double x, double y, double z) {
return (x * (z + 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 * (z + y)) - z
end function
public static double code(double x, double y, double z) {
return (x * (z + y)) - z;
}
def code(x, y, z): return (x * (z + y)) - z
function code(x, y, z) return Float64(Float64(x * Float64(z + y)) - z) end
function tmp = code(x, y, z) tmp = (x * (z + y)) - z; end
code[x_, y_, z_] := N[(N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(z + y\right) - z
\end{array}
Initial program 98.4%
*-commutative98.4%
sub-neg98.4%
distribute-rgt-in98.4%
metadata-eval98.4%
neg-mul-198.4%
associate-+r+98.4%
unsub-neg98.4%
+-commutative98.4%
distribute-lft-out100.0%
Simplified100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -2e+236)
(* x y)
(if (<= x -7.2e+52)
(* x z)
(if (<= x -1e-29) (* x y) (if (<= x 1.0) (- z) (* x z))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2e+236) {
tmp = x * y;
} else if (x <= -7.2e+52) {
tmp = x * z;
} else if (x <= -1e-29) {
tmp = x * y;
} else if (x <= 1.0) {
tmp = -z;
} else {
tmp = 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 (x <= (-2d+236)) then
tmp = x * y
else if (x <= (-7.2d+52)) then
tmp = x * z
else if (x <= (-1d-29)) then
tmp = x * y
else if (x <= 1.0d0) then
tmp = -z
else
tmp = x * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -2e+236) {
tmp = x * y;
} else if (x <= -7.2e+52) {
tmp = x * z;
} else if (x <= -1e-29) {
tmp = x * y;
} else if (x <= 1.0) {
tmp = -z;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2e+236: tmp = x * y elif x <= -7.2e+52: tmp = x * z elif x <= -1e-29: tmp = x * y elif x <= 1.0: tmp = -z else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2e+236) tmp = Float64(x * y); elseif (x <= -7.2e+52) tmp = Float64(x * z); elseif (x <= -1e-29) tmp = Float64(x * y); elseif (x <= 1.0) tmp = Float64(-z); else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -2e+236) tmp = x * y; elseif (x <= -7.2e+52) tmp = x * z; elseif (x <= -1e-29) tmp = x * y; elseif (x <= 1.0) tmp = -z; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2e+236], N[(x * y), $MachinePrecision], If[LessEqual[x, -7.2e+52], N[(x * z), $MachinePrecision], If[LessEqual[x, -1e-29], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.0], (-z), N[(x * z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{+236}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -7.2 \cdot 10^{+52}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -1 \cdot 10^{-29}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -2.00000000000000011e236 or -7.2e52 < x < -9.99999999999999943e-30Initial program 95.9%
Taylor expanded in y around inf 81.0%
if -2.00000000000000011e236 < x < -7.2e52 or 1 < x Initial program 96.7%
Taylor expanded in x around inf 99.2%
+-commutative99.2%
Simplified99.2%
distribute-lft-in96.0%
Applied egg-rr96.0%
Taylor expanded in z around inf 59.5%
*-commutative59.5%
Simplified59.5%
if -9.99999999999999943e-30 < x < 1Initial program 100.0%
Taylor expanded in x around 0 69.5%
neg-mul-169.5%
Simplified69.5%
Final simplification67.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.0) (not (<= x 1.0))) (* x (+ z y)) (- (* x y) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
tmp = x * (z + y);
} 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 ((x <= (-1.0d0)) .or. (.not. (x <= 1.0d0))) then
tmp = x * (z + y)
else
tmp = (x * y) - z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
tmp = x * (z + y);
} else {
tmp = (x * y) - z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.0) or not (x <= 1.0): tmp = x * (z + y) else: tmp = (x * y) - z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.0) || !(x <= 1.0)) tmp = Float64(x * Float64(z + y)); else tmp = Float64(Float64(x * y) - z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.0) || ~((x <= 1.0))) tmp = x * (z + y); else tmp = (x * y) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], N[(N[(x * y), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y - z\\
\end{array}
\end{array}
if x < -1 or 1 < x Initial program 96.4%
Taylor expanded in x around inf 99.3%
+-commutative99.3%
Simplified99.3%
if -1 < x < 1Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-rgt-in100.0%
metadata-eval100.0%
neg-mul-1100.0%
associate-+r+100.0%
unsub-neg100.0%
+-commutative100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around inf 94.6%
Taylor expanded in z around 0 99.0%
Final simplification99.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.48e-24) (not (<= x 7.2e-69))) (* x (+ z y)) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.48e-24) || !(x <= 7.2e-69)) {
tmp = x * (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 ((x <= (-1.48d-24)) .or. (.not. (x <= 7.2d-69))) then
tmp = x * (z + y)
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.48e-24) || !(x <= 7.2e-69)) {
tmp = x * (z + y);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.48e-24) or not (x <= 7.2e-69): tmp = x * (z + y) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.48e-24) || !(x <= 7.2e-69)) tmp = Float64(x * Float64(z + y)); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.48e-24) || ~((x <= 7.2e-69))) tmp = x * (z + y); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.48e-24], N[Not[LessEqual[x, 7.2e-69]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.48 \cdot 10^{-24} \lor \neg \left(x \leq 7.2 \cdot 10^{-69}\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -1.48000000000000003e-24 or 7.20000000000000035e-69 < x Initial program 97.0%
Taylor expanded in x around inf 92.6%
+-commutative92.6%
Simplified92.6%
if -1.48000000000000003e-24 < x < 7.20000000000000035e-69Initial program 100.0%
Taylor expanded in x around 0 72.9%
neg-mul-172.9%
Simplified72.9%
Final simplification83.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -8.2e-24) (not (<= x 6e-104))) (* x y) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -8.2e-24) || !(x <= 6e-104)) {
tmp = x * 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 ((x <= (-8.2d-24)) .or. (.not. (x <= 6d-104))) then
tmp = x * y
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -8.2e-24) || !(x <= 6e-104)) {
tmp = x * y;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -8.2e-24) or not (x <= 6e-104): tmp = x * y else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -8.2e-24) || !(x <= 6e-104)) tmp = Float64(x * y); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -8.2e-24) || ~((x <= 6e-104))) tmp = x * y; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -8.2e-24], N[Not[LessEqual[x, 6e-104]], $MachinePrecision]], N[(x * y), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8.2 \cdot 10^{-24} \lor \neg \left(x \leq 6 \cdot 10^{-104}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -8.20000000000000029e-24 or 6.0000000000000005e-104 < x Initial program 97.2%
Taylor expanded in y around inf 52.6%
if -8.20000000000000029e-24 < x < 6.0000000000000005e-104Initial program 100.0%
Taylor expanded in x around 0 74.5%
neg-mul-174.5%
Simplified74.5%
Final simplification62.3%
(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 Float64(-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 x around 0 38.9%
neg-mul-138.9%
Simplified38.9%
herbie shell --seed 2024108
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))